aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@pobox.com>2005-11-07 22:51:47 -0500
committerJeff Garzik <jgarzik@pobox.com>2005-11-07 22:51:47 -0500
commit6b995751c2e851d2bc9c277b5884d0adb519e31d (patch)
tree7a15b41b5d8ce612915584a0773c670d5c0ab5b8
parent6c2f4267833f453156f8f439cc32eb4c92f357b4 (diff)
parentd27ba47e7e8c466c18983a1779d611f82d6a354f (diff)
Merge branch 'master'
-rw-r--r--CREDITS6
-rw-r--r--Documentation/Changes11
-rw-r--r--Documentation/DocBook/Makefile2
-rw-r--r--Documentation/DocBook/journal-api.tmpl2
-rw-r--r--Documentation/DocBook/kernel-api.tmpl7
-rw-r--r--Documentation/DocBook/rapidio.tmpl160
-rw-r--r--Documentation/MSI-HOWTO.txt174
-rw-r--r--Documentation/RCU/whatisRCU.txt2
-rw-r--r--Documentation/device-mapper/snapshot.txt5
-rw-r--r--Documentation/fb/vesafb.txt4
-rw-r--r--Documentation/feature-removal-schedule.txt16
-rw-r--r--Documentation/filesystems/dentry-locking.txt173
-rw-r--r--Documentation/filesystems/devfs/README5
-rw-r--r--Documentation/filesystems/ramfs-rootfs-initramfs.txt195
-rw-r--r--Documentation/filesystems/vfs.txt434
-rw-r--r--Documentation/hpet.txt34
-rw-r--r--Documentation/ioctl-number.txt2
-rw-r--r--Documentation/magic-number.txt2
-rw-r--r--Documentation/networking/decnet.txt2
-rw-r--r--Documentation/oops-tracing.txt2
-rw-r--r--Documentation/power/video.txt17
-rw-r--r--Documentation/s390/driver-model.txt21
-rw-r--r--Documentation/sharedsubtree.txt1060
-rw-r--r--Documentation/sound/alsa/ALSA-Configuration.txt29
-rw-r--r--Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl56
-rw-r--r--Documentation/sparse.txt4
-rw-r--r--Documentation/video4linux/bttv/README.freeze6
-rw-r--r--Documentation/vm/hugetlbpage.txt25
-rw-r--r--MAINTAINERS32
-rw-r--r--Makefile2
-rw-r--r--arch/arm/Kconfig4
-rw-r--r--arch/arm/kernel/ptrace.c49
-rw-r--r--arch/arm/mach-aaec2000/clock.c1
-rw-r--r--arch/arm/mach-epxa10db/mm.c1
-rw-r--r--arch/arm/mach-integrator/impd1.c3
-rw-r--r--arch/arm/mach-ixp2000/core.c35
-rw-r--r--arch/arm/mach-pxa/corgi_lcd.c1
-rw-r--r--arch/arm/mach-realview/Kconfig9
-rw-r--r--arch/arm/mach-realview/Makefile1
-rw-r--r--arch/arm/mach-realview/core.h1
-rw-r--r--arch/arm/mach-realview/headsmp.S39
-rw-r--r--arch/arm/mach-realview/platsmp.c195
-rw-r--r--arch/arm/mach-realview/realview_eb.c5
-rw-r--r--arch/arm/mm/mm-armv.c48
-rw-r--r--arch/arm/mm/proc-v6.S26
-rw-r--r--arch/arm/nwfpe/fpa11.h2
-rw-r--r--arch/arm/nwfpe/fpa11_cpdt.c10
-rw-r--r--arch/arm/nwfpe/fpopcode.c16
-rw-r--r--arch/arm/nwfpe/softfloat-specialize1
-rw-r--r--arch/arm/nwfpe/softfloat.c6
-rw-r--r--arch/arm/nwfpe/softfloat.h14
-rw-r--r--arch/arm26/kernel/ptrace.c49
-rw-r--r--arch/cris/arch-v10/README.mm6
-rw-r--r--arch/cris/arch-v10/kernel/ptrace.c51
-rw-r--r--arch/cris/arch-v10/kernel/signal.c2
-rw-r--r--arch/cris/arch-v32/drivers/cryptocop.c14
-rw-r--r--arch/cris/arch-v32/kernel/ptrace.c51
-rw-r--r--arch/cris/arch-v32/kernel/signal.c2
-rw-r--r--arch/cris/mm/ioremap.c2
-rw-r--r--arch/frv/kernel/ptrace.c43
-rw-r--r--arch/h8300/kernel/ptrace.c39
-rw-r--r--arch/i386/Kconfig13
-rw-r--r--arch/i386/Kconfig.debug10
-rw-r--r--arch/i386/kernel/apic.c10
-rw-r--r--arch/i386/kernel/apm.c5
-rw-r--r--arch/i386/kernel/cpu/common.c5
-rw-r--r--arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c3
-rw-r--r--arch/i386/kernel/cpu/cpufreq/powernow-k7.c12
-rw-r--r--arch/i386/kernel/cpu/cpufreq/powernow-k8.c19
-rw-r--r--arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c5
-rw-r--r--arch/i386/kernel/cpu/mcheck/k7.c2
-rw-r--r--arch/i386/kernel/cpu/mcheck/mce.c4
-rw-r--r--arch/i386/kernel/cpu/mcheck/p4.c4
-rw-r--r--arch/i386/kernel/cpu/mcheck/p5.c2
-rw-r--r--arch/i386/kernel/cpu/mcheck/p6.c2
-rw-r--r--arch/i386/kernel/cpu/mcheck/winchip.c2
-rw-r--r--arch/i386/kernel/kprobes.c180
-rw-r--r--arch/i386/kernel/ldt.c1
-rw-r--r--arch/i386/kernel/mca.c2
-rw-r--r--arch/i386/kernel/ptrace.c44
-rw-r--r--arch/i386/kernel/reboot_fixups.c3
-rw-r--r--arch/i386/kernel/scx200.c1
-rw-r--r--arch/i386/kernel/smpboot.c4
-rw-r--r--arch/i386/oprofile/Kconfig6
-rw-r--r--arch/i386/power/cpu.c1
-rw-r--r--arch/ia64/Kconfig14
-rw-r--r--arch/ia64/Kconfig.debug11
-rw-r--r--arch/ia64/hp/sim/simserial.c6
-rw-r--r--arch/ia64/kernel/kprobes.c126
-rw-r--r--arch/ia64/kernel/perfmon.c2
-rw-r--r--arch/ia64/kernel/setup.c7
-rw-r--r--arch/ia64/oprofile/Kconfig6
-rw-r--r--arch/m68k/atari/time.c6
-rw-r--r--arch/m68k/kernel/ptrace.c47
-rw-r--r--arch/m68knommu/Kconfig17
-rw-r--r--arch/m68knommu/Makefile7
-rw-r--r--arch/m68knommu/kernel/asm-offsets.c1
-rw-r--r--arch/m68knommu/kernel/ptrace.c39
-rw-r--r--arch/m68knommu/kernel/setup.c5
-rw-r--r--arch/m68knommu/kernel/vmlinux.lds.S9
-rw-r--r--arch/m68knommu/platform/520x/Makefile19
-rw-r--r--arch/m68knommu/platform/520x/config.c65
-rw-r--r--arch/m68knommu/platform/5307/Makefile1
-rw-r--r--arch/m68knommu/platform/5307/head.S3
-rw-r--r--arch/m68knommu/platform/5307/ints.c1
-rw-r--r--arch/m68knommu/platform/5307/pit.c12
-rw-r--r--arch/mips/Kconfig2
-rw-r--r--arch/mips/boot/.gitignore4
-rw-r--r--arch/mips/configs/pnx8550-jbs_defconfig11
-rw-r--r--arch/mips/configs/pnx8550-v2pci_defconfig10
-rw-r--r--arch/mips/ddb5xxx/common/rtc_ds1386.c6
-rw-r--r--arch/mips/dec/time.c24
-rw-r--r--arch/mips/jmr3927/common/rtc_ds1742.c6
-rw-r--r--arch/mips/kernel/irixsig.c3
-rw-r--r--arch/mips/kernel/ptrace.c55
-rw-r--r--arch/mips/kernel/rtlx.c197
-rw-r--r--arch/mips/kernel/signal.c3
-rw-r--r--arch/mips/kernel/signal32.c13
-rw-r--r--arch/mips/kernel/vpe.c100
-rw-r--r--arch/mips/lasat/ds1603.c9
-rw-r--r--arch/mips/momentum/jaguar_atx/setup.c6
-rw-r--r--arch/mips/momentum/ocelot_3/setup.c6
-rw-r--r--arch/mips/momentum/ocelot_c/setup.c6
-rw-r--r--arch/mips/pmc-sierra/yosemite/setup.c6
-rw-r--r--arch/mips/sgi-ip22/ip22-time.c6
-rw-r--r--arch/mips/sibyte/swarm/rtc_m41t81.c7
-rw-r--r--arch/mips/sibyte/swarm/rtc_xicor1241.c6
-rw-r--r--arch/parisc/kernel/ptrace.c50
-rw-r--r--arch/powerpc/Kconfig14
-rw-r--r--arch/powerpc/Kconfig.debug10
-rw-r--r--arch/powerpc/kernel/cputable.c10
-rw-r--r--arch/powerpc/kernel/ptrace.c43
-rw-r--r--arch/powerpc/kernel/time.c1
-rw-r--r--arch/powerpc/mm/hash_utils_64.c6
-rw-r--r--arch/powerpc/mm/hugetlbpage.c6
-rw-r--r--arch/powerpc/mm/ppc_mmu_32.c4
-rw-r--r--arch/powerpc/mm/slb_low.S13
-rw-r--r--arch/powerpc/oprofile/Kconfig6
-rw-r--r--arch/powerpc/platforms/pseries/reconfig.c6
-rw-r--r--arch/ppc/4xx_io/serial_sicc.c17
-rw-r--r--arch/ppc/8260_io/fcc_enet.c3
-rw-r--r--arch/ppc/8xx_io/cs4218_tdm.c3
-rw-r--r--arch/ppc/Kconfig18
-rw-r--r--arch/ppc/boot/simple/Makefile27
-rw-r--r--arch/ppc/boot/simple/misc.c16
-rw-r--r--arch/ppc/boot/simple/openbios.c106
-rw-r--r--arch/ppc/configs/ev64360_defconfig73
-rw-r--r--arch/ppc/configs/stx_gp3_defconfig86
-rw-r--r--arch/ppc/kernel/Makefile1
-rw-r--r--arch/ppc/kernel/head_44x.S4
-rw-r--r--arch/ppc/kernel/rio.c52
-rw-r--r--arch/ppc/platforms/4xx/Kconfig19
-rw-r--r--arch/ppc/platforms/4xx/Makefile2
-rw-r--r--arch/ppc/platforms/4xx/bubinga.c2
-rw-r--r--arch/ppc/platforms/4xx/bubinga.h64
-rw-r--r--arch/ppc/platforms/4xx/ebony.h4
-rw-r--r--arch/ppc/platforms/4xx/ppc440spe.c148
-rw-r--r--arch/ppc/platforms/4xx/ppc440spe.h66
-rw-r--r--arch/ppc/platforms/4xx/sycamore.c7
-rw-r--r--arch/ppc/platforms/4xx/sycamore.h67
-rw-r--r--arch/ppc/platforms/4xx/walnut.c2
-rw-r--r--arch/ppc/platforms/4xx/walnut.h67
-rw-r--r--arch/ppc/platforms/4xx/yucca.c395
-rw-r--r--arch/ppc/platforms/4xx/yucca.h111
-rw-r--r--arch/ppc/platforms/85xx/mpc85xx_ads_common.c10
-rw-r--r--arch/ppc/platforms/85xx/stx_gp3.c14
-rw-r--r--arch/ppc/platforms/ev64360.c12
-rw-r--r--arch/ppc/syslib/Makefile4
-rw-r--r--arch/ppc/syslib/ibm440sp_common.c4
-rw-r--r--arch/ppc/syslib/ibm44x_common.c12
-rw-r--r--arch/ppc/syslib/ppc405_pci.c7
-rw-r--r--arch/ppc/syslib/ppc440spe_pcie.c442
-rw-r--r--arch/ppc/syslib/ppc440spe_pcie.h149
-rw-r--r--arch/ppc/syslib/ppc4xx_pic.c37
-rw-r--r--arch/ppc/syslib/ppc85xx_rio.c938
-rw-r--r--arch/ppc/syslib/ppc85xx_rio.h21
-rw-r--r--arch/ppc/syslib/ppc_sys.c1
-rw-r--r--arch/ppc/syslib/prom.c6
-rw-r--r--arch/ppc64/boot/main.c11
-rw-r--r--arch/ppc64/kernel/kprobes.c138
-rw-r--r--arch/ppc64/kernel/lparcfg.c4
-rw-r--r--arch/ppc64/kernel/scanlog.c3
-rw-r--r--arch/ppc64/kernel/sysfs.c1
-rw-r--r--arch/s390/Makefile4
-rw-r--r--arch/s390/kernel/Makefile4
-rw-r--r--arch/s390/kernel/entry.S4
-rw-r--r--arch/s390/kernel/entry64.S4
-rw-r--r--arch/s390/kernel/head.S383
-rw-r--r--arch/s390/kernel/head31.S336
-rw-r--r--arch/s390/kernel/head64.S543
-rw-r--r--arch/s390/kernel/time.c8
-rw-r--r--arch/s390/kernel/traps.c29
-rw-r--r--arch/s390/mm/extmem.c8
-rw-r--r--arch/s390/mm/fault.c113
-rw-r--r--arch/sh/Kconfig28
-rw-r--r--arch/sh/Makefile8
-rw-r--r--arch/sh/drivers/Makefile5
-rw-r--r--arch/sh/drivers/superhyway/Makefile6
-rw-r--r--arch/sh/drivers/superhyway/ops-sh4-202.c171
-rw-r--r--arch/sh/kernel/ptrace.c44
-rw-r--r--arch/sh/kernel/setup.c26
-rw-r--r--arch/sh/mm/init.c21
-rw-r--r--arch/sh/mm/tlb-sh3.c19
-rw-r--r--arch/sh/ramdisk/Makefile20
-rw-r--r--arch/sh/ramdisk/ld.script9
-rw-r--r--arch/sh64/kernel/ptrace.c83
-rw-r--r--arch/sh64/kernel/syscalls.S2
-rw-r--r--arch/sparc/Kconfig8
-rw-r--r--arch/sparc/kernel/Makefile1
-rw-r--r--arch/sparc/kernel/led.c139
-rw-r--r--arch/sparc/kernel/sunos_ioctl.c1
-rw-r--r--arch/sparc64/Kconfig13
-rw-r--r--arch/sparc64/Kconfig.debug10
-rw-r--r--arch/sparc64/kernel/ioctl32.c459
-rw-r--r--arch/sparc64/kernel/kprobes.c165
-rw-r--r--arch/sparc64/kernel/setup.c12
-rw-r--r--arch/sparc64/kernel/signal32.c6
-rw-r--r--arch/sparc64/kernel/smp.c79
-rw-r--r--arch/sparc64/kernel/sunos_ioctl32.c1
-rw-r--r--arch/sparc64/kernel/time.c13
-rw-r--r--arch/sparc64/kernel/us2e_cpufreq.c7
-rw-r--r--arch/sparc64/kernel/us3_cpufreq.c7
-rw-r--r--arch/sparc64/oprofile/Kconfig6
-rw-r--r--arch/um/Kconfig46
-rw-r--r--arch/um/Makefile2
-rw-r--r--arch/um/Makefile-i3862
-rw-r--r--arch/um/drivers/chan_user.c1
-rw-r--r--arch/um/drivers/harddog_kern.c1
-rw-r--r--arch/um/drivers/harddog_user.c1
-rw-r--r--arch/um/drivers/net_kern.c38
-rw-r--r--arch/um/drivers/net_user.c1
-rw-r--r--arch/um/drivers/port_user.c1
-rw-r--r--arch/um/drivers/random.c6
-rw-r--r--arch/um/drivers/slip_user.c1
-rw-r--r--arch/um/drivers/slirp_user.c1
-rw-r--r--arch/um/drivers/xterm.c1
-rw-r--r--arch/um/include/helper.h27
-rw-r--r--arch/um/include/mem_user.h2
-rw-r--r--arch/um/include/net_user.h2
-rw-r--r--arch/um/include/os.h16
-rw-r--r--arch/um/include/sysdep-i386/stub.h64
-rw-r--r--arch/um/include/sysdep-x86_64/stub.h61
-rw-r--r--arch/um/include/uml_uaccess.h4
-rw-r--r--arch/um/kernel/Makefile7
-rw-r--r--arch/um/kernel/ksyms.c1
-rw-r--r--arch/um/kernel/mem.c4
-rw-r--r--arch/um/kernel/physmem.c4
-rw-r--r--arch/um/kernel/ptrace.c50
-rw-r--r--arch/um/kernel/sigio_user.c3
-rw-r--r--arch/um/kernel/skas/include/mmu-skas.h2
-rw-r--r--arch/um/kernel/skas/include/skas.h3
-rw-r--r--arch/um/kernel/skas/mem.c2
-rw-r--r--arch/um/kernel/skas/mmu.c44
-rw-r--r--arch/um/kernel/skas/process.c17
-rw-r--r--arch/um/kernel/skas/process_kern.c2
-rw-r--r--arch/um/kernel/tt/uaccess_user.c1
-rw-r--r--arch/um/kernel/uaccess.c30
-rw-r--r--arch/um/kernel/uaccess_user.c64
-rw-r--r--arch/um/kernel/um_arch.c10
-rw-r--r--arch/um/kernel/user_util.c1
-rw-r--r--arch/um/os-Linux/Makefile9
-rw-r--r--arch/um/os-Linux/aio.c1
-rw-r--r--arch/um/os-Linux/drivers/ethertap_user.c1
-rw-r--r--arch/um/os-Linux/drivers/tuntap_user.c1
-rw-r--r--arch/um/os-Linux/helper.c (renamed from arch/um/kernel/helper.c)18
-rw-r--r--arch/um/os-Linux/main.c (renamed from arch/um/kernel/main.c)49
-rw-r--r--arch/um/os-Linux/mem.c6
-rw-r--r--arch/um/os-Linux/start_up.c77
-rw-r--r--arch/um/os-Linux/uaccess.c32
-rw-r--r--arch/um/scripts/Makefile.rules7
-rw-r--r--arch/um/sys-i386/ldt.c506
-rw-r--r--arch/um/sys-x86_64/Makefile5
-rw-r--r--arch/um/sys-x86_64/syscalls.c75
-rw-r--r--arch/v850/kernel/ptrace.c43
-rw-r--r--arch/x86_64/Kconfig13
-rw-r--r--arch/x86_64/Kconfig.debug10
-rw-r--r--arch/x86_64/kernel/kprobes.c183
-rw-r--r--arch/x86_64/kernel/ptrace.c43
-rw-r--r--arch/x86_64/kernel/smpboot.c2
-rw-r--r--arch/x86_64/oprofile/Kconfig6
-rw-r--r--arch/xtensa/kernel/ptrace.c55
-rw-r--r--block/Kconfig14
-rw-r--r--block/Kconfig.iosched (renamed from drivers/block/Kconfig.iosched)6
-rw-r--r--block/Makefile10
-rw-r--r--block/as-iosched.c (renamed from drivers/block/as-iosched.c)310
-rw-r--r--block/cfq-iosched.c (renamed from drivers/block/cfq-iosched.c)0
-rw-r--r--block/deadline-iosched.c (renamed from drivers/block/deadline-iosched.c)0
-rw-r--r--block/elevator.c (renamed from drivers/block/elevator.c)0
-rw-r--r--block/genhd.c (renamed from drivers/block/genhd.c)0
-rw-r--r--block/ioctl.c (renamed from drivers/block/ioctl.c)0
-rw-r--r--block/ll_rw_blk.c (renamed from drivers/block/ll_rw_blk.c)1
-rw-r--r--block/noop-iosched.c (renamed from drivers/block/noop-iosched.c)0
-rw-r--r--block/scsi_ioctl.c (renamed from drivers/block/scsi_ioctl.c)0
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/acpi/container.c6
-rw-r--r--drivers/acpi/osl.c6
-rw-r--r--drivers/acpi/scan.c6
-rw-r--r--drivers/acpi/video.c12
-rw-r--r--drivers/base/power/sysfs.c1
-rw-r--r--drivers/block/DAC960.c31
-rw-r--r--drivers/block/Kconfig12
-rw-r--r--drivers/block/Makefile14
-rw-r--r--drivers/block/cciss.c12
-rw-r--r--drivers/bluetooth/bcm203x.c4
-rw-r--r--drivers/bluetooth/bfusb.c4
-rw-r--r--drivers/bluetooth/bluecard_cs.c3
-rw-r--r--drivers/bluetooth/bpa10x.c4
-rw-r--r--drivers/bluetooth/bt3c_cs.c3
-rw-r--r--drivers/bluetooth/btuart_cs.c3
-rw-r--r--drivers/bluetooth/dtl1_cs.c3
-rw-r--r--drivers/bluetooth/hci_bcsp.c3
-rw-r--r--drivers/bluetooth/hci_h4.c4
-rw-r--r--drivers/bluetooth/hci_ldisc.c4
-rw-r--r--drivers/bluetooth/hci_usb.c4
-rw-r--r--drivers/bluetooth/hci_vhci.c4
-rw-r--r--drivers/cdrom/mcdx.c4
-rw-r--r--drivers/char/agp/ali-agp.c1
-rw-r--r--drivers/char/agp/amd-k7-agp.c8
-rw-r--r--drivers/char/agp/amd64-agp.c2
-rw-r--r--drivers/char/agp/ati-agp.c8
-rw-r--r--drivers/char/agp/backend.c6
-rw-r--r--drivers/char/agp/efficeon-agp.c3
-rw-r--r--drivers/char/agp/frontend.c15
-rw-r--r--drivers/char/agp/generic.c10
-rw-r--r--drivers/char/agp/i460-agp.c7
-rw-r--r--drivers/char/agp/intel-agp.c1
-rw-r--r--drivers/char/agp/nvidia-agp.c1
-rw-r--r--drivers/char/agp/sgi-agp.c2
-rw-r--r--drivers/char/agp/sis-agp.c1
-rw-r--r--drivers/char/agp/sworks-agp.c29
-rw-r--r--drivers/char/agp/uninorth-agp.c1
-rw-r--r--drivers/char/agp/via-agp.c1
-rw-r--r--drivers/char/consolemap.c12
-rw-r--r--drivers/char/drm/ffb_context.c6
-rw-r--r--drivers/char/drm/ffb_drv.c6
-rw-r--r--drivers/char/ip2/i2ellis.c4
-rw-r--r--drivers/char/ipmi/ipmi_bt_sm.c38
-rw-r--r--drivers/char/ipmi/ipmi_kcs_sm.c48
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c952
-rw-r--r--drivers/char/ipmi/ipmi_poweroff.c4
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c183
-rw-r--r--drivers/char/ipmi/ipmi_si_sm.h1
-rw-r--r--drivers/char/ipmi/ipmi_smic_sm.c15
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c259
-rw-r--r--drivers/char/istallion.c7
-rw-r--r--drivers/char/mxser.c47
-rw-r--r--drivers/char/n_hdlc.c3
-rw-r--r--drivers/char/pcmcia/synclink_cs.c3
-rw-r--r--drivers/char/rocket.c6
-rw-r--r--drivers/char/rtc.c65
-rw-r--r--drivers/char/selection.c3
-rw-r--r--drivers/char/stallion.c6
-rw-r--r--drivers/char/synclink.c10
-rw-r--r--drivers/char/synclinkmp.c9
-rw-r--r--drivers/char/tpm/tpm_nsc.c48
-rw-r--r--drivers/char/tty_io.c9
-rw-r--r--drivers/char/vt_ioctl.c5
-rw-r--r--drivers/connector/Kconfig8
-rw-r--r--drivers/connector/Makefile1
-rw-r--r--drivers/connector/cn_proc.c222
-rw-r--r--drivers/cpufreq/cpufreq.c3
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c18
-rw-r--r--drivers/cpufreq/cpufreq_stats.c12
-rw-r--r--drivers/dio/dio.c3
-rw-r--r--drivers/eisa/eisa-bus.c8
-rw-r--r--drivers/fc4/fc.c32
-rw-r--r--drivers/fc4/soc.c3
-rw-r--r--drivers/fc4/socal.c3
-rw-r--r--drivers/firmware/dell_rbu.c121
-rw-r--r--drivers/firmware/edd.c3
-rw-r--r--drivers/firmware/efivars.c10
-rw-r--r--drivers/hwmon/hwmon.c1
-rw-r--r--drivers/hwmon/max1619.c14
-rw-r--r--drivers/hwmon/w83781d.c6
-rw-r--r--drivers/i2c/busses/i2c-amd756-s4882.c6
-rw-r--r--drivers/ide/ide-cd.c22
-rw-r--r--drivers/ide/ide-disk.c4
-rw-r--r--drivers/ide/ide-floppy.c4
-rw-r--r--drivers/ide/ide-probe.c9
-rw-r--r--drivers/ide/ide-tape.c4
-rw-r--r--drivers/ide/ide-taskfile.c18
-rw-r--r--drivers/ide/ide.c6
-rw-r--r--drivers/ide/legacy/ide-cs.c6
-rw-r--r--drivers/ide/pci/hpt366.c3
-rw-r--r--drivers/ide/pci/it821x.c3
-rw-r--r--drivers/ieee1394/amdtp.c3
-rw-r--r--drivers/infiniband/core/agent.c3
-rw-r--r--drivers/infiniband/core/mad.c6
-rw-r--r--drivers/infiniband/core/packer.c2
-rw-r--r--drivers/infiniband/core/sysfs.c3
-rw-r--r--drivers/infiniband/core/ud_header.c1
-rw-r--r--drivers/infiniband/core/verbs.c1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_catas.c3
-rw-r--r--drivers/infiniband/hw/mthca/mthca_srq.c3
-rw-r--r--drivers/input/input.c27
-rw-r--r--drivers/input/keyboard/lkkbd.c101
-rw-r--r--drivers/input/keyboard/locomokbd.c63
-rw-r--r--drivers/input/misc/uinput.c10
-rw-r--r--drivers/input/mouse/logips2pp.c3
-rw-r--r--drivers/isdn/hardware/avm/avm_cs.c5
-rw-r--r--drivers/isdn/hisax/avm_pci.c12
-rw-r--r--drivers/isdn/hisax/avma1_cs.c4
-rw-r--r--drivers/isdn/hisax/config.c9
-rw-r--r--drivers/isdn/hisax/hfc_2bds0.c18
-rw-r--r--drivers/isdn/hisax/hfc_2bs0.c12
-rw-r--r--drivers/isdn/hisax/hfc_usb.c292
-rw-r--r--drivers/isdn/hisax/hfc_usb.h6
-rw-r--r--drivers/isdn/hisax/hscx.c12
-rw-r--r--drivers/isdn/hisax/icc.c12
-rw-r--r--drivers/isdn/hisax/ipacx.c12
-rw-r--r--drivers/isdn/hisax/isac.c15
-rw-r--r--drivers/isdn/hisax/isar.c6
-rw-r--r--drivers/isdn/hisax/jade.c12
-rw-r--r--drivers/isdn/hisax/netjet.c32
-rw-r--r--drivers/isdn/hisax/st5481_usb.c12
-rw-r--r--drivers/isdn/hisax/w6692.c12
-rw-r--r--drivers/isdn/hysdn/hysdn_procconf.c3
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c21
-rw-r--r--drivers/isdn/i4l/isdn_tty.c27
-rw-r--r--drivers/isdn/icn/icn.c3
-rw-r--r--drivers/isdn/isdnloop/isdnloop.c9
-rw-r--r--drivers/isdn/pcbit/drv.c6
-rw-r--r--drivers/isdn/sc/init.c3
-rw-r--r--drivers/isdn/sc/message.c3
-rw-r--r--drivers/macintosh/adbhid.c3
-rw-r--r--drivers/macintosh/therm_pm72.c3
-rw-r--r--drivers/md/raid5.c3
-rw-r--r--drivers/md/raid6main.c3
-rw-r--r--drivers/media/dvb/bt8xx/dst.c8
-rw-r--r--drivers/media/dvb/frontends/cx24110.c1
-rw-r--r--drivers/media/dvb/frontends/dvb_dummy_fe.c4
-rw-r--r--drivers/media/dvb/frontends/l64781.c3
-rw-r--r--drivers/media/dvb/frontends/lgdt330x.c3
-rw-r--r--drivers/media/dvb/frontends/mt312.c3
-rw-r--r--drivers/media/dvb/frontends/or51132.c3
-rw-r--r--drivers/media/video/arv.c12
-rw-r--r--drivers/media/video/bttv-driver.c6
-rw-r--r--drivers/media/video/indycam.c262
-rw-r--r--drivers/media/video/indycam.h88
-rw-r--r--drivers/media/video/msp3400.c4
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c4
-rw-r--r--drivers/media/video/saa7191.c533
-rw-r--r--drivers/media/video/saa7191.h172
-rw-r--r--drivers/media/video/v4l1-compat.c6
-rw-r--r--drivers/media/video/videocodec.c6
-rw-r--r--drivers/media/video/videodev.c3
-rw-r--r--drivers/media/video/vino.c1170
-rw-r--r--drivers/media/video/zoran_card.c14
-rw-r--r--drivers/media/video/zoran_driver.c4
-rw-r--r--drivers/message/fusion/mptlan.c10
-rw-r--r--drivers/message/fusion/mptscsih.c6
-rw-r--r--drivers/message/i2o/exec-osm.c1
-rw-r--r--drivers/message/i2o/iop.c15
-rw-r--r--drivers/mfd/mcp-core.c2
-rw-r--r--drivers/mmc/mmc.c2
-rw-r--r--drivers/mmc/wbsd.c3
-rw-r--r--drivers/mtd/Kconfig40
-rw-r--r--drivers/mtd/Makefile5
-rw-r--r--drivers/mtd/afs.c16
-rw-r--r--drivers/mtd/chips/Kconfig22
-rw-r--r--drivers/mtd/chips/Makefile4
-rw-r--r--drivers/mtd/chips/amd_flash.c80
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c487
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c160
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0020.c183
-rw-r--r--drivers/mtd/chips/cfi_probe.c98
-rw-r--r--drivers/mtd/chips/cfi_util.c25
-rw-r--r--drivers/mtd/chips/chipreg.c6
-rw-r--r--drivers/mtd/chips/fwh_lock.h6
-rw-r--r--drivers/mtd/chips/gen_probe.c33
-rw-r--r--drivers/mtd/chips/jedec.c206
-rw-r--r--drivers/mtd/chips/jedec_probe.c48
-rw-r--r--drivers/mtd/chips/map_absent.c8
-rw-r--r--drivers/mtd/chips/sharp.c23
-rw-r--r--drivers/mtd/cmdlinepart.c56
-rw-r--r--drivers/mtd/devices/Kconfig8
-rw-r--r--drivers/mtd/devices/blkmtd.c17
-rw-r--r--drivers/mtd/devices/block2mtd.c8
-rw-r--r--drivers/mtd/devices/doc2000.c42
-rw-r--r--drivers/mtd/devices/doc2001.c24
-rw-r--r--drivers/mtd/devices/doc2001plus.c20
-rw-r--r--drivers/mtd/devices/docecc.c40
-rw-r--r--drivers/mtd/devices/docprobe.c84
-rw-r--r--drivers/mtd/devices/lart.c8
-rw-r--r--drivers/mtd/devices/phram.c14
-rw-r--r--drivers/mtd/devices/pmc551.c24
-rw-r--r--drivers/mtd/devices/slram.c30
-rw-r--r--drivers/mtd/ftl.c128
-rw-r--r--drivers/mtd/inftlcore.c60
-rw-r--r--drivers/mtd/inftlmount.c26
-rw-r--r--drivers/mtd/maps/Kconfig115
-rw-r--r--drivers/mtd/maps/Makefile7
-rw-r--r--drivers/mtd/maps/alchemy-flash.c12
-rw-r--r--drivers/mtd/maps/amd76xrom.c20
-rw-r--r--drivers/mtd/maps/arctic-mtd.c6
-rw-r--r--drivers/mtd/maps/autcpu12-nvram.c18
-rw-r--r--drivers/mtd/maps/bast-flash.c22
-rw-r--r--drivers/mtd/maps/beech-mtd.c6
-rw-r--r--drivers/mtd/maps/cdb89712.c34
-rw-r--r--drivers/mtd/maps/ceiva.c3
-rw-r--r--drivers/mtd/maps/cfi_flagadm.c12
-rw-r--r--drivers/mtd/maps/cstm_mips_ixx.c24
-rw-r--r--drivers/mtd/maps/dbox2-flash.c38
-rw-r--r--drivers/mtd/maps/dc21285.c34
-rw-r--r--drivers/mtd/maps/dilnetpc.c32
-rw-r--r--drivers/mtd/maps/dmv182.c8
-rw-r--r--drivers/mtd/maps/ebony.c6
-rw-r--r--drivers/mtd/maps/edb7312.c10
-rw-r--r--drivers/mtd/maps/epxa10db-flash.c12
-rw-r--r--drivers/mtd/maps/fortunet.c4
-rw-r--r--drivers/mtd/maps/h720x-flash.c16
-rw-r--r--drivers/mtd/maps/ichxrom.c21
-rw-r--r--drivers/mtd/maps/impa7.c16
-rw-r--r--drivers/mtd/maps/integrator-flash.c20
-rw-r--r--drivers/mtd/maps/ipaq-flash.c37
-rw-r--r--drivers/mtd/maps/iq80310.c7
-rw-r--r--drivers/mtd/maps/ixp2000.c35
-rw-r--r--drivers/mtd/maps/ixp4xx.c56
-rw-r--r--drivers/mtd/maps/l440gx.c18
-rw-r--r--drivers/mtd/maps/lubbock-flash.c17
-rw-r--r--drivers/mtd/maps/mainstone-flash.c22
-rw-r--r--drivers/mtd/maps/mbx860.c6
-rw-r--r--drivers/mtd/maps/mtx-1_flash.c96
-rw-r--r--drivers/mtd/maps/netsc520.c32
-rw-r--r--drivers/mtd/maps/nettel.c8
-rw-r--r--drivers/mtd/maps/ocelot.c10
-rw-r--r--drivers/mtd/maps/octagon-5066.c36
-rw-r--r--drivers/mtd/maps/omap-toto-flash.c23
-rw-r--r--drivers/mtd/maps/omap_nor.c2
-rw-r--r--drivers/mtd/maps/pci.c6
-rw-r--r--drivers/mtd/maps/pcmciamtd.c30
-rw-r--r--drivers/mtd/maps/physmap.c8
-rw-r--r--drivers/mtd/maps/plat-ram.c13
-rw-r--r--drivers/mtd/maps/pnc2000.c8
-rw-r--r--drivers/mtd/maps/pq2fads.c88
-rw-r--r--drivers/mtd/maps/redwood.c4
-rw-r--r--drivers/mtd/maps/sa1100-flash.c9
-rw-r--r--drivers/mtd/maps/sbc8240.c4
-rw-r--r--drivers/mtd/maps/sbc_gxx.c46
-rw-r--r--drivers/mtd/maps/sc520cdp.c6
-rw-r--r--drivers/mtd/maps/scx200_docflash.c46
-rw-r--r--drivers/mtd/maps/sharpsl-flash.c12
-rw-r--r--drivers/mtd/maps/solutionengine.c4
-rw-r--r--drivers/mtd/maps/sun_uflash.c16
-rw-r--r--drivers/mtd/maps/tqm834x.c291
-rw-r--r--drivers/mtd/maps/tqm8xxl.c26
-rw-r--r--drivers/mtd/maps/ts5500_flash.c44
-rw-r--r--drivers/mtd/maps/tsunami_flash.c6
-rw-r--r--drivers/mtd/maps/uclinux.c4
-rw-r--r--drivers/mtd/maps/vmax301.c24
-rw-r--r--drivers/mtd/maps/walnut.c16
-rw-r--r--drivers/mtd/maps/wr_sbc82xx_flash.c6
-rw-r--r--drivers/mtd/mtd_blkdevs.c44
-rw-r--r--drivers/mtd/mtdblock.c53
-rw-r--r--drivers/mtd/mtdchar.c86
-rw-r--r--drivers/mtd/mtdconcat.c13
-rw-r--r--drivers/mtd/mtdcore.c62
-rw-r--r--drivers/mtd/mtdpart.c99
-rw-r--r--drivers/mtd/nand/Kconfig26
-rw-r--r--drivers/mtd/nand/au1550nd.c165
-rw-r--r--drivers/mtd/nand/autcpu12.c22
-rw-r--r--drivers/mtd/nand/diskonchip.c100
-rw-r--r--drivers/mtd/nand/edb7312.c48
-rw-r--r--drivers/mtd/nand/h1910.c48
-rw-r--r--drivers/mtd/nand/nand_base.c534
-rw-r--r--drivers/mtd/nand/nand_bbt.c248
-rw-r--r--drivers/mtd/nand/nand_ecc.c44
-rw-r--r--drivers/mtd/nand/nand_ids.c30
-rw-r--r--drivers/mtd/nand/nandsim.c162
-rw-r--r--drivers/mtd/nand/ppchameleonevb.c6
-rw-r--r--drivers/mtd/nand/rtc_from4.c58
-rw-r--r--drivers/mtd/nand/s3c2410.c61
-rw-r--r--drivers/mtd/nand/sharpsl.c41
-rw-r--r--drivers/mtd/nand/spia.c6
-rw-r--r--drivers/mtd/nand/toto.c20
-rw-r--r--drivers/mtd/nftlcore.c92
-rw-r--r--drivers/mtd/nftlmount.c56
-rw-r--r--drivers/mtd/onenand/Kconfig38
-rw-r--r--drivers/mtd/onenand/Makefile11
-rw-r--r--drivers/mtd/onenand/generic.c147
-rw-r--r--drivers/mtd/onenand/onenand_base.c1588
-rw-r--r--drivers/mtd/onenand/onenand_bbt.c246
-rw-r--r--drivers/mtd/redboot.c4
-rw-r--r--drivers/mtd/rfd_ftl.c855
-rw-r--r--drivers/net/3c59x.c586
-rw-r--r--drivers/net/fec.c240
-rw-r--r--drivers/net/fec.h10
-rw-r--r--drivers/parport/probe.c21
-rw-r--r--drivers/parport/share.c19
-rw-r--r--drivers/pci/hotplug/cpqphp_pci.c15
-rw-r--r--drivers/pci/hotplug/pciehprm_nonacpi.c1
-rw-r--r--drivers/pci/pci-driver.c1
-rw-r--r--drivers/pcmcia/cistpl.c12
-rw-r--r--drivers/pcmcia/cs.c6
-rw-r--r--drivers/pnp/card.c4
-rw-r--r--drivers/pnp/core.c5
-rw-r--r--drivers/pnp/driver.c2
-rw-r--r--drivers/pnp/isapnp/core.c2
-rw-r--r--drivers/pnp/manager.c2
-rw-r--r--drivers/pnp/pnpacpi/core.c6
-rw-r--r--drivers/pnp/resource.c2
-rw-r--r--drivers/rapidio/Kconfig18
-rw-r--r--drivers/rapidio/Makefile6
-rw-r--r--drivers/rapidio/rio-access.c175
-rw-r--r--drivers/rapidio/rio-driver.c229
-rw-r--r--drivers/rapidio/rio-scan.c945
-rw-r--r--drivers/rapidio/rio-sysfs.c230
-rw-r--r--drivers/rapidio/rio.c510
-rw-r--r--drivers/rapidio/rio.h60
-rw-r--r--drivers/rapidio/switches/Makefile5
-rw-r--r--drivers/rapidio/switches/tsi500.c60
-rw-r--r--drivers/s390/block/dasd.c12
-rw-r--r--drivers/s390/block/dasd_devmap.c3
-rw-r--r--drivers/s390/block/dasd_diag.c64
-rw-r--r--drivers/s390/block/dasd_diag.h10
-rw-r--r--drivers/s390/char/con3215.c3
-rw-r--r--drivers/s390/char/keyboard.c15
-rw-r--r--drivers/s390/char/raw3270.c3
-rw-r--r--drivers/s390/char/tape_core.c9
-rw-r--r--drivers/s390/char/vmcp.c4
-rw-r--r--drivers/s390/cio/ccwgroup.c6
-rw-r--r--drivers/s390/cio/cmf.c3
-rw-r--r--drivers/s390/cio/device_ops.c6
-rw-r--r--drivers/s390/cio/qdio.c17
-rw-r--r--drivers/s390/crypto/z90main.c7
-rw-r--r--drivers/s390/net/claw.c36
-rw-r--r--drivers/s390/net/fsm.c3
-rw-r--r--drivers/s390/net/iucv.c12
-rw-r--r--drivers/s390/net/lcs.c3
-rw-r--r--drivers/s390/net/qeth_eddp.c3
-rw-r--r--drivers/s390/scsi/zfcp_aux.c3
-rw-r--r--drivers/sbus/char/cpwatchdog.c24
-rw-r--r--drivers/sbus/char/display7seg.c32
-rw-r--r--drivers/sbus/char/envctrl.c31
-rw-r--r--drivers/sbus/char/openprom.c33
-rw-r--r--drivers/scsi/3w-9xxx.c3
-rw-r--r--drivers/scsi/NCR5380.c5
-rw-r--r--drivers/scsi/aacraid/commsup.c14
-rw-r--r--drivers/scsi/aacraid/rkt.c6
-rw-r--r--drivers/scsi/aacraid/rx.c6
-rw-r--r--drivers/scsi/aacraid/sa.c6
-rw-r--r--drivers/scsi/advansys.c12
-rw-r--r--drivers/scsi/aha1542.c36
-rw-r--r--drivers/scsi/aic7xxx_old.c3
-rw-r--r--drivers/scsi/arm/queue.c3
-rw-r--r--drivers/scsi/atari_dma_emul.c2
-rw-r--r--drivers/scsi/dc395x.c3
-rw-r--r--drivers/scsi/dpt_i2o.c61
-rw-r--r--drivers/scsi/eata.c3
-rw-r--r--drivers/scsi/ide-scsi.c10
-rw-r--r--drivers/scsi/ips.c18
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c9
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c6
-rw-r--r--drivers/scsi/lpfc/lpfc_mbox.c7
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c12
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c7
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c5
-rw-r--r--drivers/scsi/megaraid/megaraid_mm.c11
-rw-r--r--drivers/scsi/osst.c9
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c16
-rw-r--r--drivers/scsi/raid_class.c2
-rw-r--r--drivers/scsi/scsi_transport_sas.c2
-rw-r--r--drivers/scsi/sg.c9
-rw-r--r--drivers/scsi/st.c3
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.c1
-rw-r--r--drivers/scsi/u14-34f.c9
-rw-r--r--drivers/serial/8250.c3
-rw-r--r--drivers/serial/crisv10.c9
-rw-r--r--drivers/serial/mcfserial.c37
-rw-r--r--drivers/serial/sunsu.c2
-rw-r--r--drivers/sh/superhyway/superhyway-sysfs.c2
-rw-r--r--drivers/sh/superhyway/superhyway.c75
-rw-r--r--drivers/tc/.gitignore1
-rw-r--r--drivers/video/68328fb.c1
-rw-r--r--drivers/video/Kconfig214
-rw-r--r--drivers/video/Makefile1
-rw-r--r--drivers/video/acornfb.c1
-rw-r--r--drivers/video/amba-clcd.c1
-rw-r--r--drivers/video/amifb.c1
-rw-r--r--drivers/video/arcfb.c1
-rw-r--r--drivers/video/asiliantfb.c1
-rw-r--r--drivers/video/aty/ati_ids.h1
-rw-r--r--drivers/video/aty/aty128fb.c1
-rw-r--r--drivers/video/aty/atyfb_base.c59
-rw-r--r--drivers/video/aty/radeon_base.c3
-rw-r--r--drivers/video/aty/radeonfb.h3
-rw-r--r--drivers/video/bw2.c1
-rw-r--r--drivers/video/cfbcopyarea.c36
-rw-r--r--drivers/video/cfbfillrect.c24
-rw-r--r--drivers/video/cfbimgblt.c22
-rw-r--r--drivers/video/cg14.c1
-rw-r--r--drivers/video/cg3.c1
-rw-r--r--drivers/video/cg6.c7
-rw-r--r--drivers/video/chipsfb.c1
-rw-r--r--drivers/video/cirrusfb.c1
-rw-r--r--drivers/video/clps711xfb.c1
-rw-r--r--drivers/video/console/Kconfig9
-rw-r--r--drivers/video/console/Makefile3
-rw-r--r--drivers/video/console/bitblit.c7
-rw-r--r--drivers/video/console/fbcon.c114
-rw-r--r--drivers/video/console/fbcon.h2
-rw-r--r--drivers/video/console/font_rl.c4374
-rw-r--r--drivers/video/console/fonts.c4
-rw-r--r--drivers/video/console/softcursor.c (renamed from drivers/video/softcursor.c)8
-rw-r--r--drivers/video/controlfb.c1
-rw-r--r--drivers/video/cyber2000fb.c1
-rw-r--r--drivers/video/cyblafb.c1
-rw-r--r--drivers/video/dnfb.c1
-rw-r--r--drivers/video/epson1355fb.c1
-rw-r--r--drivers/video/fbmon.c48
-rw-r--r--drivers/video/ffb.c3
-rw-r--r--drivers/video/fm2fb.c1
-rw-r--r--drivers/video/gbefb.c1
-rw-r--r--drivers/video/geode/Kconfig1
-rw-r--r--drivers/video/geode/gx1fb_core.c1
-rw-r--r--drivers/video/hitfb.c1
-rw-r--r--drivers/video/hpfb.c1
-rw-r--r--drivers/video/i810/i810-i2c.c135
-rw-r--r--drivers/video/i810/i810.h3
-rw-r--r--drivers/video/i810/i810_main.c22
-rw-r--r--drivers/video/i810/i810_regs.h1
-rw-r--r--drivers/video/imsttfb.c1
-rw-r--r--drivers/video/imxfb.c1
-rw-r--r--drivers/video/intelfb/intelfb.h6
-rw-r--r--drivers/video/intelfb/intelfbdrv.c10
-rw-r--r--drivers/video/intelfb/intelfbhw.c5
-rw-r--r--drivers/video/kyro/fbdev.c1
-rw-r--r--drivers/video/leo.c1
-rw-r--r--drivers/video/logo/Kconfig2
-rw-r--r--drivers/video/macfb.c1
-rw-r--r--drivers/video/matrox/matroxfb_DAC1064.c4
-rw-r--r--drivers/video/matrox/matroxfb_accel.c2
-rw-r--r--drivers/video/matrox/matroxfb_base.c29
-rw-r--r--drivers/video/matrox/matroxfb_base.h5
-rw-r--r--drivers/video/matrox/matroxfb_crtc2.c1
-rw-r--r--drivers/video/maxinefb.c1
-rw-r--r--drivers/video/modedb.c84
-rw-r--r--drivers/video/neofb.c1
-rw-r--r--drivers/video/nvidia/nv_local.h2
-rw-r--r--drivers/video/nvidia/nv_of.c64
-rw-r--r--drivers/video/nvidia/nv_proto.h18
-rw-r--r--drivers/video/nvidia/nv_setup.c16
-rw-r--r--drivers/video/nvidia/nvidia.c128
-rw-r--r--drivers/video/offb.c1
-rw-r--r--drivers/video/p9100.c1
-rw-r--r--drivers/video/platinumfb.c1
-rw-r--r--drivers/video/pm2fb.c17
-rw-r--r--drivers/video/pmag-ba-fb.c1
-rw-r--r--drivers/video/pmagb-b-fb.c1
-rw-r--r--drivers/video/pvr2fb.c1
-rw-r--r--drivers/video/pxafb.c1
-rw-r--r--drivers/video/q40fb.c1
-rw-r--r--drivers/video/radeonfb.c1
-rw-r--r--drivers/video/s1d13xxxfb.c1
-rw-r--r--drivers/video/s3c2410fb.c2
-rw-r--r--drivers/video/sa1100fb.c1
-rw-r--r--drivers/video/savage/savagefb.h206
-rw-r--r--drivers/video/savage/savagefb_driver.c840
-rw-r--r--drivers/video/sgivwfb.c1
-rw-r--r--drivers/video/sis/sis_main.c2
-rw-r--r--drivers/video/skeletonfb.c9
-rw-r--r--drivers/video/sstfb.c1
-rw-r--r--drivers/video/stifb.c1
-rw-r--r--drivers/video/tcx.c1
-rw-r--r--drivers/video/tdfxfb.c1
-rw-r--r--drivers/video/tgafb.c1
-rw-r--r--drivers/video/tridentfb.c1
-rw-r--r--drivers/video/tx3912fb.c1
-rw-r--r--drivers/video/valkyriefb.c1
-rw-r--r--drivers/video/vesafb.c59
-rw-r--r--drivers/video/vfb.c1
-rw-r--r--drivers/video/vga16fb.c1
-rw-r--r--drivers/video/w100fb.c1
-rw-r--r--drivers/w1/w1_ds2433.c6
-rw-r--r--fs/9p/error.c1
-rw-r--r--fs/9p/trans_sock.c3
-rw-r--r--fs/9p/v9fs.c6
-rw-r--r--fs/9p/vfs_inode.c10
-rw-r--r--fs/Kconfig24
-rw-r--r--fs/Makefile2
-rw-r--r--fs/affs/file.c18
-rw-r--r--fs/affs/super.c16
-rw-r--r--fs/afs/file.c33
-rw-r--r--fs/afs/inode.c2
-rw-r--r--fs/afs/internal.h1
-rw-r--r--fs/aio.c31
-rw-r--r--fs/autofs/waitq.c6
-rw-r--r--fs/autofs4/inode.c6
-rw-r--r--fs/autofs4/waitq.c6
-rw-r--r--fs/befs/linuxvfs.c20
-rw-r--r--fs/binfmt_elf.c3
-rw-r--r--fs/binfmt_elf_fdpic.c15
-rw-r--r--fs/buffer.c6
-rw-r--r--fs/cifs/asn1.c3
-rw-r--r--fs/cifs/connect.c81
-rw-r--r--fs/cifs/link.c23
-rw-r--r--fs/cifs/misc.c15
-rw-r--r--fs/cifs/xattr.c15
-rw-r--r--fs/compat_ioctl.c3
-rw-r--r--fs/dcache.c10
-rw-r--r--fs/devfs/base.c6
-rw-r--r--fs/dquot.c19
-rw-r--r--fs/exec.c4
-rw-r--r--fs/ext2/acl.c6
-rw-r--r--fs/file_table.c4
-rw-r--r--fs/freevxfs/vxfs_extern.h4
-rw-r--r--fs/freevxfs/vxfs_inode.c11
-rw-r--r--fs/fs-writeback.c7
-rw-r--r--fs/fuse/dev.c7
-rw-r--r--fs/fuse/dir.c172
-rw-r--r--fs/fuse/file.c132
-rw-r--r--fs/fuse/fuse_i.h17
-rw-r--r--fs/hostfs/hostfs_kern.c3
-rw-r--r--fs/hpfs/dnode.c8
-rw-r--r--fs/hpfs/super.c10
-rw-r--r--fs/isofs/inode.c12
-rw-r--r--fs/jbd/commit.c6
-rw-r--r--fs/jbd/recovery.c4
-rw-r--r--fs/jbd/transaction.c9
-rw-r--r--fs/jffs/intrep.c18
-rw-r--r--fs/jffs2/Makefile5
-rw-r--r--fs/jffs2/TODO38
-rw-r--r--fs/jffs2/background.c4
-rw-r--r--fs/jffs2/build.c171
-rw-r--r--fs/jffs2/compr.c40
-rw-r--r--fs/jffs2/compr.h12
-rw-r--r--fs/jffs2/compr_rtime.c32
-rw-r--r--fs/jffs2/compr_rubin.c37
-rw-r--r--fs/jffs2/compr_rubin.h6
-rw-r--r--fs/jffs2/compr_zlib.c14
-rw-r--r--fs/jffs2/comprtest.c30
-rw-r--r--fs/jffs2/debug.c705
-rw-r--r--fs/jffs2/debug.h279
-rw-r--r--fs/jffs2/dir.c121
-rw-r--r--fs/jffs2/erase.c37
-rw-r--r--fs/jffs2/file.c29
-rw-r--r--fs/jffs2/fs.c104
-rw-r--r--fs/jffs2/gc.c156
-rw-r--r--fs/jffs2/histo.h2
-rw-r--r--fs/jffs2/histo_mips.h2
-rw-r--r--fs/jffs2/ioctl.c6
-rw-r--r--fs/jffs2/malloc.c84
-rw-r--r--fs/jffs2/nodelist.c1226
-rw-r--r--fs/jffs2/nodelist.h163
-rw-r--r--fs/jffs2/nodemgmt.c471
-rw-r--r--fs/jffs2/os-linux.h47
-rw-r--r--fs/jffs2/read.c17
-rw-r--r--fs/jffs2/readinode.c1153
-rw-r--r--fs/jffs2/scan.c300
-rw-r--r--fs/jffs2/summary.c730
-rw-r--r--fs/jffs2/summary.h183
-rw-r--r--fs/jffs2/super.c24
-rw-r--r--fs/jffs2/symlink.c32
-rw-r--r--fs/jffs2/wbuf.c215
-rw-r--r--fs/jffs2/write.c157
-rw-r--r--fs/jffs2/writev.c35
-rw-r--r--fs/lockd/clntproc.c3
-rw-r--r--fs/mbcache.c3
-rw-r--r--fs/namei.c2
-rw-r--r--fs/namespace.c697
-rw-r--r--fs/nfs/delegation.c3
-rw-r--r--fs/nfs/inode.c15
-rw-r--r--fs/nfs/nfs4state.c9
-rw-r--r--fs/nfs/unlink.c3
-rw-r--r--fs/nfsd/export.c6
-rw-r--r--fs/nfsd/nfs3xdr.c3
-rw-r--r--fs/nfsd/nfs4xdr.c9
-rw-r--r--fs/nfsd/nfscache.c3
-rw-r--r--fs/nfsd/nfsctl.c98
-rw-r--r--fs/nfsd/nfssvc.c80
-rw-r--r--fs/nfsd/vfs.c9
-rw-r--r--fs/open.c19
-rw-r--r--fs/openpromfs/inode.c3
-rw-r--r--fs/partitions/ibm.c15
-rw-r--r--fs/pnode.c305
-rw-r--r--fs/pnode.h37
-rw-r--r--fs/proc/base.c62
-rw-r--r--fs/quota.c1
-rw-r--r--fs/seq_file.c12
-rw-r--r--fs/smbfs/request.c3
-rw-r--r--fs/smbfs/symlink.c4
-rw-r--r--fs/super.c3
-rw-r--r--fs/udf/udf_sb.h3
-rw-r--r--fs/ufs/super.c14
-rw-r--r--fs/xattr.c9
-rw-r--r--fs/xfs/linux-2.6/kmem.h4
-rw-r--r--include/asm-alpha/pgtable.h3
-rw-r--r--include/asm-alpha/ptrace.h3
-rw-r--r--include/asm-arm/arch-realview/entry-macro.S14
-rw-r--r--include/asm-arm/arch-realview/platform.h56
-rw-r--r--include/asm-arm/arch-realview/smp.h31
-rw-r--r--include/asm-arm/hardware/arm_scu.h13
-rw-r--r--include/asm-cris/arch-v10/byteorder.h4
-rw-r--r--include/asm-cris/arch-v10/checksum.h2
-rw-r--r--include/asm-cris/arch-v10/delay.h2
-rw-r--r--include/asm-cris/arch-v10/ide.h8
-rw-r--r--include/asm-cris/arch-v10/system.h8
-rw-r--r--include/asm-cris/arch-v10/thread_info.h2
-rw-r--r--include/asm-cris/arch-v10/timex.h2
-rw-r--r--include/asm-cris/arch-v10/uaccess.h4
-rw-r--r--include/asm-cris/arch-v32/bitops.h10
-rw-r--r--include/asm-cris/arch-v32/byteorder.h4
-rw-r--r--include/asm-cris/arch-v32/checksum.h2
-rw-r--r--include/asm-cris/arch-v32/delay.h2
-rw-r--r--include/asm-cris/arch-v32/ide.h4
-rw-r--r--include/asm-cris/arch-v32/io.h6
-rw-r--r--include/asm-cris/arch-v32/system.h6
-rw-r--r--include/asm-cris/arch-v32/thread_info.h2
-rw-r--r--include/asm-cris/arch-v32/timex.h2
-rw-r--r--include/asm-cris/arch-v32/uaccess.h4
-rw-r--r--include/asm-cris/atomic.h22
-rw-r--r--include/asm-cris/bitops.h18
-rw-r--r--include/asm-cris/checksum.h8
-rw-r--r--include/asm-cris/current.h2
-rw-r--r--include/asm-cris/delay.h2
-rw-r--r--include/asm-cris/io.h6
-rw-r--r--include/asm-cris/irq.h2
-rw-r--r--include/asm-cris/pgalloc.h12
-rw-r--r--include/asm-cris/pgtable.h46
-rw-r--r--include/asm-cris/processor.h6
-rw-r--r--include/asm-cris/semaphore.h16
-rw-r--r--include/asm-cris/system.h2
-rw-r--r--include/asm-cris/timex.h2
-rw-r--r--include/asm-cris/tlbflush.h4
-rw-r--r--include/asm-cris/uaccess.h22
-rw-r--r--include/asm-cris/unistd.h20
-rw-r--r--include/asm-frv/pgtable.h2
-rw-r--r--include/asm-generic/pgtable.h1
-rw-r--r--include/asm-generic/vmlinux.lds.h7
-rw-r--r--include/asm-i386/elf.h2
-rw-r--r--include/asm-i386/kprobes.h17
-rw-r--r--include/asm-i386/pgtable.h3
-rw-r--r--include/asm-i386/processor.h6
-rw-r--r--include/asm-ia64/dma-mapping.h7
-rw-r--r--include/asm-ia64/kprobes.h13
-rw-r--r--include/asm-ia64/page.h1
-rw-r--r--include/asm-ia64/pgtable.h1
-rw-r--r--include/asm-ia64/ptrace.h3
-rw-r--r--include/asm-m32r/pgtable.h3
-rw-r--r--include/asm-m32r/ptrace.h3
-rw-r--r--include/asm-m68k/kbio.h1
-rw-r--r--include/asm-m68k/vuid_event.h4
-rw-r--r--include/asm-m68knommu/cacheflush.h4
-rw-r--r--include/asm-m68knommu/irq.h31
-rw-r--r--include/asm-m68knommu/irqnode.h36
-rw-r--r--include/asm-mips/.gitignore1
-rw-r--r--include/asm-mips/delay.h9
-rw-r--r--include/asm-mips/elf.h2
-rw-r--r--include/asm-mips/errno.h4
-rw-r--r--include/asm-mips/ip32/mace.h26
-rw-r--r--include/asm-mips/mach-generic/ide.h4
-rw-r--r--include/asm-mips/mc146818-time.h24
-rw-r--r--include/asm-mips/module.h38
-rw-r--r--include/asm-mips/pgtable.h3
-rw-r--r--include/asm-mips/rtc.h7
-rw-r--r--include/asm-mips/rtlx.h28
-rw-r--r--include/asm-mips/time.h3
-rw-r--r--include/asm-parisc/pgtable.h3
-rw-r--r--include/asm-powerpc/elf.h2
-rw-r--r--include/asm-powerpc/kprobes.h15
-rw-r--r--include/asm-ppc/ibm44x.h76
-rw-r--r--include/asm-ppc/ibm4xx.h4
-rw-r--r--include/asm-ppc/ibm_ocp.h19
-rw-r--r--include/asm-ppc/pgtable.h1
-rw-r--r--include/asm-ppc/ppcboot.h6
-rw-r--r--include/asm-ppc/rio.h18
-rw-r--r--include/asm-ppc64/pgtable-4k.h3
-rw-r--r--include/asm-ppc64/pgtable-64k.h3
-rw-r--r--include/asm-ppc64/pgtable.h1
-rw-r--r--include/asm-s390/bitops.h4
-rw-r--r--include/asm-s390/elf.h1
-rw-r--r--include/asm-s390/pgtable.h1
-rw-r--r--include/asm-s390/ptrace.h2
-rw-r--r--include/asm-s390/uaccess.h28
-rw-r--r--include/asm-s390/vtoc.h505
-rw-r--r--include/asm-sh/elf.h1
-rw-r--r--include/asm-sh/mmzone.h61
-rw-r--r--include/asm-sh/page.h7
-rw-r--r--include/asm-sh/pgtable.h4
-rw-r--r--include/asm-sh64/pgtable.h2
-rw-r--r--include/asm-sparc/audioio.h234
-rw-r--r--include/asm-sparc/kbio.h56
-rw-r--r--include/asm-sparc/ptrace.h3
-rw-r--r--include/asm-sparc/termios.h9
-rw-r--r--include/asm-sparc/vuid_event.h41
-rw-r--r--include/asm-sparc64/audioio.h234
-rw-r--r--include/asm-sparc64/ebus.h1
-rw-r--r--include/asm-sparc64/kbio.h56
-rw-r--r--include/asm-sparc64/kprobes.h20
-rw-r--r--include/asm-sparc64/mmu_context.h46
-rw-r--r--include/asm-sparc64/ptrace.h3
-rw-r--r--include/asm-sparc64/termios.h9
-rw-r--r--include/asm-sparc64/tlb.h14
-rw-r--r--include/asm-sparc64/vuid_event.h40
-rw-r--r--include/asm-um/ldt-i386.h69
-rw-r--r--include/asm-um/ldt.h69
-rw-r--r--include/asm-um/mmu_context.h3
-rw-r--r--include/asm-v850/atomic.h2
-rw-r--r--include/asm-v850/bitops.h6
-rw-r--r--include/asm-v850/delay.h4
-rw-r--r--include/asm-v850/hw_irq.h2
-rw-r--r--include/asm-v850/processor.h4
-rw-r--r--include/asm-v850/semaphore.h10
-rw-r--r--include/asm-v850/system.h2
-rw-r--r--include/asm-v850/tlbflush.h4
-rw-r--r--include/asm-v850/uaccess.h2
-rw-r--r--include/asm-v850/unaligned.h6
-rw-r--r--include/asm-x86_64/elf.h2
-rw-r--r--include/asm-x86_64/kprobes.h19
-rw-r--r--include/asm-x86_64/pgtable.h2
-rw-r--r--include/asm-xtensa/elf.h2
-rw-r--r--include/asm-xtensa/pgtable.h3
-rw-r--r--include/asm-xtensa/semaphore.h1
-rw-r--r--include/linux/acct.h3
-rw-r--r--include/linux/aio.h5
-rw-r--r--include/linux/cn_proc.h127
-rw-r--r--include/linux/connector.h6
-rw-r--r--include/linux/console_struct.h2
-rw-r--r--include/linux/dcache.h1
-rw-r--r--include/linux/fb.h5
-rw-r--r--include/linux/file.h6
-rw-r--r--include/linux/font.h2
-rw-r--r--include/linux/fs.h21
-rw-r--r--include/linux/fuse.h29
-rw-r--r--include/linux/input.h2
-rw-r--r--include/linux/ioport.h2
-rw-r--r--include/linux/ipmi.h5
-rw-r--r--include/linux/irq.h1
-rw-r--r--include/linux/jbd.h3
-rw-r--r--include/linux/jffs2.h41
-rw-r--r--include/linux/jffs2_fs_i.h7
-rw-r--r--include/linux/jffs2_fs_sb.h19
-rw-r--r--include/linux/kernel.h3
-rw-r--r--include/linux/kernel_stat.h8
-rw-r--r--include/linux/kprobes.h40
-rw-r--r--include/linux/list.h13
-rw-r--r--include/linux/memory.h3
-rw-r--r--include/linux/mm.h8
-rw-r--r--include/linux/mount.h29
-rw-r--r--include/linux/mtd/bbm.h122
-rw-r--r--include/linux/mtd/blktrans.h4
-rw-r--r--include/linux/mtd/cfi.h33
-rw-r--r--include/linux/mtd/doc2000.h18
-rw-r--r--include/linux/mtd/flashchip.h14
-rw-r--r--include/linux/mtd/ftl.h6
-rw-r--r--include/linux/mtd/gen_probe.h4
-rw-r--r--include/linux/mtd/jedec.h20
-rw-r--r--include/linux/mtd/map.h14
-rw-r--r--include/linux/mtd/mtd.h36
-rw-r--r--include/linux/mtd/nand.h57
-rw-r--r--include/linux/mtd/onenand.h155
-rw-r--r--include/linux/mtd/onenand_regs.h180
-rw-r--r--include/linux/mtd/partitions.h20
-rw-r--r--include/linux/mtd/physmap.h12
-rw-r--r--include/linux/mtd/pmc551.h12
-rw-r--r--include/linux/mtd/xip.h20
-rw-r--r--include/linux/namespace.h3
-rw-r--r--include/linux/net.h1
-rw-r--r--include/linux/nfsd/nfsd.h2
-rw-r--r--include/linux/nfsd/syscall.h17
-rw-r--r--include/linux/nfsd/xdr3.h2
-rw-r--r--include/linux/pci_ids.h1
-rw-r--r--include/linux/pkt_sched.h50
-rw-r--r--include/linux/pnp.h2
-rw-r--r--include/linux/ptrace.h2
-rw-r--r--include/linux/quota.h1
-rw-r--r--include/linux/quotaops.h12
-rw-r--r--include/linux/radix-tree.h1
-rw-r--r--include/linux/rio.h325
-rw-r--r--include/linux/rio_drv.h469
-rw-r--r--include/linux/rio_ids.h24
-rw-r--r--include/linux/rio_regs.h215
-rw-r--r--include/linux/rslib.h28
-rw-r--r--include/linux/sem.h2
-rw-r--r--include/linux/shm.h1
-rw-r--r--include/linux/skbuff.h38
-rw-r--r--include/linux/slab.h2
-rw-r--r--include/linux/sunrpc/svc.h3
-rw-r--r--include/linux/superhyway.h38
-rw-r--r--include/linux/wait.h1
-rw-r--r--include/mtd/inftl-user.h4
-rw-r--r--include/mtd/mtd-abi.h7
-rw-r--r--include/mtd/nftl-user.h4
-rw-r--r--include/net/inet_ecn.h28
-rw-r--r--include/net/inet_hashtables.h2
-rw-r--r--include/net/red.h325
-rw-r--r--include/sound/ac97_codec.h10
-rw-r--r--include/sound/core.h94
-rw-r--r--include/sound/driver.h17
-rw-r--r--include/sound/emu10k1.h3
-rw-r--r--include/sound/minors.h8
-rw-r--r--include/sound/pcm.h3
-rw-r--r--include/sound/timer.h1
-rw-r--r--include/sound/version.h4
-rw-r--r--init/Kconfig4
-rw-r--r--ipc/mqueue.c2
-rw-r--r--ipc/shm.c10
-rw-r--r--ipc/util.c9
-rw-r--r--kernel/acct.c92
-rw-r--r--kernel/exit.c2
-rw-r--r--kernel/fork.c9
-rw-r--r--kernel/futex.c5
-rw-r--r--kernel/irq/manage.c1
-rw-r--r--kernel/kprobes.c134
-rw-r--r--kernel/module.c1
-rw-r--r--kernel/posix-cpu-timers.c6
-rw-r--r--kernel/power/snapshot.c19
-rw-r--r--kernel/power/swsusp.c45
-rw-r--r--kernel/printk.c1
-rw-r--r--kernel/ptrace.c82
-rw-r--r--kernel/sched.c5
-rw-r--r--kernel/softirq.c3
-rw-r--r--kernel/softlockup.c3
-rw-r--r--kernel/sys.c26
-rw-r--r--kernel/sysctl.c5
-rw-r--r--kernel/workqueue.c2
-rw-r--r--lib/radix-tree.c51
-rw-r--r--lib/reed_solomon/Makefile2
-rw-r--r--lib/reed_solomon/decode_rs.c36
-rw-r--r--lib/reed_solomon/encode_rs.c14
-rw-r--r--lib/reed_solomon/reed_solomon.c64
-rw-r--r--mm/Kconfig2
-rw-r--r--mm/hugetlb.c1
-rw-r--r--mm/mmap.c4
-rw-r--r--mm/nommu.c4
-rw-r--r--mm/page-writeback.c1
-rw-r--r--mm/page_alloc.c1
-rw-r--r--mm/readahead.c31
-rw-r--r--mm/slab.c74
-rw-r--r--mm/swap.c1
-rw-r--r--mm/swap_state.c1
-rw-r--r--mm/swapfile.c2
-rw-r--r--mm/vmalloc.c4
-rw-r--r--net/core/stream.c12
-rw-r--r--net/dccp/ipv4.c32
-rw-r--r--net/ipv4/inet_connection_sock.c14
-rw-r--r--net/ipv4/netfilter/ip_conntrack_helper_pptp.c4
-rw-r--r--net/ipv4/netfilter/ip_conntrack_netlink.c19
-rw-r--r--net/ipv4/netfilter/ip_nat_core.c6
-rw-r--r--net/ipv4/netfilter/ip_nat_helper_pptp.c2
-rw-r--r--net/ipv4/netfilter/ip_nat_proto_gre.c4
-rw-r--r--net/ipv4/netfilter/ip_nat_proto_unknown.c2
-rw-r--r--net/ipv4/netfilter/ipt_CONNMARK.c1
-rw-r--r--net/ipv4/tcp.c1
-rw-r--r--net/ipv4/tcp_ipv4.c2
-rw-r--r--net/ipv6/tcp_ipv6.c15
-rw-r--r--net/netfilter/nf_queue.c2
-rw-r--r--net/netfilter/nfnetlink_log.c6
-rw-r--r--net/netfilter/nfnetlink_queue.c6
-rw-r--r--net/sched/sch_gred.c841
-rw-r--r--net/sched/sch_netem.c122
-rw-r--r--net/sched/sch_red.c418
-rw-r--r--net/sunrpc/svc.c12
-rw-r--r--scripts/kconfig/Makefile2
-rw-r--r--security/keys/key.c3
-rw-r--r--security/keys/keyring.c8
-rw-r--r--security/selinux/ss/policydb.c12
-rw-r--r--sound/Kconfig8
-rw-r--r--sound/core/Kconfig6
-rw-r--r--sound/core/Makefile3
-rw-r--r--sound/core/control.c18
-rw-r--r--sound/core/hwdep.c10
-rw-r--r--sound/core/info.c2
-rw-r--r--sound/core/init.c7
-rw-r--r--sound/core/memory.c216
-rw-r--r--sound/core/misc.c14
-rw-r--r--sound/core/oss/mixer_oss.c62
-rw-r--r--sound/core/oss/pcm_oss.c20
-rw-r--r--sound/core/pcm.c3
-rw-r--r--sound/core/pcm_lib.c5
-rw-r--r--sound/core/pcm_native.c18
-rw-r--r--sound/core/rawmidi.c12
-rw-r--r--sound/core/rtctimer.c24
-rw-r--r--sound/core/seq/seq_instr.c12
-rw-r--r--sound/core/seq/seq_lock.c3
-rw-r--r--sound/core/seq/seq_memory.c3
-rw-r--r--sound/core/seq/seq_midi.c2
-rw-r--r--sound/core/seq/seq_timer.c29
-rw-r--r--sound/core/sound.c24
-rw-r--r--sound/core/timer.c380
-rw-r--r--sound/core/wrappers.c50
-rw-r--r--sound/drivers/mpu401/mpu401_uart.c5
-rw-r--r--sound/drivers/mtpav.c5
-rw-r--r--sound/drivers/opl3/opl3_lib.c10
-rw-r--r--sound/drivers/opl4/opl4_lib.c10
-rw-r--r--sound/drivers/serial-u16550.c5
-rw-r--r--sound/drivers/vx/vx_pcm.c4
-rw-r--r--sound/i2c/cs8427.c17
-rw-r--r--sound/i2c/other/ak4114.c6
-rw-r--r--sound/i2c/other/ak4117.c8
-rw-r--r--sound/i2c/tea6330t.c2
-rw-r--r--sound/isa/ad1816a/ad1816a_lib.c5
-rw-r--r--sound/isa/ad1848/ad1848_lib.c27
-rw-r--r--sound/isa/cs423x/cs4231_lib.c10
-rw-r--r--sound/isa/cs423x/cs4236.c8
-rw-r--r--sound/isa/cs423x/cs4236_lib.c5
-rw-r--r--sound/isa/es1688/es1688_lib.c3
-rw-r--r--sound/isa/es18xx.c49
-rw-r--r--sound/isa/gus/gus_dma.c2
-rw-r--r--sound/isa/gus/gus_io.c94
-rw-r--r--sound/isa/gus/gus_main.c25
-rw-r--r--sound/isa/gus/gus_mem.c2
-rw-r--r--sound/isa/gus/gus_pcm.c5
-rw-r--r--sound/isa/gus/gus_reset.c4
-rw-r--r--sound/isa/gus/gus_simple.c2
-rw-r--r--sound/isa/gus/gus_uart.c4
-rw-r--r--sound/isa/gus/gus_volume.c6
-rw-r--r--sound/isa/gus/interwave.c9
-rw-r--r--sound/isa/opl3sa2.c5
-rw-r--r--sound/isa/opti9xx/opti92x-ad1848.c25
-rw-r--r--sound/isa/sb/emu8000.c24
-rw-r--r--sound/isa/sb/emu8000_patch.c3
-rw-r--r--sound/isa/sb/emu8000_pcm.c3
-rw-r--r--sound/isa/sb/emu8000_synth.c2
-rw-r--r--sound/isa/sb/sb16.c5
-rw-r--r--sound/isa/sb/sb16_main.c8
-rw-r--r--sound/isa/sb/sb8.c5
-rw-r--r--sound/isa/sb/sb8_main.c3
-rw-r--r--sound/isa/sb/sb_common.c12
-rw-r--r--sound/isa/sb/sb_mixer.c4
-rw-r--r--sound/isa/sscape.c23
-rw-r--r--sound/isa/wavefront/wavefront.c5
-rw-r--r--sound/isa/wavefront/wavefront_synth.c6
-rw-r--r--sound/mips/au1x00.c13
-rw-r--r--sound/oss/au1000.c6
-rw-r--r--sound/oss/dmasound/dmasound_awacs.c31
-rw-r--r--sound/oss/nec_vrc5477.c6
-rw-r--r--sound/oss/sequencer_syms.c1
-rw-r--r--sound/pci/Kconfig9
-rw-r--r--sound/pci/ac97/ac97_codec.c56
-rw-r--r--sound/pci/ac97/ac97_patch.c80
-rw-r--r--sound/pci/ac97/ac97_pcm.c9
-rw-r--r--sound/pci/ad1889.c5
-rw-r--r--sound/pci/ali5451/ali5451.c92
-rw-r--r--sound/pci/als4000.c8
-rw-r--r--sound/pci/atiixp.c50
-rw-r--r--sound/pci/atiixp_modem.c37
-rw-r--r--sound/pci/au88x0/au8810.h5
-rw-r--r--sound/pci/au88x0/au8820.h5
-rw-r--r--sound/pci/au88x0/au8830.h5
-rw-r--r--sound/pci/au88x0/au88x0.c2
-rw-r--r--sound/pci/au88x0/au88x0.h8
-rw-r--r--sound/pci/au88x0/au88x0_a3d.c2
-rw-r--r--sound/pci/au88x0/au88x0_core.c10
-rw-r--r--sound/pci/au88x0/au88x0_eq.c2
-rw-r--r--sound/pci/au88x0/au88x0_synth.c8
-rw-r--r--sound/pci/azt3328.c1005
-rw-r--r--sound/pci/azt3328.h135
-rw-r--r--sound/pci/ca0106/Makefile2
-rw-r--r--sound/pci/ca0106/ca0106.h27
-rw-r--r--sound/pci/ca0106/ca0106_main.c123
-rw-r--r--sound/pci/ca0106/ca_midi.c306
-rw-r--r--sound/pci/ca0106/ca_midi.h69
-rw-r--r--sound/pci/cmipci.c126
-rw-r--r--sound/pci/cs4281.c6
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.c43
-rw-r--r--sound/pci/emu10k1/emu10k1.c2
-rw-r--r--sound/pci/emu10k1/emu10k1_callback.c4
-rw-r--r--sound/pci/emu10k1/emu10k1x.c6
-rw-r--r--sound/pci/emu10k1/emufx.c59
-rw-r--r--sound/pci/emu10k1/emupcm.c3
-rw-r--r--sound/pci/emu10k1/irq.c2
-rw-r--r--sound/pci/emu10k1/memory.c6
-rw-r--r--sound/pci/emu10k1/p16v.c2
-rw-r--r--sound/pci/ens1370.c17
-rw-r--r--sound/pci/es1938.c38
-rw-r--r--sound/pci/es1968.c22
-rw-r--r--sound/pci/fm801.c25
-rw-r--r--sound/pci/hda/hda_codec.c52
-rw-r--r--sound/pci/hda/hda_codec.h2
-rw-r--r--sound/pci/hda/hda_intel.c72
-rw-r--r--sound/pci/hda/hda_local.h22
-rw-r--r--sound/pci/hda/hda_proc.c5
-rw-r--r--sound/pci/hda/patch_analog.c133
-rw-r--r--sound/pci/hda/patch_realtek.c274
-rw-r--r--sound/pci/hda/patch_si3054.c2
-rw-r--r--sound/pci/ice1712/aureon.c6
-rw-r--r--sound/pci/ice1712/delta.c2
-rw-r--r--sound/pci/ice1712/ews.c6
-rw-r--r--sound/pci/ice1712/ice1712.c10
-rw-r--r--sound/pci/ice1712/ice1724.c43
-rw-r--r--sound/pci/ice1712/pontis.c3
-rw-r--r--sound/pci/ice1712/revo.c13
-rw-r--r--sound/pci/ice1712/vt1720_mobo.c20
-rw-r--r--sound/pci/intel8x0.c160
-rw-r--r--sound/pci/intel8x0m.c55
-rw-r--r--sound/pci/maestro3.c21
-rw-r--r--sound/pci/mixart/mixart.c3
-rw-r--r--sound/pci/nm256/nm256.c145
-rw-r--r--sound/pci/rme32.c4
-rw-r--r--sound/pci/rme96.c4
-rw-r--r--sound/pci/rme9652/hdsp.c588
-rw-r--r--sound/pci/rme9652/hdspm.c3
-rw-r--r--sound/pci/rme9652/rme9652.c6
-rw-r--r--sound/pci/sonicvibes.c24
-rw-r--r--sound/pci/trident/trident_main.c18
-rw-r--r--sound/pci/trident/trident_memory.c4
-rw-r--r--sound/pci/via82xx.c375
-rw-r--r--sound/pci/via82xx_modem.c49
-rw-r--r--sound/pci/ymfpci/ymfpci.c18
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c75
-rw-r--r--sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c6
-rw-r--r--sound/ppc/beep.c2
-rw-r--r--sound/ppc/pmac.c16
-rw-r--r--sound/sparc/cs4231.c654
-rw-r--r--sound/sparc/dbri.c5
-rw-r--r--sound/synth/emux/emux_synth.c1
-rw-r--r--sound/usb/usbaudio.c144
-rw-r--r--sound/usb/usbaudio.h8
-rw-r--r--sound/usb/usbmidi.c98
-rw-r--r--sound/usb/usbmixer.c2
-rw-r--r--sound/usb/usbquirks.h40
-rw-r--r--sound/usb/usx2y/usX2Yhwdep.c10
-rw-r--r--sound/usb/usx2y/usbusx2y.c5
-rw-r--r--sound/usb/usx2y/usbusx2yaudio.c23
-rw-r--r--sound/usb/usx2y/usx2yhwdeppcm.c4
1316 files changed, 40941 insertions, 20266 deletions
diff --git a/CREDITS b/CREDITS
index 5b1edf3a38a2..7fb4c73e0228 100644
--- a/CREDITS
+++ b/CREDITS
@@ -3642,11 +3642,9 @@ S: Beaverton, OR 97005
3642S: USA 3642S: USA
3643 3643
3644N: Michal Wronski 3644N: Michal Wronski
3645E: wrona@mat.uni.torun.pl 3645E: Michal.Wronski@motorola.com
3646W: http://www.mat.uni.torun.pl/~wrona
3647D: POSIX message queues fs (with K. Benedyczak) 3646D: POSIX message queues fs (with K. Benedyczak)
3648S: ul. Teczowa 23/12 3647S: Krakow
3649S: 80-680 Gdansk-Sobieszewo
3650S: Poland 3648S: Poland
3651 3649
3652N: Frank Xia 3650N: Frank Xia
diff --git a/Documentation/Changes b/Documentation/Changes
index 783ddc3ce4e8..86b86399d61d 100644
--- a/Documentation/Changes
+++ b/Documentation/Changes
@@ -139,9 +139,14 @@ You'll probably want to upgrade.
139Ksymoops 139Ksymoops
140-------- 140--------
141 141
142If the unthinkable happens and your kernel oopses, you'll need a 2.4 142If the unthinkable happens and your kernel oopses, you may need the
143version of ksymoops to decode the report; see REPORTING-BUGS in the 143ksymoops tool to decode it, but in most cases you don't.
144root of the Linux source for more information. 144In the 2.6 kernel it is generally preferred to build the kernel with
145CONFIG_KALLSYMS so that it produces readable dumps that can be used as-is
146(this also produces better output than ksymoops).
147If for some reason your kernel is not build with CONFIG_KALLSYMS and
148you have no way to rebuild and reproduce the Oops with that option, then
149you can still decode that Oops with ksymoops.
145 150
146Module-Init-Tools 151Module-Init-Tools
147----------------- 152-----------------
diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index fa3e29ad8a46..7018f5c6a447 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -10,7 +10,7 @@ DOCBOOKS := wanbook.xml z8530book.xml mcabook.xml videobook.xml \
10 kernel-hacking.xml kernel-locking.xml deviceiobook.xml \ 10 kernel-hacking.xml kernel-locking.xml deviceiobook.xml \
11 procfs-guide.xml writing_usb_driver.xml \ 11 procfs-guide.xml writing_usb_driver.xml \
12 sis900.xml kernel-api.xml journal-api.xml lsm.xml usb.xml \ 12 sis900.xml kernel-api.xml journal-api.xml lsm.xml usb.xml \
13 gadget.xml libata.xml mtdnand.xml librs.xml 13 gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml
14 14
15### 15###
16# The build process is as follows (targets): 16# The build process is as follows (targets):
diff --git a/Documentation/DocBook/journal-api.tmpl b/Documentation/DocBook/journal-api.tmpl
index 341aaa4ce481..2077f9a28c19 100644
--- a/Documentation/DocBook/journal-api.tmpl
+++ b/Documentation/DocBook/journal-api.tmpl
@@ -306,7 +306,7 @@ an example.
306</para> 306</para>
307 <sect1><title>Journal Level</title> 307 <sect1><title>Journal Level</title>
308!Efs/jbd/journal.c 308!Efs/jbd/journal.c
309!Efs/jbd/recovery.c 309!Ifs/jbd/recovery.c
310 </sect1> 310 </sect1>
311 <sect1><title>Transasction Level</title> 311 <sect1><title>Transasction Level</title>
312!Efs/jbd/transaction.c 312!Efs/jbd/transaction.c
diff --git a/Documentation/DocBook/kernel-api.tmpl b/Documentation/DocBook/kernel-api.tmpl
index ec474e5a25ed..a8316b1a3e3d 100644
--- a/Documentation/DocBook/kernel-api.tmpl
+++ b/Documentation/DocBook/kernel-api.tmpl
@@ -118,7 +118,7 @@ X!Ilib/string.c
118 </sect1> 118 </sect1>
119 <sect1><title>User Space Memory Access</title> 119 <sect1><title>User Space Memory Access</title>
120!Iinclude/asm-i386/uaccess.h 120!Iinclude/asm-i386/uaccess.h
121!Iarch/i386/lib/usercopy.c 121!Earch/i386/lib/usercopy.c
122 </sect1> 122 </sect1>
123 <sect1><title>More Memory Management Functions</title> 123 <sect1><title>More Memory Management Functions</title>
124!Iinclude/linux/rmap.h 124!Iinclude/linux/rmap.h
@@ -174,7 +174,6 @@ X!Ilib/string.c
174 <title>The Linux VFS</title> 174 <title>The Linux VFS</title>
175 <sect1><title>The Filesystem types</title> 175 <sect1><title>The Filesystem types</title>
176!Iinclude/linux/fs.h 176!Iinclude/linux/fs.h
177!Einclude/linux/fs.h
178 </sect1> 177 </sect1>
179 <sect1><title>The Directory Cache</title> 178 <sect1><title>The Directory Cache</title>
180!Efs/dcache.c 179!Efs/dcache.c
@@ -266,7 +265,7 @@ X!Ekernel/module.c
266 <chapter id="hardware"> 265 <chapter id="hardware">
267 <title>Hardware Interfaces</title> 266 <title>Hardware Interfaces</title>
268 <sect1><title>Interrupt Handling</title> 267 <sect1><title>Interrupt Handling</title>
269!Ikernel/irq/manage.c 268!Ekernel/irq/manage.c
270 </sect1> 269 </sect1>
271 270
272 <sect1><title>Resources Management</title> 271 <sect1><title>Resources Management</title>
@@ -501,7 +500,7 @@ KAO -->
501!Edrivers/video/modedb.c 500!Edrivers/video/modedb.c
502 </sect1> 501 </sect1>
503 <sect1><title>Frame Buffer Macintosh Video Mode Database</title> 502 <sect1><title>Frame Buffer Macintosh Video Mode Database</title>
504!Idrivers/video/macmodes.c 503!Edrivers/video/macmodes.c
505 </sect1> 504 </sect1>
506 <sect1><title>Frame Buffer Fonts</title> 505 <sect1><title>Frame Buffer Fonts</title>
507 <para> 506 <para>
diff --git a/Documentation/DocBook/rapidio.tmpl b/Documentation/DocBook/rapidio.tmpl
new file mode 100644
index 000000000000..1becf27ba27e
--- /dev/null
+++ b/Documentation/DocBook/rapidio.tmpl
@@ -0,0 +1,160 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
4 <!ENTITY rapidio SYSTEM "rapidio.xml">
5 ]>
6
7<book id="RapidIO-Guide">
8 <bookinfo>
9 <title>RapidIO Subsystem Guide</title>
10
11 <authorgroup>
12 <author>
13 <firstname>Matt</firstname>
14 <surname>Porter</surname>
15 <affiliation>
16 <address>
17 <email>mporter@kernel.crashing.org</email>
18 <email>mporter@mvista.com</email>
19 </address>
20 </affiliation>
21 </author>
22 </authorgroup>
23
24 <copyright>
25 <year>2005</year>
26 <holder>MontaVista Software, Inc.</holder>
27 </copyright>
28
29 <legalnotice>
30 <para>
31 This documentation is free software; you can redistribute
32 it and/or modify it under the terms of the GNU General Public
33 License version 2 as published by the Free Software Foundation.
34 </para>
35
36 <para>
37 This program is distributed in the hope that it will be
38 useful, but WITHOUT ANY WARRANTY; without even the implied
39 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
40 See the GNU General Public License for more details.
41 </para>
42
43 <para>
44 You should have received a copy of the GNU General Public
45 License along with this program; if not, write to the Free
46 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
47 MA 02111-1307 USA
48 </para>
49
50 <para>
51 For more details see the file COPYING in the source
52 distribution of Linux.
53 </para>
54 </legalnotice>
55 </bookinfo>
56
57<toc></toc>
58
59 <chapter id="intro">
60 <title>Introduction</title>
61 <para>
62 RapidIO is a high speed switched fabric interconnect with
63 features aimed at the embedded market. RapidIO provides
64 support for memory-mapped I/O as well as message-based
65 transactions over the switched fabric network. RapidIO has
66 a standardized discovery mechanism not unlike the PCI bus
67 standard that allows simple detection of devices in a
68 network.
69 </para>
70 <para>
71 This documentation is provided for developers intending
72 to support RapidIO on new architectures, write new drivers,
73 or to understand the subsystem internals.
74 </para>
75 </chapter>
76
77 <chapter id="bugs">
78 <title>Known Bugs and Limitations</title>
79
80 <sect1>
81 <title>Bugs</title>
82 <para>None. ;)</para>
83 </sect1>
84 <sect1>
85 <title>Limitations</title>
86 <para>
87 <orderedlist>
88 <listitem><para>Access/management of RapidIO memory regions is not supported</para></listitem>
89 <listitem><para>Multiple host enumeration is not supported</para></listitem>
90 </orderedlist>
91 </para>
92 </sect1>
93 </chapter>
94
95 <chapter id="drivers">
96 <title>RapidIO driver interface</title>
97 <para>
98 Drivers are provided a set of calls in order
99 to interface with the subsystem to gather info
100 on devices, request/map memory region resources,
101 and manage mailboxes/doorbells.
102 </para>
103 <sect1>
104 <title>Functions</title>
105!Iinclude/linux/rio_drv.h
106!Edrivers/rapidio/rio-driver.c
107!Edrivers/rapidio/rio.c
108 </sect1>
109 </chapter>
110
111 <chapter id="internals">
112 <title>Internals</title>
113
114 <para>
115 This chapter contains the autogenerated documentation of the RapidIO
116 subsystem.
117 </para>
118
119 <sect1><title>Structures</title>
120!Iinclude/linux/rio.h
121 </sect1>
122 <sect1><title>Enumeration and Discovery</title>
123!Idrivers/rapidio/rio-scan.c
124 </sect1>
125 <sect1><title>Driver functionality</title>
126!Idrivers/rapidio/rio.c
127!Idrivers/rapidio/rio-access.c
128 </sect1>
129 <sect1><title>Device model support</title>
130!Idrivers/rapidio/rio-driver.c
131 </sect1>
132 <sect1><title>Sysfs support</title>
133!Idrivers/rapidio/rio-sysfs.c
134 </sect1>
135 <sect1><title>PPC32 support</title>
136!Iarch/ppc/kernel/rio.c
137!Earch/ppc/syslib/ppc85xx_rio.c
138!Iarch/ppc/syslib/ppc85xx_rio.c
139 </sect1>
140 </chapter>
141
142 <chapter id="credits">
143 <title>Credits</title>
144 <para>
145 The following people have contributed to the RapidIO
146 subsystem directly or indirectly:
147 <orderedlist>
148 <listitem><para>Matt Porter<email>mporter@kernel.crashing.org</email></para></listitem>
149 <listitem><para>Randy Vinson<email>rvinson@mvista.com</email></para></listitem>
150 <listitem><para>Dan Malek<email>dan@embeddedalley.com</email></para></listitem>
151 </orderedlist>
152 </para>
153 <para>
154 The following people have contributed to this document:
155 <orderedlist>
156 <listitem><para>Matt Porter<email>mporter@kernel.crashing.org</email></para></listitem>
157 </orderedlist>
158 </para>
159 </chapter>
160</book>
diff --git a/Documentation/MSI-HOWTO.txt b/Documentation/MSI-HOWTO.txt
index 63edc5f847c4..3ec6c720b016 100644
--- a/Documentation/MSI-HOWTO.txt
+++ b/Documentation/MSI-HOWTO.txt
@@ -10,14 +10,22 @@
10This guide describes the basics of Message Signaled Interrupts (MSI), 10This guide describes the basics of Message Signaled Interrupts (MSI),
11the advantages of using MSI over traditional interrupt mechanisms, 11the advantages of using MSI over traditional interrupt mechanisms,
12and how to enable your driver to use MSI or MSI-X. Also included is 12and how to enable your driver to use MSI or MSI-X. Also included is
13a Frequently Asked Questions. 13a Frequently Asked Questions (FAQ) section.
14
151.1 Terminology
16
17PCI devices can be single-function or multi-function. In either case,
18when this text talks about enabling or disabling MSI on a "device
19function," it is referring to one specific PCI device and function and
20not to all functions on a PCI device (unless the PCI device has only
21one function).
14 22
152. Copyright 2003 Intel Corporation 232. Copyright 2003 Intel Corporation
16 24
173. What is MSI/MSI-X? 253. What is MSI/MSI-X?
18 26
19Message Signaled Interrupt (MSI), as described in the PCI Local Bus 27Message Signaled Interrupt (MSI), as described in the PCI Local Bus
20Specification Revision 2.3 or latest, is an optional feature, and a 28Specification Revision 2.3 or later, is an optional feature, and a
21required feature for PCI Express devices. MSI enables a device function 29required feature for PCI Express devices. MSI enables a device function
22to request service by sending an Inbound Memory Write on its PCI bus to 30to request service by sending an Inbound Memory Write on its PCI bus to
23the FSB as a Message Signal Interrupt transaction. Because MSI is 31the FSB as a Message Signal Interrupt transaction. Because MSI is
@@ -27,7 +35,7 @@ supported.
27 35
28A PCI device that supports MSI must also support pin IRQ assertion 36A PCI device that supports MSI must also support pin IRQ assertion
29interrupt mechanism to provide backward compatibility for systems that 37interrupt mechanism to provide backward compatibility for systems that
30do not support MSI. In Systems, which support MSI, the bus driver is 38do not support MSI. In systems which support MSI, the bus driver is
31responsible for initializing the message address and message data of 39responsible for initializing the message address and message data of
32the device function's MSI/MSI-X capability structure during device 40the device function's MSI/MSI-X capability structure during device
33initial configuration. 41initial configuration.
@@ -61,17 +69,17 @@ over the MSI capability structure as described below.
61 69
62 - MSI and MSI-X both support per-vector masking. Per-vector 70 - MSI and MSI-X both support per-vector masking. Per-vector
63 masking is an optional extension of MSI but a required 71 masking is an optional extension of MSI but a required
64 feature for MSI-X. Per-vector masking provides the kernel 72 feature for MSI-X. Per-vector masking provides the kernel the
65 the ability to mask/unmask MSI when servicing its software 73 ability to mask/unmask a single MSI while running its
66 interrupt service routing handler. If per-vector masking is 74 interrupt service routine. If per-vector masking is
67 not supported, then the device driver should provide the 75 not supported, then the device driver should provide the
68 hardware/software synchronization to ensure that the device 76 hardware/software synchronization to ensure that the device
69 generates MSI when the driver wants it to do so. 77 generates MSI when the driver wants it to do so.
70 78
714. Why use MSI? 794. Why use MSI?
72 80
73As a benefit the simplification of board design, MSI allows board 81As a benefit to the simplification of board design, MSI allows board
74designers to remove out of band interrupt routing. MSI is another 82designers to remove out-of-band interrupt routing. MSI is another
75step towards a legacy-free environment. 83step towards a legacy-free environment.
76 84
77Due to increasing pressure on chipset and processor packages to 85Due to increasing pressure on chipset and processor packages to
@@ -87,7 +95,7 @@ support. As a result, the PCI Express technology requires MSI
87support for better interrupt performance. 95support for better interrupt performance.
88 96
89Using MSI enables the device functions to support two or more 97Using MSI enables the device functions to support two or more
90vectors, which can be configured to target different CPU's to 98vectors, which can be configured to target different CPUs to
91increase scalability. 99increase scalability.
92 100
935. Configuring a driver to use MSI/MSI-X 1015. Configuring a driver to use MSI/MSI-X
@@ -119,13 +127,13 @@ pci_enable_msi() explicitly.
119 127
120int pci_enable_msi(struct pci_dev *dev) 128int pci_enable_msi(struct pci_dev *dev)
121 129
122With this new API, any existing device driver, which like to have 130With this new API, a device driver that wants to have MSI
123MSI enabled on its device function, must call this API to enable MSI 131enabled on its device function must call this API to enable MSI.
124A successful call will initialize the MSI capability structure 132A successful call will initialize the MSI capability structure
125with ONE vector, regardless of whether a device function is 133with ONE vector, regardless of whether a device function is
126capable of supporting multiple messages. This vector replaces the 134capable of supporting multiple messages. This vector replaces the
127pre-assigned dev->irq with a new MSI vector. To avoid the conflict 135pre-assigned dev->irq with a new MSI vector. To avoid a conflict
128of new assigned vector with existing pre-assigned vector requires 136of the new assigned vector with existing pre-assigned vector requires
129a device driver to call this API before calling request_irq(). 137a device driver to call this API before calling request_irq().
130 138
1315.2.2 API pci_disable_msi 1395.2.2 API pci_disable_msi
@@ -137,14 +145,14 @@ when a device driver is unloading. This API restores dev->irq with
137the pre-assigned IOAPIC vector and switches a device's interrupt 145the pre-assigned IOAPIC vector and switches a device's interrupt
138mode to PCI pin-irq assertion/INTx emulation mode. 146mode to PCI pin-irq assertion/INTx emulation mode.
139 147
140Note that a device driver should always call free_irq() on MSI vector 148Note that a device driver should always call free_irq() on the MSI vector
141it has done request_irq() on before calling this API. Failure to do 149that it has done request_irq() on before calling this API. Failure to do
142so results a BUG_ON() and a device will be left with MSI enabled and 150so results in a BUG_ON() and a device will be left with MSI enabled and
143leaks its vector. 151leaks its vector.
144 152
1455.2.3 MSI mode vs. legacy mode diagram 1535.2.3 MSI mode vs. legacy mode diagram
146 154
147The below diagram shows the events, which switches the interrupt 155The below diagram shows the events which switch the interrupt
148mode on the MSI-capable device function between MSI mode and 156mode on the MSI-capable device function between MSI mode and
149PIN-IRQ assertion mode. 157PIN-IRQ assertion mode.
150 158
@@ -155,9 +163,9 @@ PIN-IRQ assertion mode.
155 ------------ pci_disable_msi ------------------------ 163 ------------ pci_disable_msi ------------------------
156 164
157 165
158Figure 1.0 MSI Mode vs. Legacy Mode 166Figure 1. MSI Mode vs. Legacy Mode
159 167
160In Figure 1.0, a device operates by default in legacy mode. Legacy 168In Figure 1, a device operates by default in legacy mode. Legacy
161in this context means PCI pin-irq assertion or PCI-Express INTx 169in this context means PCI pin-irq assertion or PCI-Express INTx
162emulation. A successful MSI request (using pci_enable_msi()) switches 170emulation. A successful MSI request (using pci_enable_msi()) switches
163a device's interrupt mode to MSI mode. A pre-assigned IOAPIC vector 171a device's interrupt mode to MSI mode. A pre-assigned IOAPIC vector
@@ -166,11 +174,11 @@ assigned MSI vector will replace dev->irq.
166 174
167To return back to its default mode, a device driver should always call 175To return back to its default mode, a device driver should always call
168pci_disable_msi() to undo the effect of pci_enable_msi(). Note that a 176pci_disable_msi() to undo the effect of pci_enable_msi(). Note that a
169device driver should always call free_irq() on MSI vector it has done 177device driver should always call free_irq() on the MSI vector it has
170request_irq() on before calling pci_disable_msi(). Failure to do so 178done request_irq() on before calling pci_disable_msi(). Failure to do
171results a BUG_ON() and a device will be left with MSI enabled and 179so results in a BUG_ON() and a device will be left with MSI enabled and
172leaks its vector. Otherwise, the PCI subsystem restores a device's 180leaks its vector. Otherwise, the PCI subsystem restores a device's
173dev->irq with a pre-assigned IOAPIC vector and marks released 181dev->irq with a pre-assigned IOAPIC vector and marks the released
174MSI vector as unused. 182MSI vector as unused.
175 183
176Once being marked as unused, there is no guarantee that the PCI 184Once being marked as unused, there is no guarantee that the PCI
@@ -178,8 +186,8 @@ subsystem will reserve this MSI vector for a device. Depending on
178the availability of current PCI vector resources and the number of 186the availability of current PCI vector resources and the number of
179MSI/MSI-X requests from other drivers, this MSI may be re-assigned. 187MSI/MSI-X requests from other drivers, this MSI may be re-assigned.
180 188
181For the case where the PCI subsystem re-assigned this MSI vector 189For the case where the PCI subsystem re-assigns this MSI vector to
182another driver, a request to switching back to MSI mode may result 190another driver, a request to switch back to MSI mode may result
183in being assigned a different MSI vector or a failure if no more 191in being assigned a different MSI vector or a failure if no more
184vectors are available. 192vectors are available.
185 193
@@ -208,12 +216,12 @@ Unlike the function pci_enable_msi(), the function pci_enable_msix()
208does not replace the pre-assigned IOAPIC dev->irq with a new MSI 216does not replace the pre-assigned IOAPIC dev->irq with a new MSI
209vector because the PCI subsystem writes the 1:1 vector-to-entry mapping 217vector because the PCI subsystem writes the 1:1 vector-to-entry mapping
210into the field vector of each element contained in a second argument. 218into the field vector of each element contained in a second argument.
211Note that the pre-assigned IO-APIC dev->irq is valid only if the device 219Note that the pre-assigned IOAPIC dev->irq is valid only if the device
212operates in PIN-IRQ assertion mode. In MSI-X mode, any attempt of 220operates in PIN-IRQ assertion mode. In MSI-X mode, any attempt at
213using dev->irq by the device driver to request for interrupt service 221using dev->irq by the device driver to request for interrupt service
214may result unpredictabe behavior. 222may result unpredictabe behavior.
215 223
216For each MSI-X vector granted, a device driver is responsible to call 224For each MSI-X vector granted, a device driver is responsible for calling
217other functions like request_irq(), enable_irq(), etc. to enable 225other functions like request_irq(), enable_irq(), etc. to enable
218this vector with its corresponding interrupt service handler. It is 226this vector with its corresponding interrupt service handler. It is
219a device driver's choice to assign all vectors with the same 227a device driver's choice to assign all vectors with the same
@@ -224,13 +232,13 @@ service handler.
224 232
225The PCI 3.0 specification has implementation notes that MMIO address 233The PCI 3.0 specification has implementation notes that MMIO address
226space for a device's MSI-X structure should be isolated so that the 234space for a device's MSI-X structure should be isolated so that the
227software system can set different page for controlling accesses to 235software system can set different pages for controlling accesses to the
228the MSI-X structure. The implementation of MSI patch requires the PCI 236MSI-X structure. The implementation of MSI support requires the PCI
229subsystem, not a device driver, to maintain full control of the MSI-X 237subsystem, not a device driver, to maintain full control of the MSI-X
230table/MSI-X PBA and MMIO address space of the MSI-X table/MSI-X PBA. 238table/MSI-X PBA (Pending Bit Array) and MMIO address space of the MSI-X
231A device driver is prohibited from requesting the MMIO address space 239table/MSI-X PBA. A device driver is prohibited from requesting the MMIO
232of the MSI-X table/MSI-X PBA. Otherwise, the PCI subsystem will fail 240address space of the MSI-X table/MSI-X PBA. Otherwise, the PCI subsystem
233enabling MSI-X on its hardware device when it calls the function 241will fail enabling MSI-X on its hardware device when it calls the function
234pci_enable_msix(). 242pci_enable_msix().
235 243
2365.3.2 Handling MSI-X allocation 2445.3.2 Handling MSI-X allocation
@@ -274,9 +282,9 @@ For the case where fewer MSI-X vectors are allocated to a function
274than requested, the function pci_enable_msix() will return the 282than requested, the function pci_enable_msix() will return the
275maximum number of MSI-X vectors available to the caller. A device 283maximum number of MSI-X vectors available to the caller. A device
276driver may re-send its request with fewer or equal vectors indicated 284driver may re-send its request with fewer or equal vectors indicated
277in a return. For example, if a device driver requests 5 vectors, but 285in the return. For example, if a device driver requests 5 vectors, but
278the number of available vectors is 3 vectors, a value of 3 will be a 286the number of available vectors is 3 vectors, a value of 3 will be
279return as a result of pci_enable_msix() call. A function could be 287returned as a result of pci_enable_msix() call. A function could be
280designed for its driver to use only 3 MSI-X table entries as 288designed for its driver to use only 3 MSI-X table entries as
281different combinations as ABC--, A-B-C, A--CB, etc. Note that this 289different combinations as ABC--, A-B-C, A--CB, etc. Note that this
282patch does not support multiple entries with the same vector. Such 290patch does not support multiple entries with the same vector. Such
@@ -285,49 +293,46 @@ as ABBCC, AABCC, BCCBA, etc will result as a failure by the function
285pci_enable_msix(). Below are the reasons why supporting multiple 293pci_enable_msix(). Below are the reasons why supporting multiple
286entries with the same vector is an undesirable solution. 294entries with the same vector is an undesirable solution.
287 295
288 - The PCI subsystem can not determine which entry, which 296 - The PCI subsystem cannot determine the entry that
289 generated the message, to mask/unmask MSI while handling 297 generated the message to mask/unmask MSI while handling
290 software driver ISR. Attempting to walk through all MSI-X 298 software driver ISR. Attempting to walk through all MSI-X
291 table entries (2048 max) to mask/unmask any match vector 299 table entries (2048 max) to mask/unmask any match vector
292 is an undesirable solution. 300 is an undesirable solution.
293 301
294 - Walk through all MSI-X table entries (2048 max) to handle 302 - Walking through all MSI-X table entries (2048 max) to handle
295 SMP affinity of any match vector is an undesirable solution. 303 SMP affinity of any match vector is an undesirable solution.
296 304
2975.3.4 API pci_enable_msix 3055.3.4 API pci_enable_msix
298 306
299int pci_enable_msix(struct pci_dev *dev, u32 *entries, int nvec) 307int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
300 308
301This API enables a device driver to request the PCI subsystem 309This API enables a device driver to request the PCI subsystem
302for enabling MSI-X messages on its hardware device. Depending on 310to enable MSI-X messages on its hardware device. Depending on
303the availability of PCI vectors resources, the PCI subsystem enables 311the availability of PCI vectors resources, the PCI subsystem enables
304either all or nothing. 312either all or none of the requested vectors.
305 313
306Argument dev points to the device (pci_dev) structure. 314Argument 'dev' points to the device (pci_dev) structure.
307 315
308Argument entries is a pointer of unsigned integer type. The number of 316Argument 'entries' is a pointer to an array of msix_entry structs.
309elements is indicated in argument nvec. The content of each element 317The number of entries is indicated in argument 'nvec'.
310will be mapped to the following struct defined in /driver/pci/msi.h. 318struct msix_entry is defined in /driver/pci/msi.h:
311 319
312struct msix_entry { 320struct msix_entry {
313 u16 vector; /* kernel uses to write alloc vector */ 321 u16 vector; /* kernel uses to write alloc vector */
314 u16 entry; /* driver uses to specify entry */ 322 u16 entry; /* driver uses to specify entry */
315}; 323};
316 324
317A device driver is responsible for initializing the field entry of 325A device driver is responsible for initializing the field 'entry' of
318each element with unique entry supported by MSI-X table. Otherwise, 326each element with a unique entry supported by MSI-X table. Otherwise,
319-EINVAL will be returned as a result. A successful return of zero 327-EINVAL will be returned as a result. A successful return of zero
320indicates the PCI subsystem completes initializing each of requested 328indicates the PCI subsystem completed initializing each of the requested
321entries of the MSI-X table with message address and message data. 329entries of the MSI-X table with message address and message data.
322Last but not least, the PCI subsystem will write the 1:1 330Last but not least, the PCI subsystem will write the 1:1
323vector-to-entry mapping into the field vector of each element. A 331vector-to-entry mapping into the field 'vector' of each element. A
324device driver is responsible of keeping track of allocated MSI-X 332device driver is responsible for keeping track of allocated MSI-X
325vectors in its internal data structure. 333vectors in its internal data structure.
326 334
327Argument nvec is an integer indicating the number of messages 335A return of zero indicates that the number of MSI-X vectors was
328requested.
329
330A return of zero indicates that the number of MSI-X vectors is
331successfully allocated. A return of greater than zero indicates 336successfully allocated. A return of greater than zero indicates
332MSI-X vector shortage. Or a return of less than zero indicates 337MSI-X vector shortage. Or a return of less than zero indicates
333a failure. This failure may be a result of duplicate entries 338a failure. This failure may be a result of duplicate entries
@@ -341,12 +346,12 @@ void pci_disable_msix(struct pci_dev *dev)
341This API should always be used to undo the effect of pci_enable_msix() 346This API should always be used to undo the effect of pci_enable_msix()
342when a device driver is unloading. Note that a device driver should 347when a device driver is unloading. Note that a device driver should
343always call free_irq() on all MSI-X vectors it has done request_irq() 348always call free_irq() on all MSI-X vectors it has done request_irq()
344on before calling this API. Failure to do so results a BUG_ON() and 349on before calling this API. Failure to do so results in a BUG_ON() and
345a device will be left with MSI-X enabled and leaks its vectors. 350a device will be left with MSI-X enabled and leaks its vectors.
346 351
3475.3.6 MSI-X mode vs. legacy mode diagram 3525.3.6 MSI-X mode vs. legacy mode diagram
348 353
349The below diagram shows the events, which switches the interrupt 354The below diagram shows the events which switch the interrupt
350mode on the MSI-X capable device function between MSI-X mode and 355mode on the MSI-X capable device function between MSI-X mode and
351PIN-IRQ assertion mode (legacy). 356PIN-IRQ assertion mode (legacy).
352 357
@@ -356,22 +361,22 @@ PIN-IRQ assertion mode (legacy).
356 | | ===============> | | 361 | | ===============> | |
357 ------------ pci_disable_msix ------------------------ 362 ------------ pci_disable_msix ------------------------
358 363
359Figure 2.0 MSI-X Mode vs. Legacy Mode 364Figure 2. MSI-X Mode vs. Legacy Mode
360 365
361In Figure 2.0, a device operates by default in legacy mode. A 366In Figure 2, a device operates by default in legacy mode. A
362successful MSI-X request (using pci_enable_msix()) switches a 367successful MSI-X request (using pci_enable_msix()) switches a
363device's interrupt mode to MSI-X mode. A pre-assigned IOAPIC vector 368device's interrupt mode to MSI-X mode. A pre-assigned IOAPIC vector
364stored in dev->irq will be saved by the PCI subsystem; however, 369stored in dev->irq will be saved by the PCI subsystem; however,
365unlike MSI mode, the PCI subsystem will not replace dev->irq with 370unlike MSI mode, the PCI subsystem will not replace dev->irq with
366assigned MSI-X vector because the PCI subsystem already writes the 1:1 371assigned MSI-X vector because the PCI subsystem already writes the 1:1
367vector-to-entry mapping into the field vector of each element 372vector-to-entry mapping into the field 'vector' of each element
368specified in second argument. 373specified in second argument.
369 374
370To return back to its default mode, a device driver should always call 375To return back to its default mode, a device driver should always call
371pci_disable_msix() to undo the effect of pci_enable_msix(). Note that 376pci_disable_msix() to undo the effect of pci_enable_msix(). Note that
372a device driver should always call free_irq() on all MSI-X vectors it 377a device driver should always call free_irq() on all MSI-X vectors it
373has done request_irq() on before calling pci_disable_msix(). Failure 378has done request_irq() on before calling pci_disable_msix(). Failure
374to do so results a BUG_ON() and a device will be left with MSI-X 379to do so results in a BUG_ON() and a device will be left with MSI-X
375enabled and leaks its vectors. Otherwise, the PCI subsystem switches a 380enabled and leaks its vectors. Otherwise, the PCI subsystem switches a
376device function's interrupt mode from MSI-X mode to legacy mode and 381device function's interrupt mode from MSI-X mode to legacy mode and
377marks all allocated MSI-X vectors as unused. 382marks all allocated MSI-X vectors as unused.
@@ -383,53 +388,56 @@ MSI/MSI-X requests from other drivers, these MSI-X vectors may be
383re-assigned. 388re-assigned.
384 389
385For the case where the PCI subsystem re-assigned these MSI-X vectors 390For the case where the PCI subsystem re-assigned these MSI-X vectors
386to other driver, a request to switching back to MSI-X mode may result 391to other drivers, a request to switch back to MSI-X mode may result
387being assigned with another set of MSI-X vectors or a failure if no 392being assigned with another set of MSI-X vectors or a failure if no
388more vectors are available. 393more vectors are available.
389 394
3905.4 Handling function implementng both MSI and MSI-X capabilities 3955.4 Handling function implementing both MSI and MSI-X capabilities
391 396
392For the case where a function implements both MSI and MSI-X 397For the case where a function implements both MSI and MSI-X
393capabilities, the PCI subsystem enables a device to run either in MSI 398capabilities, the PCI subsystem enables a device to run either in MSI
394mode or MSI-X mode but not both. A device driver determines whether it 399mode or MSI-X mode but not both. A device driver determines whether it
395wants MSI or MSI-X enabled on its hardware device. Once a device 400wants MSI or MSI-X enabled on its hardware device. Once a device
396driver requests for MSI, for example, it is prohibited to request for 401driver requests for MSI, for example, it is prohibited from requesting
397MSI-X; in other words, a device driver is not permitted to ping-pong 402MSI-X; in other words, a device driver is not permitted to ping-pong
398between MSI mod MSI-X mode during a run-time. 403between MSI mod MSI-X mode during a run-time.
399 404
4005.5 Hardware requirements for MSI/MSI-X support 4055.5 Hardware requirements for MSI/MSI-X support
406
401MSI/MSI-X support requires support from both system hardware and 407MSI/MSI-X support requires support from both system hardware and
402individual hardware device functions. 408individual hardware device functions.
403 409
4045.5.1 System hardware support 4105.5.1 System hardware support
411
405Since the target of MSI address is the local APIC CPU, enabling 412Since the target of MSI address is the local APIC CPU, enabling
406MSI/MSI-X support in Linux kernel is dependent on whether existing 413MSI/MSI-X support in the Linux kernel is dependent on whether existing
407system hardware supports local APIC. Users should verify their 414system hardware supports local APIC. Users should verify that their
408system whether it runs when CONFIG_X86_LOCAL_APIC=y. 415system supports local APIC operation by testing that it runs when
416CONFIG_X86_LOCAL_APIC=y.
409 417
410In SMP environment, CONFIG_X86_LOCAL_APIC is automatically set; 418In SMP environment, CONFIG_X86_LOCAL_APIC is automatically set;
411however, in UP environment, users must manually set 419however, in UP environment, users must manually set
412CONFIG_X86_LOCAL_APIC. Once CONFIG_X86_LOCAL_APIC=y, setting 420CONFIG_X86_LOCAL_APIC. Once CONFIG_X86_LOCAL_APIC=y, setting
413CONFIG_PCI_MSI enables the VECTOR based scheme and 421CONFIG_PCI_MSI enables the VECTOR based scheme and the option for
414the option for MSI-capable device drivers to selectively enable 422MSI-capable device drivers to selectively enable MSI/MSI-X.
415MSI/MSI-X.
416 423
417Note that CONFIG_X86_IO_APIC setting is irrelevant because MSI/MSI-X 424Note that CONFIG_X86_IO_APIC setting is irrelevant because MSI/MSI-X
418vector is allocated new during runtime and MSI/MSI-X support does not 425vector is allocated new during runtime and MSI/MSI-X support does not
419depend on BIOS support. This key independency enables MSI/MSI-X 426depend on BIOS support. This key independency enables MSI/MSI-X
420support on future IOxAPIC free platform. 427support on future IOxAPIC free platforms.
421 428
4225.5.2 Device hardware support 4295.5.2 Device hardware support
430
423The hardware device function supports MSI by indicating the 431The hardware device function supports MSI by indicating the
424MSI/MSI-X capability structure on its PCI capability list. By 432MSI/MSI-X capability structure on its PCI capability list. By
425default, this capability structure will not be initialized by 433default, this capability structure will not be initialized by
426the kernel to enable MSI during the system boot. In other words, 434the kernel to enable MSI during the system boot. In other words,
427the device function is running on its default pin assertion mode. 435the device function is running on its default pin assertion mode.
428Note that in many cases the hardware supporting MSI have bugs, 436Note that in many cases the hardware supporting MSI have bugs,
429which may result in system hang. The software driver of specific 437which may result in system hangs. The software driver of specific
430MSI-capable hardware is responsible for whether calling 438MSI-capable hardware is responsible for deciding whether to call
431pci_enable_msi or not. A return of zero indicates the kernel 439pci_enable_msi or not. A return of zero indicates the kernel
432successfully initializes the MSI/MSI-X capability structure of the 440successfully initialized the MSI/MSI-X capability structure of the
433device function. The device function is now running on MSI/MSI-X mode. 441device function. The device function is now running on MSI/MSI-X mode.
434 442
4355.6 How to tell whether MSI/MSI-X is enabled on device function 4435.6 How to tell whether MSI/MSI-X is enabled on device function
@@ -439,10 +447,10 @@ pci_enable_msi()/pci_enable_msix() indicates to a device driver that
439its device function is initialized successfully and ready to run in 447its device function is initialized successfully and ready to run in
440MSI/MSI-X mode. 448MSI/MSI-X mode.
441 449
442At the user level, users can use command 'cat /proc/interrupts' 450At the user level, users can use the command 'cat /proc/interrupts'
443to display the vector allocated for a device and its interrupt 451to display the vectors allocated for devices and their interrupt
444MSI/MSI-X mode ("PCI MSI"/"PCI MSIX"). Below shows below MSI mode is 452MSI/MSI-X modes ("PCI-MSI"/"PCI-MSI-X"). Below shows MSI mode is
445enabled on a SCSI Adaptec 39320D Ultra320. 453enabled on a SCSI Adaptec 39320D Ultra320 controller.
446 454
447 CPU0 CPU1 455 CPU0 CPU1
448 0: 324639 0 IO-APIC-edge timer 456 0: 324639 0 IO-APIC-edge timer
@@ -453,8 +461,8 @@ enabled on a SCSI Adaptec 39320D Ultra320.
453 15: 1 0 IO-APIC-edge ide1 461 15: 1 0 IO-APIC-edge ide1
454169: 0 0 IO-APIC-level uhci-hcd 462169: 0 0 IO-APIC-level uhci-hcd
455185: 0 0 IO-APIC-level uhci-hcd 463185: 0 0 IO-APIC-level uhci-hcd
456193: 138 10 PCI MSI aic79xx 464193: 138 10 PCI-MSI aic79xx
457201: 30 0 PCI MSI aic79xx 465201: 30 0 PCI-MSI aic79xx
458225: 30 0 IO-APIC-level aic7xxx 466225: 30 0 IO-APIC-level aic7xxx
459233: 30 0 IO-APIC-level aic7xxx 467233: 30 0 IO-APIC-level aic7xxx
460NMI: 0 0 468NMI: 0 0
@@ -490,8 +498,8 @@ target address set as 0xfeexxxxx, as conformed to PCI
490specification 2.3 or latest, then it should work. 498specification 2.3 or latest, then it should work.
491 499
492Q4. From the driver point of view, if the MSI is lost because 500Q4. From the driver point of view, if the MSI is lost because
493of the errors occur during inbound memory write, then it may 501of errors occurring during inbound memory write, then it may
494wait for ever. Is there a mechanism for it to recover? 502wait forever. Is there a mechanism for it to recover?
495 503
496A4. Since the target of the transaction is an inbound memory 504A4. Since the target of the transaction is an inbound memory
497write, all transaction termination conditions (Retry, 505write, all transaction termination conditions (Retry,
diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt
index 354d89c78377..15da16861fa3 100644
--- a/Documentation/RCU/whatisRCU.txt
+++ b/Documentation/RCU/whatisRCU.txt
@@ -772,8 +772,6 @@ RCU pointer/list traversal:
772 list_for_each_entry_rcu 772 list_for_each_entry_rcu
773 list_for_each_continue_rcu (to be deprecated in favor of new 773 list_for_each_continue_rcu (to be deprecated in favor of new
774 list_for_each_entry_continue_rcu) 774 list_for_each_entry_continue_rcu)
775 hlist_for_each_rcu (to be deprecated in favor of
776 hlist_for_each_entry_rcu)
777 hlist_for_each_entry_rcu 775 hlist_for_each_entry_rcu
778 776
779RCU pointer update: 777RCU pointer update:
diff --git a/Documentation/device-mapper/snapshot.txt b/Documentation/device-mapper/snapshot.txt
index dca274ff4005..a5009c8300f3 100644
--- a/Documentation/device-mapper/snapshot.txt
+++ b/Documentation/device-mapper/snapshot.txt
@@ -19,7 +19,6 @@ There are two dm targets available: snapshot and snapshot-origin.
19*) snapshot-origin <origin> 19*) snapshot-origin <origin>
20 20
21which will normally have one or more snapshots based on it. 21which will normally have one or more snapshots based on it.
22You must create the snapshot-origin device before you can create snapshots.
23Reads will be mapped directly to the backing device. For each write, the 22Reads will be mapped directly to the backing device. For each write, the
24original data will be saved in the <COW device> of each snapshot to keep 23original data will be saved in the <COW device> of each snapshot to keep
25its visible content unchanged, at least until the <COW device> fills up. 24its visible content unchanged, at least until the <COW device> fills up.
@@ -27,7 +26,7 @@ its visible content unchanged, at least until the <COW device> fills up.
27 26
28*) snapshot <origin> <COW device> <persistent?> <chunksize> 27*) snapshot <origin> <COW device> <persistent?> <chunksize>
29 28
30A snapshot is created of the <origin> block device. Changed chunks of 29A snapshot of the <origin> block device is created. Changed chunks of
31<chunksize> sectors will be stored on the <COW device>. Writes will 30<chunksize> sectors will be stored on the <COW device>. Writes will
32only go to the <COW device>. Reads will come from the <COW device> or 31only go to the <COW device>. Reads will come from the <COW device> or
33from <origin> for unchanged data. <COW device> will often be 32from <origin> for unchanged data. <COW device> will often be
@@ -37,6 +36,8 @@ the amount of free space and expand the <COW device> before it fills up.
37 36
38<persistent?> is P (Persistent) or N (Not persistent - will not survive 37<persistent?> is P (Persistent) or N (Not persistent - will not survive
39after reboot). 38after reboot).
39The difference is that for transient snapshots less metadata must be
40saved on disk - they can be kept in memory by the kernel.
40 41
41 42
42How this is used by LVM2 43How this is used by LVM2
diff --git a/Documentation/fb/vesafb.txt b/Documentation/fb/vesafb.txt
index 62db6758d1c1..ee277dd204b0 100644
--- a/Documentation/fb/vesafb.txt
+++ b/Documentation/fb/vesafb.txt
@@ -146,10 +146,10 @@ pmipal Use the protected mode interface for palette changes.
146 146
147mtrr:n setup memory type range registers for the vesafb framebuffer 147mtrr:n setup memory type range registers for the vesafb framebuffer
148 where n: 148 where n:
149 0 - disabled (equivalent to nomtrr) 149 0 - disabled (equivalent to nomtrr) (default)
150 1 - uncachable 150 1 - uncachable
151 2 - write-back 151 2 - write-back
152 3 - write-combining (default) 152 3 - write-combining
153 4 - write-through 153 4 - write-through
154 154
155 If you see the following in dmesg, choose the type that matches the 155 If you see the following in dmesg, choose the type that matches the
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index b67189a8d8d4..decdf9917e0d 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -69,6 +69,22 @@ Who: Grant Coady <gcoady@gmail.com>
69 69
70--------------------------- 70---------------------------
71 71
72What: remove EXPORT_SYMBOL(panic_timeout)
73When: April 2006
74Files: kernel/panic.c
75Why: No modular usage in the kernel.
76Who: Adrian Bunk <bunk@stusta.de>
77
78---------------------------
79
80What: remove EXPORT_SYMBOL(insert_resource)
81When: April 2006
82Files: kernel/resource.c
83Why: No modular usage in the kernel.
84Who: Adrian Bunk <bunk@stusta.de>
85
86---------------------------
87
72What: PCMCIA control ioctl (needed for pcmcia-cs [cardmgr, cardctl]) 88What: PCMCIA control ioctl (needed for pcmcia-cs [cardmgr, cardctl])
73When: November 2005 89When: November 2005
74Files: drivers/pcmcia/: pcmcia_ioctl.c 90Files: drivers/pcmcia/: pcmcia_ioctl.c
diff --git a/Documentation/filesystems/dentry-locking.txt b/Documentation/filesystems/dentry-locking.txt
new file mode 100644
index 000000000000..4c0c575a4012
--- /dev/null
+++ b/Documentation/filesystems/dentry-locking.txt
@@ -0,0 +1,173 @@
1RCU-based dcache locking model
2==============================
3
4On many workloads, the most common operation on dcache is to look up a
5dentry, given a parent dentry and the name of the child. Typically,
6for every open(), stat() etc., the dentry corresponding to the
7pathname will be looked up by walking the tree starting with the first
8component of the pathname and using that dentry along with the next
9component to look up the next level and so on. Since it is a frequent
10operation for workloads like multiuser environments and web servers,
11it is important to optimize this path.
12
13Prior to 2.5.10, dcache_lock was acquired in d_lookup and thus in
14every component during path look-up. Since 2.5.10 onwards, fast-walk
15algorithm changed this by holding the dcache_lock at the beginning and
16walking as many cached path component dentries as possible. This
17significantly decreases the number of acquisition of
18dcache_lock. However it also increases the lock hold time
19significantly and affects performance in large SMP machines. Since
202.5.62 kernel, dcache has been using a new locking model that uses RCU
21to make dcache look-up lock-free.
22
23The current dcache locking model is not very different from the
24existing dcache locking model. Prior to 2.5.62 kernel, dcache_lock
25protected the hash chain, d_child, d_alias, d_lru lists as well as
26d_inode and several other things like mount look-up. RCU-based changes
27affect only the way the hash chain is protected. For everything else
28the dcache_lock must be taken for both traversing as well as
29updating. The hash chain updates too take the dcache_lock. The
30significant change is the way d_lookup traverses the hash chain, it
31doesn't acquire the dcache_lock for this and rely on RCU to ensure
32that the dentry has not been *freed*.
33
34
35Dcache locking details
36======================
37
38For many multi-user workloads, open() and stat() on files are very
39frequently occurring operations. Both involve walking of path names to
40find the dentry corresponding to the concerned file. In 2.4 kernel,
41dcache_lock was held during look-up of each path component. Contention
42and cache-line bouncing of this global lock caused significant
43scalability problems. With the introduction of RCU in Linux kernel,
44this was worked around by making the look-up of path components during
45path walking lock-free.
46
47
48Safe lock-free look-up of dcache hash table
49===========================================
50
51Dcache is a complex data structure with the hash table entries also
52linked together in other lists. In 2.4 kernel, dcache_lock protected
53all the lists. We applied RCU only on hash chain walking. The rest of
54the lists are still protected by dcache_lock. Some of the important
55changes are :
56
571. The deletion from hash chain is done using hlist_del_rcu() macro
58 which doesn't initialize next pointer of the deleted dentry and
59 this allows us to walk safely lock-free while a deletion is
60 happening.
61
622. Insertion of a dentry into the hash table is done using
63 hlist_add_head_rcu() which take care of ordering the writes - the
64 writes to the dentry must be visible before the dentry is
65 inserted. This works in conjunction with hlist_for_each_rcu() while
66 walking the hash chain. The only requirement is that all
67 initialization to the dentry must be done before
68 hlist_add_head_rcu() since we don't have dcache_lock protection
69 while traversing the hash chain. This isn't different from the
70 existing code.
71
723. The dentry looked up without holding dcache_lock by cannot be
73 returned for walking if it is unhashed. It then may have a NULL
74 d_inode or other bogosity since RCU doesn't protect the other
75 fields in the dentry. We therefore use a flag DCACHE_UNHASHED to
76 indicate unhashed dentries and use this in conjunction with a
77 per-dentry lock (d_lock). Once looked up without the dcache_lock,
78 we acquire the per-dentry lock (d_lock) and check if the dentry is
79 unhashed. If so, the look-up is failed. If not, the reference count
80 of the dentry is increased and the dentry is returned.
81
824. Once a dentry is looked up, it must be ensured during the path walk
83 for that component it doesn't go away. In pre-2.5.10 code, this was
84 done holding a reference to the dentry. dcache_rcu does the same.
85 In some sense, dcache_rcu path walking looks like the pre-2.5.10
86 version.
87
885. All dentry hash chain updates must take the dcache_lock as well as
89 the per-dentry lock in that order. dput() does this to ensure that
90 a dentry that has just been looked up in another CPU doesn't get
91 deleted before dget() can be done on it.
92
936. There are several ways to do reference counting of RCU protected
94 objects. One such example is in ipv4 route cache where deferred
95 freeing (using call_rcu()) is done as soon as the reference count
96 goes to zero. This cannot be done in the case of dentries because
97 tearing down of dentries require blocking (dentry_iput()) which
98 isn't supported from RCU callbacks. Instead, tearing down of
99 dentries happen synchronously in dput(), but actual freeing happens
100 later when RCU grace period is over. This allows safe lock-free
101 walking of the hash chains, but a matched dentry may have been
102 partially torn down. The checking of DCACHE_UNHASHED flag with
103 d_lock held detects such dentries and prevents them from being
104 returned from look-up.
105
106
107Maintaining POSIX rename semantics
108==================================
109
110Since look-up of dentries is lock-free, it can race against a
111concurrent rename operation. For example, during rename of file A to
112B, look-up of either A or B must succeed. So, if look-up of B happens
113after A has been removed from the hash chain but not added to the new
114hash chain, it may fail. Also, a comparison while the name is being
115written concurrently by a rename may result in false positive matches
116violating rename semantics. Issues related to race with rename are
117handled as described below :
118
1191. Look-up can be done in two ways - d_lookup() which is safe from
120 simultaneous renames and __d_lookup() which is not. If
121 __d_lookup() fails, it must be followed up by a d_lookup() to
122 correctly determine whether a dentry is in the hash table or
123 not. d_lookup() protects look-ups using a sequence lock
124 (rename_lock).
125
1262. The name associated with a dentry (d_name) may be changed if a
127 rename is allowed to happen simultaneously. To avoid memcmp() in
128 __d_lookup() go out of bounds due to a rename and false positive
129 comparison, the name comparison is done while holding the
130 per-dentry lock. This prevents concurrent renames during this
131 operation.
132
1333. Hash table walking during look-up may move to a different bucket as
134 the current dentry is moved to a different bucket due to rename.
135 But we use hlists in dcache hash table and they are
136 null-terminated. So, even if a dentry moves to a different bucket,
137 hash chain walk will terminate. [with a list_head list, it may not
138 since termination is when the list_head in the original bucket is
139 reached]. Since we redo the d_parent check and compare name while
140 holding d_lock, lock-free look-up will not race against d_move().
141
1424. There can be a theoretical race when a dentry keeps coming back to
143 original bucket due to double moves. Due to this look-up may
144 consider that it has never moved and can end up in a infinite loop.
145 But this is not any worse that theoretical livelocks we already
146 have in the kernel.
147
148
149Important guidelines for filesystem developers related to dcache_rcu
150====================================================================
151
1521. Existing dcache interfaces (pre-2.5.62) exported to filesystem
153 don't change. Only dcache internal implementation changes. However
154 filesystems *must not* delete from the dentry hash chains directly
155 using the list macros like allowed earlier. They must use dcache
156 APIs like d_drop() or __d_drop() depending on the situation.
157
1582. d_flags is now protected by a per-dentry lock (d_lock). All access
159 to d_flags must be protected by it.
160
1613. For a hashed dentry, checking of d_count needs to be protected by
162 d_lock.
163
164
165Papers and other documentation on dcache locking
166================================================
167
1681. Scaling dcache with RCU (http://linuxjournal.com/article.php?sid=7124).
169
1702. http://lse.sourceforge.net/locking/dcache/dcache.html
171
172
173
diff --git a/Documentation/filesystems/devfs/README b/Documentation/filesystems/devfs/README
index 54366ecc241f..aabfba24bc2e 100644
--- a/Documentation/filesystems/devfs/README
+++ b/Documentation/filesystems/devfs/README
@@ -1812,11 +1812,6 @@ it may overflow the messages buffer, but try to get as much of it as
1812you can 1812you can
1813 1813
1814 1814
1815if you get an Oops, run ksymoops to decode it so that the
1816names of the offending functions are provided. A non-decoded Oops is
1817pretty useless
1818
1819
1820send a copy of your devfsd configuration file(s) 1815send a copy of your devfsd configuration file(s)
1821 1816
1822send the bug report to me first. 1817send the bug report to me first.
diff --git a/Documentation/filesystems/ramfs-rootfs-initramfs.txt b/Documentation/filesystems/ramfs-rootfs-initramfs.txt
new file mode 100644
index 000000000000..b3404a032596
--- /dev/null
+++ b/Documentation/filesystems/ramfs-rootfs-initramfs.txt
@@ -0,0 +1,195 @@
1ramfs, rootfs and initramfs
2October 17, 2005
3Rob Landley <rob@landley.net>
4=============================
5
6What is ramfs?
7--------------
8
9Ramfs is a very simple filesystem that exports Linux's disk caching
10mechanisms (the page cache and dentry cache) as a dynamically resizable
11ram-based filesystem.
12
13Normally all files are cached in memory by Linux. Pages of data read from
14backing store (usually the block device the filesystem is mounted on) are kept
15around in case it's needed again, but marked as clean (freeable) in case the
16Virtual Memory system needs the memory for something else. Similarly, data
17written to files is marked clean as soon as it has been written to backing
18store, but kept around for caching purposes until the VM reallocates the
19memory. A similar mechanism (the dentry cache) greatly speeds up access to
20directories.
21
22With ramfs, there is no backing store. Files written into ramfs allocate
23dentries and page cache as usual, but there's nowhere to write them to.
24This means the pages are never marked clean, so they can't be freed by the
25VM when it's looking to recycle memory.
26
27The amount of code required to implement ramfs is tiny, because all the
28work is done by the existing Linux caching infrastructure. Basically,
29you're mounting the disk cache as a filesystem. Because of this, ramfs is not
30an optional component removable via menuconfig, since there would be negligible
31space savings.
32
33ramfs and ramdisk:
34------------------
35
36The older "ram disk" mechanism created a synthetic block device out of
37an area of ram and used it as backing store for a filesystem. This block
38device was of fixed size, so the filesystem mounted on it was of fixed
39size. Using a ram disk also required unnecessarily copying memory from the
40fake block device into the page cache (and copying changes back out), as well
41as creating and destroying dentries. Plus it needed a filesystem driver
42(such as ext2) to format and interpret this data.
43
44Compared to ramfs, this wastes memory (and memory bus bandwidth), creates
45unnecessary work for the CPU, and pollutes the CPU caches. (There are tricks
46to avoid this copying by playing with the page tables, but they're unpleasantly
47complicated and turn out to be about as expensive as the copying anyway.)
48More to the point, all the work ramfs is doing has to happen _anyway_,
49since all file access goes through the page and dentry caches. The ram
50disk is simply unnecessary, ramfs is internally much simpler.
51
52Another reason ramdisks are semi-obsolete is that the introduction of
53loopback devices offered a more flexible and convenient way to create
54synthetic block devices, now from files instead of from chunks of memory.
55See losetup (8) for details.
56
57ramfs and tmpfs:
58----------------
59
60One downside of ramfs is you can keep writing data into it until you fill
61up all memory, and the VM can't free it because the VM thinks that files
62should get written to backing store (rather than swap space), but ramfs hasn't
63got any backing store. Because of this, only root (or a trusted user) should
64be allowed write access to a ramfs mount.
65
66A ramfs derivative called tmpfs was created to add size limits, and the ability
67to write the data to swap space. Normal users can be allowed write access to
68tmpfs mounts. See Documentation/filesystems/tmpfs.txt for more information.
69
70What is rootfs?
71---------------
72
73Rootfs is a special instance of ramfs, which is always present in 2.6 systems.
74(It's used internally as the starting and stopping point for searches of the
75kernel's doubly-linked list of mount points.)
76
77Most systems just mount another filesystem over it and ignore it. The
78amount of space an empty instance of ramfs takes up is tiny.
79
80What is initramfs?
81------------------
82
83All 2.6 Linux kernels contain a gzipped "cpio" format archive, which is
84extracted into rootfs when the kernel boots up. After extracting, the kernel
85checks to see if rootfs contains a file "init", and if so it executes it as PID
861. If found, this init process is responsible for bringing the system the
87rest of the way up, including locating and mounting the real root device (if
88any). If rootfs does not contain an init program after the embedded cpio
89archive is extracted into it, the kernel will fall through to the older code
90to locate and mount a root partition, then exec some variant of /sbin/init
91out of that.
92
93All this differs from the old initrd in several ways:
94
95 - The old initrd was a separate file, while the initramfs archive is linked
96 into the linux kernel image. (The directory linux-*/usr is devoted to
97 generating this archive during the build.)
98
99 - The old initrd file was a gzipped filesystem image (in some file format,
100 such as ext2, that had to be built into the kernel), while the new
101 initramfs archive is a gzipped cpio archive (like tar only simpler,
102 see cpio(1) and Documentation/early-userspace/buffer-format.txt).
103
104 - The program run by the old initrd (which was called /initrd, not /init) did
105 some setup and then returned to the kernel, while the init program from
106 initramfs is not expected to return to the kernel. (If /init needs to hand
107 off control it can overmount / with a new root device and exec another init
108 program. See the switch_root utility, below.)
109
110 - When switching another root device, initrd would pivot_root and then
111 umount the ramdisk. But initramfs is rootfs: you can neither pivot_root
112 rootfs, nor unmount it. Instead delete everything out of rootfs to
113 free up the space (find -xdev / -exec rm '{}' ';'), overmount rootfs
114 with the new root (cd /newmount; mount --move . /; chroot .), attach
115 stdin/stdout/stderr to the new /dev/console, and exec the new init.
116
117 Since this is a remarkably persnickity process (and involves deleting
118 commands before you can run them), the klibc package introduced a helper
119 program (utils/run_init.c) to do all this for you. Most other packages
120 (such as busybox) have named this command "switch_root".
121
122Populating initramfs:
123---------------------
124
125The 2.6 kernel build process always creates a gzipped cpio format initramfs
126archive and links it into the resulting kernel binary. By default, this
127archive is empty (consuming 134 bytes on x86). The config option
128CONFIG_INITRAMFS_SOURCE (for some reason buried under devices->block devices
129in menuconfig, and living in usr/Kconfig) can be used to specify a source for
130the initramfs archive, which will automatically be incorporated into the
131resulting binary. This option can point to an existing gzipped cpio archive, a
132directory containing files to be archived, or a text file specification such
133as the following example:
134
135 dir /dev 755 0 0
136 nod /dev/console 644 0 0 c 5 1
137 nod /dev/loop0 644 0 0 b 7 0
138 dir /bin 755 1000 1000
139 slink /bin/sh busybox 777 0 0
140 file /bin/busybox initramfs/busybox 755 0 0
141 dir /proc 755 0 0
142 dir /sys 755 0 0
143 dir /mnt 755 0 0
144 file /init initramfs/init.sh 755 0 0
145
146One advantage of the text file is that root access is not required to
147set permissions or create device nodes in the new archive. (Note that those
148two example "file" entries expect to find files named "init.sh" and "busybox" in
149a directory called "initramfs", under the linux-2.6.* directory. See
150Documentation/early-userspace/README for more details.)
151
152If you don't already understand what shared libraries, devices, and paths
153you need to get a minimal root filesystem up and running, here are some
154references:
155http://www.tldp.org/HOWTO/Bootdisk-HOWTO/
156http://www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html
157http://www.linuxfromscratch.org/lfs/view/stable/
158
159The "klibc" package (http://www.kernel.org/pub/linux/libs/klibc) is
160designed to be a tiny C library to statically link early userspace
161code against, along with some related utilities. It is BSD licensed.
162
163I use uClibc (http://www.uclibc.org) and busybox (http://www.busybox.net)
164myself. These are LGPL and GPL, respectively.
165
166In theory you could use glibc, but that's not well suited for small embedded
167uses like this. (A "hello world" program statically linked against glibc is
168over 400k. With uClibc it's 7k. Also note that glibc dlopens libnss to do
169name lookups, even when otherwise statically linked.)
170
171Future directions:
172------------------
173
174Today (2.6.14), initramfs is always compiled in, but not always used. The
175kernel falls back to legacy boot code that is reached only if initramfs does
176not contain an /init program. The fallback is legacy code, there to ensure a
177smooth transition and allowing early boot functionality to gradually move to
178"early userspace" (I.E. initramfs).
179
180The move to early userspace is necessary because finding and mounting the real
181root device is complex. Root partitions can span multiple devices (raid or
182separate journal). They can be out on the network (requiring dhcp, setting a
183specific mac address, logging into a server, etc). They can live on removable
184media, with dynamically allocated major/minor numbers and persistent naming
185issues requiring a full udev implementation to sort out. They can be
186compressed, encrypted, copy-on-write, loopback mounted, strangely partitioned,
187and so on.
188
189This kind of complexity (which inevitably includes policy) is rightly handled
190in userspace. Both klibc and busybox/uClibc are working on simple initramfs
191packages to drop into a kernel build, and when standard solutions are ready
192and widely deployed, the kernel's legacy early boot code will become obsolete
193and a candidate for the feature removal schedule.
194
195But that's a while off yet.
diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt
index f042c12e0ed2..ee4c0a8b8db7 100644
--- a/Documentation/filesystems/vfs.txt
+++ b/Documentation/filesystems/vfs.txt
@@ -3,7 +3,7 @@
3 3
4 Original author: Richard Gooch <rgooch@atnf.csiro.au> 4 Original author: Richard Gooch <rgooch@atnf.csiro.au>
5 5
6 Last updated on August 25, 2005 6 Last updated on October 28, 2005
7 7
8 Copyright (C) 1999 Richard Gooch 8 Copyright (C) 1999 Richard Gooch
9 Copyright (C) 2005 Pekka Enberg 9 Copyright (C) 2005 Pekka Enberg
@@ -11,62 +11,61 @@
11 This file is released under the GPLv2. 11 This file is released under the GPLv2.
12 12
13 13
14What is it? 14Introduction
15=========== 15============
16 16
17The Virtual File System (otherwise known as the Virtual Filesystem 17The Virtual File System (also known as the Virtual Filesystem Switch)
18Switch) is the software layer in the kernel that provides the 18is the software layer in the kernel that provides the filesystem
19filesystem interface to userspace programs. It also provides an 19interface to userspace programs. It also provides an abstraction
20abstraction within the kernel which allows different filesystem 20within the kernel which allows different filesystem implementations to
21implementations to coexist. 21coexist.
22 22
23VFS system calls open(2), stat(2), read(2), write(2), chmod(2) and so
24on are called from a process context. Filesystem locking is described
25in the document Documentation/filesystems/Locking.
23 26
24A Quick Look At How It Works
25============================
26 27
27In this section I'll briefly describe how things work, before 28Directory Entry Cache (dcache)
28launching into the details. I'll start with describing what happens 29------------------------------
29when user programs open and manipulate files, and then look from the
30other view which is how a filesystem is supported and subsequently
31mounted.
32
33
34Opening a File
35--------------
36
37The VFS implements the open(2), stat(2), chmod(2) and similar system
38calls. The pathname argument is used by the VFS to search through the
39directory entry cache (dentry cache or "dcache"). This provides a very
40fast look-up mechanism to translate a pathname (filename) into a
41specific dentry.
42
43An individual dentry usually has a pointer to an inode. Inodes are the
44things that live on disc drives, and can be regular files (you know:
45those things that you write data into), directories, FIFOs and other
46beasts. Dentries live in RAM and are never saved to disc: they exist
47only for performance. Inodes live on disc and are copied into memory
48when required. Later any changes are written back to disc. The inode
49that lives in RAM is a VFS inode, and it is this which the dentry
50points to. A single inode can be pointed to by multiple dentries
51(think about hardlinks).
52
53The dcache is meant to be a view into your entire filespace. Unlike
54Linus, most of us losers can't fit enough dentries into RAM to cover
55all of our filespace, so the dcache has bits missing. In order to
56resolve your pathname into a dentry, the VFS may have to resort to
57creating dentries along the way, and then loading the inode. This is
58done by looking up the inode.
59
60To look up an inode (usually read from disc) requires that the VFS
61calls the lookup() method of the parent directory inode. This method
62is installed by the specific filesystem implementation that the inode
63lives in. There will be more on this later.
64 30
65Once the VFS has the required dentry (and hence the inode), we can do 31The VFS implements the open(2), stat(2), chmod(2), and similar system
66all those boring things like open(2) the file, or stat(2) it to peek 32calls. The pathname argument that is passed to them is used by the VFS
67at the inode data. The stat(2) operation is fairly simple: once the 33to search through the directory entry cache (also known as the dentry
68VFS has the dentry, it peeks at the inode data and passes some of it 34cache or dcache). This provides a very fast look-up mechanism to
69back to userspace. 35translate a pathname (filename) into a specific dentry. Dentries live
36in RAM and are never saved to disc: they exist only for performance.
37
38The dentry cache is meant to be a view into your entire filespace. As
39most computers cannot fit all dentries in the RAM at the same time,
40some bits of the cache are missing. In order to resolve your pathname
41into a dentry, the VFS may have to resort to creating dentries along
42the way, and then loading the inode. This is done by looking up the
43inode.
44
45
46The Inode Object
47----------------
48
49An individual dentry usually has a pointer to an inode. Inodes are
50filesystem objects such as regular files, directories, FIFOs and other
51beasts. They live either on the disc (for block device filesystems)
52or in the memory (for pseudo filesystems). Inodes that live on the
53disc are copied into the memory when required and changes to the inode
54are written back to disc. A single inode can be pointed to by multiple
55dentries (hard links, for example, do this).
56
57To look up an inode requires that the VFS calls the lookup() method of
58the parent directory inode. This method is installed by the specific
59filesystem implementation that the inode lives in. Once the VFS has
60the required dentry (and hence the inode), we can do all those boring
61things like open(2) the file, or stat(2) it to peek at the inode
62data. The stat(2) operation is fairly simple: once the VFS has the
63dentry, it peeks at the inode data and passes some of it back to
64userspace.
65
66
67The File Object
68---------------
70 69
71Opening a file requires another operation: allocation of a file 70Opening a file requires another operation: allocation of a file
72structure (this is the kernel-side implementation of file 71structure (this is the kernel-side implementation of file
@@ -74,51 +73,39 @@ descriptors). The freshly allocated file structure is initialized with
74a pointer to the dentry and a set of file operation member functions. 73a pointer to the dentry and a set of file operation member functions.
75These are taken from the inode data. The open() file method is then 74These are taken from the inode data. The open() file method is then
76called so the specific filesystem implementation can do it's work. You 75called so the specific filesystem implementation can do it's work. You
77can see that this is another switch performed by the VFS. 76can see that this is another switch performed by the VFS. The file
78 77structure is placed into the file descriptor table for the process.
79The file structure is placed into the file descriptor table for the
80process.
81 78
82Reading, writing and closing files (and other assorted VFS operations) 79Reading, writing and closing files (and other assorted VFS operations)
83is done by using the userspace file descriptor to grab the appropriate 80is done by using the userspace file descriptor to grab the appropriate
84file structure, and then calling the required file structure method 81file structure, and then calling the required file structure method to
85function to do whatever is required. 82do whatever is required. For as long as the file is open, it keeps the
86 83dentry in use, which in turn means that the VFS inode is still in use.
87For as long as the file is open, it keeps the dentry "open" (in use),
88which in turn means that the VFS inode is still in use.
89
90All VFS system calls (i.e. open(2), stat(2), read(2), write(2),
91chmod(2) and so on) are called from a process context. You should
92assume that these calls are made without any kernel locks being
93held. This means that the processes may be executing the same piece of
94filesystem or driver code at the same time, on different
95processors. You should ensure that access to shared resources is
96protected by appropriate locks.
97 84
98 85
99Registering and Mounting a Filesystem 86Registering and Mounting a Filesystem
100------------------------------------- 87=====================================
101 88
102If you want to support a new kind of filesystem in the kernel, all you 89To register and unregister a filesystem, use the following API
103need to do is call register_filesystem(). You pass a structure 90functions:
104describing the filesystem implementation (struct file_system_type)
105which is then added to an internal table of supported filesystems. You
106can do:
107 91
108% cat /proc/filesystems 92 #include <linux/fs.h>
109 93
110to see what filesystems are currently available on your system. 94 extern int register_filesystem(struct file_system_type *);
95 extern int unregister_filesystem(struct file_system_type *);
111 96
112When a request is made to mount a block device onto a directory in 97The passed struct file_system_type describes your filesystem. When a
113your filespace the VFS will call the appropriate method for the 98request is made to mount a device onto a directory in your filespace,
114specific filesystem. The dentry for the mount point will then be 99the VFS will call the appropriate get_sb() method for the specific
115updated to point to the root inode for the new filesystem. 100filesystem. The dentry for the mount point will then be updated to
101point to the root inode for the new filesystem.
116 102
117It's now time to look at things in more detail. 103You can see all filesystems that are registered to the kernel in the
104file /proc/filesystems.
118 105
119 106
120struct file_system_type 107struct file_system_type
121======================= 108-----------------------
122 109
123This describes the filesystem. As of kernel 2.6.13, the following 110This describes the filesystem. As of kernel 2.6.13, the following
124members are defined: 111members are defined:
@@ -197,8 +184,14 @@ A fill_super() method implementation has the following arguments:
197 int silent: whether or not to be silent on error 184 int silent: whether or not to be silent on error
198 185
199 186
187The Superblock Object
188=====================
189
190A superblock object represents a mounted filesystem.
191
192
200struct super_operations 193struct super_operations
201======================= 194-----------------------
202 195
203This describes how the VFS can manipulate the superblock of your 196This describes how the VFS can manipulate the superblock of your
204filesystem. As of kernel 2.6.13, the following members are defined: 197filesystem. As of kernel 2.6.13, the following members are defined:
@@ -286,9 +279,9 @@ or bottom half).
286 a superblock. The second parameter indicates whether the method 279 a superblock. The second parameter indicates whether the method
287 should wait until the write out has been completed. Optional. 280 should wait until the write out has been completed. Optional.
288 281
289 write_super_lockfs: called when VFS is locking a filesystem and forcing 282 write_super_lockfs: called when VFS is locking a filesystem and
290 it into a consistent state. This function is currently used by the 283 forcing it into a consistent state. This method is currently
291 Logical Volume Manager (LVM). 284 used by the Logical Volume Manager (LVM).
292 285
293 unlockfs: called when VFS is unlocking a filesystem and making it writable 286 unlockfs: called when VFS is unlocking a filesystem and making it writable
294 again. 287 again.
@@ -317,8 +310,14 @@ field. This is a pointer to a "struct inode_operations" which
317describes the methods that can be performed on individual inodes. 310describes the methods that can be performed on individual inodes.
318 311
319 312
313The Inode Object
314================
315
316An inode object represents an object within the filesystem.
317
318
320struct inode_operations 319struct inode_operations
321======================= 320-----------------------
322 321
323This describes how the VFS can manipulate an inode in your 322This describes how the VFS can manipulate an inode in your
324filesystem. As of kernel 2.6.13, the following members are defined: 323filesystem. As of kernel 2.6.13, the following members are defined:
@@ -394,51 +393,62 @@ otherwise noted.
394 will probably need to call d_instantiate() just as you would 393 will probably need to call d_instantiate() just as you would
395 in the create() method 394 in the create() method
396 395
396 rename: called by the rename(2) system call to rename the object to
397 have the parent and name given by the second inode and dentry.
398
397 readlink: called by the readlink(2) system call. Only required if 399 readlink: called by the readlink(2) system call. Only required if
398 you want to support reading symbolic links 400 you want to support reading symbolic links
399 401
400 follow_link: called by the VFS to follow a symbolic link to the 402 follow_link: called by the VFS to follow a symbolic link to the
401 inode it points to. Only required if you want to support 403 inode it points to. Only required if you want to support
402 symbolic links. This function returns a void pointer cookie 404 symbolic links. This method returns a void pointer cookie
403 that is passed to put_link(). 405 that is passed to put_link().
404 406
405 put_link: called by the VFS to release resources allocated by 407 put_link: called by the VFS to release resources allocated by
406 follow_link(). The cookie returned by follow_link() is passed to 408 follow_link(). The cookie returned by follow_link() is passed
407 to this function as the last parameter. It is used by filesystems 409 to to this method as the last parameter. It is used by
408 such as NFS where page cache is not stable (i.e. page that was 410 filesystems such as NFS where page cache is not stable
409 installed when the symbolic link walk started might not be in the 411 (i.e. page that was installed when the symbolic link walk
410 page cache at the end of the walk). 412 started might not be in the page cache at the end of the
411 413 walk).
412 truncate: called by the VFS to change the size of a file. The i_size 414
413 field of the inode is set to the desired size by the VFS before 415 truncate: called by the VFS to change the size of a file. The
414 this function is called. This function is called by the truncate(2) 416 i_size field of the inode is set to the desired size by the
415 system call and related functionality. 417 VFS before this method is called. This method is called by
418 the truncate(2) system call and related functionality.
416 419
417 permission: called by the VFS to check for access rights on a POSIX-like 420 permission: called by the VFS to check for access rights on a POSIX-like
418 filesystem. 421 filesystem.
419 422
420 setattr: called by the VFS to set attributes for a file. This function is 423 setattr: called by the VFS to set attributes for a file. This method
421 called by chmod(2) and related system calls. 424 is called by chmod(2) and related system calls.
422 425
423 getattr: called by the VFS to get attributes of a file. This function is 426 getattr: called by the VFS to get attributes of a file. This method
424 called by stat(2) and related system calls. 427 is called by stat(2) and related system calls.
425 428
426 setxattr: called by the VFS to set an extended attribute for a file. 429 setxattr: called by the VFS to set an extended attribute for a file.
427 Extended attribute is a name:value pair associated with an inode. This 430 Extended attribute is a name:value pair associated with an
428 function is called by setxattr(2) system call. 431 inode. This method is called by setxattr(2) system call.
432
433 getxattr: called by the VFS to retrieve the value of an extended
434 attribute name. This method is called by getxattr(2) function
435 call.
429 436
430 getxattr: called by the VFS to retrieve the value of an extended attribute 437 listxattr: called by the VFS to list all extended attributes for a
431 name. This function is called by getxattr(2) function call. 438 given file. This method is called by listxattr(2) system call.
432 439
433 listxattr: called by the VFS to list all extended attributes for a given 440 removexattr: called by the VFS to remove an extended attribute from
434 file. This function is called by listxattr(2) system call. 441 a file. This method is called by removexattr(2) system call.
435 442
436 removexattr: called by the VFS to remove an extended attribute from a file. 443
437 This function is called by removexattr(2) system call. 444The Address Space Object
445========================
446
447The address space object is used to identify pages in the page cache.
438 448
439 449
440struct address_space_operations 450struct address_space_operations
441=============================== 451-------------------------------
442 452
443This describes how the VFS can manipulate mapping of a file to page cache in 453This describes how the VFS can manipulate mapping of a file to page cache in
444your filesystem. As of kernel 2.6.13, the following members are defined: 454your filesystem. As of kernel 2.6.13, the following members are defined:
@@ -502,8 +512,14 @@ struct address_space_operations {
502 it. An example implementation can be found in fs/ext2/xip.c. 512 it. An example implementation can be found in fs/ext2/xip.c.
503 513
504 514
515The File Object
516===============
517
518A file object represents a file opened by a process.
519
520
505struct file_operations 521struct file_operations
506====================== 522----------------------
507 523
508This describes how the VFS can manipulate an open file. As of kernel 524This describes how the VFS can manipulate an open file. As of kernel
5092.6.13, the following members are defined: 5252.6.13, the following members are defined:
@@ -661,7 +677,7 @@ of child dentries. Child dentries are basically like files in a
661directory. 677directory.
662 678
663 679
664Directory Entry Cache APIs 680Directory Entry Cache API
665-------------------------- 681--------------------------
666 682
667There are a number of functions defined which permit a filesystem to 683There are a number of functions defined which permit a filesystem to
@@ -705,178 +721,24 @@ manipulate dentries:
705 and the dentry is returned. The caller must use d_put() 721 and the dentry is returned. The caller must use d_put()
706 to free the dentry when it finishes using it. 722 to free the dentry when it finishes using it.
707 723
724For further information on dentry locking, please refer to the document
725Documentation/filesystems/dentry-locking.txt.
708 726
709RCU-based dcache locking model
710------------------------------
711 727
712On many workloads, the most common operation on dcache is 728Resources
713to look up a dentry, given a parent dentry and the name 729=========
714of the child. Typically, for every open(), stat() etc., 730
715the dentry corresponding to the pathname will be looked 731(Note some of these resources are not up-to-date with the latest kernel
716up by walking the tree starting with the first component 732 version.)
717of the pathname and using that dentry along with the next 733
718component to look up the next level and so on. Since it 734Creating Linux virtual filesystems. 2002
719is a frequent operation for workloads like multiuser 735 <http://lwn.net/Articles/13325/>
720environments and web servers, it is important to optimize 736
721this path. 737The Linux Virtual File-system Layer by Neil Brown. 1999
722 738 <http://www.cse.unsw.edu.au/~neilb/oss/linux-commentary/vfs.html>
723Prior to 2.5.10, dcache_lock was acquired in d_lookup and thus 739
724in every component during path look-up. Since 2.5.10 onwards, 740A tour of the Linux VFS by Michael K. Johnson. 1996
725fast-walk algorithm changed this by holding the dcache_lock 741 <http://www.tldp.org/LDP/khg/HyperNews/get/fs/vfstour.html>
726at the beginning and walking as many cached path component
727dentries as possible. This significantly decreases the number
728of acquisition of dcache_lock. However it also increases the
729lock hold time significantly and affects performance in large
730SMP machines. Since 2.5.62 kernel, dcache has been using
731a new locking model that uses RCU to make dcache look-up
732lock-free.
733
734The current dcache locking model is not very different from the existing
735dcache locking model. Prior to 2.5.62 kernel, dcache_lock
736protected the hash chain, d_child, d_alias, d_lru lists as well
737as d_inode and several other things like mount look-up. RCU-based
738changes affect only the way the hash chain is protected. For everything
739else the dcache_lock must be taken for both traversing as well as
740updating. The hash chain updates too take the dcache_lock.
741The significant change is the way d_lookup traverses the hash chain,
742it doesn't acquire the dcache_lock for this and rely on RCU to
743ensure that the dentry has not been *freed*.
744
745
746Dcache locking details
747----------------------
748 742
749For many multi-user workloads, open() and stat() on files are 743A small trail through the Linux kernel by Andries Brouwer. 2001
750very frequently occurring operations. Both involve walking 744 <http://www.win.tue.nl/~aeb/linux/vfs/trail.html>
751of path names to find the dentry corresponding to the
752concerned file. In 2.4 kernel, dcache_lock was held
753during look-up of each path component. Contention and
754cache-line bouncing of this global lock caused significant
755scalability problems. With the introduction of RCU
756in Linux kernel, this was worked around by making
757the look-up of path components during path walking lock-free.
758
759
760Safe lock-free look-up of dcache hash table
761===========================================
762
763Dcache is a complex data structure with the hash table entries
764also linked together in other lists. In 2.4 kernel, dcache_lock
765protected all the lists. We applied RCU only on hash chain
766walking. The rest of the lists are still protected by dcache_lock.
767Some of the important changes are :
768
7691. The deletion from hash chain is done using hlist_del_rcu() macro which
770 doesn't initialize next pointer of the deleted dentry and this
771 allows us to walk safely lock-free while a deletion is happening.
772
7732. Insertion of a dentry into the hash table is done using
774 hlist_add_head_rcu() which take care of ordering the writes -
775 the writes to the dentry must be visible before the dentry
776 is inserted. This works in conjunction with hlist_for_each_rcu()
777 while walking the hash chain. The only requirement is that
778 all initialization to the dentry must be done before hlist_add_head_rcu()
779 since we don't have dcache_lock protection while traversing
780 the hash chain. This isn't different from the existing code.
781
7823. The dentry looked up without holding dcache_lock by cannot be
783 returned for walking if it is unhashed. It then may have a NULL
784 d_inode or other bogosity since RCU doesn't protect the other
785 fields in the dentry. We therefore use a flag DCACHE_UNHASHED to
786 indicate unhashed dentries and use this in conjunction with a
787 per-dentry lock (d_lock). Once looked up without the dcache_lock,
788 we acquire the per-dentry lock (d_lock) and check if the
789 dentry is unhashed. If so, the look-up is failed. If not, the
790 reference count of the dentry is increased and the dentry is returned.
791
7924. Once a dentry is looked up, it must be ensured during the path
793 walk for that component it doesn't go away. In pre-2.5.10 code,
794 this was done holding a reference to the dentry. dcache_rcu does
795 the same. In some sense, dcache_rcu path walking looks like
796 the pre-2.5.10 version.
797
7985. All dentry hash chain updates must take the dcache_lock as well as
799 the per-dentry lock in that order. dput() does this to ensure
800 that a dentry that has just been looked up in another CPU
801 doesn't get deleted before dget() can be done on it.
802
8036. There are several ways to do reference counting of RCU protected
804 objects. One such example is in ipv4 route cache where
805 deferred freeing (using call_rcu()) is done as soon as
806 the reference count goes to zero. This cannot be done in
807 the case of dentries because tearing down of dentries
808 require blocking (dentry_iput()) which isn't supported from
809 RCU callbacks. Instead, tearing down of dentries happen
810 synchronously in dput(), but actual freeing happens later
811 when RCU grace period is over. This allows safe lock-free
812 walking of the hash chains, but a matched dentry may have
813 been partially torn down. The checking of DCACHE_UNHASHED
814 flag with d_lock held detects such dentries and prevents
815 them from being returned from look-up.
816
817
818Maintaining POSIX rename semantics
819==================================
820
821Since look-up of dentries is lock-free, it can race against
822a concurrent rename operation. For example, during rename
823of file A to B, look-up of either A or B must succeed.
824So, if look-up of B happens after A has been removed from the
825hash chain but not added to the new hash chain, it may fail.
826Also, a comparison while the name is being written concurrently
827by a rename may result in false positive matches violating
828rename semantics. Issues related to race with rename are
829handled as described below :
830
8311. Look-up can be done in two ways - d_lookup() which is safe
832 from simultaneous renames and __d_lookup() which is not.
833 If __d_lookup() fails, it must be followed up by a d_lookup()
834 to correctly determine whether a dentry is in the hash table
835 or not. d_lookup() protects look-ups using a sequence
836 lock (rename_lock).
837
8382. The name associated with a dentry (d_name) may be changed if
839 a rename is allowed to happen simultaneously. To avoid memcmp()
840 in __d_lookup() go out of bounds due to a rename and false
841 positive comparison, the name comparison is done while holding the
842 per-dentry lock. This prevents concurrent renames during this
843 operation.
844
8453. Hash table walking during look-up may move to a different bucket as
846 the current dentry is moved to a different bucket due to rename.
847 But we use hlists in dcache hash table and they are null-terminated.
848 So, even if a dentry moves to a different bucket, hash chain
849 walk will terminate. [with a list_head list, it may not since
850 termination is when the list_head in the original bucket is reached].
851 Since we redo the d_parent check and compare name while holding
852 d_lock, lock-free look-up will not race against d_move().
853
8544. There can be a theoretical race when a dentry keeps coming back
855 to original bucket due to double moves. Due to this look-up may
856 consider that it has never moved and can end up in a infinite loop.
857 But this is not any worse that theoretical livelocks we already
858 have in the kernel.
859
860
861Important guidelines for filesystem developers related to dcache_rcu
862====================================================================
863
8641. Existing dcache interfaces (pre-2.5.62) exported to filesystem
865 don't change. Only dcache internal implementation changes. However
866 filesystems *must not* delete from the dentry hash chains directly
867 using the list macros like allowed earlier. They must use dcache
868 APIs like d_drop() or __d_drop() depending on the situation.
869
8702. d_flags is now protected by a per-dentry lock (d_lock). All
871 access to d_flags must be protected by it.
872
8733. For a hashed dentry, checking of d_count needs to be protected
874 by d_lock.
875
876
877Papers and other documentation on dcache locking
878================================================
879
8801. Scaling dcache with RCU (http://linuxjournal.com/article.php?sid=7124).
881
8822. http://lse.sourceforge.net/locking/dcache/dcache.html
diff --git a/Documentation/hpet.txt b/Documentation/hpet.txt
index 4e7cc8d3359b..e52457581f47 100644
--- a/Documentation/hpet.txt
+++ b/Documentation/hpet.txt
@@ -1,18 +1,21 @@
1 High Precision Event Timer Driver for Linux 1 High Precision Event Timer Driver for Linux
2 2
3The High Precision Event Timer (HPET) hardware is the future replacement for the 8254 and Real 3The High Precision Event Timer (HPET) hardware is the future replacement
4Time Clock (RTC) periodic timer functionality. Each HPET can have up two 32 timers. It is possible 4for the 8254 and Real Time Clock (RTC) periodic timer functionality.
5to configure the first two timers as legacy replacements for 8254 and RTC periodic. A specification 5Each HPET can have up two 32 timers. It is possible to configure the
6done by INTEL and Microsoft can be found at http://www.intel.com/labs/platcomp/hpet/hpetspec.htm. 6first two timers as legacy replacements for 8254 and RTC periodic timers.
7 7A specification done by Intel and Microsoft can be found at
8The driver supports detection of HPET driver allocation and initialization of the HPET before the 8<http://www.intel.com/hardwaredesign/hpetspec.htm>.
9driver module_init routine is called. This enables platform code which uses timer 0 or 1 as the 9
10main timer to intercept HPET initialization. An example of this initialization can be found in 10The driver supports detection of HPET driver allocation and initialization
11of the HPET before the driver module_init routine is called. This enables
12platform code which uses timer 0 or 1 as the main timer to intercept HPET
13initialization. An example of this initialization can be found in
11arch/i386/kernel/time_hpet.c. 14arch/i386/kernel/time_hpet.c.
12 15
13The driver provides two APIs which are very similar to the API found in the rtc.c driver. 16The driver provides two APIs which are very similar to the API found in
14There is a user space API and a kernel space API. An example user space program is provided 17the rtc.c driver. There is a user space API and a kernel space API.
15below. 18An example user space program is provided below.
16 19
17#include <stdio.h> 20#include <stdio.h>
18#include <stdlib.h> 21#include <stdlib.h>
@@ -290,9 +293,8 @@ The kernel API has three interfaces exported from the driver:
290 hpet_unregister(struct hpet_task *tp) 293 hpet_unregister(struct hpet_task *tp)
291 hpet_control(struct hpet_task *tp, unsigned int cmd, unsigned long arg) 294 hpet_control(struct hpet_task *tp, unsigned int cmd, unsigned long arg)
292 295
293The kernel module using this interface fills in the ht_func and ht_data members of the 296The kernel module using this interface fills in the ht_func and ht_data
294hpet_task structure before calling hpet_register. hpet_control simply vectors to the hpet_ioctl 297members of the hpet_task structure before calling hpet_register.
295routine and has the same commands and respective arguments as the user API. hpet_unregister 298hpet_control simply vectors to the hpet_ioctl routine and has the same
299commands and respective arguments as the user API. hpet_unregister
296is used to terminate usage of the HPET timer reserved by hpet_register. 300is used to terminate usage of the HPET timer reserved by hpet_register.
297
298
diff --git a/Documentation/ioctl-number.txt b/Documentation/ioctl-number.txt
index 769f925c8526..87f4d052e39c 100644
--- a/Documentation/ioctl-number.txt
+++ b/Documentation/ioctl-number.txt
@@ -130,8 +130,6 @@ Code Seq# Include File Comments
130 <mailto:zapman@interlan.net> 130 <mailto:zapman@interlan.net>
131'i' 00-3F linux/i2o.h 131'i' 00-3F linux/i2o.h
132'j' 00-3F linux/joystick.h 132'j' 00-3F linux/joystick.h
133'k' all asm-sparc/kbio.h
134 asm-sparc64/kbio.h
135'l' 00-3F linux/tcfs_fs.h transparent cryptographic file system 133'l' 00-3F linux/tcfs_fs.h transparent cryptographic file system
136 <http://mikonos.dia.unisa.it/tcfs> 134 <http://mikonos.dia.unisa.it/tcfs>
137'l' 40-7F linux/udf_fs_i.h in development: 135'l' 40-7F linux/udf_fs_i.h in development:
diff --git a/Documentation/magic-number.txt b/Documentation/magic-number.txt
index bd8eefa17587..af67faccf4de 100644
--- a/Documentation/magic-number.txt
+++ b/Documentation/magic-number.txt
@@ -120,7 +120,7 @@ ISDN_NET_MAGIC 0x49344C02 isdn_net_local_s drivers/isdn/i4l/isdn_net_li
120SAVEKMSG_MAGIC2 0x4B4D5347 savekmsg arch/*/amiga/config.c 120SAVEKMSG_MAGIC2 0x4B4D5347 savekmsg arch/*/amiga/config.c
121STLI_BOARDMAGIC 0x4bc6c825 stlibrd include/linux/istallion.h 121STLI_BOARDMAGIC 0x4bc6c825 stlibrd include/linux/istallion.h
122CS_STATE_MAGIC 0x4c4f4749 cs_state sound/oss/cs46xx.c 122CS_STATE_MAGIC 0x4c4f4749 cs_state sound/oss/cs46xx.c
123SLAB_C_MAGIC 0x4f17a36d kmem_cache_s mm/slab.c 123SLAB_C_MAGIC 0x4f17a36d kmem_cache mm/slab.c
124COW_MAGIC 0x4f4f4f4d cow_header_v1 arch/um/drivers/ubd_user.c 124COW_MAGIC 0x4f4f4f4d cow_header_v1 arch/um/drivers/ubd_user.c
125I810_CARD_MAGIC 0x5072696E i810_card sound/oss/i810_audio.c 125I810_CARD_MAGIC 0x5072696E i810_card sound/oss/i810_audio.c
126TRIDENT_CARD_MAGIC 0x5072696E trident_card sound/oss/trident.c 126TRIDENT_CARD_MAGIC 0x5072696E trident_card sound/oss/trident.c
diff --git a/Documentation/networking/decnet.txt b/Documentation/networking/decnet.txt
index c6bd25f5d61d..e6c39c5831f5 100644
--- a/Documentation/networking/decnet.txt
+++ b/Documentation/networking/decnet.txt
@@ -176,8 +176,6 @@ information (_most_ of which _is_ _essential_) includes:
176 - Which client caused the problem ? 176 - Which client caused the problem ?
177 - How much data was being transferred ? 177 - How much data was being transferred ?
178 - Was the network congested ? 178 - Was the network congested ?
179 - If there was a kernel panic, please run the output through ksymoops
180 before sending it to me, otherwise its _useless_.
181 - How can the problem be reproduced ? 179 - How can the problem be reproduced ?
182 - Can you use tcpdump to get a trace ? (N.B. Most (all?) versions of 180 - Can you use tcpdump to get a trace ? (N.B. Most (all?) versions of
183 tcpdump don't understand how to dump DECnet properly, so including 181 tcpdump don't understand how to dump DECnet properly, so including
diff --git a/Documentation/oops-tracing.txt b/Documentation/oops-tracing.txt
index 66eaaab7773d..c563842ed805 100644
--- a/Documentation/oops-tracing.txt
+++ b/Documentation/oops-tracing.txt
@@ -1,6 +1,6 @@
1NOTE: ksymoops is useless on 2.6. Please use the Oops in its original format 1NOTE: ksymoops is useless on 2.6. Please use the Oops in its original format
2(from dmesg, etc). Ignore any references in this or other docs to "decoding 2(from dmesg, etc). Ignore any references in this or other docs to "decoding
3the Oops" or "running it through ksymoops". If you post an Oops fron 2.6 that 3the Oops" or "running it through ksymoops". If you post an Oops from 2.6 that
4has been run through ksymoops, people will just tell you to repost it. 4has been run through ksymoops, people will just tell you to repost it.
5 5
6Quick Summary 6Quick Summary
diff --git a/Documentation/power/video.txt b/Documentation/power/video.txt
index 526d6dd267ea..912bed87c758 100644
--- a/Documentation/power/video.txt
+++ b/Documentation/power/video.txt
@@ -11,9 +11,9 @@ boot video card. (Kernel usually does not even contain video card
11driver -- vesafb and vgacon are widely used). 11driver -- vesafb and vgacon are widely used).
12 12
13This is not problem for swsusp, because during swsusp resume, BIOS is 13This is not problem for swsusp, because during swsusp resume, BIOS is
14run normally so video card is normally initialized. S3 has absolutely 14run normally so video card is normally initialized. It should not be
15no chance of working with SMP/HT. Be sure it to turn it off before 15problem for S1 standby, because hardware should retain its state over
16testing (swsusp should work ok, OTOH). 16that.
17 17
18There are a few types of systems where video works after S3 resume: 18There are a few types of systems where video works after S3 resume:
19 19
@@ -64,7 +64,7 @@ your video card (good luck getting docs :-(). Maybe suspending from X
64(proper X, knowing your hardware, not XF68_FBcon) might have better 64(proper X, knowing your hardware, not XF68_FBcon) might have better
65chance of working. 65chance of working.
66 66
67Table of known working systems: 67Table of known working notebooks:
68 68
69Model hack (or "how to do it") 69Model hack (or "how to do it")
70------------------------------------------------------------------------------ 70------------------------------------------------------------------------------
@@ -73,7 +73,7 @@ Acer TM 242FX vbetool (6)
73Acer TM C110 video_post (8) 73Acer TM C110 video_post (8)
74Acer TM C300 vga=normal (only suspend on console, not in X), vbetool (6) or video_post (8) 74Acer TM C300 vga=normal (only suspend on console, not in X), vbetool (6) or video_post (8)
75Acer TM 4052LCi s3_bios (2) 75Acer TM 4052LCi s3_bios (2)
76Acer TM 636Lci s3_bios vga=normal (2) 76Acer TM 636Lci s3_bios,s3_mode (4)
77Acer TM 650 (Radeon M7) vga=normal plus boot-radeon (5) gets text console back 77Acer TM 650 (Radeon M7) vga=normal plus boot-radeon (5) gets text console back
78Acer TM 660 ??? (*) 78Acer TM 660 ??? (*)
79Acer TM 800 vga=normal, X patches, see webpage (5) or vbetool (6) 79Acer TM 800 vga=normal, X patches, see webpage (5) or vbetool (6)
@@ -137,6 +137,13 @@ Toshiba Satellite P10-554 s3_bios,s3_mode (4)(****)
137Toshiba M30 (2) xor X with nvidia driver using internal AGP 137Toshiba M30 (2) xor X with nvidia driver using internal AGP
138Uniwill 244IIO ??? (*) 138Uniwill 244IIO ??? (*)
139 139
140Known working desktop systems
141~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142
143Mainboard Graphics card hack (or "how to do it")
144------------------------------------------------------------------------------
145Asus A7V8X nVidia RIVA TNT2 model 64 s3_bios,s3_mode (4)
146
140 147
141(*) from http://www.ubuntulinux.org/wiki/HoaryPMResults, not sure 148(*) from http://www.ubuntulinux.org/wiki/HoaryPMResults, not sure
142 which options to use. If you know, please tell me. 149 which options to use. If you know, please tell me.
diff --git a/Documentation/s390/driver-model.txt b/Documentation/s390/driver-model.txt
index 19461958e2bd..df09758bf3fe 100644
--- a/Documentation/s390/driver-model.txt
+++ b/Documentation/s390/driver-model.txt
@@ -8,11 +8,10 @@ All devices which can be addressed by means of ccws are called 'CCW devices' -
8even if they aren't actually driven by ccws. 8even if they aren't actually driven by ccws.
9 9
10All ccw devices are accessed via a subchannel, this is reflected in the 10All ccw devices are accessed via a subchannel, this is reflected in the
11structures under root/: 11structures under devices/:
12 12
13root/ 13devices/
14 - sys 14 - system/
15 - legacy
16 - css0/ 15 - css0/
17 - 0.0.0000/0.0.0815/ 16 - 0.0.0000/0.0.0815/
18 - 0.0.0001/0.0.4711/ 17 - 0.0.0001/0.0.4711/
@@ -36,7 +35,7 @@ availability: Can be 'good' or 'boxed'; 'no path' or 'no device' for
36 35
37online: An interface to set the device online and offline. 36online: An interface to set the device online and offline.
38 In the special case of the device being disconnected (see the 37 In the special case of the device being disconnected (see the
39 notify function under 1.2), piping 0 to online will focibly delete 38 notify function under 1.2), piping 0 to online will forcibly delete
40 the device. 39 the device.
41 40
42The device drivers can add entries to export per-device data and interfaces. 41The device drivers can add entries to export per-device data and interfaces.
@@ -222,7 +221,7 @@ and are called 'chp0.<chpid>'. They have no driver and do not belong to any bus.
222Please note, that unlike /proc/chpids in 2.4, the channel path objects reflect 221Please note, that unlike /proc/chpids in 2.4, the channel path objects reflect
223only the logical state and not the physical state, since we cannot track the 222only the logical state and not the physical state, since we cannot track the
224latter consistently due to lacking machine support (we don't need to be aware 223latter consistently due to lacking machine support (we don't need to be aware
225of anyway). 224of it anyway).
226 225
227status - Can be 'online' or 'offline'. 226status - Can be 'online' or 'offline'.
228 Piping 'on' or 'off' sets the chpid logically online/offline. 227 Piping 'on' or 'off' sets the chpid logically online/offline.
@@ -235,12 +234,16 @@ status - Can be 'online' or 'offline'.
2353. System devices 2343. System devices
236----------------- 235-----------------
237 236
238Note: cpus may yet be added here.
239
2403.1 xpram 2373.1 xpram
241--------- 238---------
242 239
243xpram shows up under sys/ as 'xpram'. 240xpram shows up under devices/system/ as 'xpram'.
241
2423.2 cpus
243--------
244
245For each cpu, a directory is created under devices/system/cpu/. Each cpu has an
246attribute 'online' which can be 0 or 1.
244 247
245 248
2464. Other devices 2494. Other devices
diff --git a/Documentation/sharedsubtree.txt b/Documentation/sharedsubtree.txt
new file mode 100644
index 000000000000..2d8f403eb6eb
--- /dev/null
+++ b/Documentation/sharedsubtree.txt
@@ -0,0 +1,1060 @@
1Shared Subtrees
2---------------
3
4Contents:
5 1) Overview
6 2) Features
7 3) smount command
8 4) Use-case
9 5) Detailed semantics
10 6) Quiz
11 7) FAQ
12 8) Implementation
13
14
151) Overview
16-----------
17
18Consider the following situation:
19
20A process wants to clone its own namespace, but still wants to access the CD
21that got mounted recently. Shared subtree semantics provide the necessary
22mechanism to accomplish the above.
23
24It provides the necessary building blocks for features like per-user-namespace
25and versioned filesystem.
26
272) Features
28-----------
29
30Shared subtree provides four different flavors of mounts; struct vfsmount to be
31precise
32
33 a. shared mount
34 b. slave mount
35 c. private mount
36 d. unbindable mount
37
38
392a) A shared mount can be replicated to as many mountpoints and all the
40replicas continue to be exactly same.
41
42 Here is an example:
43
44 Lets say /mnt has a mount that is shared.
45 mount --make-shared /mnt
46
47 note: mount command does not yet support the --make-shared flag.
48 I have included a small C program which does the same by executing
49 'smount /mnt shared'
50
51 #mount --bind /mnt /tmp
52 The above command replicates the mount at /mnt to the mountpoint /tmp
53 and the contents of both the mounts remain identical.
54
55 #ls /mnt
56 a b c
57
58 #ls /tmp
59 a b c
60
61 Now lets say we mount a device at /tmp/a
62 #mount /dev/sd0 /tmp/a
63
64 #ls /tmp/a
65 t1 t2 t2
66
67 #ls /mnt/a
68 t1 t2 t2
69
70 Note that the mount has propagated to the mount at /mnt as well.
71
72 And the same is true even when /dev/sd0 is mounted on /mnt/a. The
73 contents will be visible under /tmp/a too.
74
75
762b) A slave mount is like a shared mount except that mount and umount events
77 only propagate towards it.
78
79 All slave mounts have a master mount which is a shared.
80
81 Here is an example:
82
83 Lets say /mnt has a mount which is shared.
84 #mount --make-shared /mnt
85
86 Lets bind mount /mnt to /tmp
87 #mount --bind /mnt /tmp
88
89 the new mount at /tmp becomes a shared mount and it is a replica of
90 the mount at /mnt.
91
92 Now lets make the mount at /tmp; a slave of /mnt
93 #mount --make-slave /tmp
94 [or smount /tmp slave]
95
96 lets mount /dev/sd0 on /mnt/a
97 #mount /dev/sd0 /mnt/a
98
99 #ls /mnt/a
100 t1 t2 t3
101
102 #ls /tmp/a
103 t1 t2 t3
104
105 Note the mount event has propagated to the mount at /tmp
106
107 However lets see what happens if we mount something on the mount at /tmp
108
109 #mount /dev/sd1 /tmp/b
110
111 #ls /tmp/b
112 s1 s2 s3
113
114 #ls /mnt/b
115
116 Note how the mount event has not propagated to the mount at
117 /mnt
118
119
1202c) A private mount does not forward or receive propagation.
121
122 This is the mount we are familiar with. Its the default type.
123
124
1252d) A unbindable mount is a unbindable private mount
126
127 lets say we have a mount at /mnt and we make is unbindable
128
129 #mount --make-unbindable /mnt
130 [ smount /mnt unbindable ]
131
132 Lets try to bind mount this mount somewhere else.
133 # mount --bind /mnt /tmp
134 mount: wrong fs type, bad option, bad superblock on /mnt,
135 or too many mounted file systems
136
137 Binding a unbindable mount is a invalid operation.
138
139
1403) smount command
141
142 Currently the mount command is not aware of shared subtree features.
143 Work is in progress to add the support in mount ( util-linux package ).
144 Till then use the following program.
145
146 ------------------------------------------------------------------------
147 //
148 //this code was developed my Miklos Szeredi <miklos@szeredi.hu>
149 //and modified by Ram Pai <linuxram@us.ibm.com>
150 // sample usage:
151 // smount /tmp shared
152 //
153 #include <stdio.h>
154 #include <stdlib.h>
155 #include <unistd.h>
156 #include <sys/mount.h>
157 #include <sys/fsuid.h>
158
159 #ifndef MS_REC
160 #define MS_REC 0x4000 /* 16384: Recursive loopback */
161 #endif
162
163 #ifndef MS_SHARED
164 #define MS_SHARED 1<<20 /* Shared */
165 #endif
166
167 #ifndef MS_PRIVATE
168 #define MS_PRIVATE 1<<18 /* Private */
169 #endif
170
171 #ifndef MS_SLAVE
172 #define MS_SLAVE 1<<19 /* Slave */
173 #endif
174
175 #ifndef MS_UNBINDABLE
176 #define MS_UNBINDABLE 1<<17 /* Unbindable */
177 #endif
178
179 int main(int argc, char *argv[])
180 {
181 int type;
182 if(argc != 3) {
183 fprintf(stderr, "usage: %s dir "
184 "<rshared|rslave|rprivate|runbindable|shared|slave"
185 "|private|unbindable>\n" , argv[0]);
186 return 1;
187 }
188
189 fprintf(stdout, "%s %s %s\n", argv[0], argv[1], argv[2]);
190
191 if (strcmp(argv[2],"rshared")==0)
192 type=(MS_SHARED|MS_REC);
193 else if (strcmp(argv[2],"rslave")==0)
194 type=(MS_SLAVE|MS_REC);
195 else if (strcmp(argv[2],"rprivate")==0)
196 type=(MS_PRIVATE|MS_REC);
197 else if (strcmp(argv[2],"runbindable")==0)
198 type=(MS_UNBINDABLE|MS_REC);
199 else if (strcmp(argv[2],"shared")==0)
200 type=MS_SHARED;
201 else if (strcmp(argv[2],"slave")==0)
202 type=MS_SLAVE;
203 else if (strcmp(argv[2],"private")==0)
204 type=MS_PRIVATE;
205 else if (strcmp(argv[2],"unbindable")==0)
206 type=MS_UNBINDABLE;
207 else {
208 fprintf(stderr, "invalid operation: %s\n", argv[2]);
209 return 1;
210 }
211 setfsuid(getuid());
212
213 if(mount("", argv[1], "dontcare", type, "") == -1) {
214 perror("mount");
215 return 1;
216 }
217 return 0;
218 }
219 -----------------------------------------------------------------------
220
221 Copy the above code snippet into smount.c
222 gcc -o smount smount.c
223
224
225 (i) To mark all the mounts under /mnt as shared execute the following
226 command:
227
228 smount /mnt rshared
229 the corresponding syntax planned for mount command is
230 mount --make-rshared /mnt
231
232 just to mark a mount /mnt as shared, execute the following
233 command:
234 smount /mnt shared
235 the corresponding syntax planned for mount command is
236 mount --make-shared /mnt
237
238 (ii) To mark all the shared mounts under /mnt as slave execute the
239 following
240
241 command:
242 smount /mnt rslave
243 the corresponding syntax planned for mount command is
244 mount --make-rslave /mnt
245
246 just to mark a mount /mnt as slave, execute the following
247 command:
248 smount /mnt slave
249 the corresponding syntax planned for mount command is
250 mount --make-slave /mnt
251
252 (iii) To mark all the mounts under /mnt as private execute the
253 following command:
254
255 smount /mnt rprivate
256 the corresponding syntax planned for mount command is
257 mount --make-rprivate /mnt
258
259 just to mark a mount /mnt as private, execute the following
260 command:
261 smount /mnt private
262 the corresponding syntax planned for mount command is
263 mount --make-private /mnt
264
265 NOTE: by default all the mounts are created as private. But if
266 you want to change some shared/slave/unbindable mount as
267 private at a later point in time, this command can help.
268
269 (iv) To mark all the mounts under /mnt as unbindable execute the
270 following
271
272 command:
273 smount /mnt runbindable
274 the corresponding syntax planned for mount command is
275 mount --make-runbindable /mnt
276
277 just to mark a mount /mnt as unbindable, execute the following
278 command:
279 smount /mnt unbindable
280 the corresponding syntax planned for mount command is
281 mount --make-unbindable /mnt
282
283
2844) Use cases
285------------
286
287 A) A process wants to clone its own namespace, but still wants to
288 access the CD that got mounted recently.
289
290 Solution:
291
292 The system administrator can make the mount at /cdrom shared
293 mount --bind /cdrom /cdrom
294 mount --make-shared /cdrom
295
296 Now any process that clones off a new namespace will have a
297 mount at /cdrom which is a replica of the same mount in the
298 parent namespace.
299
300 So when a CD is inserted and mounted at /cdrom that mount gets
301 propagated to the other mount at /cdrom in all the other clone
302 namespaces.
303
304 B) A process wants its mounts invisible to any other process, but
305 still be able to see the other system mounts.
306
307 Solution:
308
309 To begin with, the administrator can mark the entire mount tree
310 as shareable.
311
312 mount --make-rshared /
313
314 A new process can clone off a new namespace. And mark some part
315 of its namespace as slave
316
317 mount --make-rslave /myprivatetree
318
319 Hence forth any mounts within the /myprivatetree done by the
320 process will not show up in any other namespace. However mounts
321 done in the parent namespace under /myprivatetree still shows
322 up in the process's namespace.
323
324
325 Apart from the above semantics this feature provides the
326 building blocks to solve the following problems:
327
328 C) Per-user namespace
329
330 The above semantics allows a way to share mounts across
331 namespaces. But namespaces are associated with processes. If
332 namespaces are made first class objects with user API to
333 associate/disassociate a namespace with userid, then each user
334 could have his/her own namespace and tailor it to his/her
335 requirements. Offcourse its needs support from PAM.
336
337 D) Versioned files
338
339 If the entire mount tree is visible at multiple locations, then
340 a underlying versioning file system can return different
341 version of the file depending on the path used to access that
342 file.
343
344 An example is:
345
346 mount --make-shared /
347 mount --rbind / /view/v1
348 mount --rbind / /view/v2
349 mount --rbind / /view/v3
350 mount --rbind / /view/v4
351
352 and if /usr has a versioning filesystem mounted, than that
353 mount appears at /view/v1/usr, /view/v2/usr, /view/v3/usr and
354 /view/v4/usr too
355
356 A user can request v3 version of the file /usr/fs/namespace.c
357 by accessing /view/v3/usr/fs/namespace.c . The underlying
358 versioning filesystem can then decipher that v3 version of the
359 filesystem is being requested and return the corresponding
360 inode.
361
3625) Detailed semantics:
363-------------------
364 The section below explains the detailed semantics of
365 bind, rbind, move, mount, umount and clone-namespace operations.
366
367 Note: the word 'vfsmount' and the noun 'mount' have been used
368 to mean the same thing, throughout this document.
369
3705a) Mount states
371
372 A given mount can be in one of the following states
373 1) shared
374 2) slave
375 3) shared and slave
376 4) private
377 5) unbindable
378
379 A 'propagation event' is defined as event generated on a vfsmount
380 that leads to mount or unmount actions in other vfsmounts.
381
382 A 'peer group' is defined as a group of vfsmounts that propagate
383 events to each other.
384
385 (1) Shared mounts
386
387 A 'shared mount' is defined as a vfsmount that belongs to a
388 'peer group'.
389
390 For example:
391 mount --make-shared /mnt
392 mount --bin /mnt /tmp
393
394 The mount at /mnt and that at /tmp are both shared and belong
395 to the same peer group. Anything mounted or unmounted under
396 /mnt or /tmp reflect in all the other mounts of its peer
397 group.
398
399
400 (2) Slave mounts
401
402 A 'slave mount' is defined as a vfsmount that receives
403 propagation events and does not forward propagation events.
404
405 A slave mount as the name implies has a master mount from which
406 mount/unmount events are received. Events do not propagate from
407 the slave mount to the master. Only a shared mount can be made
408 a slave by executing the following command
409
410 mount --make-slave mount
411
412 A shared mount that is made as a slave is no more shared unless
413 modified to become shared.
414
415 (3) Shared and Slave
416
417 A vfsmount can be both shared as well as slave. This state
418 indicates that the mount is a slave of some vfsmount, and
419 has its own peer group too. This vfsmount receives propagation
420 events from its master vfsmount, and also forwards propagation
421 events to its 'peer group' and to its slave vfsmounts.
422
423 Strictly speaking, the vfsmount is shared having its own
424 peer group, and this peer-group is a slave of some other
425 peer group.
426
427 Only a slave vfsmount can be made as 'shared and slave' by
428 either executing the following command
429 mount --make-shared mount
430 or by moving the slave vfsmount under a shared vfsmount.
431
432 (4) Private mount
433
434 A 'private mount' is defined as vfsmount that does not
435 receive or forward any propagation events.
436
437 (5) Unbindable mount
438
439 A 'unbindable mount' is defined as vfsmount that does not
440 receive or forward any propagation events and cannot
441 be bind mounted.
442
443
444 State diagram:
445 The state diagram below explains the state transition of a mount,
446 in response to various commands.
447 ------------------------------------------------------------------------
448 | |make-shared | make-slave | make-private |make-unbindab|
449 --------------|------------|--------------|--------------|-------------|
450 |shared |shared |*slave/private| private | unbindable |
451 | | | | | |
452 |-------------|------------|--------------|--------------|-------------|
453 |slave |shared | **slave | private | unbindable |
454 | |and slave | | | |
455 |-------------|------------|--------------|--------------|-------------|
456 |shared |shared | slave | private | unbindable |
457 |and slave |and slave | | | |
458 |-------------|------------|--------------|--------------|-------------|
459 |private |shared | **private | private | unbindable |
460 |-------------|------------|--------------|--------------|-------------|
461 |unbindable |shared |**unbindable | private | unbindable |
462 ------------------------------------------------------------------------
463
464 * if the shared mount is the only mount in its peer group, making it
465 slave, makes it private automatically. Note that there is no master to
466 which it can be slaved to.
467
468 ** slaving a non-shared mount has no effect on the mount.
469
470 Apart from the commands listed below, the 'move' operation also changes
471 the state of a mount depending on type of the destination mount. Its
472 explained in section 5d.
473
4745b) Bind semantics
475
476 Consider the following command
477
478 mount --bind A/a B/b
479
480 where 'A' is the source mount, 'a' is the dentry in the mount 'A', 'B'
481 is the destination mount and 'b' is the dentry in the destination mount.
482
483 The outcome depends on the type of mount of 'A' and 'B'. The table
484 below contains quick reference.
485 ---------------------------------------------------------------------------
486 | BIND MOUNT OPERATION |
487 |**************************************************************************
488 |source(A)->| shared | private | slave | unbindable |
489 | dest(B) | | | | |
490 | | | | | | |
491 | v | | | | |
492 |**************************************************************************
493 | shared | shared | shared | shared & slave | invalid |
494 | | | | | |
495 |non-shared| shared | private | slave | invalid |
496 ***************************************************************************
497
498 Details:
499
500 1. 'A' is a shared mount and 'B' is a shared mount. A new mount 'C'
501 which is clone of 'A', is created. Its root dentry is 'a' . 'C' is
502 mounted on mount 'B' at dentry 'b'. Also new mount 'C1', 'C2', 'C3' ...
503 are created and mounted at the dentry 'b' on all mounts where 'B'
504 propagates to. A new propagation tree containing 'C1',..,'Cn' is
505 created. This propagation tree is identical to the propagation tree of
506 'B'. And finally the peer-group of 'C' is merged with the peer group
507 of 'A'.
508
509 2. 'A' is a private mount and 'B' is a shared mount. A new mount 'C'
510 which is clone of 'A', is created. Its root dentry is 'a'. 'C' is
511 mounted on mount 'B' at dentry 'b'. Also new mount 'C1', 'C2', 'C3' ...
512 are created and mounted at the dentry 'b' on all mounts where 'B'
513 propagates to. A new propagation tree is set containing all new mounts
514 'C', 'C1', .., 'Cn' with exactly the same configuration as the
515 propagation tree for 'B'.
516
517 3. 'A' is a slave mount of mount 'Z' and 'B' is a shared mount. A new
518 mount 'C' which is clone of 'A', is created. Its root dentry is 'a' .
519 'C' is mounted on mount 'B' at dentry 'b'. Also new mounts 'C1', 'C2',
520 'C3' ... are created and mounted at the dentry 'b' on all mounts where
521 'B' propagates to. A new propagation tree containing the new mounts
522 'C','C1',.. 'Cn' is created. This propagation tree is identical to the
523 propagation tree for 'B'. And finally the mount 'C' and its peer group
524 is made the slave of mount 'Z'. In other words, mount 'C' is in the
525 state 'slave and shared'.
526
527 4. 'A' is a unbindable mount and 'B' is a shared mount. This is a
528 invalid operation.
529
530 5. 'A' is a private mount and 'B' is a non-shared(private or slave or
531 unbindable) mount. A new mount 'C' which is clone of 'A', is created.
532 Its root dentry is 'a'. 'C' is mounted on mount 'B' at dentry 'b'.
533
534 6. 'A' is a shared mount and 'B' is a non-shared mount. A new mount 'C'
535 which is a clone of 'A' is created. Its root dentry is 'a'. 'C' is
536 mounted on mount 'B' at dentry 'b'. 'C' is made a member of the
537 peer-group of 'A'.
538
539 7. 'A' is a slave mount of mount 'Z' and 'B' is a non-shared mount. A
540 new mount 'C' which is a clone of 'A' is created. Its root dentry is
541 'a'. 'C' is mounted on mount 'B' at dentry 'b'. Also 'C' is set as a
542 slave mount of 'Z'. In other words 'A' and 'C' are both slave mounts of
543 'Z'. All mount/unmount events on 'Z' propagates to 'A' and 'C'. But
544 mount/unmount on 'A' do not propagate anywhere else. Similarly
545 mount/unmount on 'C' do not propagate anywhere else.
546
547 8. 'A' is a unbindable mount and 'B' is a non-shared mount. This is a
548 invalid operation. A unbindable mount cannot be bind mounted.
549
5505c) Rbind semantics
551
552 rbind is same as bind. Bind replicates the specified mount. Rbind
553 replicates all the mounts in the tree belonging to the specified mount.
554 Rbind mount is bind mount applied to all the mounts in the tree.
555
556 If the source tree that is rbind has some unbindable mounts,
557 then the subtree under the unbindable mount is pruned in the new
558 location.
559
560 eg: lets say we have the following mount tree.
561
562 A
563 / \
564 B C
565 / \ / \
566 D E F G
567
568 Lets say all the mount except the mount C in the tree are
569 of a type other than unbindable.
570
571 If this tree is rbound to say Z
572
573 We will have the following tree at the new location.
574
575 Z
576 |
577 A'
578 /
579 B' Note how the tree under C is pruned
580 / \ in the new location.
581 D' E'
582
583
584
5855d) Move semantics
586
587 Consider the following command
588
589 mount --move A B/b
590
591 where 'A' is the source mount, 'B' is the destination mount and 'b' is
592 the dentry in the destination mount.
593
594 The outcome depends on the type of the mount of 'A' and 'B'. The table
595 below is a quick reference.
596 ---------------------------------------------------------------------------
597 | MOVE MOUNT OPERATION |
598 |**************************************************************************
599 | source(A)->| shared | private | slave | unbindable |
600 | dest(B) | | | | |
601 | | | | | | |
602 | v | | | | |
603 |**************************************************************************
604 | shared | shared | shared |shared and slave| invalid |
605 | | | | | |
606 |non-shared| shared | private | slave | unbindable |
607 ***************************************************************************
608 NOTE: moving a mount residing under a shared mount is invalid.
609
610 Details follow:
611
612 1. 'A' is a shared mount and 'B' is a shared mount. The mount 'A' is
613 mounted on mount 'B' at dentry 'b'. Also new mounts 'A1', 'A2'...'An'
614 are created and mounted at dentry 'b' on all mounts that receive
615 propagation from mount 'B'. A new propagation tree is created in the
616 exact same configuration as that of 'B'. This new propagation tree
617 contains all the new mounts 'A1', 'A2'... 'An'. And this new
618 propagation tree is appended to the already existing propagation tree
619 of 'A'.
620
621 2. 'A' is a private mount and 'B' is a shared mount. The mount 'A' is
622 mounted on mount 'B' at dentry 'b'. Also new mount 'A1', 'A2'... 'An'
623 are created and mounted at dentry 'b' on all mounts that receive
624 propagation from mount 'B'. The mount 'A' becomes a shared mount and a
625 propagation tree is created which is identical to that of
626 'B'. This new propagation tree contains all the new mounts 'A1',
627 'A2'... 'An'.
628
629 3. 'A' is a slave mount of mount 'Z' and 'B' is a shared mount. The
630 mount 'A' is mounted on mount 'B' at dentry 'b'. Also new mounts 'A1',
631 'A2'... 'An' are created and mounted at dentry 'b' on all mounts that
632 receive propagation from mount 'B'. A new propagation tree is created
633 in the exact same configuration as that of 'B'. This new propagation
634 tree contains all the new mounts 'A1', 'A2'... 'An'. And this new
635 propagation tree is appended to the already existing propagation tree of
636 'A'. Mount 'A' continues to be the slave mount of 'Z' but it also
637 becomes 'shared'.
638
639 4. 'A' is a unbindable mount and 'B' is a shared mount. The operation
640 is invalid. Because mounting anything on the shared mount 'B' can
641 create new mounts that get mounted on the mounts that receive
642 propagation from 'B'. And since the mount 'A' is unbindable, cloning
643 it to mount at other mountpoints is not possible.
644
645 5. 'A' is a private mount and 'B' is a non-shared(private or slave or
646 unbindable) mount. The mount 'A' is mounted on mount 'B' at dentry 'b'.
647
648 6. 'A' is a shared mount and 'B' is a non-shared mount. The mount 'A'
649 is mounted on mount 'B' at dentry 'b'. Mount 'A' continues to be a
650 shared mount.
651
652 7. 'A' is a slave mount of mount 'Z' and 'B' is a non-shared mount.
653 The mount 'A' is mounted on mount 'B' at dentry 'b'. Mount 'A'
654 continues to be a slave mount of mount 'Z'.
655
656 8. 'A' is a unbindable mount and 'B' is a non-shared mount. The mount
657 'A' is mounted on mount 'B' at dentry 'b'. Mount 'A' continues to be a
658 unbindable mount.
659
6605e) Mount semantics
661
662 Consider the following command
663
664 mount device B/b
665
666 'B' is the destination mount and 'b' is the dentry in the destination
667 mount.
668
669 The above operation is the same as bind operation with the exception
670 that the source mount is always a private mount.
671
672
6735f) Unmount semantics
674
675 Consider the following command
676
677 umount A
678
679 where 'A' is a mount mounted on mount 'B' at dentry 'b'.
680
681 If mount 'B' is shared, then all most-recently-mounted mounts at dentry
682 'b' on mounts that receive propagation from mount 'B' and does not have
683 sub-mounts within them are unmounted.
684
685 Example: Lets say 'B1', 'B2', 'B3' are shared mounts that propagate to
686 each other.
687
688 lets say 'A1', 'A2', 'A3' are first mounted at dentry 'b' on mount
689 'B1', 'B2' and 'B3' respectively.
690
691 lets say 'C1', 'C2', 'C3' are next mounted at the same dentry 'b' on
692 mount 'B1', 'B2' and 'B3' respectively.
693
694 if 'C1' is unmounted, all the mounts that are most-recently-mounted on
695 'B1' and on the mounts that 'B1' propagates-to are unmounted.
696
697 'B1' propagates to 'B2' and 'B3'. And the most recently mounted mount
698 on 'B2' at dentry 'b' is 'C2', and that of mount 'B3' is 'C3'.
699
700 So all 'C1', 'C2' and 'C3' should be unmounted.
701
702 If any of 'C2' or 'C3' has some child mounts, then that mount is not
703 unmounted, but all other mounts are unmounted. However if 'C1' is told
704 to be unmounted and 'C1' has some sub-mounts, the umount operation is
705 failed entirely.
706
7075g) Clone Namespace
708
709 A cloned namespace contains all the mounts as that of the parent
710 namespace.
711
712 Lets say 'A' and 'B' are the corresponding mounts in the parent and the
713 child namespace.
714
715 If 'A' is shared, then 'B' is also shared and 'A' and 'B' propagate to
716 each other.
717
718 If 'A' is a slave mount of 'Z', then 'B' is also the slave mount of
719 'Z'.
720
721 If 'A' is a private mount, then 'B' is a private mount too.
722
723 If 'A' is unbindable mount, then 'B' is a unbindable mount too.
724
725
7266) Quiz
727
728 A. What is the result of the following command sequence?
729
730 mount --bind /mnt /mnt
731 mount --make-shared /mnt
732 mount --bind /mnt /tmp
733 mount --move /tmp /mnt/1
734
735 what should be the contents of /mnt /mnt/1 /mnt/1/1 should be?
736 Should they all be identical? or should /mnt and /mnt/1 be
737 identical only?
738
739
740 B. What is the result of the following command sequence?
741
742 mount --make-rshared /
743 mkdir -p /v/1
744 mount --rbind / /v/1
745
746 what should be the content of /v/1/v/1 be?
747
748
749 C. What is the result of the following command sequence?
750
751 mount --bind /mnt /mnt
752 mount --make-shared /mnt
753 mkdir -p /mnt/1/2/3 /mnt/1/test
754 mount --bind /mnt/1 /tmp
755 mount --make-slave /mnt
756 mount --make-shared /mnt
757 mount --bind /mnt/1/2 /tmp1
758 mount --make-slave /mnt
759
760 At this point we have the first mount at /tmp and
761 its root dentry is 1. Lets call this mount 'A'
762 And then we have a second mount at /tmp1 with root
763 dentry 2. Lets call this mount 'B'
764 Next we have a third mount at /mnt with root dentry
765 mnt. Lets call this mount 'C'
766
767 'B' is the slave of 'A' and 'C' is a slave of 'B'
768 A -> B -> C
769
770 at this point if we execute the following command
771
772 mount --bind /bin /tmp/test
773
774 The mount is attempted on 'A'
775
776 will the mount propagate to 'B' and 'C' ?
777
778 what would be the contents of
779 /mnt/1/test be?
780
7817) FAQ
782
783 Q1. Why is bind mount needed? How is it different from symbolic links?
784 symbolic links can get stale if the destination mount gets
785 unmounted or moved. Bind mounts continue to exist even if the
786 other mount is unmounted or moved.
787
788 Q2. Why can't the shared subtree be implemented using exportfs?
789
790 exportfs is a heavyweight way of accomplishing part of what
791 shared subtree can do. I cannot imagine a way to implement the
792 semantics of slave mount using exportfs?
793
794 Q3 Why is unbindable mount needed?
795
796 Lets say we want to replicate the mount tree at multiple
797 locations within the same subtree.
798
799 if one rbind mounts a tree within the same subtree 'n' times
800 the number of mounts created is an exponential function of 'n'.
801 Having unbindable mount can help prune the unneeded bind
802 mounts. Here is a example.
803
804 step 1:
805 lets say the root tree has just two directories with
806 one vfsmount.
807 root
808 / \
809 tmp usr
810
811 And we want to replicate the tree at multiple
812 mountpoints under /root/tmp
813
814 step2:
815 mount --make-shared /root
816
817 mkdir -p /tmp/m1
818
819 mount --rbind /root /tmp/m1
820
821 the new tree now looks like this:
822
823 root
824 / \
825 tmp usr
826 /
827 m1
828 / \
829 tmp usr
830 /
831 m1
832
833 it has two vfsmounts
834
835 step3:
836 mkdir -p /tmp/m2
837 mount --rbind /root /tmp/m2
838
839 the new tree now looks like this:
840
841 root
842 / \
843 tmp usr
844 / \
845 m1 m2
846 / \ / \
847 tmp usr tmp usr
848 / \ /
849 m1 m2 m1
850 / \ / \
851 tmp usr tmp usr
852 / / \
853 m1 m1 m2
854 / \
855 tmp usr
856 / \
857 m1 m2
858
859 it has 6 vfsmounts
860
861 step 4:
862 mkdir -p /tmp/m3
863 mount --rbind /root /tmp/m3
864
865 I wont' draw the tree..but it has 24 vfsmounts
866
867
868 at step i the number of vfsmounts is V[i] = i*V[i-1].
869 This is an exponential function. And this tree has way more
870 mounts than what we really needed in the first place.
871
872 One could use a series of umount at each step to prune
873 out the unneeded mounts. But there is a better solution.
874 Unclonable mounts come in handy here.
875
876 step 1:
877 lets say the root tree has just two directories with
878 one vfsmount.
879 root
880 / \
881 tmp usr
882
883 How do we set up the same tree at multiple locations under
884 /root/tmp
885
886 step2:
887 mount --bind /root/tmp /root/tmp
888
889 mount --make-rshared /root
890 mount --make-unbindable /root/tmp
891
892 mkdir -p /tmp/m1
893
894 mount --rbind /root /tmp/m1
895
896 the new tree now looks like this:
897
898 root
899 / \
900 tmp usr
901 /
902 m1
903 / \
904 tmp usr
905
906 step3:
907 mkdir -p /tmp/m2
908 mount --rbind /root /tmp/m2
909
910 the new tree now looks like this:
911
912 root
913 / \
914 tmp usr
915 / \
916 m1 m2
917 / \ / \
918 tmp usr tmp usr
919
920 step4:
921
922 mkdir -p /tmp/m3
923 mount --rbind /root /tmp/m3
924
925 the new tree now looks like this:
926
927 root
928 / \
929 tmp usr
930 / \ \
931 m1 m2 m3
932 / \ / \ / \
933 tmp usr tmp usr tmp usr
934
9358) Implementation
936
9378A) Datastructure
938
939 4 new fields are introduced to struct vfsmount
940 ->mnt_share
941 ->mnt_slave_list
942 ->mnt_slave
943 ->mnt_master
944
945 ->mnt_share links togather all the mount to/from which this vfsmount
946 send/receives propagation events.
947
948 ->mnt_slave_list links all the mounts to which this vfsmount propagates
949 to.
950
951 ->mnt_slave links togather all the slaves that its master vfsmount
952 propagates to.
953
954 ->mnt_master points to the master vfsmount from which this vfsmount
955 receives propagation.
956
957 ->mnt_flags takes two more flags to indicate the propagation status of
958 the vfsmount. MNT_SHARE indicates that the vfsmount is a shared
959 vfsmount. MNT_UNCLONABLE indicates that the vfsmount cannot be
960 replicated.
961
962 All the shared vfsmounts in a peer group form a cyclic list through
963 ->mnt_share.
964
965 All vfsmounts with the same ->mnt_master form on a cyclic list anchored
966 in ->mnt_master->mnt_slave_list and going through ->mnt_slave.
967
968 ->mnt_master can point to arbitrary (and possibly different) members
969 of master peer group. To find all immediate slaves of a peer group
970 you need to go through _all_ ->mnt_slave_list of its members.
971 Conceptually it's just a single set - distribution among the
972 individual lists does not affect propagation or the way propagation
973 tree is modified by operations.
974
975 A example propagation tree looks as shown in the figure below.
976 [ NOTE: Though it looks like a forest, if we consider all the shared
977 mounts as a conceptual entity called 'pnode', it becomes a tree]
978
979
980 A <--> B <--> C <---> D
981 /|\ /| |\
982 / F G J K H I
983 /
984 E<-->K
985 /|\
986 M L N
987
988 In the above figure A,B,C and D all are shared and propagate to each
989 other. 'A' has got 3 slave mounts 'E' 'F' and 'G' 'C' has got 2 slave
990 mounts 'J' and 'K' and 'D' has got two slave mounts 'H' and 'I'.
991 'E' is also shared with 'K' and they propagate to each other. And
992 'K' has 3 slaves 'M', 'L' and 'N'
993
994 A's ->mnt_share links with the ->mnt_share of 'B' 'C' and 'D'
995
996 A's ->mnt_slave_list links with ->mnt_slave of 'E', 'K', 'F' and 'G'
997
998 E's ->mnt_share links with ->mnt_share of K
999 'E', 'K', 'F', 'G' have their ->mnt_master point to struct
1000 vfsmount of 'A'
1001 'M', 'L', 'N' have their ->mnt_master point to struct vfsmount of 'K'
1002 K's ->mnt_slave_list links with ->mnt_slave of 'M', 'L' and 'N'
1003
1004 C's ->mnt_slave_list links with ->mnt_slave of 'J' and 'K'
1005 J and K's ->mnt_master points to struct vfsmount of C
1006 and finally D's ->mnt_slave_list links with ->mnt_slave of 'H' and 'I'
1007 'H' and 'I' have their ->mnt_master pointing to struct vfsmount of 'D'.
1008
1009
1010 NOTE: The propagation tree is orthogonal to the mount tree.
1011
1012
10138B Algorithm:
1014
1015 The crux of the implementation resides in rbind/move operation.
1016
1017 The overall algorithm breaks the operation into 3 phases: (look at
1018 attach_recursive_mnt() and propagate_mnt())
1019
1020 1. prepare phase.
1021 2. commit phases.
1022 3. abort phases.
1023
1024 Prepare phase:
1025
1026 for each mount in the source tree:
1027 a) Create the necessary number of mount trees to
1028 be attached to each of the mounts that receive
1029 propagation from the destination mount.
1030 b) Do not attach any of the trees to its destination.
1031 However note down its ->mnt_parent and ->mnt_mountpoint
1032 c) Link all the new mounts to form a propagation tree that
1033 is identical to the propagation tree of the destination
1034 mount.
1035
1036 If this phase is successful, there should be 'n' new
1037 propagation trees; where 'n' is the number of mounts in the
1038 source tree. Go to the commit phase
1039
1040 Also there should be 'm' new mount trees, where 'm' is
1041 the number of mounts to which the destination mount
1042 propagates to.
1043
1044 if any memory allocations fail, go to the abort phase.
1045
1046 Commit phase
1047 attach each of the mount trees to their corresponding
1048 destination mounts.
1049
1050 Abort phase
1051 delete all the newly created trees.
1052
1053 NOTE: all the propagation related functionality resides in the file
1054 pnode.c
1055
1056
1057------------------------------------------------------------------------
1058
1059version 0.1 (created the initial document, Ram Pai linuxram@us.ibm.com)
1060version 0.2 (Incorporated comments from Al Viro)
diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
index 13cba955cb5a..2f27f391c7cc 100644
--- a/Documentation/sound/alsa/ALSA-Configuration.txt
+++ b/Documentation/sound/alsa/ALSA-Configuration.txt
@@ -167,7 +167,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
167 spdif - Support SPDIF I/O 167 spdif - Support SPDIF I/O
168 - Default: disabled 168 - Default: disabled
169 169
170 Module supports autoprobe and multiple chips (max 8). 170 This module supports one chip and autoprobe.
171 171
172 The power-management is supported. 172 The power-management is supported.
173 173
@@ -206,7 +206,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
206 See "AC97 Quirk Option" section below. 206 See "AC97 Quirk Option" section below.
207 spdif_aclink - S/PDIF transfer over AC-link (default = 1) 207 spdif_aclink - S/PDIF transfer over AC-link (default = 1)
208 208
209 This module supports up to 8 cards and autoprobe. 209 This module supports one card and autoprobe.
210 210
211 ATI IXP has two different methods to control SPDIF output. One is 211 ATI IXP has two different methods to control SPDIF output. One is
212 over AC-link and another is over the "direct" SPDIF output. The 212 over AC-link and another is over the "direct" SPDIF output. The
@@ -218,7 +218,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
218 218
219 Module for ATI IXP 150/200/250 AC97 modem controllers. 219 Module for ATI IXP 150/200/250 AC97 modem controllers.
220 220
221 Module supports up to 8 cards. 221 This module supports one card and autoprobe.
222 222
223 Note: The default index value of this module is -2, i.e. the first 223 Note: The default index value of this module is -2, i.e. the first
224 slot is excluded. 224 slot is excluded.
@@ -637,7 +637,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
637 model - force the model name 637 model - force the model name
638 position_fix - Fix DMA pointer (0 = auto, 1 = none, 2 = POSBUF, 3 = FIFO size) 638 position_fix - Fix DMA pointer (0 = auto, 1 = none, 2 = POSBUF, 3 = FIFO size)
639 639
640 Module supports up to 8 cards. 640 This module supports one card and autoprobe.
641 641
642 Each codec may have a model table for different configurations. 642 Each codec may have a model table for different configurations.
643 If your machine isn't listed there, the default (usually minimal) 643 If your machine isn't listed there, the default (usually minimal)
@@ -663,6 +663,10 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
663 adjusted. Appearing only when compiled with 663 adjusted. Appearing only when compiled with
664 $CONFIG_SND_DEBUG=y 664 $CONFIG_SND_DEBUG=y
665 665
666 ALC260
667 hp HP machines
668 fujitsu Fujitsu S7020
669
666 CMI9880 670 CMI9880
667 minimal 3-jack in back 671 minimal 3-jack in back
668 min_fp 3-jack in back, 2-jack in front 672 min_fp 3-jack in back, 2-jack in front
@@ -811,7 +815,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
811 semaphores (e.g. on some ASUS laptops) 815 semaphores (e.g. on some ASUS laptops)
812 (default off) 816 (default off)
813 817
814 Module supports autoprobe and multiple bus-master chips (max 8). 818 This module supports one chip and autoprobe.
815 819
816 Note: the latest driver supports auto-detection of chip clock. 820 Note: the latest driver supports auto-detection of chip clock.
817 if you still encounter too fast playback, specify the clock 821 if you still encounter too fast playback, specify the clock
@@ -830,7 +834,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
830 834
831 ac97_clock - AC'97 codec clock base (0 = auto-detect) 835 ac97_clock - AC'97 codec clock base (0 = auto-detect)
832 836
833 This module supports up to 8 cards and autoprobe. 837 This module supports one card and autoprobe.
834 838
835 Note: The default index value of this module is -2, i.e. the first 839 Note: The default index value of this module is -2, i.e. the first
836 slot is excluded. 840 slot is excluded.
@@ -950,8 +954,10 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
950 use_cache - 0 or 1 (disabled by default) 954 use_cache - 0 or 1 (disabled by default)
951 vaio_hack - alias buffer_top=0x25a800 955 vaio_hack - alias buffer_top=0x25a800
952 reset_workaround - enable AC97 RESET workaround for some laptops 956 reset_workaround - enable AC97 RESET workaround for some laptops
957 reset_workaround2 - enable extended AC97 RESET workaround for some
958 other laptops
953 959
954 Module supports autoprobe and multiple chips (max 8). 960 This module supports one chip and autoprobe.
955 961
956 The power-management is supported. 962 The power-management is supported.
957 963
@@ -980,6 +986,11 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
980 workaround is enabled automatically. For other laptops with a 986 workaround is enabled automatically. For other laptops with a
981 hard freeze, you can try reset_workaround=1 option. 987 hard freeze, you can try reset_workaround=1 option.
982 988
989 Note: Dell Latitude CSx laptops have another problem regarding
990 AC97 RESET. On these laptops, reset_workaround2 option is
991 turned on as default. This option is worth to try if the
992 previous reset_workaround option doesn't help.
993
983 Note: This driver is really crappy. It's a porting from the 994 Note: This driver is really crappy. It's a porting from the
984 OSS driver, which is a result of black-magic reverse engineering. 995 OSS driver, which is a result of black-magic reverse engineering.
985 The detection of codec will fail if the driver is loaded *after* 996 The detection of codec will fail if the driver is loaded *after*
@@ -1310,7 +1321,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
1310 ac97_quirk - AC'97 workaround for strange hardware 1321 ac97_quirk - AC'97 workaround for strange hardware
1311 See "AC97 Quirk Option" section below. 1322 See "AC97 Quirk Option" section below.
1312 1323
1313 Module supports autoprobe and multiple bus-master chips (max 8). 1324 This module supports one chip and autoprobe.
1314 1325
1315 Note: on some SMP motherboards like MSI 694D the interrupts might 1326 Note: on some SMP motherboards like MSI 694D the interrupts might
1316 not be generated properly. In such a case, please try to 1327 not be generated properly. In such a case, please try to
@@ -1352,7 +1363,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
1352 1363
1353 ac97_clock - AC'97 codec clock base (default 48000Hz) 1364 ac97_clock - AC'97 codec clock base (default 48000Hz)
1354 1365
1355 Module supports up to 8 cards. 1366 This module supports one card and autoprobe.
1356 1367
1357 Note: The default index value of this module is -2, i.e. the first 1368 Note: The default index value of this module is -2, i.e. the first
1358 slot is excluded. 1369 slot is excluded.
diff --git a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl b/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
index 24e85520890b..260334c98d95 100644
--- a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
+++ b/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
@@ -18,8 +18,8 @@
18 </affiliation> 18 </affiliation>
19 </author> 19 </author>
20 20
21 <date>March 6, 2005</date> 21 <date>October 6, 2005</date>
22 <edition>0.3.4</edition> 22 <edition>0.3.5</edition>
23 23
24 <abstract> 24 <abstract>
25 <para> 25 <para>
@@ -30,7 +30,7 @@
30 30
31 <legalnotice> 31 <legalnotice>
32 <para> 32 <para>
33 Copyright (c) 2002-2004 Takashi Iwai <email>tiwai@suse.de</email> 33 Copyright (c) 2002-2005 Takashi Iwai <email>tiwai@suse.de</email>
34 </para> 34 </para>
35 35
36 <para> 36 <para>
@@ -1433,25 +1433,10 @@
1433 <informalexample> 1433 <informalexample>
1434 <programlisting> 1434 <programlisting>
1435<![CDATA[ 1435<![CDATA[
1436 if (chip->res_port) { 1436 release_and_free_resource(chip->res_port);
1437 release_resource(chip->res_port);
1438 kfree_nocheck(chip->res_port);
1439 }
1440]]> 1437]]>
1441 </programlisting> 1438 </programlisting>
1442 </informalexample> 1439 </informalexample>
1443
1444 As you can see, the resource pointer is also to be freed
1445 via <function>kfree_nocheck()</function> after
1446 <function>release_resource()</function> is called. You
1447 cannot use <function>kfree()</function> here, because on ALSA,
1448 <function>kfree()</function> may be a wrapper to its own
1449 allocator with the memory debugging. Since the resource pointer
1450 is allocated externally outside the ALSA, it must be released
1451 via the native
1452 <function>kfree()</function>.
1453 <function>kfree_nocheck()</function> is used for that; it calls
1454 the native <function>kfree()</function> without wrapper.
1455 </para> 1440 </para>
1456 1441
1457 <para> 1442 <para>
@@ -2190,8 +2175,7 @@ struct _snd_pcm_runtime {
2190 unsigned int rate_den; 2175 unsigned int rate_den;
2191 2176
2192 /* -- SW params -- */ 2177 /* -- SW params -- */
2193 int tstamp_timespec; /* use timeval (0) or timespec (1) */ 2178 struct timespec tstamp_mode; /* mmap timestamp is updated */
2194 snd_pcm_tstamp_t tstamp_mode; /* mmap timestamp is updated */
2195 unsigned int period_step; 2179 unsigned int period_step;
2196 unsigned int sleep_min; /* min ticks to sleep */ 2180 unsigned int sleep_min; /* min ticks to sleep */
2197 snd_pcm_uframes_t xfer_align; /* xfer size need to be a multiple */ 2181 snd_pcm_uframes_t xfer_align; /* xfer size need to be a multiple */
@@ -3709,8 +3693,7 @@ struct _snd_pcm_runtime {
3709 <para> 3693 <para>
3710 Here, the chip instance is retrieved via 3694 Here, the chip instance is retrieved via
3711 <function>snd_kcontrol_chip()</function> macro. This macro 3695 <function>snd_kcontrol_chip()</function> macro. This macro
3712 converts from kcontrol-&gt;private_data to the type defined by 3696 just accesses to kcontrol-&gt;private_data. The
3713 <type>chip_t</type>. The
3714 kcontrol-&gt;private_data field is 3697 kcontrol-&gt;private_data field is
3715 given as the argument of <function>snd_ctl_new()</function> 3698 given as the argument of <function>snd_ctl_new()</function>
3716 (see the later subsection 3699 (see the later subsection
@@ -5998,32 +5981,23 @@ struct _snd_pcm_runtime {
5998 The first argument is the expression to evaluate, and the 5981 The first argument is the expression to evaluate, and the
5999 second argument is the action if it fails. When 5982 second argument is the action if it fails. When
6000 <constant>CONFIG_SND_DEBUG</constant>, is set, it will show an 5983 <constant>CONFIG_SND_DEBUG</constant>, is set, it will show an
6001 error message such as <computeroutput>BUG? (xxx) (called from 5984 error message such as <computeroutput>BUG? (xxx)</computeroutput>
6002 yyy)</computeroutput>. When no debug flag is set, this is 5985 together with stack trace.
6003 ignored.
6004 </para> 5986 </para>
6005 </section>
6006
6007 <section id="useful-functions-snd-runtime-check">
6008 <title><function>snd_runtime_check()</function></title>
6009 <para> 5987 <para>
6010 This macro is quite similar with 5988 When no debug flag is set, this macro is ignored.
6011 <function>snd_assert()</function>. Unlike
6012 <function>snd_assert()</function>, the expression is always
6013 evaluated regardless of
6014 <constant>CONFIG_SND_DEBUG</constant>. When
6015 <constant>CONFIG_SND_DEBUG</constant> is set, the macro will
6016 show a message like <computeroutput>ERROR (xx) (called from
6017 yyy)</computeroutput>.
6018 </para> 5989 </para>
6019 </section> 5990 </section>
6020 5991
6021 <section id="useful-functions-snd-bug"> 5992 <section id="useful-functions-snd-bug">
6022 <title><function>snd_BUG()</function></title> 5993 <title><function>snd_BUG()</function></title>
6023 <para> 5994 <para>
6024 It calls <function>snd_assert(0,)</function> -- that is, just 5995 It shows <computeroutput>BUG?</computeroutput> message and
6025 prints the error message at the point. It's useful to show that 5996 stack trace as well as <function>snd_assert</function> at the point.
6026 a fatal error happens there. 5997 It's useful to show that a fatal error happens there.
5998 </para>
5999 <para>
6000 When no debug flag is set, this macro is ignored.
6027 </para> 6001 </para>
6028 </section> 6002 </section>
6029 </chapter> 6003 </chapter>
diff --git a/Documentation/sparse.txt b/Documentation/sparse.txt
index 1829009db771..3f1c5464b1c9 100644
--- a/Documentation/sparse.txt
+++ b/Documentation/sparse.txt
@@ -41,9 +41,9 @@ sure that bitwise types don't get mixed up (little-endian vs big-endian
41vs cpu-endian vs whatever), and there the constant "0" really _is_ 41vs cpu-endian vs whatever), and there the constant "0" really _is_
42special. 42special.
43 43
44Modify top-level Makefile to say 44Use
45 45
46CHECK = sparse -Wbitwise 46 make C=[12] CF=-Wbitwise
47 47
48or you don't get any checking at all. 48or you don't get any checking at all.
49 49
diff --git a/Documentation/video4linux/bttv/README.freeze b/Documentation/video4linux/bttv/README.freeze
index 51f8d4379a94..4259dccc8287 100644
--- a/Documentation/video4linux/bttv/README.freeze
+++ b/Documentation/video4linux/bttv/README.freeze
@@ -27,9 +27,9 @@ information out of a register+stack dump printed by the kernel on
27protection faults (so-called "kernel oops"). 27protection faults (so-called "kernel oops").
28 28
29If you run into some kind of deadlock, you can try to dump a call trace 29If you run into some kind of deadlock, you can try to dump a call trace
30for each process using sysrq-t (see Documentation/sysrq.txt). ksymoops 30for each process using sysrq-t (see Documentation/sysrq.txt).
31will translate these dumps into kernel symbols too. This way it is 31This way it is possible to figure where *exactly* some process in "D"
32possible to figure where *exactly* some process in "D" state is stuck. 32state is stuck.
33 33
34I've seen reports that bttv 0.7.x crashes whereas 0.8.x works rock solid 34I've seen reports that bttv 0.7.x crashes whereas 0.8.x works rock solid
35for some people. Thus probably a small buglet left somewhere in bttv 35for some people. Thus probably a small buglet left somewhere in bttv
diff --git a/Documentation/vm/hugetlbpage.txt b/Documentation/vm/hugetlbpage.txt
index 1b9bcd1fe98b..1ad9af1ca4d0 100644
--- a/Documentation/vm/hugetlbpage.txt
+++ b/Documentation/vm/hugetlbpage.txt
@@ -13,12 +13,13 @@ This optimization is more critical now as bigger and bigger physical memories
13Users can use the huge page support in Linux kernel by either using the mmap 13Users can use the huge page support in Linux kernel by either using the mmap
14system call or standard SYSv shared memory system calls (shmget, shmat). 14system call or standard SYSv shared memory system calls (shmget, shmat).
15 15
16First the Linux kernel needs to be built with CONFIG_HUGETLB_PAGE (present 16First the Linux kernel needs to be built with the CONFIG_HUGETLBFS
17under Processor types and feature) and CONFIG_HUGETLBFS (present under file 17(present under "File systems") and CONFIG_HUGETLB_PAGE (selected
18system option on config menu) config options. 18automatically when CONFIG_HUGETLBFS is selected) configuration
19options.
19 20
20The kernel built with hugepage support should show the number of configured 21The kernel built with hugepage support should show the number of configured
21hugepages in the system by running the "cat /proc/meminfo" command. 22hugepages in the system by running the "cat /proc/meminfo" command.
22 23
23/proc/meminfo also provides information about the total number of hugetlb 24/proc/meminfo also provides information about the total number of hugetlb
24pages configured in the kernel. It also displays information about the 25pages configured in the kernel. It also displays information about the
@@ -38,19 +39,19 @@ in the kernel.
38 39
39/proc/sys/vm/nr_hugepages indicates the current number of configured hugetlb 40/proc/sys/vm/nr_hugepages indicates the current number of configured hugetlb
40pages in the kernel. Super user can dynamically request more (or free some 41pages in the kernel. Super user can dynamically request more (or free some
41pre-configured) hugepages. 42pre-configured) hugepages.
42The allocation( or deallocation) of hugetlb pages is posible only if there are 43The allocation (or deallocation) of hugetlb pages is possible only if there are
43enough physically contiguous free pages in system (freeing of hugepages is 44enough physically contiguous free pages in system (freeing of hugepages is
44possible only if there are enough hugetlb pages free that can be transfered 45possible only if there are enough hugetlb pages free that can be transfered
45back to regular memory pool). 46back to regular memory pool).
46 47
47Pages that are used as hugetlb pages are reserved inside the kernel and can 48Pages that are used as hugetlb pages are reserved inside the kernel and can
48not be used for other purposes. 49not be used for other purposes.
49 50
50Once the kernel with Hugetlb page support is built and running, a user can 51Once the kernel with Hugetlb page support is built and running, a user can
51use either the mmap system call or shared memory system calls to start using 52use either the mmap system call or shared memory system calls to start using
52the huge pages. It is required that the system administrator preallocate 53the huge pages. It is required that the system administrator preallocate
53enough memory for huge page purposes. 54enough memory for huge page purposes.
54 55
55Use the following command to dynamically allocate/deallocate hugepages: 56Use the following command to dynamically allocate/deallocate hugepages:
56 57
@@ -80,9 +81,9 @@ memory (huge pages) allowed for that filesystem (/mnt/huge). The size is
80rounded down to HPAGE_SIZE. The option nr_inode sets the maximum number of 81rounded down to HPAGE_SIZE. The option nr_inode sets the maximum number of
81inodes that /mnt/huge can use. If the size or nr_inode options are not 82inodes that /mnt/huge can use. If the size or nr_inode options are not
82provided on command line then no limits are set. For size and nr_inodes 83provided on command line then no limits are set. For size and nr_inodes
83options, you can use [G|g]/[M|m]/[K|k] to represent giga/mega/kilo. For 84options, you can use [G|g]/[M|m]/[K|k] to represent giga/mega/kilo. For
84example, size=2K has the same meaning as size=2048. An example is given at 85example, size=2K has the same meaning as size=2048. An example is given at
85the end of this document. 86the end of this document.
86 87
87read and write system calls are not supported on files that reside on hugetlb 88read and write system calls are not supported on files that reside on hugetlb
88file systems. 89file systems.
diff --git a/MAINTAINERS b/MAINTAINERS
index d57c491212b1..995bfd8e6e7f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1077,6 +1077,26 @@ P: Jaroslav Kysela
1077M: perex@suse.cz 1077M: perex@suse.cz
1078S: Maintained 1078S: Maintained
1079 1079
1080HPET: High Precision Event Timers driver (hpet.c)
1081P: Clemens Ladisch
1082M: clemens@ladisch.de
1083S: Maintained
1084
1085HPET: i386
1086P: Venkatesh Pallipadi (Venki)
1087M: venkatesh.pallipadi@intel.com
1088S: Maintained
1089
1090HPET: x86_64
1091P: Andi Kleen and Vojtech Pavlik
1092M: ak@muc.de and vojtech@suse.cz
1093S: Maintained
1094
1095HPET: ACPI hpet.c
1096P: Bob Picco
1097M: bob.picco@hp.com
1098S: Maintained
1099
1080HPFS FILESYSTEM 1100HPFS FILESYSTEM
1081P: Mikulas Patocka 1101P: Mikulas Patocka
1082M: mikulas@artax.karlin.mff.cuni.cz 1102M: mikulas@artax.karlin.mff.cuni.cz
@@ -2051,6 +2071,12 @@ P: Matt Mackall
2051M: mpm@selenic.com 2071M: mpm@selenic.com
2052S: Maintained 2072S: Maintained
2053 2073
2074RAPIDIO SUBSYSTEM
2075P: Matt Porter
2076M: mporter@kernel.crashing.org
2077L: linux-kernel@vger.kernel.org
2078S: Maintained
2079
2054REAL TIME CLOCK DRIVER 2080REAL TIME CLOCK DRIVER
2055P: Paul Gortmaker 2081P: Paul Gortmaker
2056M: p_gortmaker@yahoo.com 2082M: p_gortmaker@yahoo.com
@@ -2455,10 +2481,10 @@ L: linux-kernel@vger.kernel.org
2455S: Maintained 2481S: Maintained
2456 2482
2457TRIVIAL PATCHES 2483TRIVIAL PATCHES
2458P: Rusty Russell 2484P: Adrian Bunk
2459M: trivial@rustcorp.com.au 2485M: trivial@kernel.org
2460L: linux-kernel@vger.kernel.org 2486L: linux-kernel@vger.kernel.org
2461W: http://www.kernel.org/pub/linux/kernel/people/rusty/trivial/ 2487W: http://www.kernel.org/pub/linux/kernel/people/bunk/trivial/
2462S: Maintained 2488S: Maintained
2463 2489
2464TMS380 TOKEN-RING NETWORK DRIVER 2490TMS380 TOKEN-RING NETWORK DRIVER
diff --git a/Makefile b/Makefile
index 2dac8010c142..ea96da1572d5 100644
--- a/Makefile
+++ b/Makefile
@@ -583,7 +583,7 @@ export MODLIB
583 583
584 584
585ifeq ($(KBUILD_EXTMOD),) 585ifeq ($(KBUILD_EXTMOD),)
586core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ 586core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
587 587
588vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ 588vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
589 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ 589 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 296bc03d1cf1..91d5ef3397be 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -324,7 +324,7 @@ menu "Kernel Features"
324 324
325config SMP 325config SMP
326 bool "Symmetric Multi-Processing (EXPERIMENTAL)" 326 bool "Symmetric Multi-Processing (EXPERIMENTAL)"
327 depends on EXPERIMENTAL && BROKEN #&& n 327 depends on EXPERIMENTAL && REALVIEW_MPCORE
328 help 328 help
329 This enables support for systems with more than one CPU. If you have 329 This enables support for systems with more than one CPU. If you have
330 a system with only one CPU, like most personal computers, say N. If 330 a system with only one CPU, like most personal computers, say N. If
@@ -585,7 +585,7 @@ config FPE_NWFPE
585 585
586config FPE_NWFPE_XP 586config FPE_NWFPE_XP
587 bool "Support extended precision" 587 bool "Support extended precision"
588 depends on FPE_NWFPE && !CPU_BIG_ENDIAN 588 depends on FPE_NWFPE
589 help 589 help
590 Say Y to include 80-bit support in the kernel floating-point 590 Say Y to include 80-bit support in the kernel floating-point
591 emulator. Otherwise, only 32 and 64-bit support is compiled in. 591 emulator. Otherwise, only 32 and 64-bit support is compiled in.
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index 9bd8609a2926..9a340e790da5 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -648,7 +648,7 @@ static int ptrace_setwmmxregs(struct task_struct *tsk, void __user *ufp)
648 648
649#endif 649#endif
650 650
651static int do_ptrace(int request, struct task_struct *child, long addr, long data) 651long arch_ptrace(struct task_struct *child, long request, long addr, long data)
652{ 652{
653 unsigned long tmp; 653 unsigned long tmp;
654 int ret; 654 int ret;
@@ -782,53 +782,6 @@ static int do_ptrace(int request, struct task_struct *child, long addr, long dat
782 return ret; 782 return ret;
783} 783}
784 784
785asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
786{
787 struct task_struct *child;
788 int ret;
789
790 lock_kernel();
791 ret = -EPERM;
792 if (request == PTRACE_TRACEME) {
793 /* are we already being traced? */
794 if (current->ptrace & PT_PTRACED)
795 goto out;
796 ret = security_ptrace(current->parent, current);
797 if (ret)
798 goto out;
799 /* set the ptrace bit in the process flags. */
800 current->ptrace |= PT_PTRACED;
801 ret = 0;
802 goto out;
803 }
804 ret = -ESRCH;
805 read_lock(&tasklist_lock);
806 child = find_task_by_pid(pid);
807 if (child)
808 get_task_struct(child);
809 read_unlock(&tasklist_lock);
810 if (!child)
811 goto out;
812
813 ret = -EPERM;
814 if (pid == 1) /* you may not mess with init */
815 goto out_tsk;
816
817 if (request == PTRACE_ATTACH) {
818 ret = ptrace_attach(child);
819 goto out_tsk;
820 }
821 ret = ptrace_check_attach(child, request == PTRACE_KILL);
822 if (ret == 0)
823 ret = do_ptrace(request, child, addr, data);
824
825out_tsk:
826 put_task_struct(child);
827out:
828 unlock_kernel();
829 return ret;
830}
831
832asmlinkage void syscall_trace(int why, struct pt_regs *regs) 785asmlinkage void syscall_trace(int why, struct pt_regs *regs)
833{ 786{
834 unsigned long ip; 787 unsigned long ip;
diff --git a/arch/arm/mach-aaec2000/clock.c b/arch/arm/mach-aaec2000/clock.c
index 99e019169dda..0340ddc4824e 100644
--- a/arch/arm/mach-aaec2000/clock.c
+++ b/arch/arm/mach-aaec2000/clock.c
@@ -14,6 +14,7 @@
14#include <linux/list.h> 14#include <linux/list.h>
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/string.h>
17 18
18#include <asm/semaphore.h> 19#include <asm/semaphore.h>
19#include <asm/hardware/clock.h> 20#include <asm/hardware/clock.h>
diff --git a/arch/arm/mach-epxa10db/mm.c b/arch/arm/mach-epxa10db/mm.c
index e8832d0910ee..cfd0d2182d44 100644
--- a/arch/arm/mach-epxa10db/mm.c
+++ b/arch/arm/mach-epxa10db/mm.c
@@ -25,6 +25,7 @@
25#include <asm/hardware.h> 25#include <asm/hardware.h>
26#include <asm/io.h> 26#include <asm/io.h>
27#include <asm/sizes.h> 27#include <asm/sizes.h>
28#include <asm/page.h>
28 29
29#include <asm/mach/map.h> 30#include <asm/mach/map.h>
30 31
diff --git a/arch/arm/mach-integrator/impd1.c b/arch/arm/mach-integrator/impd1.c
index a1b153d1626c..a4bafee77a06 100644
--- a/arch/arm/mach-integrator/impd1.c
+++ b/arch/arm/mach-integrator/impd1.c
@@ -420,8 +420,7 @@ static int impd1_probe(struct lm_device *dev)
420 free_impd1: 420 free_impd1:
421 if (impd1 && impd1->base) 421 if (impd1 && impd1->base)
422 iounmap(impd1->base); 422 iounmap(impd1->base);
423 if (impd1) 423 kfree(impd1);
424 kfree(impd1);
425 release_lm: 424 release_lm:
426 release_mem_region(dev->resource.start, SZ_4K); 425 release_mem_region(dev->resource.start, SZ_4K);
427 return ret; 426 return ret;
diff --git a/arch/arm/mach-ixp2000/core.c b/arch/arm/mach-ixp2000/core.c
index df140962bb0f..6851abaf5524 100644
--- a/arch/arm/mach-ixp2000/core.c
+++ b/arch/arm/mach-ixp2000/core.c
@@ -84,63 +84,54 @@ static struct map_desc ixp2000_io_desc[] __initdata = {
84 .virtual = IXP2000_CAP_VIRT_BASE, 84 .virtual = IXP2000_CAP_VIRT_BASE,
85 .pfn = __phys_to_pfn(IXP2000_CAP_PHYS_BASE), 85 .pfn = __phys_to_pfn(IXP2000_CAP_PHYS_BASE),
86 .length = IXP2000_CAP_SIZE, 86 .length = IXP2000_CAP_SIZE,
87 .type = MT_DEVICE 87 .type = MT_IXP2000_DEVICE,
88 }, { 88 }, {
89 .virtual = IXP2000_INTCTL_VIRT_BASE, 89 .virtual = IXP2000_INTCTL_VIRT_BASE,
90 .pfn = __phys_to_pfn(IXP2000_INTCTL_PHYS_BASE), 90 .pfn = __phys_to_pfn(IXP2000_INTCTL_PHYS_BASE),
91 .length = IXP2000_INTCTL_SIZE, 91 .length = IXP2000_INTCTL_SIZE,
92 .type = MT_DEVICE 92 .type = MT_IXP2000_DEVICE,
93 }, { 93 }, {
94 .virtual = IXP2000_PCI_CREG_VIRT_BASE, 94 .virtual = IXP2000_PCI_CREG_VIRT_BASE,
95 .pfn = __phys_to_pfn(IXP2000_PCI_CREG_PHYS_BASE), 95 .pfn = __phys_to_pfn(IXP2000_PCI_CREG_PHYS_BASE),
96 .length = IXP2000_PCI_CREG_SIZE, 96 .length = IXP2000_PCI_CREG_SIZE,
97 .type = MT_DEVICE 97 .type = MT_IXP2000_DEVICE,
98 }, { 98 }, {
99 .virtual = IXP2000_PCI_CSR_VIRT_BASE, 99 .virtual = IXP2000_PCI_CSR_VIRT_BASE,
100 .pfn = __phys_to_pfn(IXP2000_PCI_CSR_PHYS_BASE), 100 .pfn = __phys_to_pfn(IXP2000_PCI_CSR_PHYS_BASE),
101 .length = IXP2000_PCI_CSR_SIZE, 101 .length = IXP2000_PCI_CSR_SIZE,
102 .type = MT_DEVICE 102 .type = MT_IXP2000_DEVICE,
103 }, { 103 }, {
104 .virtual = IXP2000_MSF_VIRT_BASE, 104 .virtual = IXP2000_MSF_VIRT_BASE,
105 .pfn = __phys_to_pfn(IXP2000_MSF_PHYS_BASE), 105 .pfn = __phys_to_pfn(IXP2000_MSF_PHYS_BASE),
106 .length = IXP2000_MSF_SIZE, 106 .length = IXP2000_MSF_SIZE,
107 .type = MT_DEVICE 107 .type = MT_IXP2000_DEVICE,
108 }, { 108 }, {
109 .virtual = IXP2000_PCI_IO_VIRT_BASE, 109 .virtual = IXP2000_PCI_IO_VIRT_BASE,
110 .pfn = __phys_to_pfn(IXP2000_PCI_IO_PHYS_BASE), 110 .pfn = __phys_to_pfn(IXP2000_PCI_IO_PHYS_BASE),
111 .length = IXP2000_PCI_IO_SIZE, 111 .length = IXP2000_PCI_IO_SIZE,
112 .type = MT_DEVICE 112 .type = MT_IXP2000_DEVICE,
113 }, { 113 }, {
114 .virtual = IXP2000_PCI_CFG0_VIRT_BASE, 114 .virtual = IXP2000_PCI_CFG0_VIRT_BASE,
115 .pfn = __phys_to_pfn(IXP2000_PCI_CFG0_PHYS_BASE), 115 .pfn = __phys_to_pfn(IXP2000_PCI_CFG0_PHYS_BASE),
116 .length = IXP2000_PCI_CFG0_SIZE, 116 .length = IXP2000_PCI_CFG0_SIZE,
117 .type = MT_DEVICE 117 .type = MT_IXP2000_DEVICE,
118 }, { 118 }, {
119 .virtual = IXP2000_PCI_CFG1_VIRT_BASE, 119 .virtual = IXP2000_PCI_CFG1_VIRT_BASE,
120 .pfn = __phys_to_pfn(IXP2000_PCI_CFG1_PHYS_BASE), 120 .pfn = __phys_to_pfn(IXP2000_PCI_CFG1_PHYS_BASE),
121 .length = IXP2000_PCI_CFG1_SIZE, 121 .length = IXP2000_PCI_CFG1_SIZE,
122 .type = MT_DEVICE 122 .type = MT_IXP2000_DEVICE,
123 } 123 }
124}; 124};
125 125
126void __init ixp2000_map_io(void) 126void __init ixp2000_map_io(void)
127{ 127{
128 extern unsigned int processor_id;
129
130 /* 128 /*
131 * On IXP2400 CPUs we need to use MT_IXP2000_DEVICE for 129 * On IXP2400 CPUs we need to use MT_IXP2000_DEVICE so that
132 * tweaking the PMDs so XCB=101. On IXP2800s we use the normal 130 * XCB=101 (to avoid triggering erratum #66), and given that
133 * PMD flags. 131 * this mode speeds up I/O accesses and we have write buffer
132 * flushes in the right places anyway, it doesn't hurt to use
133 * XCB=101 for all IXP2000s.
134 */ 134 */
135 if ((processor_id & 0xfffffff0) == 0x69054190) {
136 int i;
137
138 printk(KERN_INFO "Enabling IXP2400 erratum #66 workaround\n");
139
140 for(i=0;i<ARRAY_SIZE(ixp2000_io_desc);i++)
141 ixp2000_io_desc[i].type = MT_IXP2000_DEVICE;
142 }
143
144 iotable_init(ixp2000_io_desc, ARRAY_SIZE(ixp2000_io_desc)); 135 iotable_init(ixp2000_io_desc, ARRAY_SIZE(ixp2000_io_desc));
145 136
146 /* Set slowport to 8-bit mode. */ 137 /* Set slowport to 8-bit mode. */
diff --git a/arch/arm/mach-pxa/corgi_lcd.c b/arch/arm/mach-pxa/corgi_lcd.c
index 54162ba95414..698eb06545c4 100644
--- a/arch/arm/mach-pxa/corgi_lcd.c
+++ b/arch/arm/mach-pxa/corgi_lcd.c
@@ -19,6 +19,7 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/string.h>
22#include <asm/arch/akita.h> 23#include <asm/arch/akita.h>
23#include <asm/arch/corgi.h> 24#include <asm/arch/corgi.h>
24#include <asm/arch/hardware.h> 25#include <asm/arch/hardware.h>
diff --git a/arch/arm/mach-realview/Kconfig b/arch/arm/mach-realview/Kconfig
index 4b63dc9eabfe..129976866d47 100644
--- a/arch/arm/mach-realview/Kconfig
+++ b/arch/arm/mach-realview/Kconfig
@@ -8,4 +8,13 @@ config MACH_REALVIEW_EB
8 help 8 help
9 Include support for the ARM(R) RealView Emulation Baseboard platform. 9 Include support for the ARM(R) RealView Emulation Baseboard platform.
10 10
11config REALVIEW_MPCORE
12 bool "Support MPcore tile"
13 depends on MACH_REALVIEW_EB
14 help
15 Enable support for the MPCore tile on the Realview platform.
16 Since there are device address and interrupt differences, a
17 kernel built with this option enabled is not compatible with
18 other tiles.
19
11endmenu 20endmenu
diff --git a/arch/arm/mach-realview/Makefile b/arch/arm/mach-realview/Makefile
index 8d37ea1605fd..011a85c10627 100644
--- a/arch/arm/mach-realview/Makefile
+++ b/arch/arm/mach-realview/Makefile
@@ -4,3 +4,4 @@
4 4
5obj-y := core.o clock.o 5obj-y := core.o clock.o
6obj-$(CONFIG_MACH_REALVIEW_EB) += realview_eb.o 6obj-$(CONFIG_MACH_REALVIEW_EB) += realview_eb.o
7obj-$(CONFIG_SMP) += platsmp.o headsmp.o
diff --git a/arch/arm/mach-realview/core.h b/arch/arm/mach-realview/core.h
index 575599db74db..d83e8bad2038 100644
--- a/arch/arm/mach-realview/core.h
+++ b/arch/arm/mach-realview/core.h
@@ -23,6 +23,7 @@
23#define __ASM_ARCH_REALVIEW_H 23#define __ASM_ARCH_REALVIEW_H
24 24
25#include <asm/hardware/amba.h> 25#include <asm/hardware/amba.h>
26#include <asm/leds.h>
26#include <asm/io.h> 27#include <asm/io.h>
27 28
28#define __io_address(n) __io(IO_ADDRESS(n)) 29#define __io_address(n) __io(IO_ADDRESS(n))
diff --git a/arch/arm/mach-realview/headsmp.S b/arch/arm/mach-realview/headsmp.S
new file mode 100644
index 000000000000..4075473cf68a
--- /dev/null
+++ b/arch/arm/mach-realview/headsmp.S
@@ -0,0 +1,39 @@
1/*
2 * linux/arch/arm/mach-realview/headsmp.S
3 *
4 * Copyright (c) 2003 ARM Limited
5 * All Rights Reserved
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/linkage.h>
12#include <linux/init.h>
13
14 __INIT
15
16/*
17 * Realview specific entry point for secondary CPUs. This provides
18 * a "holding pen" into which all secondary cores are held until we're
19 * ready for them to initialise.
20 */
21ENTRY(realview_secondary_startup)
22 mrc p15, 0, r0, c0, c0, 5
23 and r0, r0, #15
24 adr r4, 1f
25 ldmia r4, {r5, r6}
26 sub r4, r4, r5
27 add r6, r6, r4
28pen: ldr r7, [r6]
29 cmp r7, r0
30 bne pen
31
32 /*
33 * we've been released from the holding pen: secondary_stack
34 * should now contain the SVC stack for this core
35 */
36 b secondary_startup
37
381: .long .
39 .long pen_release
diff --git a/arch/arm/mach-realview/platsmp.c b/arch/arm/mach-realview/platsmp.c
new file mode 100644
index 000000000000..9844644d0fb5
--- /dev/null
+++ b/arch/arm/mach-realview/platsmp.c
@@ -0,0 +1,195 @@
1/*
2 * linux/arch/arm/mach-realview/platsmp.c
3 *
4 * Copyright (C) 2002 ARM Ltd.
5 * All Rights Reserved
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/init.h>
12#include <linux/errno.h>
13#include <linux/delay.h>
14#include <linux/device.h>
15#include <linux/smp.h>
16
17#include <asm/cacheflush.h>
18#include <asm/hardware/arm_scu.h>
19#include <asm/hardware.h>
20
21#include "core.h"
22
23extern void realview_secondary_startup(void);
24
25/*
26 * control for which core is the next to come out of the secondary
27 * boot "holding pen"
28 */
29volatile int __cpuinitdata pen_release = -1;
30
31static unsigned int __init get_core_count(void)
32{
33 unsigned int ncores;
34
35 ncores = __raw_readl(IO_ADDRESS(REALVIEW_MPCORE_SCU_BASE) + SCU_CONFIG);
36
37 return (ncores & 0x03) + 1;
38}
39
40static DEFINE_SPINLOCK(boot_lock);
41
42void __cpuinit platform_secondary_init(unsigned int cpu)
43{
44 /*
45 * the primary core may have used a "cross call" soft interrupt
46 * to get this processor out of WFI in the BootMonitor - make
47 * sure that we are no longer being sent this soft interrupt
48 */
49 smp_cross_call_done(cpumask_of_cpu(cpu));
50
51 /*
52 * if any interrupts are already enabled for the primary
53 * core (e.g. timer irq), then they will not have been enabled
54 * for us: do so
55 */
56 gic_cpu_init(__io_address(REALVIEW_GIC_CPU_BASE));
57
58 /*
59 * let the primary processor know we're out of the
60 * pen, then head off into the C entry point
61 */
62 pen_release = -1;
63
64 /*
65 * Synchronise with the boot thread.
66 */
67 spin_lock(&boot_lock);
68 spin_unlock(&boot_lock);
69}
70
71int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
72{
73 unsigned long timeout;
74
75 /*
76 * set synchronisation state between this boot processor
77 * and the secondary one
78 */
79 spin_lock(&boot_lock);
80
81 /*
82 * The secondary processor is waiting to be released from
83 * the holding pen - release it, then wait for it to flag
84 * that it has been released by resetting pen_release.
85 *
86 * Note that "pen_release" is the hardware CPU ID, whereas
87 * "cpu" is Linux's internal ID.
88 */
89 pen_release = cpu;
90 flush_cache_all();
91
92 /*
93 * XXX
94 *
95 * This is a later addition to the booting protocol: the
96 * bootMonitor now puts secondary cores into WFI, so
97 * poke_milo() no longer gets the cores moving; we need
98 * to send a soft interrupt to wake the secondary core.
99 * Use smp_cross_call() for this, since there's little
100 * point duplicating the code here
101 */
102 smp_cross_call(cpumask_of_cpu(cpu));
103
104 timeout = jiffies + (1 * HZ);
105 while (time_before(jiffies, timeout)) {
106 if (pen_release == -1)
107 break;
108
109 udelay(10);
110 }
111
112 /*
113 * now the secondary core is starting up let it run its
114 * calibrations, then wait for it to finish
115 */
116 spin_unlock(&boot_lock);
117
118 return pen_release != -1 ? -ENOSYS : 0;
119}
120
121static void __init poke_milo(void)
122{
123 extern void secondary_startup(void);
124
125 /* nobody is to be released from the pen yet */
126 pen_release = -1;
127
128 /*
129 * write the address of secondary startup into the system-wide
130 * flags register, then clear the bottom two bits, which is what
131 * BootMonitor is waiting for
132 */
133#if 1
134#define REALVIEW_SYS_FLAGSS_OFFSET 0x30
135 __raw_writel(virt_to_phys(realview_secondary_startup),
136 (IO_ADDRESS(REALVIEW_SYS_BASE) +
137 REALVIEW_SYS_FLAGSS_OFFSET));
138#define REALVIEW_SYS_FLAGSC_OFFSET 0x34
139 __raw_writel(3,
140 (IO_ADDRESS(REALVIEW_SYS_BASE) +
141 REALVIEW_SYS_FLAGSC_OFFSET));
142#endif
143
144 mb();
145}
146
147void __init smp_prepare_cpus(unsigned int max_cpus)
148{
149 unsigned int ncores = get_core_count();
150 unsigned int cpu = smp_processor_id();
151 int i;
152
153 /* sanity check */
154 if (ncores == 0) {
155 printk(KERN_ERR
156 "Realview: strange CM count of 0? Default to 1\n");
157
158 ncores = 1;
159 }
160
161 if (ncores > NR_CPUS) {
162 printk(KERN_WARNING
163 "Realview: no. of cores (%d) greater than configured "
164 "maximum of %d - clipping\n",
165 ncores, NR_CPUS);
166 ncores = NR_CPUS;
167 }
168
169 smp_store_cpu_info(cpu);
170
171 /*
172 * are we trying to boot more cores than exist?
173 */
174 if (max_cpus > ncores)
175 max_cpus = ncores;
176
177 /*
178 * Initialise the possible/present maps.
179 * cpu_possible_map describes the set of CPUs which may be present
180 * cpu_present_map describes the set of CPUs populated
181 */
182 for (i = 0; i < max_cpus; i++) {
183 cpu_set(i, cpu_possible_map);
184 cpu_set(i, cpu_present_map);
185 }
186
187 /*
188 * Do we need any more CPUs? If so, then let them know where
189 * to start. Note that, on modern versions of MILO, the "poke"
190 * doesn't actually do anything until each individual core is
191 * sent a soft interrupt to get it out of WFI
192 */
193 if (max_cpus > 1)
194 poke_milo();
195}
diff --git a/arch/arm/mach-realview/realview_eb.c b/arch/arm/mach-realview/realview_eb.c
index 267bb07e39b7..7dc32503fdf2 100644
--- a/arch/arm/mach-realview/realview_eb.c
+++ b/arch/arm/mach-realview/realview_eb.c
@@ -136,6 +136,11 @@ static struct amba_device *amba_devs[] __initdata = {
136 136
137static void __init gic_init_irq(void) 137static void __init gic_init_irq(void)
138{ 138{
139#ifdef CONFIG_REALVIEW_MPCORE
140 writel(0x0000a05f, __io_address(REALVIEW_SYS_LOCK));
141 writel(0x008003c0, __io_address(REALVIEW_SYS_BASE) + 0xd8);
142 writel(0x00000000, __io_address(REALVIEW_SYS_LOCK));
143#endif
139 gic_dist_init(__io_address(REALVIEW_GIC_DIST_BASE)); 144 gic_dist_init(__io_address(REALVIEW_GIC_DIST_BASE));
140 gic_cpu_init(__io_address(REALVIEW_GIC_CPU_BASE)); 145 gic_cpu_init(__io_address(REALVIEW_GIC_CPU_BASE));
141} 146}
diff --git a/arch/arm/mm/mm-armv.c b/arch/arm/mm/mm-armv.c
index fb5b40289de2..9e50127be635 100644
--- a/arch/arm/mm/mm-armv.c
+++ b/arch/arm/mm/mm-armv.c
@@ -354,7 +354,7 @@ void __init build_mem_type_table(void)
354{ 354{
355 struct cachepolicy *cp; 355 struct cachepolicy *cp;
356 unsigned int cr = get_cr(); 356 unsigned int cr = get_cr();
357 unsigned int user_pgprot; 357 unsigned int user_pgprot, kern_pgprot;
358 int cpu_arch = cpu_architecture(); 358 int cpu_arch = cpu_architecture();
359 int i; 359 int i;
360 360
@@ -381,7 +381,7 @@ void __init build_mem_type_table(void)
381 } 381 }
382 382
383 cp = &cache_policies[cachepolicy]; 383 cp = &cache_policies[cachepolicy];
384 user_pgprot = cp->pte; 384 kern_pgprot = user_pgprot = cp->pte;
385 385
386 /* 386 /*
387 * ARMv6 and above have extended page tables. 387 * ARMv6 and above have extended page tables.
@@ -393,6 +393,7 @@ void __init build_mem_type_table(void)
393 */ 393 */
394 mem_types[MT_MEMORY].prot_sect &= ~PMD_BIT4; 394 mem_types[MT_MEMORY].prot_sect &= ~PMD_BIT4;
395 mem_types[MT_ROM].prot_sect &= ~PMD_BIT4; 395 mem_types[MT_ROM].prot_sect &= ~PMD_BIT4;
396
396 /* 397 /*
397 * Mark cache clean areas and XIP ROM read only 398 * Mark cache clean areas and XIP ROM read only
398 * from SVC mode and no access from userspace. 399 * from SVC mode and no access from userspace.
@@ -412,32 +413,47 @@ void __init build_mem_type_table(void)
412 * (iow, non-global) 413 * (iow, non-global)
413 */ 414 */
414 user_pgprot |= L_PTE_ASID; 415 user_pgprot |= L_PTE_ASID;
416
417#ifdef CONFIG_SMP
418 /*
419 * Mark memory with the "shared" attribute for SMP systems
420 */
421 user_pgprot |= L_PTE_SHARED;
422 kern_pgprot |= L_PTE_SHARED;
423 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
424#endif
415 } 425 }
416 426
427 for (i = 0; i < 16; i++) {
428 unsigned long v = pgprot_val(protection_map[i]);
429 v = (v & ~(L_PTE_BUFFERABLE|L_PTE_CACHEABLE)) | user_pgprot;
430 protection_map[i] = __pgprot(v);
431 }
432
433 mem_types[MT_LOW_VECTORS].prot_pte |= kern_pgprot;
434 mem_types[MT_HIGH_VECTORS].prot_pte |= kern_pgprot;
435
417 if (cpu_arch >= CPU_ARCH_ARMv5) { 436 if (cpu_arch >= CPU_ARCH_ARMv5) {
418 mem_types[MT_LOW_VECTORS].prot_pte |= cp->pte & PTE_CACHEABLE; 437#ifndef CONFIG_SMP
419 mem_types[MT_HIGH_VECTORS].prot_pte |= cp->pte & PTE_CACHEABLE; 438 /*
439 * Only use write-through for non-SMP systems
440 */
441 mem_types[MT_LOW_VECTORS].prot_pte &= ~L_PTE_BUFFERABLE;
442 mem_types[MT_HIGH_VECTORS].prot_pte &= ~L_PTE_BUFFERABLE;
443#endif
420 } else { 444 } else {
421 mem_types[MT_LOW_VECTORS].prot_pte |= cp->pte;
422 mem_types[MT_HIGH_VECTORS].prot_pte |= cp->pte;
423 mem_types[MT_MINICLEAN].prot_sect &= ~PMD_SECT_TEX(1); 445 mem_types[MT_MINICLEAN].prot_sect &= ~PMD_SECT_TEX(1);
424 } 446 }
425 447
448 pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
449 L_PTE_DIRTY | L_PTE_WRITE |
450 L_PTE_EXEC | kern_pgprot);
451
426 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask; 452 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
427 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask; 453 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
428 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd; 454 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
429 mem_types[MT_ROM].prot_sect |= cp->pmd; 455 mem_types[MT_ROM].prot_sect |= cp->pmd;
430 456
431 for (i = 0; i < 16; i++) {
432 unsigned long v = pgprot_val(protection_map[i]);
433 v = (v & ~(PTE_BUFFERABLE|PTE_CACHEABLE)) | user_pgprot;
434 protection_map[i] = __pgprot(v);
435 }
436
437 pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
438 L_PTE_DIRTY | L_PTE_WRITE |
439 L_PTE_EXEC | cp->pte);
440
441 switch (cp->pmd) { 457 switch (cp->pmd) {
442 case PMD_SECT_WT: 458 case PMD_SECT_WT:
443 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT; 459 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
diff --git a/arch/arm/mm/proc-v6.S b/arch/arm/mm/proc-v6.S
index 9bb5fff406fb..92f3ca31b7b9 100644
--- a/arch/arm/mm/proc-v6.S
+++ b/arch/arm/mm/proc-v6.S
@@ -12,6 +12,7 @@
12#include <linux/linkage.h> 12#include <linux/linkage.h>
13#include <asm/assembler.h> 13#include <asm/assembler.h>
14#include <asm/asm-offsets.h> 14#include <asm/asm-offsets.h>
15#include <asm/hardware/arm_scu.h>
15#include <asm/procinfo.h> 16#include <asm/procinfo.h>
16#include <asm/pgtable.h> 17#include <asm/pgtable.h>
17 18
@@ -112,6 +113,9 @@ ENTRY(cpu_v6_dcache_clean_area)
112ENTRY(cpu_v6_switch_mm) 113ENTRY(cpu_v6_switch_mm)
113 mov r2, #0 114 mov r2, #0
114 ldr r1, [r1, #MM_CONTEXT_ID] @ get mm->context.id 115 ldr r1, [r1, #MM_CONTEXT_ID] @ get mm->context.id
116#ifdef CONFIG_SMP
117 orr r0, r0, #2 @ set shared pgtable
118#endif
115 mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB 119 mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB
116 mcr p15, 0, r2, c7, c10, 4 @ drain write buffer 120 mcr p15, 0, r2, c7, c10, 4 @ drain write buffer
117 mcr p15, 0, r0, c2, c0, 0 @ set TTB 0 121 mcr p15, 0, r0, c2, c0, 0 @ set TTB 0
@@ -140,7 +144,7 @@ ENTRY(cpu_v6_switch_mm)
140ENTRY(cpu_v6_set_pte) 144ENTRY(cpu_v6_set_pte)
141 str r1, [r0], #-2048 @ linux version 145 str r1, [r0], #-2048 @ linux version
142 146
143 bic r2, r1, #0x000007f0 147 bic r2, r1, #0x000003f0
144 bic r2, r2, #0x00000003 148 bic r2, r2, #0x00000003
145 orr r2, r2, #PTE_EXT_AP0 | 2 149 orr r2, r2, #PTE_EXT_AP0 | 2
146 150
@@ -191,6 +195,23 @@ cpu_v6_name:
191 * - cache type register is implemented 195 * - cache type register is implemented
192 */ 196 */
193__v6_setup: 197__v6_setup:
198#ifdef CONFIG_SMP
199 /* Set up the SCU on core 0 only */
200 mrc p15, 0, r0, c0, c0, 5 @ CPU core number
201 ands r0, r0, #15
202 moveq r0, #0x10000000 @ SCU_BASE
203 orreq r0, r0, #0x00100000
204 ldreq r5, [r0, #SCU_CTRL]
205 orreq r5, r5, #1
206 streq r5, [r0, #SCU_CTRL]
207
208#ifndef CONFIG_CPU_DCACHE_DISABLE
209 mrc p15, 0, r0, c1, c0, 1 @ Enable SMP/nAMP mode
210 orr r0, r0, #0x20
211 mcr p15, 0, r0, c1, c0, 1
212#endif
213#endif
214
194 mov r0, #0 215 mov r0, #0
195 mcr p15, 0, r0, c7, c14, 0 @ clean+invalidate D cache 216 mcr p15, 0, r0, c7, c14, 0 @ clean+invalidate D cache
196 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache 217 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
@@ -198,6 +219,9 @@ __v6_setup:
198 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer 219 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
199 mcr p15, 0, r0, c8, c7, 0 @ invalidate I + D TLBs 220 mcr p15, 0, r0, c8, c7, 0 @ invalidate I + D TLBs
200 mcr p15, 0, r0, c2, c0, 2 @ TTB control register 221 mcr p15, 0, r0, c2, c0, 2 @ TTB control register
222#ifdef CONFIG_SMP
223 orr r4, r4, #2 @ set shared pgtable
224#endif
201 mcr p15, 0, r4, c2, c0, 1 @ load TTB1 225 mcr p15, 0, r4, c2, c0, 1 @ load TTB1
202#ifdef CONFIG_VFP 226#ifdef CONFIG_VFP
203 mrc p15, 0, r0, c1, c0, 2 227 mrc p15, 0, r0, c1, c0, 2
diff --git a/arch/arm/nwfpe/fpa11.h b/arch/arm/nwfpe/fpa11.h
index 9677ae8448e8..da4c616b6c49 100644
--- a/arch/arm/nwfpe/fpa11.h
+++ b/arch/arm/nwfpe/fpa11.h
@@ -60,7 +60,7 @@ typedef union tagFPREG {
60#ifdef CONFIG_FPE_NWFPE_XP 60#ifdef CONFIG_FPE_NWFPE_XP
61 floatx80 fExtended; 61 floatx80 fExtended;
62#else 62#else
63 int padding[3]; 63 u32 padding[3];
64#endif 64#endif
65} FPREG; 65} FPREG;
66 66
diff --git a/arch/arm/nwfpe/fpa11_cpdt.c b/arch/arm/nwfpe/fpa11_cpdt.c
index b0db5cbcc3b1..32859fa8dcfc 100644
--- a/arch/arm/nwfpe/fpa11_cpdt.c
+++ b/arch/arm/nwfpe/fpa11_cpdt.c
@@ -59,8 +59,13 @@ static inline void loadExtended(const unsigned int Fn, const unsigned int __user
59 p = (unsigned int *) &fpa11->fpreg[Fn].fExtended; 59 p = (unsigned int *) &fpa11->fpreg[Fn].fExtended;
60 fpa11->fType[Fn] = typeExtended; 60 fpa11->fType[Fn] = typeExtended;
61 get_user(p[0], &pMem[0]); /* sign & exponent */ 61 get_user(p[0], &pMem[0]); /* sign & exponent */
62#ifdef __ARMEB__
63 get_user(p[1], &pMem[1]); /* ms bits */
64 get_user(p[2], &pMem[2]); /* ls bits */
65#else
62 get_user(p[1], &pMem[2]); /* ls bits */ 66 get_user(p[1], &pMem[2]); /* ls bits */
63 get_user(p[2], &pMem[1]); /* ms bits */ 67 get_user(p[2], &pMem[1]); /* ms bits */
68#endif
64} 69}
65#endif 70#endif
66 71
@@ -177,8 +182,13 @@ static inline void storeExtended(const unsigned int Fn, unsigned int __user *pMe
177 } 182 }
178 183
179 put_user(val.i[0], &pMem[0]); /* sign & exp */ 184 put_user(val.i[0], &pMem[0]); /* sign & exp */
185#ifdef __ARMEB__
186 put_user(val.i[1], &pMem[1]); /* msw */
187 put_user(val.i[2], &pMem[2]);
188#else
180 put_user(val.i[1], &pMem[2]); 189 put_user(val.i[1], &pMem[2]);
181 put_user(val.i[2], &pMem[1]); /* msw */ 190 put_user(val.i[2], &pMem[1]); /* msw */
191#endif
182} 192}
183#endif 193#endif
184 194
diff --git a/arch/arm/nwfpe/fpopcode.c b/arch/arm/nwfpe/fpopcode.c
index 4c9f5703148c..67ff2ab08ea0 100644
--- a/arch/arm/nwfpe/fpopcode.c
+++ b/arch/arm/nwfpe/fpopcode.c
@@ -29,14 +29,14 @@
29 29
30#ifdef CONFIG_FPE_NWFPE_XP 30#ifdef CONFIG_FPE_NWFPE_XP
31const floatx80 floatx80Constant[] = { 31const floatx80 floatx80Constant[] = {
32 {0x0000, 0x0000000000000000ULL}, /* extended 0.0 */ 32 { .high = 0x0000, .low = 0x0000000000000000ULL},/* extended 0.0 */
33 {0x3fff, 0x8000000000000000ULL}, /* extended 1.0 */ 33 { .high = 0x3fff, .low = 0x8000000000000000ULL},/* extended 1.0 */
34 {0x4000, 0x8000000000000000ULL}, /* extended 2.0 */ 34 { .high = 0x4000, .low = 0x8000000000000000ULL},/* extended 2.0 */
35 {0x4000, 0xc000000000000000ULL}, /* extended 3.0 */ 35 { .high = 0x4000, .low = 0xc000000000000000ULL},/* extended 3.0 */
36 {0x4001, 0x8000000000000000ULL}, /* extended 4.0 */ 36 { .high = 0x4001, .low = 0x8000000000000000ULL},/* extended 4.0 */
37 {0x4001, 0xa000000000000000ULL}, /* extended 5.0 */ 37 { .high = 0x4001, .low = 0xa000000000000000ULL},/* extended 5.0 */
38 {0x3ffe, 0x8000000000000000ULL}, /* extended 0.5 */ 38 { .high = 0x3ffe, .low = 0x8000000000000000ULL},/* extended 0.5 */
39 {0x4002, 0xa000000000000000ULL} /* extended 10.0 */ 39 { .high = 0x4002, .low = 0xa000000000000000ULL},/* extended 10.0 */
40}; 40};
41#endif 41#endif
42 42
diff --git a/arch/arm/nwfpe/softfloat-specialize b/arch/arm/nwfpe/softfloat-specialize
index acf409144763..d4a4c8e06635 100644
--- a/arch/arm/nwfpe/softfloat-specialize
+++ b/arch/arm/nwfpe/softfloat-specialize
@@ -332,6 +332,7 @@ static floatx80 commonNaNToFloatx80( commonNaNT a )
332 332
333 z.low = LIT64( 0xC000000000000000 ) | ( a.high>>1 ); 333 z.low = LIT64( 0xC000000000000000 ) | ( a.high>>1 );
334 z.high = ( ( (bits16) a.sign )<<15 ) | 0x7FFF; 334 z.high = ( ( (bits16) a.sign )<<15 ) | 0x7FFF;
335 z.__padding = 0;
335 return z; 336 return z;
336 337
337} 338}
diff --git a/arch/arm/nwfpe/softfloat.c b/arch/arm/nwfpe/softfloat.c
index f9f049132a17..0f9656e482ba 100644
--- a/arch/arm/nwfpe/softfloat.c
+++ b/arch/arm/nwfpe/softfloat.c
@@ -531,6 +531,7 @@ INLINE floatx80 packFloatx80( flag zSign, int32 zExp, bits64 zSig )
531 531
532 z.low = zSig; 532 z.low = zSig;
533 z.high = ( ( (bits16) zSign )<<15 ) + zExp; 533 z.high = ( ( (bits16) zSign )<<15 ) + zExp;
534 z.__padding = 0;
534 return z; 535 return z;
535 536
536} 537}
@@ -2831,6 +2832,7 @@ static floatx80 subFloatx80Sigs( struct roundingData *roundData, floatx80 a, flo
2831 roundData->exception |= float_flag_invalid; 2832 roundData->exception |= float_flag_invalid;
2832 z.low = floatx80_default_nan_low; 2833 z.low = floatx80_default_nan_low;
2833 z.high = floatx80_default_nan_high; 2834 z.high = floatx80_default_nan_high;
2835 z.__padding = 0;
2834 return z; 2836 return z;
2835 } 2837 }
2836 if ( aExp == 0 ) { 2838 if ( aExp == 0 ) {
@@ -2950,6 +2952,7 @@ floatx80 floatx80_mul( struct roundingData *roundData, floatx80 a, floatx80 b )
2950 roundData->exception |= float_flag_invalid; 2952 roundData->exception |= float_flag_invalid;
2951 z.low = floatx80_default_nan_low; 2953 z.low = floatx80_default_nan_low;
2952 z.high = floatx80_default_nan_high; 2954 z.high = floatx80_default_nan_high;
2955 z.__padding = 0;
2953 return z; 2956 return z;
2954 } 2957 }
2955 return packFloatx80( zSign, 0x7FFF, LIT64( 0x8000000000000000 ) ); 2958 return packFloatx80( zSign, 0x7FFF, LIT64( 0x8000000000000000 ) );
@@ -3015,6 +3018,7 @@ floatx80 floatx80_div( struct roundingData *roundData, floatx80 a, floatx80 b )
3015 roundData->exception |= float_flag_invalid; 3018 roundData->exception |= float_flag_invalid;
3016 z.low = floatx80_default_nan_low; 3019 z.low = floatx80_default_nan_low;
3017 z.high = floatx80_default_nan_high; 3020 z.high = floatx80_default_nan_high;
3021 z.__padding = 0;
3018 return z; 3022 return z;
3019 } 3023 }
3020 roundData->exception |= float_flag_divbyzero; 3024 roundData->exception |= float_flag_divbyzero;
@@ -3093,6 +3097,7 @@ floatx80 floatx80_rem( struct roundingData *roundData, floatx80 a, floatx80 b )
3093 roundData->exception |= float_flag_invalid; 3097 roundData->exception |= float_flag_invalid;
3094 z.low = floatx80_default_nan_low; 3098 z.low = floatx80_default_nan_low;
3095 z.high = floatx80_default_nan_high; 3099 z.high = floatx80_default_nan_high;
3100 z.__padding = 0;
3096 return z; 3101 return z;
3097 } 3102 }
3098 normalizeFloatx80Subnormal( bSig, &bExp, &bSig ); 3103 normalizeFloatx80Subnormal( bSig, &bExp, &bSig );
@@ -3184,6 +3189,7 @@ floatx80 floatx80_sqrt( struct roundingData *roundData, floatx80 a )
3184 roundData->exception |= float_flag_invalid; 3189 roundData->exception |= float_flag_invalid;
3185 z.low = floatx80_default_nan_low; 3190 z.low = floatx80_default_nan_low;
3186 z.high = floatx80_default_nan_high; 3191 z.high = floatx80_default_nan_high;
3192 z.__padding = 0;
3187 return z; 3193 return z;
3188 } 3194 }
3189 if ( aExp == 0 ) { 3195 if ( aExp == 0 ) {
diff --git a/arch/arm/nwfpe/softfloat.h b/arch/arm/nwfpe/softfloat.h
index 14151700b6b2..978c699673c6 100644
--- a/arch/arm/nwfpe/softfloat.h
+++ b/arch/arm/nwfpe/softfloat.h
@@ -51,11 +51,17 @@ input or output the `floatx80' type will be defined.
51Software IEC/IEEE floating-point types. 51Software IEC/IEEE floating-point types.
52------------------------------------------------------------------------------- 52-------------------------------------------------------------------------------
53*/ 53*/
54typedef unsigned long int float32; 54typedef u32 float32;
55typedef unsigned long long float64; 55typedef u64 float64;
56typedef struct { 56typedef struct {
57 unsigned short high; 57#ifdef __ARMEB__
58 unsigned long long low; 58 u16 __padding;
59 u16 high;
60#else
61 u16 high;
62 u16 __padding;
63#endif
64 u64 low;
59} floatx80; 65} floatx80;
60 66
61/* 67/*
diff --git a/arch/arm26/kernel/ptrace.c b/arch/arm26/kernel/ptrace.c
index cf7e977d18c8..4e6b7356a722 100644
--- a/arch/arm26/kernel/ptrace.c
+++ b/arch/arm26/kernel/ptrace.c
@@ -546,7 +546,7 @@ static int ptrace_setfpregs(struct task_struct *tsk, void *ufp)
546 sizeof(struct user_fp)) ? -EFAULT : 0; 546 sizeof(struct user_fp)) ? -EFAULT : 0;
547} 547}
548 548
549static int do_ptrace(int request, struct task_struct *child, long addr, long data) 549long arch_ptrace(struct task_struct *child, long request, long addr, long data)
550{ 550{
551 unsigned long tmp; 551 unsigned long tmp;
552 int ret; 552 int ret;
@@ -665,53 +665,6 @@ static int do_ptrace(int request, struct task_struct *child, long addr, long dat
665 return ret; 665 return ret;
666} 666}
667 667
668asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
669{
670 struct task_struct *child;
671 int ret;
672
673 lock_kernel();
674 ret = -EPERM;
675 if (request == PTRACE_TRACEME) {
676 /* are we already being traced? */
677 if (current->ptrace & PT_PTRACED)
678 goto out;
679 ret = security_ptrace(current->parent, current);
680 if (ret)
681 goto out;
682 /* set the ptrace bit in the process flags. */
683 current->ptrace |= PT_PTRACED;
684 ret = 0;
685 goto out;
686 }
687 ret = -ESRCH;
688 read_lock(&tasklist_lock);
689 child = find_task_by_pid(pid);
690 if (child)
691 get_task_struct(child);
692 read_unlock(&tasklist_lock);
693 if (!child)
694 goto out;
695
696 ret = -EPERM;
697 if (pid == 1) /* you may not mess with init */
698 goto out_tsk;
699
700 if (request == PTRACE_ATTACH) {
701 ret = ptrace_attach(child);
702 goto out_tsk;
703 }
704 ret = ptrace_check_attach(child, request == PTRACE_KILL);
705 if (ret == 0)
706 ret = do_ptrace(request, child, addr, data);
707
708out_tsk:
709 put_task_struct(child);
710out:
711 unlock_kernel();
712 return ret;
713}
714
715asmlinkage void syscall_trace(int why, struct pt_regs *regs) 668asmlinkage void syscall_trace(int why, struct pt_regs *regs)
716{ 669{
717 unsigned long ip; 670 unsigned long ip;
diff --git a/arch/cris/arch-v10/README.mm b/arch/cris/arch-v10/README.mm
index 6f08903f3139..517d1f027fe8 100644
--- a/arch/cris/arch-v10/README.mm
+++ b/arch/cris/arch-v10/README.mm
@@ -177,7 +177,7 @@ The example address is 0xd004000c; in binary this is:
177Given the top-level Page Directory, the offset in that directory is calculated 177Given the top-level Page Directory, the offset in that directory is calculated
178using the upper 8 bits: 178using the upper 8 bits:
179 179
180extern inline pgd_t * pgd_offset(struct mm_struct * mm, unsigned long address) 180static inline pgd_t * pgd_offset(struct mm_struct * mm, unsigned long address)
181{ 181{
182 return mm->pgd + (address >> PGDIR_SHIFT); 182 return mm->pgd + (address >> PGDIR_SHIFT);
183} 183}
@@ -190,14 +190,14 @@ The pgd_t from our example will therefore be the 208'th (0xd0) entry in mm->pgd.
190 190
191Since the Middle Directory does not exist, it is a unity mapping: 191Since the Middle Directory does not exist, it is a unity mapping:
192 192
193extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address) 193static inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
194{ 194{
195 return (pmd_t *) dir; 195 return (pmd_t *) dir;
196} 196}
197 197
198The Page Table provides the final lookup by using bits 13 to 23 as index: 198The Page Table provides the final lookup by using bits 13 to 23 as index:
199 199
200extern inline pte_t * pte_offset(pmd_t * dir, unsigned long address) 200static inline pte_t * pte_offset(pmd_t * dir, unsigned long address)
201{ 201{
202 return (pte_t *) pmd_page(*dir) + ((address >> PAGE_SHIFT) & 202 return (pte_t *) pmd_page(*dir) + ((address >> PAGE_SHIFT) &
203 (PTRS_PER_PTE - 1)); 203 (PTRS_PER_PTE - 1));
diff --git a/arch/cris/arch-v10/kernel/ptrace.c b/arch/cris/arch-v10/kernel/ptrace.c
index 130dd214e41d..6cbd34a27b90 100644
--- a/arch/cris/arch-v10/kernel/ptrace.c
+++ b/arch/cris/arch-v10/kernel/ptrace.c
@@ -76,55 +76,11 @@ ptrace_disable(struct task_struct *child)
76 * (in user space) where the result of the ptrace call is written (instead of 76 * (in user space) where the result of the ptrace call is written (instead of
77 * being returned). 77 * being returned).
78 */ 78 */
79asmlinkage int 79long arch_ptrace(struct task_struct *child, long request, long addr, long data)
80sys_ptrace(long request, long pid, long addr, long data)
81{ 80{
82 struct task_struct *child;
83 int ret; 81 int ret;
84 unsigned long __user *datap = (unsigned long __user *)data; 82 unsigned long __user *datap = (unsigned long __user *)data;
85 83
86 lock_kernel();
87 ret = -EPERM;
88
89 if (request == PTRACE_TRACEME) {
90 /* are we already being traced? */
91 if (current->ptrace & PT_PTRACED)
92 goto out;
93 ret = security_ptrace(current->parent, current);
94 if (ret)
95 goto out;
96 /* set the ptrace bit in the process flags. */
97 current->ptrace |= PT_PTRACED;
98 ret = 0;
99 goto out;
100 }
101
102 ret = -ESRCH;
103 read_lock(&tasklist_lock);
104 child = find_task_by_pid(pid);
105
106 if (child)
107 get_task_struct(child);
108
109 read_unlock(&tasklist_lock);
110
111 if (!child)
112 goto out;
113
114 ret = -EPERM;
115
116 if (pid == 1) /* Leave the init process alone! */
117 goto out_tsk;
118
119 if (request == PTRACE_ATTACH) {
120 ret = ptrace_attach(child);
121 goto out_tsk;
122 }
123
124 ret = ptrace_check_attach(child, request == PTRACE_KILL);
125 if (ret < 0)
126 goto out_tsk;
127
128 switch (request) { 84 switch (request) {
129 /* Read word at location address. */ 85 /* Read word at location address. */
130 case PTRACE_PEEKTEXT: 86 case PTRACE_PEEKTEXT:
@@ -289,10 +245,7 @@ sys_ptrace(long request, long pid, long addr, long data)
289 ret = ptrace_request(child, request, addr, data); 245 ret = ptrace_request(child, request, addr, data);
290 break; 246 break;
291 } 247 }
292out_tsk: 248
293 put_task_struct(child);
294out:
295 unlock_kernel();
296 return ret; 249 return ret;
297} 250}
298 251
diff --git a/arch/cris/arch-v10/kernel/signal.c b/arch/cris/arch-v10/kernel/signal.c
index 693771961f85..19bcad05716f 100644
--- a/arch/cris/arch-v10/kernel/signal.c
+++ b/arch/cris/arch-v10/kernel/signal.c
@@ -476,7 +476,7 @@ give_sigsegv:
476 * OK, we're invoking a handler 476 * OK, we're invoking a handler
477 */ 477 */
478 478
479extern inline void 479static inline void
480handle_signal(int canrestart, unsigned long sig, 480handle_signal(int canrestart, unsigned long sig,
481 siginfo_t *info, struct k_sigaction *ka, 481 siginfo_t *info, struct k_sigaction *ka,
482 sigset_t *oldset, struct pt_regs * regs) 482 sigset_t *oldset, struct pt_regs * regs)
diff --git a/arch/cris/arch-v32/drivers/cryptocop.c b/arch/cris/arch-v32/drivers/cryptocop.c
index ca72076c630a..501fa52d8d3a 100644
--- a/arch/cris/arch-v32/drivers/cryptocop.c
+++ b/arch/cris/arch-v32/drivers/cryptocop.c
@@ -277,7 +277,7 @@ struct file_operations cryptocop_fops = {
277static void free_cdesc(struct cryptocop_dma_desc *cdesc) 277static void free_cdesc(struct cryptocop_dma_desc *cdesc)
278{ 278{
279 DEBUG(printk("free_cdesc: cdesc 0x%p, from_pool=%d\n", cdesc, cdesc->from_pool)); 279 DEBUG(printk("free_cdesc: cdesc 0x%p, from_pool=%d\n", cdesc, cdesc->from_pool));
280 if (cdesc->free_buf) kfree(cdesc->free_buf); 280 kfree(cdesc->free_buf);
281 281
282 if (cdesc->from_pool) { 282 if (cdesc->from_pool) {
283 unsigned long int flags; 283 unsigned long int flags;
@@ -2950,15 +2950,15 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
2950 put_page(outpages[i]); 2950 put_page(outpages[i]);
2951 } 2951 }
2952 2952
2953 if (digest_result) kfree(digest_result); 2953 kfree(digest_result);
2954 if (inpages) kfree(inpages); 2954 kfree(inpages);
2955 if (outpages) kfree(outpages); 2955 kfree(outpages);
2956 if (cop){ 2956 if (cop){
2957 if (cop->tfrm_op.indata) kfree(cop->tfrm_op.indata); 2957 kfree(cop->tfrm_op.indata);
2958 if (cop->tfrm_op.outdata) kfree(cop->tfrm_op.outdata); 2958 kfree(cop->tfrm_op.outdata);
2959 kfree(cop); 2959 kfree(cop);
2960 } 2960 }
2961 if (jc) kfree(jc); 2961 kfree(jc);
2962 2962
2963 DEBUG(print_lock_status()); 2963 DEBUG(print_lock_status());
2964 2964
diff --git a/arch/cris/arch-v32/kernel/ptrace.c b/arch/cris/arch-v32/kernel/ptrace.c
index 208489da2a87..5528b83a622b 100644
--- a/arch/cris/arch-v32/kernel/ptrace.c
+++ b/arch/cris/arch-v32/kernel/ptrace.c
@@ -99,55 +99,11 @@ ptrace_disable(struct task_struct *child)
99} 99}
100 100
101 101
102asmlinkage int 102long arch_ptrace(struct task_struct *child, long request, long addr, long data)
103sys_ptrace(long request, long pid, long addr, long data)
104{ 103{
105 struct task_struct *child;
106 int ret; 104 int ret;
107 unsigned long __user *datap = (unsigned long __user *)data; 105 unsigned long __user *datap = (unsigned long __user *)data;
108 106
109 lock_kernel();
110 ret = -EPERM;
111
112 if (request == PTRACE_TRACEME) {
113 /* are we already being traced? */
114 if (current->ptrace & PT_PTRACED)
115 goto out;
116 ret = security_ptrace(current->parent, current);
117 if (ret)
118 goto out;
119 /* set the ptrace bit in the process flags. */
120 current->ptrace |= PT_PTRACED;
121 ret = 0;
122 goto out;
123 }
124
125 ret = -ESRCH;
126 read_lock(&tasklist_lock);
127 child = find_task_by_pid(pid);
128
129 if (child)
130 get_task_struct(child);
131
132 read_unlock(&tasklist_lock);
133
134 if (!child)
135 goto out;
136
137 ret = -EPERM;
138
139 if (pid == 1) /* Leave the init process alone! */
140 goto out_tsk;
141
142 if (request == PTRACE_ATTACH) {
143 ret = ptrace_attach(child);
144 goto out_tsk;
145 }
146
147 ret = ptrace_check_attach(child, request == PTRACE_KILL);
148 if (ret < 0)
149 goto out_tsk;
150
151 switch (request) { 107 switch (request) {
152 /* Read word at location address. */ 108 /* Read word at location address. */
153 case PTRACE_PEEKTEXT: 109 case PTRACE_PEEKTEXT:
@@ -347,10 +303,7 @@ sys_ptrace(long request, long pid, long addr, long data)
347 ret = ptrace_request(child, request, addr, data); 303 ret = ptrace_request(child, request, addr, data);
348 break; 304 break;
349 } 305 }
350out_tsk: 306
351 put_task_struct(child);
352out:
353 unlock_kernel();
354 return ret; 307 return ret;
355} 308}
356 309
diff --git a/arch/cris/arch-v32/kernel/signal.c b/arch/cris/arch-v32/kernel/signal.c
index 0a3614dab887..99e59b3eacf8 100644
--- a/arch/cris/arch-v32/kernel/signal.c
+++ b/arch/cris/arch-v32/kernel/signal.c
@@ -513,7 +513,7 @@ give_sigsegv:
513} 513}
514 514
515/* Invoke a singal handler to, well, handle the signal. */ 515/* Invoke a singal handler to, well, handle the signal. */
516extern inline void 516static inline void
517handle_signal(int canrestart, unsigned long sig, 517handle_signal(int canrestart, unsigned long sig,
518 siginfo_t *info, struct k_sigaction *ka, 518 siginfo_t *info, struct k_sigaction *ka,
519 sigset_t *oldset, struct pt_regs * regs) 519 sigset_t *oldset, struct pt_regs * regs)
diff --git a/arch/cris/mm/ioremap.c b/arch/cris/mm/ioremap.c
index a92ac9877582..1780df3ed9e5 100644
--- a/arch/cris/mm/ioremap.c
+++ b/arch/cris/mm/ioremap.c
@@ -16,7 +16,7 @@
16#include <asm/tlbflush.h> 16#include <asm/tlbflush.h>
17#include <asm/arch/memmap.h> 17#include <asm/arch/memmap.h>
18 18
19extern inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size, 19static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
20 unsigned long phys_addr, pgprot_t prot) 20 unsigned long phys_addr, pgprot_t prot)
21{ 21{
22 unsigned long end; 22 unsigned long end;
diff --git a/arch/frv/kernel/ptrace.c b/arch/frv/kernel/ptrace.c
index cb335a14a315..f953484e7d59 100644
--- a/arch/frv/kernel/ptrace.c
+++ b/arch/frv/kernel/ptrace.c
@@ -106,48 +106,11 @@ void ptrace_enable(struct task_struct *child)
106 child->thread.frame0->__status |= REG__STATUS_STEP; 106 child->thread.frame0->__status |= REG__STATUS_STEP;
107} 107}
108 108
109asmlinkage long sys_ptrace(long request, long pid, long addr, long data) 109long arch_ptrace(struct task_struct *child, long request, long addr, long data)
110{ 110{
111 struct task_struct *child;
112 unsigned long tmp; 111 unsigned long tmp;
113 int ret; 112 int ret;
114 113
115 lock_kernel();
116 ret = -EPERM;
117 if (request == PTRACE_TRACEME) {
118 /* are we already being traced? */
119 if (current->ptrace & PT_PTRACED)
120 goto out;
121 ret = security_ptrace(current->parent, current);
122 if (ret)
123 goto out;
124 /* set the ptrace bit in the process flags. */
125 current->ptrace |= PT_PTRACED;
126 ret = 0;
127 goto out;
128 }
129 ret = -ESRCH;
130 read_lock(&tasklist_lock);
131 child = find_task_by_pid(pid);
132 if (child)
133 get_task_struct(child);
134 read_unlock(&tasklist_lock);
135 if (!child)
136 goto out;
137
138 ret = -EPERM;
139 if (pid == 1) /* you may not mess with init */
140 goto out_tsk;
141
142 if (request == PTRACE_ATTACH) {
143 ret = ptrace_attach(child);
144 goto out_tsk;
145 }
146
147 ret = ptrace_check_attach(child, request == PTRACE_KILL);
148 if (ret < 0)
149 goto out_tsk;
150
151 switch (request) { 114 switch (request) {
152 /* when I and D space are separate, these will need to be fixed. */ 115 /* when I and D space are separate, these will need to be fixed. */
153 case PTRACE_PEEKTEXT: /* read word at location addr. */ 116 case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -351,10 +314,6 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
351 ret = -EIO; 314 ret = -EIO;
352 break; 315 break;
353 } 316 }
354out_tsk:
355 put_task_struct(child);
356out:
357 unlock_kernel();
358 return ret; 317 return ret;
359} 318}
360 319
diff --git a/arch/h8300/kernel/ptrace.c b/arch/h8300/kernel/ptrace.c
index a569fe4aa284..0ff6f79b0fed 100644
--- a/arch/h8300/kernel/ptrace.c
+++ b/arch/h8300/kernel/ptrace.c
@@ -57,43 +57,10 @@ void ptrace_disable(struct task_struct *child)
57 h8300_disable_trace(child); 57 h8300_disable_trace(child);
58} 58}
59 59
60asmlinkage long sys_ptrace(long request, long pid, long addr, long data) 60long arch_ptrace(struct task_struct *child, long request, long addr, long data)
61{ 61{
62 struct task_struct *child;
63 int ret; 62 int ret;
64 63
65 lock_kernel();
66 ret = -EPERM;
67 if (request == PTRACE_TRACEME) {
68 /* are we already being traced? */
69 if (current->ptrace & PT_PTRACED)
70 goto out;
71 /* set the ptrace bit in the process flags. */
72 current->ptrace |= PT_PTRACED;
73 ret = 0;
74 goto out;
75 }
76 ret = -ESRCH;
77 read_lock(&tasklist_lock);
78 child = find_task_by_pid(pid);
79 if (child)
80 get_task_struct(child);
81 read_unlock(&tasklist_lock);
82 if (!child)
83 goto out;
84
85 ret = -EPERM;
86 if (pid == 1) /* you may not mess with init */
87 goto out_tsk;
88
89 if (request == PTRACE_ATTACH) {
90 ret = ptrace_attach(child);
91 goto out_tsk;
92 }
93 ret = ptrace_check_attach(child, request == PTRACE_KILL);
94 if (ret < 0)
95 goto out_tsk;
96
97 switch (request) { 64 switch (request) {
98 case PTRACE_PEEKTEXT: /* read word at location addr. */ 65 case PTRACE_PEEKTEXT: /* read word at location addr. */
99 case PTRACE_PEEKDATA: { 66 case PTRACE_PEEKDATA: {
@@ -251,10 +218,6 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
251 ret = -EIO; 218 ret = -EIO;
252 break; 219 break;
253 } 220 }
254out_tsk:
255 put_task_struct(child);
256out:
257 unlock_kernel();
258 return ret; 221 return ret;
259} 222}
260 223
diff --git a/arch/i386/Kconfig b/arch/i386/Kconfig
index bac0da731ee3..dbf90ad6eac3 100644
--- a/arch/i386/Kconfig
+++ b/arch/i386/Kconfig
@@ -997,8 +997,21 @@ source "drivers/Kconfig"
997 997
998source "fs/Kconfig" 998source "fs/Kconfig"
999 999
1000menu "Instrumentation Support"
1001 depends on EXPERIMENTAL
1002
1000source "arch/i386/oprofile/Kconfig" 1003source "arch/i386/oprofile/Kconfig"
1001 1004
1005config KPROBES
1006 bool "Kprobes (EXPERIMENTAL)"
1007 help
1008 Kprobes allows you to trap at almost any kernel address and
1009 execute a callback function. register_kprobe() establishes
1010 a probepoint and specifies the callback. Kprobes is useful
1011 for kernel debugging, non-intrusive instrumentation and testing.
1012 If in doubt, say "N".
1013endmenu
1014
1002source "arch/i386/Kconfig.debug" 1015source "arch/i386/Kconfig.debug"
1003 1016
1004source "security/Kconfig" 1017source "security/Kconfig"
diff --git a/arch/i386/Kconfig.debug b/arch/i386/Kconfig.debug
index 5228c40a6fb2..c48b424dd640 100644
--- a/arch/i386/Kconfig.debug
+++ b/arch/i386/Kconfig.debug
@@ -22,16 +22,6 @@ config DEBUG_STACKOVERFLOW
22 This option will cause messages to be printed if free stack space 22 This option will cause messages to be printed if free stack space
23 drops below a certain limit. 23 drops below a certain limit.
24 24
25config KPROBES
26 bool "Kprobes"
27 depends on DEBUG_KERNEL
28 help
29 Kprobes allows you to trap at almost any kernel address and
30 execute a callback function. register_kprobe() establishes
31 a probepoint and specifies the callback. Kprobes is useful
32 for kernel debugging, non-intrusive instrumentation and testing.
33 If in doubt, say "N".
34
35config DEBUG_STACK_USAGE 25config DEBUG_STACK_USAGE
36 bool "Stack utilization instrumentation" 26 bool "Stack utilization instrumentation"
37 depends on DEBUG_KERNEL 27 depends on DEBUG_KERNEL
diff --git a/arch/i386/kernel/apic.c b/arch/i386/kernel/apic.c
index 7c724ffa08bb..496a2c9909fe 100644
--- a/arch/i386/kernel/apic.c
+++ b/arch/i386/kernel/apic.c
@@ -559,14 +559,20 @@ void __devinit setup_local_APIC(void)
559 * If Linux enabled the LAPIC against the BIOS default 559 * If Linux enabled the LAPIC against the BIOS default
560 * disable it down before re-entering the BIOS on shutdown. 560 * disable it down before re-entering the BIOS on shutdown.
561 * Otherwise the BIOS may get confused and not power-off. 561 * Otherwise the BIOS may get confused and not power-off.
562 * Additionally clear all LVT entries before disable_local_APIC
563 * for the case where Linux didn't enable the LAPIC.
562 */ 564 */
563void lapic_shutdown(void) 565void lapic_shutdown(void)
564{ 566{
565 if (!cpu_has_apic || !enabled_via_apicbase) 567 if (!cpu_has_apic)
566 return; 568 return;
567 569
568 local_irq_disable(); 570 local_irq_disable();
569 disable_local_APIC(); 571 clear_local_APIC();
572
573 if (enabled_via_apicbase)
574 disable_local_APIC();
575
570 local_irq_enable(); 576 local_irq_enable();
571} 577}
572 578
diff --git a/arch/i386/kernel/apm.c b/arch/i386/kernel/apm.c
index d2ef0c2aa93e..86e80c551478 100644
--- a/arch/i386/kernel/apm.c
+++ b/arch/i386/kernel/apm.c
@@ -447,8 +447,7 @@ static char * apm_event_name[] = {
447 "system standby resume", 447 "system standby resume",
448 "capabilities change" 448 "capabilities change"
449}; 449};
450#define NR_APM_EVENT_NAME \ 450#define NR_APM_EVENT_NAME ARRAY_SIZE(apm_event_name)
451 (sizeof(apm_event_name) / sizeof(apm_event_name[0]))
452 451
453typedef struct lookup_t { 452typedef struct lookup_t {
454 int key; 453 int key;
@@ -479,7 +478,7 @@ static const lookup_t error_table[] = {
479 { APM_NO_ERROR, "BIOS did not set a return code" }, 478 { APM_NO_ERROR, "BIOS did not set a return code" },
480 { APM_NOT_PRESENT, "No APM present" } 479 { APM_NOT_PRESENT, "No APM present" }
481}; 480};
482#define ERROR_COUNT (sizeof(error_table)/sizeof(lookup_t)) 481#define ERROR_COUNT ARRAY_SIZE(error_table)
483 482
484/** 483/**
485 * apm_error - display an APM error 484 * apm_error - display an APM error
diff --git a/arch/i386/kernel/cpu/common.c b/arch/i386/kernel/cpu/common.c
index 74145a33cb0f..c145fb30002e 100644
--- a/arch/i386/kernel/cpu/common.c
+++ b/arch/i386/kernel/cpu/common.c
@@ -30,8 +30,6 @@ static int disable_x86_serial_nr __devinitdata = 1;
30 30
31struct cpu_dev * cpu_devs[X86_VENDOR_NUM] = {}; 31struct cpu_dev * cpu_devs[X86_VENDOR_NUM] = {};
32 32
33extern void mcheck_init(struct cpuinfo_x86 *c);
34
35extern int disable_pse; 33extern int disable_pse;
36 34
37static void default_init(struct cpuinfo_x86 * c) 35static void default_init(struct cpuinfo_x86 * c)
@@ -429,9 +427,8 @@ void __devinit identify_cpu(struct cpuinfo_x86 *c)
429 } 427 }
430 428
431 /* Init Machine Check Exception if available. */ 429 /* Init Machine Check Exception if available. */
432#ifdef CONFIG_X86_MCE
433 mcheck_init(c); 430 mcheck_init(c);
434#endif 431
435 if (c == &boot_cpu_data) 432 if (c == &boot_cpu_data)
436 sysenter_setup(); 433 sysenter_setup();
437 enable_sep_cpu(); 434 enable_sep_cpu();
diff --git a/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c b/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c
index caa9f7711343..871366b83b3f 100644
--- a/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c
+++ b/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c
@@ -377,10 +377,9 @@ acpi_cpufreq_cpu_init (
377 arg0.buffer.length = 12; 377 arg0.buffer.length = 12;
378 arg0.buffer.pointer = (u8 *) arg0_buf; 378 arg0.buffer.pointer = (u8 *) arg0_buf;
379 379
380 data = kmalloc(sizeof(struct cpufreq_acpi_io), GFP_KERNEL); 380 data = kzalloc(sizeof(struct cpufreq_acpi_io), GFP_KERNEL);
381 if (!data) 381 if (!data)
382 return (-ENOMEM); 382 return (-ENOMEM);
383 memset(data, 0, sizeof(struct cpufreq_acpi_io));
384 383
385 acpi_io_data[cpu] = data; 384 acpi_io_data[cpu] = data;
386 385
diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k7.c b/arch/i386/kernel/cpu/cpufreq/powernow-k7.c
index 73a5dc5b26b8..edcd626001da 100644
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k7.c
+++ b/arch/i386/kernel/cpu/cpufreq/powernow-k7.c
@@ -171,10 +171,9 @@ static int get_ranges (unsigned char *pst)
171 unsigned int speed; 171 unsigned int speed;
172 u8 fid, vid; 172 u8 fid, vid;
173 173
174 powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) * (number_scales + 1)), GFP_KERNEL); 174 powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * (number_scales + 1)), GFP_KERNEL);
175 if (!powernow_table) 175 if (!powernow_table)
176 return -ENOMEM; 176 return -ENOMEM;
177 memset(powernow_table, 0, (sizeof(struct cpufreq_frequency_table) * (number_scales + 1)));
178 177
179 for (j=0 ; j < number_scales; j++) { 178 for (j=0 ; j < number_scales; j++) {
180 fid = *pst++; 179 fid = *pst++;
@@ -305,16 +304,13 @@ static int powernow_acpi_init(void)
305 goto err0; 304 goto err0;
306 } 305 }
307 306
308 acpi_processor_perf = kmalloc(sizeof(struct acpi_processor_performance), 307 acpi_processor_perf = kzalloc(sizeof(struct acpi_processor_performance),
309 GFP_KERNEL); 308 GFP_KERNEL);
310
311 if (!acpi_processor_perf) { 309 if (!acpi_processor_perf) {
312 retval = -ENOMEM; 310 retval = -ENOMEM;
313 goto err0; 311 goto err0;
314 } 312 }
315 313
316 memset(acpi_processor_perf, 0, sizeof(struct acpi_processor_performance));
317
318 if (acpi_processor_register_performance(acpi_processor_perf, 0)) { 314 if (acpi_processor_register_performance(acpi_processor_perf, 0)) {
319 retval = -EIO; 315 retval = -EIO;
320 goto err1; 316 goto err1;
@@ -337,14 +333,12 @@ static int powernow_acpi_init(void)
337 goto err2; 333 goto err2;
338 } 334 }
339 335
340 powernow_table = kmalloc((number_scales + 1) * (sizeof(struct cpufreq_frequency_table)), GFP_KERNEL); 336 powernow_table = kzalloc((number_scales + 1) * (sizeof(struct cpufreq_frequency_table)), GFP_KERNEL);
341 if (!powernow_table) { 337 if (!powernow_table) {
342 retval = -ENOMEM; 338 retval = -ENOMEM;
343 goto err2; 339 goto err2;
344 } 340 }
345 341
346 memset(powernow_table, 0, ((number_scales + 1) * sizeof(struct cpufreq_frequency_table)));
347
348 pc.val = (unsigned long) acpi_processor_perf->states[0].control; 342 pc.val = (unsigned long) acpi_processor_perf->states[0].control;
349 for (i = 0; i < number_scales; i++) { 343 for (i = 0; i < number_scales; i++) {
350 u8 fid, vid; 344 u8 fid, vid;
diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
index 2d5c9adba0cd..68a1fc87f4ca 100644
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
+++ b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
@@ -462,7 +462,6 @@ static int check_supported_cpu(unsigned int cpu)
462 462
463 oldmask = current->cpus_allowed; 463 oldmask = current->cpus_allowed;
464 set_cpus_allowed(current, cpumask_of_cpu(cpu)); 464 set_cpus_allowed(current, cpumask_of_cpu(cpu));
465 schedule();
466 465
467 if (smp_processor_id() != cpu) { 466 if (smp_processor_id() != cpu) {
468 printk(KERN_ERR "limiting to cpu %u failed\n", cpu); 467 printk(KERN_ERR "limiting to cpu %u failed\n", cpu);
@@ -497,9 +496,7 @@ static int check_supported_cpu(unsigned int cpu)
497 496
498out: 497out:
499 set_cpus_allowed(current, oldmask); 498 set_cpus_allowed(current, oldmask);
500 schedule();
501 return rc; 499 return rc;
502
503} 500}
504 501
505static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, u8 maxvid) 502static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, u8 maxvid)
@@ -913,7 +910,6 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi
913 /* only run on specific CPU from here on */ 910 /* only run on specific CPU from here on */
914 oldmask = current->cpus_allowed; 911 oldmask = current->cpus_allowed;
915 set_cpus_allowed(current, cpumask_of_cpu(pol->cpu)); 912 set_cpus_allowed(current, cpumask_of_cpu(pol->cpu));
916 schedule();
917 913
918 if (smp_processor_id() != pol->cpu) { 914 if (smp_processor_id() != pol->cpu) {
919 printk(KERN_ERR "limiting to cpu %u failed\n", pol->cpu); 915 printk(KERN_ERR "limiting to cpu %u failed\n", pol->cpu);
@@ -968,8 +964,6 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi
968 964
969err_out: 965err_out:
970 set_cpus_allowed(current, oldmask); 966 set_cpus_allowed(current, oldmask);
971 schedule();
972
973 return ret; 967 return ret;
974} 968}
975 969
@@ -991,12 +985,11 @@ static int __init powernowk8_cpu_init(struct cpufreq_policy *pol)
991 if (!check_supported_cpu(pol->cpu)) 985 if (!check_supported_cpu(pol->cpu))
992 return -ENODEV; 986 return -ENODEV;
993 987
994 data = kmalloc(sizeof(struct powernow_k8_data), GFP_KERNEL); 988 data = kzalloc(sizeof(struct powernow_k8_data), GFP_KERNEL);
995 if (!data) { 989 if (!data) {
996 printk(KERN_ERR PFX "unable to alloc powernow_k8_data"); 990 printk(KERN_ERR PFX "unable to alloc powernow_k8_data");
997 return -ENOMEM; 991 return -ENOMEM;
998 } 992 }
999 memset(data,0,sizeof(struct powernow_k8_data));
1000 993
1001 data->cpu = pol->cpu; 994 data->cpu = pol->cpu;
1002 995
@@ -1026,7 +1019,6 @@ static int __init powernowk8_cpu_init(struct cpufreq_policy *pol)
1026 /* only run on specific CPU from here on */ 1019 /* only run on specific CPU from here on */
1027 oldmask = current->cpus_allowed; 1020 oldmask = current->cpus_allowed;
1028 set_cpus_allowed(current, cpumask_of_cpu(pol->cpu)); 1021 set_cpus_allowed(current, cpumask_of_cpu(pol->cpu));
1029 schedule();
1030 1022
1031 if (smp_processor_id() != pol->cpu) { 1023 if (smp_processor_id() != pol->cpu) {
1032 printk(KERN_ERR "limiting to cpu %u failed\n", pol->cpu); 1024 printk(KERN_ERR "limiting to cpu %u failed\n", pol->cpu);
@@ -1045,7 +1037,6 @@ static int __init powernowk8_cpu_init(struct cpufreq_policy *pol)
1045 1037
1046 /* run on any CPU again */ 1038 /* run on any CPU again */
1047 set_cpus_allowed(current, oldmask); 1039 set_cpus_allowed(current, oldmask);
1048 schedule();
1049 1040
1050 pol->governor = CPUFREQ_DEFAULT_GOVERNOR; 1041 pol->governor = CPUFREQ_DEFAULT_GOVERNOR;
1051 pol->cpus = cpu_core_map[pol->cpu]; 1042 pol->cpus = cpu_core_map[pol->cpu];
@@ -1080,7 +1071,6 @@ static int __init powernowk8_cpu_init(struct cpufreq_policy *pol)
1080 1071
1081err_out: 1072err_out:
1082 set_cpus_allowed(current, oldmask); 1073 set_cpus_allowed(current, oldmask);
1083 schedule();
1084 powernow_k8_cpu_exit_acpi(data); 1074 powernow_k8_cpu_exit_acpi(data);
1085 1075
1086 kfree(data); 1076 kfree(data);
@@ -1116,17 +1106,14 @@ static unsigned int powernowk8_get (unsigned int cpu)
1116 set_cpus_allowed(current, oldmask); 1106 set_cpus_allowed(current, oldmask);
1117 return 0; 1107 return 0;
1118 } 1108 }
1119 preempt_disable(); 1109
1120
1121 if (query_current_values_with_pending_wait(data)) 1110 if (query_current_values_with_pending_wait(data))
1122 goto out; 1111 goto out;
1123 1112
1124 khz = find_khz_freq_from_fid(data->currfid); 1113 khz = find_khz_freq_from_fid(data->currfid);
1125 1114
1126 out: 1115out:
1127 preempt_enable_no_resched();
1128 set_cpus_allowed(current, oldmask); 1116 set_cpus_allowed(current, oldmask);
1129
1130 return khz; 1117 return khz;
1131} 1118}
1132 1119
diff --git a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
index 1465974256c9..edb9873e27e3 100644
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
+++ b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
@@ -67,7 +67,7 @@ static const struct cpu_id cpu_ids[] = {
67 [CPU_MP4HT_D0] = {15, 3, 4 }, 67 [CPU_MP4HT_D0] = {15, 3, 4 },
68 [CPU_MP4HT_E0] = {15, 4, 1 }, 68 [CPU_MP4HT_E0] = {15, 4, 1 },
69}; 69};
70#define N_IDS (sizeof(cpu_ids)/sizeof(cpu_ids[0])) 70#define N_IDS ARRAY_SIZE(cpu_ids)
71 71
72struct cpu_model 72struct cpu_model
73{ 73{
@@ -423,12 +423,11 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy)
423 } 423 }
424 } 424 }
425 425
426 centrino_model[cpu] = kmalloc(sizeof(struct cpu_model), GFP_KERNEL); 426 centrino_model[cpu] = kzalloc(sizeof(struct cpu_model), GFP_KERNEL);
427 if (!centrino_model[cpu]) { 427 if (!centrino_model[cpu]) {
428 result = -ENOMEM; 428 result = -ENOMEM;
429 goto err_unreg; 429 goto err_unreg;
430 } 430 }
431 memset(centrino_model[cpu], 0, sizeof(struct cpu_model));
432 431
433 centrino_model[cpu]->model_name=NULL; 432 centrino_model[cpu]->model_name=NULL;
434 centrino_model[cpu]->max_freq = p.states[0].core_frequency * 1000; 433 centrino_model[cpu]->max_freq = p.states[0].core_frequency * 1000;
diff --git a/arch/i386/kernel/cpu/mcheck/k7.c b/arch/i386/kernel/cpu/mcheck/k7.c
index 7c6b9c73522f..fc5d5215e23d 100644
--- a/arch/i386/kernel/cpu/mcheck/k7.c
+++ b/arch/i386/kernel/cpu/mcheck/k7.c
@@ -68,7 +68,7 @@ static fastcall void k7_machine_check(struct pt_regs * regs, long error_code)
68 68
69 69
70/* AMD K7 machine check is Intel like */ 70/* AMD K7 machine check is Intel like */
71void __devinit amd_mcheck_init(struct cpuinfo_x86 *c) 71void amd_mcheck_init(struct cpuinfo_x86 *c)
72{ 72{
73 u32 l, h; 73 u32 l, h;
74 int i; 74 int i;
diff --git a/arch/i386/kernel/cpu/mcheck/mce.c b/arch/i386/kernel/cpu/mcheck/mce.c
index 2cf25d2ba0f1..6170af3c271a 100644
--- a/arch/i386/kernel/cpu/mcheck/mce.c
+++ b/arch/i386/kernel/cpu/mcheck/mce.c
@@ -16,7 +16,7 @@
16 16
17#include "mce.h" 17#include "mce.h"
18 18
19int mce_disabled __devinitdata = 0; 19int mce_disabled = 0;
20int nr_mce_banks; 20int nr_mce_banks;
21 21
22EXPORT_SYMBOL_GPL(nr_mce_banks); /* non-fatal.o */ 22EXPORT_SYMBOL_GPL(nr_mce_banks); /* non-fatal.o */
@@ -31,7 +31,7 @@ static fastcall void unexpected_machine_check(struct pt_regs * regs, long error_
31void fastcall (*machine_check_vector)(struct pt_regs *, long error_code) = unexpected_machine_check; 31void fastcall (*machine_check_vector)(struct pt_regs *, long error_code) = unexpected_machine_check;
32 32
33/* This has to be run for each processor */ 33/* This has to be run for each processor */
34void __devinit mcheck_init(struct cpuinfo_x86 *c) 34void mcheck_init(struct cpuinfo_x86 *c)
35{ 35{
36 if (mce_disabled==1) 36 if (mce_disabled==1)
37 return; 37 return;
diff --git a/arch/i386/kernel/cpu/mcheck/p4.c b/arch/i386/kernel/cpu/mcheck/p4.c
index 1d1e885f500a..fd2c459a31ef 100644
--- a/arch/i386/kernel/cpu/mcheck/p4.c
+++ b/arch/i386/kernel/cpu/mcheck/p4.c
@@ -77,7 +77,7 @@ fastcall void smp_thermal_interrupt(struct pt_regs *regs)
77} 77}
78 78
79/* P4/Xeon Thermal regulation detect and init */ 79/* P4/Xeon Thermal regulation detect and init */
80static void __devinit intel_init_thermal(struct cpuinfo_x86 *c) 80static void intel_init_thermal(struct cpuinfo_x86 *c)
81{ 81{
82 u32 l, h; 82 u32 l, h;
83 unsigned int cpu = smp_processor_id(); 83 unsigned int cpu = smp_processor_id();
@@ -231,7 +231,7 @@ static fastcall void intel_machine_check(struct pt_regs * regs, long error_code)
231} 231}
232 232
233 233
234void __devinit intel_p4_mcheck_init(struct cpuinfo_x86 *c) 234void intel_p4_mcheck_init(struct cpuinfo_x86 *c)
235{ 235{
236 u32 l, h; 236 u32 l, h;
237 int i; 237 int i;
diff --git a/arch/i386/kernel/cpu/mcheck/p5.c b/arch/i386/kernel/cpu/mcheck/p5.c
index 3a2e24baddc7..94bc43d950cf 100644
--- a/arch/i386/kernel/cpu/mcheck/p5.c
+++ b/arch/i386/kernel/cpu/mcheck/p5.c
@@ -28,7 +28,7 @@ static fastcall void pentium_machine_check(struct pt_regs * regs, long error_cod
28} 28}
29 29
30/* Set up machine check reporting for processors with Intel style MCE */ 30/* Set up machine check reporting for processors with Intel style MCE */
31void __devinit intel_p5_mcheck_init(struct cpuinfo_x86 *c) 31void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
32{ 32{
33 u32 l, h; 33 u32 l, h;
34 34
diff --git a/arch/i386/kernel/cpu/mcheck/p6.c b/arch/i386/kernel/cpu/mcheck/p6.c
index 979b18bc95c1..deeae42ce199 100644
--- a/arch/i386/kernel/cpu/mcheck/p6.c
+++ b/arch/i386/kernel/cpu/mcheck/p6.c
@@ -79,7 +79,7 @@ static fastcall void intel_machine_check(struct pt_regs * regs, long error_code)
79} 79}
80 80
81/* Set up machine check reporting for processors with Intel style MCE */ 81/* Set up machine check reporting for processors with Intel style MCE */
82void __devinit intel_p6_mcheck_init(struct cpuinfo_x86 *c) 82void intel_p6_mcheck_init(struct cpuinfo_x86 *c)
83{ 83{
84 u32 l, h; 84 u32 l, h;
85 int i; 85 int i;
diff --git a/arch/i386/kernel/cpu/mcheck/winchip.c b/arch/i386/kernel/cpu/mcheck/winchip.c
index 5b9d2dd411d3..9e424b6c293d 100644
--- a/arch/i386/kernel/cpu/mcheck/winchip.c
+++ b/arch/i386/kernel/cpu/mcheck/winchip.c
@@ -22,7 +22,7 @@ static fastcall void winchip_machine_check(struct pt_regs * regs, long error_cod
22} 22}
23 23
24/* Set up machine check reporting on the Winchip C6 series */ 24/* Set up machine check reporting on the Winchip C6 series */
25void __devinit winchip_mcheck_init(struct cpuinfo_x86 *c) 25void winchip_mcheck_init(struct cpuinfo_x86 *c)
26{ 26{
27 u32 lo, hi; 27 u32 lo, hi;
28 machine_check_vector = winchip_machine_check; 28 machine_check_vector = winchip_machine_check;
diff --git a/arch/i386/kernel/kprobes.c b/arch/i386/kernel/kprobes.c
index 6345b430b105..32b0c24ab9a6 100644
--- a/arch/i386/kernel/kprobes.c
+++ b/arch/i386/kernel/kprobes.c
@@ -31,22 +31,16 @@
31#include <linux/config.h> 31#include <linux/config.h>
32#include <linux/kprobes.h> 32#include <linux/kprobes.h>
33#include <linux/ptrace.h> 33#include <linux/ptrace.h>
34#include <linux/spinlock.h>
35#include <linux/preempt.h> 34#include <linux/preempt.h>
36#include <asm/cacheflush.h> 35#include <asm/cacheflush.h>
37#include <asm/kdebug.h> 36#include <asm/kdebug.h>
38#include <asm/desc.h> 37#include <asm/desc.h>
39 38
40static struct kprobe *current_kprobe;
41static unsigned long kprobe_status, kprobe_old_eflags, kprobe_saved_eflags;
42static struct kprobe *kprobe_prev;
43static unsigned long kprobe_status_prev, kprobe_old_eflags_prev, kprobe_saved_eflags_prev;
44static struct pt_regs jprobe_saved_regs;
45static long *jprobe_saved_esp;
46/* copy of the kernel stack at the probe fire time */
47static kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE];
48void jprobe_return_end(void); 39void jprobe_return_end(void);
49 40
41DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
42DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
43
50/* 44/*
51 * returns non-zero if opcode modifies the interrupt flag. 45 * returns non-zero if opcode modifies the interrupt flag.
52 */ 46 */
@@ -91,29 +85,30 @@ void __kprobes arch_remove_kprobe(struct kprobe *p)
91{ 85{
92} 86}
93 87
94static inline void save_previous_kprobe(void) 88static inline void save_previous_kprobe(struct kprobe_ctlblk *kcb)
95{ 89{
96 kprobe_prev = current_kprobe; 90 kcb->prev_kprobe.kp = kprobe_running();
97 kprobe_status_prev = kprobe_status; 91 kcb->prev_kprobe.status = kcb->kprobe_status;
98 kprobe_old_eflags_prev = kprobe_old_eflags; 92 kcb->prev_kprobe.old_eflags = kcb->kprobe_old_eflags;
99 kprobe_saved_eflags_prev = kprobe_saved_eflags; 93 kcb->prev_kprobe.saved_eflags = kcb->kprobe_saved_eflags;
100} 94}
101 95
102static inline void restore_previous_kprobe(void) 96static inline void restore_previous_kprobe(struct kprobe_ctlblk *kcb)
103{ 97{
104 current_kprobe = kprobe_prev; 98 __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
105 kprobe_status = kprobe_status_prev; 99 kcb->kprobe_status = kcb->prev_kprobe.status;
106 kprobe_old_eflags = kprobe_old_eflags_prev; 100 kcb->kprobe_old_eflags = kcb->prev_kprobe.old_eflags;
107 kprobe_saved_eflags = kprobe_saved_eflags_prev; 101 kcb->kprobe_saved_eflags = kcb->prev_kprobe.saved_eflags;
108} 102}
109 103
110static inline void set_current_kprobe(struct kprobe *p, struct pt_regs *regs) 104static inline void set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
105 struct kprobe_ctlblk *kcb)
111{ 106{
112 current_kprobe = p; 107 __get_cpu_var(current_kprobe) = p;
113 kprobe_saved_eflags = kprobe_old_eflags 108 kcb->kprobe_saved_eflags = kcb->kprobe_old_eflags
114 = (regs->eflags & (TF_MASK | IF_MASK)); 109 = (regs->eflags & (TF_MASK | IF_MASK));
115 if (is_IF_modifier(p->opcode)) 110 if (is_IF_modifier(p->opcode))
116 kprobe_saved_eflags &= ~IF_MASK; 111 kcb->kprobe_saved_eflags &= ~IF_MASK;
117} 112}
118 113
119static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs) 114static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
@@ -127,6 +122,7 @@ static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
127 regs->eip = (unsigned long)&p->ainsn.insn; 122 regs->eip = (unsigned long)&p->ainsn.insn;
128} 123}
129 124
125/* Called with kretprobe_lock held */
130void __kprobes arch_prepare_kretprobe(struct kretprobe *rp, 126void __kprobes arch_prepare_kretprobe(struct kretprobe *rp,
131 struct pt_regs *regs) 127 struct pt_regs *regs)
132{ 128{
@@ -157,9 +153,15 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
157 int ret = 0; 153 int ret = 0;
158 kprobe_opcode_t *addr = NULL; 154 kprobe_opcode_t *addr = NULL;
159 unsigned long *lp; 155 unsigned long *lp;
156 struct kprobe_ctlblk *kcb;
160 157
161 /* We're in an interrupt, but this is clear and BUG()-safe. */ 158 /*
159 * We don't want to be preempted for the entire
160 * duration of kprobe processing
161 */
162 preempt_disable(); 162 preempt_disable();
163 kcb = get_kprobe_ctlblk();
164
163 /* Check if the application is using LDT entry for its code segment and 165 /* Check if the application is using LDT entry for its code segment and
164 * calculate the address by reading the base address from the LDT entry. 166 * calculate the address by reading the base address from the LDT entry.
165 */ 167 */
@@ -173,15 +175,12 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
173 } 175 }
174 /* Check we're not actually recursing */ 176 /* Check we're not actually recursing */
175 if (kprobe_running()) { 177 if (kprobe_running()) {
176 /* We *are* holding lock here, so this is safe.
177 Disarm the probe we just hit, and ignore it. */
178 p = get_kprobe(addr); 178 p = get_kprobe(addr);
179 if (p) { 179 if (p) {
180 if (kprobe_status == KPROBE_HIT_SS && 180 if (kcb->kprobe_status == KPROBE_HIT_SS &&
181 *p->ainsn.insn == BREAKPOINT_INSTRUCTION) { 181 *p->ainsn.insn == BREAKPOINT_INSTRUCTION) {
182 regs->eflags &= ~TF_MASK; 182 regs->eflags &= ~TF_MASK;
183 regs->eflags |= kprobe_saved_eflags; 183 regs->eflags |= kcb->kprobe_saved_eflags;
184 unlock_kprobes();
185 goto no_kprobe; 184 goto no_kprobe;
186 } 185 }
187 /* We have reentered the kprobe_handler(), since 186 /* We have reentered the kprobe_handler(), since
@@ -190,26 +189,23 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
190 * just single step on the instruction of the new probe 189 * just single step on the instruction of the new probe
191 * without calling any user handlers. 190 * without calling any user handlers.
192 */ 191 */
193 save_previous_kprobe(); 192 save_previous_kprobe(kcb);
194 set_current_kprobe(p, regs); 193 set_current_kprobe(p, regs, kcb);
195 p->nmissed++; 194 p->nmissed++;
196 prepare_singlestep(p, regs); 195 prepare_singlestep(p, regs);
197 kprobe_status = KPROBE_REENTER; 196 kcb->kprobe_status = KPROBE_REENTER;
198 return 1; 197 return 1;
199 } else { 198 } else {
200 p = current_kprobe; 199 p = __get_cpu_var(current_kprobe);
201 if (p->break_handler && p->break_handler(p, regs)) { 200 if (p->break_handler && p->break_handler(p, regs)) {
202 goto ss_probe; 201 goto ss_probe;
203 } 202 }
204 } 203 }
205 /* If it's not ours, can't be delete race, (we hold lock). */
206 goto no_kprobe; 204 goto no_kprobe;
207 } 205 }
208 206
209 lock_kprobes();
210 p = get_kprobe(addr); 207 p = get_kprobe(addr);
211 if (!p) { 208 if (!p) {
212 unlock_kprobes();
213 if (regs->eflags & VM_MASK) { 209 if (regs->eflags & VM_MASK) {
214 /* We are in virtual-8086 mode. Return 0 */ 210 /* We are in virtual-8086 mode. Return 0 */
215 goto no_kprobe; 211 goto no_kprobe;
@@ -232,8 +228,8 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
232 goto no_kprobe; 228 goto no_kprobe;
233 } 229 }
234 230
235 kprobe_status = KPROBE_HIT_ACTIVE; 231 set_current_kprobe(p, regs, kcb);
236 set_current_kprobe(p, regs); 232 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
237 233
238 if (p->pre_handler && p->pre_handler(p, regs)) 234 if (p->pre_handler && p->pre_handler(p, regs))
239 /* handler has already set things up, so skip ss setup */ 235 /* handler has already set things up, so skip ss setup */
@@ -241,7 +237,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
241 237
242ss_probe: 238ss_probe:
243 prepare_singlestep(p, regs); 239 prepare_singlestep(p, regs);
244 kprobe_status = KPROBE_HIT_SS; 240 kcb->kprobe_status = KPROBE_HIT_SS;
245 return 1; 241 return 1;
246 242
247no_kprobe: 243no_kprobe:
@@ -269,9 +265,10 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
269 struct kretprobe_instance *ri = NULL; 265 struct kretprobe_instance *ri = NULL;
270 struct hlist_head *head; 266 struct hlist_head *head;
271 struct hlist_node *node, *tmp; 267 struct hlist_node *node, *tmp;
272 unsigned long orig_ret_address = 0; 268 unsigned long flags, orig_ret_address = 0;
273 unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline; 269 unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline;
274 270
271 spin_lock_irqsave(&kretprobe_lock, flags);
275 head = kretprobe_inst_table_head(current); 272 head = kretprobe_inst_table_head(current);
276 273
277 /* 274 /*
@@ -310,14 +307,15 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
310 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address)); 307 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
311 regs->eip = orig_ret_address; 308 regs->eip = orig_ret_address;
312 309
313 unlock_kprobes(); 310 reset_current_kprobe();
311 spin_unlock_irqrestore(&kretprobe_lock, flags);
314 preempt_enable_no_resched(); 312 preempt_enable_no_resched();
315 313
316 /* 314 /*
317 * By returning a non-zero value, we are telling 315 * By returning a non-zero value, we are telling
318 * kprobe_handler() that we have handled unlocking 316 * kprobe_handler() that we don't want the post_handler
319 * and re-enabling preemption. 317 * to run (and have re-enabled preemption)
320 */ 318 */
321 return 1; 319 return 1;
322} 320}
323 321
@@ -343,7 +341,8 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
343 * that is atop the stack is the address following the copied instruction. 341 * that is atop the stack is the address following the copied instruction.
344 * We need to make it the address following the original instruction. 342 * We need to make it the address following the original instruction.
345 */ 343 */
346static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs) 344static void __kprobes resume_execution(struct kprobe *p,
345 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
347{ 346{
348 unsigned long *tos = (unsigned long *)&regs->esp; 347 unsigned long *tos = (unsigned long *)&regs->esp;
349 unsigned long next_eip = 0; 348 unsigned long next_eip = 0;
@@ -353,7 +352,7 @@ static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
353 switch (p->ainsn.insn[0]) { 352 switch (p->ainsn.insn[0]) {
354 case 0x9c: /* pushfl */ 353 case 0x9c: /* pushfl */
355 *tos &= ~(TF_MASK | IF_MASK); 354 *tos &= ~(TF_MASK | IF_MASK);
356 *tos |= kprobe_old_eflags; 355 *tos |= kcb->kprobe_old_eflags;
357 break; 356 break;
358 case 0xc3: /* ret/lret */ 357 case 0xc3: /* ret/lret */
359 case 0xcb: 358 case 0xcb:
@@ -394,27 +393,30 @@ static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
394 393
395/* 394/*
396 * Interrupts are disabled on entry as trap1 is an interrupt gate and they 395 * Interrupts are disabled on entry as trap1 is an interrupt gate and they
397 * remain disabled thoroughout this function. And we hold kprobe lock. 396 * remain disabled thoroughout this function.
398 */ 397 */
399static inline int post_kprobe_handler(struct pt_regs *regs) 398static inline int post_kprobe_handler(struct pt_regs *regs)
400{ 399{
401 if (!kprobe_running()) 400 struct kprobe *cur = kprobe_running();
401 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
402
403 if (!cur)
402 return 0; 404 return 0;
403 405
404 if ((kprobe_status != KPROBE_REENTER) && current_kprobe->post_handler) { 406 if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
405 kprobe_status = KPROBE_HIT_SSDONE; 407 kcb->kprobe_status = KPROBE_HIT_SSDONE;
406 current_kprobe->post_handler(current_kprobe, regs, 0); 408 cur->post_handler(cur, regs, 0);
407 } 409 }
408 410
409 resume_execution(current_kprobe, regs); 411 resume_execution(cur, regs, kcb);
410 regs->eflags |= kprobe_saved_eflags; 412 regs->eflags |= kcb->kprobe_saved_eflags;
411 413
412 /*Restore back the original saved kprobes variables and continue. */ 414 /*Restore back the original saved kprobes variables and continue. */
413 if (kprobe_status == KPROBE_REENTER) { 415 if (kcb->kprobe_status == KPROBE_REENTER) {
414 restore_previous_kprobe(); 416 restore_previous_kprobe(kcb);
415 goto out; 417 goto out;
416 } 418 }
417 unlock_kprobes(); 419 reset_current_kprobe();
418out: 420out:
419 preempt_enable_no_resched(); 421 preempt_enable_no_resched();
420 422
@@ -429,18 +431,19 @@ out:
429 return 1; 431 return 1;
430} 432}
431 433
432/* Interrupts disabled, kprobe_lock held. */
433static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr) 434static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
434{ 435{
435 if (current_kprobe->fault_handler 436 struct kprobe *cur = kprobe_running();
436 && current_kprobe->fault_handler(current_kprobe, regs, trapnr)) 437 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
438
439 if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
437 return 1; 440 return 1;
438 441
439 if (kprobe_status & KPROBE_HIT_SS) { 442 if (kcb->kprobe_status & KPROBE_HIT_SS) {
440 resume_execution(current_kprobe, regs); 443 resume_execution(cur, regs, kcb);
441 regs->eflags |= kprobe_old_eflags; 444 regs->eflags |= kcb->kprobe_old_eflags;
442 445
443 unlock_kprobes(); 446 reset_current_kprobe();
444 preempt_enable_no_resched(); 447 preempt_enable_no_resched();
445 } 448 }
446 return 0; 449 return 0;
@@ -453,39 +456,41 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
453 unsigned long val, void *data) 456 unsigned long val, void *data)
454{ 457{
455 struct die_args *args = (struct die_args *)data; 458 struct die_args *args = (struct die_args *)data;
459 int ret = NOTIFY_DONE;
460
456 switch (val) { 461 switch (val) {
457 case DIE_INT3: 462 case DIE_INT3:
458 if (kprobe_handler(args->regs)) 463 if (kprobe_handler(args->regs))
459 return NOTIFY_STOP; 464 ret = NOTIFY_STOP;
460 break; 465 break;
461 case DIE_DEBUG: 466 case DIE_DEBUG:
462 if (post_kprobe_handler(args->regs)) 467 if (post_kprobe_handler(args->regs))
463 return NOTIFY_STOP; 468 ret = NOTIFY_STOP;
464 break; 469 break;
465 case DIE_GPF: 470 case DIE_GPF:
466 if (kprobe_running() &&
467 kprobe_fault_handler(args->regs, args->trapnr))
468 return NOTIFY_STOP;
469 break;
470 case DIE_PAGE_FAULT: 471 case DIE_PAGE_FAULT:
472 /* kprobe_running() needs smp_processor_id() */
473 preempt_disable();
471 if (kprobe_running() && 474 if (kprobe_running() &&
472 kprobe_fault_handler(args->regs, args->trapnr)) 475 kprobe_fault_handler(args->regs, args->trapnr))
473 return NOTIFY_STOP; 476 ret = NOTIFY_STOP;
477 preempt_enable();
474 break; 478 break;
475 default: 479 default:
476 break; 480 break;
477 } 481 }
478 return NOTIFY_DONE; 482 return ret;
479} 483}
480 484
481int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) 485int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
482{ 486{
483 struct jprobe *jp = container_of(p, struct jprobe, kp); 487 struct jprobe *jp = container_of(p, struct jprobe, kp);
484 unsigned long addr; 488 unsigned long addr;
489 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
485 490
486 jprobe_saved_regs = *regs; 491 kcb->jprobe_saved_regs = *regs;
487 jprobe_saved_esp = &regs->esp; 492 kcb->jprobe_saved_esp = &regs->esp;
488 addr = (unsigned long)jprobe_saved_esp; 493 addr = (unsigned long)(kcb->jprobe_saved_esp);
489 494
490 /* 495 /*
491 * TBD: As Linus pointed out, gcc assumes that the callee 496 * TBD: As Linus pointed out, gcc assumes that the callee
@@ -494,7 +499,8 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
494 * we also save and restore enough stack bytes to cover 499 * we also save and restore enough stack bytes to cover
495 * the argument area. 500 * the argument area.
496 */ 501 */
497 memcpy(jprobes_stack, (kprobe_opcode_t *) addr, MIN_STACK_SIZE(addr)); 502 memcpy(kcb->jprobes_stack, (kprobe_opcode_t *)addr,
503 MIN_STACK_SIZE(addr));
498 regs->eflags &= ~IF_MASK; 504 regs->eflags &= ~IF_MASK;
499 regs->eip = (unsigned long)(jp->entry); 505 regs->eip = (unsigned long)(jp->entry);
500 return 1; 506 return 1;
@@ -502,36 +508,40 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
502 508
503void __kprobes jprobe_return(void) 509void __kprobes jprobe_return(void)
504{ 510{
505 preempt_enable_no_resched(); 511 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
512
506 asm volatile (" xchgl %%ebx,%%esp \n" 513 asm volatile (" xchgl %%ebx,%%esp \n"
507 " int3 \n" 514 " int3 \n"
508 " .globl jprobe_return_end \n" 515 " .globl jprobe_return_end \n"
509 " jprobe_return_end: \n" 516 " jprobe_return_end: \n"
510 " nop \n"::"b" 517 " nop \n"::"b"
511 (jprobe_saved_esp):"memory"); 518 (kcb->jprobe_saved_esp):"memory");
512} 519}
513 520
514int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) 521int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
515{ 522{
523 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
516 u8 *addr = (u8 *) (regs->eip - 1); 524 u8 *addr = (u8 *) (regs->eip - 1);
517 unsigned long stack_addr = (unsigned long)jprobe_saved_esp; 525 unsigned long stack_addr = (unsigned long)(kcb->jprobe_saved_esp);
518 struct jprobe *jp = container_of(p, struct jprobe, kp); 526 struct jprobe *jp = container_of(p, struct jprobe, kp);
519 527
520 if ((addr > (u8 *) jprobe_return) && (addr < (u8 *) jprobe_return_end)) { 528 if ((addr > (u8 *) jprobe_return) && (addr < (u8 *) jprobe_return_end)) {
521 if (&regs->esp != jprobe_saved_esp) { 529 if (&regs->esp != kcb->jprobe_saved_esp) {
522 struct pt_regs *saved_regs = 530 struct pt_regs *saved_regs =
523 container_of(jprobe_saved_esp, struct pt_regs, esp); 531 container_of(kcb->jprobe_saved_esp,
532 struct pt_regs, esp);
524 printk("current esp %p does not match saved esp %p\n", 533 printk("current esp %p does not match saved esp %p\n",
525 &regs->esp, jprobe_saved_esp); 534 &regs->esp, kcb->jprobe_saved_esp);
526 printk("Saved registers for jprobe %p\n", jp); 535 printk("Saved registers for jprobe %p\n", jp);
527 show_registers(saved_regs); 536 show_registers(saved_regs);
528 printk("Current registers\n"); 537 printk("Current registers\n");
529 show_registers(regs); 538 show_registers(regs);
530 BUG(); 539 BUG();
531 } 540 }
532 *regs = jprobe_saved_regs; 541 *regs = kcb->jprobe_saved_regs;
533 memcpy((kprobe_opcode_t *) stack_addr, jprobes_stack, 542 memcpy((kprobe_opcode_t *) stack_addr, kcb->jprobes_stack,
534 MIN_STACK_SIZE(stack_addr)); 543 MIN_STACK_SIZE(stack_addr));
544 preempt_enable_no_resched();
535 return 1; 545 return 1;
536 } 546 }
537 return 0; 547 return 0;
diff --git a/arch/i386/kernel/ldt.c b/arch/i386/kernel/ldt.c
index fe1ffa55587d..983f95707e11 100644
--- a/arch/i386/kernel/ldt.c
+++ b/arch/i386/kernel/ldt.c
@@ -18,6 +18,7 @@
18#include <asm/system.h> 18#include <asm/system.h>
19#include <asm/ldt.h> 19#include <asm/ldt.h>
20#include <asm/desc.h> 20#include <asm/desc.h>
21#include <asm/mmu_context.h>
21 22
22#ifdef CONFIG_SMP /* avoids "defined but not used" warnig */ 23#ifdef CONFIG_SMP /* avoids "defined but not used" warnig */
23static void flush_ldt(void *null) 24static void flush_ldt(void *null)
diff --git a/arch/i386/kernel/mca.c b/arch/i386/kernel/mca.c
index 8600faeea29d..558bb207720f 100644
--- a/arch/i386/kernel/mca.c
+++ b/arch/i386/kernel/mca.c
@@ -132,7 +132,7 @@ static struct resource mca_standard_resources[] = {
132 { .start = 0x100, .end = 0x107, .name = "POS (MCA)" } 132 { .start = 0x100, .end = 0x107, .name = "POS (MCA)" }
133}; 133};
134 134
135#define MCA_STANDARD_RESOURCES (sizeof(mca_standard_resources)/sizeof(struct resource)) 135#define MCA_STANDARD_RESOURCES ARRAY_SIZE(mca_standard_resources)
136 136
137/** 137/**
138 * mca_read_and_store_pos - read the POS registers into a memory buffer 138 * mca_read_and_store_pos - read the POS registers into a memory buffer
diff --git a/arch/i386/kernel/ptrace.c b/arch/i386/kernel/ptrace.c
index efd11f09c996..5ffbb4b7ad05 100644
--- a/arch/i386/kernel/ptrace.c
+++ b/arch/i386/kernel/ptrace.c
@@ -354,49 +354,12 @@ ptrace_set_thread_area(struct task_struct *child,
354 return 0; 354 return 0;
355} 355}
356 356
357asmlinkage long sys_ptrace(long request, long pid, long addr, long data) 357long arch_ptrace(struct task_struct *child, long request, long addr, long data)
358{ 358{
359 struct task_struct *child;
360 struct user * dummy = NULL; 359 struct user * dummy = NULL;
361 int i, ret; 360 int i, ret;
362 unsigned long __user *datap = (unsigned long __user *)data; 361 unsigned long __user *datap = (unsigned long __user *)data;
363 362
364 lock_kernel();
365 ret = -EPERM;
366 if (request == PTRACE_TRACEME) {
367 /* are we already being traced? */
368 if (current->ptrace & PT_PTRACED)
369 goto out;
370 ret = security_ptrace(current->parent, current);
371 if (ret)
372 goto out;
373 /* set the ptrace bit in the process flags. */
374 current->ptrace |= PT_PTRACED;
375 ret = 0;
376 goto out;
377 }
378 ret = -ESRCH;
379 read_lock(&tasklist_lock);
380 child = find_task_by_pid(pid);
381 if (child)
382 get_task_struct(child);
383 read_unlock(&tasklist_lock);
384 if (!child)
385 goto out;
386
387 ret = -EPERM;
388 if (pid == 1) /* you may not mess with init */
389 goto out_tsk;
390
391 if (request == PTRACE_ATTACH) {
392 ret = ptrace_attach(child);
393 goto out_tsk;
394 }
395
396 ret = ptrace_check_attach(child, request == PTRACE_KILL);
397 if (ret < 0)
398 goto out_tsk;
399
400 switch (request) { 363 switch (request) {
401 /* when I and D space are separate, these will need to be fixed. */ 364 /* when I and D space are separate, these will need to be fixed. */
402 case PTRACE_PEEKTEXT: /* read word at location addr. */ 365 case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -663,10 +626,7 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
663 ret = ptrace_request(child, request, addr, data); 626 ret = ptrace_request(child, request, addr, data);
664 break; 627 break;
665 } 628 }
666out_tsk: 629 out_tsk:
667 put_task_struct(child);
668out:
669 unlock_kernel();
670 return ret; 630 return ret;
671} 631}
672 632
diff --git a/arch/i386/kernel/reboot_fixups.c b/arch/i386/kernel/reboot_fixups.c
index c9b87330aeea..10e21a4773dd 100644
--- a/arch/i386/kernel/reboot_fixups.c
+++ b/arch/i386/kernel/reboot_fixups.c
@@ -10,6 +10,7 @@
10 10
11#include <asm/delay.h> 11#include <asm/delay.h>
12#include <linux/pci.h> 12#include <linux/pci.h>
13#include <linux/reboot_fixups.h>
13 14
14static void cs5530a_warm_reset(struct pci_dev *dev) 15static void cs5530a_warm_reset(struct pci_dev *dev)
15{ 16{
@@ -42,7 +43,7 @@ void mach_reboot_fixups(void)
42 struct pci_dev *dev; 43 struct pci_dev *dev;
43 int i; 44 int i;
44 45
45 for (i=0; i < (sizeof(fixups_table)/sizeof(fixups_table[0])); i++) { 46 for (i=0; i < ARRAY_SIZE(fixups_table); i++) {
46 cur = &(fixups_table[i]); 47 cur = &(fixups_table[i]);
47 dev = pci_get_device(cur->vendor, cur->device, NULL); 48 dev = pci_get_device(cur->vendor, cur->device, NULL);
48 if (!dev) 49 if (!dev)
diff --git a/arch/i386/kernel/scx200.c b/arch/i386/kernel/scx200.c
index 69e203a0d330..9c968ae67c43 100644
--- a/arch/i386/kernel/scx200.c
+++ b/arch/i386/kernel/scx200.c
@@ -12,6 +12,7 @@
12#include <linux/pci.h> 12#include <linux/pci.h>
13 13
14#include <linux/scx200.h> 14#include <linux/scx200.h>
15#include <linux/scx200_gpio.h>
15 16
16/* Verify that the configuration block really is there */ 17/* Verify that the configuration block really is there */
17#define scx200_cb_probe(base) (inw((base) + SCx200_CBA) == (base)) 18#define scx200_cb_probe(base) (inw((base) + SCx200_CBA) == (base))
diff --git a/arch/i386/kernel/smpboot.c b/arch/i386/kernel/smpboot.c
index 01b618e73ecd..47ec76794d02 100644
--- a/arch/i386/kernel/smpboot.c
+++ b/arch/i386/kernel/smpboot.c
@@ -68,11 +68,9 @@ EXPORT_SYMBOL(smp_num_siblings);
68 68
69/* Package ID of each logical CPU */ 69/* Package ID of each logical CPU */
70int phys_proc_id[NR_CPUS] __read_mostly = {[0 ... NR_CPUS-1] = BAD_APICID}; 70int phys_proc_id[NR_CPUS] __read_mostly = {[0 ... NR_CPUS-1] = BAD_APICID};
71EXPORT_SYMBOL(phys_proc_id);
72 71
73/* Core ID of each logical CPU */ 72/* Core ID of each logical CPU */
74int cpu_core_id[NR_CPUS] __read_mostly = {[0 ... NR_CPUS-1] = BAD_APICID}; 73int cpu_core_id[NR_CPUS] __read_mostly = {[0 ... NR_CPUS-1] = BAD_APICID};
75EXPORT_SYMBOL(cpu_core_id);
76 74
77cpumask_t cpu_sibling_map[NR_CPUS] __read_mostly; 75cpumask_t cpu_sibling_map[NR_CPUS] __read_mostly;
78EXPORT_SYMBOL(cpu_sibling_map); 76EXPORT_SYMBOL(cpu_sibling_map);
@@ -612,7 +610,7 @@ static inline void __inquire_remote_apic(int apicid)
612 610
613 printk("Inquiring remote APIC #%d...\n", apicid); 611 printk("Inquiring remote APIC #%d...\n", apicid);
614 612
615 for (i = 0; i < sizeof(regs) / sizeof(*regs); i++) { 613 for (i = 0; i < ARRAY_SIZE(regs); i++) {
616 printk("... APIC #%d %s: ", apicid, names[i]); 614 printk("... APIC #%d %s: ", apicid, names[i]);
617 615
618 /* 616 /*
diff --git a/arch/i386/oprofile/Kconfig b/arch/i386/oprofile/Kconfig
index 5ade19801b97..d8a84088471a 100644
--- a/arch/i386/oprofile/Kconfig
+++ b/arch/i386/oprofile/Kconfig
@@ -1,7 +1,3 @@
1
2menu "Profiling support"
3 depends on EXPERIMENTAL
4
5config PROFILING 1config PROFILING
6 bool "Profiling support (EXPERIMENTAL)" 2 bool "Profiling support (EXPERIMENTAL)"
7 help 3 help
@@ -19,5 +15,3 @@ config OPROFILE
19 15
20 If unsure, say N. 16 If unsure, say N.
21 17
22endmenu
23
diff --git a/arch/i386/power/cpu.c b/arch/i386/power/cpu.c
index 1f1572692e0b..50a0bef8c85f 100644
--- a/arch/i386/power/cpu.c
+++ b/arch/i386/power/cpu.c
@@ -118,6 +118,7 @@ void __restore_processor_state(struct saved_context *ctxt)
118 fix_processor_context(); 118 fix_processor_context();
119 do_fpu_end(); 119 do_fpu_end();
120 mtrr_ap_init(); 120 mtrr_ap_init();
121 mcheck_init(&boot_cpu_data);
121} 122}
122 123
123void restore_processor_state(void) 124void restore_processor_state(void)
diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
index 3b4248cff9a7..d4de8a4814be 100644
--- a/arch/ia64/Kconfig
+++ b/arch/ia64/Kconfig
@@ -191,6 +191,7 @@ config IOSAPIC
191 191
192config IA64_SGI_SN_XP 192config IA64_SGI_SN_XP
193 tristate "Support communication between SGI SSIs" 193 tristate "Support communication between SGI SSIs"
194 depends on IA64_GENERIC || IA64_SGI_SN2
194 select IA64_UNCACHED_ALLOCATOR 195 select IA64_UNCACHED_ALLOCATOR
195 help 196 help
196 An SGI machine can be divided into multiple Single System 197 An SGI machine can be divided into multiple Single System
@@ -426,8 +427,21 @@ config GENERIC_PENDING_IRQ
426 427
427source "arch/ia64/hp/sim/Kconfig" 428source "arch/ia64/hp/sim/Kconfig"
428 429
430menu "Instrumentation Support"
431 depends on EXPERIMENTAL
432
429source "arch/ia64/oprofile/Kconfig" 433source "arch/ia64/oprofile/Kconfig"
430 434
435config KPROBES
436 bool "Kprobes (EXPERIMENTAL)"
437 help
438 Kprobes allows you to trap at almost any kernel address and
439 execute a callback function. register_kprobe() establishes
440 a probepoint and specifies the callback. Kprobes is useful
441 for kernel debugging, non-intrusive instrumentation and testing.
442 If in doubt, say "N".
443endmenu
444
431source "arch/ia64/Kconfig.debug" 445source "arch/ia64/Kconfig.debug"
432 446
433source "security/Kconfig" 447source "security/Kconfig"
diff --git a/arch/ia64/Kconfig.debug b/arch/ia64/Kconfig.debug
index fda67ac993d7..de9d507ba0fd 100644
--- a/arch/ia64/Kconfig.debug
+++ b/arch/ia64/Kconfig.debug
@@ -2,17 +2,6 @@ menu "Kernel hacking"
2 2
3source "lib/Kconfig.debug" 3source "lib/Kconfig.debug"
4 4
5config KPROBES
6 bool "Kprobes"
7 depends on DEBUG_KERNEL
8 help
9 Kprobes allows you to trap at almost any kernel address and
10 execute a callback function. register_kprobe() establishes
11 a probepoint and specifies the callback. Kprobes is useful
12 for kernel debugging, non-intrusive instrumentation and testing.
13 If in doubt, say "N".
14
15
16choice 5choice
17 prompt "Physical memory granularity" 6 prompt "Physical memory granularity"
18 default IA64_GRANULE_64MB 7 default IA64_GRANULE_64MB
diff --git a/arch/ia64/hp/sim/simserial.c b/arch/ia64/hp/sim/simserial.c
index b42ec37be51c..19ee635eeb70 100644
--- a/arch/ia64/hp/sim/simserial.c
+++ b/arch/ia64/hp/sim/simserial.c
@@ -642,10 +642,8 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
642 info->event = 0; 642 info->event = 0;
643 info->tty = 0; 643 info->tty = 0;
644 if (info->blocked_open) { 644 if (info->blocked_open) {
645 if (info->close_delay) { 645 if (info->close_delay)
646 current->state = TASK_INTERRUPTIBLE; 646 schedule_timeout_interruptible(info->close_delay);
647 schedule_timeout(info->close_delay);
648 }
649 wake_up_interruptible(&info->open_wait); 647 wake_up_interruptible(&info->open_wait);
650 } 648 }
651 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 649 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c
index 471086b808a4..96736a119c91 100644
--- a/arch/ia64/kernel/kprobes.c
+++ b/arch/ia64/kernel/kprobes.c
@@ -26,7 +26,6 @@
26#include <linux/config.h> 26#include <linux/config.h>
27#include <linux/kprobes.h> 27#include <linux/kprobes.h>
28#include <linux/ptrace.h> 28#include <linux/ptrace.h>
29#include <linux/spinlock.h>
30#include <linux/string.h> 29#include <linux/string.h>
31#include <linux/slab.h> 30#include <linux/slab.h>
32#include <linux/preempt.h> 31#include <linux/preempt.h>
@@ -38,13 +37,8 @@
38 37
39extern void jprobe_inst_return(void); 38extern void jprobe_inst_return(void);
40 39
41/* kprobe_status settings */ 40DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
42#define KPROBE_HIT_ACTIVE 0x00000001 41DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
43#define KPROBE_HIT_SS 0x00000002
44
45static struct kprobe *current_kprobe, *kprobe_prev;
46static unsigned long kprobe_status, kprobe_status_prev;
47static struct pt_regs jprobe_saved_regs;
48 42
49enum instruction_type {A, I, M, F, B, L, X, u}; 43enum instruction_type {A, I, M, F, B, L, X, u};
50static enum instruction_type bundle_encoding[32][3] = { 44static enum instruction_type bundle_encoding[32][3] = {
@@ -313,21 +307,22 @@ static int __kprobes valid_kprobe_addr(int template, int slot,
313 return 0; 307 return 0;
314} 308}
315 309
316static inline void save_previous_kprobe(void) 310static inline void save_previous_kprobe(struct kprobe_ctlblk *kcb)
317{ 311{
318 kprobe_prev = current_kprobe; 312 kcb->prev_kprobe.kp = kprobe_running();
319 kprobe_status_prev = kprobe_status; 313 kcb->prev_kprobe.status = kcb->kprobe_status;
320} 314}
321 315
322static inline void restore_previous_kprobe(void) 316static inline void restore_previous_kprobe(struct kprobe_ctlblk *kcb)
323{ 317{
324 current_kprobe = kprobe_prev; 318 __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
325 kprobe_status = kprobe_status_prev; 319 kcb->kprobe_status = kcb->prev_kprobe.status;
326} 320}
327 321
328static inline void set_current_kprobe(struct kprobe *p) 322static inline void set_current_kprobe(struct kprobe *p,
323 struct kprobe_ctlblk *kcb)
329{ 324{
330 current_kprobe = p; 325 __get_cpu_var(current_kprobe) = p;
331} 326}
332 327
333static void kretprobe_trampoline(void) 328static void kretprobe_trampoline(void)
@@ -347,10 +342,11 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
347 struct kretprobe_instance *ri = NULL; 342 struct kretprobe_instance *ri = NULL;
348 struct hlist_head *head; 343 struct hlist_head *head;
349 struct hlist_node *node, *tmp; 344 struct hlist_node *node, *tmp;
350 unsigned long orig_ret_address = 0; 345 unsigned long flags, orig_ret_address = 0;
351 unsigned long trampoline_address = 346 unsigned long trampoline_address =
352 ((struct fnptr *)kretprobe_trampoline)->ip; 347 ((struct fnptr *)kretprobe_trampoline)->ip;
353 348
349 spin_lock_irqsave(&kretprobe_lock, flags);
354 head = kretprobe_inst_table_head(current); 350 head = kretprobe_inst_table_head(current);
355 351
356 /* 352 /*
@@ -389,17 +385,19 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
389 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address)); 385 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
390 regs->cr_iip = orig_ret_address; 386 regs->cr_iip = orig_ret_address;
391 387
392 unlock_kprobes(); 388 reset_current_kprobe();
389 spin_unlock_irqrestore(&kretprobe_lock, flags);
393 preempt_enable_no_resched(); 390 preempt_enable_no_resched();
394 391
395 /* 392 /*
396 * By returning a non-zero value, we are telling 393 * By returning a non-zero value, we are telling
397 * kprobe_handler() that we have handled unlocking 394 * kprobe_handler() that we don't want the post_handler
398 * and re-enabling preemption. 395 * to run (and have re-enabled preemption)
399 */ 396 */
400 return 1; 397 return 1;
401} 398}
402 399
400/* Called with kretprobe_lock held */
403void __kprobes arch_prepare_kretprobe(struct kretprobe *rp, 401void __kprobes arch_prepare_kretprobe(struct kretprobe *rp,
404 struct pt_regs *regs) 402 struct pt_regs *regs)
405{ 403{
@@ -606,17 +604,22 @@ static int __kprobes pre_kprobes_handler(struct die_args *args)
606 int ret = 0; 604 int ret = 0;
607 struct pt_regs *regs = args->regs; 605 struct pt_regs *regs = args->regs;
608 kprobe_opcode_t *addr = (kprobe_opcode_t *)instruction_pointer(regs); 606 kprobe_opcode_t *addr = (kprobe_opcode_t *)instruction_pointer(regs);
607 struct kprobe_ctlblk *kcb;
609 608
609 /*
610 * We don't want to be preempted for the entire
611 * duration of kprobe processing
612 */
610 preempt_disable(); 613 preempt_disable();
614 kcb = get_kprobe_ctlblk();
611 615
612 /* Handle recursion cases */ 616 /* Handle recursion cases */
613 if (kprobe_running()) { 617 if (kprobe_running()) {
614 p = get_kprobe(addr); 618 p = get_kprobe(addr);
615 if (p) { 619 if (p) {
616 if ( (kprobe_status == KPROBE_HIT_SS) && 620 if ((kcb->kprobe_status == KPROBE_HIT_SS) &&
617 (p->ainsn.inst_flag == INST_FLAG_BREAK_INST)) { 621 (p->ainsn.inst_flag == INST_FLAG_BREAK_INST)) {
618 ia64_psr(regs)->ss = 0; 622 ia64_psr(regs)->ss = 0;
619 unlock_kprobes();
620 goto no_kprobe; 623 goto no_kprobe;
621 } 624 }
622 /* We have reentered the pre_kprobe_handler(), since 625 /* We have reentered the pre_kprobe_handler(), since
@@ -625,17 +628,17 @@ static int __kprobes pre_kprobes_handler(struct die_args *args)
625 * just single step on the instruction of the new probe 628 * just single step on the instruction of the new probe
626 * without calling any user handlers. 629 * without calling any user handlers.
627 */ 630 */
628 save_previous_kprobe(); 631 save_previous_kprobe(kcb);
629 set_current_kprobe(p); 632 set_current_kprobe(p, kcb);
630 p->nmissed++; 633 p->nmissed++;
631 prepare_ss(p, regs); 634 prepare_ss(p, regs);
632 kprobe_status = KPROBE_REENTER; 635 kcb->kprobe_status = KPROBE_REENTER;
633 return 1; 636 return 1;
634 } else if (args->err == __IA64_BREAK_JPROBE) { 637 } else if (args->err == __IA64_BREAK_JPROBE) {
635 /* 638 /*
636 * jprobe instrumented function just completed 639 * jprobe instrumented function just completed
637 */ 640 */
638 p = current_kprobe; 641 p = __get_cpu_var(current_kprobe);
639 if (p->break_handler && p->break_handler(p, regs)) { 642 if (p->break_handler && p->break_handler(p, regs)) {
640 goto ss_probe; 643 goto ss_probe;
641 } 644 }
@@ -645,10 +648,8 @@ static int __kprobes pre_kprobes_handler(struct die_args *args)
645 } 648 }
646 } 649 }
647 650
648 lock_kprobes();
649 p = get_kprobe(addr); 651 p = get_kprobe(addr);
650 if (!p) { 652 if (!p) {
651 unlock_kprobes();
652 if (!is_ia64_break_inst(regs)) { 653 if (!is_ia64_break_inst(regs)) {
653 /* 654 /*
654 * The breakpoint instruction was removed right 655 * The breakpoint instruction was removed right
@@ -665,8 +666,8 @@ static int __kprobes pre_kprobes_handler(struct die_args *args)
665 goto no_kprobe; 666 goto no_kprobe;
666 } 667 }
667 668
668 kprobe_status = KPROBE_HIT_ACTIVE; 669 set_current_kprobe(p, kcb);
669 set_current_kprobe(p); 670 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
670 671
671 if (p->pre_handler && p->pre_handler(p, regs)) 672 if (p->pre_handler && p->pre_handler(p, regs))
672 /* 673 /*
@@ -678,7 +679,7 @@ static int __kprobes pre_kprobes_handler(struct die_args *args)
678 679
679ss_probe: 680ss_probe:
680 prepare_ss(p, regs); 681 prepare_ss(p, regs);
681 kprobe_status = KPROBE_HIT_SS; 682 kcb->kprobe_status = KPROBE_HIT_SS;
682 return 1; 683 return 1;
683 684
684no_kprobe: 685no_kprobe:
@@ -688,23 +689,25 @@ no_kprobe:
688 689
689static int __kprobes post_kprobes_handler(struct pt_regs *regs) 690static int __kprobes post_kprobes_handler(struct pt_regs *regs)
690{ 691{
691 if (!kprobe_running()) 692 struct kprobe *cur = kprobe_running();
693 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
694
695 if (!cur)
692 return 0; 696 return 0;
693 697
694 if ((kprobe_status != KPROBE_REENTER) && current_kprobe->post_handler) { 698 if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
695 kprobe_status = KPROBE_HIT_SSDONE; 699 kcb->kprobe_status = KPROBE_HIT_SSDONE;
696 current_kprobe->post_handler(current_kprobe, regs, 0); 700 cur->post_handler(cur, regs, 0);
697 } 701 }
698 702
699 resume_execution(current_kprobe, regs); 703 resume_execution(cur, regs);
700 704
701 /*Restore back the original saved kprobes variables and continue. */ 705 /*Restore back the original saved kprobes variables and continue. */
702 if (kprobe_status == KPROBE_REENTER) { 706 if (kcb->kprobe_status == KPROBE_REENTER) {
703 restore_previous_kprobe(); 707 restore_previous_kprobe(kcb);
704 goto out; 708 goto out;
705 } 709 }
706 710 reset_current_kprobe();
707 unlock_kprobes();
708 711
709out: 712out:
710 preempt_enable_no_resched(); 713 preempt_enable_no_resched();
@@ -713,16 +716,15 @@ out:
713 716
714static int __kprobes kprobes_fault_handler(struct pt_regs *regs, int trapnr) 717static int __kprobes kprobes_fault_handler(struct pt_regs *regs, int trapnr)
715{ 718{
716 if (!kprobe_running()) 719 struct kprobe *cur = kprobe_running();
717 return 0; 720 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
718 721
719 if (current_kprobe->fault_handler && 722 if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
720 current_kprobe->fault_handler(current_kprobe, regs, trapnr))
721 return 1; 723 return 1;
722 724
723 if (kprobe_status & KPROBE_HIT_SS) { 725 if (kcb->kprobe_status & KPROBE_HIT_SS) {
724 resume_execution(current_kprobe, regs); 726 resume_execution(cur, regs);
725 unlock_kprobes(); 727 reset_current_kprobe();
726 preempt_enable_no_resched(); 728 preempt_enable_no_resched();
727 } 729 }
728 730
@@ -733,31 +735,38 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
733 unsigned long val, void *data) 735 unsigned long val, void *data)
734{ 736{
735 struct die_args *args = (struct die_args *)data; 737 struct die_args *args = (struct die_args *)data;
738 int ret = NOTIFY_DONE;
739
736 switch(val) { 740 switch(val) {
737 case DIE_BREAK: 741 case DIE_BREAK:
738 if (pre_kprobes_handler(args)) 742 if (pre_kprobes_handler(args))
739 return NOTIFY_STOP; 743 ret = NOTIFY_STOP;
740 break; 744 break;
741 case DIE_SS: 745 case DIE_SS:
742 if (post_kprobes_handler(args->regs)) 746 if (post_kprobes_handler(args->regs))
743 return NOTIFY_STOP; 747 ret = NOTIFY_STOP;
744 break; 748 break;
745 case DIE_PAGE_FAULT: 749 case DIE_PAGE_FAULT:
746 if (kprobes_fault_handler(args->regs, args->trapnr)) 750 /* kprobe_running() needs smp_processor_id() */
747 return NOTIFY_STOP; 751 preempt_disable();
752 if (kprobe_running() &&
753 kprobes_fault_handler(args->regs, args->trapnr))
754 ret = NOTIFY_STOP;
755 preempt_enable();
748 default: 756 default:
749 break; 757 break;
750 } 758 }
751 return NOTIFY_DONE; 759 return ret;
752} 760}
753 761
754int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) 762int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
755{ 763{
756 struct jprobe *jp = container_of(p, struct jprobe, kp); 764 struct jprobe *jp = container_of(p, struct jprobe, kp);
757 unsigned long addr = ((struct fnptr *)(jp->entry))->ip; 765 unsigned long addr = ((struct fnptr *)(jp->entry))->ip;
766 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
758 767
759 /* save architectural state */ 768 /* save architectural state */
760 jprobe_saved_regs = *regs; 769 kcb->jprobe_saved_regs = *regs;
761 770
762 /* after rfi, execute the jprobe instrumented function */ 771 /* after rfi, execute the jprobe instrumented function */
763 regs->cr_iip = addr & ~0xFULL; 772 regs->cr_iip = addr & ~0xFULL;
@@ -775,7 +784,10 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
775 784
776int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) 785int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
777{ 786{
778 *regs = jprobe_saved_regs; 787 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
788
789 *regs = kcb->jprobe_saved_regs;
790 preempt_enable_no_resched();
779 return 1; 791 return 1;
780} 792}
781 793
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index f7dfc107cb7b..410d4804fa6e 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -4940,7 +4940,7 @@ abort_locked:
4940 if (call_made && PFM_CMD_RW_ARG(cmd) && copy_to_user(arg, args_k, base_sz*count)) ret = -EFAULT; 4940 if (call_made && PFM_CMD_RW_ARG(cmd) && copy_to_user(arg, args_k, base_sz*count)) ret = -EFAULT;
4941 4941
4942error_args: 4942error_args:
4943 if (args_k) kfree(args_k); 4943 kfree(args_k);
4944 4944
4945 DPRINT(("cmd=%s ret=%ld\n", PFM_CMD_NAME(cmd), ret)); 4945 DPRINT(("cmd=%s ret=%ld\n", PFM_CMD_NAME(cmd), ret));
4946 4946
diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c
index fc56ca2da358..3af6de36a482 100644
--- a/arch/ia64/kernel/setup.c
+++ b/arch/ia64/kernel/setup.c
@@ -92,6 +92,13 @@ extern void efi_initialize_iomem_resources(struct resource *,
92extern char _text[], _end[], _etext[]; 92extern char _text[], _end[], _etext[];
93 93
94unsigned long ia64_max_cacheline_size; 94unsigned long ia64_max_cacheline_size;
95
96int dma_get_cache_alignment(void)
97{
98 return ia64_max_cacheline_size;
99}
100EXPORT_SYMBOL(dma_get_cache_alignment);
101
95unsigned long ia64_iobase; /* virtual address for I/O accesses */ 102unsigned long ia64_iobase; /* virtual address for I/O accesses */
96EXPORT_SYMBOL(ia64_iobase); 103EXPORT_SYMBOL(ia64_iobase);
97struct io_space io_space[MAX_IO_SPACES]; 104struct io_space io_space[MAX_IO_SPACES];
diff --git a/arch/ia64/oprofile/Kconfig b/arch/ia64/oprofile/Kconfig
index 56e6f614b04a..97271ab484dc 100644
--- a/arch/ia64/oprofile/Kconfig
+++ b/arch/ia64/oprofile/Kconfig
@@ -1,7 +1,3 @@
1
2menu "Profiling support"
3 depends on EXPERIMENTAL
4
5config PROFILING 1config PROFILING
6 bool "Profiling support (EXPERIMENTAL)" 2 bool "Profiling support (EXPERIMENTAL)"
7 help 3 help
@@ -22,5 +18,3 @@ config OPROFILE
22 18
23 If unsure, say N. 19 If unsure, say N.
24 20
25endmenu
26
diff --git a/arch/m68k/atari/time.c b/arch/m68k/atari/time.c
index 6df7fb60dfea..e79bbc94216d 100644
--- a/arch/m68k/atari/time.c
+++ b/arch/m68k/atari/time.c
@@ -212,10 +212,8 @@ int atari_tt_hwclk( int op, struct rtc_time *t )
212 * additionally the RTC_SET bit is set to prevent an update cycle. 212 * additionally the RTC_SET bit is set to prevent an update cycle.
213 */ 213 */
214 214
215 while( RTC_READ(RTC_FREQ_SELECT) & RTC_UIP ) { 215 while( RTC_READ(RTC_FREQ_SELECT) & RTC_UIP )
216 current->state = TASK_INTERRUPTIBLE; 216 schedule_timeout_interruptible(HWCLK_POLL_INTERVAL);
217 schedule_timeout(HWCLK_POLL_INTERVAL);
218 }
219 217
220 local_irq_save(flags); 218 local_irq_save(flags);
221 RTC_WRITE( RTC_CONTROL, ctrl | RTC_SET ); 219 RTC_WRITE( RTC_CONTROL, ctrl | RTC_SET );
diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
index f7f1d2e5b90b..7e54422685cf 100644
--- a/arch/m68k/kernel/ptrace.c
+++ b/arch/m68k/kernel/ptrace.c
@@ -121,48 +121,11 @@ void ptrace_disable(struct task_struct *child)
121 child->thread.work.syscall_trace = 0; 121 child->thread.work.syscall_trace = 0;
122} 122}
123 123
124asmlinkage long sys_ptrace(long request, long pid, long addr, long data) 124long arch_ptrace(struct task_struct *child, long request, long addr, long data)
125{ 125{
126 struct task_struct *child;
127 unsigned long tmp; 126 unsigned long tmp;
128 int i, ret = 0; 127 int i, ret = 0;
129 128
130 lock_kernel();
131 if (request == PTRACE_TRACEME) {
132 /* are we already being traced? */
133 if (current->ptrace & PT_PTRACED) {
134 ret = -EPERM;
135 goto out;
136 }
137 /* set the ptrace bit in the process flags. */
138 current->ptrace |= PT_PTRACED;
139 goto out;
140 }
141 read_lock(&tasklist_lock);
142 child = find_task_by_pid(pid);
143 if (child)
144 get_task_struct(child);
145 read_unlock(&tasklist_lock);
146 if (unlikely(!child)) {
147 ret = -ESRCH;
148 goto out;
149 }
150
151 /* you may not mess with init */
152 if (unlikely(pid == 1)) {
153 ret = -EPERM;
154 goto out_tsk;
155 }
156
157 if (request == PTRACE_ATTACH) {
158 ret = ptrace_attach(child);
159 goto out_tsk;
160 }
161
162 ret = ptrace_check_attach(child, request == PTRACE_KILL);
163 if (ret)
164 goto out_tsk;
165
166 switch (request) { 129 switch (request) {
167 /* when I and D space are separate, these will need to be fixed. */ 130 /* when I and D space are separate, these will need to be fixed. */
168 case PTRACE_PEEKTEXT: /* read word at location addr. */ 131 case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -317,14 +280,10 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
317 ret = ptrace_request(child, request, addr, data); 280 ret = ptrace_request(child, request, addr, data);
318 break; 281 break;
319 } 282 }
320out_tsk: 283
321 put_task_struct(child);
322out:
323 unlock_kernel();
324 return ret; 284 return ret;
325out_eio: 285out_eio:
326 ret = -EIO; 286 return -EIO;
327 goto out_tsk;
328} 287}
329 288
330asmlinkage void syscall_trace(void) 289asmlinkage void syscall_trace(void)
diff --git a/arch/m68knommu/Kconfig b/arch/m68knommu/Kconfig
index 8520df9cee6d..b96498120fe9 100644
--- a/arch/m68knommu/Kconfig
+++ b/arch/m68knommu/Kconfig
@@ -71,6 +71,11 @@ config M5206e
71 help 71 help
72 Motorola ColdFire 5206e processor support. 72 Motorola ColdFire 5206e processor support.
73 73
74config M520x
75 bool "MCF520x"
76 help
77 Freescale Coldfire 5207/5208 processor support.
78
74config M523x 79config M523x
75 bool "MCF523x" 80 bool "MCF523x"
76 help 81 help
@@ -120,7 +125,7 @@ config M527x
120 125
121config COLDFIRE 126config COLDFIRE
122 bool 127 bool
123 depends on (M5206 || M5206e || M523x || M5249 || M527x || M5272 || M528x || M5307 || M5407) 128 depends on (M5206 || M5206e || M520x || M523x || M5249 || M527x || M5272 || M528x || M5307 || M5407)
124 default y 129 default y
125 130
126choice 131choice
@@ -322,6 +327,12 @@ config ELITE
322 help 327 help
323 Support for the Motorola M5206eLITE board. 328 Support for the Motorola M5206eLITE board.
324 329
330config M5208EVB
331 bool "Freescale M5208EVB board support"
332 depends on M520x
333 help
334 Support for the Freescale Coldfire M5208EVB.
335
325config M5235EVB 336config M5235EVB
326 bool "Freescale M5235EVB support" 337 bool "Freescale M5235EVB support"
327 depends on M523x 338 depends on M523x
@@ -465,10 +476,10 @@ config ARNEWSH
465 default y 476 default y
466 depends on (ARN5206 || ARN5307) 477 depends on (ARN5206 || ARN5307)
467 478
468config MOTOROLA 479config FREESCALE
469 bool 480 bool
470 default y 481 default y
471 depends on (M5206eC3 || M5235EVB || M5249C3 || M5271EVB || M5272C3 || M5275EVB || M5282EVB || M5307C3 || M5407C3) 482 depends on (M5206eC3 || M5208EVB || M5235EVB || M5249C3 || M5271EVB || M5272C3 || M5275EVB || M5282EVB || M5307C3 || M5407C3)
472 483
473config HW_FEITH 484config HW_FEITH
474 bool 485 bool
diff --git a/arch/m68knommu/Makefile b/arch/m68knommu/Makefile
index b8fdf191b8f6..b6b5c14e55fd 100644
--- a/arch/m68knommu/Makefile
+++ b/arch/m68knommu/Makefile
@@ -14,6 +14,7 @@ platform-$(CONFIG_M68VZ328) := 68VZ328
14platform-$(CONFIG_M68360) := 68360 14platform-$(CONFIG_M68360) := 68360
15platform-$(CONFIG_M5206) := 5206 15platform-$(CONFIG_M5206) := 5206
16platform-$(CONFIG_M5206e) := 5206e 16platform-$(CONFIG_M5206e) := 5206e
17platform-$(CONFIG_M520x) := 520x
17platform-$(CONFIG_M523x) := 523x 18platform-$(CONFIG_M523x) := 523x
18platform-$(CONFIG_M5249) := 5249 19platform-$(CONFIG_M5249) := 5249
19platform-$(CONFIG_M527x) := 527x 20platform-$(CONFIG_M527x) := 527x
@@ -29,7 +30,7 @@ board-$(CONFIG_UCDIMM) := ucdimm
29board-$(CONFIG_UCQUICC) := uCquicc 30board-$(CONFIG_UCQUICC) := uCquicc
30board-$(CONFIG_DRAGEN2) := de2 31board-$(CONFIG_DRAGEN2) := de2
31board-$(CONFIG_ARNEWSH) := ARNEWSH 32board-$(CONFIG_ARNEWSH) := ARNEWSH
32board-$(CONFIG_MOTOROLA) := MOTOROLA 33board-$(CONFIG_FREESCALE) := FREESCALE
33board-$(CONFIG_M5235EVB) := M5235EVB 34board-$(CONFIG_M5235EVB) := M5235EVB
34board-$(CONFIG_M5271EVB) := M5271EVB 35board-$(CONFIG_M5271EVB) := M5271EVB
35board-$(CONFIG_M5275EVB) := M5275EVB 36board-$(CONFIG_M5275EVB) := M5275EVB
@@ -41,6 +42,7 @@ board-$(CONFIG_SECUREEDGEMP3) := MP3
41board-$(CONFIG_CLEOPATRA) := CLEOPATRA 42board-$(CONFIG_CLEOPATRA) := CLEOPATRA
42board-$(CONFIG_senTec) := senTec 43board-$(CONFIG_senTec) := senTec
43board-$(CONFIG_SNEHA) := SNEHA 44board-$(CONFIG_SNEHA) := SNEHA
45board-$(CONFIG_M5208EVB) := M5208EVB
44board-$(CONFIG_MOD5272) := MOD5272 46board-$(CONFIG_MOD5272) := MOD5272
45BOARD := $(board-y) 47BOARD := $(board-y)
46 48
@@ -56,6 +58,7 @@ MODEL := $(model-y)
56# 58#
57cpuclass-$(CONFIG_M5206) := 5307 59cpuclass-$(CONFIG_M5206) := 5307
58cpuclass-$(CONFIG_M5206e) := 5307 60cpuclass-$(CONFIG_M5206e) := 5307
61cpuclass-$(CONFIG_M520x) := 5307
59cpuclass-$(CONFIG_M523x) := 5307 62cpuclass-$(CONFIG_M523x) := 5307
60cpuclass-$(CONFIG_M5249) := 5307 63cpuclass-$(CONFIG_M5249) := 5307
61cpuclass-$(CONFIG_M527x) := 5307 64cpuclass-$(CONFIG_M527x) := 5307
@@ -80,6 +83,7 @@ export PLATFORM BOARD MODEL CPUCLASS
80# 83#
81cflags-$(CONFIG_M5206) := -m5200 -Wa,-S -Wa,-m5200 84cflags-$(CONFIG_M5206) := -m5200 -Wa,-S -Wa,-m5200
82cflags-$(CONFIG_M5206e) := -m5200 -Wa,-S -Wa,-m5200 85cflags-$(CONFIG_M5206e) := -m5200 -Wa,-S -Wa,-m5200
86cflags-$(CONFIG_M520x) := -m5307 -Wa,-S -Wa,-m5307
83cflags-$(CONFIG_M523x) := -m5307 -Wa,-S -Wa,-m5307 87cflags-$(CONFIG_M523x) := -m5307 -Wa,-S -Wa,-m5307
84cflags-$(CONFIG_M5249) := -m5200 -Wa,-S -Wa,-m5200 88cflags-$(CONFIG_M5249) := -m5200 -Wa,-S -Wa,-m5200
85cflags-$(CONFIG_M527x) := -m5307 -Wa,-S -Wa,-m5307 89cflags-$(CONFIG_M527x) := -m5307 -Wa,-S -Wa,-m5307
@@ -95,7 +99,6 @@ cflags-$(CONFIG_M68360) := -m68332
95AFLAGS += $(cflags-y) 99AFLAGS += $(cflags-y)
96 100
97CFLAGS += $(cflags-y) 101CFLAGS += $(cflags-y)
98CFLAGS += -fno-builtin
99CFLAGS += -O1 -g 102CFLAGS += -O1 -g
100CFLAGS += -D__linux__ 103CFLAGS += -D__linux__
101CFLAGS += -DUTS_SYSNAME=\"uClinux\" 104CFLAGS += -DUTS_SYSNAME=\"uClinux\"
diff --git a/arch/m68knommu/kernel/asm-offsets.c b/arch/m68knommu/kernel/asm-offsets.c
index cd3ffe12653e..b988c7bdc6e4 100644
--- a/arch/m68knommu/kernel/asm-offsets.c
+++ b/arch/m68knommu/kernel/asm-offsets.c
@@ -15,6 +15,7 @@
15#include <linux/hardirq.h> 15#include <linux/hardirq.h>
16#include <asm/bootinfo.h> 16#include <asm/bootinfo.h>
17#include <asm/irq.h> 17#include <asm/irq.h>
18#include <asm/irqnode.h>
18#include <asm/thread_info.h> 19#include <asm/thread_info.h>
19 20
20#define DEFINE(sym, val) \ 21#define DEFINE(sym, val) \
diff --git a/arch/m68knommu/kernel/ptrace.c b/arch/m68knommu/kernel/ptrace.c
index 621d7b91ccfe..262ab8c72e5f 100644
--- a/arch/m68knommu/kernel/ptrace.c
+++ b/arch/m68knommu/kernel/ptrace.c
@@ -101,43 +101,10 @@ void ptrace_disable(struct task_struct *child)
101 put_reg(child, PT_SR, tmp); 101 put_reg(child, PT_SR, tmp);
102} 102}
103 103
104asmlinkage long sys_ptrace(long request, long pid, long addr, long data) 104long arch_ptrace(truct task_struct *child, long request, long addr, long data)
105{ 105{
106 struct task_struct *child;
107 int ret; 106 int ret;
108 107
109 lock_kernel();
110 ret = -EPERM;
111 if (request == PTRACE_TRACEME) {
112 /* are we already being traced? */
113 if (current->ptrace & PT_PTRACED)
114 goto out;
115 /* set the ptrace bit in the process flags. */
116 current->ptrace |= PT_PTRACED;
117 ret = 0;
118 goto out;
119 }
120 ret = -ESRCH;
121 read_lock(&tasklist_lock);
122 child = find_task_by_pid(pid);
123 if (child)
124 get_task_struct(child);
125 read_unlock(&tasklist_lock);
126 if (!child)
127 goto out;
128
129 ret = -EPERM;
130 if (pid == 1) /* you may not mess with init */
131 goto out_tsk;
132
133 if (request == PTRACE_ATTACH) {
134 ret = ptrace_attach(child);
135 goto out_tsk;
136 }
137 ret = ptrace_check_attach(child, request == PTRACE_KILL);
138 if (ret < 0)
139 goto out_tsk;
140
141 switch (request) { 108 switch (request) {
142 /* when I and D space are separate, these will need to be fixed. */ 109 /* when I and D space are separate, these will need to be fixed. */
143 case PTRACE_PEEKTEXT: /* read word at location addr. */ 110 case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -357,10 +324,6 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
357 ret = -EIO; 324 ret = -EIO;
358 break; 325 break;
359 } 326 }
360out_tsk:
361 put_task_struct(child);
362out:
363 unlock_kernel();
364 return ret; 327 return ret;
365} 328}
366 329
diff --git a/arch/m68knommu/kernel/setup.c b/arch/m68knommu/kernel/setup.c
index a220345e9746..abb80fa2b940 100644
--- a/arch/m68knommu/kernel/setup.c
+++ b/arch/m68knommu/kernel/setup.c
@@ -107,6 +107,9 @@ void (*mach_power_off)( void ) = NULL;
107#if defined(CONFIG_M5206e) 107#if defined(CONFIG_M5206e)
108 #define CPU "COLDFIRE(m5206e)" 108 #define CPU "COLDFIRE(m5206e)"
109#endif 109#endif
110#if defined(CONFIG_M520x)
111 #define CPU "COLDFIRE(m520x)"
112#endif
110#if defined(CONFIG_M523x) 113#if defined(CONFIG_M523x)
111 #define CPU "COLDFIRE(m523x)" 114 #define CPU "COLDFIRE(m523x)"
112#endif 115#endif
@@ -132,7 +135,7 @@ void (*mach_power_off)( void ) = NULL;
132 #define CPU "COLDFIRE(m5407)" 135 #define CPU "COLDFIRE(m5407)"
133#endif 136#endif
134#ifndef CPU 137#ifndef CPU
135 #define CPU "UNKOWN" 138 #define CPU "UNKNOWN"
136#endif 139#endif
137 140
138/* (es) */ 141/* (es) */
diff --git a/arch/m68knommu/kernel/vmlinux.lds.S b/arch/m68knommu/kernel/vmlinux.lds.S
index 47f06787190d..0eab92ca4b97 100644
--- a/arch/m68knommu/kernel/vmlinux.lds.S
+++ b/arch/m68knommu/kernel/vmlinux.lds.S
@@ -125,6 +125,14 @@
125#endif 125#endif
126 126
127/* 127/*
128 * The Freescale 5208EVB board has 32MB of RAM.
129 */
130#if defined(CONFIG_M5208EVB)
131#define RAM_START 0x40020000
132#define RAM_LENGTH 0x01e00000
133#endif
134
135/*
128 * The senTec COBRA5272 board has nearly the same memory layout as 136 * The senTec COBRA5272 board has nearly the same memory layout as
129 * the M5272C3. We assume 16MiB ram. 137 * the M5272C3. We assume 16MiB ram.
130 */ 138 */
@@ -275,6 +283,7 @@ SECTIONS {
275 *(__ksymtab_strings) 283 *(__ksymtab_strings)
276 284
277 /* Built-in module parameters */ 285 /* Built-in module parameters */
286 . = ALIGN(4) ;
278 __start___param = .; 287 __start___param = .;
279 *(__param) 288 *(__param)
280 __stop___param = .; 289 __stop___param = .;
diff --git a/arch/m68knommu/platform/520x/Makefile b/arch/m68knommu/platform/520x/Makefile
new file mode 100644
index 000000000000..e861b05106bc
--- /dev/null
+++ b/arch/m68knommu/platform/520x/Makefile
@@ -0,0 +1,19 @@
1#
2# Makefile for the M5208 specific file.
3#
4
5#
6# If you want to play with the HW breakpoints then you will
7# need to add define this, which will give you a stack backtrace
8# on the console port whenever a DBG interrupt occurs. You have to
9# set up you HW breakpoints to trigger a DBG interrupt:
10#
11# EXTRA_CFLAGS += -DTRAP_DBG_INTERRUPT
12# EXTRA_AFLAGS += -DTRAP_DBG_INTERRUPT
13#
14
15ifdef CONFIG_FULLDEBUG
16AFLAGS += -DDEBUGGER_COMPATIBLE_CACHE=1
17endif
18
19obj-y := config.o
diff --git a/arch/m68knommu/platform/520x/config.c b/arch/m68knommu/platform/520x/config.c
new file mode 100644
index 000000000000..71dea2e0f452
--- /dev/null
+++ b/arch/m68knommu/platform/520x/config.c
@@ -0,0 +1,65 @@
1/***************************************************************************/
2
3/*
4 * linux/arch/m68knommu/platform/520x/config.c
5 *
6 * Copyright (C) 2005, Freescale (www.freescale.com)
7 * Copyright (C) 2005, Intec Automation (mike@steroidmicros.com)
8 * Copyright (C) 1999-2003, Greg Ungerer (gerg@snapgear.com)
9 * Copyright (C) 2001-2003, SnapGear Inc. (www.snapgear.com)
10 */
11
12/***************************************************************************/
13
14#include <linux/config.h>
15#include <linux/kernel.h>
16#include <linux/param.h>
17#include <asm/machdep.h>
18#include <asm/dma.h>
19
20/***************************************************************************/
21
22/*
23 * DMA channel base address table.
24 */
25unsigned int dma_base_addr[MAX_M68K_DMA_CHANNELS];
26unsigned int dma_device_address[MAX_M68K_DMA_CHANNELS];
27
28/***************************************************************************/
29
30void coldfire_pit_tick(void);
31void coldfire_pit_init(irqreturn_t (*handler)(int, void *, struct pt_regs *));
32unsigned long coldfire_pit_offset(void);
33void coldfire_trap_init(void);
34void coldfire_reset(void);
35
36/***************************************************************************/
37
38/*
39 * Program the vector to be an auto-vectored.
40 */
41
42void mcf_autovector(unsigned int vec)
43{
44 /* Everything is auto-vectored on the 520x devices */
45}
46
47/***************************************************************************/
48
49void config_BSP(char *commandp, int size)
50{
51#ifdef CONFIG_BOOTPARAM
52 strncpy(commandp, CONFIG_BOOTPARAM_STRING, size);
53 commandp[size-1] = 0;
54#else
55 memset(commandp, 0, size);
56#endif
57
58 mach_sched_init = coldfire_pit_init;
59 mach_tick = coldfire_pit_tick;
60 mach_gettimeoffset = coldfire_pit_offset;
61 mach_trap_init = coldfire_trap_init;
62 mach_reset = coldfire_reset;
63}
64
65/***************************************************************************/
diff --git a/arch/m68knommu/platform/5307/Makefile b/arch/m68knommu/platform/5307/Makefile
index 6fe5a2b8fb08..8d1619dc1ea6 100644
--- a/arch/m68knommu/platform/5307/Makefile
+++ b/arch/m68knommu/platform/5307/Makefile
@@ -19,6 +19,7 @@ endif
19obj-$(CONFIG_COLDFIRE) += entry.o vectors.o ints.o 19obj-$(CONFIG_COLDFIRE) += entry.o vectors.o ints.o
20obj-$(CONFIG_M5206) += timers.o 20obj-$(CONFIG_M5206) += timers.o
21obj-$(CONFIG_M5206e) += timers.o 21obj-$(CONFIG_M5206e) += timers.o
22obj-$(CONFIG_M520x) += pit.o
22obj-$(CONFIG_M523x) += pit.o 23obj-$(CONFIG_M523x) += pit.o
23obj-$(CONFIG_M5249) += timers.o 24obj-$(CONFIG_M5249) += timers.o
24obj-$(CONFIG_M527x) += pit.o 25obj-$(CONFIG_M527x) += pit.o
diff --git a/arch/m68knommu/platform/5307/head.S b/arch/m68knommu/platform/5307/head.S
index 7f4ba837901f..c30c462b99b1 100644
--- a/arch/m68knommu/platform/5307/head.S
+++ b/arch/m68knommu/platform/5307/head.S
@@ -113,6 +113,9 @@
113#define MEM_BASE 0x02000000 113#define MEM_BASE 0x02000000
114#define VBR_BASE 0x20000000 /* vectors in SRAM */ 114#define VBR_BASE 0x20000000 /* vectors in SRAM */
115#endif 115#endif
116#if defined(CONFIG_M5208EVB)
117#define MEM_BASE 0x40000000
118#endif
116 119
117#ifndef MEM_BASE 120#ifndef MEM_BASE
118#define MEM_BASE 0x00000000 /* memory base at address 0 */ 121#define MEM_BASE 0x00000000 /* memory base at address 0 */
diff --git a/arch/m68knommu/platform/5307/ints.c b/arch/m68knommu/platform/5307/ints.c
index 0117754d44f3..a134fb2f0566 100644
--- a/arch/m68knommu/platform/5307/ints.c
+++ b/arch/m68knommu/platform/5307/ints.c
@@ -26,6 +26,7 @@
26 26
27#include <asm/system.h> 27#include <asm/system.h>
28#include <asm/irq.h> 28#include <asm/irq.h>
29#include <asm/irqnode.h>
29#include <asm/traps.h> 30#include <asm/traps.h>
30#include <asm/page.h> 31#include <asm/page.h>
31#include <asm/machdep.h> 32#include <asm/machdep.h>
diff --git a/arch/m68knommu/platform/5307/pit.c b/arch/m68knommu/platform/5307/pit.c
index a9b2c2e7e280..323f2677e49d 100644
--- a/arch/m68knommu/platform/5307/pit.c
+++ b/arch/m68knommu/platform/5307/pit.c
@@ -3,7 +3,7 @@
3/* 3/*
4 * pit.c -- Motorola ColdFire PIT timer. Currently this type of 4 * pit.c -- Motorola ColdFire PIT timer. Currently this type of
5 * hardware timer only exists in the Motorola ColdFire 5 * hardware timer only exists in the Motorola ColdFire
6 * 5270/5271 and 5282 CPUs. 6 * 5270/5271, 5282 and other CPUs.
7 * 7 *
8 * Copyright (C) 1999-2004, Greg Ungerer (gerg@snapgear.com) 8 * Copyright (C) 1999-2004, Greg Ungerer (gerg@snapgear.com)
9 * Copyright (C) 2001-2004, SnapGear Inc. (www.snapgear.com) 9 * Copyright (C) 2001-2004, SnapGear Inc. (www.snapgear.com)
@@ -47,10 +47,10 @@ void coldfire_pit_init(irqreturn_t (*handler)(int, void *, struct pt_regs *))
47 47
48 icrp = (volatile unsigned char *) (MCF_IPSBAR + MCFICM_INTC0 + 48 icrp = (volatile unsigned char *) (MCF_IPSBAR + MCFICM_INTC0 +
49 MCFINTC_ICR0 + MCFINT_PIT1); 49 MCFINTC_ICR0 + MCFINT_PIT1);
50 *icrp = 0x2b; /* PIT1 with level 5, priority 3 */ 50 *icrp = ICR_INTRCONF;
51 51
52 imrp = (volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRH); 52 imrp = (volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFPIT_IMR);
53 *imrp &= ~(1 << (MCFINT_PIT1 - 32)); 53 *imrp &= ~MCFPIT_IMR_IBIT;
54 54
55 /* Set up PIT timer 1 as poll clock */ 55 /* Set up PIT timer 1 as poll clock */
56 tp = (volatile struct mcfpit *) (MCF_IPSBAR + MCFPIT_BASE1); 56 tp = (volatile struct mcfpit *) (MCF_IPSBAR + MCFPIT_BASE1);
@@ -70,7 +70,7 @@ unsigned long coldfire_pit_offset(void)
70 unsigned long pmr, pcntr, offset; 70 unsigned long pmr, pcntr, offset;
71 71
72 tp = (volatile struct mcfpit *) (MCF_IPSBAR + MCFPIT_BASE1); 72 tp = (volatile struct mcfpit *) (MCF_IPSBAR + MCFPIT_BASE1);
73 ipr = (volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IPRH); 73 ipr = (volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFPIT_IMR);
74 74
75 pmr = *(&tp->pmr); 75 pmr = *(&tp->pmr);
76 pcntr = *(&tp->pcntr); 76 pcntr = *(&tp->pcntr);
@@ -80,7 +80,7 @@ unsigned long coldfire_pit_offset(void)
80 * timer interupt is pending, then add on a ticks worth of time. 80 * timer interupt is pending, then add on a ticks worth of time.
81 */ 81 */
82 offset = ((pmr - pcntr) * (1000000 / HZ)) / pmr; 82 offset = ((pmr - pcntr) * (1000000 / HZ)) / pmr;
83 if ((offset < (1000000 / HZ / 2)) && (*ipr & (1 << (MCFINT_PIT1 - 32)))) 83 if ((offset < (1000000 / HZ / 2)) && (*ipr & MCFPIT_IMR_IBIT))
84 offset += 1000000 / HZ; 84 offset += 1000000 / HZ;
85 return offset; 85 return offset;
86} 86}
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 0097a0d53b3b..e380a8322a94 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -958,7 +958,7 @@ config SOC_PNX8550
958 bool 958 bool
959 select DMA_NONCOHERENT 959 select DMA_NONCOHERENT
960 select HW_HAS_PCI 960 select HW_HAS_PCI
961 select SYS_HAS_CPU_R4X00 961 select SYS_HAS_CPU_MIPS32_R1
962 select SYS_SUPPORTS_32BIT_KERNEL 962 select SYS_SUPPORTS_32BIT_KERNEL
963 963
964config SWAP_IO_SPACE 964config SWAP_IO_SPACE
diff --git a/arch/mips/boot/.gitignore b/arch/mips/boot/.gitignore
new file mode 100644
index 000000000000..ba63401c6e10
--- /dev/null
+++ b/arch/mips/boot/.gitignore
@@ -0,0 +1,4 @@
1mkboot
2elf2ecoff
3zImage
4zImage.tmp
diff --git a/arch/mips/configs/pnx8550-jbs_defconfig b/arch/mips/configs/pnx8550-jbs_defconfig
index 95f84d711912..555837e4c06f 100644
--- a/arch/mips/configs/pnx8550-jbs_defconfig
+++ b/arch/mips/configs/pnx8550-jbs_defconfig
@@ -129,7 +129,7 @@ CONFIG_MIPS_L1_CACHE_SHIFT=5
129# 129#
130# CPU selection 130# CPU selection
131# 131#
132# CONFIG_CPU_MIPS32_R1 is not set 132CONFIG_CPU_MIPS32_R1=y
133# CONFIG_CPU_MIPS32_R2 is not set 133# CONFIG_CPU_MIPS32_R2 is not set
134# CONFIG_CPU_MIPS64_R1 is not set 134# CONFIG_CPU_MIPS64_R1 is not set
135# CONFIG_CPU_MIPS64_R2 is not set 135# CONFIG_CPU_MIPS64_R2 is not set
@@ -137,7 +137,7 @@ CONFIG_MIPS_L1_CACHE_SHIFT=5
137# CONFIG_CPU_TX39XX is not set 137# CONFIG_CPU_TX39XX is not set
138# CONFIG_CPU_VR41XX is not set 138# CONFIG_CPU_VR41XX is not set
139# CONFIG_CPU_R4300 is not set 139# CONFIG_CPU_R4300 is not set
140CONFIG_CPU_R4X00=y 140# CONFIG_CPU_R4X00 is not set
141# CONFIG_CPU_TX49XX is not set 141# CONFIG_CPU_TX49XX is not set
142# CONFIG_CPU_R5000 is not set 142# CONFIG_CPU_R5000 is not set
143# CONFIG_CPU_R5432 is not set 143# CONFIG_CPU_R5432 is not set
@@ -148,10 +148,11 @@ CONFIG_CPU_R4X00=y
148# CONFIG_CPU_RM7000 is not set 148# CONFIG_CPU_RM7000 is not set
149# CONFIG_CPU_RM9000 is not set 149# CONFIG_CPU_RM9000 is not set
150# CONFIG_CPU_SB1 is not set 150# CONFIG_CPU_SB1 is not set
151CONFIG_SYS_HAS_CPU_R4X00=y 151CONFIG_SYS_HAS_CPU_MIPS32_R1=y
152CONFIG_CPU_MIPS32=y
153CONFIG_CPU_MIPSR1=y
152CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y 154CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
153CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y 155CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
154CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
155 156
156# 157#
157# Kernel type 158# Kernel type
@@ -162,11 +163,11 @@ CONFIG_PAGE_SIZE_4KB=y
162# CONFIG_PAGE_SIZE_8KB is not set 163# CONFIG_PAGE_SIZE_8KB is not set
163# CONFIG_PAGE_SIZE_16KB is not set 164# CONFIG_PAGE_SIZE_16KB is not set
164# CONFIG_PAGE_SIZE_64KB is not set 165# CONFIG_PAGE_SIZE_64KB is not set
166CONFIG_CPU_HAS_PREFETCH=y
165# CONFIG_MIPS_MT is not set 167# CONFIG_MIPS_MT is not set
166# CONFIG_64BIT_PHYS_ADDR is not set 168# CONFIG_64BIT_PHYS_ADDR is not set
167# CONFIG_CPU_ADVANCED is not set 169# CONFIG_CPU_ADVANCED is not set
168CONFIG_CPU_HAS_LLSC=y 170CONFIG_CPU_HAS_LLSC=y
169CONFIG_CPU_HAS_LLDSCD=y
170CONFIG_CPU_HAS_SYNC=y 171CONFIG_CPU_HAS_SYNC=y
171CONFIG_GENERIC_HARDIRQS=y 172CONFIG_GENERIC_HARDIRQS=y
172CONFIG_GENERIC_IRQ_PROBE=y 173CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/pnx8550-v2pci_defconfig b/arch/mips/configs/pnx8550-v2pci_defconfig
index deb24c29ac0a..05e65206a7b4 100644
--- a/arch/mips/configs/pnx8550-v2pci_defconfig
+++ b/arch/mips/configs/pnx8550-v2pci_defconfig
@@ -128,7 +128,7 @@ CONFIG_MIPS_L1_CACHE_SHIFT=5
128# 128#
129# CPU selection 129# CPU selection
130# 130#
131# CONFIG_CPU_MIPS32_R1 is not set 131CONFIG_CPU_MIPS32_R1=y
132# CONFIG_CPU_MIPS32_R2 is not set 132# CONFIG_CPU_MIPS32_R2 is not set
133# CONFIG_CPU_MIPS64_R1 is not set 133# CONFIG_CPU_MIPS64_R1 is not set
134# CONFIG_CPU_MIPS64_R2 is not set 134# CONFIG_CPU_MIPS64_R2 is not set
@@ -136,7 +136,7 @@ CONFIG_MIPS_L1_CACHE_SHIFT=5
136# CONFIG_CPU_TX39XX is not set 136# CONFIG_CPU_TX39XX is not set
137# CONFIG_CPU_VR41XX is not set 137# CONFIG_CPU_VR41XX is not set
138# CONFIG_CPU_R4300 is not set 138# CONFIG_CPU_R4300 is not set
139CONFIG_CPU_R4X00=y 139# CONFIG_CPU_R4X00 is not set
140# CONFIG_CPU_TX49XX is not set 140# CONFIG_CPU_TX49XX is not set
141# CONFIG_CPU_R5000 is not set 141# CONFIG_CPU_R5000 is not set
142# CONFIG_CPU_R5432 is not set 142# CONFIG_CPU_R5432 is not set
@@ -147,10 +147,11 @@ CONFIG_CPU_R4X00=y
147# CONFIG_CPU_RM7000 is not set 147# CONFIG_CPU_RM7000 is not set
148# CONFIG_CPU_RM9000 is not set 148# CONFIG_CPU_RM9000 is not set
149# CONFIG_CPU_SB1 is not set 149# CONFIG_CPU_SB1 is not set
150CONFIG_SYS_HAS_CPU_R4X00=y 150CONFIG_SYS_HAS_CPU_MIPS32_R1=y
151CONFIG_CPU_MIPS32=y
152CONFIG_CPU_MIPSR1=y
151CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y 153CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
152CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y 154CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
153CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
154 155
155# 156#
156# Kernel type 157# Kernel type
@@ -161,6 +162,7 @@ CONFIG_PAGE_SIZE_4KB=y
161# CONFIG_PAGE_SIZE_8KB is not set 162# CONFIG_PAGE_SIZE_8KB is not set
162# CONFIG_PAGE_SIZE_16KB is not set 163# CONFIG_PAGE_SIZE_16KB is not set
163# CONFIG_PAGE_SIZE_64KB is not set 164# CONFIG_PAGE_SIZE_64KB is not set
165CONFIG_CPU_HAS_PREFETCH=y
164# CONFIG_MIPS_MT is not set 166# CONFIG_MIPS_MT is not set
165# CONFIG_64BIT_PHYS_ADDR is not set 167# CONFIG_64BIT_PHYS_ADDR is not set
166CONFIG_CPU_ADVANCED=y 168CONFIG_CPU_ADVANCED=y
diff --git a/arch/mips/ddb5xxx/common/rtc_ds1386.c b/arch/mips/ddb5xxx/common/rtc_ds1386.c
index f5b11508ff2f..995896ac0e39 100644
--- a/arch/mips/ddb5xxx/common/rtc_ds1386.c
+++ b/arch/mips/ddb5xxx/common/rtc_ds1386.c
@@ -41,7 +41,9 @@ rtc_ds1386_get_time(void)
41 u8 byte; 41 u8 byte;
42 u8 temp; 42 u8 temp;
43 unsigned int year, month, day, hour, minute, second; 43 unsigned int year, month, day, hour, minute, second;
44 unsigned long flags;
44 45
46 spin_lock_irqsave(&rtc_lock, flags);
45 /* let us freeze external registers */ 47 /* let us freeze external registers */
46 byte = READ_RTC(0xB); 48 byte = READ_RTC(0xB);
47 byte &= 0x3f; 49 byte &= 0x3f;
@@ -60,6 +62,7 @@ rtc_ds1386_get_time(void)
60 /* enable time transfer */ 62 /* enable time transfer */
61 byte |= 0x80; 63 byte |= 0x80;
62 WRITE_RTC(0xB, byte); 64 WRITE_RTC(0xB, byte);
65 spin_unlock_irqrestore(&rtc_lock, flags);
63 66
64 /* calc hour */ 67 /* calc hour */
65 if (temp & 0x40) { 68 if (temp & 0x40) {
@@ -81,7 +84,9 @@ rtc_ds1386_set_time(unsigned long t)
81 u8 byte; 84 u8 byte;
82 u8 temp; 85 u8 temp;
83 u8 year, month, day, hour, minute, second; 86 u8 year, month, day, hour, minute, second;
87 unsigned long flags;
84 88
89 spin_lock_irqsave(&rtc_lock, flags);
85 /* let us freeze external registers */ 90 /* let us freeze external registers */
86 byte = READ_RTC(0xB); 91 byte = READ_RTC(0xB);
87 byte &= 0x3f; 92 byte &= 0x3f;
@@ -133,6 +138,7 @@ rtc_ds1386_set_time(unsigned long t)
133 if (second != READ_RTC(0x1)) { 138 if (second != READ_RTC(0x1)) {
134 WRITE_RTC(0x1, second); 139 WRITE_RTC(0x1, second);
135 } 140 }
141 spin_unlock_irqrestore(&rtc_lock, flags);
136 142
137 return 0; 143 return 0;
138} 144}
diff --git a/arch/mips/dec/time.c b/arch/mips/dec/time.c
index dc7091caa7aa..174822344131 100644
--- a/arch/mips/dec/time.c
+++ b/arch/mips/dec/time.c
@@ -37,10 +37,25 @@
37#include <asm/dec/machtype.h> 37#include <asm/dec/machtype.h>
38 38
39 39
40/*
41 * Returns true if a clock update is in progress
42 */
43static inline unsigned char dec_rtc_is_updating(void)
44{
45 unsigned char uip;
46 unsigned long flags;
47
48 spin_lock_irqsave(&rtc_lock, flags);
49 uip = (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP);
50 spin_unlock_irqrestore(&rtc_lock, flags);
51 return uip;
52}
53
40static unsigned long dec_rtc_get_time(void) 54static unsigned long dec_rtc_get_time(void)
41{ 55{
42 unsigned int year, mon, day, hour, min, sec, real_year; 56 unsigned int year, mon, day, hour, min, sec, real_year;
43 int i; 57 int i;
58 unsigned long flags;
44 59
45 /* The Linux interpretation of the DS1287 clock register contents: 60 /* The Linux interpretation of the DS1287 clock register contents:
46 * When the Update-In-Progress (UIP) flag goes from 1 to 0, the 61 * When the Update-In-Progress (UIP) flag goes from 1 to 0, the
@@ -49,11 +64,12 @@ static unsigned long dec_rtc_get_time(void)
49 */ 64 */
50 /* read RTC exactly on falling edge of update flag */ 65 /* read RTC exactly on falling edge of update flag */
51 for (i = 0; i < 1000000; i++) /* may take up to 1 second... */ 66 for (i = 0; i < 1000000; i++) /* may take up to 1 second... */
52 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) 67 if (dec_rtc_is_updating())
53 break; 68 break;
54 for (i = 0; i < 1000000; i++) /* must try at least 2.228 ms */ 69 for (i = 0; i < 1000000; i++) /* must try at least 2.228 ms */
55 if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)) 70 if (!dec_rtc_is_updating())
56 break; 71 break;
72 spin_lock_irqsave(&rtc_lock, flags);
57 /* Isn't this overkill? UIP above should guarantee consistency */ 73 /* Isn't this overkill? UIP above should guarantee consistency */
58 do { 74 do {
59 sec = CMOS_READ(RTC_SECONDS); 75 sec = CMOS_READ(RTC_SECONDS);
@@ -77,6 +93,7 @@ static unsigned long dec_rtc_get_time(void)
77 * of unused BBU RAM locations. 93 * of unused BBU RAM locations.
78 */ 94 */
79 real_year = CMOS_READ(RTC_DEC_YEAR); 95 real_year = CMOS_READ(RTC_DEC_YEAR);
96 spin_unlock_irqrestore(&rtc_lock, flags);
80 year += real_year - 72 + 2000; 97 year += real_year - 72 + 2000;
81 98
82 return mktime(year, mon, day, hour, min, sec); 99 return mktime(year, mon, day, hour, min, sec);
@@ -95,6 +112,8 @@ static int dec_rtc_set_mmss(unsigned long nowtime)
95 int real_seconds, real_minutes, cmos_minutes; 112 int real_seconds, real_minutes, cmos_minutes;
96 unsigned char save_control, save_freq_select; 113 unsigned char save_control, save_freq_select;
97 114
115 /* irq are locally disabled here */
116 spin_lock(&rtc_lock);
98 /* tell the clock it's being set */ 117 /* tell the clock it's being set */
99 save_control = CMOS_READ(RTC_CONTROL); 118 save_control = CMOS_READ(RTC_CONTROL);
100 CMOS_WRITE((save_control | RTC_SET), RTC_CONTROL); 119 CMOS_WRITE((save_control | RTC_SET), RTC_CONTROL);
@@ -141,6 +160,7 @@ static int dec_rtc_set_mmss(unsigned long nowtime)
141 */ 160 */
142 CMOS_WRITE(save_control, RTC_CONTROL); 161 CMOS_WRITE(save_control, RTC_CONTROL);
143 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); 162 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
163 spin_unlock(&rtc_lock);
144 164
145 return retval; 165 return retval;
146} 166}
diff --git a/arch/mips/jmr3927/common/rtc_ds1742.c b/arch/mips/jmr3927/common/rtc_ds1742.c
index 1ae4318e1358..8b407d7dc460 100644
--- a/arch/mips/jmr3927/common/rtc_ds1742.c
+++ b/arch/mips/jmr3927/common/rtc_ds1742.c
@@ -57,7 +57,9 @@ rtc_ds1742_get_time(void)
57{ 57{
58 unsigned int year, month, day, hour, minute, second; 58 unsigned int year, month, day, hour, minute, second;
59 unsigned int century; 59 unsigned int century;
60 unsigned long flags;
60 61
62 spin_lock_irqsave(&rtc_lock, flags);
61 CMOS_WRITE(RTC_READ, RTC_CONTROL); 63 CMOS_WRITE(RTC_READ, RTC_CONTROL);
62 second = BCD2BIN(CMOS_READ(RTC_SECONDS) & RTC_SECONDS_MASK); 64 second = BCD2BIN(CMOS_READ(RTC_SECONDS) & RTC_SECONDS_MASK);
63 minute = BCD2BIN(CMOS_READ(RTC_MINUTES)); 65 minute = BCD2BIN(CMOS_READ(RTC_MINUTES));
@@ -67,6 +69,7 @@ rtc_ds1742_get_time(void)
67 year = BCD2BIN(CMOS_READ(RTC_YEAR)); 69 year = BCD2BIN(CMOS_READ(RTC_YEAR));
68 century = BCD2BIN(CMOS_READ(RTC_CENTURY) & RTC_CENTURY_MASK); 70 century = BCD2BIN(CMOS_READ(RTC_CENTURY) & RTC_CENTURY_MASK);
69 CMOS_WRITE(0, RTC_CONTROL); 71 CMOS_WRITE(0, RTC_CONTROL);
72 spin_unlock_irqrestore(&rtc_lock, flags);
70 73
71 year += century * 100; 74 year += century * 100;
72 75
@@ -81,7 +84,9 @@ rtc_ds1742_set_time(unsigned long t)
81 u8 year, month, day, hour, minute, second; 84 u8 year, month, day, hour, minute, second;
82 u8 cmos_year, cmos_month, cmos_day, cmos_hour, cmos_minute, cmos_second; 85 u8 cmos_year, cmos_month, cmos_day, cmos_hour, cmos_minute, cmos_second;
83 int cmos_century; 86 int cmos_century;
87 unsigned long flags;
84 88
89 spin_lock_irqsave(&rtc_lock, flags);
85 CMOS_WRITE(RTC_READ, RTC_CONTROL); 90 CMOS_WRITE(RTC_READ, RTC_CONTROL);
86 cmos_second = (u8)(CMOS_READ(RTC_SECONDS) & RTC_SECONDS_MASK); 91 cmos_second = (u8)(CMOS_READ(RTC_SECONDS) & RTC_SECONDS_MASK);
87 cmos_minute = (u8)CMOS_READ(RTC_MINUTES); 92 cmos_minute = (u8)CMOS_READ(RTC_MINUTES);
@@ -139,6 +144,7 @@ rtc_ds1742_set_time(unsigned long t)
139 144
140 /* RTC_CENTURY and RTC_CONTROL share same address... */ 145 /* RTC_CENTURY and RTC_CONTROL share same address... */
141 CMOS_WRITE(cmos_century, RTC_CONTROL); 146 CMOS_WRITE(cmos_century, RTC_CONTROL);
147 spin_unlock_irqrestore(&rtc_lock, flags);
142 148
143 return 0; 149 return 0;
144} 150}
diff --git a/arch/mips/kernel/irixsig.c b/arch/mips/kernel/irixsig.c
index 908e63684208..dd118c60bcd0 100644
--- a/arch/mips/kernel/irixsig.c
+++ b/arch/mips/kernel/irixsig.c
@@ -502,8 +502,7 @@ asmlinkage int irix_sigpoll_sys(unsigned long __user *set,
502 while(1) { 502 while(1) {
503 long tmp = 0; 503 long tmp = 0;
504 504
505 current->state = TASK_INTERRUPTIBLE; 505 expire = schedule_timeout_interruptible(expire);
506 expire = schedule_timeout(expire);
507 506
508 for (i=0; i<=4; i++) 507 for (i=0; i<=4; i++)
509 tmp |= (current->pending.signal.sig[i] & kset.sig[i]); 508 tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index f1b0f3e1f95b..510da5fda567 100644
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -174,51 +174,10 @@ int ptrace_setfpregs (struct task_struct *child, __u32 __user *data)
174 return 0; 174 return 0;
175} 175}
176 176
177asmlinkage long sys_ptrace(long request, long pid, long addr, long data) 177long arch_ptrace(struct task_struct *child, long request, long addr, long data)
178{ 178{
179 struct task_struct *child;
180 int ret; 179 int ret;
181 180
182#if 0
183 printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
184 (int) request, (int) pid, (unsigned long) addr,
185 (unsigned long) data);
186#endif
187 lock_kernel();
188 ret = -EPERM;
189 if (request == PTRACE_TRACEME) {
190 /* are we already being traced? */
191 if (current->ptrace & PT_PTRACED)
192 goto out;
193 if ((ret = security_ptrace(current->parent, current)))
194 goto out;
195 /* set the ptrace bit in the process flags. */
196 current->ptrace |= PT_PTRACED;
197 ret = 0;
198 goto out;
199 }
200 ret = -ESRCH;
201 read_lock(&tasklist_lock);
202 child = find_task_by_pid(pid);
203 if (child)
204 get_task_struct(child);
205 read_unlock(&tasklist_lock);
206 if (!child)
207 goto out;
208
209 ret = -EPERM;
210 if (pid == 1) /* you may not mess with init */
211 goto out_tsk;
212
213 if (request == PTRACE_ATTACH) {
214 ret = ptrace_attach(child);
215 goto out_tsk;
216 }
217
218 ret = ptrace_check_attach(child, request == PTRACE_KILL);
219 if (ret < 0)
220 goto out_tsk;
221
222 switch (request) { 181 switch (request) {
223 /* when I and D space are separate, these will need to be fixed. */ 182 /* when I and D space are separate, these will need to be fixed. */
224 case PTRACE_PEEKTEXT: /* read word at location addr. */ 183 case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -319,7 +278,7 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
319 if (!cpu_has_dsp) { 278 if (!cpu_has_dsp) {
320 tmp = 0; 279 tmp = 0;
321 ret = -EIO; 280 ret = -EIO;
322 goto out_tsk; 281 goto out;
323 } 282 }
324 if (child->thread.dsp.used_dsp) { 283 if (child->thread.dsp.used_dsp) {
325 dregs = __get_dsp_regs(child); 284 dregs = __get_dsp_regs(child);
@@ -333,14 +292,14 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
333 if (!cpu_has_dsp) { 292 if (!cpu_has_dsp) {
334 tmp = 0; 293 tmp = 0;
335 ret = -EIO; 294 ret = -EIO;
336 goto out_tsk; 295 goto out;
337 } 296 }
338 tmp = child->thread.dsp.dspcontrol; 297 tmp = child->thread.dsp.dspcontrol;
339 break; 298 break;
340 default: 299 default:
341 tmp = 0; 300 tmp = 0;
342 ret = -EIO; 301 ret = -EIO;
343 goto out_tsk; 302 goto out;
344 } 303 }
345 ret = put_user(tmp, (unsigned long __user *) data); 304 ret = put_user(tmp, (unsigned long __user *) data);
346 break; 305 break;
@@ -495,11 +454,7 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
495 ret = ptrace_request(child, request, addr, data); 454 ret = ptrace_request(child, request, addr, data);
496 break; 455 break;
497 } 456 }
498 457 out:
499out_tsk:
500 put_task_struct(child);
501out:
502 unlock_kernel();
503 return ret; 458 return ret;
504} 459}
505 460
diff --git a/arch/mips/kernel/rtlx.c b/arch/mips/kernel/rtlx.c
index 8c81f3cb4e2d..1d855112bac2 100644
--- a/arch/mips/kernel/rtlx.c
+++ b/arch/mips/kernel/rtlx.c
@@ -20,42 +20,42 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/fs.h> 21#include <linux/fs.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <asm/uaccess.h>
24#include <linux/slab.h>
25#include <linux/list.h>
26#include <linux/vmalloc.h>
27#include <linux/elf.h>
28#include <linux/seq_file.h>
29#include <linux/syscalls.h>
30#include <linux/moduleloader.h>
31#include <linux/interrupt.h>
32#include <linux/poll.h> 23#include <linux/poll.h>
33#include <linux/sched.h> 24#include <linux/sched.h>
34#include <linux/wait.h> 25#include <linux/wait.h>
35#include <asm/mipsmtregs.h> 26#include <asm/mipsmtregs.h>
36#include <asm/cacheflush.h> 27#include <asm/bitops.h>
37#include <asm/atomic.h>
38#include <asm/cpu.h> 28#include <asm/cpu.h>
39#include <asm/processor.h> 29#include <asm/processor.h>
40#include <asm/system.h>
41#include <asm/rtlx.h> 30#include <asm/rtlx.h>
31#include <asm/uaccess.h>
42 32
43#define RTLX_MAJOR 64
44#define RTLX_TARG_VPE 1 33#define RTLX_TARG_VPE 1
45 34
46struct rtlx_info *rtlx; 35static struct rtlx_info *rtlx;
47static int major; 36static int major;
48static char module_name[] = "rtlx"; 37static char module_name[] = "rtlx";
49static inline int spacefree(int read, int write, int size); 38static struct irqaction irq;
39static int irq_num;
40
41static inline int spacefree(int read, int write, int size)
42{
43 if (read == write) {
44 /*
45 * never fill the buffer completely, so indexes are always
46 * equal if empty and only empty, or !equal if data available
47 */
48 return size - 1;
49 }
50
51 return ((read + size - write) % size) - 1;
52}
50 53
51static struct chan_waitqueues { 54static struct chan_waitqueues {
52 wait_queue_head_t rt_queue; 55 wait_queue_head_t rt_queue;
53 wait_queue_head_t lx_queue; 56 wait_queue_head_t lx_queue;
54} channel_wqs[RTLX_CHANNELS]; 57} channel_wqs[RTLX_CHANNELS];
55 58
56static struct irqaction irq;
57static int irq_num;
58
59extern void *vpe_get_shared(int index); 59extern void *vpe_get_shared(int index);
60 60
61static void rtlx_dispatch(struct pt_regs *regs) 61static void rtlx_dispatch(struct pt_regs *regs)
@@ -63,9 +63,8 @@ static void rtlx_dispatch(struct pt_regs *regs)
63 do_IRQ(MIPSCPU_INT_BASE + MIPS_CPU_RTLX_IRQ, regs); 63 do_IRQ(MIPSCPU_INT_BASE + MIPS_CPU_RTLX_IRQ, regs);
64} 64}
65 65
66irqreturn_t rtlx_interrupt(int irq, void *dev_id, struct pt_regs *regs) 66static irqreturn_t rtlx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
67{ 67{
68 irqreturn_t r = IRQ_HANDLED;
69 int i; 68 int i;
70 69
71 for (i = 0; i < RTLX_CHANNELS; i++) { 70 for (i = 0; i < RTLX_CHANNELS; i++) {
@@ -75,30 +74,7 @@ irqreturn_t rtlx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
75 wake_up_interruptible(&channel_wqs[i].lx_queue); 74 wake_up_interruptible(&channel_wqs[i].lx_queue);
76 } 75 }
77 76
78 return r; 77 return IRQ_HANDLED;
79}
80
81void dump_rtlx(void)
82{
83 int i;
84
85 printk("id 0x%lx state %d\n", rtlx->id, rtlx->state);
86
87 for (i = 0; i < RTLX_CHANNELS; i++) {
88 struct rtlx_channel *chan = &rtlx->channel[i];
89
90 printk(" rt_state %d lx_state %d buffer_size %d\n",
91 chan->rt_state, chan->lx_state, chan->buffer_size);
92
93 printk(" rt_read %d rt_write %d\n",
94 chan->rt_read, chan->rt_write);
95
96 printk(" lx_read %d lx_write %d\n",
97 chan->lx_read, chan->lx_write);
98
99 printk(" rt_buffer <%s>\n", chan->rt_buffer);
100 printk(" lx_buffer <%s>\n", chan->lx_buffer);
101 }
102} 78}
103 79
104/* call when we have the address of the shared structure from the SP side. */ 80/* call when we have the address of the shared structure from the SP side. */
@@ -108,7 +84,7 @@ static int rtlx_init(struct rtlx_info *rtlxi)
108 84
109 if (rtlxi->id != RTLX_ID) { 85 if (rtlxi->id != RTLX_ID) {
110 printk(KERN_WARNING "no valid RTLX id at 0x%p\n", rtlxi); 86 printk(KERN_WARNING "no valid RTLX id at 0x%p\n", rtlxi);
111 return (-ENOEXEC); 87 return -ENOEXEC;
112 } 88 }
113 89
114 /* initialise the wait queues */ 90 /* initialise the wait queues */
@@ -120,9 +96,8 @@ static int rtlx_init(struct rtlx_info *rtlxi)
120 /* set up for interrupt handling */ 96 /* set up for interrupt handling */
121 memset(&irq, 0, sizeof(struct irqaction)); 97 memset(&irq, 0, sizeof(struct irqaction));
122 98
123 if (cpu_has_vint) { 99 if (cpu_has_vint)
124 set_vi_handler(MIPS_CPU_RTLX_IRQ, rtlx_dispatch); 100 set_vi_handler(MIPS_CPU_RTLX_IRQ, rtlx_dispatch);
125 }
126 101
127 irq_num = MIPSCPU_INT_BASE + MIPS_CPU_RTLX_IRQ; 102 irq_num = MIPSCPU_INT_BASE + MIPS_CPU_RTLX_IRQ;
128 irq.handler = rtlx_interrupt; 103 irq.handler = rtlx_interrupt;
@@ -132,7 +107,8 @@ static int rtlx_init(struct rtlx_info *rtlxi)
132 setup_irq(irq_num, &irq); 107 setup_irq(irq_num, &irq);
133 108
134 rtlx = rtlxi; 109 rtlx = rtlxi;
135 return (0); 110
111 return 0;
136} 112}
137 113
138/* only allow one open process at a time to open each channel */ 114/* only allow one open process at a time to open each channel */
@@ -147,36 +123,36 @@ static int rtlx_open(struct inode *inode, struct file *filp)
147 if (rtlx == NULL) { 123 if (rtlx == NULL) {
148 struct rtlx_info **p; 124 struct rtlx_info **p;
149 if( (p = vpe_get_shared(RTLX_TARG_VPE)) == NULL) { 125 if( (p = vpe_get_shared(RTLX_TARG_VPE)) == NULL) {
150 printk(" vpe_get_shared is NULL. Has an SP program been loaded?\n"); 126 printk(KERN_ERR "vpe_get_shared is NULL. "
151 return (-EFAULT); 127 "Has an SP program been loaded?\n");
128 return -EFAULT;
152 } 129 }
153 130
154 if (*p == NULL) { 131 if (*p == NULL) {
155 printk(" vpe_shared %p %p\n", p, *p); 132 printk(KERN_ERR "vpe_shared %p %p\n", p, *p);
156 return (-EFAULT); 133 return -EFAULT;
157 } 134 }
158 135
159 if ((ret = rtlx_init(*p)) < 0) 136 if ((ret = rtlx_init(*p)) < 0)
160 return (ret); 137 return ret;
161 } 138 }
162 139
163 chan = &rtlx->channel[minor]; 140 chan = &rtlx->channel[minor];
164 141
165 /* already open? */ 142 if (test_and_set_bit(RTLX_STATE_OPENED, &chan->lx_state))
166 if (chan->lx_state == RTLX_STATE_OPENED) 143 return -EBUSY;
167 return (-EBUSY);
168 144
169 chan->lx_state = RTLX_STATE_OPENED; 145 return 0;
170 return (0);
171} 146}
172 147
173static int rtlx_release(struct inode *inode, struct file *filp) 148static int rtlx_release(struct inode *inode, struct file *filp)
174{ 149{
175 int minor; 150 int minor = MINOR(inode->i_rdev);
176 151
177 minor = MINOR(inode->i_rdev); 152 clear_bit(RTLX_STATE_OPENED, &rtlx->channel[minor].lx_state);
178 rtlx->channel[minor].lx_state = RTLX_STATE_UNUSED; 153 smp_mb__after_clear_bit();
179 return (0); 154
155 return 0;
180} 156}
181 157
182static unsigned int rtlx_poll(struct file *file, poll_table * wait) 158static unsigned int rtlx_poll(struct file *file, poll_table * wait)
@@ -199,12 +175,13 @@ static unsigned int rtlx_poll(struct file *file, poll_table * wait)
199 if (spacefree(chan->rt_read, chan->rt_write, chan->buffer_size)) 175 if (spacefree(chan->rt_read, chan->rt_write, chan->buffer_size))
200 mask |= POLLOUT | POLLWRNORM; 176 mask |= POLLOUT | POLLWRNORM;
201 177
202 return (mask); 178 return mask;
203} 179}
204 180
205static ssize_t rtlx_read(struct file *file, char __user * buffer, size_t count, 181static ssize_t rtlx_read(struct file *file, char __user * buffer, size_t count,
206 loff_t * ppos) 182 loff_t * ppos)
207{ 183{
184 unsigned long failed;
208 size_t fl = 0L; 185 size_t fl = 0L;
209 int minor; 186 int minor;
210 struct rtlx_channel *lx; 187 struct rtlx_channel *lx;
@@ -216,7 +193,7 @@ static ssize_t rtlx_read(struct file *file, char __user * buffer, size_t count,
216 /* data available? */ 193 /* data available? */
217 if (lx->lx_write == lx->lx_read) { 194 if (lx->lx_write == lx->lx_read) {
218 if (file->f_flags & O_NONBLOCK) 195 if (file->f_flags & O_NONBLOCK)
219 return (0); // -EAGAIN makes cat whinge 196 return 0; /* -EAGAIN makes cat whinge */
220 197
221 /* go to sleep */ 198 /* go to sleep */
222 add_wait_queue(&channel_wqs[minor].lx_queue, &wait); 199 add_wait_queue(&channel_wqs[minor].lx_queue, &wait);
@@ -232,39 +209,39 @@ static ssize_t rtlx_read(struct file *file, char __user * buffer, size_t count,
232 } 209 }
233 210
234 /* find out how much in total */ 211 /* find out how much in total */
235 count = min( count, 212 count = min(count,
236 (size_t)(lx->lx_write + lx->buffer_size - lx->lx_read) % lx->buffer_size); 213 (size_t)(lx->lx_write + lx->buffer_size - lx->lx_read) % lx->buffer_size);
237 214
238 /* then how much from the read pointer onwards */ 215 /* then how much from the read pointer onwards */
239 fl = min( count, (size_t)lx->buffer_size - lx->lx_read); 216 fl = min(count, (size_t)lx->buffer_size - lx->lx_read);
240 217
241 copy_to_user (buffer, &lx->lx_buffer[lx->lx_read], fl); 218 failed = copy_to_user (buffer, &lx->lx_buffer[lx->lx_read], fl);
219 if (failed) {
220 count = fl - failed;
221 goto out;
222 }
242 223
243 /* and if there is anything left at the beginning of the buffer */ 224 /* and if there is anything left at the beginning of the buffer */
244 if ( count - fl ) 225 if (count - fl) {
245 copy_to_user (buffer + fl, lx->lx_buffer, count - fl); 226 failed = copy_to_user (buffer + fl, lx->lx_buffer, count - fl);
227 if (failed) {
228 count -= failed;
229 goto out;
230 }
231 }
246 232
233out:
247 /* update the index */ 234 /* update the index */
248 lx->lx_read += count; 235 lx->lx_read += count;
249 lx->lx_read %= lx->buffer_size; 236 lx->lx_read %= lx->buffer_size;
250 237
251 return (count); 238 return count;
252}
253
254static inline int spacefree(int read, int write, int size)
255{
256 if (read == write) {
257 /* never fill the buffer completely, so indexes are always equal if empty
258 and only empty, or !equal if data available */
259 return (size - 1);
260 }
261
262 return ((read + size - write) % size) - 1;
263} 239}
264 240
265static ssize_t rtlx_write(struct file *file, const char __user * buffer, 241static ssize_t rtlx_write(struct file *file, const char __user * buffer,
266 size_t count, loff_t * ppos) 242 size_t count, loff_t * ppos)
267{ 243{
244 unsigned long failed;
268 int minor; 245 int minor;
269 struct rtlx_channel *rt; 246 struct rtlx_channel *rt;
270 size_t fl; 247 size_t fl;
@@ -277,7 +254,7 @@ static ssize_t rtlx_write(struct file *file, const char __user * buffer,
277 if (!spacefree(rt->rt_read, rt->rt_write, rt->buffer_size)) { 254 if (!spacefree(rt->rt_read, rt->rt_write, rt->buffer_size)) {
278 255
279 if (file->f_flags & O_NONBLOCK) 256 if (file->f_flags & O_NONBLOCK)
280 return (-EAGAIN); 257 return -EAGAIN;
281 258
282 add_wait_queue(&channel_wqs[minor].rt_queue, &wait); 259 add_wait_queue(&channel_wqs[minor].rt_queue, &wait);
283 set_current_state(TASK_INTERRUPTIBLE); 260 set_current_state(TASK_INTERRUPTIBLE);
@@ -290,52 +267,64 @@ static ssize_t rtlx_write(struct file *file, const char __user * buffer,
290 } 267 }
291 268
292 /* total number of bytes to copy */ 269 /* total number of bytes to copy */
293 count = min( count, (size_t)spacefree(rt->rt_read, rt->rt_write, rt->buffer_size) ); 270 count = min(count, (size_t)spacefree(rt->rt_read, rt->rt_write, rt->buffer_size) );
294 271
295 /* first bit from write pointer to the end of the buffer, or count */ 272 /* first bit from write pointer to the end of the buffer, or count */
296 fl = min(count, (size_t) rt->buffer_size - rt->rt_write); 273 fl = min(count, (size_t) rt->buffer_size - rt->rt_write);
297 274
298 copy_from_user(&rt->rt_buffer[rt->rt_write], buffer, fl); 275 failed = copy_from_user(&rt->rt_buffer[rt->rt_write], buffer, fl);
276 if (failed) {
277 count = fl - failed;
278 goto out;
279 }
299 280
300 /* if there's any left copy to the beginning of the buffer */ 281 /* if there's any left copy to the beginning of the buffer */
301 if( count - fl ) 282 if (count - fl) {
302 copy_from_user(rt->rt_buffer, buffer + fl, count - fl); 283 failed = copy_from_user(rt->rt_buffer, buffer + fl, count - fl);
284 if (failed) {
285 count -= failed;
286 goto out;
287 }
288 }
303 289
290out:
304 rt->rt_write += count; 291 rt->rt_write += count;
305 rt->rt_write %= rt->buffer_size; 292 rt->rt_write %= rt->buffer_size;
306 293
307 return(count); 294 return count;
308} 295}
309 296
310static struct file_operations rtlx_fops = { 297static struct file_operations rtlx_fops = {
311 .owner = THIS_MODULE, 298 .owner = THIS_MODULE,
312 .open = rtlx_open, 299 .open = rtlx_open,
313 .release = rtlx_release, 300 .release = rtlx_release,
314 .write = rtlx_write, 301 .write = rtlx_write,
315 .read = rtlx_read, 302 .read = rtlx_read,
316 .poll = rtlx_poll 303 .poll = rtlx_poll
317}; 304};
318 305
319static int rtlx_module_init(void) 306static char register_chrdev_failed[] __initdata =
307 KERN_ERR "rtlx_module_init: unable to register device\n";
308
309static int __init rtlx_module_init(void)
320{ 310{
321 if ((major = register_chrdev(RTLX_MAJOR, module_name, &rtlx_fops)) < 0) { 311 major = register_chrdev(0, module_name, &rtlx_fops);
322 printk("rtlx_module_init: unable to register device\n"); 312 if (major < 0) {
323 return (-EBUSY); 313 printk(register_chrdev_failed);
314 return major;
324 } 315 }
325 316
326 if (major == 0) 317 return 0;
327 major = RTLX_MAJOR;
328
329 return (0);
330} 318}
331 319
332static void rtlx_module_exit(void) 320static void __exit rtlx_module_exit(void)
333{ 321{
334 unregister_chrdev(major, module_name); 322 unregister_chrdev(major, module_name);
335} 323}
336 324
337module_init(rtlx_module_init); 325module_init(rtlx_module_init);
338module_exit(rtlx_module_exit); 326module_exit(rtlx_module_exit);
327
339MODULE_DESCRIPTION("MIPS RTLX"); 328MODULE_DESCRIPTION("MIPS RTLX");
340MODULE_AUTHOR("Elizabeth Clarke, MIPS Technologies, Inc"); 329MODULE_AUTHOR("Elizabeth Clarke, MIPS Technologies, Inc.");
341MODULE_LICENSE("GPL"); 330MODULE_LICENSE("GPL");
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 9202a17db8f7..05e09eedabff 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -384,9 +384,6 @@ give_sigsegv:
384 return 0; 384 return 0;
385} 385}
386 386
387extern void setup_rt_frame_n32(struct k_sigaction * ka,
388 struct pt_regs *regs, int signr, sigset_t *set, siginfo_t *info);
389
390static inline int handle_signal(unsigned long sig, siginfo_t *info, 387static inline int handle_signal(unsigned long sig, siginfo_t *info,
391 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs) 388 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs)
392{ 389{
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index dbe821303125..e315d3f6aa6e 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -647,8 +647,8 @@ static inline void *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
647 return (void *)((sp - frame_size) & ALMASK); 647 return (void *)((sp - frame_size) & ALMASK);
648} 648}
649 649
650void setup_frame_32(struct k_sigaction * ka, struct pt_regs *regs, 650int setup_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
651 int signr, sigset_t *set) 651 int signr, sigset_t *set)
652{ 652{
653 struct sigframe *frame; 653 struct sigframe *frame;
654 int err = 0; 654 int err = 0;
@@ -694,13 +694,15 @@ void setup_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
694 current->comm, current->pid, 694 current->comm, current->pid,
695 frame, regs->cp0_epc, frame->sf_code); 695 frame, regs->cp0_epc, frame->sf_code);
696#endif 696#endif
697 return; 697 return 1;
698 698
699give_sigsegv: 699give_sigsegv:
700 force_sigsegv(signr, current); 700 force_sigsegv(signr, current);
701 return 0;
701} 702}
702 703
703void setup_rt_frame_32(struct k_sigaction * ka, struct pt_regs *regs, int signr, sigset_t *set, siginfo_t *info) 704int setup_rt_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
705 int signr, sigset_t *set, siginfo_t *info)
704{ 706{
705 struct rt_sigframe32 *frame; 707 struct rt_sigframe32 *frame;
706 int err = 0; 708 int err = 0;
@@ -763,10 +765,11 @@ void setup_rt_frame_32(struct k_sigaction * ka, struct pt_regs *regs, int signr,
763 current->comm, current->pid, 765 current->comm, current->pid,
764 frame, regs->cp0_epc, frame->rs_code); 766 frame, regs->cp0_epc, frame->rs_code);
765#endif 767#endif
766 return; 768 return 1;
767 769
768give_sigsegv: 770give_sigsegv:
769 force_sigsegv(signr, current); 771 force_sigsegv(signr, current);
772 return 0;
770} 773}
771 774
772static inline int handle_signal(unsigned long sig, siginfo_t *info, 775static inline int handle_signal(unsigned long sig, siginfo_t *info,
diff --git a/arch/mips/kernel/vpe.c b/arch/mips/kernel/vpe.c
index 97fefcc9dbe7..06be405be399 100644
--- a/arch/mips/kernel/vpe.c
+++ b/arch/mips/kernel/vpe.c
@@ -58,10 +58,6 @@
58 58
59typedef void *vpe_handle; 59typedef void *vpe_handle;
60 60
61// defined here because the kernel module loader doesn't have
62// anything to do with it.
63#define SHN_MIPS_SCOMMON 0xff03
64
65#ifndef ARCH_SHF_SMALL 61#ifndef ARCH_SHF_SMALL
66#define ARCH_SHF_SMALL 0 62#define ARCH_SHF_SMALL 0
67#endif 63#endif
@@ -69,11 +65,8 @@ typedef void *vpe_handle;
69/* If this is set, the section belongs in the init part of the module */ 65/* If this is set, the section belongs in the init part of the module */
70#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) 66#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
71 67
72// temp number,
73#define VPE_MAJOR 63
74
75static char module_name[] = "vpe"; 68static char module_name[] = "vpe";
76static int major = 0; 69static int major;
77 70
78/* grab the likely amount of memory we will need. */ 71/* grab the likely amount of memory we will need. */
79#ifdef CONFIG_MIPS_VPE_LOADER_TOM 72#ifdef CONFIG_MIPS_VPE_LOADER_TOM
@@ -98,22 +91,7 @@ enum tc_state {
98 TC_STATE_DYNAMIC 91 TC_STATE_DYNAMIC
99}; 92};
100 93
101struct vpe; 94struct vpe {
102typedef struct tc {
103 enum tc_state state;
104 int index;
105
106 /* parent VPE */
107 struct vpe *pvpe;
108
109 /* The list of TC's with this VPE */
110 struct list_head tc;
111
112 /* The global list of tc's */
113 struct list_head list;
114} tc_t;
115
116typedef struct vpe {
117 enum vpe_state state; 95 enum vpe_state state;
118 96
119 /* (device) minor associated with this vpe */ 97 /* (device) minor associated with this vpe */
@@ -135,7 +113,21 @@ typedef struct vpe {
135 113
136 /* shared symbol address */ 114 /* shared symbol address */
137 void *shared_ptr; 115 void *shared_ptr;
138} vpe_t; 116};
117
118struct tc {
119 enum tc_state state;
120 int index;
121
122 /* parent VPE */
123 struct vpe *pvpe;
124
125 /* The list of TC's with this VPE */
126 struct list_head tc;
127
128 /* The global list of tc's */
129 struct list_head list;
130};
139 131
140struct vpecontrol_ { 132struct vpecontrol_ {
141 /* Virtual processing elements */ 133 /* Virtual processing elements */
@@ -146,7 +138,7 @@ struct vpecontrol_ {
146} vpecontrol; 138} vpecontrol;
147 139
148static void release_progmem(void *ptr); 140static void release_progmem(void *ptr);
149static void dump_vpe(vpe_t * v); 141static void dump_vpe(struct vpe * v);
150extern void save_gp_address(unsigned int secbase, unsigned int rel); 142extern void save_gp_address(unsigned int secbase, unsigned int rel);
151 143
152/* get the vpe associated with this minor */ 144/* get the vpe associated with this minor */
@@ -197,13 +189,11 @@ struct vpe *alloc_vpe(int minor)
197{ 189{
198 struct vpe *v; 190 struct vpe *v;
199 191
200 if ((v = kmalloc(sizeof(struct vpe), GFP_KERNEL)) == NULL) { 192 if ((v = kzalloc(sizeof(struct vpe), GFP_KERNEL)) == NULL) {
201 printk(KERN_WARNING "VPE: alloc_vpe no mem\n"); 193 printk(KERN_WARNING "VPE: alloc_vpe no mem\n");
202 return NULL; 194 return NULL;
203 } 195 }
204 196
205 memset(v, 0, sizeof(struct vpe));
206
207 INIT_LIST_HEAD(&v->tc); 197 INIT_LIST_HEAD(&v->tc);
208 list_add_tail(&v->list, &vpecontrol.vpe_list); 198 list_add_tail(&v->list, &vpecontrol.vpe_list);
209 199
@@ -216,13 +206,11 @@ struct tc *alloc_tc(int index)
216{ 206{
217 struct tc *t; 207 struct tc *t;
218 208
219 if ((t = kmalloc(sizeof(struct tc), GFP_KERNEL)) == NULL) { 209 if ((t = kzalloc(sizeof(struct tc), GFP_KERNEL)) == NULL) {
220 printk(KERN_WARNING "VPE: alloc_tc no mem\n"); 210 printk(KERN_WARNING "VPE: alloc_tc no mem\n");
221 return NULL; 211 return NULL;
222 } 212 }
223 213
224 memset(t, 0, sizeof(struct tc));
225
226 INIT_LIST_HEAD(&t->tc); 214 INIT_LIST_HEAD(&t->tc);
227 list_add_tail(&t->list, &vpecontrol.tc_list); 215 list_add_tail(&t->list, &vpecontrol.tc_list);
228 216
@@ -412,16 +400,17 @@ static int apply_r_mips_26(struct module *me, uint32_t *location,
412 return -ENOEXEC; 400 return -ENOEXEC;
413 } 401 }
414 402
415/* Not desperately convinced this is a good check of an overflow condition 403/*
416 anyway. But it gets in the way of handling undefined weak symbols which 404 * Not desperately convinced this is a good check of an overflow condition
417 we want to set to zero. 405 * anyway. But it gets in the way of handling undefined weak symbols which
418 if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) { 406 * we want to set to zero.
419 printk(KERN_ERR 407 * if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
420 "module %s: relocation overflow\n", 408 * printk(KERN_ERR
421 me->name); 409 * "module %s: relocation overflow\n",
422 return -ENOEXEC; 410 * me->name);
423 } 411 * return -ENOEXEC;
424*/ 412 * }
413 */
425 414
426 *location = (*location & ~0x03ffffff) | 415 *location = (*location & ~0x03ffffff) |
427 ((*location + (v >> 2)) & 0x03ffffff); 416 ((*location + (v >> 2)) & 0x03ffffff);
@@ -681,7 +670,7 @@ static void dump_tclist(void)
681} 670}
682 671
683/* We are prepared so configure and start the VPE... */ 672/* We are prepared so configure and start the VPE... */
684int vpe_run(vpe_t * v) 673int vpe_run(struct vpe * v)
685{ 674{
686 unsigned long val; 675 unsigned long val;
687 struct tc *t; 676 struct tc *t;
@@ -772,7 +761,7 @@ int vpe_run(vpe_t * v)
772 return 0; 761 return 0;
773} 762}
774 763
775static unsigned long find_vpe_symbols(vpe_t * v, Elf_Shdr * sechdrs, 764static unsigned long find_vpe_symbols(struct vpe * v, Elf_Shdr * sechdrs,
776 unsigned int symindex, const char *strtab, 765 unsigned int symindex, const char *strtab,
777 struct module *mod) 766 struct module *mod)
778{ 767{
@@ -792,10 +781,12 @@ static unsigned long find_vpe_symbols(vpe_t * v, Elf_Shdr * sechdrs,
792 return 0; 781 return 0;
793} 782}
794 783
795/* Allocates a VPE with some program code space(the load address), copies the contents 784/*
796 of the program (p)buffer performing relocatations/etc, free's it when finished. 785 * Allocates a VPE with some program code space(the load address), copies
786 * the contents of the program (p)buffer performing relocatations/etc,
787 * free's it when finished.
797*/ 788*/
798int vpe_elfload(vpe_t * v) 789int vpe_elfload(struct vpe * v)
799{ 790{
800 Elf_Ehdr *hdr; 791 Elf_Ehdr *hdr;
801 Elf_Shdr *sechdrs; 792 Elf_Shdr *sechdrs;
@@ -931,7 +922,7 @@ cleanup:
931 return err; 922 return err;
932} 923}
933 924
934static void dump_vpe(vpe_t * v) 925static void dump_vpe(struct vpe * v)
935{ 926{
936 struct tc *t; 927 struct tc *t;
937 928
@@ -947,7 +938,7 @@ static void dump_vpe(vpe_t * v)
947static int vpe_open(struct inode *inode, struct file *filp) 938static int vpe_open(struct inode *inode, struct file *filp)
948{ 939{
949 int minor; 940 int minor;
950 vpe_t *v; 941 struct vpe *v;
951 942
952 /* assume only 1 device at the mo. */ 943 /* assume only 1 device at the mo. */
953 if ((minor = MINOR(inode->i_rdev)) != 1) { 944 if ((minor = MINOR(inode->i_rdev)) != 1) {
@@ -1001,7 +992,7 @@ static int vpe_open(struct inode *inode, struct file *filp)
1001static int vpe_release(struct inode *inode, struct file *filp) 992static int vpe_release(struct inode *inode, struct file *filp)
1002{ 993{
1003 int minor, ret = 0; 994 int minor, ret = 0;
1004 vpe_t *v; 995 struct vpe *v;
1005 Elf_Ehdr *hdr; 996 Elf_Ehdr *hdr;
1006 997
1007 minor = MINOR(inode->i_rdev); 998 minor = MINOR(inode->i_rdev);
@@ -1035,7 +1026,7 @@ static ssize_t vpe_write(struct file *file, const char __user * buffer,
1035{ 1026{
1036 int minor; 1027 int minor;
1037 size_t ret = count; 1028 size_t ret = count;
1038 vpe_t *v; 1029 struct vpe *v;
1039 1030
1040 minor = MINOR(file->f_dentry->d_inode->i_rdev); 1031 minor = MINOR(file->f_dentry->d_inode->i_rdev);
1041 if ((v = get_vpe(minor)) == NULL) 1032 if ((v = get_vpe(minor)) == NULL)
@@ -1180,14 +1171,11 @@ static int __init vpe_module_init(void)
1180 return -ENODEV; 1171 return -ENODEV;
1181 } 1172 }
1182 1173
1183 if ((major = register_chrdev(VPE_MAJOR, module_name, &vpe_fops) < 0)) { 1174 if ((major = register_chrdev(0, module_name, &vpe_fops) < 0)) {
1184 printk("VPE loader: unable to register character device\n"); 1175 printk("VPE loader: unable to register character device\n");
1185 return -EBUSY; 1176 return major;
1186 } 1177 }
1187 1178
1188 if (major == 0)
1189 major = VPE_MAJOR;
1190
1191 dmt(); 1179 dmt();
1192 dvpe(); 1180 dvpe();
1193 1181
diff --git a/arch/mips/lasat/ds1603.c b/arch/mips/lasat/ds1603.c
index 9d7812e03dcd..7dced67c55eb 100644
--- a/arch/mips/lasat/ds1603.c
+++ b/arch/mips/lasat/ds1603.c
@@ -8,6 +8,7 @@
8#include <asm/lasat/lasat.h> 8#include <asm/lasat/lasat.h>
9#include <linux/delay.h> 9#include <linux/delay.h>
10#include <asm/lasat/ds1603.h> 10#include <asm/lasat/ds1603.h>
11#include <asm/time.h>
11 12
12#include "ds1603.h" 13#include "ds1603.h"
13 14
@@ -138,19 +139,27 @@ static void rtc_end_op(void)
138unsigned long ds1603_read(void) 139unsigned long ds1603_read(void)
139{ 140{
140 unsigned long word; 141 unsigned long word;
142 unsigned long flags;
143
144 spin_lock_irqsave(&rtc_lock, flags);
141 rtc_init_op(); 145 rtc_init_op();
142 rtc_write_byte(READ_TIME_CMD); 146 rtc_write_byte(READ_TIME_CMD);
143 word = rtc_read_word(); 147 word = rtc_read_word();
144 rtc_end_op(); 148 rtc_end_op();
149 spin_unlock_irqrestore(&rtc_lock, flags);
145 return word; 150 return word;
146} 151}
147 152
148int ds1603_set(unsigned long time) 153int ds1603_set(unsigned long time)
149{ 154{
155 unsigned long flags;
156
157 spin_lock_irqsave(&rtc_lock, flags);
150 rtc_init_op(); 158 rtc_init_op();
151 rtc_write_byte(SET_TIME_CMD); 159 rtc_write_byte(SET_TIME_CMD);
152 rtc_write_word(time); 160 rtc_write_word(time);
153 rtc_end_op(); 161 rtc_end_op();
162 spin_unlock_irqrestore(&rtc_lock, flags);
154 163
155 return 0; 164 return 0;
156} 165}
diff --git a/arch/mips/momentum/jaguar_atx/setup.c b/arch/mips/momentum/jaguar_atx/setup.c
index 768bf4406452..bab192ddc185 100644
--- a/arch/mips/momentum/jaguar_atx/setup.c
+++ b/arch/mips/momentum/jaguar_atx/setup.c
@@ -149,7 +149,9 @@ arch_initcall(per_cpu_mappings);
149unsigned long m48t37y_get_time(void) 149unsigned long m48t37y_get_time(void)
150{ 150{
151 unsigned int year, month, day, hour, min, sec; 151 unsigned int year, month, day, hour, min, sec;
152 unsigned long flags;
152 153
154 spin_lock_irqsave(&rtc_lock, flags);
153 /* stop the update */ 155 /* stop the update */
154 rtc_base[0x7ff8] = 0x40; 156 rtc_base[0x7ff8] = 0x40;
155 157
@@ -166,6 +168,7 @@ unsigned long m48t37y_get_time(void)
166 168
167 /* start the update */ 169 /* start the update */
168 rtc_base[0x7ff8] = 0x00; 170 rtc_base[0x7ff8] = 0x00;
171 spin_unlock_irqrestore(&rtc_lock, flags);
169 172
170 return mktime(year, month, day, hour, min, sec); 173 return mktime(year, month, day, hour, min, sec);
171} 174}
@@ -173,11 +176,13 @@ unsigned long m48t37y_get_time(void)
173int m48t37y_set_time(unsigned long sec) 176int m48t37y_set_time(unsigned long sec)
174{ 177{
175 struct rtc_time tm; 178 struct rtc_time tm;
179 unsigned long flags;
176 180
177 /* convert to a more useful format -- note months count from 0 */ 181 /* convert to a more useful format -- note months count from 0 */
178 to_tm(sec, &tm); 182 to_tm(sec, &tm);
179 tm.tm_mon += 1; 183 tm.tm_mon += 1;
180 184
185 spin_lock_irqsave(&rtc_lock, flags);
181 /* enable writing */ 186 /* enable writing */
182 rtc_base[0x7ff8] = 0x80; 187 rtc_base[0x7ff8] = 0x80;
183 188
@@ -201,6 +206,7 @@ int m48t37y_set_time(unsigned long sec)
201 206
202 /* disable writing */ 207 /* disable writing */
203 rtc_base[0x7ff8] = 0x00; 208 rtc_base[0x7ff8] = 0x00;
209 spin_unlock_irqrestore(&rtc_lock, flags);
204 210
205 return 0; 211 return 0;
206} 212}
diff --git a/arch/mips/momentum/ocelot_3/setup.c b/arch/mips/momentum/ocelot_3/setup.c
index a7803e08f9db..c9b7ff8148ec 100644
--- a/arch/mips/momentum/ocelot_3/setup.c
+++ b/arch/mips/momentum/ocelot_3/setup.c
@@ -135,7 +135,9 @@ void setup_wired_tlb_entries(void)
135unsigned long m48t37y_get_time(void) 135unsigned long m48t37y_get_time(void)
136{ 136{
137 unsigned int year, month, day, hour, min, sec; 137 unsigned int year, month, day, hour, min, sec;
138 unsigned long flags;
138 139
140 spin_lock_irqsave(&rtc_lock, flags);
139 /* stop the update */ 141 /* stop the update */
140 rtc_base[0x7ff8] = 0x40; 142 rtc_base[0x7ff8] = 0x40;
141 143
@@ -152,6 +154,7 @@ unsigned long m48t37y_get_time(void)
152 154
153 /* start the update */ 155 /* start the update */
154 rtc_base[0x7ff8] = 0x00; 156 rtc_base[0x7ff8] = 0x00;
157 spin_unlock_irqrestore(&rtc_lock, flags);
155 158
156 return mktime(year, month, day, hour, min, sec); 159 return mktime(year, month, day, hour, min, sec);
157} 160}
@@ -159,11 +162,13 @@ unsigned long m48t37y_get_time(void)
159int m48t37y_set_time(unsigned long sec) 162int m48t37y_set_time(unsigned long sec)
160{ 163{
161 struct rtc_time tm; 164 struct rtc_time tm;
165 unsigned long flags;
162 166
163 /* convert to a more useful format -- note months count from 0 */ 167 /* convert to a more useful format -- note months count from 0 */
164 to_tm(sec, &tm); 168 to_tm(sec, &tm);
165 tm.tm_mon += 1; 169 tm.tm_mon += 1;
166 170
171 spin_lock_irqsave(&rtc_lock, flags);
167 /* enable writing */ 172 /* enable writing */
168 rtc_base[0x7ff8] = 0x80; 173 rtc_base[0x7ff8] = 0x80;
169 174
@@ -187,6 +192,7 @@ int m48t37y_set_time(unsigned long sec)
187 192
188 /* disable writing */ 193 /* disable writing */
189 rtc_base[0x7ff8] = 0x00; 194 rtc_base[0x7ff8] = 0x00;
195 spin_unlock_irqrestore(&rtc_lock, flags);
190 196
191 return 0; 197 return 0;
192} 198}
diff --git a/arch/mips/momentum/ocelot_c/setup.c b/arch/mips/momentum/ocelot_c/setup.c
index ce70fc96f160..2755c1547473 100644
--- a/arch/mips/momentum/ocelot_c/setup.c
+++ b/arch/mips/momentum/ocelot_c/setup.c
@@ -140,7 +140,9 @@ unsigned long m48t37y_get_time(void)
140 unsigned char* rtc_base = (unsigned char*)0xfc800000; 140 unsigned char* rtc_base = (unsigned char*)0xfc800000;
141#endif 141#endif
142 unsigned int year, month, day, hour, min, sec; 142 unsigned int year, month, day, hour, min, sec;
143 unsigned long flags;
143 144
145 spin_lock_irqsave(&rtc_lock, flags);
144 /* stop the update */ 146 /* stop the update */
145 rtc_base[0x7ff8] = 0x40; 147 rtc_base[0x7ff8] = 0x40;
146 148
@@ -157,6 +159,7 @@ unsigned long m48t37y_get_time(void)
157 159
158 /* start the update */ 160 /* start the update */
159 rtc_base[0x7ff8] = 0x00; 161 rtc_base[0x7ff8] = 0x00;
162 spin_unlock_irqrestore(&rtc_lock, flags);
160 163
161 return mktime(year, month, day, hour, min, sec); 164 return mktime(year, month, day, hour, min, sec);
162} 165}
@@ -169,11 +172,13 @@ int m48t37y_set_time(unsigned long sec)
169 unsigned char* rtc_base = (unsigned char*)0xfc800000; 172 unsigned char* rtc_base = (unsigned char*)0xfc800000;
170#endif 173#endif
171 struct rtc_time tm; 174 struct rtc_time tm;
175 unsigned long flags;
172 176
173 /* convert to a more useful format -- note months count from 0 */ 177 /* convert to a more useful format -- note months count from 0 */
174 to_tm(sec, &tm); 178 to_tm(sec, &tm);
175 tm.tm_mon += 1; 179 tm.tm_mon += 1;
176 180
181 spin_lock_irqsave(&rtc_lock, flags);
177 /* enable writing */ 182 /* enable writing */
178 rtc_base[0x7ff8] = 0x80; 183 rtc_base[0x7ff8] = 0x80;
179 184
@@ -197,6 +202,7 @@ int m48t37y_set_time(unsigned long sec)
197 202
198 /* disable writing */ 203 /* disable writing */
199 rtc_base[0x7ff8] = 0x00; 204 rtc_base[0x7ff8] = 0x00;
205 spin_unlock_irqrestore(&rtc_lock, flags);
200 206
201 return 0; 207 return 0;
202} 208}
diff --git a/arch/mips/pmc-sierra/yosemite/setup.c b/arch/mips/pmc-sierra/yosemite/setup.c
index bdc2ab55bed6..059755b5ed57 100644
--- a/arch/mips/pmc-sierra/yosemite/setup.c
+++ b/arch/mips/pmc-sierra/yosemite/setup.c
@@ -73,7 +73,9 @@ void __init bus_error_init(void)
73unsigned long m48t37y_get_time(void) 73unsigned long m48t37y_get_time(void)
74{ 74{
75 unsigned int year, month, day, hour, min, sec; 75 unsigned int year, month, day, hour, min, sec;
76 unsigned long flags;
76 77
78 spin_lock_irqsave(&rtc_lock, flags);
77 /* Stop the update to the time */ 79 /* Stop the update to the time */
78 m48t37_base->control = 0x40; 80 m48t37_base->control = 0x40;
79 81
@@ -88,6 +90,7 @@ unsigned long m48t37y_get_time(void)
88 90
89 /* Start the update to the time again */ 91 /* Start the update to the time again */
90 m48t37_base->control = 0x00; 92 m48t37_base->control = 0x00;
93 spin_unlock_irqrestore(&rtc_lock, flags);
91 94
92 return mktime(year, month, day, hour, min, sec); 95 return mktime(year, month, day, hour, min, sec);
93} 96}
@@ -95,11 +98,13 @@ unsigned long m48t37y_get_time(void)
95int m48t37y_set_time(unsigned long sec) 98int m48t37y_set_time(unsigned long sec)
96{ 99{
97 struct rtc_time tm; 100 struct rtc_time tm;
101 unsigned long flags;
98 102
99 /* convert to a more useful format -- note months count from 0 */ 103 /* convert to a more useful format -- note months count from 0 */
100 to_tm(sec, &tm); 104 to_tm(sec, &tm);
101 tm.tm_mon += 1; 105 tm.tm_mon += 1;
102 106
107 spin_lock_irqsave(&rtc_lock, flags);
103 /* enable writing */ 108 /* enable writing */
104 m48t37_base->control = 0x80; 109 m48t37_base->control = 0x80;
105 110
@@ -123,6 +128,7 @@ int m48t37y_set_time(unsigned long sec)
123 128
124 /* disable writing */ 129 /* disable writing */
125 m48t37_base->control = 0x00; 130 m48t37_base->control = 0x00;
131 spin_unlock_irqrestore(&rtc_lock, flags);
126 132
127 return 0; 133 return 0;
128} 134}
diff --git a/arch/mips/sgi-ip22/ip22-time.c b/arch/mips/sgi-ip22/ip22-time.c
index df9b5694328a..b7300cc5c5ad 100644
--- a/arch/mips/sgi-ip22/ip22-time.c
+++ b/arch/mips/sgi-ip22/ip22-time.c
@@ -35,7 +35,9 @@ static unsigned long indy_rtc_get_time(void)
35{ 35{
36 unsigned int yrs, mon, day, hrs, min, sec; 36 unsigned int yrs, mon, day, hrs, min, sec;
37 unsigned int save_control; 37 unsigned int save_control;
38 unsigned long flags;
38 39
40 spin_lock_irqsave(&rtc_lock, flags);
39 save_control = hpc3c0->rtcregs[RTC_CMD] & 0xff; 41 save_control = hpc3c0->rtcregs[RTC_CMD] & 0xff;
40 hpc3c0->rtcregs[RTC_CMD] = save_control | RTC_TE; 42 hpc3c0->rtcregs[RTC_CMD] = save_control | RTC_TE;
41 43
@@ -47,6 +49,7 @@ static unsigned long indy_rtc_get_time(void)
47 yrs = BCD2BIN(hpc3c0->rtcregs[RTC_YEAR] & 0xff); 49 yrs = BCD2BIN(hpc3c0->rtcregs[RTC_YEAR] & 0xff);
48 50
49 hpc3c0->rtcregs[RTC_CMD] = save_control; 51 hpc3c0->rtcregs[RTC_CMD] = save_control;
52 spin_unlock_irqrestore(&rtc_lock, flags);
50 53
51 if (yrs < 45) 54 if (yrs < 45)
52 yrs += 30; 55 yrs += 30;
@@ -60,6 +63,7 @@ static int indy_rtc_set_time(unsigned long tim)
60{ 63{
61 struct rtc_time tm; 64 struct rtc_time tm;
62 unsigned int save_control; 65 unsigned int save_control;
66 unsigned long flags;
63 67
64 to_tm(tim, &tm); 68 to_tm(tim, &tm);
65 69
@@ -68,6 +72,7 @@ static int indy_rtc_set_time(unsigned long tim)
68 if (tm.tm_year >= 100) 72 if (tm.tm_year >= 100)
69 tm.tm_year -= 100; 73 tm.tm_year -= 100;
70 74
75 spin_lock_irqsave(&rtc_lock, flags);
71 save_control = hpc3c0->rtcregs[RTC_CMD] & 0xff; 76 save_control = hpc3c0->rtcregs[RTC_CMD] & 0xff;
72 hpc3c0->rtcregs[RTC_CMD] = save_control | RTC_TE; 77 hpc3c0->rtcregs[RTC_CMD] = save_control | RTC_TE;
73 78
@@ -80,6 +85,7 @@ static int indy_rtc_set_time(unsigned long tim)
80 hpc3c0->rtcregs[RTC_HUNDREDTH_SECOND] = 0; 85 hpc3c0->rtcregs[RTC_HUNDREDTH_SECOND] = 0;
81 86
82 hpc3c0->rtcregs[RTC_CMD] = save_control; 87 hpc3c0->rtcregs[RTC_CMD] = save_control;
88 spin_unlock_irqrestore(&rtc_lock, flags);
83 89
84 return 0; 90 return 0;
85} 91}
diff --git a/arch/mips/sibyte/swarm/rtc_m41t81.c b/arch/mips/sibyte/swarm/rtc_m41t81.c
index 5b4fc26c1b36..c13914bdda59 100644
--- a/arch/mips/sibyte/swarm/rtc_m41t81.c
+++ b/arch/mips/sibyte/swarm/rtc_m41t81.c
@@ -144,6 +144,7 @@ static int m41t81_write(uint8_t addr, int b)
144int m41t81_set_time(unsigned long t) 144int m41t81_set_time(unsigned long t)
145{ 145{
146 struct rtc_time tm; 146 struct rtc_time tm;
147 unsigned long flags;
147 148
148 to_tm(t, &tm); 149 to_tm(t, &tm);
149 150
@@ -153,6 +154,7 @@ int m41t81_set_time(unsigned long t)
153 * believe we should finish writing min within a second. 154 * believe we should finish writing min within a second.
154 */ 155 */
155 156
157 spin_lock_irqsave(&rtc_lock, flags);
156 tm.tm_sec = BIN2BCD(tm.tm_sec); 158 tm.tm_sec = BIN2BCD(tm.tm_sec);
157 m41t81_write(M41T81REG_SC, tm.tm_sec); 159 m41t81_write(M41T81REG_SC, tm.tm_sec);
158 160
@@ -180,6 +182,7 @@ int m41t81_set_time(unsigned long t)
180 tm.tm_year %= 100; 182 tm.tm_year %= 100;
181 tm.tm_year = BIN2BCD(tm.tm_year); 183 tm.tm_year = BIN2BCD(tm.tm_year);
182 m41t81_write(M41T81REG_YR, tm.tm_year); 184 m41t81_write(M41T81REG_YR, tm.tm_year);
185 spin_unlock_irqrestore(&rtc_lock, flags);
183 186
184 return 0; 187 return 0;
185} 188}
@@ -187,19 +190,23 @@ int m41t81_set_time(unsigned long t)
187unsigned long m41t81_get_time(void) 190unsigned long m41t81_get_time(void)
188{ 191{
189 unsigned int year, mon, day, hour, min, sec; 192 unsigned int year, mon, day, hour, min, sec;
193 unsigned long flags;
190 194
191 /* 195 /*
192 * min is valid if two reads of sec are the same. 196 * min is valid if two reads of sec are the same.
193 */ 197 */
194 for (;;) { 198 for (;;) {
199 spin_lock_irqsave(&rtc_lock, flags);
195 sec = m41t81_read(M41T81REG_SC); 200 sec = m41t81_read(M41T81REG_SC);
196 min = m41t81_read(M41T81REG_MN); 201 min = m41t81_read(M41T81REG_MN);
197 if (sec == m41t81_read(M41T81REG_SC)) break; 202 if (sec == m41t81_read(M41T81REG_SC)) break;
203 spin_unlock_irqrestore(&rtc_lock, flags);
198 } 204 }
199 hour = m41t81_read(M41T81REG_HR) & 0x3f; 205 hour = m41t81_read(M41T81REG_HR) & 0x3f;
200 day = m41t81_read(M41T81REG_DT); 206 day = m41t81_read(M41T81REG_DT);
201 mon = m41t81_read(M41T81REG_MO); 207 mon = m41t81_read(M41T81REG_MO);
202 year = m41t81_read(M41T81REG_YR); 208 year = m41t81_read(M41T81REG_YR);
209 spin_unlock_irqrestore(&rtc_lock, flags);
203 210
204 sec = BCD2BIN(sec); 211 sec = BCD2BIN(sec);
205 min = BCD2BIN(min); 212 min = BCD2BIN(min);
diff --git a/arch/mips/sibyte/swarm/rtc_xicor1241.c b/arch/mips/sibyte/swarm/rtc_xicor1241.c
index d9ff9323f24e..f4a178836415 100644
--- a/arch/mips/sibyte/swarm/rtc_xicor1241.c
+++ b/arch/mips/sibyte/swarm/rtc_xicor1241.c
@@ -113,9 +113,11 @@ int xicor_set_time(unsigned long t)
113{ 113{
114 struct rtc_time tm; 114 struct rtc_time tm;
115 int tmp; 115 int tmp;
116 unsigned long flags;
116 117
117 to_tm(t, &tm); 118 to_tm(t, &tm);
118 119
120 spin_lock_irqsave(&rtc_lock, flags);
119 /* unlock writes to the CCR */ 121 /* unlock writes to the CCR */
120 xicor_write(X1241REG_SR, X1241REG_SR_WEL); 122 xicor_write(X1241REG_SR, X1241REG_SR_WEL);
121 xicor_write(X1241REG_SR, X1241REG_SR_WEL | X1241REG_SR_RWEL); 123 xicor_write(X1241REG_SR, X1241REG_SR_WEL | X1241REG_SR_RWEL);
@@ -160,6 +162,7 @@ int xicor_set_time(unsigned long t)
160 xicor_write(X1241REG_HR, tmp); 162 xicor_write(X1241REG_HR, tmp);
161 163
162 xicor_write(X1241REG_SR, 0); 164 xicor_write(X1241REG_SR, 0);
165 spin_unlock_irqrestore(&rtc_lock, flags);
163 166
164 return 0; 167 return 0;
165} 168}
@@ -167,7 +170,9 @@ int xicor_set_time(unsigned long t)
167unsigned long xicor_get_time(void) 170unsigned long xicor_get_time(void)
168{ 171{
169 unsigned int year, mon, day, hour, min, sec, y2k; 172 unsigned int year, mon, day, hour, min, sec, y2k;
173 unsigned long flags;
170 174
175 spin_lock_irqsave(&rtc_lock, flags);
171 sec = xicor_read(X1241REG_SC); 176 sec = xicor_read(X1241REG_SC);
172 min = xicor_read(X1241REG_MN); 177 min = xicor_read(X1241REG_MN);
173 hour = xicor_read(X1241REG_HR); 178 hour = xicor_read(X1241REG_HR);
@@ -183,6 +188,7 @@ unsigned long xicor_get_time(void)
183 mon = xicor_read(X1241REG_MO); 188 mon = xicor_read(X1241REG_MO);
184 year = xicor_read(X1241REG_YR); 189 year = xicor_read(X1241REG_YR);
185 y2k = xicor_read(X1241REG_Y2K); 190 y2k = xicor_read(X1241REG_Y2K);
191 spin_unlock_irqrestore(&rtc_lock, flags);
186 192
187 sec = BCD2BIN(sec); 193 sec = BCD2BIN(sec);
188 min = BCD2BIN(min); 194 min = BCD2BIN(min);
diff --git a/arch/parisc/kernel/ptrace.c b/arch/parisc/kernel/ptrace.c
index 18130c3748f3..b6fe202a620d 100644
--- a/arch/parisc/kernel/ptrace.c
+++ b/arch/parisc/kernel/ptrace.c
@@ -78,52 +78,13 @@ void ptrace_disable(struct task_struct *child)
78 pa_psw(child)->l = 0; 78 pa_psw(child)->l = 0;
79} 79}
80 80
81long sys_ptrace(long request, long pid, long addr, long data) 81long arch_ptrace(struct task_struct *child, long request, long addr, long data)
82{ 82{
83 struct task_struct *child;
84 long ret; 83 long ret;
85#ifdef DEBUG_PTRACE 84#ifdef DEBUG_PTRACE
86 long oaddr=addr, odata=data; 85 long oaddr=addr, odata=data;
87#endif 86#endif
88 87
89 lock_kernel();
90 ret = -EPERM;
91 if (request == PTRACE_TRACEME) {
92 /* are we already being traced? */
93 if (current->ptrace & PT_PTRACED)
94 goto out;
95
96 ret = security_ptrace(current->parent, current);
97 if (ret)
98 goto out;
99
100 /* set the ptrace bit in the process flags. */
101 current->ptrace |= PT_PTRACED;
102 ret = 0;
103 goto out;
104 }
105
106 ret = -ESRCH;
107 read_lock(&tasklist_lock);
108 child = find_task_by_pid(pid);
109 if (child)
110 get_task_struct(child);
111 read_unlock(&tasklist_lock);
112 if (!child)
113 goto out;
114 ret = -EPERM;
115 if (pid == 1) /* no messing around with init! */
116 goto out_tsk;
117
118 if (request == PTRACE_ATTACH) {
119 ret = ptrace_attach(child);
120 goto out_tsk;
121 }
122
123 ret = ptrace_check_attach(child, request == PTRACE_KILL);
124 if (ret < 0)
125 goto out_tsk;
126
127 switch (request) { 88 switch (request) {
128 case PTRACE_PEEKTEXT: /* read word at location addr. */ 89 case PTRACE_PEEKTEXT: /* read word at location addr. */
129 case PTRACE_PEEKDATA: { 90 case PTRACE_PEEKDATA: {
@@ -383,11 +344,11 @@ long sys_ptrace(long request, long pid, long addr, long data)
383 344
384 case PTRACE_GETEVENTMSG: 345 case PTRACE_GETEVENTMSG:
385 ret = put_user(child->ptrace_message, (unsigned int __user *) data); 346 ret = put_user(child->ptrace_message, (unsigned int __user *) data);
386 goto out_tsk; 347 goto out;
387 348
388 default: 349 default:
389 ret = ptrace_request(child, request, addr, data); 350 ret = ptrace_request(child, request, addr, data);
390 goto out_tsk; 351 goto out;
391 } 352 }
392 353
393out_wake_notrap: 354out_wake_notrap:
@@ -396,10 +357,7 @@ out_wake:
396 wake_up_process(child); 357 wake_up_process(child);
397 ret = 0; 358 ret = 0;
398out_tsk: 359out_tsk:
399 put_task_struct(child); 360 DBG("arch_ptrace(%ld, %d, %lx, %lx) returning %ld\n",
400out:
401 unlock_kernel();
402 DBG("sys_ptrace(%ld, %d, %lx, %lx) returning %ld\n",
403 request, pid, oaddr, odata, ret); 361 request, pid, oaddr, odata, ret);
404 return ret; 362 return ret;
405} 363}
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index ca7acb0c79f0..6ffae2d2b3fa 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -605,6 +605,7 @@ config NODES_SPAN_OTHER_NODES
605 605
606config PPC_64K_PAGES 606config PPC_64K_PAGES
607 bool "64k page size" 607 bool "64k page size"
608 depends on PPC64
608 help 609 help
609 This option changes the kernel logical page size to 64k. On machines 610 This option changes the kernel logical page size to 64k. On machines
610 without processor support for 64k pages, the kernel will simulate 611 without processor support for 64k pages, the kernel will simulate
@@ -916,8 +917,21 @@ source "arch/powerpc/platforms/iseries/Kconfig"
916 917
917source "lib/Kconfig" 918source "lib/Kconfig"
918 919
920menu "Instrumentation Support"
921 depends on EXPERIMENTAL
922
919source "arch/powerpc/oprofile/Kconfig" 923source "arch/powerpc/oprofile/Kconfig"
920 924
925config KPROBES
926 bool "Kprobes (EXPERIMENTAL)"
927 help
928 Kprobes allows you to trap at almost any kernel address and
929 execute a callback function. register_kprobe() establishes
930 a probepoint and specifies the callback. Kprobes is useful
931 for kernel debugging, non-intrusive instrumentation and testing.
932 If in doubt, say "N".
933endmenu
934
921source "arch/powerpc/Kconfig.debug" 935source "arch/powerpc/Kconfig.debug"
922 936
923source "security/Kconfig" 937source "security/Kconfig"
diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 0baf64ec80d0..30a30bf559ea 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -9,16 +9,6 @@ config DEBUG_STACKOVERFLOW
9 This option will cause messages to be printed if free stack space 9 This option will cause messages to be printed if free stack space
10 drops below a certain limit. 10 drops below a certain limit.
11 11
12config KPROBES
13 bool "Kprobes"
14 depends on DEBUG_KERNEL && PPC64
15 help
16 Kprobes allows you to trap at almost any kernel address and
17 execute a callback function. register_kprobe() establishes
18 a probepoint and specifies the callback. Kprobes is useful
19 for kernel debugging, non-intrusive instrumentation and testing.
20 If in doubt, say "N".
21
22config DEBUG_STACK_USAGE 12config DEBUG_STACK_USAGE
23 bool "Stack utilization instrumentation" 13 bool "Stack utilization instrumentation"
24 depends on DEBUG_KERNEL && PPC64 14 depends on DEBUG_KERNEL && PPC64
diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index 33c63bcf69f8..cc4e9eb1c13f 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -929,6 +929,16 @@ struct cpu_spec cpu_specs[] = {
929 .icache_bsize = 32, 929 .icache_bsize = 32,
930 .dcache_bsize = 32, 930 .dcache_bsize = 32,
931 }, 931 },
932 { /* 440SPe Rev. A */
933 .pvr_mask = 0xff000fff,
934 .pvr_value = 0x53000890,
935 .cpu_name = "440SPe Rev. A",
936 .cpu_features = CPU_FTR_SPLIT_ID_CACHE |
937 CPU_FTR_USE_TB,
938 .cpu_user_features = PPC_FEATURE_32 | PPC_FEATURE_HAS_MMU,
939 .icache_bsize = 32,
940 .dcache_bsize = 32,
941 },
932#endif /* CONFIG_44x */ 942#endif /* CONFIG_44x */
933#ifdef CONFIG_FSL_BOOKE 943#ifdef CONFIG_FSL_BOOKE
934 { /* e200z5 */ 944 { /* e200z5 */
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 568ea335d616..3d2abd95c7ae 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -248,46 +248,10 @@ void ptrace_disable(struct task_struct *child)
248 clear_single_step(child); 248 clear_single_step(child);
249} 249}
250 250
251long sys_ptrace(long request, long pid, long addr, long data) 251long arch_ptrace(struct task_struct *child, long request, long addr, long data)
252{ 252{
253 struct task_struct *child;
254 int ret = -EPERM; 253 int ret = -EPERM;
255 254
256 lock_kernel();
257 if (request == PTRACE_TRACEME) {
258 /* are we already being traced? */
259 if (current->ptrace & PT_PTRACED)
260 goto out;
261 ret = security_ptrace(current->parent, current);
262 if (ret)
263 goto out;
264 /* set the ptrace bit in the process flags. */
265 current->ptrace |= PT_PTRACED;
266 ret = 0;
267 goto out;
268 }
269 ret = -ESRCH;
270 read_lock(&tasklist_lock);
271 child = find_task_by_pid(pid);
272 if (child)
273 get_task_struct(child);
274 read_unlock(&tasklist_lock);
275 if (!child)
276 goto out;
277
278 ret = -EPERM;
279 if (pid == 1) /* you may not mess with init */
280 goto out_tsk;
281
282 if (request == PTRACE_ATTACH) {
283 ret = ptrace_attach(child);
284 goto out_tsk;
285 }
286
287 ret = ptrace_check_attach(child, request == PTRACE_KILL);
288 if (ret < 0)
289 goto out_tsk;
290
291 switch (request) { 255 switch (request) {
292 /* when I and D space are separate, these will need to be fixed. */ 256 /* when I and D space are separate, these will need to be fixed. */
293 case PTRACE_PEEKTEXT: /* read word at location addr. */ 257 case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -540,10 +504,7 @@ long sys_ptrace(long request, long pid, long addr, long data)
540 ret = ptrace_request(child, request, addr, data); 504 ret = ptrace_request(child, request, addr, data);
541 break; 505 break;
542 } 506 }
543out_tsk: 507
544 put_task_struct(child);
545out:
546 unlock_kernel();
547 return ret; 508 return ret;
548} 509}
549 510
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 6996a593dcb3..b1c89bc4bf90 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -69,6 +69,7 @@
69#include <asm/iseries/it_lp_queue.h> 69#include <asm/iseries/it_lp_queue.h>
70#include <asm/iseries/hv_call_xm.h> 70#include <asm/iseries/hv_call_xm.h>
71#endif 71#endif
72#include <asm/smp.h>
72 73
73/* keep track of when we need to update the rtc */ 74/* keep track of when we need to update the rtc */
74time_t last_rtc_update; 75time_t last_rtc_update;
diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index b2f3dbca6952..f15dfb92dec0 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -329,12 +329,14 @@ static void __init htab_init_page_sizes(void)
329 */ 329 */
330 if (mmu_psize_defs[MMU_PAGE_16M].shift) 330 if (mmu_psize_defs[MMU_PAGE_16M].shift)
331 mmu_huge_psize = MMU_PAGE_16M; 331 mmu_huge_psize = MMU_PAGE_16M;
332 /* With 4k/4level pagetables, we can't (for now) cope with a
333 * huge page size < PMD_SIZE */
332 else if (mmu_psize_defs[MMU_PAGE_1M].shift) 334 else if (mmu_psize_defs[MMU_PAGE_1M].shift)
333 mmu_huge_psize = MMU_PAGE_1M; 335 mmu_huge_psize = MMU_PAGE_1M;
334 336
335 /* Calculate HPAGE_SHIFT and sanity check it */ 337 /* Calculate HPAGE_SHIFT and sanity check it */
336 if (mmu_psize_defs[mmu_huge_psize].shift > 16 && 338 if (mmu_psize_defs[mmu_huge_psize].shift > MIN_HUGEPTE_SHIFT &&
337 mmu_psize_defs[mmu_huge_psize].shift < 28) 339 mmu_psize_defs[mmu_huge_psize].shift < SID_SHIFT)
338 HPAGE_SHIFT = mmu_psize_defs[mmu_huge_psize].shift; 340 HPAGE_SHIFT = mmu_psize_defs[mmu_huge_psize].shift;
339 else 341 else
340 HPAGE_SHIFT = 0; /* No huge pages dude ! */ 342 HPAGE_SHIFT = 0; /* No huge pages dude ! */
diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index 0073a04047e4..426c269e552e 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -212,6 +212,12 @@ static int prepare_high_area_for_htlb(struct mm_struct *mm, unsigned long area)
212 212
213 BUG_ON(area >= NUM_HIGH_AREAS); 213 BUG_ON(area >= NUM_HIGH_AREAS);
214 214
215 /* Hack, so that each addresses is controlled by exactly one
216 * of the high or low area bitmaps, the first high area starts
217 * at 4GB, not 0 */
218 if (start == 0)
219 start = 0x100000000UL;
220
215 /* Check no VMAs are in the region */ 221 /* Check no VMAs are in the region */
216 vma = find_vma(mm, start); 222 vma = find_vma(mm, start);
217 if (vma && (vma->vm_start < end)) 223 if (vma && (vma->vm_start < end))
diff --git a/arch/powerpc/mm/ppc_mmu_32.c b/arch/powerpc/mm/ppc_mmu_32.c
index d137abd241ff..ed7fcfe5fd37 100644
--- a/arch/powerpc/mm/ppc_mmu_32.c
+++ b/arch/powerpc/mm/ppc_mmu_32.c
@@ -188,9 +188,9 @@ void hash_preload(struct mm_struct *mm, unsigned long ea,
188 188
189 if (Hash == 0) 189 if (Hash == 0)
190 return; 190 return;
191 pmd = pmd_offset(pgd_offset(vma->vm_mm, address), address); 191 pmd = pmd_offset(pgd_offset(mm, ea), ea);
192 if (!pmd_none(*pmd)) 192 if (!pmd_none(*pmd))
193 add_hash_page(vma->vm_mm->context, address, pmd_val(*pmd)); 193 add_hash_page(mm->context, ea, pmd_val(*pmd));
194} 194}
195 195
196/* 196/*
diff --git a/arch/powerpc/mm/slb_low.S b/arch/powerpc/mm/slb_low.S
index 3e18241b6f35..950ffc5848c7 100644
--- a/arch/powerpc/mm/slb_low.S
+++ b/arch/powerpc/mm/slb_low.S
@@ -80,12 +80,17 @@ _GLOBAL(slb_miss_kernel_load_virtual)
80BEGIN_FTR_SECTION 80BEGIN_FTR_SECTION
81 b 1f 81 b 1f
82END_FTR_SECTION_IFCLR(CPU_FTR_16M_PAGE) 82END_FTR_SECTION_IFCLR(CPU_FTR_16M_PAGE)
83 cmpldi r10,16
84
85 lhz r9,PACALOWHTLBAREAS(r13)
86 mr r11,r10
87 blt 5f
88
83 lhz r9,PACAHIGHHTLBAREAS(r13) 89 lhz r9,PACAHIGHHTLBAREAS(r13)
84 srdi r11,r10,(HTLB_AREA_SHIFT-SID_SHIFT) 90 srdi r11,r10,(HTLB_AREA_SHIFT-SID_SHIFT)
85 srd r9,r9,r11 91
86 lhz r11,PACALOWHTLBAREAS(r13) 925: srd r9,r9,r11
87 srd r11,r11,r10 93 andi. r9,r9,1
88 or. r9,r9,r11
89 beq 1f 94 beq 1f
90_GLOBAL(slb_miss_user_load_huge) 95_GLOBAL(slb_miss_user_load_huge)
91 li r11,0 96 li r11,0
diff --git a/arch/powerpc/oprofile/Kconfig b/arch/powerpc/oprofile/Kconfig
index 19d37730b664..eb2dece76a54 100644
--- a/arch/powerpc/oprofile/Kconfig
+++ b/arch/powerpc/oprofile/Kconfig
@@ -1,7 +1,3 @@
1
2menu "Profiling support"
3 depends on EXPERIMENTAL
4
5config PROFILING 1config PROFILING
6 bool "Profiling support (EXPERIMENTAL)" 2 bool "Profiling support (EXPERIMENTAL)"
7 help 3 help
@@ -19,5 +15,3 @@ config OPROFILE
19 15
20 If unsure, say N. 16 If unsure, say N.
21 17
22endmenu
23
diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
index 58c61219d08e..d7d400339458 100644
--- a/arch/powerpc/platforms/pseries/reconfig.c
+++ b/arch/powerpc/platforms/pseries/reconfig.c
@@ -286,10 +286,8 @@ static struct property *new_property(const char *name, const int length,
286 return new; 286 return new;
287 287
288cleanup: 288cleanup:
289 if (new->name) 289 kfree(new->name);
290 kfree(new->name); 290 kfree(new->value);
291 if (new->value)
292 kfree(new->value);
293 kfree(new); 291 kfree(new);
294 return NULL; 292 return NULL;
295} 293}
diff --git a/arch/ppc/4xx_io/serial_sicc.c b/arch/ppc/4xx_io/serial_sicc.c
index e95c48d57571..84d96b857e4a 100644
--- a/arch/ppc/4xx_io/serial_sicc.c
+++ b/arch/ppc/4xx_io/serial_sicc.c
@@ -1145,8 +1145,8 @@ static int set_serial_info(struct SICC_info *info,
1145 info->flags = ((state->flags & ~ASYNC_INTERNAL_FLAGS) | 1145 info->flags = ((state->flags & ~ASYNC_INTERNAL_FLAGS) |
1146 (info->flags & ASYNC_INTERNAL_FLAGS)); 1146 (info->flags & ASYNC_INTERNAL_FLAGS));
1147 state->custom_divisor = new_serial.custom_divisor; 1147 state->custom_divisor = new_serial.custom_divisor;
1148 state->close_delay = new_serial.close_delay * HZ / 100; 1148 state->close_delay = msecs_to_jiffies(10 * new_serial.close_delay);
1149 state->closing_wait = new_serial.closing_wait * HZ / 100; 1149 state->closing_wait = msecs_to_jiffies(10 * new_serial.closing_wait);
1150 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1150 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1151 port->fifosize = new_serial.xmit_fifo_size; 1151 port->fifosize = new_serial.xmit_fifo_size;
1152 1152
@@ -1465,10 +1465,8 @@ static void siccuart_close(struct tty_struct *tty, struct file *filp)
1465 info->event = 0; 1465 info->event = 0;
1466 info->tty = NULL; 1466 info->tty = NULL;
1467 if (info->blocked_open) { 1467 if (info->blocked_open) {
1468 if (info->state->close_delay) { 1468 if (info->state->close_delay)
1469 set_current_state(TASK_INTERRUPTIBLE); 1469 schedule_timeout_interruptible(info->state->close_delay);
1470 schedule_timeout(info->state->close_delay);
1471 }
1472 wake_up_interruptible(&info->open_wait); 1470 wake_up_interruptible(&info->open_wait);
1473 } 1471 }
1474 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1472 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
@@ -1496,7 +1494,7 @@ static void siccuart_wait_until_sent(struct tty_struct *tty, int timeout)
1496 * Note: we have to use pretty tight timings here to satisfy 1494 * Note: we have to use pretty tight timings here to satisfy
1497 * the NIST-PCTS. 1495 * the NIST-PCTS.
1498 */ 1496 */
1499 char_time = (info->timeout - HZ/50) / info->port->fifosize; 1497 char_time = (info->timeout - msecs_to_jiffies(20)) / info->port->fifosize;
1500 char_time = char_time / 5; 1498 char_time = char_time / 5;
1501 if (char_time == 0) 1499 if (char_time == 0)
1502 char_time = 1; 1500 char_time = 1;
@@ -1521,8 +1519,7 @@ static void siccuart_wait_until_sent(struct tty_struct *tty, int timeout)
1521 tty->index, jiffies, 1519 tty->index, jiffies,
1522 expire, char_time); 1520 expire, char_time);
1523 while ((readb(info->port->uart_base + BL_SICC_LSR) & _LSR_TX_ALL) != _LSR_TX_ALL) { 1521 while ((readb(info->port->uart_base + BL_SICC_LSR) & _LSR_TX_ALL) != _LSR_TX_ALL) {
1524 set_current_state(TASK_INTERRUPTIBLE); 1522 schedule_timeout_interruptible(char_time);
1525 schedule_timeout(char_time);
1526 if (signal_pending(current)) 1523 if (signal_pending(current))
1527 break; 1524 break;
1528 if (timeout && time_after(jiffies, expire)) 1525 if (timeout && time_after(jiffies, expire))
@@ -1773,7 +1770,7 @@ int __init siccuart_init(void)
1773 for (i = 0; i < SERIAL_SICC_NR; i++) { 1770 for (i = 0; i < SERIAL_SICC_NR; i++) {
1774 struct SICC_state *state = sicc_state + i; 1771 struct SICC_state *state = sicc_state + i;
1775 state->line = i; 1772 state->line = i;
1776 state->close_delay = 5 * HZ / 10; 1773 state->close_delay = msecs_to_jiffies(500);
1777 state->closing_wait = 30 * HZ; 1774 state->closing_wait = 30 * HZ;
1778 spin_lock_init(&state->sicc_lock); 1775 spin_lock_init(&state->sicc_lock);
1779 } 1776 }
diff --git a/arch/ppc/8260_io/fcc_enet.c b/arch/ppc/8260_io/fcc_enet.c
index 2086c6ad1147..4edeede9ccfd 100644
--- a/arch/ppc/8260_io/fcc_enet.c
+++ b/arch/ppc/8260_io/fcc_enet.c
@@ -1309,8 +1309,7 @@ static void mii_dm9161_wait(uint mii_reg, struct net_device *dev)
1309 1309
1310 /* Davicom takes a bit to come up after a reset, 1310 /* Davicom takes a bit to come up after a reset,
1311 * so wait here for a bit */ 1311 * so wait here for a bit */
1312 set_current_state(TASK_UNINTERRUPTIBLE); 1312 schedule_timeout_uninterruptible(timeout);
1313 schedule_timeout(timeout);
1314} 1313}
1315 1314
1316static phy_info_t phy_info_dm9161 = { 1315static phy_info_t phy_info_dm9161 = {
diff --git a/arch/ppc/8xx_io/cs4218_tdm.c b/arch/ppc/8xx_io/cs4218_tdm.c
index 532caa388dc2..49eb2a7e65c0 100644
--- a/arch/ppc/8xx_io/cs4218_tdm.c
+++ b/arch/ppc/8xx_io/cs4218_tdm.c
@@ -1013,8 +1013,7 @@ static void CS_IrqCleanup(void)
1013 */ 1013 */
1014 cpm_free_handler(CPMVEC_SMC2); 1014 cpm_free_handler(CPMVEC_SMC2);
1015 1015
1016 if (beep_buf) 1016 kfree(beep_buf);
1017 kfree(beep_buf);
1018 kd_mksound = orig_mksound; 1017 kd_mksound = orig_mksound;
1019} 1018}
1020#endif /* MODULE */ 1019#endif /* MODULE */
diff --git a/arch/ppc/Kconfig b/arch/ppc/Kconfig
index 114b90fdea24..8fa51b0a32d2 100644
--- a/arch/ppc/Kconfig
+++ b/arch/ppc/Kconfig
@@ -746,6 +746,16 @@ config MPC834x
746 bool 746 bool
747 default y if MPC834x_SYS 747 default y if MPC834x_SYS
748 748
749config CPM1
750 bool
751 depends on 8xx
752 default y
753 help
754 The CPM1 (Communications Processor Module) is a coprocessor on
755 embedded CPUs made by Motorola. Selecting this option means that
756 you wish to build a kernel for a machine with a CPM1 coprocessor
757 on it (8xx, 827x, 8560).
758
749config CPM2 759config CPM2
750 bool 760 bool
751 depends on 8260 || MPC8560 || MPC8555 761 depends on 8260 || MPC8560 || MPC8555
@@ -1247,6 +1257,14 @@ source "drivers/pci/Kconfig"
1247 1257
1248source "drivers/pcmcia/Kconfig" 1258source "drivers/pcmcia/Kconfig"
1249 1259
1260config RAPIDIO
1261 bool "RapidIO support" if MPC8540 || MPC8560
1262 help
1263 If you say Y here, the kernel will include drivers and
1264 infrastructure code to support RapidIO interconnect devices.
1265
1266source "drivers/rapidio/Kconfig"
1267
1250endmenu 1268endmenu
1251 1269
1252menu "Advanced setup" 1270menu "Advanced setup"
diff --git a/arch/ppc/boot/simple/Makefile b/arch/ppc/boot/simple/Makefile
index b7bd8f61a4ad..82df88b01bbe 100644
--- a/arch/ppc/boot/simple/Makefile
+++ b/arch/ppc/boot/simple/Makefile
@@ -67,6 +67,12 @@ zimageinitrd-$(CONFIG_BAMBOO) := zImage.initrd-TREE
67 entrypoint-$(CONFIG_BAMBOO) := 0x01000000 67 entrypoint-$(CONFIG_BAMBOO) := 0x01000000
68 extra.o-$(CONFIG_BAMBOO) := pibs.o 68 extra.o-$(CONFIG_BAMBOO) := pibs.o
69 69
70 zimage-$(CONFIG_BUBINGA) := zImage-TREE
71zimageinitrd-$(CONFIG_BUBINGA) := zImage.initrd-TREE
72 end-$(CONFIG_BUBINGA) := bubinga
73 entrypoint-$(CONFIG_BUBINGA) := 0x01000000
74 extra.o-$(CONFIG_BUBINGA) := openbios.o
75
70 zimage-$(CONFIG_EBONY) := zImage-TREE 76 zimage-$(CONFIG_EBONY) := zImage-TREE
71zimageinitrd-$(CONFIG_EBONY) := zImage.initrd-TREE 77zimageinitrd-$(CONFIG_EBONY) := zImage.initrd-TREE
72 end-$(CONFIG_EBONY) := ebony 78 end-$(CONFIG_EBONY) := ebony
@@ -79,12 +85,30 @@ zimageinitrd-$(CONFIG_LUAN) := zImage.initrd-TREE
79 entrypoint-$(CONFIG_LUAN) := 0x01000000 85 entrypoint-$(CONFIG_LUAN) := 0x01000000
80 extra.o-$(CONFIG_LUAN) := pibs.o 86 extra.o-$(CONFIG_LUAN) := pibs.o
81 87
88 zimage-$(CONFIG_YUCCA) := zImage-TREE
89zimageinitrd-$(CONFIG_YUCCA) := zImage.initrd-TREE
90 end-$(CONFIG_YUCCA) := yucca
91 entrypoint-$(CONFIG_YUCCA) := 0x01000000
92 extra.o-$(CONFIG_YUCCA) := pibs.o
93
82 zimage-$(CONFIG_OCOTEA) := zImage-TREE 94 zimage-$(CONFIG_OCOTEA) := zImage-TREE
83zimageinitrd-$(CONFIG_OCOTEA) := zImage.initrd-TREE 95zimageinitrd-$(CONFIG_OCOTEA) := zImage.initrd-TREE
84 end-$(CONFIG_OCOTEA) := ocotea 96 end-$(CONFIG_OCOTEA) := ocotea
85 entrypoint-$(CONFIG_OCOTEA) := 0x01000000 97 entrypoint-$(CONFIG_OCOTEA) := 0x01000000
86 extra.o-$(CONFIG_OCOTEA) := pibs.o 98 extra.o-$(CONFIG_OCOTEA) := pibs.o
87 99
100 zimage-$(CONFIG_SYCAMORE) := zImage-TREE
101zimageinitrd-$(CONFIG_SYCAMORE) := zImage.initrd-TREE
102 end-$(CONFIG_SYCAMORE) := sycamore
103 entrypoint-$(CONFIG_SYCAMORE) := 0x01000000
104 extra.o-$(CONFIG_SYCAMORE) := openbios.o
105
106 zimage-$(CONFIG_WALNUT) := zImage-TREE
107zimageinitrd-$(CONFIG_WALNUT) := zImage.initrd-TREE
108 end-$(CONFIG_WALNUT) := walnut
109 entrypoint-$(CONFIG_WALNUT) := 0x01000000
110 extra.o-$(CONFIG_WALNUT) := openbios.o
111
88 extra.o-$(CONFIG_EV64260) := misc-ev64260.o 112 extra.o-$(CONFIG_EV64260) := misc-ev64260.o
89 end-$(CONFIG_EV64260) := ev64260 113 end-$(CONFIG_EV64260) := ev64260
90 cacheflag-$(CONFIG_EV64260) := -include $(clear_L2_L3) 114 cacheflag-$(CONFIG_EV64260) := -include $(clear_L2_L3)
@@ -162,7 +186,8 @@ OBJCOPY_ARGS := -O elf32-powerpc
162 186
163# head.o and relocate.o must be at the start. 187# head.o and relocate.o must be at the start.
164boot-y := head.o relocate.o $(extra.o-y) $(misc-y) 188boot-y := head.o relocate.o $(extra.o-y) $(misc-y)
165boot-$(CONFIG_40x) += embed_config.o 189boot-$(CONFIG_REDWOOD_5) += embed_config.o
190boot-$(CONFIG_REDWOOD_6) += embed_config.o
166boot-$(CONFIG_8xx) += embed_config.o 191boot-$(CONFIG_8xx) += embed_config.o
167boot-$(CONFIG_8260) += embed_config.o 192boot-$(CONFIG_8260) += embed_config.o
168boot-$(CONFIG_BSEIP) += iic.o 193boot-$(CONFIG_BSEIP) += iic.o
diff --git a/arch/ppc/boot/simple/misc.c b/arch/ppc/boot/simple/misc.c
index e02de5b467a4..f415d6c62362 100644
--- a/arch/ppc/boot/simple/misc.c
+++ b/arch/ppc/boot/simple/misc.c
@@ -23,7 +23,7 @@
23#include <asm/page.h> 23#include <asm/page.h>
24#include <asm/mmu.h> 24#include <asm/mmu.h>
25#include <asm/bootinfo.h> 25#include <asm/bootinfo.h>
26#ifdef CONFIG_44x 26#ifdef CONFIG_4xx
27#include <asm/ibm4xx.h> 27#include <asm/ibm4xx.h>
28#endif 28#endif
29#include <asm/reg.h> 29#include <asm/reg.h>
@@ -88,6 +88,14 @@ get_mem_size(void)
88 return 0; 88 return 0;
89} 89}
90 90
91#if defined(CONFIG_40x)
92#define PPC4xx_EMAC0_MR0 EMAC0_BASE
93#endif
94
95#if defined(CONFIG_44x) && defined(PPC44x_EMAC0_MR0)
96#define PPC4xx_EMAC0_MR0 PPC44x_EMAC0_MR0
97#endif
98
91struct bi_record * 99struct bi_record *
92decompress_kernel(unsigned long load_addr, int num_words, unsigned long cksum) 100decompress_kernel(unsigned long load_addr, int num_words, unsigned long cksum)
93{ 101{
@@ -103,13 +111,13 @@ decompress_kernel(unsigned long load_addr, int num_words, unsigned long cksum)
103 com_port = serial_init(0, NULL); 111 com_port = serial_init(0, NULL);
104#endif 112#endif
105 113
106#if defined(CONFIG_44x) && defined(PPC44x_EMAC0_MR0) 114#if defined(PPC4xx_EMAC0_MR0)
107 /* Reset MAL */ 115 /* Reset MAL */
108 mtdcr(DCRN_MALCR(DCRN_MAL_BASE), MALCR_MMSR); 116 mtdcr(DCRN_MALCR(DCRN_MAL_BASE), MALCR_MMSR);
109 /* Wait for reset */ 117 /* Wait for reset */
110 while (mfdcr(DCRN_MALCR(DCRN_MAL_BASE)) & MALCR_MMSR) {}; 118 while (mfdcr(DCRN_MALCR(DCRN_MAL_BASE)) & MALCR_MMSR) {};
111 /* Reset EMAC */ 119 /* Reset EMAC */
112 *(volatile unsigned long *)PPC44x_EMAC0_MR0 = 0x20000000; 120 *(volatile unsigned long *)PPC4xx_EMAC0_MR0 = 0x20000000;
113 __asm__ __volatile__("eieio"); 121 __asm__ __volatile__("eieio");
114#endif 122#endif
115 123
@@ -164,7 +172,9 @@ decompress_kernel(unsigned long load_addr, int num_words, unsigned long cksum)
164 puts(" "); puthex((unsigned long)(&__ramdisk_end));puts("\n"); 172 puts(" "); puthex((unsigned long)(&__ramdisk_end));puts("\n");
165 } 173 }
166 174
175#ifndef CONFIG_40x /* don't overwrite the 40x image located at 0x00400000! */
167 avail_ram = (char *)0x00400000; 176 avail_ram = (char *)0x00400000;
177#endif
168 end_avail = (char *)0x00800000; 178 end_avail = (char *)0x00800000;
169 puts("avail ram: "); puthex((unsigned long)avail_ram); puts(" "); 179 puts("avail ram: "); puthex((unsigned long)avail_ram); puts(" ");
170 puthex((unsigned long)end_avail); puts("\n"); 180 puthex((unsigned long)end_avail); puts("\n");
diff --git a/arch/ppc/boot/simple/openbios.c b/arch/ppc/boot/simple/openbios.c
index c732b6d70cfb..81f11d8b30a7 100644
--- a/arch/ppc/boot/simple/openbios.c
+++ b/arch/ppc/boot/simple/openbios.c
@@ -1,19 +1,43 @@
1/* 1/*
2 * arch/ppc/boot/simple/openbios.c 2 * arch/ppc/boot/simple/openbios.c
3 * 3 *
4 * 2005 (c) SYSGO AG - g.jaeger@sysgo.com 4 * Copyright (c) 2005 DENX Software Engineering
5 * Stefan Roese <sr@denx.de>
6 *
7 * Based on original work by
8 * 2005 (c) SYSGO AG - g.jaeger@sysgo.com
9 *
5 * This file is licensed under the terms of the GNU General Public 10 * This file is licensed under the terms of the GNU General Public
6 * License version 2. This program is licensed "as is" without 11 * License version 2. This program is licensed "as is" without
7 * any warranty of any kind, whether express or implied. 12 * any warranty of any kind, whether express or implied.
8 * 13 *
9 * Derived from arch/ppc/boot/simple/pibs.c (from MontaVista)
10 */ 14 */
11 15
12#include <linux/types.h> 16#include <linux/types.h>
13#include <linux/config.h> 17#include <linux/config.h>
14#include <linux/string.h> 18#include <linux/string.h>
15#include <asm/ppcboot.h> 19#include <asm/ppcboot.h>
16#include <platforms/4xx/ebony.h> 20#include <asm/ibm4xx.h>
21#include <asm/reg.h>
22#ifdef CONFIG_40x
23#include <asm/io.h>
24#endif
25
26#if defined(CONFIG_BUBINGA)
27#define BOARD_INFO_VECTOR 0xFFF80B50 /* openbios 1.19 moved this vector down - armin */
28#else
29#define BOARD_INFO_VECTOR 0xFFFE0B50
30#endif
31
32#ifdef CONFIG_40x
33/* Supply a default Ethernet address for those eval boards that don't
34 * ship with one. This is an address from the MBX board I have, so
35 * it is unlikely you will find it on your network.
36 */
37static ushort def_enet_addr[] = { 0x0800, 0x3e26, 0x1559 };
38
39extern unsigned long timebase_period_ns;
40#endif /* CONFIG_40x */
17 41
18extern unsigned long decompress_kernel(unsigned long load_addr, int num_words, 42extern unsigned long decompress_kernel(unsigned long load_addr, int num_words,
19 unsigned long cksum); 43 unsigned long cksum);
@@ -23,15 +47,85 @@ extern unsigned long decompress_kernel(unsigned long load_addr, int num_words,
23bd_t hold_resid_buf __attribute__ ((__section__ (".data.boot"))); 47bd_t hold_resid_buf __attribute__ ((__section__ (".data.boot")));
24bd_t *hold_residual = &hold_resid_buf; 48bd_t *hold_residual = &hold_resid_buf;
25 49
50typedef struct openbios_board_info {
51 unsigned char bi_s_version[4]; /* Version of this structure */
52 unsigned char bi_r_version[30]; /* Version of the IBM ROM */
53 unsigned int bi_memsize; /* DRAM installed, in bytes */
54#ifdef CONFIG_405EP
55 unsigned char bi_enetaddr[2][6]; /* Local Ethernet MAC address */
56#else /* CONFIG_405EP */
57 unsigned char bi_enetaddr[6]; /* Local Ethernet MAC address */
58#endif /* CONFIG_405EP */
59 unsigned char bi_pci_enetaddr[6]; /* PCI Ethernet MAC address */
60 unsigned int bi_intfreq; /* Processor speed, in Hz */
61 unsigned int bi_busfreq; /* PLB Bus speed, in Hz */
62 unsigned int bi_pci_busfreq; /* PCI Bus speed, in Hz */
63#ifdef CONFIG_405EP
64 unsigned int bi_opb_busfreq; /* OPB Bus speed, in Hz */
65 unsigned int bi_pllouta_freq; /* PLL OUTA speed, in Hz */
66#endif /* CONFIG_405EP */
67} openbios_bd_t;
68
26void * 69void *
27load_kernel(unsigned long load_addr, int num_words, unsigned long cksum, 70load_kernel(unsigned long load_addr, int num_words, unsigned long cksum,
28 void *ign1, void *ign2) 71 void *ign1, void *ign2)
29{ 72{
30 decompress_kernel(load_addr, num_words, cksum); 73#ifdef CONFIG_40x
74 openbios_bd_t *openbios_bd = NULL;
75 openbios_bd_t *(*get_board_info)(void) =
76 (openbios_bd_t *(*)(void))(*(unsigned long *)BOARD_INFO_VECTOR);
77
78 /*
79 * On 40x platforms we not only need the MAC-addresses, but also the
80 * clocks and memsize. Now try to get all values using the OpenBIOS
81 * "get_board_info()" callback.
82 */
83 if ((openbios_bd = get_board_info()) != NULL) {
84 /*
85 * Copy bd_info from OpenBIOS struct into U-Boot struct
86 * used by kernel
87 */
88 hold_residual->bi_memsize = openbios_bd->bi_memsize;
89 hold_residual->bi_intfreq = openbios_bd->bi_intfreq;
90 hold_residual->bi_busfreq = openbios_bd->bi_busfreq;
91 hold_residual->bi_pci_busfreq = openbios_bd->bi_pci_busfreq;
92 memcpy(hold_residual->bi_pci_enetaddr, openbios_bd->bi_pci_enetaddr, 6);
93#ifdef CONFIG_405EP
94 memcpy(hold_residual->bi_enetaddr, openbios_bd->bi_enetaddr[0], 6);
95 memcpy(hold_residual->bi_enet1addr, openbios_bd->bi_enetaddr[1], 6);
96 hold_residual->bi_opbfreq = openbios_bd->bi_opb_busfreq;
97 hold_residual->bi_procfreq = openbios_bd->bi_pllouta_freq;
98#else /* CONFIG_405EP */
99 memcpy(hold_residual->bi_enetaddr, openbios_bd->bi_enetaddr, 6);
100#endif /* CONFIG_405EP */
101 } else {
102 /* Hmmm...better try to stuff some defaults.
103 */
104 hold_residual->bi_memsize = 16 * 1024 * 1024;
105 hold_residual->bi_intfreq = 200000000;
106 hold_residual->bi_busfreq = 100000000;
107 hold_residual->bi_pci_busfreq = 66666666;
108
109 /*
110 * Only supply one mac-address in this fallback
111 */
112 memcpy(hold_residual->bi_enetaddr, (void *)def_enet_addr, 6);
113#ifdef CONFIG_405EP
114 hold_residual->bi_opbfreq = 50000000;
115 hold_residual->bi_procfreq = 200000000;
116#endif /* CONFIG_405EP */
117 }
31 118
119 timebase_period_ns = 1000000000 / hold_residual->bi_intfreq;
120#endif /* CONFIG_40x */
121
122#ifdef CONFIG_440GP
32 /* simply copy the MAC addresses */ 123 /* simply copy the MAC addresses */
33 memcpy(hold_residual->bi_enetaddr, (char *)EBONY_OPENBIOS_MAC_BASE, 6); 124 memcpy(hold_residual->bi_enetaddr, (char *)OPENBIOS_MAC_BASE, 6);
34 memcpy(hold_residual->bi_enet1addr, (char *)(EBONY_OPENBIOS_MAC_BASE+EBONY_OPENBIOS_MAC_OFFSET), 6); 125 memcpy(hold_residual->bi_enet1addr, (char *)(OPENBIOS_MAC_BASE+OPENBIOS_MAC_OFFSET), 6);
126#endif /* CONFIG_440GP */
127
128 decompress_kernel(load_addr, num_words, cksum);
35 129
36 return (void *)hold_residual; 130 return (void *)hold_residual;
37} 131}
diff --git a/arch/ppc/configs/ev64360_defconfig b/arch/ppc/configs/ev64360_defconfig
index de9bbb791db9..d471e578dcb5 100644
--- a/arch/ppc/configs/ev64360_defconfig
+++ b/arch/ppc/configs/ev64360_defconfig
@@ -1,17 +1,17 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.13-rc5 3# Linux kernel version: 2.6.14
4# Fri Aug 5 15:18:23 2005 4# Fri Oct 28 19:15:34 2005
5# 5#
6CONFIG_MMU=y 6CONFIG_MMU=y
7CONFIG_GENERIC_HARDIRQS=y 7CONFIG_GENERIC_HARDIRQS=y
8CONFIG_RWSEM_XCHGADD_ALGORITHM=y 8CONFIG_RWSEM_XCHGADD_ALGORITHM=y
9CONFIG_GENERIC_CALIBRATE_DELAY=y 9CONFIG_GENERIC_CALIBRATE_DELAY=y
10CONFIG_HAVE_DEC_LOCK=y
11CONFIG_PPC=y 10CONFIG_PPC=y
12CONFIG_PPC32=y 11CONFIG_PPC32=y
13CONFIG_GENERIC_NVRAM=y 12CONFIG_GENERIC_NVRAM=y
14CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y 13CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
14CONFIG_ARCH_MAY_HAVE_PC_FDC=y
15 15
16# 16#
17# Code maturity level options 17# Code maturity level options
@@ -26,6 +26,7 @@ CONFIG_INIT_ENV_ARG_LIMIT=32
26# General setup 26# General setup
27# 27#
28CONFIG_LOCALVERSION="" 28CONFIG_LOCALVERSION=""
29CONFIG_LOCALVERSION_AUTO=y
29CONFIG_SWAP=y 30CONFIG_SWAP=y
30CONFIG_SYSVIPC=y 31CONFIG_SYSVIPC=y
31CONFIG_POSIX_MQUEUE=y 32CONFIG_POSIX_MQUEUE=y
@@ -35,6 +36,7 @@ CONFIG_SYSCTL=y
35CONFIG_HOTPLUG=y 36CONFIG_HOTPLUG=y
36CONFIG_KOBJECT_UEVENT=y 37CONFIG_KOBJECT_UEVENT=y
37# CONFIG_IKCONFIG is not set 38# CONFIG_IKCONFIG is not set
39CONFIG_INITRAMFS_SOURCE=""
38# CONFIG_EMBEDDED is not set 40# CONFIG_EMBEDDED is not set
39CONFIG_KALLSYMS=y 41CONFIG_KALLSYMS=y
40# CONFIG_KALLSYMS_EXTRA_PASS is not set 42# CONFIG_KALLSYMS_EXTRA_PASS is not set
@@ -74,7 +76,7 @@ CONFIG_TAU=y
74# CONFIG_TAU_AVERAGE is not set 76# CONFIG_TAU_AVERAGE is not set
75# CONFIG_KEXEC is not set 77# CONFIG_KEXEC is not set
76# CONFIG_CPU_FREQ is not set 78# CONFIG_CPU_FREQ is not set
77# CONFIG_PM is not set 79# CONFIG_WANT_EARLY_SERIAL is not set
78CONFIG_PPC_STD_MMU=y 80CONFIG_PPC_STD_MMU=y
79CONFIG_NOT_COHERENT_CACHE=y 81CONFIG_NOT_COHERENT_CACHE=y
80 82
@@ -86,22 +88,18 @@ CONFIG_NOT_COHERENT_CACHE=y
86# CONFIG_KATANA is not set 88# CONFIG_KATANA is not set
87# CONFIG_WILLOW is not set 89# CONFIG_WILLOW is not set
88# CONFIG_CPCI690 is not set 90# CONFIG_CPCI690 is not set
89# CONFIG_PCORE is not set
90# CONFIG_POWERPMC250 is not set 91# CONFIG_POWERPMC250 is not set
91# CONFIG_CHESTNUT is not set 92# CONFIG_CHESTNUT is not set
92# CONFIG_SPRUCE is not set 93# CONFIG_SPRUCE is not set
93# CONFIG_HDPU is not set 94# CONFIG_HDPU is not set
94# CONFIG_EV64260 is not set 95# CONFIG_EV64260 is not set
95# CONFIG_LOPEC is not set 96# CONFIG_LOPEC is not set
96# CONFIG_MCPN765 is not set
97# CONFIG_MVME5100 is not set 97# CONFIG_MVME5100 is not set
98# CONFIG_PPLUS is not set 98# CONFIG_PPLUS is not set
99# CONFIG_PRPMC750 is not set 99# CONFIG_PRPMC750 is not set
100# CONFIG_PRPMC800 is not set 100# CONFIG_PRPMC800 is not set
101# CONFIG_SANDPOINT is not set 101# CONFIG_SANDPOINT is not set
102# CONFIG_RADSTONE_PPC7D is not set 102# CONFIG_RADSTONE_PPC7D is not set
103# CONFIG_ADIR is not set
104# CONFIG_K2 is not set
105# CONFIG_PAL4 is not set 103# CONFIG_PAL4 is not set
106# CONFIG_GEMINI is not set 104# CONFIG_GEMINI is not set
107# CONFIG_EST8260 is not set 105# CONFIG_EST8260 is not set
@@ -138,10 +136,13 @@ CONFIG_FLATMEM_MANUAL=y
138# CONFIG_SPARSEMEM_MANUAL is not set 136# CONFIG_SPARSEMEM_MANUAL is not set
139CONFIG_FLATMEM=y 137CONFIG_FLATMEM=y
140CONFIG_FLAT_NODE_MEM_MAP=y 138CONFIG_FLAT_NODE_MEM_MAP=y
139# CONFIG_SPARSEMEM_STATIC is not set
141CONFIG_BINFMT_ELF=y 140CONFIG_BINFMT_ELF=y
142CONFIG_BINFMT_MISC=y 141CONFIG_BINFMT_MISC=y
143CONFIG_CMDLINE_BOOL=y 142CONFIG_CMDLINE_BOOL=y
144CONFIG_CMDLINE="console=ttyMM0,115200 root=/dev/mtdblock1 rw rootfstype=jffs2" 143CONFIG_CMDLINE="console=ttyMM0,115200 root=/dev/mtdblock1 rw rootfstype=jffs2"
144# CONFIG_PM is not set
145# CONFIG_SOFTWARE_SUSPEND is not set
145CONFIG_SECCOMP=y 146CONFIG_SECCOMP=y
146CONFIG_ISA_DMA_API=y 147CONFIG_ISA_DMA_API=y
147 148
@@ -152,7 +153,6 @@ CONFIG_GENERIC_ISA_DMA=y
152CONFIG_PCI=y 153CONFIG_PCI=y
153CONFIG_PCI_DOMAINS=y 154CONFIG_PCI_DOMAINS=y
154# CONFIG_PCI_LEGACY_PROC is not set 155# CONFIG_PCI_LEGACY_PROC is not set
155# CONFIG_PCI_NAMES is not set
156 156
157# 157#
158# PCCARD (PCMCIA/CardBus) support 158# PCCARD (PCMCIA/CardBus) support
@@ -206,14 +206,19 @@ CONFIG_SYN_COOKIES=y
206# CONFIG_INET_ESP is not set 206# CONFIG_INET_ESP is not set
207# CONFIG_INET_IPCOMP is not set 207# CONFIG_INET_IPCOMP is not set
208# CONFIG_INET_TUNNEL is not set 208# CONFIG_INET_TUNNEL is not set
209CONFIG_IP_TCPDIAG=y 209CONFIG_INET_DIAG=y
210# CONFIG_IP_TCPDIAG_IPV6 is not set 210CONFIG_INET_TCP_DIAG=y
211# CONFIG_TCP_CONG_ADVANCED is not set 211# CONFIG_TCP_CONG_ADVANCED is not set
212CONFIG_TCP_CONG_BIC=y 212CONFIG_TCP_CONG_BIC=y
213# CONFIG_IPV6 is not set 213# CONFIG_IPV6 is not set
214# CONFIG_NETFILTER is not set 214# CONFIG_NETFILTER is not set
215 215
216# 216#
217# DCCP Configuration (EXPERIMENTAL)
218#
219# CONFIG_IP_DCCP is not set
220
221#
217# SCTP Configuration (EXPERIMENTAL) 222# SCTP Configuration (EXPERIMENTAL)
218# 223#
219# CONFIG_IP_SCTP is not set 224# CONFIG_IP_SCTP is not set
@@ -239,6 +244,7 @@ CONFIG_TCP_CONG_BIC=y
239# CONFIG_HAMRADIO is not set 244# CONFIG_HAMRADIO is not set
240# CONFIG_IRDA is not set 245# CONFIG_IRDA is not set
241# CONFIG_BT is not set 246# CONFIG_BT is not set
247# CONFIG_IEEE80211 is not set
242 248
243# 249#
244# Device Drivers 250# Device Drivers
@@ -252,6 +258,11 @@ CONFIG_PREVENT_FIRMWARE_BUILD=y
252# CONFIG_FW_LOADER is not set 258# CONFIG_FW_LOADER is not set
253 259
254# 260#
261# Connector - unified userspace <-> kernelspace linker
262#
263# CONFIG_CONNECTOR is not set
264
265#
255# Memory Technology Devices (MTD) 266# Memory Technology Devices (MTD)
256# 267#
257CONFIG_MTD=y 268CONFIG_MTD=y
@@ -358,7 +369,6 @@ CONFIG_BLK_DEV_RAM=y
358CONFIG_BLK_DEV_RAM_COUNT=16 369CONFIG_BLK_DEV_RAM_COUNT=16
359CONFIG_BLK_DEV_RAM_SIZE=32768 370CONFIG_BLK_DEV_RAM_SIZE=32768
360CONFIG_BLK_DEV_INITRD=y 371CONFIG_BLK_DEV_INITRD=y
361CONFIG_INITRAMFS_SOURCE=""
362# CONFIG_LBD is not set 372# CONFIG_LBD is not set
363# CONFIG_CDROM_PKTCDVD is not set 373# CONFIG_CDROM_PKTCDVD is not set
364 374
@@ -379,6 +389,7 @@ CONFIG_IOSCHED_CFQ=y
379# 389#
380# SCSI device support 390# SCSI device support
381# 391#
392# CONFIG_RAID_ATTRS is not set
382# CONFIG_SCSI is not set 393# CONFIG_SCSI is not set
383 394
384# 395#
@@ -420,6 +431,10 @@ CONFIG_NETDEVICES=y
420# CONFIG_ARCNET is not set 431# CONFIG_ARCNET is not set
421 432
422# 433#
434# PHY device support
435#
436
437#
423# Ethernet (10 or 100Mbit) 438# Ethernet (10 or 100Mbit)
424# 439#
425# CONFIG_NET_ETHERNET is not set 440# CONFIG_NET_ETHERNET is not set
@@ -434,6 +449,7 @@ CONFIG_NETDEVICES=y
434# CONFIG_HAMACHI is not set 449# CONFIG_HAMACHI is not set
435# CONFIG_YELLOWFIN is not set 450# CONFIG_YELLOWFIN is not set
436# CONFIG_R8169 is not set 451# CONFIG_R8169 is not set
452# CONFIG_SIS190 is not set
437# CONFIG_SKGE is not set 453# CONFIG_SKGE is not set
438# CONFIG_SK98LIN is not set 454# CONFIG_SK98LIN is not set
439# CONFIG_TIGON3 is not set 455# CONFIG_TIGON3 is not set
@@ -446,6 +462,7 @@ CONFIG_MV643XX_ETH_0=y
446# 462#
447# Ethernet (10000 Mbit) 463# Ethernet (10000 Mbit)
448# 464#
465# CONFIG_CHELSIO_T1 is not set
449# CONFIG_IXGB is not set 466# CONFIG_IXGB is not set
450# CONFIG_S2IO is not set 467# CONFIG_S2IO is not set
451 468
@@ -547,7 +564,20 @@ CONFIG_LEGACY_PTY_COUNT=256
547# 564#
548# Watchdog Cards 565# Watchdog Cards
549# 566#
550# CONFIG_WATCHDOG is not set 567CONFIG_WATCHDOG=y
568# CONFIG_WATCHDOG_NOWAYOUT is not set
569
570#
571# Watchdog Device Drivers
572#
573# CONFIG_SOFT_WATCHDOG is not set
574CONFIG_MV64X60_WDT=y
575
576#
577# PCI-based Watchdog Cards
578#
579# CONFIG_PCIPCWATCHDOG is not set
580# CONFIG_WDTPCI is not set
551# CONFIG_NVRAM is not set 581# CONFIG_NVRAM is not set
552CONFIG_GEN_RTC=y 582CONFIG_GEN_RTC=y
553# CONFIG_GEN_RTC_X is not set 583# CONFIG_GEN_RTC_X is not set
@@ -571,7 +601,6 @@ CONFIG_GEN_RTC=y
571# I2C support 601# I2C support
572# 602#
573# CONFIG_I2C is not set 603# CONFIG_I2C is not set
574# CONFIG_I2C_SENSOR is not set
575 604
576# 605#
577# Dallas's 1-wire bus 606# Dallas's 1-wire bus
@@ -582,6 +611,7 @@ CONFIG_GEN_RTC=y
582# Hardware Monitoring support 611# Hardware Monitoring support
583# 612#
584CONFIG_HWMON=y 613CONFIG_HWMON=y
614# CONFIG_HWMON_VID is not set
585# CONFIG_HWMON_DEBUG_CHIP is not set 615# CONFIG_HWMON_DEBUG_CHIP is not set
586 616
587# 617#
@@ -589,6 +619,10 @@ CONFIG_HWMON=y
589# 619#
590 620
591# 621#
622# Multimedia Capabilities Port drivers
623#
624
625#
592# Multimedia devices 626# Multimedia devices
593# 627#
594# CONFIG_VIDEO_DEV is not set 628# CONFIG_VIDEO_DEV is not set
@@ -651,10 +685,6 @@ CONFIG_EXT2_FS=y
651# CONFIG_REISERFS_FS is not set 685# CONFIG_REISERFS_FS is not set
652# CONFIG_JFS_FS is not set 686# CONFIG_JFS_FS is not set
653# CONFIG_FS_POSIX_ACL is not set 687# CONFIG_FS_POSIX_ACL is not set
654
655#
656# XFS support
657#
658# CONFIG_XFS_FS is not set 688# CONFIG_XFS_FS is not set
659# CONFIG_MINIX_FS is not set 689# CONFIG_MINIX_FS is not set
660# CONFIG_ROMFS_FS is not set 690# CONFIG_ROMFS_FS is not set
@@ -663,6 +693,7 @@ CONFIG_INOTIFY=y
663CONFIG_DNOTIFY=y 693CONFIG_DNOTIFY=y
664# CONFIG_AUTOFS_FS is not set 694# CONFIG_AUTOFS_FS is not set
665# CONFIG_AUTOFS4_FS is not set 695# CONFIG_AUTOFS4_FS is not set
696# CONFIG_FUSE_FS is not set
666 697
667# 698#
668# CD-ROM/DVD Filesystems 699# CD-ROM/DVD Filesystems
@@ -683,11 +714,10 @@ CONFIG_DNOTIFY=y
683CONFIG_PROC_FS=y 714CONFIG_PROC_FS=y
684CONFIG_PROC_KCORE=y 715CONFIG_PROC_KCORE=y
685CONFIG_SYSFS=y 716CONFIG_SYSFS=y
686# CONFIG_DEVPTS_FS_XATTR is not set
687CONFIG_TMPFS=y 717CONFIG_TMPFS=y
688# CONFIG_TMPFS_XATTR is not set
689# CONFIG_HUGETLB_PAGE is not set 718# CONFIG_HUGETLB_PAGE is not set
690CONFIG_RAMFS=y 719CONFIG_RAMFS=y
720# CONFIG_RELAYFS_FS is not set
691 721
692# 722#
693# Miscellaneous filesystems 723# Miscellaneous filesystems
@@ -735,6 +765,7 @@ CONFIG_SUNRPC=y
735# CONFIG_NCP_FS is not set 765# CONFIG_NCP_FS is not set
736# CONFIG_CODA_FS is not set 766# CONFIG_CODA_FS is not set
737# CONFIG_AFS_FS is not set 767# CONFIG_AFS_FS is not set
768# CONFIG_9P_FS is not set
738 769
739# 770#
740# Partition Types 771# Partition Types
@@ -751,6 +782,7 @@ CONFIG_MSDOS_PARTITION=y
751# Library routines 782# Library routines
752# 783#
753# CONFIG_CRC_CCITT is not set 784# CONFIG_CRC_CCITT is not set
785# CONFIG_CRC16 is not set
754CONFIG_CRC32=y 786CONFIG_CRC32=y
755# CONFIG_LIBCRC32C is not set 787# CONFIG_LIBCRC32C is not set
756CONFIG_ZLIB_INFLATE=y 788CONFIG_ZLIB_INFLATE=y
@@ -767,6 +799,7 @@ CONFIG_ZLIB_DEFLATE=y
767# CONFIG_PRINTK_TIME is not set 799# CONFIG_PRINTK_TIME is not set
768# CONFIG_DEBUG_KERNEL is not set 800# CONFIG_DEBUG_KERNEL is not set
769CONFIG_LOG_BUF_SHIFT=14 801CONFIG_LOG_BUF_SHIFT=14
802# CONFIG_SERIAL_TEXT_DEBUG is not set
770 803
771# 804#
772# Security options 805# Security options
diff --git a/arch/ppc/configs/stx_gp3_defconfig b/arch/ppc/configs/stx_gp3_defconfig
index 66dae8367659..3fedc43e44ad 100644
--- a/arch/ppc/configs/stx_gp3_defconfig
+++ b/arch/ppc/configs/stx_gp3_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.11-rc2 3# Linux kernel version: 2.6.12-rc4
4# Wed Jan 26 14:32:58 2005 4# Tue May 24 18:11:04 2005
5# 5#
6CONFIG_MMU=y 6CONFIG_MMU=y
7CONFIG_GENERIC_HARDIRQS=y 7CONFIG_GENERIC_HARDIRQS=y
@@ -11,6 +11,7 @@ CONFIG_HAVE_DEC_LOCK=y
11CONFIG_PPC=y 11CONFIG_PPC=y
12CONFIG_PPC32=y 12CONFIG_PPC32=y
13CONFIG_GENERIC_NVRAM=y 13CONFIG_GENERIC_NVRAM=y
14CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
14 15
15# 16#
16# Code maturity level options 17# Code maturity level options
@@ -18,6 +19,7 @@ CONFIG_GENERIC_NVRAM=y
18CONFIG_EXPERIMENTAL=y 19CONFIG_EXPERIMENTAL=y
19CONFIG_CLEAN_COMPILE=y 20CONFIG_CLEAN_COMPILE=y
20CONFIG_BROKEN_ON_SMP=y 21CONFIG_BROKEN_ON_SMP=y
22CONFIG_INIT_ENV_ARG_LIMIT=32
21 23
22# 24#
23# General setup 25# General setup
@@ -29,7 +31,6 @@ CONFIG_SYSVIPC=y
29# CONFIG_BSD_PROCESS_ACCT is not set 31# CONFIG_BSD_PROCESS_ACCT is not set
30CONFIG_SYSCTL=y 32CONFIG_SYSCTL=y
31# CONFIG_AUDIT is not set 33# CONFIG_AUDIT is not set
32CONFIG_LOG_BUF_SHIFT=14
33CONFIG_HOTPLUG=y 34CONFIG_HOTPLUG=y
34CONFIG_KOBJECT_UEVENT=y 35CONFIG_KOBJECT_UEVENT=y
35# CONFIG_IKCONFIG is not set 36# CONFIG_IKCONFIG is not set
@@ -37,6 +38,9 @@ CONFIG_EMBEDDED=y
37CONFIG_KALLSYMS=y 38CONFIG_KALLSYMS=y
38# CONFIG_KALLSYMS_ALL is not set 39# CONFIG_KALLSYMS_ALL is not set
39# CONFIG_KALLSYMS_EXTRA_PASS is not set 40# CONFIG_KALLSYMS_EXTRA_PASS is not set
41CONFIG_PRINTK=y
42CONFIG_BUG=y
43CONFIG_BASE_FULL=y
40CONFIG_FUTEX=y 44CONFIG_FUTEX=y
41CONFIG_EPOLL=y 45CONFIG_EPOLL=y
42# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 46# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
@@ -46,6 +50,7 @@ CONFIG_CC_ALIGN_LABELS=0
46CONFIG_CC_ALIGN_LOOPS=0 50CONFIG_CC_ALIGN_LOOPS=0
47CONFIG_CC_ALIGN_JUMPS=0 51CONFIG_CC_ALIGN_JUMPS=0
48# CONFIG_TINY_SHMEM is not set 52# CONFIG_TINY_SHMEM is not set
53CONFIG_BASE_SMALL=0
49 54
50# 55#
51# Loadable module support 56# Loadable module support
@@ -69,9 +74,11 @@ CONFIG_KMOD=y
69CONFIG_E500=y 74CONFIG_E500=y
70CONFIG_BOOKE=y 75CONFIG_BOOKE=y
71CONFIG_FSL_BOOKE=y 76CONFIG_FSL_BOOKE=y
77# CONFIG_PHYS_64BIT is not set
72# CONFIG_SPE is not set 78# CONFIG_SPE is not set
73CONFIG_MATH_EMULATION=y 79CONFIG_MATH_EMULATION=y
74# CONFIG_CPU_FREQ is not set 80# CONFIG_CPU_FREQ is not set
81# CONFIG_PM is not set
75CONFIG_85xx=y 82CONFIG_85xx=y
76CONFIG_PPC_INDIRECT_PCI_BE=y 83CONFIG_PPC_INDIRECT_PCI_BE=y
77 84
@@ -96,6 +103,7 @@ CONFIG_HIGHMEM=y
96CONFIG_BINFMT_ELF=y 103CONFIG_BINFMT_ELF=y
97CONFIG_BINFMT_MISC=m 104CONFIG_BINFMT_MISC=m
98# CONFIG_CMDLINE_BOOL is not set 105# CONFIG_CMDLINE_BOOL is not set
106CONFIG_ISA_DMA_API=y
99 107
100# 108#
101# Bus options 109# Bus options
@@ -104,15 +112,15 @@ CONFIG_PCI=y
104CONFIG_PCI_DOMAINS=y 112CONFIG_PCI_DOMAINS=y
105# CONFIG_PCI_LEGACY_PROC is not set 113# CONFIG_PCI_LEGACY_PROC is not set
106# CONFIG_PCI_NAMES is not set 114# CONFIG_PCI_NAMES is not set
115# CONFIG_PCI_DEBUG is not set
107 116
108# 117#
109# PCCARD (PCMCIA/CardBus) support 118# PCCARD (PCMCIA/CardBus) support
110# 119#
111# CONFIG_PCCARD is not set 120# CONFIG_PCCARD is not set
112 121CONFIG_RAPIDIO=y
113# 122CONFIG_RAPIDIO_8_BIT_TRANSPORT=y
114# PC-card bridges 123CONFIG_RAPIDIO_DISC_TIMEOUT=30
115#
116 124
117# 125#
118# Advanced setup 126# Advanced setup
@@ -152,7 +160,7 @@ CONFIG_PARPORT=m
152CONFIG_PARPORT_PC=m 160CONFIG_PARPORT_PC=m
153# CONFIG_PARPORT_PC_FIFO is not set 161# CONFIG_PARPORT_PC_FIFO is not set
154# CONFIG_PARPORT_PC_SUPERIO is not set 162# CONFIG_PARPORT_PC_SUPERIO is not set
155# CONFIG_PARPORT_OTHER is not set 163# CONFIG_PARPORT_GSC is not set
156# CONFIG_PARPORT_1284 is not set 164# CONFIG_PARPORT_1284 is not set
157 165
158# 166#
@@ -264,7 +272,6 @@ CONFIG_SCSI_CONSTANTS=y
264# CONFIG_SCSI_BUSLOGIC is not set 272# CONFIG_SCSI_BUSLOGIC is not set
265# CONFIG_SCSI_DMX3191D is not set 273# CONFIG_SCSI_DMX3191D is not set
266# CONFIG_SCSI_EATA is not set 274# CONFIG_SCSI_EATA is not set
267# CONFIG_SCSI_EATA_PIO is not set
268# CONFIG_SCSI_FUTURE_DOMAIN is not set 275# CONFIG_SCSI_FUTURE_DOMAIN is not set
269# CONFIG_SCSI_GDTH is not set 276# CONFIG_SCSI_GDTH is not set
270# CONFIG_SCSI_IPS is not set 277# CONFIG_SCSI_IPS is not set
@@ -274,7 +281,6 @@ CONFIG_SCSI_CONSTANTS=y
274# CONFIG_SCSI_IMM is not set 281# CONFIG_SCSI_IMM is not set
275# CONFIG_SCSI_SYM53C8XX_2 is not set 282# CONFIG_SCSI_SYM53C8XX_2 is not set
276# CONFIG_SCSI_IPR is not set 283# CONFIG_SCSI_IPR is not set
277# CONFIG_SCSI_QLOGIC_ISP is not set
278# CONFIG_SCSI_QLOGIC_FC is not set 284# CONFIG_SCSI_QLOGIC_FC is not set
279# CONFIG_SCSI_QLOGIC_1280 is not set 285# CONFIG_SCSI_QLOGIC_1280 is not set
280CONFIG_SCSI_QLA2XXX=m 286CONFIG_SCSI_QLA2XXX=m
@@ -283,6 +289,7 @@ CONFIG_SCSI_QLA2XXX=m
283# CONFIG_SCSI_QLA2300 is not set 289# CONFIG_SCSI_QLA2300 is not set
284# CONFIG_SCSI_QLA2322 is not set 290# CONFIG_SCSI_QLA2322 is not set
285# CONFIG_SCSI_QLA6312 is not set 291# CONFIG_SCSI_QLA6312 is not set
292# CONFIG_SCSI_LPFC is not set
286# CONFIG_SCSI_DC395x is not set 293# CONFIG_SCSI_DC395x is not set
287# CONFIG_SCSI_DC390T is not set 294# CONFIG_SCSI_DC390T is not set
288# CONFIG_SCSI_NSP32 is not set 295# CONFIG_SCSI_NSP32 is not set
@@ -322,7 +329,6 @@ CONFIG_NET=y
322# 329#
323CONFIG_PACKET=y 330CONFIG_PACKET=y
324# CONFIG_PACKET_MMAP is not set 331# CONFIG_PACKET_MMAP is not set
325# CONFIG_NETLINK_DEV is not set
326CONFIG_UNIX=y 332CONFIG_UNIX=y
327# CONFIG_NET_KEY is not set 333# CONFIG_NET_KEY is not set
328CONFIG_INET=y 334CONFIG_INET=y
@@ -431,7 +437,7 @@ CONFIG_IP_NF_NAT_FTP=m
431# 437#
432# Network testing 438# Network testing
433# 439#
434# CONFIG_NET_PKTGEN is not set 440CONFIG_NET_PKTGEN=y
435# CONFIG_NETPOLL is not set 441# CONFIG_NETPOLL is not set
436# CONFIG_NET_POLL_CONTROLLER is not set 442# CONFIG_NET_POLL_CONTROLLER is not set
437# CONFIG_HAMRADIO is not set 443# CONFIG_HAMRADIO is not set
@@ -499,6 +505,7 @@ CONFIG_GFAR_NAPI=y
499# Wan interfaces 505# Wan interfaces
500# 506#
501# CONFIG_WAN is not set 507# CONFIG_WAN is not set
508CONFIG_RIONET=y
502# CONFIG_FDDI is not set 509# CONFIG_FDDI is not set
503# CONFIG_HIPPI is not set 510# CONFIG_HIPPI is not set
504# CONFIG_PLIP is not set 511# CONFIG_PLIP is not set
@@ -536,20 +543,6 @@ CONFIG_INPUT_EVDEV=m
536# CONFIG_INPUT_EVBUG is not set 543# CONFIG_INPUT_EVBUG is not set
537 544
538# 545#
539# Input I/O drivers
540#
541# CONFIG_GAMEPORT is not set
542CONFIG_SOUND_GAMEPORT=y
543CONFIG_SERIO=y
544CONFIG_SERIO_I8042=y
545CONFIG_SERIO_SERPORT=y
546# CONFIG_SERIO_CT82C710 is not set
547# CONFIG_SERIO_PARKBD is not set
548# CONFIG_SERIO_PCIPS2 is not set
549CONFIG_SERIO_LIBPS2=y
550# CONFIG_SERIO_RAW is not set
551
552#
553# Input Device Drivers 546# Input Device Drivers
554# 547#
555CONFIG_INPUT_KEYBOARD=y 548CONFIG_INPUT_KEYBOARD=y
@@ -567,6 +560,19 @@ CONFIG_MOUSE_PS2=y
567# CONFIG_INPUT_MISC is not set 560# CONFIG_INPUT_MISC is not set
568 561
569# 562#
563# Hardware I/O ports
564#
565CONFIG_SERIO=y
566CONFIG_SERIO_I8042=y
567CONFIG_SERIO_SERPORT=y
568# CONFIG_SERIO_PARKBD is not set
569# CONFIG_SERIO_PCIPS2 is not set
570CONFIG_SERIO_LIBPS2=y
571# CONFIG_SERIO_RAW is not set
572# CONFIG_GAMEPORT is not set
573CONFIG_SOUND_GAMEPORT=y
574
575#
570# Character devices 576# Character devices
571# 577#
572# CONFIG_VT is not set 578# CONFIG_VT is not set
@@ -590,6 +596,7 @@ CONFIG_SERIAL_CPM_SCC2=y
590# CONFIG_SERIAL_CPM_SCC4 is not set 596# CONFIG_SERIAL_CPM_SCC4 is not set
591# CONFIG_SERIAL_CPM_SMC1 is not set 597# CONFIG_SERIAL_CPM_SMC1 is not set
592# CONFIG_SERIAL_CPM_SMC2 is not set 598# CONFIG_SERIAL_CPM_SMC2 is not set
599# CONFIG_SERIAL_JSM is not set
593CONFIG_UNIX98_PTYS=y 600CONFIG_UNIX98_PTYS=y
594CONFIG_LEGACY_PTYS=y 601CONFIG_LEGACY_PTYS=y
595CONFIG_LEGACY_PTY_COUNT=256 602CONFIG_LEGACY_PTY_COUNT=256
@@ -626,6 +633,11 @@ CONFIG_DRM=m
626# CONFIG_RAW_DRIVER is not set 633# CONFIG_RAW_DRIVER is not set
627 634
628# 635#
636# TPM devices
637#
638# CONFIG_TCG_TPM is not set
639
640#
629# I2C support 641# I2C support
630# 642#
631CONFIG_I2C=m 643CONFIG_I2C=m
@@ -648,12 +660,12 @@ CONFIG_I2C_ALGOBIT=m
648# CONFIG_I2C_AMD8111 is not set 660# CONFIG_I2C_AMD8111 is not set
649# CONFIG_I2C_I801 is not set 661# CONFIG_I2C_I801 is not set
650# CONFIG_I2C_I810 is not set 662# CONFIG_I2C_I810 is not set
663# CONFIG_I2C_PIIX4 is not set
651# CONFIG_I2C_ISA is not set 664# CONFIG_I2C_ISA is not set
652# CONFIG_I2C_MPC is not set 665# CONFIG_I2C_MPC is not set
653# CONFIG_I2C_NFORCE2 is not set 666# CONFIG_I2C_NFORCE2 is not set
654# CONFIG_I2C_PARPORT is not set 667# CONFIG_I2C_PARPORT is not set
655# CONFIG_I2C_PARPORT_LIGHT is not set 668# CONFIG_I2C_PARPORT_LIGHT is not set
656# CONFIG_I2C_PIIX4 is not set
657# CONFIG_I2C_PROSAVAGE is not set 669# CONFIG_I2C_PROSAVAGE is not set
658# CONFIG_I2C_SAVAGE4 is not set 670# CONFIG_I2C_SAVAGE4 is not set
659# CONFIG_SCx200_ACB is not set 671# CONFIG_SCx200_ACB is not set
@@ -677,7 +689,9 @@ CONFIG_I2C_ALGOBIT=m
677# CONFIG_SENSORS_ASB100 is not set 689# CONFIG_SENSORS_ASB100 is not set
678# CONFIG_SENSORS_DS1621 is not set 690# CONFIG_SENSORS_DS1621 is not set
679# CONFIG_SENSORS_FSCHER is not set 691# CONFIG_SENSORS_FSCHER is not set
692# CONFIG_SENSORS_FSCPOS is not set
680# CONFIG_SENSORS_GL518SM is not set 693# CONFIG_SENSORS_GL518SM is not set
694# CONFIG_SENSORS_GL520SM is not set
681# CONFIG_SENSORS_IT87 is not set 695# CONFIG_SENSORS_IT87 is not set
682# CONFIG_SENSORS_LM63 is not set 696# CONFIG_SENSORS_LM63 is not set
683# CONFIG_SENSORS_LM75 is not set 697# CONFIG_SENSORS_LM75 is not set
@@ -688,9 +702,11 @@ CONFIG_I2C_ALGOBIT=m
688# CONFIG_SENSORS_LM85 is not set 702# CONFIG_SENSORS_LM85 is not set
689# CONFIG_SENSORS_LM87 is not set 703# CONFIG_SENSORS_LM87 is not set
690# CONFIG_SENSORS_LM90 is not set 704# CONFIG_SENSORS_LM90 is not set
705# CONFIG_SENSORS_LM92 is not set
691# CONFIG_SENSORS_MAX1619 is not set 706# CONFIG_SENSORS_MAX1619 is not set
692# CONFIG_SENSORS_PC87360 is not set 707# CONFIG_SENSORS_PC87360 is not set
693# CONFIG_SENSORS_SMSC47B397 is not set 708# CONFIG_SENSORS_SMSC47B397 is not set
709# CONFIG_SENSORS_SIS5595 is not set
694# CONFIG_SENSORS_SMSC47M1 is not set 710# CONFIG_SENSORS_SMSC47M1 is not set
695# CONFIG_SENSORS_VIA686A is not set 711# CONFIG_SENSORS_VIA686A is not set
696# CONFIG_SENSORS_W83781D is not set 712# CONFIG_SENSORS_W83781D is not set
@@ -700,10 +716,12 @@ CONFIG_I2C_ALGOBIT=m
700# 716#
701# Other I2C Chip support 717# Other I2C Chip support
702# 718#
719# CONFIG_SENSORS_DS1337 is not set
703# CONFIG_SENSORS_EEPROM is not set 720# CONFIG_SENSORS_EEPROM is not set
704# CONFIG_SENSORS_PCF8574 is not set 721# CONFIG_SENSORS_PCF8574 is not set
705# CONFIG_SENSORS_PCF8591 is not set 722# CONFIG_SENSORS_PCF8591 is not set
706# CONFIG_SENSORS_RTC8564 is not set 723# CONFIG_SENSORS_RTC8564 is not set
724# CONFIG_SENSORS_M41T00 is not set
707# CONFIG_I2C_DEBUG_CORE is not set 725# CONFIG_I2C_DEBUG_CORE is not set
708# CONFIG_I2C_DEBUG_ALGO is not set 726# CONFIG_I2C_DEBUG_ALGO is not set
709# CONFIG_I2C_DEBUG_BUS is not set 727# CONFIG_I2C_DEBUG_BUS is not set
@@ -732,7 +750,6 @@ CONFIG_I2C_ALGOBIT=m
732# Graphics support 750# Graphics support
733# 751#
734# CONFIG_FB is not set 752# CONFIG_FB is not set
735# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
736 753
737# 754#
738# Sound 755# Sound
@@ -752,13 +769,9 @@ CONFIG_SOUND=m
752# 769#
753# USB support 770# USB support
754# 771#
755# CONFIG_USB is not set
756CONFIG_USB_ARCH_HAS_HCD=y 772CONFIG_USB_ARCH_HAS_HCD=y
757CONFIG_USB_ARCH_HAS_OHCI=y 773CONFIG_USB_ARCH_HAS_OHCI=y
758 774# CONFIG_USB is not set
759#
760# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' may also be needed; see USB_STORAGE Help for more information
761#
762 775
763# 776#
764# USB Gadget Support 777# USB Gadget Support
@@ -789,6 +802,10 @@ CONFIG_JBD_DEBUG=y
789CONFIG_FS_MBCACHE=y 802CONFIG_FS_MBCACHE=y
790# CONFIG_REISERFS_FS is not set 803# CONFIG_REISERFS_FS is not set
791# CONFIG_JFS_FS is not set 804# CONFIG_JFS_FS is not set
805
806#
807# XFS support
808#
792# CONFIG_XFS_FS is not set 809# CONFIG_XFS_FS is not set
793# CONFIG_MINIX_FS is not set 810# CONFIG_MINIX_FS is not set
794# CONFIG_ROMFS_FS is not set 811# CONFIG_ROMFS_FS is not set
@@ -859,7 +876,6 @@ CONFIG_NFS_V3=y
859CONFIG_ROOT_NFS=y 876CONFIG_ROOT_NFS=y
860CONFIG_LOCKD=y 877CONFIG_LOCKD=y
861CONFIG_LOCKD_V4=y 878CONFIG_LOCKD_V4=y
862# CONFIG_EXPORTFS is not set
863CONFIG_SUNRPC=y 879CONFIG_SUNRPC=y
864# CONFIG_RPCSEC_GSS_KRB5 is not set 880# CONFIG_RPCSEC_GSS_KRB5 is not set
865# CONFIG_RPCSEC_GSS_SPKM3 is not set 881# CONFIG_RPCSEC_GSS_SPKM3 is not set
@@ -942,8 +958,10 @@ CONFIG_ZLIB_INFLATE=m
942# 958#
943# Kernel hacking 959# Kernel hacking
944# 960#
961# CONFIG_PRINTK_TIME is not set
945CONFIG_DEBUG_KERNEL=y 962CONFIG_DEBUG_KERNEL=y
946# CONFIG_MAGIC_SYSRQ is not set 963# CONFIG_MAGIC_SYSRQ is not set
964CONFIG_LOG_BUF_SHIFT=14
947# CONFIG_SCHEDSTATS is not set 965# CONFIG_SCHEDSTATS is not set
948# CONFIG_DEBUG_SLAB is not set 966# CONFIG_DEBUG_SLAB is not set
949# CONFIG_DEBUG_SPINLOCK is not set 967# CONFIG_DEBUG_SPINLOCK is not set
diff --git a/arch/ppc/kernel/Makefile b/arch/ppc/kernel/Makefile
index c610ca933a25..76a55a438f23 100644
--- a/arch/ppc/kernel/Makefile
+++ b/arch/ppc/kernel/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_POWER4) += cpu_setup_power4.o
22obj-$(CONFIG_MODULES) += module.o ppc_ksyms.o 22obj-$(CONFIG_MODULES) += module.o ppc_ksyms.o
23obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-mapping.o 23obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-mapping.o
24obj-$(CONFIG_PCI) += pci.o 24obj-$(CONFIG_PCI) += pci.o
25obj-$(CONFIG_RAPIDIO) += rio.o
25obj-$(CONFIG_KGDB) += ppc-stub.o 26obj-$(CONFIG_KGDB) += ppc-stub.o
26obj-$(CONFIG_SMP) += smp.o smp-tbsync.o 27obj-$(CONFIG_SMP) += smp.o smp-tbsync.o
27obj-$(CONFIG_TAU) += temp.o 28obj-$(CONFIG_TAU) += temp.o
diff --git a/arch/ppc/kernel/head_44x.S b/arch/ppc/kernel/head_44x.S
index 8b49679fad54..677c571aa276 100644
--- a/arch/ppc/kernel/head_44x.S
+++ b/arch/ppc/kernel/head_44x.S
@@ -190,8 +190,8 @@ skpinv: addi r4,r4,1 /* Increment */
190 190
191 /* xlat fields */ 191 /* xlat fields */
192 lis r4,UART0_PHYS_IO_BASE@h /* RPN depends on SoC */ 192 lis r4,UART0_PHYS_IO_BASE@h /* RPN depends on SoC */
193#ifndef CONFIG_440EP 193#ifdef UART0_PHYS_ERPN
194 ori r4,r4,0x0001 /* ERPN is 1 for second 4GB page */ 194 ori r4,r4,UART0_PHYS_ERPN /* Add ERPN if above 4GB */
195#endif 195#endif
196 196
197 /* attrib fields */ 197 /* attrib fields */
diff --git a/arch/ppc/kernel/rio.c b/arch/ppc/kernel/rio.c
new file mode 100644
index 000000000000..29487fedfc76
--- /dev/null
+++ b/arch/ppc/kernel/rio.c
@@ -0,0 +1,52 @@
1/*
2 * RapidIO PPC32 support
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/init.h>
14#include <linux/kernel.h>
15#include <linux/rio.h>
16
17#include <asm/rio.h>
18
19/**
20 * platform_rio_init - Do platform specific RIO init
21 *
22 * Any platform specific initialization of RapdIO
23 * hardware is done here as well as registration
24 * of any active master ports in the system.
25 */
26void __attribute__ ((weak))
27 platform_rio_init(void)
28{
29 printk(KERN_WARNING "RIO: No platform_rio_init() present\n");
30}
31
32/**
33 * ppc_rio_init - Do PPC32 RIO init
34 *
35 * Calls platform-specific RIO init code and then calls
36 * rio_init_mports() to initialize any master ports that
37 * have been registered with the RIO subsystem.
38 */
39static int __init ppc_rio_init(void)
40{
41 printk(KERN_INFO "RIO: RapidIO init\n");
42
43 /* Platform specific initialization */
44 platform_rio_init();
45
46 /* Enumerate all registered ports */
47 rio_init_mports();
48
49 return 0;
50}
51
52subsys_initcall(ppc_rio_init);
diff --git a/arch/ppc/platforms/4xx/Kconfig b/arch/ppc/platforms/4xx/Kconfig
index 76f4476cab44..d8837911bbc6 100644
--- a/arch/ppc/platforms/4xx/Kconfig
+++ b/arch/ppc/platforms/4xx/Kconfig
@@ -82,6 +82,12 @@ config LUAN
82 help 82 help
83 This option enables support for the IBM PPC440SP evaluation board. 83 This option enables support for the IBM PPC440SP evaluation board.
84 84
85config YUCCA
86 bool "Yucca"
87 select WANT_EARLY_SERIAL
88 help
89 This option enables support for the AMCC PPC440SPe evaluation board.
90
85config OCOTEA 91config OCOTEA
86 bool "Ocotea" 92 bool "Ocotea"
87 select WANT_EARLY_SERIAL 93 select WANT_EARLY_SERIAL
@@ -124,9 +130,14 @@ config 440SP
124 depends on LUAN 130 depends on LUAN
125 default y 131 default y
126 132
133config 440SPE
134 bool
135 depends on YUCCA
136 default y
137
127config 440 138config 440
128 bool 139 bool
129 depends on 440GP || 440SP || 440EP 140 depends on 440GP || 440SP || 440SPE || 440EP
130 default y 141 default y
131 142
132config 440A 143config 440A
@@ -158,7 +169,7 @@ config BOOKE
158 169
159config IBM_OCP 170config IBM_OCP
160 bool 171 bool
161 depends on ASH || BAMBOO || BUBINGA || CPCI405 || EBONY || EP405 || LUAN || OCOTEA || REDWOOD_5 || REDWOOD_6 || SYCAMORE || WALNUT 172 depends on ASH || BAMBOO || BUBINGA || CPCI405 || EBONY || EP405 || LUAN || YUCCA || OCOTEA || REDWOOD_5 || REDWOOD_6 || SYCAMORE || WALNUT
162 default y 173 default y
163 174
164config XILINX_OCP 175config XILINX_OCP
@@ -168,7 +179,7 @@ config XILINX_OCP
168 179
169config IBM_EMAC4 180config IBM_EMAC4
170 bool 181 bool
171 depends on 440GX || 440SP 182 depends on 440GX || 440SP || 440SPE
172 default y 183 default y
173 184
174config BIOS_FIXUP 185config BIOS_FIXUP
@@ -214,7 +225,7 @@ config EMBEDDEDBOOT
214 225
215config IBM_OPENBIOS 226config IBM_OPENBIOS
216 bool 227 bool
217 depends on ASH || BUBINGA || REDWOOD_5 || REDWOOD_6 || SYCAMORE || WALNUT 228 depends on ASH || REDWOOD_5 || REDWOOD_6
218 default y 229 default y
219 230
220config PPC4xx_DMA 231config PPC4xx_DMA
diff --git a/arch/ppc/platforms/4xx/Makefile b/arch/ppc/platforms/4xx/Makefile
index 1dd6d7fd6a9a..c9bb61170954 100644
--- a/arch/ppc/platforms/4xx/Makefile
+++ b/arch/ppc/platforms/4xx/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_EBONY) += ebony.o
7obj-$(CONFIG_EP405) += ep405.o 7obj-$(CONFIG_EP405) += ep405.o
8obj-$(CONFIG_BUBINGA) += bubinga.o 8obj-$(CONFIG_BUBINGA) += bubinga.o
9obj-$(CONFIG_LUAN) += luan.o 9obj-$(CONFIG_LUAN) += luan.o
10obj-$(CONFIG_YUCCA) += yucca.o
10obj-$(CONFIG_OCOTEA) += ocotea.o 11obj-$(CONFIG_OCOTEA) += ocotea.o
11obj-$(CONFIG_REDWOOD_5) += redwood5.o 12obj-$(CONFIG_REDWOOD_5) += redwood5.o
12obj-$(CONFIG_REDWOOD_6) += redwood6.o 13obj-$(CONFIG_REDWOOD_6) += redwood6.o
@@ -22,6 +23,7 @@ obj-$(CONFIG_440EP) += ibm440ep.o
22obj-$(CONFIG_440GP) += ibm440gp.o 23obj-$(CONFIG_440GP) += ibm440gp.o
23obj-$(CONFIG_440GX) += ibm440gx.o 24obj-$(CONFIG_440GX) += ibm440gx.o
24obj-$(CONFIG_440SP) += ibm440sp.o 25obj-$(CONFIG_440SP) += ibm440sp.o
26obj-$(CONFIG_440SPE) += ppc440spe.o
25obj-$(CONFIG_405EP) += ibm405ep.o 27obj-$(CONFIG_405EP) += ibm405ep.o
26obj-$(CONFIG_405GPR) += ibm405gpr.o 28obj-$(CONFIG_405GPR) += ibm405gpr.o
27obj-$(CONFIG_VIRTEX_II_PRO) += virtex-ii_pro.o 29obj-$(CONFIG_VIRTEX_II_PRO) += virtex-ii_pro.o
diff --git a/arch/ppc/platforms/4xx/bubinga.c b/arch/ppc/platforms/4xx/bubinga.c
index 3678abf86313..8110f55668c5 100644
--- a/arch/ppc/platforms/4xx/bubinga.c
+++ b/arch/ppc/platforms/4xx/bubinga.c
@@ -89,7 +89,7 @@ bubinga_early_serial_map(void)
89 * by 16. 89 * by 16.
90 */ 90 */
91 uart_div = (mfdcr(DCRN_CPC0_UCR_BASE) & DCRN_CPC0_UCR_U0DIV); 91 uart_div = (mfdcr(DCRN_CPC0_UCR_BASE) & DCRN_CPC0_UCR_U0DIV);
92 uart_clock = __res.bi_pllouta_freq / uart_div; 92 uart_clock = __res.bi_procfreq / uart_div;
93 93
94 /* Setup serial port access */ 94 /* Setup serial port access */
95 memset(&port, 0, sizeof(port)); 95 memset(&port, 0, sizeof(port));
diff --git a/arch/ppc/platforms/4xx/bubinga.h b/arch/ppc/platforms/4xx/bubinga.h
index b1df856f8e22..b5380cfaf5c0 100644
--- a/arch/ppc/platforms/4xx/bubinga.h
+++ b/arch/ppc/platforms/4xx/bubinga.h
@@ -1,52 +1,34 @@
1/* 1/*
2 * Support for IBM PPC 405EP evaluation board (Bubinga). 2 * arch/ppc/platforms/4xx/bubinga.h
3 * 3 *
4 * Author: SAW (IBM), derived from walnut.h. 4 * Bubinga board definitions
5 * Maintained by MontaVista Software <source@mvista.com> 5 *
6 * Copyright (c) 2005 DENX Software Engineering
7 * Stefan Roese <sr@denx.de>
8 *
9 * Based on original work by
10 * SAW (IBM)
11 * 2003 (c) MontaVista Softare Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
6 * 17 *
7 * 2003 (c) MontaVista Softare Inc. This file is licensed under the
8 * terms of the GNU General Public License version 2. This program is
9 * licensed "as is" without any warranty of any kind, whether express
10 * or implied.
11 */ 18 */
12 19
13#ifdef __KERNEL__ 20#ifdef __KERNEL__
14#ifndef __BUBINGA_H__ 21#ifndef __BUBINGA_H__
15#define __BUBINGA_H__ 22#define __BUBINGA_H__
16 23
17/* 405EP */ 24#include <linux/config.h>
18#include <platforms/4xx/ibm405ep.h> 25#include <platforms/4xx/ibm405ep.h>
19 26#include <asm/ppcboot.h>
20#ifndef __ASSEMBLY__
21/*
22 * Data structure defining board information maintained by the boot
23 * ROM on IBM's evaluation board. An effort has been made to
24 * keep the field names consistent with the 8xx 'bd_t' board info
25 * structures.
26 */
27
28typedef struct board_info {
29 unsigned char bi_s_version[4]; /* Version of this structure */
30 unsigned char bi_r_version[30]; /* Version of the IBM ROM */
31 unsigned int bi_memsize; /* DRAM installed, in bytes */
32 unsigned char bi_enetaddr[2][6]; /* Local Ethernet MAC address */ unsigned char bi_pci_enetaddr[6]; /* PCI Ethernet MAC address */
33 unsigned int bi_intfreq; /* Processor speed, in Hz */
34 unsigned int bi_busfreq; /* PLB Bus speed, in Hz */
35 unsigned int bi_pci_busfreq; /* PCI Bus speed, in Hz */
36 unsigned int bi_opb_busfreq; /* OPB Bus speed, in Hz */
37 unsigned int bi_pllouta_freq; /* PLL OUTA speed, in Hz */
38} bd_t;
39
40/* Some 4xx parts use a different timebase frequency from the internal clock.
41*/
42#define bi_tbfreq bi_intfreq
43
44 27
45/* Memory map for the Bubinga board. 28/* Memory map for the Bubinga board.
46 * Generic 4xx plus RTC. 29 * Generic 4xx plus RTC.
47 */ 30 */
48 31
49extern void *bubinga_rtc_base;
50#define BUBINGA_RTC_PADDR ((uint)0xf0000000) 32#define BUBINGA_RTC_PADDR ((uint)0xf0000000)
51#define BUBINGA_RTC_VADDR BUBINGA_RTC_PADDR 33#define BUBINGA_RTC_VADDR BUBINGA_RTC_PADDR
52#define BUBINGA_RTC_SIZE ((uint)8*1024) 34#define BUBINGA_RTC_SIZE ((uint)8*1024)
@@ -58,12 +40,18 @@ extern void *bubinga_rtc_base;
58 * for typical configurations at various CPU speeds. 40 * for typical configurations at various CPU speeds.
59 * The base baud is calculated as (FWDA / EXT UART DIV / 16) 41 * The base baud is calculated as (FWDA / EXT UART DIV / 16)
60 */ 42 */
61#define BASE_BAUD 0 43#define BASE_BAUD 0
62 44
63#define BUBINGA_FPGA_BASE 0xF0300000 45/* Flash */
46#define PPC40x_FPGA_BASE 0xF0300000
47#define PPC40x_FPGA_REG_OFFS 1 /* offset to flash map reg */
48#define PPC40x_FLASH_ONBD_N(x) (x & 0x02)
49#define PPC40x_FLASH_SRAM_SEL(x) (x & 0x01)
50#define PPC40x_FLASH_LOW 0xFFF00000
51#define PPC40x_FLASH_HIGH 0xFFF80000
52#define PPC40x_FLASH_SIZE 0x80000
64 53
65#define PPC4xx_MACHINE_NAME "IBM Bubinga" 54#define PPC4xx_MACHINE_NAME "IBM Bubinga"
66 55
67#endif /* !__ASSEMBLY__ */
68#endif /* __BUBINGA_H__ */ 56#endif /* __BUBINGA_H__ */
69#endif /* __KERNEL__ */ 57#endif /* __KERNEL__ */
diff --git a/arch/ppc/platforms/4xx/ebony.h b/arch/ppc/platforms/4xx/ebony.h
index d08faa46a0ae..b91ad4272dfe 100644
--- a/arch/ppc/platforms/4xx/ebony.h
+++ b/arch/ppc/platforms/4xx/ebony.h
@@ -24,8 +24,8 @@
24#define PPC44x_EMAC0_MR0 0xE0000800 24#define PPC44x_EMAC0_MR0 0xE0000800
25 25
26/* Where to find the MAC info */ 26/* Where to find the MAC info */
27#define EBONY_OPENBIOS_MAC_BASE 0xfffffe0c 27#define OPENBIOS_MAC_BASE 0xfffffe0c
28#define EBONY_OPENBIOS_MAC_OFFSET 0x0c 28#define OPENBIOS_MAC_OFFSET 0x0c
29 29
30/* Default clock rates for Rev. B and Rev. C silicon */ 30/* Default clock rates for Rev. B and Rev. C silicon */
31#define EBONY_440GP_RB_SYSCLK 33000000 31#define EBONY_440GP_RB_SYSCLK 33000000
diff --git a/arch/ppc/platforms/4xx/ppc440spe.c b/arch/ppc/platforms/4xx/ppc440spe.c
new file mode 100644
index 000000000000..6139a0b3393e
--- /dev/null
+++ b/arch/ppc/platforms/4xx/ppc440spe.c
@@ -0,0 +1,148 @@
1/*
2 * arch/ppc/platforms/4xx/ppc440spe.c
3 *
4 * PPC440SPe I/O descriptions
5 *
6 * Roland Dreier <rolandd@cisco.com>
7 * Copyright (c) 2005 Cisco Systems. All rights reserved.
8 *
9 * Matt Porter <mporter@kernel.crashing.org>
10 * Copyright 2002-2005 MontaVista Software Inc.
11 *
12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
13 * Copyright (c) 2003, 2004 Zultys Technologies
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2 of the License, or (at your
18 * option) any later version.
19 *
20 */
21#include <linux/init.h>
22#include <linux/module.h>
23#include <platforms/4xx/ppc440spe.h>
24#include <asm/ocp.h>
25#include <asm/ppc4xx_pic.h>
26
27static struct ocp_func_emac_data ppc440spe_emac0_def = {
28 .rgmii_idx = -1, /* No RGMII */
29 .rgmii_mux = -1, /* No RGMII */
30 .zmii_idx = -1, /* No ZMII */
31 .zmii_mux = -1, /* No ZMII */
32 .mal_idx = 0, /* MAL device index */
33 .mal_rx_chan = 0, /* MAL rx channel number */
34 .mal_tx_chan = 0, /* MAL tx channel number */
35 .wol_irq = 61, /* WOL interrupt number */
36 .mdio_idx = -1, /* No shared MDIO */
37 .tah_idx = -1, /* No TAH */
38};
39OCP_SYSFS_EMAC_DATA()
40
41static struct ocp_func_mal_data ppc440spe_mal0_def = {
42 .num_tx_chans = 1, /* Number of TX channels */
43 .num_rx_chans = 1, /* Number of RX channels */
44 .txeob_irq = 38, /* TX End Of Buffer IRQ */
45 .rxeob_irq = 39, /* RX End Of Buffer IRQ */
46 .txde_irq = 34, /* TX Descriptor Error IRQ */
47 .rxde_irq = 35, /* RX Descriptor Error IRQ */
48 .serr_irq = 33, /* MAL System Error IRQ */
49 .dcr_base = DCRN_MAL_BASE /* MAL0_CFG DCR number */
50};
51OCP_SYSFS_MAL_DATA()
52
53static struct ocp_func_iic_data ppc440spe_iic0_def = {
54 .fast_mode = 0, /* Use standad mode (100Khz) */
55};
56
57static struct ocp_func_iic_data ppc440spe_iic1_def = {
58 .fast_mode = 0, /* Use standad mode (100Khz) */
59};
60OCP_SYSFS_IIC_DATA()
61
62struct ocp_def core_ocp[] = {
63 { .vendor = OCP_VENDOR_IBM,
64 .function = OCP_FUNC_16550,
65 .index = 0,
66 .paddr = PPC440SPE_UART0_ADDR,
67 .irq = UART0_INT,
68 .pm = IBM_CPM_UART0,
69 },
70 { .vendor = OCP_VENDOR_IBM,
71 .function = OCP_FUNC_16550,
72 .index = 1,
73 .paddr = PPC440SPE_UART1_ADDR,
74 .irq = UART1_INT,
75 .pm = IBM_CPM_UART1,
76 },
77 { .vendor = OCP_VENDOR_IBM,
78 .function = OCP_FUNC_16550,
79 .index = 2,
80 .paddr = PPC440SPE_UART2_ADDR,
81 .irq = UART2_INT,
82 .pm = IBM_CPM_UART2,
83 },
84 { .vendor = OCP_VENDOR_IBM,
85 .function = OCP_FUNC_IIC,
86 .index = 0,
87 .paddr = 0x00000004f0000400ULL,
88 .irq = 2,
89 .pm = IBM_CPM_IIC0,
90 .additions = &ppc440spe_iic0_def,
91 .show = &ocp_show_iic_data
92 },
93 { .vendor = OCP_VENDOR_IBM,
94 .function = OCP_FUNC_IIC,
95 .index = 1,
96 .paddr = 0x00000004f0000500ULL,
97 .irq = 3,
98 .pm = IBM_CPM_IIC1,
99 .additions = &ppc440spe_iic1_def,
100 .show = &ocp_show_iic_data
101 },
102 { .vendor = OCP_VENDOR_IBM,
103 .function = OCP_FUNC_GPIO,
104 .index = 0,
105 .paddr = 0x00000004f0000700ULL,
106 .irq = OCP_IRQ_NA,
107 .pm = IBM_CPM_GPIO0,
108 },
109 { .vendor = OCP_VENDOR_IBM,
110 .function = OCP_FUNC_MAL,
111 .paddr = OCP_PADDR_NA,
112 .irq = OCP_IRQ_NA,
113 .pm = OCP_CPM_NA,
114 .additions = &ppc440spe_mal0_def,
115 .show = &ocp_show_mal_data,
116 },
117 { .vendor = OCP_VENDOR_IBM,
118 .function = OCP_FUNC_EMAC,
119 .index = 0,
120 .paddr = 0x00000004f0000800ULL,
121 .irq = 60,
122 .pm = OCP_CPM_NA,
123 .additions = &ppc440spe_emac0_def,
124 .show = &ocp_show_emac_data,
125 },
126 { .vendor = OCP_VENDOR_INVALID
127 }
128};
129
130/* Polarity and triggering settings for internal interrupt sources */
131struct ppc4xx_uic_settings ppc4xx_core_uic_cfg[] __initdata = {
132 { .polarity = 0xffffffff,
133 .triggering = 0x010f0004,
134 .ext_irq_mask = 0x00000000,
135 },
136 { .polarity = 0xffffffff,
137 .triggering = 0x001f8040,
138 .ext_irq_mask = 0x00007c30, /* IRQ6 - IRQ7, IRQ8 - IRQ12 */
139 },
140 { .polarity = 0xffffffff,
141 .triggering = 0x00000000,
142 .ext_irq_mask = 0x000000fc, /* IRQ0 - IRQ5 */
143 },
144 { .polarity = 0xffffffff,
145 .triggering = 0x00000000,
146 .ext_irq_mask = 0x00000000,
147 },
148};
diff --git a/arch/ppc/platforms/4xx/ppc440spe.h b/arch/ppc/platforms/4xx/ppc440spe.h
new file mode 100644
index 000000000000..2216846973b8
--- /dev/null
+++ b/arch/ppc/platforms/4xx/ppc440spe.h
@@ -0,0 +1,66 @@
1/*
2 * arch/ppc/platforms/4xx/ibm440spe.h
3 *
4 * PPC440SPe definitions
5 *
6 * Roland Dreier <rolandd@cisco.com>
7 * Copyright (c) 2005 Cisco Systems. All rights reserved.
8 *
9 * Matt Porter <mporter@kernel.crashing.org>
10 * Copyright 2004-2005 MontaVista Software, Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 */
17
18#ifdef __KERNEL__
19#ifndef __PPC_PLATFORMS_PPC440SPE_H
20#define __PPC_PLATFORMS_PPC440SPE_H
21
22#include <linux/config.h>
23
24#include <asm/ibm44x.h>
25
26/* UART */
27#define PPC440SPE_UART0_ADDR 0x00000004f0000200ULL
28#define PPC440SPE_UART1_ADDR 0x00000004f0000300ULL
29#define PPC440SPE_UART2_ADDR 0x00000004f0000600ULL
30#define UART0_INT 0
31#define UART1_INT 1
32#define UART2_INT 37
33
34/* Clock and Power Management */
35#define IBM_CPM_IIC0 0x80000000 /* IIC interface */
36#define IBM_CPM_IIC1 0x40000000 /* IIC interface */
37#define IBM_CPM_PCI 0x20000000 /* PCI bridge */
38#define IBM_CPM_CPU 0x02000000 /* processor core */
39#define IBM_CPM_DMA 0x01000000 /* DMA controller */
40#define IBM_CPM_BGO 0x00800000 /* PLB to OPB bus arbiter */
41#define IBM_CPM_BGI 0x00400000 /* OPB to PLB bridge */
42#define IBM_CPM_EBC 0x00200000 /* External Bux Controller */
43#define IBM_CPM_EBM 0x00100000 /* Ext Bus Master Interface */
44#define IBM_CPM_DMC 0x00080000 /* SDRAM peripheral controller */
45#define IBM_CPM_PLB 0x00040000 /* PLB bus arbiter */
46#define IBM_CPM_SRAM 0x00020000 /* SRAM memory controller */
47#define IBM_CPM_PPM 0x00002000 /* PLB Performance Monitor */
48#define IBM_CPM_UIC1 0x00001000 /* Universal Interrupt Controller */
49#define IBM_CPM_GPIO0 0x00000800 /* General Purpose IO (??) */
50#define IBM_CPM_GPT 0x00000400 /* General Purpose Timers */
51#define IBM_CPM_UART0 0x00000200 /* serial port 0 */
52#define IBM_CPM_UART1 0x00000100 /* serial port 1 */
53#define IBM_CPM_UART2 0x00000100 /* serial port 1 */
54#define IBM_CPM_UIC0 0x00000080 /* Universal Interrupt Controller */
55#define IBM_CPM_TMRCLK 0x00000040 /* CPU timers */
56#define IBM_CPM_EMAC0 0x00000020 /* EMAC 0 */
57
58#define DFLT_IBM4xx_PM ~(IBM_CPM_UIC | IBM_CPM_UIC1 | IBM_CPM_CPU \
59 | IBM_CPM_EBC | IBM_CPM_SRAM | IBM_CPM_BGO \
60 | IBM_CPM_EBM | IBM_CPM_PLB | IBM_CPM_OPB \
61 | IBM_CPM_TMRCLK | IBM_CPM_DMA | IBM_CPM_PCI \
62 | IBM_CPM_TAHOE0 | IBM_CPM_TAHOE1 \
63 | IBM_CPM_EMAC0 | IBM_CPM_EMAC1 \
64 | IBM_CPM_EMAC2 | IBM_CPM_EMAC3 )
65#endif /* __PPC_PLATFORMS_PPC440SP_H */
66#endif /* __KERNEL__ */
diff --git a/arch/ppc/platforms/4xx/sycamore.c b/arch/ppc/platforms/4xx/sycamore.c
index d8019eec4704..281b4a2ffb96 100644
--- a/arch/ppc/platforms/4xx/sycamore.c
+++ b/arch/ppc/platforms/4xx/sycamore.c
@@ -88,9 +88,6 @@ ppc405_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
88void __init 88void __init
89sycamore_setup_arch(void) 89sycamore_setup_arch(void)
90{ 90{
91#define SYCAMORE_PS2_BASE 0xF0100000
92#define SYCAMORE_FPGA_BASE 0xF0300000
93
94 void *fpga_brdc; 91 void *fpga_brdc;
95 unsigned char fpga_brdc_data; 92 unsigned char fpga_brdc_data;
96 void *fpga_enable; 93 void *fpga_enable;
@@ -100,7 +97,7 @@ sycamore_setup_arch(void)
100 97
101 ppc4xx_setup_arch(); 98 ppc4xx_setup_arch();
102 99
103 ibm_ocp_set_emac(0, 1); 100 ibm_ocp_set_emac(0, 0);
104 101
105 kb_data = ioremap(SYCAMORE_PS2_BASE, 8); 102 kb_data = ioremap(SYCAMORE_PS2_BASE, 8);
106 if (!kb_data) { 103 if (!kb_data) {
@@ -111,7 +108,7 @@ sycamore_setup_arch(void)
111 108
112 kb_cs = kb_data + 1; 109 kb_cs = kb_data + 1;
113 110
114 fpga_status = ioremap(SYCAMORE_FPGA_BASE, 8); 111 fpga_status = ioremap(PPC40x_FPGA_BASE, 8);
115 if (!fpga_status) { 112 if (!fpga_status) {
116 printk(KERN_CRIT 113 printk(KERN_CRIT
117 "sycamore_setup_arch() fpga_status ioremap failed\n"); 114 "sycamore_setup_arch() fpga_status ioremap failed\n");
diff --git a/arch/ppc/platforms/4xx/sycamore.h b/arch/ppc/platforms/4xx/sycamore.h
index 3e7b4e2c8c57..1cd6c824fd62 100644
--- a/arch/ppc/platforms/4xx/sycamore.h
+++ b/arch/ppc/platforms/4xx/sycamore.h
@@ -1,67 +1,52 @@
1/* 1/*
2 * arch/ppc/platforms/4xx/sycamore.h 2 * arch/ppc/platforms/4xx/sycamore.h
3 * 3 *
4 * Macros, definitions, and data structures specific to the IBM PowerPC 4 * Sycamore board definitions
5 * 405GPr "Sycamore" evaluation board.
6 * 5 *
7 * Author: Armin Kuster <akuster@mvista.com> 6 * Copyright (c) 2005 DENX Software Engineering
7 * Stefan Roese <sr@denx.de>
8 *
9 * Based on original work by
10 * Armin Kuster <akuster@mvista.com>
11 * 2000 (c) MontaVista, Software, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
8 * 17 *
9 * 2000 (c) MontaVista, Software, Inc. This file is licensed under
10 * the terms of the GNU General Public License version 2. This program
11 * is licensed "as is" without any warranty of any kind, whether express
12 * or implied.
13 */ 18 */
14 19
15#ifdef __KERNEL__ 20#ifdef __KERNEL__
16#ifndef __ASM_SYCAMORE_H__ 21#ifndef __ASM_SYCAMORE_H__
17#define __ASM_SYCAMORE_H__ 22#define __ASM_SYCAMORE_H__
18 23
24#include <linux/config.h>
19#include <platforms/4xx/ibm405gpr.h> 25#include <platforms/4xx/ibm405gpr.h>
26#include <asm/ppcboot.h>
20 27
21#ifndef __ASSEMBLY__ 28/* Memory map for the IBM "Sycamore" 405GPr evaluation board.
22/*
23 * Data structure defining board information maintained by the boot
24 * ROM on IBM's "Sycamore" evaluation board. An effort has been made to
25 * keep the field names consistent with the 8xx 'bd_t' board info
26 * structures.
27 */
28
29typedef struct board_info {
30 unsigned char bi_s_version[4]; /* Version of this structure */
31 unsigned char bi_r_version[30]; /* Version of the IBM ROM */
32 unsigned int bi_memsize; /* DRAM installed, in bytes */
33 unsigned char bi_enetaddr[6]; /* Local Ethernet MAC address */
34 unsigned char bi_pci_enetaddr[6]; /* PCI Ethernet MAC address */
35 unsigned int bi_intfreq; /* Processor speed, in Hz */
36 unsigned int bi_busfreq; /* PLB Bus speed, in Hz */
37 unsigned int bi_pci_busfreq; /* PCI Bus speed, in Hz */
38} bd_t;
39
40/* Some 4xx parts use a different timebase frequency from the internal clock.
41*/
42#define bi_tbfreq bi_intfreq
43
44
45/* Memory map for the IBM "Sycamore" 405GP evaluation board.
46 * Generic 4xx plus RTC. 29 * Generic 4xx plus RTC.
47 */ 30 */
48 31
49extern void *sycamore_rtc_base;
50#define SYCAMORE_RTC_PADDR ((uint)0xf0000000) 32#define SYCAMORE_RTC_PADDR ((uint)0xf0000000)
51#define SYCAMORE_RTC_VADDR SYCAMORE_RTC_PADDR 33#define SYCAMORE_RTC_VADDR SYCAMORE_RTC_PADDR
52#define SYCAMORE_RTC_SIZE ((uint)8*1024) 34#define SYCAMORE_RTC_SIZE ((uint)8*1024)
53 35
54#ifdef CONFIG_PPC405GP_INTERNAL_CLOCK
55#define BASE_BAUD 201600
56#else
57#define BASE_BAUD 691200 36#define BASE_BAUD 691200
58#endif
59 37
60#define SYCAMORE_PS2_BASE 0xF0100000 38#define SYCAMORE_PS2_BASE 0xF0100000
61#define SYCAMORE_FPGA_BASE 0xF0300000 39
40/* Flash */
41#define PPC40x_FPGA_BASE 0xF0300000
42#define PPC40x_FPGA_REG_OFFS 5 /* offset to flash map reg */
43#define PPC40x_FLASH_ONBD_N(x) (x & 0x02)
44#define PPC40x_FLASH_SRAM_SEL(x) (x & 0x01)
45#define PPC40x_FLASH_LOW 0xFFF00000
46#define PPC40x_FLASH_HIGH 0xFFF80000
47#define PPC40x_FLASH_SIZE 0x80000
62 48
63#define PPC4xx_MACHINE_NAME "IBM Sycamore" 49#define PPC4xx_MACHINE_NAME "IBM Sycamore"
64 50
65#endif /* !__ASSEMBLY__ */
66#endif /* __ASM_SYCAMORE_H__ */ 51#endif /* __ASM_SYCAMORE_H__ */
67#endif /* __KERNEL__ */ 52#endif /* __KERNEL__ */
diff --git a/arch/ppc/platforms/4xx/walnut.c b/arch/ppc/platforms/4xx/walnut.c
index a33eda4b7489..74cb33182d9f 100644
--- a/arch/ppc/platforms/4xx/walnut.c
+++ b/arch/ppc/platforms/4xx/walnut.c
@@ -90,7 +90,7 @@ walnut_setup_arch(void)
90 90
91 kb_cs = kb_data + 1; 91 kb_cs = kb_data + 1;
92 92
93 fpga_status = ioremap(WALNUT_FPGA_BASE, 8); 93 fpga_status = ioremap(PPC40x_FPGA_BASE, 8);
94 if (!fpga_status) { 94 if (!fpga_status) {
95 printk(KERN_CRIT 95 printk(KERN_CRIT
96 "walnut_setup_arch() fpga_status ioremap failed\n"); 96 "walnut_setup_arch() fpga_status ioremap failed\n");
diff --git a/arch/ppc/platforms/4xx/walnut.h b/arch/ppc/platforms/4xx/walnut.h
index 04cfbf3696b9..dcf2691698c0 100644
--- a/arch/ppc/platforms/4xx/walnut.h
+++ b/arch/ppc/platforms/4xx/walnut.h
@@ -1,72 +1,55 @@
1/* 1/*
2 * arch/ppc/platforms/4xx/walnut.h 2 * arch/ppc/platforms/4xx/walnut.h
3 * 3 *
4 * Macros, definitions, and data structures specific to the IBM PowerPC 4 * Walnut board definitions
5 * 405GP "Walnut" evaluation board.
6 * 5 *
7 * Authors: Grant Erickson <grant@lcse.umn.edu>, Frank Rowand 6 * Copyright (c) 2005 DENX Software Engineering
8 * <frank_rowand@mvista.com>, Debbie Chu <debbie_chu@mvista.com> or 7 * Stefan Roese <sr@denx.de>
9 * source@mvista.com
10 * 8 *
11 * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu> 9 * Based on original work by
10 * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
11 * Frank Rowand <frank_rowand@mvista.com>
12 * Debbie Chu <debbie_chu@mvista.com>
13 * 2000 (c) MontaVista, Software, Inc.
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2 of the License, or (at your
18 * option) any later version.
12 * 19 *
13 * 2000 (c) MontaVista, Software, Inc. This file is licensed under
14 * the terms of the GNU General Public License version 2. This program
15 * is licensed "as is" without any warranty of any kind, whether express
16 * or implied.
17 */ 20 */
18 21
19#ifdef __KERNEL__ 22#ifdef __KERNEL__
20#ifndef __ASM_WALNUT_H__ 23#ifndef __ASM_WALNUT_H__
21#define __ASM_WALNUT_H__ 24#define __ASM_WALNUT_H__
22 25
23/* We have a 405GP core */ 26#include <linux/config.h>
24#include <platforms/4xx/ibm405gp.h> 27#include <platforms/4xx/ibm405gp.h>
25 28#include <asm/ppcboot.h>
26#ifndef __ASSEMBLY__
27/*
28 * Data structure defining board information maintained by the boot
29 * ROM on IBM's "Walnut" evaluation board. An effort has been made to
30 * keep the field names consistent with the 8xx 'bd_t' board info
31 * structures.
32 */
33
34typedef struct board_info {
35 unsigned char bi_s_version[4]; /* Version of this structure */
36 unsigned char bi_r_version[30]; /* Version of the IBM ROM */
37 unsigned int bi_memsize; /* DRAM installed, in bytes */
38 unsigned char bi_enetaddr[6]; /* Local Ethernet MAC address */
39 unsigned char bi_pci_enetaddr[6]; /* PCI Ethernet MAC address */
40 unsigned int bi_intfreq; /* Processor speed, in Hz */
41 unsigned int bi_busfreq; /* PLB Bus speed, in Hz */
42 unsigned int bi_pci_busfreq; /* PCI Bus speed, in Hz */
43} bd_t;
44
45/* Some 4xx parts use a different timebase frequency from the internal clock.
46*/
47#define bi_tbfreq bi_intfreq
48
49 29
50/* Memory map for the IBM "Walnut" 405GP evaluation board. 30/* Memory map for the IBM "Walnut" 405GP evaluation board.
51 * Generic 4xx plus RTC. 31 * Generic 4xx plus RTC.
52 */ 32 */
53 33
54extern void *walnut_rtc_base;
55#define WALNUT_RTC_PADDR ((uint)0xf0000000) 34#define WALNUT_RTC_PADDR ((uint)0xf0000000)
56#define WALNUT_RTC_VADDR WALNUT_RTC_PADDR 35#define WALNUT_RTC_VADDR WALNUT_RTC_PADDR
57#define WALNUT_RTC_SIZE ((uint)8*1024) 36#define WALNUT_RTC_SIZE ((uint)8*1024)
58 37
59#ifdef CONFIG_PPC405GP_INTERNAL_CLOCK
60#define BASE_BAUD 201600
61#else
62#define BASE_BAUD 691200 38#define BASE_BAUD 691200
63#endif
64 39
65#define WALNUT_PS2_BASE 0xF0100000 40#define WALNUT_PS2_BASE 0xF0100000
66#define WALNUT_FPGA_BASE 0xF0300000 41
42/* Flash */
43#define PPC40x_FPGA_BASE 0xF0300000
44#define PPC40x_FPGA_REG_OFFS 5 /* offset to flash map reg */
45#define PPC40x_FLASH_ONBD_N(x) (x & 0x02)
46#define PPC40x_FLASH_SRAM_SEL(x) (x & 0x01)
47#define PPC40x_FLASH_LOW 0xFFF00000
48#define PPC40x_FLASH_HIGH 0xFFF80000
49#define PPC40x_FLASH_SIZE 0x80000
50#define WALNUT_FPGA_BASE PPC40x_FPGA_BASE
67 51
68#define PPC4xx_MACHINE_NAME "IBM Walnut" 52#define PPC4xx_MACHINE_NAME "IBM Walnut"
69 53
70#endif /* !__ASSEMBLY__ */
71#endif /* __ASM_WALNUT_H__ */ 54#endif /* __ASM_WALNUT_H__ */
72#endif /* __KERNEL__ */ 55#endif /* __KERNEL__ */
diff --git a/arch/ppc/platforms/4xx/yucca.c b/arch/ppc/platforms/4xx/yucca.c
new file mode 100644
index 000000000000..e60f4bd437ec
--- /dev/null
+++ b/arch/ppc/platforms/4xx/yucca.c
@@ -0,0 +1,395 @@
1/*
2 * arch/ppc/platforms/4xx/yucca.c
3 *
4 * Yucca board specific routines
5 *
6 * Roland Dreier <rolandd@cisco.com> (based on luan.c by Matt Porter)
7 *
8 * Copyright 2004-2005 MontaVista Software Inc.
9 * Copyright (c) 2005 Cisco Systems. All rights reserved.
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/config.h>
18#include <linux/stddef.h>
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/errno.h>
22#include <linux/reboot.h>
23#include <linux/pci.h>
24#include <linux/kdev_t.h>
25#include <linux/types.h>
26#include <linux/major.h>
27#include <linux/blkdev.h>
28#include <linux/console.h>
29#include <linux/delay.h>
30#include <linux/ide.h>
31#include <linux/initrd.h>
32#include <linux/seq_file.h>
33#include <linux/root_dev.h>
34#include <linux/tty.h>
35#include <linux/serial.h>
36#include <linux/serial_core.h>
37
38#include <asm/system.h>
39#include <asm/pgtable.h>
40#include <asm/page.h>
41#include <asm/dma.h>
42#include <asm/io.h>
43#include <asm/machdep.h>
44#include <asm/ocp.h>
45#include <asm/pci-bridge.h>
46#include <asm/time.h>
47#include <asm/todc.h>
48#include <asm/bootinfo.h>
49#include <asm/ppc4xx_pic.h>
50#include <asm/ppcboot.h>
51
52#include <syslib/ibm44x_common.h>
53#include <syslib/ibm440gx_common.h>
54#include <syslib/ibm440sp_common.h>
55#include <syslib/ppc440spe_pcie.h>
56
57extern bd_t __res;
58
59static struct ibm44x_clocks clocks __initdata;
60
61static void __init
62yucca_calibrate_decr(void)
63{
64 unsigned int freq;
65
66 if (mfspr(SPRN_CCR1) & CCR1_TCS)
67 freq = YUCCA_TMR_CLK;
68 else
69 freq = clocks.cpu;
70
71 ibm44x_calibrate_decr(freq);
72}
73
74static int
75yucca_show_cpuinfo(struct seq_file *m)
76{
77 seq_printf(m, "vendor\t\t: AMCC\n");
78 seq_printf(m, "machine\t\t: PPC440SPe EVB (Yucca)\n");
79
80 return 0;
81}
82
83static enum {
84 HOSE_UNKNOWN,
85 HOSE_PCIX,
86 HOSE_PCIE0,
87 HOSE_PCIE1,
88 HOSE_PCIE2
89} hose_type[4];
90
91static inline int
92yucca_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
93{
94 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
95
96 if (hose_type[hose->index] == HOSE_PCIX) {
97 static char pci_irq_table[][4] =
98 /*
99 * PCI IDSEL/INTPIN->INTLINE
100 * A B C D
101 */
102 {
103 { 81, -1, -1, -1 }, /* IDSEL 1 - PCIX0 Slot 0 */
104 };
105 const long min_idsel = 1, max_idsel = 1, irqs_per_slot = 4;
106 return PCI_IRQ_TABLE_LOOKUP;
107 } else if (hose_type[hose->index] == HOSE_PCIE0) {
108 static char pci_irq_table[][4] =
109 /*
110 * PCI IDSEL/INTPIN->INTLINE
111 * A B C D
112 */
113 {
114 { 96, 97, 98, 99 },
115 };
116 const long min_idsel = 1, max_idsel = 1, irqs_per_slot = 4;
117 return PCI_IRQ_TABLE_LOOKUP;
118 } else if (hose_type[hose->index] == HOSE_PCIE1) {
119 static char pci_irq_table[][4] =
120 /*
121 * PCI IDSEL/INTPIN->INTLINE
122 * A B C D
123 */
124 {
125 { 100, 101, 102, 103 },
126 };
127 const long min_idsel = 1, max_idsel = 1, irqs_per_slot = 4;
128 return PCI_IRQ_TABLE_LOOKUP;
129 } else if (hose_type[hose->index] == HOSE_PCIE2) {
130 static char pci_irq_table[][4] =
131 /*
132 * PCI IDSEL/INTPIN->INTLINE
133 * A B C D
134 */
135 {
136 { 104, 105, 106, 107 },
137 };
138 const long min_idsel = 1, max_idsel = 1, irqs_per_slot = 4;
139 return PCI_IRQ_TABLE_LOOKUP;
140 }
141 return -1;
142}
143
144static void __init yucca_set_emacdata(void)
145{
146 struct ocp_def *def;
147 struct ocp_func_emac_data *emacdata;
148
149 /* Set phy_map, phy_mode, and mac_addr for the EMAC */
150 def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 0);
151 emacdata = def->additions;
152 emacdata->phy_map = 0x00000001; /* Skip 0x00 */
153 emacdata->phy_mode = PHY_MODE_GMII;
154 memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
155}
156
157static int __init yucca_pcie_card_present(int port)
158{
159 void __iomem *pcie_fpga_base;
160 u16 reg;
161
162 pcie_fpga_base = ioremap64(YUCCA_FPGA_REG_BASE, YUCCA_FPGA_REG_SIZE);
163 reg = in_be16(pcie_fpga_base + FPGA_REG1C);
164 iounmap(pcie_fpga_base);
165
166 switch(port) {
167 case 0: return !(reg & FPGA_REG1C_PE0_PRSNT);
168 case 1: return !(reg & FPGA_REG1C_PE1_PRSNT);
169 case 2: return !(reg & FPGA_REG1C_PE2_PRSNT);
170 default: return 0;
171 }
172}
173
174/*
175 * For the given slot, set rootpoint mode, send power to the slot,
176 * turn on the green LED and turn off the yellow LED, enable the clock
177 * and turn off reset.
178 */
179static void __init yucca_setup_pcie_fpga_rootpoint(int port)
180{
181 void __iomem *pcie_reg_fpga_base;
182 u16 power, clock, green_led, yellow_led, reset_off, rootpoint, endpoint;
183
184 pcie_reg_fpga_base = ioremap64(YUCCA_FPGA_REG_BASE, YUCCA_FPGA_REG_SIZE);
185
186 switch(port) {
187 case 0:
188 rootpoint = FPGA_REG1C_PE0_ROOTPOINT;
189 endpoint = 0;
190 power = FPGA_REG1A_PE0_PWRON;
191 green_led = FPGA_REG1A_PE0_GLED;
192 clock = FPGA_REG1A_PE0_REFCLK_ENABLE;
193 yellow_led = FPGA_REG1A_PE0_YLED;
194 reset_off = FPGA_REG1C_PE0_PERST;
195 break;
196 case 1:
197 rootpoint = 0;
198 endpoint = FPGA_REG1C_PE1_ENDPOINT;
199 power = FPGA_REG1A_PE1_PWRON;
200 green_led = FPGA_REG1A_PE1_GLED;
201 clock = FPGA_REG1A_PE1_REFCLK_ENABLE;
202 yellow_led = FPGA_REG1A_PE1_YLED;
203 reset_off = FPGA_REG1C_PE1_PERST;
204 break;
205 case 2:
206 rootpoint = 0;
207 endpoint = FPGA_REG1C_PE2_ENDPOINT;
208 power = FPGA_REG1A_PE2_PWRON;
209 green_led = FPGA_REG1A_PE2_GLED;
210 clock = FPGA_REG1A_PE2_REFCLK_ENABLE;
211 yellow_led = FPGA_REG1A_PE2_YLED;
212 reset_off = FPGA_REG1C_PE2_PERST;
213 break;
214
215 default:
216 return;
217 }
218
219 out_be16(pcie_reg_fpga_base + FPGA_REG1A,
220 ~(power | clock | green_led) &
221 (yellow_led | in_be16(pcie_reg_fpga_base + FPGA_REG1A)));
222 out_be16(pcie_reg_fpga_base + FPGA_REG1C,
223 ~(endpoint | reset_off) &
224 (rootpoint | in_be16(pcie_reg_fpga_base + FPGA_REG1C)));
225
226 /*
227 * Leave device in reset for a while after powering on the
228 * slot to give it a chance to initialize.
229 */
230 mdelay(250);
231
232 out_be16(pcie_reg_fpga_base + FPGA_REG1C,
233 reset_off | in_be16(pcie_reg_fpga_base + FPGA_REG1C));
234
235 iounmap(pcie_reg_fpga_base);
236}
237
238static void __init
239yucca_setup_hoses(void)
240{
241 struct pci_controller *hose;
242 char name[20];
243 int i;
244
245 if (0 && ppc440spe_init_pcie()) {
246 printk(KERN_WARNING "PPC440SPe PCI Express initialization failed\n");
247 return;
248 }
249
250 for (i = 0; i <= 2; ++i) {
251 if (!yucca_pcie_card_present(i))
252 continue;
253
254 printk(KERN_INFO "PCIE%d: card present\n", i);
255 yucca_setup_pcie_fpga_rootpoint(i);
256 if (ppc440spe_init_pcie_rootport(i)) {
257 printk(KERN_WARNING "PCIE%d: initialization failed\n", i);
258 continue;
259 }
260
261 hose = pcibios_alloc_controller();
262 if (!hose)
263 return;
264
265 sprintf(name, "PCIE%d host bridge", i);
266 pci_init_resource(&hose->io_resource,
267 YUCCA_PCIX_LOWER_IO,
268 YUCCA_PCIX_UPPER_IO,
269 IORESOURCE_IO,
270 name);
271
272 hose->mem_space.start = YUCCA_PCIE_LOWER_MEM +
273 i * YUCCA_PCIE_MEM_SIZE;
274 hose->mem_space.end = hose->mem_space.start +
275 YUCCA_PCIE_MEM_SIZE - 1;
276
277 pci_init_resource(&hose->mem_resources[0],
278 hose->mem_space.start,
279 hose->mem_space.end,
280 IORESOURCE_MEM,
281 name);
282
283 hose->first_busno = 0;
284 hose->last_busno = 15;
285 hose_type[hose->index] = HOSE_PCIE0 + i;
286
287 ppc440spe_setup_pcie(hose, i);
288 hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
289 }
290
291 ppc_md.pci_swizzle = common_swizzle;
292 ppc_md.pci_map_irq = yucca_map_irq;
293}
294
295TODC_ALLOC();
296
297static void __init
298yucca_early_serial_map(void)
299{
300 struct uart_port port;
301
302 /* Setup ioremapped serial port access */
303 memset(&port, 0, sizeof(port));
304 port.membase = ioremap64(PPC440SPE_UART0_ADDR, 8);
305 port.irq = UART0_INT;
306 port.uartclk = clocks.uart0;
307 port.regshift = 0;
308 port.iotype = SERIAL_IO_MEM;
309 port.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
310 port.line = 0;
311
312 if (early_serial_setup(&port) != 0) {
313 printk("Early serial init of port 0 failed\n");
314 }
315
316 port.membase = ioremap64(PPC440SPE_UART1_ADDR, 8);
317 port.irq = UART1_INT;
318 port.uartclk = clocks.uart1;
319 port.line = 1;
320
321 if (early_serial_setup(&port) != 0) {
322 printk("Early serial init of port 1 failed\n");
323 }
324
325 port.membase = ioremap64(PPC440SPE_UART2_ADDR, 8);
326 port.irq = UART2_INT;
327 port.uartclk = BASE_BAUD;
328 port.line = 2;
329
330 if (early_serial_setup(&port) != 0) {
331 printk("Early serial init of port 2 failed\n");
332 }
333}
334
335static void __init
336yucca_setup_arch(void)
337{
338 yucca_set_emacdata();
339
340#if !defined(CONFIG_BDI_SWITCH)
341 /*
342 * The Abatron BDI JTAG debugger does not tolerate others
343 * mucking with the debug registers.
344 */
345 mtspr(SPRN_DBCR0, (DBCR0_TDE | DBCR0_IDM));
346#endif
347
348 /*
349 * Determine various clocks.
350 * To be completely correct we should get SysClk
351 * from FPGA, because it can be changed by on-board switches
352 * --ebs
353 */
354 /* 440GX and 440SPe clocking is the same - rd */
355 ibm440gx_get_clocks(&clocks, 33333333, 6 * 1843200);
356 ocp_sys_info.opb_bus_freq = clocks.opb;
357
358 /* init to some ~sane value until calibrate_delay() runs */
359 loops_per_jiffy = 50000000/HZ;
360
361 /* Setup PCIXn host bridges */
362 yucca_setup_hoses();
363
364#ifdef CONFIG_BLK_DEV_INITRD
365 if (initrd_start)
366 ROOT_DEV = Root_RAM0;
367 else
368#endif
369#ifdef CONFIG_ROOT_NFS
370 ROOT_DEV = Root_NFS;
371#else
372 ROOT_DEV = Root_HDA1;
373#endif
374
375 yucca_early_serial_map();
376
377 /* Identify the system */
378 printk("Yucca port (Roland Dreier <rolandd@cisco.com>)\n");
379}
380
381void __init platform_init(unsigned long r3, unsigned long r4,
382 unsigned long r5, unsigned long r6, unsigned long r7)
383{
384 ibm44x_platform_init(r3, r4, r5, r6, r7);
385
386 ppc_md.setup_arch = yucca_setup_arch;
387 ppc_md.show_cpuinfo = yucca_show_cpuinfo;
388 ppc_md.find_end_of_memory = ibm440sp_find_end_of_memory;
389 ppc_md.get_irq = NULL; /* Set in ppc4xx_pic_init() */
390
391 ppc_md.calibrate_decr = yucca_calibrate_decr;
392#ifdef CONFIG_KGDB
393 ppc_md.early_serial_map = yucca_early_serial_map;
394#endif
395}
diff --git a/arch/ppc/platforms/4xx/yucca.h b/arch/ppc/platforms/4xx/yucca.h
new file mode 100644
index 000000000000..01a4afea1514
--- /dev/null
+++ b/arch/ppc/platforms/4xx/yucca.h
@@ -0,0 +1,111 @@
1/*
2 * arch/ppc/platforms/4xx/yucca.h
3 *
4 * Yucca board definitions
5 *
6 * Roland Dreier <rolandd@cisco.com> (based on luan.h by Matt Porter)
7 *
8 * Copyright 2004-2005 MontaVista Software Inc.
9 * Copyright (c) 2005 Cisco Systems. All rights reserved.
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
18#ifdef __KERNEL__
19#ifndef __ASM_YUCCA_H__
20#define __ASM_YUCCA_H__
21
22#include <linux/config.h>
23#include <platforms/4xx/ppc440spe.h>
24
25/* F/W TLB mapping used in bootloader glue to reset EMAC */
26#define PPC44x_EMAC0_MR0 0xa0000800
27
28/* Location of MAC addresses in PIBS image */
29#define PIBS_FLASH_BASE 0xffe00000
30#define PIBS_MAC_BASE (PIBS_FLASH_BASE+0x1b0400)
31
32/* External timer clock frequency */
33#define YUCCA_TMR_CLK 25000000
34
35/*
36 * FPGA registers
37 */
38#define YUCCA_FPGA_REG_BASE 0x00000004e2000000ULL
39#define YUCCA_FPGA_REG_SIZE 0x24
40
41#define FPGA_REG1A 0x1a
42
43#define FPGA_REG1A_PE0_GLED 0x8000
44#define FPGA_REG1A_PE1_GLED 0x4000
45#define FPGA_REG1A_PE2_GLED 0x2000
46#define FPGA_REG1A_PE0_YLED 0x1000
47#define FPGA_REG1A_PE1_YLED 0x0800
48#define FPGA_REG1A_PE2_YLED 0x0400
49#define FPGA_REG1A_PE0_PWRON 0x0200
50#define FPGA_REG1A_PE1_PWRON 0x0100
51#define FPGA_REG1A_PE2_PWRON 0x0080
52#define FPGA_REG1A_PE0_REFCLK_ENABLE 0x0040
53#define FPGA_REG1A_PE1_REFCLK_ENABLE 0x0020
54#define FPGA_REG1A_PE2_REFCLK_ENABLE 0x0010
55#define FPGA_REG1A_PE_SPREAD0 0x0008
56#define FPGA_REG1A_PE_SPREAD1 0x0004
57#define FPGA_REG1A_PE_SELSOURCE_0 0x0002
58#define FPGA_REG1A_PE_SELSOURCE_1 0x0001
59
60#define FPGA_REG1C 0x1c
61
62#define FPGA_REG1C_PE0_ROOTPOINT 0x8000
63#define FPGA_REG1C_PE1_ENDPOINT 0x4000
64#define FPGA_REG1C_PE2_ENDPOINT 0x2000
65#define FPGA_REG1C_PE0_PRSNT 0x1000
66#define FPGA_REG1C_PE1_PRSNT 0x0800
67#define FPGA_REG1C_PE2_PRSNT 0x0400
68#define FPGA_REG1C_PE0_WAKE 0x0080
69#define FPGA_REG1C_PE1_WAKE 0x0040
70#define FPGA_REG1C_PE2_WAKE 0x0020
71#define FPGA_REG1C_PE0_PERST 0x0010
72#define FPGA_REG1C_PE1_PERST 0x0008
73#define FPGA_REG1C_PE2_PERST 0x0004
74
75/*
76 * Serial port defines
77 */
78#define RS_TABLE_SIZE 3
79
80/* PIBS defined UART mappings, used before early_serial_setup */
81#define UART0_IO_BASE 0xa0000200
82#define UART1_IO_BASE 0xa0000300
83#define UART2_IO_BASE 0xa0000600
84
85#define BASE_BAUD 11059200
86#define STD_UART_OP(num) \
87 { 0, BASE_BAUD, 0, UART##num##_INT, \
88 (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST), \
89 iomem_base: (void*)UART##num##_IO_BASE, \
90 io_type: SERIAL_IO_MEM},
91
92#define SERIAL_PORT_DFNS \
93 STD_UART_OP(0) \
94 STD_UART_OP(1) \
95 STD_UART_OP(2)
96
97/* PCI support */
98#define YUCCA_PCIX_LOWER_IO 0x00000000
99#define YUCCA_PCIX_UPPER_IO 0x0000ffff
100#define YUCCA_PCIX_LOWER_MEM 0x80000000
101#define YUCCA_PCIX_UPPER_MEM 0x8fffffff
102#define YUCCA_PCIE_LOWER_MEM 0x90000000
103#define YUCCA_PCIE_MEM_SIZE 0x10000000
104
105#define YUCCA_PCIX_MEM_SIZE 0x10000000
106#define YUCCA_PCIX_MEM_OFFSET 0x00000000
107#define YUCCA_PCIE_MEM_SIZE 0x10000000
108#define YUCCA_PCIE_MEM_OFFSET 0x00000000
109
110#endif /* __ASM_YUCCA_H__ */
111#endif /* __KERNEL__ */
diff --git a/arch/ppc/platforms/85xx/mpc85xx_ads_common.c b/arch/ppc/platforms/85xx/mpc85xx_ads_common.c
index bd3ac0136756..16ad092d8a06 100644
--- a/arch/ppc/platforms/85xx/mpc85xx_ads_common.c
+++ b/arch/ppc/platforms/85xx/mpc85xx_ads_common.c
@@ -45,6 +45,8 @@
45 45
46#include <mm/mmu_decl.h> 46#include <mm/mmu_decl.h>
47 47
48#include <syslib/ppc85xx_rio.h>
49
48#include <platforms/85xx/mpc85xx_ads_common.h> 50#include <platforms/85xx/mpc85xx_ads_common.h>
49 51
50#ifndef CONFIG_PCI 52#ifndef CONFIG_PCI
@@ -189,3 +191,11 @@ mpc85xx_exclude_device(u_char bus, u_char devfn)
189} 191}
190 192
191#endif /* CONFIG_PCI */ 193#endif /* CONFIG_PCI */
194
195#ifdef CONFIG_RAPIDIO
196void platform_rio_init(void)
197{
198 /* 512MB RIO LAW at 0xc0000000 */
199 mpc85xx_rio_setup(0xc0000000, 0x20000000);
200}
201#endif /* CONFIG_RAPIDIO */
diff --git a/arch/ppc/platforms/85xx/stx_gp3.c b/arch/ppc/platforms/85xx/stx_gp3.c
index 1e1b85f8193a..15ce9d070634 100644
--- a/arch/ppc/platforms/85xx/stx_gp3.c
+++ b/arch/ppc/platforms/85xx/stx_gp3.c
@@ -37,6 +37,7 @@
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/fsl_devices.h> 38#include <linux/fsl_devices.h>
39#include <linux/interrupt.h> 39#include <linux/interrupt.h>
40#include <linux/rio.h>
40 41
41#include <asm/system.h> 42#include <asm/system.h>
42#include <asm/pgtable.h> 43#include <asm/pgtable.h>
@@ -57,6 +58,7 @@
57 58
58#include <syslib/cpm2_pic.h> 59#include <syslib/cpm2_pic.h>
59#include <syslib/ppc85xx_common.h> 60#include <syslib/ppc85xx_common.h>
61#include <syslib/ppc85xx_rio.h>
60 62
61 63
62unsigned char __res[sizeof(bd_t)]; 64unsigned char __res[sizeof(bd_t)];
@@ -273,6 +275,18 @@ int mpc85xx_exclude_device(u_char bus, u_char devfn)
273} 275}
274#endif /* CONFIG_PCI */ 276#endif /* CONFIG_PCI */
275 277
278#ifdef CONFIG_RAPIDIO
279void
280platform_rio_init(void)
281{
282 /*
283 * The STx firmware configures the RapidIO Local Access Window
284 * at 0xc0000000 with a size of 512MB.
285 */
286 mpc85xx_rio_setup(0xc0000000, 0x20000000);
287}
288#endif /* CONFIG_RAPIDIO */
289
276void __init 290void __init
277platform_init(unsigned long r3, unsigned long r4, unsigned long r5, 291platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
278 unsigned long r6, unsigned long r7) 292 unsigned long r6, unsigned long r7)
diff --git a/arch/ppc/platforms/ev64360.c b/arch/ppc/platforms/ev64360.c
index b1324564456e..b9d844f88c2b 100644
--- a/arch/ppc/platforms/ev64360.c
+++ b/arch/ppc/platforms/ev64360.c
@@ -52,6 +52,8 @@ static u32 ev64360_bus_frequency;
52 52
53unsigned char __res[sizeof(bd_t)]; 53unsigned char __res[sizeof(bd_t)];
54 54
55TODC_ALLOC();
56
55static int __init 57static int __init
56ev64360_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin) 58ev64360_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
57{ 59{
@@ -182,6 +184,9 @@ ev64360_setup_peripherals(void)
182 EV64360_RTC_WINDOW_BASE, EV64360_RTC_WINDOW_SIZE, 0); 184 EV64360_RTC_WINDOW_BASE, EV64360_RTC_WINDOW_SIZE, 0);
183 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_1_WIN); 185 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_1_WIN);
184 186
187 TODC_INIT(TODC_TYPE_DS1501, 0, 0,
188 ioremap(EV64360_RTC_WINDOW_BASE, EV64360_RTC_WINDOW_SIZE), 8);
189
185 mv64x60_set_32bit_window(&bh, MV64x60_CPU2SRAM_WIN, 190 mv64x60_set_32bit_window(&bh, MV64x60_CPU2SRAM_WIN,
186 EV64360_INTERNAL_SRAM_BASE, MV64360_SRAM_SIZE, 0); 191 EV64360_INTERNAL_SRAM_BASE, MV64360_SRAM_SIZE, 0);
187 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN); 192 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN);
@@ -496,6 +501,13 @@ platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
496 ppc_md.power_off = ev64360_power_off; 501 ppc_md.power_off = ev64360_power_off;
497 ppc_md.halt = ev64360_halt; 502 ppc_md.halt = ev64360_halt;
498 ppc_md.find_end_of_memory = ev64360_find_end_of_memory; 503 ppc_md.find_end_of_memory = ev64360_find_end_of_memory;
504 ppc_md.init = NULL;
505
506 ppc_md.time_init = todc_time_init;
507 ppc_md.set_rtc_time = todc_set_rtc_time;
508 ppc_md.get_rtc_time = todc_get_rtc_time;
509 ppc_md.nvram_read_val = todc_direct_read_val;
510 ppc_md.nvram_write_val = todc_direct_write_val;
499 ppc_md.calibrate_decr = ev64360_calibrate_decr; 511 ppc_md.calibrate_decr = ev64360_calibrate_decr;
500 512
501#if defined(CONFIG_SERIAL_TEXT_DEBUG) && defined(CONFIG_SERIAL_MPSC_CONSOLE) 513#if defined(CONFIG_SERIAL_TEXT_DEBUG) && defined(CONFIG_SERIAL_MPSC_CONSOLE)
diff --git a/arch/ppc/syslib/Makefile b/arch/ppc/syslib/Makefile
index b4ef15b45c4a..5bd33baac243 100644
--- a/arch/ppc/syslib/Makefile
+++ b/arch/ppc/syslib/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_440EP) += ibm440gx_common.o
15obj-$(CONFIG_440GP) += ibm440gp_common.o 15obj-$(CONFIG_440GP) += ibm440gp_common.o
16obj-$(CONFIG_440GX) += ibm440gx_common.o 16obj-$(CONFIG_440GX) += ibm440gx_common.o
17obj-$(CONFIG_440SP) += ibm440gx_common.o ibm440sp_common.o 17obj-$(CONFIG_440SP) += ibm440gx_common.o ibm440sp_common.o
18obj-$(CONFIG_440SPE) += ibm440gx_common.o ibm440sp_common.o ppc440spe_pcie.o
18ifeq ($(CONFIG_4xx),y) 19ifeq ($(CONFIG_4xx),y)
19ifeq ($(CONFIG_VIRTEX_II_PRO),y) 20ifeq ($(CONFIG_VIRTEX_II_PRO),y)
20obj-$(CONFIG_40x) += xilinx_pic.o 21obj-$(CONFIG_40x) += xilinx_pic.o
@@ -32,6 +33,7 @@ obj-$(CONFIG_PPC4xx_DMA) += ppc4xx_dma.o
32obj-$(CONFIG_PPC4xx_EDMA) += ppc4xx_sgdma.o 33obj-$(CONFIG_PPC4xx_EDMA) += ppc4xx_sgdma.o
33ifeq ($(CONFIG_40x),y) 34ifeq ($(CONFIG_40x),y)
34obj-$(CONFIG_PCI) += pci_auto.o ppc405_pci.o 35obj-$(CONFIG_PCI) += pci_auto.o ppc405_pci.o
36obj-$(CONFIG_RAPIDIO) += ppc85xx_rio.o
35endif 37endif
36endif 38endif
37obj-$(CONFIG_8xx) += m8xx_setup.o ppc8xx_pic.o $(wdt-mpc8xx-y) \ 39obj-$(CONFIG_8xx) += m8xx_setup.o ppc8xx_pic.o $(wdt-mpc8xx-y) \
@@ -46,12 +48,14 @@ obj-$(CONFIG_BAMBOO) += pci_auto.o todc_time.o
46obj-$(CONFIG_CPCI690) += todc_time.o pci_auto.o 48obj-$(CONFIG_CPCI690) += todc_time.o pci_auto.o
47obj-$(CONFIG_EBONY) += pci_auto.o todc_time.o 49obj-$(CONFIG_EBONY) += pci_auto.o todc_time.o
48obj-$(CONFIG_EV64260) += todc_time.o pci_auto.o 50obj-$(CONFIG_EV64260) += todc_time.o pci_auto.o
51obj-$(CONFIG_EV64360) += todc_time.o
49obj-$(CONFIG_CHESTNUT) += mv64360_pic.o pci_auto.o 52obj-$(CONFIG_CHESTNUT) += mv64360_pic.o pci_auto.o
50obj-$(CONFIG_GEMINI) += open_pic.o 53obj-$(CONFIG_GEMINI) += open_pic.o
51obj-$(CONFIG_GT64260) += gt64260_pic.o 54obj-$(CONFIG_GT64260) += gt64260_pic.o
52obj-$(CONFIG_LOPEC) += pci_auto.o todc_time.o 55obj-$(CONFIG_LOPEC) += pci_auto.o todc_time.o
53obj-$(CONFIG_HDPU) += pci_auto.o 56obj-$(CONFIG_HDPU) += pci_auto.o
54obj-$(CONFIG_LUAN) += pci_auto.o todc_time.o 57obj-$(CONFIG_LUAN) += pci_auto.o todc_time.o
58obj-$(CONFIG_YUCCA) += pci_auto.o todc_time.o
55obj-$(CONFIG_KATANA) += pci_auto.o 59obj-$(CONFIG_KATANA) += pci_auto.o
56obj-$(CONFIG_MV64360) += mv64360_pic.o 60obj-$(CONFIG_MV64360) += mv64360_pic.o
57obj-$(CONFIG_MV64X60) += mv64x60.o mv64x60_win.o 61obj-$(CONFIG_MV64X60) += mv64x60.o mv64x60_win.o
diff --git a/arch/ppc/syslib/ibm440sp_common.c b/arch/ppc/syslib/ibm440sp_common.c
index 417d4cff77a0..cdafda127d81 100644
--- a/arch/ppc/syslib/ibm440sp_common.c
+++ b/arch/ppc/syslib/ibm440sp_common.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * arch/ppc/syslib/ibm440sp_common.c 2 * arch/ppc/syslib/ibm440sp_common.c
3 * 3 *
4 * PPC440SP system library 4 * PPC440SP/PPC440SPe system library
5 * 5 *
6 * Matt Porter <mporter@kernel.crashing.org> 6 * Matt Porter <mporter@kernel.crashing.org>
7 * Copyright 2002-2005 MontaVista Software Inc. 7 * Copyright 2002-2005 MontaVista Software Inc.
@@ -35,7 +35,7 @@ unsigned long __init ibm440sp_find_end_of_memory(void)
35 u32 mem_size = 0; 35 u32 mem_size = 0;
36 36
37 /* Read two bank sizes and sum */ 37 /* Read two bank sizes and sum */
38 for (i=0; i<2; i++) 38 for (i=0; i< MQ0_NUM_BANKS; i++)
39 switch (mfdcr(DCRN_MQ0_BS0BAS + i) & MQ0_CONFIG_SIZE_MASK) { 39 switch (mfdcr(DCRN_MQ0_BS0BAS + i) & MQ0_CONFIG_SIZE_MASK) {
40 case MQ0_CONFIG_SIZE_8M: 40 case MQ0_CONFIG_SIZE_8M:
41 mem_size += PPC44x_MEM_SIZE_8M; 41 mem_size += PPC44x_MEM_SIZE_8M;
diff --git a/arch/ppc/syslib/ibm44x_common.c b/arch/ppc/syslib/ibm44x_common.c
index 5152c8e41340..71db11d22158 100644
--- a/arch/ppc/syslib/ibm44x_common.c
+++ b/arch/ppc/syslib/ibm44x_common.c
@@ -20,6 +20,7 @@
20#include <linux/types.h> 20#include <linux/types.h>
21#include <linux/serial.h> 21#include <linux/serial.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/initrd.h>
23 24
24#include <asm/ibm44x.h> 25#include <asm/ibm44x.h>
25#include <asm/mmu.h> 26#include <asm/mmu.h>
@@ -214,9 +215,20 @@ void __init ibm44x_platform_init(unsigned long r3, unsigned long r4, unsigned lo
214/* Called from machine_check_exception */ 215/* Called from machine_check_exception */
215void platform_machine_check(struct pt_regs *regs) 216void platform_machine_check(struct pt_regs *regs)
216{ 217{
218#if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
219 printk("PLB0: BEAR=0x%08x%08x ACR= 0x%08x BESR= 0x%08x%08x\n",
220 mfdcr(DCRN_PLB0_BEARH), mfdcr(DCRN_PLB0_BEARL),
221 mfdcr(DCRN_PLB0_ACR), mfdcr(DCRN_PLB0_BESRH),
222 mfdcr(DCRN_PLB0_BESRL));
223 printk("PLB1: BEAR=0x%08x%08x ACR= 0x%08x BESR= 0x%08x%08x\n",
224 mfdcr(DCRN_PLB1_BEARH), mfdcr(DCRN_PLB1_BEARL),
225 mfdcr(DCRN_PLB1_ACR), mfdcr(DCRN_PLB1_BESRH),
226 mfdcr(DCRN_PLB1_BESRL));
227#else
217 printk("PLB0: BEAR=0x%08x%08x ACR= 0x%08x BESR= 0x%08x\n", 228 printk("PLB0: BEAR=0x%08x%08x ACR= 0x%08x BESR= 0x%08x\n",
218 mfdcr(DCRN_PLB0_BEARH), mfdcr(DCRN_PLB0_BEARL), 229 mfdcr(DCRN_PLB0_BEARH), mfdcr(DCRN_PLB0_BEARL),
219 mfdcr(DCRN_PLB0_ACR), mfdcr(DCRN_PLB0_BESR)); 230 mfdcr(DCRN_PLB0_ACR), mfdcr(DCRN_PLB0_BESR));
231#endif
220 printk("POB0: BEAR=0x%08x%08x BESR0=0x%08x BESR1=0x%08x\n", 232 printk("POB0: BEAR=0x%08x%08x BESR0=0x%08x BESR1=0x%08x\n",
221 mfdcr(DCRN_POB0_BEARH), mfdcr(DCRN_POB0_BEARL), 233 mfdcr(DCRN_POB0_BEARH), mfdcr(DCRN_POB0_BEARL),
222 mfdcr(DCRN_POB0_BESR0), mfdcr(DCRN_POB0_BESR1)); 234 mfdcr(DCRN_POB0_BESR0), mfdcr(DCRN_POB0_BESR1));
diff --git a/arch/ppc/syslib/ppc405_pci.c b/arch/ppc/syslib/ppc405_pci.c
index 81c83bf98df4..d6d838b16dac 100644
--- a/arch/ppc/syslib/ppc405_pci.c
+++ b/arch/ppc/syslib/ppc405_pci.c
@@ -89,13 +89,6 @@ ppc4xx_find_bridges(void)
89 isa_mem_base = 0; 89 isa_mem_base = 0;
90 pci_dram_offset = 0; 90 pci_dram_offset = 0;
91 91
92#if (PSR_PCI_ARBIT_EN > 1)
93 /* Check if running in slave mode */
94 if ((mfdcr(DCRN_CHPSR) & PSR_PCI_ARBIT_EN) == 0) {
95 printk("Running as PCI slave, kernel PCI disabled !\n");
96 return;
97 }
98#endif
99 /* Setup PCI32 hose */ 92 /* Setup PCI32 hose */
100 hose_a = pcibios_alloc_controller(); 93 hose_a = pcibios_alloc_controller();
101 if (!hose_a) 94 if (!hose_a)
diff --git a/arch/ppc/syslib/ppc440spe_pcie.c b/arch/ppc/syslib/ppc440spe_pcie.c
new file mode 100644
index 000000000000..1509fc1ddfb6
--- /dev/null
+++ b/arch/ppc/syslib/ppc440spe_pcie.c
@@ -0,0 +1,442 @@
1/*
2 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * Roland Dreier <rolandd@cisco.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#include <linux/config.h>
12#include <linux/kernel.h>
13#include <linux/delay.h>
14#include <linux/pci.h>
15#include <linux/init.h>
16
17#include <asm/reg.h>
18#include <asm/io.h>
19#include <asm/ibm44x.h>
20
21#include "ppc440spe_pcie.h"
22
23static int
24pcie_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
25 int len, u32 *val)
26{
27 struct pci_controller *hose = bus->sysdata;
28
29 if (PCI_SLOT(devfn) != 1)
30 return PCIBIOS_DEVICE_NOT_FOUND;
31
32 offset += devfn << 12;
33
34 /*
35 * Note: the caller has already checked that offset is
36 * suitably aligned and that len is 1, 2 or 4.
37 */
38 switch (len) {
39 case 1:
40 *val = in_8(hose->cfg_data + offset);
41 break;
42 case 2:
43 *val = in_le16(hose->cfg_data + offset);
44 break;
45 default:
46 *val = in_le32(hose->cfg_data + offset);
47 break;
48 }
49
50 if (0) printk("%s: read %x(%d) @ %x\n", __func__, *val, len, offset);
51
52 return PCIBIOS_SUCCESSFUL;
53}
54
55static int
56pcie_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
57 int len, u32 val)
58{
59 struct pci_controller *hose = bus->sysdata;
60
61 if (PCI_SLOT(devfn) != 1)
62 return PCIBIOS_DEVICE_NOT_FOUND;
63
64 offset += devfn << 12;
65
66 switch (len) {
67 case 1:
68 out_8(hose->cfg_data + offset, val);
69 break;
70 case 2:
71 out_le16(hose->cfg_data + offset, val);
72 break;
73 default:
74 out_le32(hose->cfg_data + offset, val);
75 break;
76 }
77 return PCIBIOS_SUCCESSFUL;
78}
79
80static struct pci_ops pcie_pci_ops =
81{
82 .read = pcie_read_config,
83 .write = pcie_write_config
84};
85
86enum {
87 PTYPE_ENDPOINT = 0x0,
88 PTYPE_LEGACY_ENDPOINT = 0x1,
89 PTYPE_ROOT_PORT = 0x4,
90
91 LNKW_X1 = 0x1,
92 LNKW_X4 = 0x4,
93 LNKW_X8 = 0x8
94};
95
96static void check_error(void)
97{
98 u32 valPE0, valPE1, valPE2;
99
100 /* SDR0_PEGPLLLCT1 reset */
101 if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000)) {
102 printk(KERN_INFO "PCIE: SDR0_PEGPLLLCT1 reset error 0x%8x\n", valPE0);
103 }
104
105 valPE0 = SDR_READ(PESDR0_RCSSET);
106 valPE1 = SDR_READ(PESDR1_RCSSET);
107 valPE2 = SDR_READ(PESDR2_RCSSET);
108
109 /* SDR0_PExRCSSET rstgu */
110 if ( !(valPE0 & 0x01000000) ||
111 !(valPE1 & 0x01000000) ||
112 !(valPE2 & 0x01000000)) {
113 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstgu error\n");
114 }
115
116 /* SDR0_PExRCSSET rstdl */
117 if ( !(valPE0 & 0x00010000) ||
118 !(valPE1 & 0x00010000) ||
119 !(valPE2 & 0x00010000)) {
120 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstdl error\n");
121 }
122
123 /* SDR0_PExRCSSET rstpyn */
124 if ( (valPE0 & 0x00001000) ||
125 (valPE1 & 0x00001000) ||
126 (valPE2 & 0x00001000)) {
127 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstpyn error\n");
128 }
129
130 /* SDR0_PExRCSSET hldplb */
131 if ( (valPE0 & 0x10000000) ||
132 (valPE1 & 0x10000000) ||
133 (valPE2 & 0x10000000)) {
134 printk(KERN_INFO "PCIE: SDR0_PExRCSSET hldplb error\n");
135 }
136
137 /* SDR0_PExRCSSET rdy */
138 if ( (valPE0 & 0x00100000) ||
139 (valPE1 & 0x00100000) ||
140 (valPE2 & 0x00100000)) {
141 printk(KERN_INFO "PCIE: SDR0_PExRCSSET rdy error\n");
142 }
143
144 /* SDR0_PExRCSSET shutdown */
145 if ( (valPE0 & 0x00000100) ||
146 (valPE1 & 0x00000100) ||
147 (valPE2 & 0x00000100)) {
148 printk(KERN_INFO "PCIE: SDR0_PExRCSSET shutdown error\n");
149 }
150}
151
152/*
153 * Initialize PCI Express core as described in User Manual section 27.12.1
154 */
155int ppc440spe_init_pcie(void)
156{
157 /* Set PLL clock receiver to LVPECL */
158 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
159
160 check_error();
161
162 printk(KERN_INFO "PCIE initialization OK\n");
163
164 if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000))
165 printk(KERN_INFO "PESDR_PLLCT2 resistance calibration failed (0x%08x)\n",
166 SDR_READ(PESDR0_PLLLCT2));
167
168 /* De-assert reset of PCIe PLL, wait for lock */
169 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
170 udelay(3);
171
172 return 0;
173}
174
175int ppc440spe_init_pcie_rootport(int port)
176{
177 static int core_init;
178 void __iomem *utl_base;
179 u32 val = 0;
180 int i;
181
182 if (!core_init) {
183 ++core_init;
184 i = ppc440spe_init_pcie();
185 if (i)
186 return i;
187 }
188
189 /*
190 * Initialize various parts of the PCI Express core for our port:
191 *
192 * - Set as a root port and enable max width
193 * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
194 * - Set up UTL configuration.
195 * - Increase SERDES drive strength to levels suggested by AMCC.
196 * - De-assert RSTPYN, RSTDL and RSTGU.
197 */
198 switch (port) {
199 case 0:
200 SDR_WRITE(PESDR0_DLPSET, PTYPE_ROOT_PORT << 20 | LNKW_X8 << 12);
201
202 SDR_WRITE(PESDR0_UTLSET1, 0x21222222);
203 SDR_WRITE(PESDR0_UTLSET2, 0x11000000);
204
205 SDR_WRITE(PESDR0_HSSL0SET1, 0x35000000);
206 SDR_WRITE(PESDR0_HSSL1SET1, 0x35000000);
207 SDR_WRITE(PESDR0_HSSL2SET1, 0x35000000);
208 SDR_WRITE(PESDR0_HSSL3SET1, 0x35000000);
209 SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
210 SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
211 SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
212 SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
213
214 SDR_WRITE(PESDR0_RCSSET,
215 (SDR_READ(PESDR0_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
216 break;
217
218 case 1:
219 SDR_WRITE(PESDR1_DLPSET, PTYPE_ROOT_PORT << 20 | LNKW_X4 << 12);
220
221 SDR_WRITE(PESDR1_UTLSET1, 0x21222222);
222 SDR_WRITE(PESDR1_UTLSET2, 0x11000000);
223
224 SDR_WRITE(PESDR1_HSSL0SET1, 0x35000000);
225 SDR_WRITE(PESDR1_HSSL1SET1, 0x35000000);
226 SDR_WRITE(PESDR1_HSSL2SET1, 0x35000000);
227 SDR_WRITE(PESDR1_HSSL3SET1, 0x35000000);
228
229 SDR_WRITE(PESDR1_RCSSET,
230 (SDR_READ(PESDR1_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
231 break;
232
233 case 2:
234 SDR_WRITE(PESDR2_DLPSET, PTYPE_ROOT_PORT << 20 | LNKW_X4 << 12);
235
236 SDR_WRITE(PESDR2_UTLSET1, 0x21222222);
237 SDR_WRITE(PESDR2_UTLSET2, 0x11000000);
238
239 SDR_WRITE(PESDR2_HSSL0SET1, 0x35000000);
240 SDR_WRITE(PESDR2_HSSL1SET1, 0x35000000);
241 SDR_WRITE(PESDR2_HSSL2SET1, 0x35000000);
242 SDR_WRITE(PESDR2_HSSL3SET1, 0x35000000);
243
244 SDR_WRITE(PESDR2_RCSSET,
245 (SDR_READ(PESDR2_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
246 break;
247 }
248
249 mdelay(1000);
250
251 switch (port) {
252 case 0: val = SDR_READ(PESDR0_RCSSTS); break;
253 case 1: val = SDR_READ(PESDR1_RCSSTS); break;
254 case 2: val = SDR_READ(PESDR2_RCSSTS); break;
255 }
256
257 if (!(val & (1 << 20)))
258 printk(KERN_INFO "PCIE%d: PGRST inactive\n", port);
259 else
260 printk(KERN_WARNING "PGRST for PCIE%d failed %08x\n", port, val);
261
262 switch (port) {
263 case 0: printk(KERN_INFO "PCIE0: LOOP %08x\n", SDR_READ(PESDR0_LOOP)); break;
264 case 1: printk(KERN_INFO "PCIE1: LOOP %08x\n", SDR_READ(PESDR1_LOOP)); break;
265 case 2: printk(KERN_INFO "PCIE2: LOOP %08x\n", SDR_READ(PESDR2_LOOP)); break;
266 }
267
268 /*
269 * Map UTL registers at 0xc_1000_0n00
270 */
271 switch (port) {
272 case 0:
273 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
274 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x10000000);
275 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
276 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
277 break;
278
279 case 1:
280 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
281 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x10001000);
282 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
283 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
284 break;
285
286 case 2:
287 mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
288 mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x10002000);
289 mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
290 mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
291 }
292
293 utl_base = ioremap64(0xc10000000ull + 0x1000 * port, 0x100);
294
295 /*
296 * Set buffer allocations and then assert VRB and TXE.
297 */
298 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
299 out_be32(utl_base + PEUTL_INTR, 0x02000000);
300 out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
301 out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
302 out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
303 out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
304 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
305 out_be32(utl_base + PEUTL_PCTL, 0x80800066);
306
307 iounmap(utl_base);
308
309 /*
310 * We map PCI Express configuration access into the 512MB regions
311 * PCIE0: 0xc_4000_0000
312 * PCIE1: 0xc_8000_0000
313 * PCIE2: 0xc_c000_0000
314 */
315 switch (port) {
316 case 0:
317 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000c);
318 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x40000000);
319 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
320 break;
321
322 case 1:
323 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000c);
324 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x80000000);
325 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
326 break;
327
328 case 2:
329 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000c);
330 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0xc0000000);
331 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
332 break;
333 }
334
335 /*
336 * Check for VC0 active and assert RDY.
337 */
338 switch (port) {
339 case 0:
340 if (!(SDR_READ(PESDR0_RCSSTS) & (1 << 16)))
341 printk(KERN_WARNING "PCIE0: VC0 not active\n");
342 SDR_WRITE(PESDR0_RCSSET, SDR_READ(PESDR0_RCSSET) | 1 << 20);
343 break;
344 case 1:
345 if (!(SDR_READ(PESDR1_RCSSTS) & (1 << 16)))
346 printk(KERN_WARNING "PCIE0: VC0 not active\n");
347 SDR_WRITE(PESDR1_RCSSET, SDR_READ(PESDR1_RCSSET) | 1 << 20);
348 break;
349 case 2:
350 if (!(SDR_READ(PESDR2_RCSSTS) & (1 << 16)))
351 printk(KERN_WARNING "PCIE0: VC0 not active\n");
352 SDR_WRITE(PESDR2_RCSSET, SDR_READ(PESDR2_RCSSET) | 1 << 20);
353 break;
354 }
355
356#if 0
357 /* Dump all config regs */
358 for (i = 0x300; i <= 0x320; ++i)
359 printk("[%04x] 0x%08x\n", i, SDR_READ(i));
360 for (i = 0x340; i <= 0x353; ++i)
361 printk("[%04x] 0x%08x\n", i, SDR_READ(i));
362 for (i = 0x370; i <= 0x383; ++i)
363 printk("[%04x] 0x%08x\n", i, SDR_READ(i));
364 for (i = 0x3a0; i <= 0x3a2; ++i)
365 printk("[%04x] 0x%08x\n", i, SDR_READ(i));
366 for (i = 0x3c0; i <= 0x3c3; ++i)
367 printk("[%04x] 0x%08x\n", i, SDR_READ(i));
368#endif
369
370 mdelay(100);
371
372 return 0;
373}
374
375void ppc440spe_setup_pcie(struct pci_controller *hose, int port)
376{
377 void __iomem *mbase;
378
379 /*
380 * Map 16MB, which is enough for 4 bits of bus #
381 */
382 hose->cfg_data = ioremap64(0xc40000000ull + port * 0x40000000,
383 1 << 24);
384 hose->ops = &pcie_pci_ops;
385
386 /*
387 * Set bus numbers on our root port
388 */
389 mbase = ioremap64(0xc50000000ull + port * 0x40000000, 4096);
390 out_8(mbase + PCI_PRIMARY_BUS, 0);
391 out_8(mbase + PCI_SECONDARY_BUS, 0);
392
393 /*
394 * Set up outbound translation to hose->mem_space from PLB
395 * addresses at an offset of 0xd_0000_0000. We set the low
396 * bits of the mask to 11 to turn off splitting into 8
397 * subregions and to enable the outbound translation.
398 */
399 out_le32(mbase + PECFG_POM0LAH, 0);
400 out_le32(mbase + PECFG_POM0LAL, hose->mem_space.start);
401
402 switch (port) {
403 case 0:
404 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), 0x0000000d);
405 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), hose->mem_space.start);
406 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
407 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
408 ~(hose->mem_space.end - hose->mem_space.start) | 3);
409 break;
410 case 1:
411 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), 0x0000000d);
412 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), hose->mem_space.start);
413 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
414 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
415 ~(hose->mem_space.end - hose->mem_space.start) | 3);
416
417 break;
418 case 2:
419 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), 0x0000000d);
420 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), hose->mem_space.start);
421 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
422 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
423 ~(hose->mem_space.end - hose->mem_space.start) | 3);
424 break;
425 }
426
427 /* Set up 16GB inbound memory window at 0 */
428 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
429 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
430 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
431 out_le32(mbase + PECFG_BAR0LMPA, 0);
432 out_le32(mbase + PECFG_PIM0LAL, 0);
433 out_le32(mbase + PECFG_PIM0LAH, 0);
434 out_le32(mbase + PECFG_PIMEN, 0x1);
435
436 /* Enable I/O, Mem, and Busmaster cycles */
437 out_le16(mbase + PCI_COMMAND,
438 in_le16(mbase + PCI_COMMAND) |
439 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
440
441 iounmap(mbase);
442}
diff --git a/arch/ppc/syslib/ppc440spe_pcie.h b/arch/ppc/syslib/ppc440spe_pcie.h
new file mode 100644
index 000000000000..55b765ad3272
--- /dev/null
+++ b/arch/ppc/syslib/ppc440spe_pcie.h
@@ -0,0 +1,149 @@
1/*
2 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * Roland Dreier <rolandd@cisco.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#ifndef __PPC_SYSLIB_PPC440SPE_PCIE_H
12#define __PPC_SYSLIB_PPC440SPE_PCIE_H
13
14#define DCRN_SDR0_CFGADDR 0x00e
15#define DCRN_SDR0_CFGDATA 0x00f
16
17#define DCRN_PCIE0_BASE 0x100
18#define DCRN_PCIE1_BASE 0x120
19#define DCRN_PCIE2_BASE 0x140
20#define PCIE0 DCRN_PCIE0_BASE
21#define PCIE1 DCRN_PCIE1_BASE
22#define PCIE2 DCRN_PCIE2_BASE
23
24#define DCRN_PEGPL_CFGBAH(base) (base + 0x00)
25#define DCRN_PEGPL_CFGBAL(base) (base + 0x01)
26#define DCRN_PEGPL_CFGMSK(base) (base + 0x02)
27#define DCRN_PEGPL_MSGBAH(base) (base + 0x03)
28#define DCRN_PEGPL_MSGBAL(base) (base + 0x04)
29#define DCRN_PEGPL_MSGMSK(base) (base + 0x05)
30#define DCRN_PEGPL_OMR1BAH(base) (base + 0x06)
31#define DCRN_PEGPL_OMR1BAL(base) (base + 0x07)
32#define DCRN_PEGPL_OMR1MSKH(base) (base + 0x08)
33#define DCRN_PEGPL_OMR1MSKL(base) (base + 0x09)
34#define DCRN_PEGPL_REGBAH(base) (base + 0x12)
35#define DCRN_PEGPL_REGBAL(base) (base + 0x13)
36#define DCRN_PEGPL_REGMSK(base) (base + 0x14)
37#define DCRN_PEGPL_SPECIAL(base) (base + 0x15)
38
39/*
40 * System DCRs (SDRs)
41 */
42#define PESDR0_PLLLCT1 0x03a0
43#define PESDR0_PLLLCT2 0x03a1
44#define PESDR0_PLLLCT3 0x03a2
45
46#define PESDR0_UTLSET1 0x0300
47#define PESDR0_UTLSET2 0x0301
48#define PESDR0_DLPSET 0x0302
49#define PESDR0_LOOP 0x0303
50#define PESDR0_RCSSET 0x0304
51#define PESDR0_RCSSTS 0x0305
52#define PESDR0_HSSL0SET1 0x0306
53#define PESDR0_HSSL0SET2 0x0307
54#define PESDR0_HSSL0STS 0x0308
55#define PESDR0_HSSL1SET1 0x0309
56#define PESDR0_HSSL1SET2 0x030a
57#define PESDR0_HSSL1STS 0x030b
58#define PESDR0_HSSL2SET1 0x030c
59#define PESDR0_HSSL2SET2 0x030d
60#define PESDR0_HSSL2STS 0x030e
61#define PESDR0_HSSL3SET1 0x030f
62#define PESDR0_HSSL3SET2 0x0310
63#define PESDR0_HSSL3STS 0x0311
64#define PESDR0_HSSL4SET1 0x0312
65#define PESDR0_HSSL4SET2 0x0313
66#define PESDR0_HSSL4STS 0x0314
67#define PESDR0_HSSL5SET1 0x0315
68#define PESDR0_HSSL5SET2 0x0316
69#define PESDR0_HSSL5STS 0x0317
70#define PESDR0_HSSL6SET1 0x0318
71#define PESDR0_HSSL6SET2 0x0319
72#define PESDR0_HSSL6STS 0x031a
73#define PESDR0_HSSL7SET1 0x031b
74#define PESDR0_HSSL7SET2 0x031c
75#define PESDR0_HSSL7STS 0x031d
76#define PESDR0_HSSCTLSET 0x031e
77#define PESDR0_LANE_ABCD 0x031f
78#define PESDR0_LANE_EFGH 0x0320
79
80#define PESDR1_UTLSET1 0x0340
81#define PESDR1_UTLSET2 0x0341
82#define PESDR1_DLPSET 0x0342
83#define PESDR1_LOOP 0x0343
84#define PESDR1_RCSSET 0x0344
85#define PESDR1_RCSSTS 0x0345
86#define PESDR1_HSSL0SET1 0x0346
87#define PESDR1_HSSL0SET2 0x0347
88#define PESDR1_HSSL0STS 0x0348
89#define PESDR1_HSSL1SET1 0x0349
90#define PESDR1_HSSL1SET2 0x034a
91#define PESDR1_HSSL1STS 0x034b
92#define PESDR1_HSSL2SET1 0x034c
93#define PESDR1_HSSL2SET2 0x034d
94#define PESDR1_HSSL2STS 0x034e
95#define PESDR1_HSSL3SET1 0x034f
96#define PESDR1_HSSL3SET2 0x0350
97#define PESDR1_HSSL3STS 0x0351
98#define PESDR1_HSSCTLSET 0x0352
99#define PESDR1_LANE_ABCD 0x0353
100
101#define PESDR2_UTLSET1 0x0370
102#define PESDR2_UTLSET2 0x0371
103#define PESDR2_DLPSET 0x0372
104#define PESDR2_LOOP 0x0373
105#define PESDR2_RCSSET 0x0374
106#define PESDR2_RCSSTS 0x0375
107#define PESDR2_HSSL0SET1 0x0376
108#define PESDR2_HSSL0SET2 0x0377
109#define PESDR2_HSSL0STS 0x0378
110#define PESDR2_HSSL1SET1 0x0379
111#define PESDR2_HSSL1SET2 0x037a
112#define PESDR2_HSSL1STS 0x037b
113#define PESDR2_HSSL2SET1 0x037c
114#define PESDR2_HSSL2SET2 0x037d
115#define PESDR2_HSSL2STS 0x037e
116#define PESDR2_HSSL3SET1 0x037f
117#define PESDR2_HSSL3SET2 0x0380
118#define PESDR2_HSSL3STS 0x0381
119#define PESDR2_HSSCTLSET 0x0382
120#define PESDR2_LANE_ABCD 0x0383
121
122/*
123 * UTL register offsets
124 */
125#define PEUTL_PBBSZ 0x20
126#define PEUTL_OPDBSZ 0x68
127#define PEUTL_IPHBSZ 0x70
128#define PEUTL_IPDBSZ 0x78
129#define PEUTL_OUTTR 0x90
130#define PEUTL_INTR 0x98
131#define PEUTL_PCTL 0xa0
132#define PEUTL_RCIRQEN 0xb8
133
134/*
135 * Config space register offsets
136 */
137#define PECFG_BAR0LMPA 0x210
138#define PECFG_BAR0HMPA 0x214
139#define PECFG_PIMEN 0x33c
140#define PECFG_PIM0LAL 0x340
141#define PECFG_PIM0LAH 0x344
142#define PECFG_POM0LAL 0x380
143#define PECFG_POM0LAH 0x384
144
145int ppc440spe_init_pcie(void);
146int ppc440spe_init_pcie_rootport(int port);
147void ppc440spe_setup_pcie(struct pci_controller *hose, int port);
148
149#endif /* __PPC_SYSLIB_PPC440SPE_PCIE_H */
diff --git a/arch/ppc/syslib/ppc4xx_pic.c b/arch/ppc/syslib/ppc4xx_pic.c
index 0b435633a0d1..aa4165144ec2 100644
--- a/arch/ppc/syslib/ppc4xx_pic.c
+++ b/arch/ppc/syslib/ppc4xx_pic.c
@@ -38,6 +38,7 @@ extern unsigned char ppc4xx_uic_ext_irq_cfg[] __attribute__ ((weak));
38#define IRQ_MASK_UICx(irq) (1 << (31 - ((irq) & 0x1f))) 38#define IRQ_MASK_UICx(irq) (1 << (31 - ((irq) & 0x1f)))
39#define IRQ_MASK_UIC1(irq) IRQ_MASK_UICx(irq) 39#define IRQ_MASK_UIC1(irq) IRQ_MASK_UICx(irq)
40#define IRQ_MASK_UIC2(irq) IRQ_MASK_UICx(irq) 40#define IRQ_MASK_UIC2(irq) IRQ_MASK_UICx(irq)
41#define IRQ_MASK_UIC3(irq) IRQ_MASK_UICx(irq)
41 42
42#define UIC_HANDLERS(n) \ 43#define UIC_HANDLERS(n) \
43static void ppc4xx_uic##n##_enable(unsigned int irq) \ 44static void ppc4xx_uic##n##_enable(unsigned int irq) \
@@ -88,7 +89,38 @@ static void ppc4xx_uic##n##_end(unsigned int irq) \
88 .end = ppc4xx_uic##n##_end, \ 89 .end = ppc4xx_uic##n##_end, \
89} \ 90} \
90 91
91#if NR_UICS == 3 92#if NR_UICS == 4
93#define ACK_UIC0_PARENT
94#define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC);
95#define ACK_UIC2_PARENT mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC2NC);
96#define ACK_UIC3_PARENT mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC3NC);
97UIC_HANDLERS(0);
98UIC_HANDLERS(1);
99UIC_HANDLERS(2);
100UIC_HANDLERS(3);
101
102static int ppc4xx_pic_get_irq(struct pt_regs *regs)
103{
104 u32 uic0 = mfdcr(DCRN_UIC_MSR(UIC0));
105 if (uic0 & UIC0_UIC1NC)
106 return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1)));
107 else if (uic0 & UIC0_UIC2NC)
108 return 96 - ffs(mfdcr(DCRN_UIC_MSR(UIC2)));
109 else if (uic0 & UIC0_UIC3NC)
110 return 128 - ffs(mfdcr(DCRN_UIC_MSR(UIC3)));
111 else
112 return uic0 ? 32 - ffs(uic0) : -1;
113}
114
115static void __init ppc4xx_pic_impl_init(void)
116{
117 /* Enable cascade interrupts in UIC0 */
118 ppc_cached_irq_mask[0] |= UIC0_UIC1NC | UIC0_UIC2NC | UIC0_UIC3NC;
119 mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC | UIC0_UIC2NC | UIC0_UIC3NC);
120 mtdcr(DCRN_UIC_ER(UIC0), ppc_cached_irq_mask[0]);
121}
122
123#elif NR_UICS == 3
92#define ACK_UIC0_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC0NC); 124#define ACK_UIC0_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC0NC);
93#define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC1NC); 125#define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC1NC);
94#define ACK_UIC2_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC2NC); 126#define ACK_UIC2_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC2NC);
@@ -170,6 +202,9 @@ static struct ppc4xx_uic_impl {
170 { .decl = DECLARE_UIC(1), .base = UIC1 }, 202 { .decl = DECLARE_UIC(1), .base = UIC1 },
171#if NR_UICS > 2 203#if NR_UICS > 2
172 { .decl = DECLARE_UIC(2), .base = UIC2 }, 204 { .decl = DECLARE_UIC(2), .base = UIC2 },
205#if NR_UICS > 3
206 { .decl = DECLARE_UIC(3), .base = UIC3 },
207#endif
173#endif 208#endif
174#endif 209#endif
175}; 210};
diff --git a/arch/ppc/syslib/ppc85xx_rio.c b/arch/ppc/syslib/ppc85xx_rio.c
new file mode 100644
index 000000000000..297f3b549177
--- /dev/null
+++ b/arch/ppc/syslib/ppc85xx_rio.c
@@ -0,0 +1,938 @@
1/*
2 * MPC85xx RapidIO support
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/config.h>
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/types.h>
17#include <linux/dma-mapping.h>
18#include <linux/interrupt.h>
19#include <linux/rio.h>
20#include <linux/rio_drv.h>
21
22#include <asm/io.h>
23
24#define RIO_REGS_BASE (CCSRBAR + 0xc0000)
25#define RIO_ATMU_REGS_OFFSET 0x10c00
26#define RIO_MSG_REGS_OFFSET 0x11000
27#define RIO_MAINT_WIN_SIZE 0x400000
28#define RIO_DBELL_WIN_SIZE 0x1000
29
30#define RIO_MSG_OMR_MUI 0x00000002
31#define RIO_MSG_OSR_TE 0x00000080
32#define RIO_MSG_OSR_QOI 0x00000020
33#define RIO_MSG_OSR_QFI 0x00000010
34#define RIO_MSG_OSR_MUB 0x00000004
35#define RIO_MSG_OSR_EOMI 0x00000002
36#define RIO_MSG_OSR_QEI 0x00000001
37
38#define RIO_MSG_IMR_MI 0x00000002
39#define RIO_MSG_ISR_TE 0x00000080
40#define RIO_MSG_ISR_QFI 0x00000010
41#define RIO_MSG_ISR_DIQI 0x00000001
42
43#define RIO_MSG_DESC_SIZE 32
44#define RIO_MSG_BUFFER_SIZE 4096
45#define RIO_MIN_TX_RING_SIZE 2
46#define RIO_MAX_TX_RING_SIZE 2048
47#define RIO_MIN_RX_RING_SIZE 2
48#define RIO_MAX_RX_RING_SIZE 2048
49
50#define DOORBELL_DMR_DI 0x00000002
51#define DOORBELL_DSR_TE 0x00000080
52#define DOORBELL_DSR_QFI 0x00000010
53#define DOORBELL_DSR_DIQI 0x00000001
54#define DOORBELL_TID_OFFSET 0x03
55#define DOORBELL_SID_OFFSET 0x05
56#define DOORBELL_INFO_OFFSET 0x06
57
58#define DOORBELL_MESSAGE_SIZE 0x08
59#define DBELL_SID(x) (*(u8 *)(x + DOORBELL_SID_OFFSET))
60#define DBELL_TID(x) (*(u8 *)(x + DOORBELL_TID_OFFSET))
61#define DBELL_INF(x) (*(u16 *)(x + DOORBELL_INFO_OFFSET))
62
63#define is_power_of_2(x) (((x) & ((x) - 1)) == 0)
64
65struct rio_atmu_regs {
66 u32 rowtar;
67 u32 pad1;
68 u32 rowbar;
69 u32 pad2;
70 u32 rowar;
71 u32 pad3[3];
72};
73
74struct rio_msg_regs {
75 u32 omr;
76 u32 osr;
77 u32 pad1;
78 u32 odqdpar;
79 u32 pad2;
80 u32 osar;
81 u32 odpr;
82 u32 odatr;
83 u32 odcr;
84 u32 pad3;
85 u32 odqepar;
86 u32 pad4[13];
87 u32 imr;
88 u32 isr;
89 u32 pad5;
90 u32 ifqdpar;
91 u32 pad6;
92 u32 ifqepar;
93 u32 pad7[250];
94 u32 dmr;
95 u32 dsr;
96 u32 pad8;
97 u32 dqdpar;
98 u32 pad9;
99 u32 dqepar;
100 u32 pad10[26];
101 u32 pwmr;
102 u32 pwsr;
103 u32 pad11;
104 u32 pwqbar;
105};
106
107struct rio_tx_desc {
108 u32 res1;
109 u32 saddr;
110 u32 dport;
111 u32 dattr;
112 u32 res2;
113 u32 res3;
114 u32 dwcnt;
115 u32 res4;
116};
117
118static u32 regs_win;
119static struct rio_atmu_regs *atmu_regs;
120static struct rio_atmu_regs *maint_atmu_regs;
121static struct rio_atmu_regs *dbell_atmu_regs;
122static u32 dbell_win;
123static u32 maint_win;
124static struct rio_msg_regs *msg_regs;
125
126static struct rio_dbell_ring {
127 void *virt;
128 dma_addr_t phys;
129} dbell_ring;
130
131static struct rio_msg_tx_ring {
132 void *virt;
133 dma_addr_t phys;
134 void *virt_buffer[RIO_MAX_TX_RING_SIZE];
135 dma_addr_t phys_buffer[RIO_MAX_TX_RING_SIZE];
136 int tx_slot;
137 int size;
138 void *dev_id;
139} msg_tx_ring;
140
141static struct rio_msg_rx_ring {
142 void *virt;
143 dma_addr_t phys;
144 void *virt_buffer[RIO_MAX_RX_RING_SIZE];
145 int rx_slot;
146 int size;
147 void *dev_id;
148} msg_rx_ring;
149
150/**
151 * mpc85xx_rio_doorbell_send - Send a MPC85xx doorbell message
152 * @index: ID of RapidIO interface
153 * @destid: Destination ID of target device
154 * @data: 16-bit info field of RapidIO doorbell message
155 *
156 * Sends a MPC85xx doorbell message. Returns %0 on success or
157 * %-EINVAL on failure.
158 */
159static int mpc85xx_rio_doorbell_send(int index, u16 destid, u16 data)
160{
161 pr_debug("mpc85xx_doorbell_send: index %d destid %4.4x data %4.4x\n",
162 index, destid, data);
163 out_be32((void *)&dbell_atmu_regs->rowtar, destid << 22);
164 out_be16((void *)(dbell_win), data);
165
166 return 0;
167}
168
169/**
170 * mpc85xx_local_config_read - Generate a MPC85xx local config space read
171 * @index: ID of RapdiIO interface
172 * @offset: Offset into configuration space
173 * @len: Length (in bytes) of the maintenance transaction
174 * @data: Value to be read into
175 *
176 * Generates a MPC85xx local configuration space read. Returns %0 on
177 * success or %-EINVAL on failure.
178 */
179static int mpc85xx_local_config_read(int index, u32 offset, int len, u32 * data)
180{
181 pr_debug("mpc85xx_local_config_read: index %d offset %8.8x\n", index,
182 offset);
183 *data = in_be32((void *)(regs_win + offset));
184
185 return 0;
186}
187
188/**
189 * mpc85xx_local_config_write - Generate a MPC85xx local config space write
190 * @index: ID of RapdiIO interface
191 * @offset: Offset into configuration space
192 * @len: Length (in bytes) of the maintenance transaction
193 * @data: Value to be written
194 *
195 * Generates a MPC85xx local configuration space write. Returns %0 on
196 * success or %-EINVAL on failure.
197 */
198static int mpc85xx_local_config_write(int index, u32 offset, int len, u32 data)
199{
200 pr_debug
201 ("mpc85xx_local_config_write: index %d offset %8.8x data %8.8x\n",
202 index, offset, data);
203 out_be32((void *)(regs_win + offset), data);
204
205 return 0;
206}
207
208/**
209 * mpc85xx_rio_config_read - Generate a MPC85xx read maintenance transaction
210 * @index: ID of RapdiIO interface
211 * @destid: Destination ID of transaction
212 * @hopcount: Number of hops to target device
213 * @offset: Offset into configuration space
214 * @len: Length (in bytes) of the maintenance transaction
215 * @val: Location to be read into
216 *
217 * Generates a MPC85xx read maintenance transaction. Returns %0 on
218 * success or %-EINVAL on failure.
219 */
220static int
221mpc85xx_rio_config_read(int index, u16 destid, u8 hopcount, u32 offset, int len,
222 u32 * val)
223{
224 u8 *data;
225
226 pr_debug
227 ("mpc85xx_rio_config_read: index %d destid %d hopcount %d offset %8.8x len %d\n",
228 index, destid, hopcount, offset, len);
229 out_be32((void *)&maint_atmu_regs->rowtar,
230 (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9));
231
232 data = (u8 *) maint_win + offset;
233 switch (len) {
234 case 1:
235 *val = in_8((u8 *) data);
236 break;
237 case 2:
238 *val = in_be16((u16 *) data);
239 break;
240 default:
241 *val = in_be32((u32 *) data);
242 break;
243 }
244
245 return 0;
246}
247
248/**
249 * mpc85xx_rio_config_write - Generate a MPC85xx write maintenance transaction
250 * @index: ID of RapdiIO interface
251 * @destid: Destination ID of transaction
252 * @hopcount: Number of hops to target device
253 * @offset: Offset into configuration space
254 * @len: Length (in bytes) of the maintenance transaction
255 * @val: Value to be written
256 *
257 * Generates an MPC85xx write maintenance transaction. Returns %0 on
258 * success or %-EINVAL on failure.
259 */
260static int
261mpc85xx_rio_config_write(int index, u16 destid, u8 hopcount, u32 offset,
262 int len, u32 val)
263{
264 u8 *data;
265 pr_debug
266 ("mpc85xx_rio_config_write: index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n",
267 index, destid, hopcount, offset, len, val);
268 out_be32((void *)&maint_atmu_regs->rowtar,
269 (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9));
270
271 data = (u8 *) maint_win + offset;
272 switch (len) {
273 case 1:
274 out_8((u8 *) data, val);
275 break;
276 case 2:
277 out_be16((u16 *) data, val);
278 break;
279 default:
280 out_be32((u32 *) data, val);
281 break;
282 }
283
284 return 0;
285}
286
287/**
288 * rio_hw_add_outb_message - Add message to the MPC85xx outbound message queue
289 * @mport: Master port with outbound message queue
290 * @rdev: Target of outbound message
291 * @mbox: Outbound mailbox
292 * @buffer: Message to add to outbound queue
293 * @len: Length of message
294 *
295 * Adds the @buffer message to the MPC85xx outbound message queue. Returns
296 * %0 on success or %-EINVAL on failure.
297 */
298int
299rio_hw_add_outb_message(struct rio_mport *mport, struct rio_dev *rdev, int mbox,
300 void *buffer, size_t len)
301{
302 u32 omr;
303 struct rio_tx_desc *desc =
304 (struct rio_tx_desc *)msg_tx_ring.virt + msg_tx_ring.tx_slot;
305 int ret = 0;
306
307 pr_debug
308 ("RIO: rio_hw_add_outb_message(): destid %4.4x mbox %d buffer %8.8x len %8.8x\n",
309 rdev->destid, mbox, (int)buffer, len);
310
311 if ((len < 8) || (len > RIO_MAX_MSG_SIZE)) {
312 ret = -EINVAL;
313 goto out;
314 }
315
316 /* Copy and clear rest of buffer */
317 memcpy(msg_tx_ring.virt_buffer[msg_tx_ring.tx_slot], buffer, len);
318 if (len < (RIO_MAX_MSG_SIZE - 4))
319 memset((void *)((u32) msg_tx_ring.
320 virt_buffer[msg_tx_ring.tx_slot] + len), 0,
321 RIO_MAX_MSG_SIZE - len);
322
323 /* Set mbox field for message */
324 desc->dport = mbox & 0x3;
325
326 /* Enable EOMI interrupt, set priority, and set destid */
327 desc->dattr = 0x28000000 | (rdev->destid << 2);
328
329 /* Set transfer size aligned to next power of 2 (in double words) */
330 desc->dwcnt = is_power_of_2(len) ? len : 1 << get_bitmask_order(len);
331
332 /* Set snooping and source buffer address */
333 desc->saddr = 0x00000004 | msg_tx_ring.phys_buffer[msg_tx_ring.tx_slot];
334
335 /* Increment enqueue pointer */
336 omr = in_be32((void *)&msg_regs->omr);
337 out_be32((void *)&msg_regs->omr, omr | RIO_MSG_OMR_MUI);
338
339 /* Go to next descriptor */
340 if (++msg_tx_ring.tx_slot == msg_tx_ring.size)
341 msg_tx_ring.tx_slot = 0;
342
343 out:
344 return ret;
345}
346
347EXPORT_SYMBOL_GPL(rio_hw_add_outb_message);
348
349/**
350 * mpc85xx_rio_tx_handler - MPC85xx outbound message interrupt handler
351 * @irq: Linux interrupt number
352 * @dev_instance: Pointer to interrupt-specific data
353 * @regs: Register context
354 *
355 * Handles outbound message interrupts. Executes a register outbound
356 * mailbox event handler and acks the interrupt occurence.
357 */
358static irqreturn_t
359mpc85xx_rio_tx_handler(int irq, void *dev_instance, struct pt_regs *regs)
360{
361 int osr;
362 struct rio_mport *port = (struct rio_mport *)dev_instance;
363
364 osr = in_be32((void *)&msg_regs->osr);
365
366 if (osr & RIO_MSG_OSR_TE) {
367 pr_info("RIO: outbound message transmission error\n");
368 out_be32((void *)&msg_regs->osr, RIO_MSG_OSR_TE);
369 goto out;
370 }
371
372 if (osr & RIO_MSG_OSR_QOI) {
373 pr_info("RIO: outbound message queue overflow\n");
374 out_be32((void *)&msg_regs->osr, RIO_MSG_OSR_QOI);
375 goto out;
376 }
377
378 if (osr & RIO_MSG_OSR_EOMI) {
379 u32 dqp = in_be32((void *)&msg_regs->odqdpar);
380 int slot = (dqp - msg_tx_ring.phys) >> 5;
381 port->outb_msg[0].mcback(port, msg_tx_ring.dev_id, -1, slot);
382
383 /* Ack the end-of-message interrupt */
384 out_be32((void *)&msg_regs->osr, RIO_MSG_OSR_EOMI);
385 }
386
387 out:
388 return IRQ_HANDLED;
389}
390
391/**
392 * rio_open_outb_mbox - Initialize MPC85xx outbound mailbox
393 * @mport: Master port implementing the outbound message unit
394 * @dev_id: Device specific pointer to pass on event
395 * @mbox: Mailbox to open
396 * @entries: Number of entries in the outbound mailbox ring
397 *
398 * Initializes buffer ring, request the outbound message interrupt,
399 * and enables the outbound message unit. Returns %0 on success and
400 * %-EINVAL or %-ENOMEM on failure.
401 */
402int rio_open_outb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries)
403{
404 int i, j, rc = 0;
405
406 if ((entries < RIO_MIN_TX_RING_SIZE) ||
407 (entries > RIO_MAX_TX_RING_SIZE) || (!is_power_of_2(entries))) {
408 rc = -EINVAL;
409 goto out;
410 }
411
412 /* Initialize shadow copy ring */
413 msg_tx_ring.dev_id = dev_id;
414 msg_tx_ring.size = entries;
415
416 for (i = 0; i < msg_tx_ring.size; i++) {
417 if (!
418 (msg_tx_ring.virt_buffer[i] =
419 dma_alloc_coherent(NULL, RIO_MSG_BUFFER_SIZE,
420 &msg_tx_ring.phys_buffer[i],
421 GFP_KERNEL))) {
422 rc = -ENOMEM;
423 for (j = 0; j < msg_tx_ring.size; j++)
424 if (msg_tx_ring.virt_buffer[j])
425 dma_free_coherent(NULL,
426 RIO_MSG_BUFFER_SIZE,
427 msg_tx_ring.
428 virt_buffer[j],
429 msg_tx_ring.
430 phys_buffer[j]);
431 goto out;
432 }
433 }
434
435 /* Initialize outbound message descriptor ring */
436 if (!(msg_tx_ring.virt = dma_alloc_coherent(NULL,
437 msg_tx_ring.size *
438 RIO_MSG_DESC_SIZE,
439 &msg_tx_ring.phys,
440 GFP_KERNEL))) {
441 rc = -ENOMEM;
442 goto out_dma;
443 }
444 memset(msg_tx_ring.virt, 0, msg_tx_ring.size * RIO_MSG_DESC_SIZE);
445 msg_tx_ring.tx_slot = 0;
446
447 /* Point dequeue/enqueue pointers at first entry in ring */
448 out_be32((void *)&msg_regs->odqdpar, msg_tx_ring.phys);
449 out_be32((void *)&msg_regs->odqepar, msg_tx_ring.phys);
450
451 /* Configure for snooping */
452 out_be32((void *)&msg_regs->osar, 0x00000004);
453
454 /* Clear interrupt status */
455 out_be32((void *)&msg_regs->osr, 0x000000b3);
456
457 /* Hook up outbound message handler */
458 if ((rc =
459 request_irq(MPC85xx_IRQ_RIO_TX, mpc85xx_rio_tx_handler, 0,
460 "msg_tx", (void *)mport)) < 0)
461 goto out_irq;
462
463 /*
464 * Configure outbound message unit
465 * Snooping
466 * Interrupts (all enabled, except QEIE)
467 * Chaining mode
468 * Disable
469 */
470 out_be32((void *)&msg_regs->omr, 0x00100220);
471
472 /* Set number of entries */
473 out_be32((void *)&msg_regs->omr,
474 in_be32((void *)&msg_regs->omr) |
475 ((get_bitmask_order(entries) - 2) << 12));
476
477 /* Now enable the unit */
478 out_be32((void *)&msg_regs->omr, in_be32((void *)&msg_regs->omr) | 0x1);
479
480 out:
481 return rc;
482
483 out_irq:
484 dma_free_coherent(NULL, msg_tx_ring.size * RIO_MSG_DESC_SIZE,
485 msg_tx_ring.virt, msg_tx_ring.phys);
486
487 out_dma:
488 for (i = 0; i < msg_tx_ring.size; i++)
489 dma_free_coherent(NULL, RIO_MSG_BUFFER_SIZE,
490 msg_tx_ring.virt_buffer[i],
491 msg_tx_ring.phys_buffer[i]);
492
493 return rc;
494}
495
496/**
497 * rio_close_outb_mbox - Shut down MPC85xx outbound mailbox
498 * @mport: Master port implementing the outbound message unit
499 * @mbox: Mailbox to close
500 *
501 * Disables the outbound message unit, free all buffers, and
502 * frees the outbound message interrupt.
503 */
504void rio_close_outb_mbox(struct rio_mport *mport, int mbox)
505{
506 /* Disable inbound message unit */
507 out_be32((void *)&msg_regs->omr, 0);
508
509 /* Free ring */
510 dma_free_coherent(NULL, msg_tx_ring.size * RIO_MSG_DESC_SIZE,
511 msg_tx_ring.virt, msg_tx_ring.phys);
512
513 /* Free interrupt */
514 free_irq(MPC85xx_IRQ_RIO_TX, (void *)mport);
515}
516
517/**
518 * mpc85xx_rio_rx_handler - MPC85xx inbound message interrupt handler
519 * @irq: Linux interrupt number
520 * @dev_instance: Pointer to interrupt-specific data
521 * @regs: Register context
522 *
523 * Handles inbound message interrupts. Executes a registered inbound
524 * mailbox event handler and acks the interrupt occurence.
525 */
526static irqreturn_t
527mpc85xx_rio_rx_handler(int irq, void *dev_instance, struct pt_regs *regs)
528{
529 int isr;
530 struct rio_mport *port = (struct rio_mport *)dev_instance;
531
532 isr = in_be32((void *)&msg_regs->isr);
533
534 if (isr & RIO_MSG_ISR_TE) {
535 pr_info("RIO: inbound message reception error\n");
536 out_be32((void *)&msg_regs->isr, RIO_MSG_ISR_TE);
537 goto out;
538 }
539
540 /* XXX Need to check/dispatch until queue empty */
541 if (isr & RIO_MSG_ISR_DIQI) {
542 /*
543 * We implement *only* mailbox 0, but can receive messages
544 * for any mailbox/letter to that mailbox destination. So,
545 * make the callback with an unknown/invalid mailbox number
546 * argument.
547 */
548 port->inb_msg[0].mcback(port, msg_rx_ring.dev_id, -1, -1);
549
550 /* Ack the queueing interrupt */
551 out_be32((void *)&msg_regs->isr, RIO_MSG_ISR_DIQI);
552 }
553
554 out:
555 return IRQ_HANDLED;
556}
557
558/**
559 * rio_open_inb_mbox - Initialize MPC85xx inbound mailbox
560 * @mport: Master port implementing the inbound message unit
561 * @dev_id: Device specific pointer to pass on event
562 * @mbox: Mailbox to open
563 * @entries: Number of entries in the inbound mailbox ring
564 *
565 * Initializes buffer ring, request the inbound message interrupt,
566 * and enables the inbound message unit. Returns %0 on success
567 * and %-EINVAL or %-ENOMEM on failure.
568 */
569int rio_open_inb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries)
570{
571 int i, rc = 0;
572
573 if ((entries < RIO_MIN_RX_RING_SIZE) ||
574 (entries > RIO_MAX_RX_RING_SIZE) || (!is_power_of_2(entries))) {
575 rc = -EINVAL;
576 goto out;
577 }
578
579 /* Initialize client buffer ring */
580 msg_rx_ring.dev_id = dev_id;
581 msg_rx_ring.size = entries;
582 msg_rx_ring.rx_slot = 0;
583 for (i = 0; i < msg_rx_ring.size; i++)
584 msg_rx_ring.virt_buffer[i] = NULL;
585
586 /* Initialize inbound message ring */
587 if (!(msg_rx_ring.virt = dma_alloc_coherent(NULL,
588 msg_rx_ring.size *
589 RIO_MAX_MSG_SIZE,
590 &msg_rx_ring.phys,
591 GFP_KERNEL))) {
592 rc = -ENOMEM;
593 goto out;
594 }
595
596 /* Point dequeue/enqueue pointers at first entry in ring */
597 out_be32((void *)&msg_regs->ifqdpar, (u32) msg_rx_ring.phys);
598 out_be32((void *)&msg_regs->ifqepar, (u32) msg_rx_ring.phys);
599
600 /* Clear interrupt status */
601 out_be32((void *)&msg_regs->isr, 0x00000091);
602
603 /* Hook up inbound message handler */
604 if ((rc =
605 request_irq(MPC85xx_IRQ_RIO_RX, mpc85xx_rio_rx_handler, 0,
606 "msg_rx", (void *)mport)) < 0) {
607 dma_free_coherent(NULL, RIO_MSG_BUFFER_SIZE,
608 msg_tx_ring.virt_buffer[i],
609 msg_tx_ring.phys_buffer[i]);
610 goto out;
611 }
612
613 /*
614 * Configure inbound message unit:
615 * Snooping
616 * 4KB max message size
617 * Unmask all interrupt sources
618 * Disable
619 */
620 out_be32((void *)&msg_regs->imr, 0x001b0060);
621
622 /* Set number of queue entries */
623 out_be32((void *)&msg_regs->imr,
624 in_be32((void *)&msg_regs->imr) |
625 ((get_bitmask_order(entries) - 2) << 12));
626
627 /* Now enable the unit */
628 out_be32((void *)&msg_regs->imr, in_be32((void *)&msg_regs->imr) | 0x1);
629
630 out:
631 return rc;
632}
633
634/**
635 * rio_close_inb_mbox - Shut down MPC85xx inbound mailbox
636 * @mport: Master port implementing the inbound message unit
637 * @mbox: Mailbox to close
638 *
639 * Disables the inbound message unit, free all buffers, and
640 * frees the inbound message interrupt.
641 */
642void rio_close_inb_mbox(struct rio_mport *mport, int mbox)
643{
644 /* Disable inbound message unit */
645 out_be32((void *)&msg_regs->imr, 0);
646
647 /* Free ring */
648 dma_free_coherent(NULL, msg_rx_ring.size * RIO_MAX_MSG_SIZE,
649 msg_rx_ring.virt, msg_rx_ring.phys);
650
651 /* Free interrupt */
652 free_irq(MPC85xx_IRQ_RIO_RX, (void *)mport);
653}
654
655/**
656 * rio_hw_add_inb_buffer - Add buffer to the MPC85xx inbound message queue
657 * @mport: Master port implementing the inbound message unit
658 * @mbox: Inbound mailbox number
659 * @buf: Buffer to add to inbound queue
660 *
661 * Adds the @buf buffer to the MPC85xx inbound message queue. Returns
662 * %0 on success or %-EINVAL on failure.
663 */
664int rio_hw_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf)
665{
666 int rc = 0;
667
668 pr_debug("RIO: rio_hw_add_inb_buffer(), msg_rx_ring.rx_slot %d\n",
669 msg_rx_ring.rx_slot);
670
671 if (msg_rx_ring.virt_buffer[msg_rx_ring.rx_slot]) {
672 printk(KERN_ERR
673 "RIO: error adding inbound buffer %d, buffer exists\n",
674 msg_rx_ring.rx_slot);
675 rc = -EINVAL;
676 goto out;
677 }
678
679 msg_rx_ring.virt_buffer[msg_rx_ring.rx_slot] = buf;
680 if (++msg_rx_ring.rx_slot == msg_rx_ring.size)
681 msg_rx_ring.rx_slot = 0;
682
683 out:
684 return rc;
685}
686
687EXPORT_SYMBOL_GPL(rio_hw_add_inb_buffer);
688
689/**
690 * rio_hw_get_inb_message - Fetch inbound message from the MPC85xx message unit
691 * @mport: Master port implementing the inbound message unit
692 * @mbox: Inbound mailbox number
693 *
694 * Gets the next available inbound message from the inbound message queue.
695 * A pointer to the message is returned on success or NULL on failure.
696 */
697void *rio_hw_get_inb_message(struct rio_mport *mport, int mbox)
698{
699 u32 imr;
700 u32 phys_buf, virt_buf;
701 void *buf = NULL;
702 int buf_idx;
703
704 phys_buf = in_be32((void *)&msg_regs->ifqdpar);
705
706 /* If no more messages, then bail out */
707 if (phys_buf == in_be32((void *)&msg_regs->ifqepar))
708 goto out2;
709
710 virt_buf = (u32) msg_rx_ring.virt + (phys_buf - msg_rx_ring.phys);
711 buf_idx = (phys_buf - msg_rx_ring.phys) / RIO_MAX_MSG_SIZE;
712 buf = msg_rx_ring.virt_buffer[buf_idx];
713
714 if (!buf) {
715 printk(KERN_ERR
716 "RIO: inbound message copy failed, no buffers\n");
717 goto out1;
718 }
719
720 /* Copy max message size, caller is expected to allocate that big */
721 memcpy(buf, (void *)virt_buf, RIO_MAX_MSG_SIZE);
722
723 /* Clear the available buffer */
724 msg_rx_ring.virt_buffer[buf_idx] = NULL;
725
726 out1:
727 imr = in_be32((void *)&msg_regs->imr);
728 out_be32((void *)&msg_regs->imr, imr | RIO_MSG_IMR_MI);
729
730 out2:
731 return buf;
732}
733
734EXPORT_SYMBOL_GPL(rio_hw_get_inb_message);
735
736/**
737 * mpc85xx_rio_dbell_handler - MPC85xx doorbell interrupt handler
738 * @irq: Linux interrupt number
739 * @dev_instance: Pointer to interrupt-specific data
740 * @regs: Register context
741 *
742 * Handles doorbell interrupts. Parses a list of registered
743 * doorbell event handlers and executes a matching event handler.
744 */
745static irqreturn_t
746mpc85xx_rio_dbell_handler(int irq, void *dev_instance, struct pt_regs *regs)
747{
748 int dsr;
749 struct rio_mport *port = (struct rio_mport *)dev_instance;
750
751 dsr = in_be32((void *)&msg_regs->dsr);
752
753 if (dsr & DOORBELL_DSR_TE) {
754 pr_info("RIO: doorbell reception error\n");
755 out_be32((void *)&msg_regs->dsr, DOORBELL_DSR_TE);
756 goto out;
757 }
758
759 if (dsr & DOORBELL_DSR_QFI) {
760 pr_info("RIO: doorbell queue full\n");
761 out_be32((void *)&msg_regs->dsr, DOORBELL_DSR_QFI);
762 goto out;
763 }
764
765 /* XXX Need to check/dispatch until queue empty */
766 if (dsr & DOORBELL_DSR_DIQI) {
767 u32 dmsg =
768 (u32) dbell_ring.virt +
769 (in_be32((void *)&msg_regs->dqdpar) & 0xfff);
770 u32 dmr;
771 struct rio_dbell *dbell;
772 int found = 0;
773
774 pr_debug
775 ("RIO: processing doorbell, sid %2.2x tid %2.2x info %4.4x\n",
776 DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg));
777
778 list_for_each_entry(dbell, &port->dbells, node) {
779 if ((dbell->res->start <= DBELL_INF(dmsg)) &&
780 (dbell->res->end >= DBELL_INF(dmsg))) {
781 found = 1;
782 break;
783 }
784 }
785 if (found) {
786 dbell->dinb(port, dbell->dev_id, DBELL_SID(dmsg), DBELL_TID(dmsg),
787 DBELL_INF(dmsg));
788 } else {
789 pr_debug
790 ("RIO: spurious doorbell, sid %2.2x tid %2.2x info %4.4x\n",
791 DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg));
792 }
793 dmr = in_be32((void *)&msg_regs->dmr);
794 out_be32((void *)&msg_regs->dmr, dmr | DOORBELL_DMR_DI);
795 out_be32((void *)&msg_regs->dsr, DOORBELL_DSR_DIQI);
796 }
797
798 out:
799 return IRQ_HANDLED;
800}
801
802/**
803 * mpc85xx_rio_doorbell_init - MPC85xx doorbell interface init
804 * @mport: Master port implementing the inbound doorbell unit
805 *
806 * Initializes doorbell unit hardware and inbound DMA buffer
807 * ring. Called from mpc85xx_rio_setup(). Returns %0 on success
808 * or %-ENOMEM on failure.
809 */
810static int mpc85xx_rio_doorbell_init(struct rio_mport *mport)
811{
812 int rc = 0;
813
814 /* Map outbound doorbell window immediately after maintenance window */
815 if (!(dbell_win =
816 (u32) ioremap(mport->iores.start + RIO_MAINT_WIN_SIZE,
817 RIO_DBELL_WIN_SIZE))) {
818 printk(KERN_ERR
819 "RIO: unable to map outbound doorbell window\n");
820 rc = -ENOMEM;
821 goto out;
822 }
823
824 /* Initialize inbound doorbells */
825 if (!(dbell_ring.virt = dma_alloc_coherent(NULL,
826 512 * DOORBELL_MESSAGE_SIZE,
827 &dbell_ring.phys,
828 GFP_KERNEL))) {
829 printk(KERN_ERR "RIO: unable allocate inbound doorbell ring\n");
830 rc = -ENOMEM;
831 iounmap((void *)dbell_win);
832 goto out;
833 }
834
835 /* Point dequeue/enqueue pointers at first entry in ring */
836 out_be32((void *)&msg_regs->dqdpar, (u32) dbell_ring.phys);
837 out_be32((void *)&msg_regs->dqepar, (u32) dbell_ring.phys);
838
839 /* Clear interrupt status */
840 out_be32((void *)&msg_regs->dsr, 0x00000091);
841
842 /* Hook up doorbell handler */
843 if ((rc =
844 request_irq(MPC85xx_IRQ_RIO_BELL, mpc85xx_rio_dbell_handler, 0,
845 "dbell_rx", (void *)mport) < 0)) {
846 iounmap((void *)dbell_win);
847 dma_free_coherent(NULL, 512 * DOORBELL_MESSAGE_SIZE,
848 dbell_ring.virt, dbell_ring.phys);
849 printk(KERN_ERR
850 "MPC85xx RIO: unable to request inbound doorbell irq");
851 goto out;
852 }
853
854 /* Configure doorbells for snooping, 512 entries, and enable */
855 out_be32((void *)&msg_regs->dmr, 0x00108161);
856
857 out:
858 return rc;
859}
860
861static char *cmdline = NULL;
862
863static int mpc85xx_rio_get_hdid(int index)
864{
865 /* XXX Need to parse multiple entries in some format */
866 if (!cmdline)
867 return -1;
868
869 return simple_strtol(cmdline, NULL, 0);
870}
871
872static int mpc85xx_rio_get_cmdline(char *s)
873{
874 if (!s)
875 return 0;
876
877 cmdline = s;
878 return 1;
879}
880
881__setup("riohdid=", mpc85xx_rio_get_cmdline);
882
883/**
884 * mpc85xx_rio_setup - Setup MPC85xx RapidIO interface
885 * @law_start: Starting physical address of RapidIO LAW
886 * @law_size: Size of RapidIO LAW
887 *
888 * Initializes MPC85xx RapidIO hardware interface, configures
889 * master port with system-specific info, and registers the
890 * master port with the RapidIO subsystem.
891 */
892void mpc85xx_rio_setup(int law_start, int law_size)
893{
894 struct rio_ops *ops;
895 struct rio_mport *port;
896
897 ops = kmalloc(sizeof(struct rio_ops), GFP_KERNEL);
898 ops->lcread = mpc85xx_local_config_read;
899 ops->lcwrite = mpc85xx_local_config_write;
900 ops->cread = mpc85xx_rio_config_read;
901 ops->cwrite = mpc85xx_rio_config_write;
902 ops->dsend = mpc85xx_rio_doorbell_send;
903
904 port = kmalloc(sizeof(struct rio_mport), GFP_KERNEL);
905 port->id = 0;
906 port->index = 0;
907 INIT_LIST_HEAD(&port->dbells);
908 port->iores.start = law_start;
909 port->iores.end = law_start + law_size;
910 port->iores.flags = IORESOURCE_MEM;
911
912 rio_init_dbell_res(&port->riores[RIO_DOORBELL_RESOURCE], 0, 0xffff);
913 rio_init_mbox_res(&port->riores[RIO_INB_MBOX_RESOURCE], 0, 0);
914 rio_init_mbox_res(&port->riores[RIO_OUTB_MBOX_RESOURCE], 0, 0);
915 strcpy(port->name, "RIO0 mport");
916
917 port->ops = ops;
918 port->host_deviceid = mpc85xx_rio_get_hdid(port->id);
919
920 rio_register_mport(port);
921
922 regs_win = (u32) ioremap(RIO_REGS_BASE, 0x20000);
923 atmu_regs = (struct rio_atmu_regs *)(regs_win + RIO_ATMU_REGS_OFFSET);
924 maint_atmu_regs = atmu_regs + 1;
925 dbell_atmu_regs = atmu_regs + 2;
926 msg_regs = (struct rio_msg_regs *)(regs_win + RIO_MSG_REGS_OFFSET);
927
928 /* Configure maintenance transaction window */
929 out_be32((void *)&maint_atmu_regs->rowbar, 0x000c0000);
930 out_be32((void *)&maint_atmu_regs->rowar, 0x80077015);
931
932 maint_win = (u32) ioremap(law_start, RIO_MAINT_WIN_SIZE);
933
934 /* Configure outbound doorbell window */
935 out_be32((void *)&dbell_atmu_regs->rowbar, 0x000c0400);
936 out_be32((void *)&dbell_atmu_regs->rowar, 0x8004200b);
937 mpc85xx_rio_doorbell_init(port);
938}
diff --git a/arch/ppc/syslib/ppc85xx_rio.h b/arch/ppc/syslib/ppc85xx_rio.h
new file mode 100644
index 000000000000..c0827a2c3eec
--- /dev/null
+++ b/arch/ppc/syslib/ppc85xx_rio.h
@@ -0,0 +1,21 @@
1/*
2 * MPC85xx RapidIO definitions
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#ifndef __PPC_SYSLIB_PPC85XX_RIO_H
14#define __PPC_SYSLIB_PPC85XX_RIO_H
15
16#include <linux/config.h>
17#include <linux/init.h>
18
19extern void mpc85xx_rio_setup(int law_start, int law_size);
20
21#endif /* __PPC_SYSLIB_PPC85XX_RIO_H */
diff --git a/arch/ppc/syslib/ppc_sys.c b/arch/ppc/syslib/ppc_sys.c
index 62ee86e80711..603f01190816 100644
--- a/arch/ppc/syslib/ppc_sys.c
+++ b/arch/ppc/syslib/ppc_sys.c
@@ -14,6 +14,7 @@
14 * option) any later version. 14 * option) any later version.
15 */ 15 */
16 16
17#include <linux/string.h>
17#include <asm/ppc_sys.h> 18#include <asm/ppc_sys.h>
18 19
19int (*ppc_sys_device_fixup) (struct platform_device * pdev); 20int (*ppc_sys_device_fixup) (struct platform_device * pdev);
diff --git a/arch/ppc/syslib/prom.c b/arch/ppc/syslib/prom.c
index 278da6ee62ea..1b9aa0d6a924 100644
--- a/arch/ppc/syslib/prom.c
+++ b/arch/ppc/syslib/prom.c
@@ -1335,10 +1335,8 @@ release_OF_resource(struct device_node* node, int index)
1335 if (!res) 1335 if (!res)
1336 return -ENODEV; 1336 return -ENODEV;
1337 1337
1338 if (res->name) { 1338 kfree(res->name);
1339 kfree(res->name); 1339 res->name = NULL;
1340 res->name = NULL;
1341 }
1342 release_resource(res); 1340 release_resource(res);
1343 kfree(res); 1341 kfree(res);
1344 1342
diff --git a/arch/ppc64/boot/main.c b/arch/ppc64/boot/main.c
index c1dc876bccab..e0dde24a72ce 100644
--- a/arch/ppc64/boot/main.c
+++ b/arch/ppc64/boot/main.c
@@ -203,8 +203,15 @@ void start(unsigned long a1, unsigned long a2, void *promptr, void *sp)
203 if (elf64ph->p_type == PT_LOAD && elf64ph->p_offset != 0) 203 if (elf64ph->p_type == PT_LOAD && elf64ph->p_offset != 0)
204 break; 204 break;
205 } 205 }
206 vmlinux.size = (unsigned long)elf64ph->p_filesz; 206 vmlinux.size = (unsigned long)elf64ph->p_filesz +
207 vmlinux.memsize = (unsigned long)elf64ph->p_memsz; 207 (unsigned long)elf64ph->p_offset;
208 /* We need to claim the memsize plus the file offset since gzip
209 * will expand the header (file offset), then the kernel, then
210 * possible rubbish we don't care about. But the kernel bss must
211 * be claimed (it will be zero'd by the kernel itself)
212 */
213 vmlinux.memsize = (unsigned long)elf64ph->p_memsz +
214 (unsigned long)elf64ph->p_offset;
208 printf("Allocating 0x%lx bytes for kernel ...\n\r", vmlinux.memsize); 215 printf("Allocating 0x%lx bytes for kernel ...\n\r", vmlinux.memsize);
209 vmlinux.addr = try_claim(vmlinux.memsize); 216 vmlinux.addr = try_claim(vmlinux.memsize);
210 if (vmlinux.addr == 0) { 217 if (vmlinux.addr == 0) {
diff --git a/arch/ppc64/kernel/kprobes.c b/arch/ppc64/kernel/kprobes.c
index ed876a5178ae..511af54e6230 100644
--- a/arch/ppc64/kernel/kprobes.c
+++ b/arch/ppc64/kernel/kprobes.c
@@ -30,19 +30,14 @@
30#include <linux/config.h> 30#include <linux/config.h>
31#include <linux/kprobes.h> 31#include <linux/kprobes.h>
32#include <linux/ptrace.h> 32#include <linux/ptrace.h>
33#include <linux/spinlock.h>
34#include <linux/preempt.h> 33#include <linux/preempt.h>
35#include <asm/cacheflush.h> 34#include <asm/cacheflush.h>
36#include <asm/kdebug.h> 35#include <asm/kdebug.h>
37#include <asm/sstep.h> 36#include <asm/sstep.h>
38 37
39static DECLARE_MUTEX(kprobe_mutex); 38static DECLARE_MUTEX(kprobe_mutex);
40 39DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
41static struct kprobe *current_kprobe; 40DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
42static unsigned long kprobe_status, kprobe_saved_msr;
43static struct kprobe *kprobe_prev;
44static unsigned long kprobe_status_prev, kprobe_saved_msr_prev;
45static struct pt_regs jprobe_saved_regs;
46 41
47int __kprobes arch_prepare_kprobe(struct kprobe *p) 42int __kprobes arch_prepare_kprobe(struct kprobe *p)
48{ 43{
@@ -108,20 +103,28 @@ static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
108 regs->nip = (unsigned long)p->ainsn.insn; 103 regs->nip = (unsigned long)p->ainsn.insn;
109} 104}
110 105
111static inline void save_previous_kprobe(void) 106static inline void save_previous_kprobe(struct kprobe_ctlblk *kcb)
107{
108 kcb->prev_kprobe.kp = kprobe_running();
109 kcb->prev_kprobe.status = kcb->kprobe_status;
110 kcb->prev_kprobe.saved_msr = kcb->kprobe_saved_msr;
111}
112
113static inline void restore_previous_kprobe(struct kprobe_ctlblk *kcb)
112{ 114{
113 kprobe_prev = current_kprobe; 115 __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
114 kprobe_status_prev = kprobe_status; 116 kcb->kprobe_status = kcb->prev_kprobe.status;
115 kprobe_saved_msr_prev = kprobe_saved_msr; 117 kcb->kprobe_saved_msr = kcb->prev_kprobe.saved_msr;
116} 118}
117 119
118static inline void restore_previous_kprobe(void) 120static inline void set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
121 struct kprobe_ctlblk *kcb)
119{ 122{
120 current_kprobe = kprobe_prev; 123 __get_cpu_var(current_kprobe) = p;
121 kprobe_status = kprobe_status_prev; 124 kcb->kprobe_saved_msr = regs->msr;
122 kprobe_saved_msr = kprobe_saved_msr_prev;
123} 125}
124 126
127/* Called with kretprobe_lock held */
125void __kprobes arch_prepare_kretprobe(struct kretprobe *rp, 128void __kprobes arch_prepare_kretprobe(struct kretprobe *rp,
126 struct pt_regs *regs) 129 struct pt_regs *regs)
127{ 130{
@@ -145,19 +148,24 @@ static inline int kprobe_handler(struct pt_regs *regs)
145 struct kprobe *p; 148 struct kprobe *p;
146 int ret = 0; 149 int ret = 0;
147 unsigned int *addr = (unsigned int *)regs->nip; 150 unsigned int *addr = (unsigned int *)regs->nip;
151 struct kprobe_ctlblk *kcb;
152
153 /*
154 * We don't want to be preempted for the entire
155 * duration of kprobe processing
156 */
157 preempt_disable();
158 kcb = get_kprobe_ctlblk();
148 159
149 /* Check we're not actually recursing */ 160 /* Check we're not actually recursing */
150 if (kprobe_running()) { 161 if (kprobe_running()) {
151 /* We *are* holding lock here, so this is safe.
152 Disarm the probe we just hit, and ignore it. */
153 p = get_kprobe(addr); 162 p = get_kprobe(addr);
154 if (p) { 163 if (p) {
155 kprobe_opcode_t insn = *p->ainsn.insn; 164 kprobe_opcode_t insn = *p->ainsn.insn;
156 if (kprobe_status == KPROBE_HIT_SS && 165 if (kcb->kprobe_status == KPROBE_HIT_SS &&
157 is_trap(insn)) { 166 is_trap(insn)) {
158 regs->msr &= ~MSR_SE; 167 regs->msr &= ~MSR_SE;
159 regs->msr |= kprobe_saved_msr; 168 regs->msr |= kcb->kprobe_saved_msr;
160 unlock_kprobes();
161 goto no_kprobe; 169 goto no_kprobe;
162 } 170 }
163 /* We have reentered the kprobe_handler(), since 171 /* We have reentered the kprobe_handler(), since
@@ -166,27 +174,24 @@ static inline int kprobe_handler(struct pt_regs *regs)
166 * just single step on the instruction of the new probe 174 * just single step on the instruction of the new probe
167 * without calling any user handlers. 175 * without calling any user handlers.
168 */ 176 */
169 save_previous_kprobe(); 177 save_previous_kprobe(kcb);
170 current_kprobe = p; 178 set_current_kprobe(p, regs, kcb);
171 kprobe_saved_msr = regs->msr; 179 kcb->kprobe_saved_msr = regs->msr;
172 p->nmissed++; 180 p->nmissed++;
173 prepare_singlestep(p, regs); 181 prepare_singlestep(p, regs);
174 kprobe_status = KPROBE_REENTER; 182 kcb->kprobe_status = KPROBE_REENTER;
175 return 1; 183 return 1;
176 } else { 184 } else {
177 p = current_kprobe; 185 p = __get_cpu_var(current_kprobe);
178 if (p->break_handler && p->break_handler(p, regs)) { 186 if (p->break_handler && p->break_handler(p, regs)) {
179 goto ss_probe; 187 goto ss_probe;
180 } 188 }
181 } 189 }
182 /* If it's not ours, can't be delete race, (we hold lock). */
183 goto no_kprobe; 190 goto no_kprobe;
184 } 191 }
185 192
186 lock_kprobes();
187 p = get_kprobe(addr); 193 p = get_kprobe(addr);
188 if (!p) { 194 if (!p) {
189 unlock_kprobes();
190 if (*addr != BREAKPOINT_INSTRUCTION) { 195 if (*addr != BREAKPOINT_INSTRUCTION) {
191 /* 196 /*
192 * PowerPC has multiple variants of the "trap" 197 * PowerPC has multiple variants of the "trap"
@@ -209,24 +214,19 @@ static inline int kprobe_handler(struct pt_regs *regs)
209 goto no_kprobe; 214 goto no_kprobe;
210 } 215 }
211 216
212 kprobe_status = KPROBE_HIT_ACTIVE; 217 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
213 current_kprobe = p; 218 set_current_kprobe(p, regs, kcb);
214 kprobe_saved_msr = regs->msr;
215 if (p->pre_handler && p->pre_handler(p, regs)) 219 if (p->pre_handler && p->pre_handler(p, regs))
216 /* handler has already set things up, so skip ss setup */ 220 /* handler has already set things up, so skip ss setup */
217 return 1; 221 return 1;
218 222
219ss_probe: 223ss_probe:
220 prepare_singlestep(p, regs); 224 prepare_singlestep(p, regs);
221 kprobe_status = KPROBE_HIT_SS; 225 kcb->kprobe_status = KPROBE_HIT_SS;
222 /*
223 * This preempt_disable() matches the preempt_enable_no_resched()
224 * in post_kprobe_handler().
225 */
226 preempt_disable();
227 return 1; 226 return 1;
228 227
229no_kprobe: 228no_kprobe:
229 preempt_enable_no_resched();
230 return ret; 230 return ret;
231} 231}
232 232
@@ -251,9 +251,10 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
251 struct kretprobe_instance *ri = NULL; 251 struct kretprobe_instance *ri = NULL;
252 struct hlist_head *head; 252 struct hlist_head *head;
253 struct hlist_node *node, *tmp; 253 struct hlist_node *node, *tmp;
254 unsigned long orig_ret_address = 0; 254 unsigned long flags, orig_ret_address = 0;
255 unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline; 255 unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline;
256 256
257 spin_lock_irqsave(&kretprobe_lock, flags);
257 head = kretprobe_inst_table_head(current); 258 head = kretprobe_inst_table_head(current);
258 259
259 /* 260 /*
@@ -292,12 +293,14 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
292 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address)); 293 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
293 regs->nip = orig_ret_address; 294 regs->nip = orig_ret_address;
294 295
295 unlock_kprobes(); 296 reset_current_kprobe();
297 spin_unlock_irqrestore(&kretprobe_lock, flags);
298 preempt_enable_no_resched();
296 299
297 /* 300 /*
298 * By returning a non-zero value, we are telling 301 * By returning a non-zero value, we are telling
299 * kprobe_handler() that we have handled unlocking 302 * kprobe_handler() that we don't want the post_handler
300 * and re-enabling preemption. 303 * to run (and have re-enabled preemption)
301 */ 304 */
302 return 1; 305 return 1;
303} 306}
@@ -323,23 +326,26 @@ static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
323 326
324static inline int post_kprobe_handler(struct pt_regs *regs) 327static inline int post_kprobe_handler(struct pt_regs *regs)
325{ 328{
326 if (!kprobe_running()) 329 struct kprobe *cur = kprobe_running();
330 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
331
332 if (!cur)
327 return 0; 333 return 0;
328 334
329 if ((kprobe_status != KPROBE_REENTER) && current_kprobe->post_handler) { 335 if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
330 kprobe_status = KPROBE_HIT_SSDONE; 336 kcb->kprobe_status = KPROBE_HIT_SSDONE;
331 current_kprobe->post_handler(current_kprobe, regs, 0); 337 cur->post_handler(cur, regs, 0);
332 } 338 }
333 339
334 resume_execution(current_kprobe, regs); 340 resume_execution(cur, regs);
335 regs->msr |= kprobe_saved_msr; 341 regs->msr |= kcb->kprobe_saved_msr;
336 342
337 /*Restore back the original saved kprobes variables and continue. */ 343 /*Restore back the original saved kprobes variables and continue. */
338 if (kprobe_status == KPROBE_REENTER) { 344 if (kcb->kprobe_status == KPROBE_REENTER) {
339 restore_previous_kprobe(); 345 restore_previous_kprobe(kcb);
340 goto out; 346 goto out;
341 } 347 }
342 unlock_kprobes(); 348 reset_current_kprobe();
343out: 349out:
344 preempt_enable_no_resched(); 350 preempt_enable_no_resched();
345 351
@@ -354,19 +360,20 @@ out:
354 return 1; 360 return 1;
355} 361}
356 362
357/* Interrupts disabled, kprobe_lock held. */
358static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr) 363static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
359{ 364{
360 if (current_kprobe->fault_handler 365 struct kprobe *cur = kprobe_running();
361 && current_kprobe->fault_handler(current_kprobe, regs, trapnr)) 366 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
367
368 if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
362 return 1; 369 return 1;
363 370
364 if (kprobe_status & KPROBE_HIT_SS) { 371 if (kcb->kprobe_status & KPROBE_HIT_SS) {
365 resume_execution(current_kprobe, regs); 372 resume_execution(cur, regs);
366 regs->msr &= ~MSR_SE; 373 regs->msr &= ~MSR_SE;
367 regs->msr |= kprobe_saved_msr; 374 regs->msr |= kcb->kprobe_saved_msr;
368 375
369 unlock_kprobes(); 376 reset_current_kprobe();
370 preempt_enable_no_resched(); 377 preempt_enable_no_resched();
371 } 378 }
372 return 0; 379 return 0;
@@ -381,11 +388,6 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
381 struct die_args *args = (struct die_args *)data; 388 struct die_args *args = (struct die_args *)data;
382 int ret = NOTIFY_DONE; 389 int ret = NOTIFY_DONE;
383 390
384 /*
385 * Interrupts are not disabled here. We need to disable
386 * preemption, because kprobe_running() uses smp_processor_id().
387 */
388 preempt_disable();
389 switch (val) { 391 switch (val) {
390 case DIE_BPT: 392 case DIE_BPT:
391 if (kprobe_handler(args->regs)) 393 if (kprobe_handler(args->regs))
@@ -396,22 +398,25 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
396 ret = NOTIFY_STOP; 398 ret = NOTIFY_STOP;
397 break; 399 break;
398 case DIE_PAGE_FAULT: 400 case DIE_PAGE_FAULT:
401 /* kprobe_running() needs smp_processor_id() */
402 preempt_disable();
399 if (kprobe_running() && 403 if (kprobe_running() &&
400 kprobe_fault_handler(args->regs, args->trapnr)) 404 kprobe_fault_handler(args->regs, args->trapnr))
401 ret = NOTIFY_STOP; 405 ret = NOTIFY_STOP;
406 preempt_enable();
402 break; 407 break;
403 default: 408 default:
404 break; 409 break;
405 } 410 }
406 preempt_enable_no_resched();
407 return ret; 411 return ret;
408} 412}
409 413
410int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) 414int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
411{ 415{
412 struct jprobe *jp = container_of(p, struct jprobe, kp); 416 struct jprobe *jp = container_of(p, struct jprobe, kp);
417 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
413 418
414 memcpy(&jprobe_saved_regs, regs, sizeof(struct pt_regs)); 419 memcpy(&kcb->jprobe_saved_regs, regs, sizeof(struct pt_regs));
415 420
416 /* setup return addr to the jprobe handler routine */ 421 /* setup return addr to the jprobe handler routine */
417 regs->nip = (unsigned long)(((func_descr_t *)jp->entry)->entry); 422 regs->nip = (unsigned long)(((func_descr_t *)jp->entry)->entry);
@@ -431,12 +436,15 @@ void __kprobes jprobe_return_end(void)
431 436
432int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) 437int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
433{ 438{
439 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
440
434 /* 441 /*
435 * FIXME - we should ideally be validating that we got here 'cos 442 * FIXME - we should ideally be validating that we got here 'cos
436 * of the "trap" in jprobe_return() above, before restoring the 443 * of the "trap" in jprobe_return() above, before restoring the
437 * saved regs... 444 * saved regs...
438 */ 445 */
439 memcpy(regs, &jprobe_saved_regs, sizeof(struct pt_regs)); 446 memcpy(regs, &kcb->jprobe_saved_regs, sizeof(struct pt_regs));
447 preempt_enable_no_resched();
440 return 1; 448 return 1;
441} 449}
442 450
diff --git a/arch/ppc64/kernel/lparcfg.c b/arch/ppc64/kernel/lparcfg.c
index e86155770bbc..3e7b2f28ec83 100644
--- a/arch/ppc64/kernel/lparcfg.c
+++ b/arch/ppc64/kernel/lparcfg.c
@@ -599,9 +599,7 @@ int __init lparcfg_init(void)
599void __exit lparcfg_cleanup(void) 599void __exit lparcfg_cleanup(void)
600{ 600{
601 if (proc_ppc64_lparcfg) { 601 if (proc_ppc64_lparcfg) {
602 if (proc_ppc64_lparcfg->data) { 602 kfree(proc_ppc64_lparcfg->data);
603 kfree(proc_ppc64_lparcfg->data);
604 }
605 remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent); 603 remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
606 } 604 }
607} 605}
diff --git a/arch/ppc64/kernel/scanlog.c b/arch/ppc64/kernel/scanlog.c
index 215bf8900304..2edc947f7c44 100644
--- a/arch/ppc64/kernel/scanlog.c
+++ b/arch/ppc64/kernel/scanlog.c
@@ -225,8 +225,7 @@ int __init scanlog_init(void)
225void __exit scanlog_cleanup(void) 225void __exit scanlog_cleanup(void)
226{ 226{
227 if (proc_ppc64_scan_log_dump) { 227 if (proc_ppc64_scan_log_dump) {
228 if (proc_ppc64_scan_log_dump->data) 228 kfree(proc_ppc64_scan_log_dump->data);
229 kfree(proc_ppc64_scan_log_dump->data);
230 remove_proc_entry("scan-log-dump", proc_ppc64_scan_log_dump->parent); 229 remove_proc_entry("scan-log-dump", proc_ppc64_scan_log_dump->parent);
231 } 230 }
232} 231}
diff --git a/arch/ppc64/kernel/sysfs.c b/arch/ppc64/kernel/sysfs.c
index 6654b350979c..e99ec62c2c52 100644
--- a/arch/ppc64/kernel/sysfs.c
+++ b/arch/ppc64/kernel/sysfs.c
@@ -20,6 +20,7 @@
20#include <asm/paca.h> 20#include <asm/paca.h>
21#include <asm/lppaca.h> 21#include <asm/lppaca.h>
22#include <asm/machdep.h> 22#include <asm/machdep.h>
23#include <asm/smp.h>
23 24
24static DEFINE_PER_CPU(struct cpu, cpu_devices); 25static DEFINE_PER_CPU(struct cpu, cpu_devices);
25 26
diff --git a/arch/s390/Makefile b/arch/s390/Makefile
index 98db30481d97..73a09a6ee6c8 100644
--- a/arch/s390/Makefile
+++ b/arch/s390/Makefile
@@ -76,9 +76,7 @@ AFLAGS += $(aflags-y)
76OBJCOPYFLAGS := -O binary 76OBJCOPYFLAGS := -O binary
77LDFLAGS_vmlinux := -e start 77LDFLAGS_vmlinux := -e start
78 78
79head-$(CONFIG_ARCH_S390_31) += arch/$(ARCH)/kernel/head.o 79head-y := arch/$(ARCH)/kernel/head.o arch/$(ARCH)/kernel/init_task.o
80head-$(CONFIG_ARCH_S390X) += arch/$(ARCH)/kernel/head64.o
81head-y += arch/$(ARCH)/kernel/init_task.o
82 80
83core-y += arch/$(ARCH)/mm/ arch/$(ARCH)/kernel/ arch/$(ARCH)/crypto/ \ 81core-y += arch/$(ARCH)/mm/ arch/$(ARCH)/kernel/ arch/$(ARCH)/crypto/ \
84 arch/$(ARCH)/appldata/ 82 arch/$(ARCH)/appldata/
diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile
index 8584dd823218..7434c32bc631 100644
--- a/arch/s390/kernel/Makefile
+++ b/arch/s390/kernel/Makefile
@@ -8,9 +8,7 @@ obj-y := bitmap.o traps.o time.o process.o \
8 setup.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o \ 8 setup.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o \
9 semaphore.o s390_ext.o debug.o profile.o irq.o reipl_diag.o 9 semaphore.o s390_ext.o debug.o profile.o irq.o reipl_diag.o
10 10
11extra-$(CONFIG_ARCH_S390_31) += head.o 11extra-y += head.o init_task.o vmlinux.lds
12extra-$(CONFIG_ARCH_S390X) += head64.o
13extra-y += init_task.o vmlinux.lds
14 12
15obj-$(CONFIG_MODULES) += s390_ksyms.o module.o 13obj-$(CONFIG_MODULES) += s390_ksyms.o module.o
16obj-$(CONFIG_SMP) += smp.o 14obj-$(CONFIG_SMP) += smp.o
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 9b30f4cf32c4..27b07730b7b8 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -288,7 +288,7 @@ sysc_sigpending:
288 bo BASED(sysc_restart) 288 bo BASED(sysc_restart)
289 tm __TI_flags+3(%r9),_TIF_SINGLE_STEP 289 tm __TI_flags+3(%r9),_TIF_SINGLE_STEP
290 bo BASED(sysc_singlestep) 290 bo BASED(sysc_singlestep)
291 b BASED(sysc_leave) # out of here, do NOT recheck 291 b BASED(sysc_work_loop)
292 292
293# 293#
294# _TIF_RESTART_SVC is set, set up registers and restart svc 294# _TIF_RESTART_SVC is set, set up registers and restart svc
@@ -645,7 +645,7 @@ io_sigpending:
645 l %r1,BASED(.Ldo_signal) 645 l %r1,BASED(.Ldo_signal)
646 basr %r14,%r1 # call do_signal 646 basr %r14,%r1 # call do_signal
647 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts 647 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
648 b BASED(io_leave) # out of here, do NOT recheck 648 b BASED(io_work_loop)
649 649
650/* 650/*
651 * External interrupt handler routine 651 * External interrupt handler routine
diff --git a/arch/s390/kernel/entry64.S b/arch/s390/kernel/entry64.S
index 7b9b4a2ba1d7..4eb71ffcf484 100644
--- a/arch/s390/kernel/entry64.S
+++ b/arch/s390/kernel/entry64.S
@@ -283,7 +283,7 @@ sysc_sigpending:
283 jo sysc_restart 283 jo sysc_restart
284 tm __TI_flags+7(%r9),_TIF_SINGLE_STEP 284 tm __TI_flags+7(%r9),_TIF_SINGLE_STEP
285 jo sysc_singlestep 285 jo sysc_singlestep
286 j sysc_leave # out of here, do NOT recheck 286 j sysc_work_loop
287 287
288# 288#
289# _TIF_RESTART_SVC is set, set up registers and restart svc 289# _TIF_RESTART_SVC is set, set up registers and restart svc
@@ -684,7 +684,7 @@ io_sigpending:
684 slgr %r3,%r3 # clear *oldset 684 slgr %r3,%r3 # clear *oldset
685 brasl %r14,do_signal # call do_signal 685 brasl %r14,do_signal # call do_signal
686 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts 686 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
687 j sysc_leave # out of here, do NOT recheck 687 j io_work_loop
688 688
689/* 689/*
690 * External interrupt handler routine 690 * External interrupt handler routine
diff --git a/arch/s390/kernel/head.S b/arch/s390/kernel/head.S
index 039354d72348..d31a97c89f68 100644
--- a/arch/s390/kernel/head.S
+++ b/arch/s390/kernel/head.S
@@ -1,11 +1,12 @@
1/* 1/*
2 * arch/s390/kernel/head.S 2 * arch/s390/kernel/head.S
3 * 3 *
4 * S390 version 4 * (C) Copyright IBM Corp. 1999, 2005
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation 5 *
6 * Author(s): Hartmut Penner (hp@de.ibm.com), 6 * Author(s): Hartmut Penner <hp@de.ibm.com>
7 * Martin Schwidefsky (schwidefsky@de.ibm.com), 7 * Martin Schwidefsky <schwidefsky@de.ibm.com>
8 * Rob van der Heij (rvdhei@iae.nl) 8 * Rob van der Heij <rvdhei@iae.nl>
9 * Heiko Carstens <heiko.carstens@de.ibm.com>
9 * 10 *
10 * There are 5 different IPL methods 11 * There are 5 different IPL methods
11 * 1) load the image directly into ram at address 0 and do an PSW restart 12 * 1) load the image directly into ram at address 0 and do an PSW restart
@@ -19,12 +20,7 @@
19 * 5) direct call of start by the SALIPL loader 20 * 5) direct call of start by the SALIPL loader
20 * We use the cpuid to distinguish between VM and native ipl 21 * We use the cpuid to distinguish between VM and native ipl
21 * params for kernel are pushed to 0x10400 (see setup.h) 22 * params for kernel are pushed to 0x10400 (see setup.h)
22 23 *
23 Changes:
24 Okt 25 2000 <rvdheij@iae.nl>
25 added code to skip HDR and EOF to allow SL tape IPL (5 retries)
26 changed first CCW from rewind to backspace block
27
28 */ 24 */
29 25
30#include <linux/config.h> 26#include <linux/config.h>
@@ -34,6 +30,12 @@
34#include <asm/thread_info.h> 30#include <asm/thread_info.h>
35#include <asm/page.h> 31#include <asm/page.h>
36 32
33#ifdef CONFIG_ARCH_S390X
34#define ARCH_OFFSET 4
35#else
36#define ARCH_OFFSET 0
37#endif
38
37#ifndef CONFIG_IPL 39#ifndef CONFIG_IPL
38 .org 0 40 .org 0
39 .long 0x00080000,0x80000000+startup # Just a restart PSW 41 .long 0x00080000,0x80000000+startup # Just a restart PSW
@@ -201,7 +203,7 @@
201 ssch 0(%r3) # load chunk of 1600 bytes 203 ssch 0(%r3) # load chunk of 1600 bytes
202 bnz .Llderr 204 bnz .Llderr
203.Lwait4irq: 205.Lwait4irq:
204 mvc __LC_IO_NEW_PSW(8),.Lnewpsw # set up IO interrupt psw 206 mvc 0x78(8),.Lnewpsw # set up IO interrupt psw
205 lpsw .Lwaitpsw 207 lpsw .Lwaitpsw
206.Lioint: 208.Lioint:
207 c %r1,0xb8 # compare subchannel number 209 c %r1,0xb8 # compare subchannel number
@@ -265,13 +267,13 @@ iplstart:
265 la %r2,IPL_BS # load start address 267 la %r2,IPL_BS # load start address
266 bas %r14,.Lloader # load rest of ipl image 268 bas %r14,.Lloader # load rest of ipl image
267 l %r12,.Lparm # pointer to parameter area 269 l %r12,.Lparm # pointer to parameter area
268 st %r1,IPL_DEVICE-PARMAREA(%r12) # store ipl device number 270 st %r1,IPL_DEVICE+ARCH_OFFSET-PARMAREA(%r12) # save ipl device number
269 271
270# 272#
271# load parameter file from ipl device 273# load parameter file from ipl device
272# 274#
273.Lagain1: 275.Lagain1:
274 l %r2,INITRD_START-PARMAREA(%r12) # use ramdisk location as temp 276 l %r2,INITRD_START+ARCH_OFFSET-PARMAREA(%r12) # ramdisk loc. is temp
275 bas %r14,.Lloader # load parameter file 277 bas %r14,.Lloader # load parameter file
276 ltr %r2,%r2 # got anything ? 278 ltr %r2,%r2 # got anything ?
277 bz .Lnopf 279 bz .Lnopf
@@ -279,7 +281,7 @@ iplstart:
279 bnh .Lnotrunc 281 bnh .Lnotrunc
280 la %r2,895 282 la %r2,895
281.Lnotrunc: 283.Lnotrunc:
282 l %r4,INITRD_START-PARMAREA(%r12) 284 l %r4,INITRD_START+ARCH_OFFSET-PARMAREA(%r12)
283 clc 0(3,%r4),.L_hdr # if it is HDRx 285 clc 0(3,%r4),.L_hdr # if it is HDRx
284 bz .Lagain1 # skip dataset header 286 bz .Lagain1 # skip dataset header
285 clc 0(3,%r4),.L_eof # if it is EOFx 287 clc 0(3,%r4),.L_eof # if it is EOFx
@@ -322,14 +324,14 @@ iplstart:
322# load ramdisk from ipl device 324# load ramdisk from ipl device
323# 325#
324.Lagain2: 326.Lagain2:
325 l %r2,INITRD_START-PARMAREA(%r12) # load adr. of ramdisk 327 l %r2,INITRD_START+ARCH_OFFSET-PARMAREA(%r12) # addr of ramdisk
326 bas %r14,.Lloader # load ramdisk 328 bas %r14,.Lloader # load ramdisk
327 st %r2,INITRD_SIZE-PARMAREA(%r12) # store size of ramdisk 329 st %r2,INITRD_SIZE+ARCH_OFFSET-PARMAREA(%r12) # store size of ramdisk
328 ltr %r2,%r2 330 ltr %r2,%r2
329 bnz .Lrdcont 331 bnz .Lrdcont
330 st %r2,INITRD_START-PARMAREA(%r12) # no ramdisk found, null it 332 st %r2,INITRD_START+ARCH_OFFSET-PARMAREA(%r12) # no ramdisk found
331.Lrdcont: 333.Lrdcont:
332 l %r2,INITRD_START-PARMAREA(%r12) 334 l %r2,INITRD_START+ARCH_OFFSET-PARMAREA(%r12)
333 335
334 clc 0(3,%r2),.L_hdr # skip HDRx and EOFx 336 clc 0(3,%r2),.L_hdr # skip HDRx and EOFx
335 bz .Lagain2 337 bz .Lagain2
@@ -432,10 +434,10 @@ start:
432 la %r3,1(%r3) 434 la %r3,1(%r3)
433.done: 435.done:
434 l %r1,.memsize 436 l %r1,.memsize
435 st %r3,0(%r1) 437 st %r3,ARCH_OFFSET(%r1)
436 slr %r0,%r0 438 slr %r0,%r0
437 st %r0,INITRD_SIZE-PARMAREA(%r11) 439 st %r0,INITRD_SIZE+ARCH_OFFSET-PARMAREA(%r11)
438 st %r0,INITRD_START-PARMAREA(%r11) 440 st %r0,INITRD_START+ARCH_OFFSET-PARMAREA(%r11)
439 j startup # continue with startup 441 j startup # continue with startup
440.tbl: .long _ebcasc # translate table 442.tbl: .long _ebcasc # translate table
441.cmd: .long COMMAND_LINE # address of command line buffer 443.cmd: .long COMMAND_LINE # address of command line buffer
@@ -478,304 +480,23 @@ start:
478 .byte 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7 480 .byte 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7
479 .byte 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff 481 .byte 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
480 482
481# 483.macro GET_IPL_DEVICE
482# startup-code at 0x10000, running in real mode
483# this is called either by the ipl loader or directly by PSW restart
484# or linload or SALIPL
485#
486 .org 0x10000
487startup:basr %r13,0 # get base
488.LPG1: l %r1, .Lget_ipl_device_addr-.LPG1(%r13)
489 basr %r14, %r1
490 lctl %c0,%c15,.Lctl-.LPG1(%r13) # load control registers
491 la %r12,_pstart-.LPG1(%r13) # pointer to parameter area
492 # move IPL device to lowcore
493 mvc __LC_IPLDEV(4),IPL_DEVICE-PARMAREA(%r12)
494
495#
496# clear bss memory
497#
498 l %r2,.Lbss_bgn-.LPG1(%r13) # start of bss
499 l %r3,.Lbss_end-.LPG1(%r13) # end of bss
500 sr %r3,%r2 # length of bss
501 sr %r4,%r4 #
502 sr %r5,%r5 # set src,length and pad to zero
503 sr %r0,%r0 #
504 mvcle %r2,%r4,0 # clear mem
505 jo .-4 # branch back, if not finish
506
507 l %r2,.Lrcp-.LPG1(%r13) # Read SCP forced command word
508.Lservicecall:
509 stosm .Lpmask-.LPG1(%r13),0x01 # authorize ext interrupts
510
511 stctl %r0, %r0,.Lcr-.LPG1(%r13) # get cr0
512 la %r1,0x200 # set bit 22
513 o %r1,.Lcr-.LPG1(%r13) # or old cr0 with r1
514 st %r1,.Lcr-.LPG1(%r13)
515 lctl %r0, %r0,.Lcr-.LPG1(%r13) # load modified cr0
516
517 mvc __LC_EXT_NEW_PSW(8),.Lpcext-.LPG1(%r13) # set postcall psw
518 la %r1, .Lsclph-.LPG1(%r13)
519 a %r1,__LC_EXT_NEW_PSW+4 # set handler
520 st %r1,__LC_EXT_NEW_PSW+4
521
522 la %r4,_pstart-.LPG1(%r13) # %r4 is our index for sccb stuff
523 la %r1, .Lsccb-PARMAREA(%r4) # our sccb
524 .insn rre,0xb2200000,%r2,%r1 # service call
525 ipm %r1
526 srl %r1,28 # get cc code
527 xr %r3, %r3
528 chi %r1,3
529 be .Lfchunk-.LPG1(%r13) # leave
530 chi %r1,2
531 be .Lservicecall-.LPG1(%r13)
532 lpsw .Lwaitsclp-.LPG1(%r13)
533.Lsclph:
534 lh %r1,.Lsccbr-PARMAREA(%r4)
535 chi %r1,0x10 # 0x0010 is the sucess code
536 je .Lprocsccb # let's process the sccb
537 chi %r1,0x1f0
538 bne .Lfchunk-.LPG1(%r13) # unhandled error code
539 c %r2, .Lrcp-.LPG1(%r13) # Did we try Read SCP forced
540 bne .Lfchunk-.LPG1(%r13) # if no, give up
541 l %r2, .Lrcp2-.LPG1(%r13) # try with Read SCP
542 b .Lservicecall-.LPG1(%r13)
543.Lprocsccb:
544 lhi %r1,0
545 icm %r1,3,.Lscpincr1-PARMAREA(%r4) # use this one if != 0
546 jnz .Lscnd
547 lhi %r1,0x800 # otherwise report 2GB
548.Lscnd:
549 lhi %r3,0x800 # limit reported memory size to 2GB
550 cr %r1,%r3
551 jl .Lno2gb
552 lr %r1,%r3
553.Lno2gb:
554 xr %r3,%r3 # same logic
555 ic %r3,.Lscpa1-PARMAREA(%r4)
556 chi %r3,0x00
557 jne .Lcompmem
558 l %r3,.Lscpa2-PARMAREA(%r13)
559.Lcompmem:
560 mr %r2,%r1 # mem in MB on 128-bit
561 l %r1,.Lonemb-.LPG1(%r13)
562 mr %r2,%r1 # mem size in bytes in %r3
563 b .Lfchunk-.LPG1(%r13)
564
565 .align 4
566.Lget_ipl_device_addr:
567 .long .Lget_ipl_device
568.Lpmask:
569 .byte 0
570.align 8
571.Lpcext:.long 0x00080000,0x80000000
572.Lcr:
573 .long 0x00 # place holder for cr0
574.Lwaitsclp:
575 .long 0x020A0000
576 .long .Lsclph
577.Lrcp:
578 .int 0x00120001 # Read SCP forced code
579.Lrcp2:
580 .int 0x00020001 # Read SCP code
581.Lonemb:
582 .int 0x100000
583.Lfchunk:
584
585#
586# find memory chunks.
587#
588 lr %r9,%r3 # end of mem
589 mvc __LC_PGM_NEW_PSW(8),.Lpcmem-.LPG1(%r13)
590 la %r1,1 # test in increments of 128KB
591 sll %r1,17
592 l %r3,.Lmchunk-.LPG1(%r13) # get pointer to memory_chunk array
593 slr %r4,%r4 # set start of chunk to zero
594 slr %r5,%r5 # set end of chunk to zero
595 slr %r6,%r6 # set access code to zero
596 la %r10, MEMORY_CHUNKS # number of chunks
597.Lloop:
598 tprot 0(%r5),0 # test protection of first byte
599 ipm %r7
600 srl %r7,28
601 clr %r6,%r7 # compare cc with last access code
602 be .Lsame-.LPG1(%r13)
603 b .Lchkmem-.LPG1(%r13)
604.Lsame:
605 ar %r5,%r1 # add 128KB to end of chunk
606 bno .Lloop-.LPG1(%r13) # r1 < 0x80000000 -> loop
607.Lchkmem: # > 2GB or tprot got a program check
608 clr %r4,%r5 # chunk size > 0?
609 be .Lchkloop-.LPG1(%r13)
610 st %r4,0(%r3) # store start address of chunk
611 lr %r0,%r5
612 slr %r0,%r4
613 st %r0,4(%r3) # store size of chunk
614 st %r6,8(%r3) # store type of chunk
615 la %r3,12(%r3)
616 l %r4,.Lmemsize-.LPG1(%r13) # address of variable memory_size
617 st %r5,0(%r4) # store last end to memory size
618 ahi %r10,-1 # update chunk number
619.Lchkloop:
620 lr %r6,%r7 # set access code to last cc
621 # we got an exception or we're starting a new
622 # chunk , we must check if we should
623 # still try to find valid memory (if we detected
624 # the amount of available storage), and if we
625 # have chunks left
626 xr %r0,%r0
627 clr %r0,%r9 # did we detect memory?
628 je .Ldonemem # if not, leave
629 chi %r10,0 # do we have chunks left?
630 je .Ldonemem
631 alr %r5,%r1 # add 128KB to end of chunk
632 lr %r4,%r5 # potential new chunk
633 clr %r5,%r9 # should we go on?
634 jl .Lloop
635.Ldonemem:
636 l %r12,.Lmflags-.LPG1(%r13) # get address of machine_flags
637#
638# find out if we are running under VM
639#
640 stidp __LC_CPUID # store cpuid
641 tm __LC_CPUID,0xff # running under VM ?
642 bno .Lnovm-.LPG1(%r13)
643 oi 3(%r12),1 # set VM flag
644.Lnovm:
645 lh %r0,__LC_CPUID+4 # get cpu version
646 chi %r0,0x7490 # running on a P/390 ?
647 bne .Lnop390-.LPG1(%r13)
648 oi 3(%r12),4 # set P/390 flag
649.Lnop390:
650
651#
652# find out if we have an IEEE fpu
653#
654 mvc __LC_PGM_NEW_PSW(8),.Lpcfpu-.LPG1(%r13)
655 efpc %r0,0 # test IEEE extract fpc instruction
656 oi 3(%r12),2 # set IEEE fpu flag
657.Lchkfpu:
658
659#
660# find out if we have the CSP instruction
661#
662 mvc __LC_PGM_NEW_PSW(8),.Lpccsp-.LPG1(%r13)
663 la %r0,0
664 lr %r1,%r0
665 la %r2,4
666 csp %r0,%r2 # Test CSP instruction
667 oi 3(%r12),8 # set CSP flag
668.Lchkcsp:
669
670#
671# find out if we have the MVPG instruction
672#
673 mvc __LC_PGM_NEW_PSW(8),.Lpcmvpg-.LPG1(%r13)
674 sr %r0,%r0
675 la %r1,0
676 la %r2,0
677 mvpg %r1,%r2 # Test CSP instruction
678 oi 3(%r12),16 # set MVPG flag
679.Lchkmvpg:
680
681#
682# find out if we have the IDTE instruction
683#
684 mvc __LC_PGM_NEW_PSW(8),.Lpcidte-.LPG1(%r13)
685 .long 0xb2b10000 # store facility list
686 tm 0xc8,0x08 # check bit for clearing-by-ASCE
687 bno .Lchkidte-.LPG1(%r13)
688 lhi %r1,2094
689 lhi %r2,0
690 .long 0xb98e2001
691 oi 3(%r12),0x80 # set IDTE flag
692.Lchkidte:
693
694 lpsw .Lentry-.LPG1(13) # jump to _stext in primary-space,
695 # virtual and never return ...
696 .align 8
697.Lentry:.long 0x00080000,0x80000000 + _stext
698.Lctl: .long 0x04b50002 # cr0: various things
699 .long 0 # cr1: primary space segment table
700 .long .Lduct # cr2: dispatchable unit control table
701 .long 0 # cr3: instruction authorization
702 .long 0 # cr4: instruction authorization
703 .long 0xffffffff # cr5: primary-aste origin
704 .long 0 # cr6: I/O interrupts
705 .long 0 # cr7: secondary space segment table
706 .long 0 # cr8: access registers translation
707 .long 0 # cr9: tracing off
708 .long 0 # cr10: tracing off
709 .long 0 # cr11: tracing off
710 .long 0 # cr12: tracing off
711 .long 0 # cr13: home space segment table
712 .long 0xc0000000 # cr14: machine check handling off
713 .long 0 # cr15: linkage stack operations
714.Lpcmem:.long 0x00080000,0x80000000 + .Lchkmem
715.Lpcfpu:.long 0x00080000,0x80000000 + .Lchkfpu
716.Lpccsp:.long 0x00080000,0x80000000 + .Lchkcsp
717.Lpcmvpg:.long 0x00080000,0x80000000 + .Lchkmvpg
718.Lpcidte:.long 0x00080000,0x80000000 + .Lchkidte
719.Lmemsize:.long memory_size
720.Lmchunk:.long memory_chunk
721.Lmflags:.long machine_flags
722.Lbss_bgn: .long __bss_start
723.Lbss_end: .long _end
724
725 .org PARMAREA-64
726.Lduct: .long 0,0,0,0,0,0,0,0
727 .long 0,0,0,0,0,0,0,0
728
729#
730# params at 10400 (setup.h)
731#
732 .org PARMAREA
733 .global _pstart
734_pstart:
735 .long 0,0 # IPL_DEVICE
736 .long 0,RAMDISK_ORIGIN # INITRD_START
737 .long 0,RAMDISK_SIZE # INITRD_SIZE
738
739 .org COMMAND_LINE
740 .byte "root=/dev/ram0 ro"
741 .byte 0
742 .org 0x11000
743.Lsccb:
744 .hword 0x1000 # length, one page
745 .byte 0x00,0x00,0x00
746 .byte 0x80 # variable response bit set
747.Lsccbr:
748 .hword 0x00 # response code
749.Lscpincr1:
750 .hword 0x00
751.Lscpa1:
752 .byte 0x00
753 .fill 89,1,0
754.Lscpa2:
755 .int 0x00
756.Lscpincr2:
757 .quad 0x00
758 .fill 3984,1,0
759 .org 0x12000
760 .global _pend
761_pend:
762
763.Lget_ipl_device: 484.Lget_ipl_device:
764 basr %r12,0 485 basr %r12,0
765.LPG2: l %r1,0xb8 # get sid 486.LGID: l %r1,0xb8 # get sid
766 sll %r1,15 # test if subchannel is enabled 487 sll %r1,15 # test if subchannel is enabled
767 srl %r1,31 488 srl %r1,31
768 ltr %r1,%r1 489 ltr %r1,%r1
769 bz 0(%r14) # subchannel disabled 490 bz 0(%r14) # subchannel disabled
770 l %r1,0xb8 491 l %r1,0xb8
771 la %r5,.Lipl_schib-.LPG2(%r12) 492 la %r5,.Lipl_schib-.LGID(%r12)
772 stsch 0(%r5) # get schib of subchannel 493 stsch 0(%r5) # get schib of subchannel
773 bnz 0(%r14) # schib not available 494 bnz 0(%r14) # schib not available
774 tm 5(%r5),0x01 # devno valid? 495 tm 5(%r5),0x01 # devno valid?
775 bno 0(%r14) 496 bno 0(%r14)
776 la %r6,ipl_parameter_flags-.LPG2(%r12) 497 la %r6,ipl_parameter_flags-.LGID(%r12)
777 oi 3(%r6),0x01 # set flag 498 oi 3(%r6),0x01 # set flag
778 la %r2,ipl_devno-.LPG2(%r12) 499 la %r2,ipl_devno-.LGID(%r12)
779 mvc 0(2,%r2),6(%r5) # store devno 500 mvc 0(2,%r2),6(%r5) # store devno
780 tm 4(%r5),0x80 # qdio capable device? 501 tm 4(%r5),0x80 # qdio capable device?
781 bno 0(%r14) 502 bno 0(%r14)
@@ -816,46 +537,10 @@ ipl_parameter_flags:
816 .globl ipl_devno 537 .globl ipl_devno
817ipl_devno: 538ipl_devno:
818 .word 0 539 .word 0
540.endm
819 541
820#ifdef CONFIG_SHARED_KERNEL 542#ifdef CONFIG_ARCH_S390X
821 .org 0x100000 543#include "head64.S"
544#else
545#include "head31.S"
822#endif 546#endif
823
824#
825# startup-code, running in virtual mode
826#
827 .globl _stext
828_stext: basr %r13,0 # get base
829.LPG3:
830#
831# Setup stack
832#
833 l %r15,.Linittu-.LPG3(%r13)
834 mvc __LC_CURRENT(4),__TI_task(%r15)
835 ahi %r15,1<<(PAGE_SHIFT+THREAD_ORDER) # init_task_union + THREAD_SIZE
836 st %r15,__LC_KERNEL_STACK # set end of kernel stack
837 ahi %r15,-96
838 xc __SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15) # clear backchain
839
840# check control registers
841 stctl %c0,%c15,0(%r15)
842 oi 2(%r15),0x40 # enable sigp emergency signal
843 oi 0(%r15),0x10 # switch on low address protection
844 lctl %c0,%c15,0(%r15)
845
846#
847 lam 0,15,.Laregs-.LPG3(%r13) # load access regs needed by uaccess
848 l %r14,.Lstart-.LPG3(%r13)
849 basr %r14,%r14 # call start_kernel
850#
851# We returned from start_kernel ?!? PANIK
852#
853 basr %r13,0
854 lpsw .Ldw-.(%r13) # load disabled wait psw
855#
856 .align 8
857.Ldw: .long 0x000a0000,0x00000000
858.Linittu: .long init_thread_union
859.Lstart: .long start_kernel
860.Laregs: .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
861
diff --git a/arch/s390/kernel/head31.S b/arch/s390/kernel/head31.S
new file mode 100644
index 000000000000..2d3b089bfb83
--- /dev/null
+++ b/arch/s390/kernel/head31.S
@@ -0,0 +1,336 @@
1/*
2 * arch/s390/kernel/head31.S
3 *
4 * (C) Copyright IBM Corp. 2005
5 *
6 * Author(s): Hartmut Penner <hp@de.ibm.com>
7 * Martin Schwidefsky <schwidefsky@de.ibm.com>
8 * Rob van der Heij <rvdhei@iae.nl>
9 * Heiko Carstens <heiko.carstens@de.ibm.com>
10 *
11 */
12
13#
14# startup-code at 0x10000, running in absolute addressing mode
15# this is called either by the ipl loader or directly by PSW restart
16# or linload or SALIPL
17#
18 .org 0x10000
19startup:basr %r13,0 # get base
20.LPG1: l %r1, .Lget_ipl_device_addr-.LPG1(%r13)
21 basr %r14, %r1
22 lctl %c0,%c15,.Lctl-.LPG1(%r13) # load control registers
23 la %r12,_pstart-.LPG1(%r13) # pointer to parameter area
24 # move IPL device to lowcore
25 mvc __LC_IPLDEV(4),IPL_DEVICE-PARMAREA(%r12)
26
27#
28# clear bss memory
29#
30 l %r2,.Lbss_bgn-.LPG1(%r13) # start of bss
31 l %r3,.Lbss_end-.LPG1(%r13) # end of bss
32 sr %r3,%r2 # length of bss
33 sr %r4,%r4
34 sr %r5,%r5 # set src,length and pad to zero
35 sr %r0,%r0
36 mvcle %r2,%r4,0 # clear mem
37 jo .-4 # branch back, if not finish
38
39 l %r2,.Lrcp-.LPG1(%r13) # Read SCP forced command word
40.Lservicecall:
41 stosm .Lpmask-.LPG1(%r13),0x01 # authorize ext interrupts
42
43 stctl %r0, %r0,.Lcr-.LPG1(%r13) # get cr0
44 la %r1,0x200 # set bit 22
45 o %r1,.Lcr-.LPG1(%r13) # or old cr0 with r1
46 st %r1,.Lcr-.LPG1(%r13)
47 lctl %r0, %r0,.Lcr-.LPG1(%r13) # load modified cr0
48
49 mvc __LC_EXT_NEW_PSW(8),.Lpcext-.LPG1(%r13) # set postcall psw
50 la %r1, .Lsclph-.LPG1(%r13)
51 a %r1,__LC_EXT_NEW_PSW+4 # set handler
52 st %r1,__LC_EXT_NEW_PSW+4
53
54 la %r4,_pstart-.LPG1(%r13) # %r4 is our index for sccb stuff
55 la %r1, .Lsccb-PARMAREA(%r4) # our sccb
56 .insn rre,0xb2200000,%r2,%r1 # service call
57 ipm %r1
58 srl %r1,28 # get cc code
59 xr %r3, %r3
60 chi %r1,3
61 be .Lfchunk-.LPG1(%r13) # leave
62 chi %r1,2
63 be .Lservicecall-.LPG1(%r13)
64 lpsw .Lwaitsclp-.LPG1(%r13)
65.Lsclph:
66 lh %r1,.Lsccbr-PARMAREA(%r4)
67 chi %r1,0x10 # 0x0010 is the sucess code
68 je .Lprocsccb # let's process the sccb
69 chi %r1,0x1f0
70 bne .Lfchunk-.LPG1(%r13) # unhandled error code
71 c %r2, .Lrcp-.LPG1(%r13) # Did we try Read SCP forced
72 bne .Lfchunk-.LPG1(%r13) # if no, give up
73 l %r2, .Lrcp2-.LPG1(%r13) # try with Read SCP
74 b .Lservicecall-.LPG1(%r13)
75.Lprocsccb:
76 lhi %r1,0
77 icm %r1,3,.Lscpincr1-PARMAREA(%r4) # use this one if != 0
78 jnz .Lscnd
79 lhi %r1,0x800 # otherwise report 2GB
80.Lscnd:
81 lhi %r3,0x800 # limit reported memory size to 2GB
82 cr %r1,%r3
83 jl .Lno2gb
84 lr %r1,%r3
85.Lno2gb:
86 xr %r3,%r3 # same logic
87 ic %r3,.Lscpa1-PARMAREA(%r4)
88 chi %r3,0x00
89 jne .Lcompmem
90 l %r3,.Lscpa2-PARMAREA(%r13)
91.Lcompmem:
92 mr %r2,%r1 # mem in MB on 128-bit
93 l %r1,.Lonemb-.LPG1(%r13)
94 mr %r2,%r1 # mem size in bytes in %r3
95 b .Lfchunk-.LPG1(%r13)
96
97 .align 4
98.Lget_ipl_device_addr:
99 .long .Lget_ipl_device
100.Lpmask:
101 .byte 0
102.align 8
103.Lpcext:.long 0x00080000,0x80000000
104.Lcr:
105 .long 0x00 # place holder for cr0
106.Lwaitsclp:
107 .long 0x010a0000,0x80000000 + .Lsclph
108.Lrcp:
109 .int 0x00120001 # Read SCP forced code
110.Lrcp2:
111 .int 0x00020001 # Read SCP code
112.Lonemb:
113 .int 0x100000
114.Lfchunk:
115
116#
117# find memory chunks.
118#
119 lr %r9,%r3 # end of mem
120 mvc __LC_PGM_NEW_PSW(8),.Lpcmem-.LPG1(%r13)
121 la %r1,1 # test in increments of 128KB
122 sll %r1,17
123 l %r3,.Lmchunk-.LPG1(%r13) # get pointer to memory_chunk array
124 slr %r4,%r4 # set start of chunk to zero
125 slr %r5,%r5 # set end of chunk to zero
126 slr %r6,%r6 # set access code to zero
127 la %r10, MEMORY_CHUNKS # number of chunks
128.Lloop:
129 tprot 0(%r5),0 # test protection of first byte
130 ipm %r7
131 srl %r7,28
132 clr %r6,%r7 # compare cc with last access code
133 be .Lsame-.LPG1(%r13)
134 b .Lchkmem-.LPG1(%r13)
135.Lsame:
136 ar %r5,%r1 # add 128KB to end of chunk
137 bno .Lloop-.LPG1(%r13) # r1 < 0x80000000 -> loop
138.Lchkmem: # > 2GB or tprot got a program check
139 clr %r4,%r5 # chunk size > 0?
140 be .Lchkloop-.LPG1(%r13)
141 st %r4,0(%r3) # store start address of chunk
142 lr %r0,%r5
143 slr %r0,%r4
144 st %r0,4(%r3) # store size of chunk
145 st %r6,8(%r3) # store type of chunk
146 la %r3,12(%r3)
147 l %r4,.Lmemsize-.LPG1(%r13) # address of variable memory_size
148 st %r5,0(%r4) # store last end to memory size
149 ahi %r10,-1 # update chunk number
150.Lchkloop:
151 lr %r6,%r7 # set access code to last cc
152 # we got an exception or we're starting a new
153 # chunk , we must check if we should
154 # still try to find valid memory (if we detected
155 # the amount of available storage), and if we
156 # have chunks left
157 xr %r0,%r0
158 clr %r0,%r9 # did we detect memory?
159 je .Ldonemem # if not, leave
160 chi %r10,0 # do we have chunks left?
161 je .Ldonemem
162 alr %r5,%r1 # add 128KB to end of chunk
163 lr %r4,%r5 # potential new chunk
164 clr %r5,%r9 # should we go on?
165 jl .Lloop
166.Ldonemem:
167 l %r12,.Lmflags-.LPG1(%r13) # get address of machine_flags
168#
169# find out if we are running under VM
170#
171 stidp __LC_CPUID # store cpuid
172 tm __LC_CPUID,0xff # running under VM ?
173 bno .Lnovm-.LPG1(%r13)
174 oi 3(%r12),1 # set VM flag
175.Lnovm:
176 lh %r0,__LC_CPUID+4 # get cpu version
177 chi %r0,0x7490 # running on a P/390 ?
178 bne .Lnop390-.LPG1(%r13)
179 oi 3(%r12),4 # set P/390 flag
180.Lnop390:
181
182#
183# find out if we have an IEEE fpu
184#
185 mvc __LC_PGM_NEW_PSW(8),.Lpcfpu-.LPG1(%r13)
186 efpc %r0,0 # test IEEE extract fpc instruction
187 oi 3(%r12),2 # set IEEE fpu flag
188.Lchkfpu:
189
190#
191# find out if we have the CSP instruction
192#
193 mvc __LC_PGM_NEW_PSW(8),.Lpccsp-.LPG1(%r13)
194 la %r0,0
195 lr %r1,%r0
196 la %r2,4
197 csp %r0,%r2 # Test CSP instruction
198 oi 3(%r12),8 # set CSP flag
199.Lchkcsp:
200
201#
202# find out if we have the MVPG instruction
203#
204 mvc __LC_PGM_NEW_PSW(8),.Lpcmvpg-.LPG1(%r13)
205 sr %r0,%r0
206 la %r1,0
207 la %r2,0
208 mvpg %r1,%r2 # Test CSP instruction
209 oi 3(%r12),16 # set MVPG flag
210.Lchkmvpg:
211
212#
213# find out if we have the IDTE instruction
214#
215 mvc __LC_PGM_NEW_PSW(8),.Lpcidte-.LPG1(%r13)
216 .long 0xb2b10000 # store facility list
217 tm 0xc8,0x08 # check bit for clearing-by-ASCE
218 bno .Lchkidte-.LPG1(%r13)
219 lhi %r1,2094
220 lhi %r2,0
221 .long 0xb98e2001
222 oi 3(%r12),0x80 # set IDTE flag
223.Lchkidte:
224
225 lpsw .Lentry-.LPG1(13) # jump to _stext in primary-space,
226 # virtual and never return ...
227 .align 8
228.Lentry:.long 0x00080000,0x80000000 + _stext
229.Lctl: .long 0x04b50002 # cr0: various things
230 .long 0 # cr1: primary space segment table
231 .long .Lduct # cr2: dispatchable unit control table
232 .long 0 # cr3: instruction authorization
233 .long 0 # cr4: instruction authorization
234 .long 0xffffffff # cr5: primary-aste origin
235 .long 0 # cr6: I/O interrupts
236 .long 0 # cr7: secondary space segment table
237 .long 0 # cr8: access registers translation
238 .long 0 # cr9: tracing off
239 .long 0 # cr10: tracing off
240 .long 0 # cr11: tracing off
241 .long 0 # cr12: tracing off
242 .long 0 # cr13: home space segment table
243 .long 0xc0000000 # cr14: machine check handling off
244 .long 0 # cr15: linkage stack operations
245.Lpcmem:.long 0x00080000,0x80000000 + .Lchkmem
246.Lpcfpu:.long 0x00080000,0x80000000 + .Lchkfpu
247.Lpccsp:.long 0x00080000,0x80000000 + .Lchkcsp
248.Lpcmvpg:.long 0x00080000,0x80000000 + .Lchkmvpg
249.Lpcidte:.long 0x00080000,0x80000000 + .Lchkidte
250.Lmemsize:.long memory_size
251.Lmchunk:.long memory_chunk
252.Lmflags:.long machine_flags
253.Lbss_bgn: .long __bss_start
254.Lbss_end: .long _end
255
256 .org PARMAREA-64
257.Lduct: .long 0,0,0,0,0,0,0,0
258 .long 0,0,0,0,0,0,0,0
259
260#
261# params at 10400 (setup.h)
262#
263 .org PARMAREA
264 .global _pstart
265_pstart:
266 .long 0,0 # IPL_DEVICE
267 .long 0,RAMDISK_ORIGIN # INITRD_START
268 .long 0,RAMDISK_SIZE # INITRD_SIZE
269
270 .org COMMAND_LINE
271 .byte "root=/dev/ram0 ro"
272 .byte 0
273 .org 0x11000
274.Lsccb:
275 .hword 0x1000 # length, one page
276 .byte 0x00,0x00,0x00
277 .byte 0x80 # variable response bit set
278.Lsccbr:
279 .hword 0x00 # response code
280.Lscpincr1:
281 .hword 0x00
282.Lscpa1:
283 .byte 0x00
284 .fill 89,1,0
285.Lscpa2:
286 .int 0x00
287.Lscpincr2:
288 .quad 0x00
289 .fill 3984,1,0
290 .org 0x12000
291 .global _pend
292_pend:
293
294 GET_IPL_DEVICE
295
296#ifdef CONFIG_SHARED_KERNEL
297 .org 0x100000
298#endif
299
300#
301# startup-code, running in virtual mode
302#
303 .globl _stext
304_stext: basr %r13,0 # get base
305.LPG3:
306#
307# Setup stack
308#
309 l %r15,.Linittu-.LPG3(%r13)
310 mvc __LC_CURRENT(4),__TI_task(%r15)
311 ahi %r15,1<<(PAGE_SHIFT+THREAD_ORDER) # init_task_union+THREAD_SIZE
312 st %r15,__LC_KERNEL_STACK # set end of kernel stack
313 ahi %r15,-96
314 xc __SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15) # clear backchain
315
316# check control registers
317 stctl %c0,%c15,0(%r15)
318 oi 2(%r15),0x40 # enable sigp emergency signal
319 oi 0(%r15),0x10 # switch on low address protection
320 lctl %c0,%c15,0(%r15)
321
322#
323 lam 0,15,.Laregs-.LPG3(%r13) # load access regs needed by uaccess
324 l %r14,.Lstart-.LPG3(%r13)
325 basr %r14,%r14 # call start_kernel
326#
327# We returned from start_kernel ?!? PANIK
328#
329 basr %r13,0
330 lpsw .Ldw-.(%r13) # load disabled wait psw
331#
332 .align 8
333.Ldw: .long 0x000a0000,0x00000000
334.Linittu:.long init_thread_union
335.Lstart:.long start_kernel
336.Laregs:.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
diff --git a/arch/s390/kernel/head64.S b/arch/s390/kernel/head64.S
index 193aafa72f54..f08c06f45d5c 100644
--- a/arch/s390/kernel/head64.S
+++ b/arch/s390/kernel/head64.S
@@ -1,482 +1,17 @@
1/* 1/*
2 * arch/s390/kernel/head.S 2 * arch/s390/kernel/head64.S
3 * 3 *
4 * S390 version 4 * (C) Copyright IBM Corp. 1999,2005
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation 5 *
6 * Author(s): Hartmut Penner (hp@de.ibm.com), 6 * Author(s): Hartmut Penner <hp@de.ibm.com>
7 * Martin Schwidefsky (schwidefsky@de.ibm.com), 7 * Martin Schwidefsky <schwidefsky@de.ibm.com>
8 * Rob van der Heij (rvdhei@iae.nl) 8 * Rob van der Heij <rvdhei@iae.nl>
9 * Heiko Carstens <heiko.carstens@de.ibm.com>
9 * 10 *
10 * There are 5 different IPL methods
11 * 1) load the image directly into ram at address 0 and do an PSW restart
12 * 2) linload will load the image from address 0x10000 to memory 0x10000
13 * and start the code thru LPSW 0x0008000080010000 (VM only, deprecated)
14 * 3) generate the tape ipl header, store the generated image on a tape
15 * and ipl from it
16 * In case of SL tape you need to IPL 5 times to get past VOL1 etc
17 * 4) generate the vm reader ipl header, move the generated image to the
18 * VM reader (use option NOH!) and do a ipl from reader (VM only)
19 * 5) direct call of start by the SALIPL loader
20 * We use the cpuid to distinguish between VM and native ipl
21 * params for kernel are pushed to 0x10400 (see setup.h)
22
23 Changes:
24 Okt 25 2000 <rvdheij@iae.nl>
25 added code to skip HDR and EOF to allow SL tape IPL (5 retries)
26 changed first CCW from rewind to backspace block
27
28 */ 11 */
29 12
30#include <linux/config.h>
31#include <asm/setup.h>
32#include <asm/lowcore.h>
33#include <asm/asm-offsets.h>
34#include <asm/thread_info.h>
35#include <asm/page.h>
36
37#ifndef CONFIG_IPL
38 .org 0
39 .long 0x00080000,0x80000000+startup # Just a restart PSW
40#else
41#ifdef CONFIG_IPL_TAPE
42#define IPL_BS 1024
43 .org 0
44 .long 0x00080000,0x80000000+iplstart # The first 24 bytes are loaded
45 .long 0x27000000,0x60000001 # by ipl to addresses 0-23.
46 .long 0x02000000,0x20000000+IPL_BS # (a PSW and two CCWs).
47 .long 0x00000000,0x00000000 # external old psw
48 .long 0x00000000,0x00000000 # svc old psw
49 .long 0x00000000,0x00000000 # program check old psw
50 .long 0x00000000,0x00000000 # machine check old psw
51 .long 0x00000000,0x00000000 # io old psw
52 .long 0x00000000,0x00000000
53 .long 0x00000000,0x00000000
54 .long 0x00000000,0x00000000
55 .long 0x000a0000,0x00000058 # external new psw
56 .long 0x000a0000,0x00000060 # svc new psw
57 .long 0x000a0000,0x00000068 # program check new psw
58 .long 0x000a0000,0x00000070 # machine check new psw
59 .long 0x00080000,0x80000000+.Lioint # io new psw
60
61 .org 0x100
62#
63# subroutine for loading from tape
64# Paramters:
65# R1 = device number
66# R2 = load address
67.Lloader:
68 st %r14,.Lldret
69 la %r3,.Lorbread # r3 = address of orb
70 la %r5,.Lirb # r5 = address of irb
71 st %r2,.Lccwread+4 # initialize CCW data addresses
72 lctl %c6,%c6,.Lcr6
73 slr %r2,%r2
74.Lldlp:
75 la %r6,3 # 3 retries
76.Lssch:
77 ssch 0(%r3) # load chunk of IPL_BS bytes
78 bnz .Llderr
79.Lw4end:
80 bas %r14,.Lwait4io
81 tm 8(%r5),0x82 # do we have a problem ?
82 bnz .Lrecov
83 slr %r7,%r7
84 icm %r7,3,10(%r5) # get residual count
85 lcr %r7,%r7
86 la %r7,IPL_BS(%r7) # IPL_BS-residual=#bytes read
87 ar %r2,%r7 # add to total size
88 tm 8(%r5),0x01 # found a tape mark ?
89 bnz .Ldone
90 l %r0,.Lccwread+4 # update CCW data addresses
91 ar %r0,%r7
92 st %r0,.Lccwread+4
93 b .Lldlp
94.Ldone:
95 l %r14,.Lldret
96 br %r14 # r2 contains the total size
97.Lrecov:
98 bas %r14,.Lsense # do the sensing
99 bct %r6,.Lssch # dec. retry count & branch
100 b .Llderr
101#
102# Sense subroutine
103#
104.Lsense:
105 st %r14,.Lsnsret
106 la %r7,.Lorbsense
107 ssch 0(%r7) # start sense command
108 bnz .Llderr
109 bas %r14,.Lwait4io
110 l %r14,.Lsnsret
111 tm 8(%r5),0x82 # do we have a problem ?
112 bnz .Llderr
113 br %r14
114#
115# Wait for interrupt subroutine
116#
117.Lwait4io:
118 lpsw .Lwaitpsw
119.Lioint:
120 c %r1,0xb8 # compare subchannel number
121 bne .Lwait4io
122 tsch 0(%r5)
123 slr %r0,%r0
124 tm 8(%r5),0x82 # do we have a problem ?
125 bnz .Lwtexit
126 tm 8(%r5),0x04 # got device end ?
127 bz .Lwait4io
128.Lwtexit:
129 br %r14
130.Llderr:
131 lpsw .Lcrash
132
133 .align 8
134.Lorbread:
135 .long 0x00000000,0x0080ff00,.Lccwread
136 .align 8
137.Lorbsense:
138 .long 0x00000000,0x0080ff00,.Lccwsense
139 .align 8
140.Lccwread:
141 .long 0x02200000+IPL_BS,0x00000000
142.Lccwsense:
143 .long 0x04200001,0x00000000
144.Lwaitpsw:
145 .long 0x020a0000,0x80000000+.Lioint
146
147.Lirb: .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
148.Lcr6: .long 0xff000000
149 .align 8
150.Lcrash:.long 0x000a0000,0x00000000
151.Lldret:.long 0
152.Lsnsret: .long 0
153#endif /* CONFIG_IPL_TAPE */
154
155#ifdef CONFIG_IPL_VM
156#define IPL_BS 0x730
157 .org 0
158 .long 0x00080000,0x80000000+iplstart # The first 24 bytes are loaded
159 .long 0x02000018,0x60000050 # by ipl to addresses 0-23.
160 .long 0x02000068,0x60000050 # (a PSW and two CCWs).
161 .fill 80-24,1,0x40 # bytes 24-79 are discarded !!
162 .long 0x020000f0,0x60000050 # The next 160 byte are loaded
163 .long 0x02000140,0x60000050 # to addresses 0x18-0xb7
164 .long 0x02000190,0x60000050 # They form the continuation
165 .long 0x020001e0,0x60000050 # of the CCW program started
166 .long 0x02000230,0x60000050 # by ipl and load the range
167 .long 0x02000280,0x60000050 # 0x0f0-0x730 from the image
168 .long 0x020002d0,0x60000050 # to the range 0x0f0-0x730
169 .long 0x02000320,0x60000050 # in memory. At the end of
170 .long 0x02000370,0x60000050 # the channel program the PSW
171 .long 0x020003c0,0x60000050 # at location 0 is loaded.
172 .long 0x02000410,0x60000050 # Initial processing starts
173 .long 0x02000460,0x60000050 # at 0xf0 = iplstart.
174 .long 0x020004b0,0x60000050
175 .long 0x02000500,0x60000050
176 .long 0x02000550,0x60000050
177 .long 0x020005a0,0x60000050
178 .long 0x020005f0,0x60000050
179 .long 0x02000640,0x60000050
180 .long 0x02000690,0x60000050
181 .long 0x020006e0,0x20000050
182
183 .org 0xf0
184#
185# subroutine for loading cards from the reader
186#
187.Lloader:
188 la %r3,.Lorb # r2 = address of orb into r2
189 la %r5,.Lirb # r4 = address of irb
190 la %r6,.Lccws
191 la %r7,20
192.Linit:
193 st %r2,4(%r6) # initialize CCW data addresses
194 la %r2,0x50(%r2)
195 la %r6,8(%r6)
196 bct 7,.Linit
197
198 lctl %c6,%c6,.Lcr6 # set IO subclass mask
199 slr %r2,%r2
200.Lldlp:
201 ssch 0(%r3) # load chunk of 1600 bytes
202 bnz .Llderr
203.Lwait4irq:
204 mvc 0x78(8),.Lnewpsw # set up IO interrupt psw
205 lpsw .Lwaitpsw
206.Lioint:
207 c %r1,0xb8 # compare subchannel number
208 bne .Lwait4irq
209 tsch 0(%r5)
210
211 slr %r0,%r0
212 ic %r0,8(%r5) # get device status
213 chi %r0,8 # channel end ?
214 be .Lcont
215 chi %r0,12 # channel end + device end ?
216 be .Lcont
217
218 l %r0,4(%r5)
219 s %r0,8(%r3) # r0/8 = number of ccws executed
220 mhi %r0,10 # *10 = number of bytes in ccws
221 lh %r3,10(%r5) # get residual count
222 sr %r0,%r3 # #ccws*80-residual=#bytes read
223 ar %r2,%r0
224
225 br %r14 # r2 contains the total size
226
227.Lcont:
228 ahi %r2,0x640 # add 0x640 to total size
229 la %r6,.Lccws
230 la %r7,20
231.Lincr:
232 l %r0,4(%r6) # update CCW data addresses
233 ahi %r0,0x640
234 st %r0,4(%r6)
235 ahi %r6,8
236 bct 7,.Lincr
237
238 b .Lldlp
239.Llderr:
240 lpsw .Lcrash
241
242 .align 8
243.Lorb: .long 0x00000000,0x0080ff00,.Lccws
244.Lirb: .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
245.Lcr6: .long 0xff000000
246.Lloadp:.long 0,0
247 .align 8
248.Lcrash:.long 0x000a0000,0x00000000
249.Lnewpsw:
250 .long 0x00080000,0x80000000+.Lioint
251.Lwaitpsw:
252 .long 0x020a0000,0x80000000+.Lioint
253
254 .align 8
255.Lccws: .rept 19
256 .long 0x02600050,0x00000000
257 .endr
258 .long 0x02200050,0x00000000
259#endif /* CONFIG_IPL_VM */
260
261iplstart:
262 lh %r1,0xb8 # test if subchannel number
263 bct %r1,.Lnoload # is valid
264 l %r1,0xb8 # load ipl subchannel number
265 la %r2,IPL_BS # load start address
266 bas %r14,.Lloader # load rest of ipl image
267 larl %r12,_pstart # pointer to parameter area
268 st %r1,IPL_DEVICE+4-PARMAREA(%r12) # store ipl device number
269
270#
271# load parameter file from ipl device
272# 13#
273.Lagain1: 14# startup-code at 0x10000, running in absolute addressing mode
274 l %r2,INITRD_START+4-PARMAREA(%r12)# use ramdisk location as temp
275 bas %r14,.Lloader # load parameter file
276 ltr %r2,%r2 # got anything ?
277 bz .Lnopf
278 chi %r2,895
279 bnh .Lnotrunc
280 la %r2,895
281.Lnotrunc:
282 l %r4,INITRD_START+4-PARMAREA(%r12)
283 clc 0(3,%r4),.L_hdr # if it is HDRx
284 bz .Lagain1 # skip dataset header
285 clc 0(3,%r4),.L_eof # if it is EOFx
286 bz .Lagain1 # skip dateset trailer
287 la %r5,0(%r4,%r2)
288 lr %r3,%r2
289.Lidebc:
290 tm 0(%r5),0x80 # high order bit set ?
291 bo .Ldocv # yes -> convert from EBCDIC
292 ahi %r5,-1
293 bct %r3,.Lidebc
294 b .Lnocv
295.Ldocv:
296 l %r3,.Lcvtab
297 tr 0(256,%r4),0(%r3) # convert parameters to ascii
298 tr 256(256,%r4),0(%r3)
299 tr 512(256,%r4),0(%r3)
300 tr 768(122,%r4),0(%r3)
301.Lnocv: la %r3,COMMAND_LINE-PARMAREA(%r12) # load adr. of command line
302 mvc 0(256,%r3),0(%r4)
303 mvc 256(256,%r3),256(%r4)
304 mvc 512(256,%r3),512(%r4)
305 mvc 768(122,%r3),768(%r4)
306 slr %r0,%r0
307 b .Lcntlp
308.Ldelspc:
309 ic %r0,0(%r2,%r3)
310 chi %r0,0x20 # is it a space ?
311 be .Lcntlp
312 ahi %r2,1
313 b .Leolp
314.Lcntlp:
315 brct %r2,.Ldelspc
316.Leolp:
317 slr %r0,%r0
318 stc %r0,0(%r2,%r3) # terminate buffer
319.Lnopf:
320
321#
322# load ramdisk from ipl device
323#
324.Lagain2:
325 l %r2,INITRD_START+4-PARMAREA(%r12)# load adr. of ramdisk
326 bas %r14,.Lloader # load ramdisk
327 st %r2,INITRD_SIZE+4-PARMAREA(%r12) # store size of ramdisk
328 ltr %r2,%r2
329 bnz .Lrdcont
330 st %r2,INITRD_START+4-PARMAREA(%r12)# no ramdisk found, null it
331.Lrdcont:
332 l %r2,INITRD_START+4-PARMAREA(%r12)
333 clc 0(3,%r2),.L_hdr # skip HDRx and EOFx
334 bz .Lagain2
335 clc 0(3,%r2),.L_eof
336 bz .Lagain2
337
338#ifdef CONFIG_IPL_VM
339#
340# reset files in VM reader
341#
342 stidp __LC_CPUID # store cpuid
343 tm __LC_CPUID,0xff # running VM ?
344 bno .Lnoreset
345 la %r2,.Lreset
346 lhi %r3,26
347 diag %r2,%r3,8
348 la %r5,.Lirb
349 stsch 0(%r5) # check if irq is pending
350 tm 30(%r5),0x0f # by verifying if any of the
351 bnz .Lwaitforirq # activity or status control
352 tm 31(%r5),0xff # bits is set in the schib
353 bz .Lnoreset
354.Lwaitforirq:
355 mvc 0x78(8),.Lrdrnewpsw # set up IO interrupt psw
356.Lwaitrdrirq:
357 lpsw .Lrdrwaitpsw
358.Lrdrint:
359 c %r1,0xb8 # compare subchannel number
360 bne .Lwaitrdrirq
361 la %r5,.Lirb
362 tsch 0(%r5)
363.Lnoreset:
364 b .Lnoload
365
366 .align 8
367.Lrdrnewpsw:
368 .long 0x00080000,0x80000000+.Lrdrint
369.Lrdrwaitpsw:
370 .long 0x020a0000,0x80000000+.Lrdrint
371#endif
372
373#
374# everything loaded, go for it
375#
376.Lnoload:
377 l %r1,.Lstartup
378 br %r1
379
380.Lstartup: .long startup
381.Lcvtab:.long _ebcasc # ebcdic to ascii table
382.Lreset:.byte 0xc3,0xc8,0xc1,0xd5,0xc7,0xc5,0x40,0xd9,0xc4,0xd9,0x40
383 .byte 0xc1,0xd3,0xd3,0x40,0xd2,0xc5,0xc5,0xd7,0x40,0xd5,0xd6
384 .byte 0xc8,0xd6,0xd3,0xc4 # "change rdr all keep nohold"
385.L_eof: .long 0xc5d6c600 /* C'EOF' */
386.L_hdr: .long 0xc8c4d900 /* C'HDR' */
387#endif /* CONFIG_IPL */
388
389#
390# SALIPL loader support. Based on a patch by Rob van der Heij.
391# This entry point is called directly from the SALIPL loader and
392# doesn't need a builtin ipl record.
393#
394 .org 0x800
395 .globl start
396start:
397 stm %r0,%r15,0x07b0 # store registers
398 basr %r12,%r0
399.base:
400 l %r11,.parm
401 l %r8,.cmd # pointer to command buffer
402
403 ltr %r9,%r9 # do we have SALIPL parameters?
404 bp .sk8x8
405
406 mvc 0(64,%r8),0x00b0 # copy saved registers
407 xc 64(240-64,%r8),0(%r8) # remainder of buffer
408 tr 0(64,%r8),.lowcase
409 b .gotr
410.sk8x8:
411 mvc 0(240,%r8),0(%r9) # copy iplparms into buffer
412.gotr:
413 l %r10,.tbl # EBCDIC to ASCII table
414 tr 0(240,%r8),0(%r10)
415 stidp __LC_CPUID # Are we running on VM maybe
416 cli __LC_CPUID,0xff
417 bnz .test
418 .long 0x83300060 # diag 3,0,x'0060' - storage size
419 b .done
420.test:
421 mvc 0x68(8),.pgmnw # set up pgm check handler
422 l %r2,.fourmeg
423 lr %r3,%r2
424 bctr %r3,%r0 # 4M-1
425.loop: iske %r0,%r3
426 ar %r3,%r2
427.pgmx:
428 sr %r3,%r2
429 la %r3,1(%r3)
430.done:
431 l %r1,.memsize
432 st %r3,4(%r1)
433 slr %r0,%r0
434 st %r0,INITRD_SIZE+4-PARMAREA(%r11)
435 st %r0,INITRD_START+4-PARMAREA(%r11)
436 j startup # continue with startup
437.tbl: .long _ebcasc # translate table
438.cmd: .long COMMAND_LINE # address of command line buffer
439.parm: .long PARMAREA
440.fourmeg: .long 0x00400000 # 4M
441.pgmnw: .long 0x00080000,.pgmx
442.memsize: .long memory_size
443.lowcase:
444 .byte 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
445 .byte 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
446 .byte 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17
447 .byte 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f
448 .byte 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27
449 .byte 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f
450 .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37
451 .byte 0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f
452 .byte 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47
453 .byte 0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f
454 .byte 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57
455 .byte 0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f
456 .byte 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67
457 .byte 0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f
458 .byte 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77
459 .byte 0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f
460
461 .byte 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87
462 .byte 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f
463 .byte 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97
464 .byte 0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f
465 .byte 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7
466 .byte 0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf
467 .byte 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7
468 .byte 0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf
469 .byte 0xc0,0x81,0x82,0x83,0x84,0x85,0x86,0x87 # .abcdefg
470 .byte 0x88,0x89,0xca,0xcb,0xcc,0xcd,0xce,0xcf # hi
471 .byte 0xd0,0x91,0x92,0x93,0x94,0x95,0x96,0x97 # .jklmnop
472 .byte 0x98,0x99,0xda,0xdb,0xdc,0xdd,0xde,0xdf # qr
473 .byte 0xe0,0xe1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7 # ..stuvwx
474 .byte 0xa8,0xa9,0xea,0xeb,0xec,0xed,0xee,0xef # yz
475 .byte 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7
476 .byte 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
477
478#
479# startup-code at 0x10000, running in real mode
480# this is called either by the ipl loader or directly by PSW restart 15# this is called either by the ipl loader or directly by PSW restart
481# or linload or SALIPL 16# or linload or SALIPL
482# 17#
@@ -530,7 +65,7 @@ startup:basr %r13,0 # get base
530 be .Lfchunk-.LPG1(%r13) # leave 65 be .Lfchunk-.LPG1(%r13) # leave
531 chi %r1,2 66 chi %r1,2
532 be .Lservicecall-.LPG1(%r13) 67 be .Lservicecall-.LPG1(%r13)
533 lpsw .Lwaitsclp-.LPG1(%r13) 68 lpswe .Lwaitsclp-.LPG1(%r13)
534.Lsclph: 69.Lsclph:
535 lh %r1,.Lsccbr-PARMAREA(%r4) 70 lh %r1,.Lsccbr-PARMAREA(%r4)
536 chi %r1,0x10 # 0x0010 is the sucess code 71 chi %r1,0x10 # 0x0010 is the sucess code
@@ -567,8 +102,7 @@ startup:basr %r13,0 # get base
567.Lcr: 102.Lcr:
568 .quad 0x00 # place holder for cr0 103 .quad 0x00 # place holder for cr0
569.Lwaitsclp: 104.Lwaitsclp:
570 .long 0x020A0000 105 .quad 0x0102000180000000,.Lsclph
571 .quad .Lsclph
572.Lrcp: 106.Lrcp:
573 .int 0x00120001 # Read SCP forced code 107 .int 0x00120001 # Read SCP forced code
574.Lrcp2: 108.Lrcp2:
@@ -751,62 +285,7 @@ _pstart:
751 .global _pend 285 .global _pend
752_pend: 286_pend:
753 287
754.Lget_ipl_device: 288 GET_IPL_DEVICE
755 basr %r12,0
756.LPG2: l %r1,0xb8 # get sid
757 sll %r1,15 # test if subchannel is enabled
758 srl %r1,31
759 ltr %r1,%r1
760 bz 0(%r14) # subchannel disabled
761 l %r1,0xb8
762 la %r5,.Lipl_schib-.LPG2(%r12)
763 stsch 0(%r5) # get schib of subchannel
764 bnz 0(%r14) # schib not available
765 tm 5(%r5),0x01 # devno valid?
766 bno 0(%r14)
767 la %r6,ipl_parameter_flags-.LPG2(%r12)
768 oi 3(%r6),0x01 # set flag
769 la %r2,ipl_devno-.LPG2(%r12)
770 mvc 0(2,%r2),6(%r5) # store devno
771 tm 4(%r5),0x80 # qdio capable device?
772 bno 0(%r14)
773 oi 3(%r6),0x02 # set flag
774
775 # copy ipl parameters
776
777 lhi %r0,4096
778 l %r2,20(%r0) # get address of parameter list
779 lhi %r3,IPL_PARMBLOCK_ORIGIN
780 st %r3,20(%r0)
781 lhi %r4,1
782 cr %r2,%r3 # start parameters < destination ?
783 jl 0f
784 lhi %r1,1 # copy direction is upwards
785 j 1f
7860: lhi %r1,-1 # copy direction is downwards
787 ar %r2,%r0
788 ar %r3,%r0
789 ar %r2,%r1
790 ar %r3,%r1
7911: mvc 0(1,%r3),0(%r2) # finally copy ipl parameters
792 ar %r3,%r1
793 ar %r2,%r1
794 sr %r0,%r4
795 jne 1b
796 b 0(%r14)
797
798 .align 4
799.Lipl_schib:
800 .rept 13
801 .long 0
802 .endr
803
804 .globl ipl_parameter_flags
805ipl_parameter_flags:
806 .long 0
807 .globl ipl_devno
808ipl_devno:
809 .word 0
810 289
811#ifdef CONFIG_SHARED_KERNEL 290#ifdef CONFIG_SHARED_KERNEL
812 .org 0x100000 291 .org 0x100000
diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c
index 9a1d95894f3d..c36353e8c140 100644
--- a/arch/s390/kernel/time.c
+++ b/arch/s390/kernel/time.c
@@ -237,6 +237,8 @@ int sysctl_hz_timer = 1;
237 */ 237 */
238static inline void stop_hz_timer(void) 238static inline void stop_hz_timer(void)
239{ 239{
240 unsigned long flags;
241 unsigned long seq, next;
240 __u64 timer, todval; 242 __u64 timer, todval;
241 243
242 if (sysctl_hz_timer != 0) 244 if (sysctl_hz_timer != 0)
@@ -257,7 +259,11 @@ static inline void stop_hz_timer(void)
257 * This cpu is going really idle. Set up the clock comparator 259 * This cpu is going really idle. Set up the clock comparator
258 * for the next event. 260 * for the next event.
259 */ 261 */
260 timer = (__u64) (next_timer_interrupt() - jiffies) + jiffies_64; 262 next = next_timer_interrupt();
263 do {
264 seq = read_seqbegin_irqsave(&xtime_lock, flags);
265 timer = (__u64)(next - jiffies) + jiffies_64;
266 } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
261 todval = -1ULL; 267 todval = -1ULL;
262 /* Be careful about overflows. */ 268 /* Be careful about overflows. */
263 if (timer < (-1ULL / CLK_TICKS_PER_JIFFY)) { 269 if (timer < (-1ULL / CLK_TICKS_PER_JIFFY)) {
diff --git a/arch/s390/kernel/traps.c b/arch/s390/kernel/traps.c
index 6b8703ec2ae6..c5bd36fae56b 100644
--- a/arch/s390/kernel/traps.c
+++ b/arch/s390/kernel/traps.c
@@ -57,7 +57,6 @@ int sysctl_userprocess_debug = 0;
57 57
58extern pgm_check_handler_t do_protection_exception; 58extern pgm_check_handler_t do_protection_exception;
59extern pgm_check_handler_t do_dat_exception; 59extern pgm_check_handler_t do_dat_exception;
60extern pgm_check_handler_t do_pseudo_page_fault;
61#ifdef CONFIG_PFAULT 60#ifdef CONFIG_PFAULT
62extern int pfault_init(void); 61extern int pfault_init(void);
63extern void pfault_fini(void); 62extern void pfault_fini(void);
@@ -676,20 +675,6 @@ asmlinkage void kernel_stack_overflow(struct pt_regs * regs)
676 panic("Corrupt kernel stack, can't continue."); 675 panic("Corrupt kernel stack, can't continue.");
677} 676}
678 677
679#ifndef CONFIG_ARCH_S390X
680static int
681pagex_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
682{
683 if (MACHINE_IS_VM)
684 cpcmd("SET PAGEX OFF", NULL, 0, NULL);
685 return NOTIFY_DONE;
686}
687
688static struct notifier_block pagex_reboot_notifier = {
689 .notifier_call = &pagex_reboot_event,
690};
691#endif
692
693/* init is done in lowcore.S and head.S */ 678/* init is done in lowcore.S and head.S */
694 679
695void __init trap_init(void) 680void __init trap_init(void)
@@ -717,9 +702,7 @@ void __init trap_init(void)
717 pgm_check_table[0x11] = &do_dat_exception; 702 pgm_check_table[0x11] = &do_dat_exception;
718 pgm_check_table[0x12] = &translation_exception; 703 pgm_check_table[0x12] = &translation_exception;
719 pgm_check_table[0x13] = &special_op_exception; 704 pgm_check_table[0x13] = &special_op_exception;
720#ifndef CONFIG_ARCH_S390X 705#ifdef CONFIG_ARCH_S390X
721 pgm_check_table[0x14] = &do_pseudo_page_fault;
722#else /* CONFIG_ARCH_S390X */
723 pgm_check_table[0x38] = &do_dat_exception; 706 pgm_check_table[0x38] = &do_dat_exception;
724 pgm_check_table[0x39] = &do_dat_exception; 707 pgm_check_table[0x39] = &do_dat_exception;
725 pgm_check_table[0x3A] = &do_dat_exception; 708 pgm_check_table[0x3A] = &do_dat_exception;
@@ -731,12 +714,10 @@ void __init trap_init(void)
731 pgm_check_table[0x40] = &do_monitor_call; 714 pgm_check_table[0x40] = &do_monitor_call;
732 715
733 if (MACHINE_IS_VM) { 716 if (MACHINE_IS_VM) {
717#ifdef CONFIG_PFAULT
734 /* 718 /*
735 * First try to get pfault pseudo page faults going. 719 * Try to get pfault pseudo page faults going.
736 * If this isn't available turn on pagex page faults.
737 */ 720 */
738#ifdef CONFIG_PFAULT
739 /* request the 0x2603 external interrupt */
740 if (register_early_external_interrupt(0x2603, pfault_interrupt, 721 if (register_early_external_interrupt(0x2603, pfault_interrupt,
741 &ext_int_pfault) != 0) 722 &ext_int_pfault) != 0)
742 panic("Couldn't request external interrupt 0x2603"); 723 panic("Couldn't request external interrupt 0x2603");
@@ -748,9 +729,5 @@ void __init trap_init(void)
748 unregister_early_external_interrupt(0x2603, pfault_interrupt, 729 unregister_early_external_interrupt(0x2603, pfault_interrupt,
749 &ext_int_pfault); 730 &ext_int_pfault);
750#endif 731#endif
751#ifndef CONFIG_ARCH_S390X
752 register_reboot_notifier(&pagex_reboot_notifier);
753 cpcmd("SET PAGEX ON", NULL, 0, NULL);
754#endif
755 } 732 }
756} 733}
diff --git a/arch/s390/mm/extmem.c b/arch/s390/mm/extmem.c
index c5348108ca3c..506a33b51e4f 100644
--- a/arch/s390/mm/extmem.c
+++ b/arch/s390/mm/extmem.c
@@ -234,8 +234,8 @@ query_segment_type (struct dcss_segment *seg)
234 rc = 0; 234 rc = 0;
235 235
236 out_free: 236 out_free:
237 if (qin) kfree(qin); 237 kfree(qin);
238 if (qout) kfree(qout); 238 kfree(qout);
239 return rc; 239 return rc;
240} 240}
241 241
@@ -394,7 +394,7 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
394 segtype_string[seg->vm_segtype]); 394 segtype_string[seg->vm_segtype]);
395 goto out; 395 goto out;
396 out_free: 396 out_free:
397 kfree (seg); 397 kfree(seg);
398 out: 398 out:
399 return rc; 399 return rc;
400} 400}
@@ -505,7 +505,7 @@ segment_modify_shared (char *name, int do_nonshared)
505 list_del(&seg->list); 505 list_del(&seg->list);
506 dcss_diag(DCSS_PURGESEG, seg->dcss_name, 506 dcss_diag(DCSS_PURGESEG, seg->dcss_name,
507 &dummy, &dummy); 507 &dummy, &dummy);
508 kfree (seg); 508 kfree(seg);
509 out_unlock: 509 out_unlock:
510 spin_unlock(&dcss_lock); 510 spin_unlock(&dcss_lock);
511 return rc; 511 return rc;
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
index 856a971759b1..64e32da77754 100644
--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -352,115 +352,6 @@ void do_dat_exception(struct pt_regs *regs, unsigned long error_code)
352 do_exception(regs, error_code & 0xff, 0); 352 do_exception(regs, error_code & 0xff, 0);
353} 353}
354 354
355#ifndef CONFIG_ARCH_S390X
356
357typedef struct _pseudo_wait_t {
358 struct _pseudo_wait_t *next;
359 wait_queue_head_t queue;
360 unsigned long address;
361 int resolved;
362} pseudo_wait_t;
363
364static pseudo_wait_t *pseudo_lock_queue = NULL;
365static spinlock_t pseudo_wait_spinlock; /* spinlock to protect lock queue */
366
367/*
368 * This routine handles 'pagex' pseudo page faults.
369 */
370asmlinkage void
371do_pseudo_page_fault(struct pt_regs *regs, unsigned long error_code)
372{
373 pseudo_wait_t wait_struct;
374 pseudo_wait_t *ptr, *last, *next;
375 unsigned long address;
376
377 /*
378 * get the failing address
379 * more specific the segment and page table portion of
380 * the address
381 */
382 address = S390_lowcore.trans_exc_code & 0xfffff000;
383
384 if (address & 0x80000000) {
385 /* high bit set -> a page has been swapped in by VM */
386 address &= 0x7fffffff;
387 spin_lock(&pseudo_wait_spinlock);
388 last = NULL;
389 ptr = pseudo_lock_queue;
390 while (ptr != NULL) {
391 next = ptr->next;
392 if (address == ptr->address) {
393 /*
394 * This is one of the processes waiting
395 * for the page. Unchain from the queue.
396 * There can be more than one process
397 * waiting for the same page. VM presents
398 * an initial and a completion interrupt for
399 * every process that tries to access a
400 * page swapped out by VM.
401 */
402 if (last == NULL)
403 pseudo_lock_queue = next;
404 else
405 last->next = next;
406 /* now wake up the process */
407 ptr->resolved = 1;
408 wake_up(&ptr->queue);
409 } else
410 last = ptr;
411 ptr = next;
412 }
413 spin_unlock(&pseudo_wait_spinlock);
414 } else {
415 /* Pseudo page faults in kernel mode is a bad idea */
416 if (!(regs->psw.mask & PSW_MASK_PSTATE)) {
417 /*
418 * VM presents pseudo page faults if the interrupted
419 * state was not disabled for interrupts. So we can
420 * get pseudo page fault interrupts while running
421 * in kernel mode. We simply access the page here
422 * while we are running disabled. VM will then swap
423 * in the page synchronously.
424 */
425 if (check_user_space(regs, error_code) == 0)
426 /* dereference a virtual kernel address */
427 __asm__ __volatile__ (
428 " ic 0,0(%0)"
429 : : "a" (address) : "0");
430 else
431 /* dereference a virtual user address */
432 __asm__ __volatile__ (
433 " la 2,0(%0)\n"
434 " sacf 512\n"
435 " ic 2,0(2)\n"
436 "0:sacf 0\n"
437 ".section __ex_table,\"a\"\n"
438 " .align 4\n"
439 " .long 0b,0b\n"
440 ".previous"
441 : : "a" (address) : "2" );
442
443 return;
444 }
445 /* initialize and add element to pseudo_lock_queue */
446 init_waitqueue_head (&wait_struct.queue);
447 wait_struct.address = address;
448 wait_struct.resolved = 0;
449 spin_lock(&pseudo_wait_spinlock);
450 wait_struct.next = pseudo_lock_queue;
451 pseudo_lock_queue = &wait_struct;
452 spin_unlock(&pseudo_wait_spinlock);
453 /*
454 * The instruction that caused the program check will
455 * be repeated. Don't signal single step via SIGTRAP.
456 */
457 clear_tsk_thread_flag(current, TIF_SINGLE_STEP);
458 /* go to sleep */
459 wait_event(wait_struct.queue, wait_struct.resolved);
460 }
461}
462#endif /* CONFIG_ARCH_S390X */
463
464#ifdef CONFIG_PFAULT 355#ifdef CONFIG_PFAULT
465/* 356/*
466 * 'pfault' pseudo page faults routines. 357 * 'pfault' pseudo page faults routines.
@@ -508,7 +399,7 @@ int pfault_init(void)
508 " .quad 0b,1b\n" 399 " .quad 0b,1b\n"
509#endif /* CONFIG_ARCH_S390X */ 400#endif /* CONFIG_ARCH_S390X */
510 ".previous" 401 ".previous"
511 : "=d" (rc) : "a" (&refbk) : "cc" ); 402 : "=d" (rc) : "a" (&refbk), "m" (refbk) : "cc" );
512 __ctl_set_bit(0, 9); 403 __ctl_set_bit(0, 9);
513 return rc; 404 return rc;
514} 405}
@@ -532,7 +423,7 @@ void pfault_fini(void)
532 " .quad 0b,0b\n" 423 " .quad 0b,0b\n"
533#endif /* CONFIG_ARCH_S390X */ 424#endif /* CONFIG_ARCH_S390X */
534 ".previous" 425 ".previous"
535 : : "a" (&refbk) : "cc" ); 426 : : "a" (&refbk), "m" (refbk) : "cc" );
536} 427}
537 428
538asmlinkage void 429asmlinkage void
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index 3e804c736e64..64f5ae0ff96d 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -490,16 +490,6 @@ config CPU_SUBTYPE_ST40
490 depends on CPU_SUBTYPE_ST40STB1 || CPU_SUBTYPE_ST40GX1 490 depends on CPU_SUBTYPE_ST40STB1 || CPU_SUBTYPE_ST40GX1
491 default y 491 default y
492 492
493config ARCH_DISCONTIGMEM_ENABLE
494 bool
495 depends on SH_HP690
496 default y
497 help
498 Say Y to upport efficient handling of discontiguous physical memory,
499 for architectures which are either NUMA (Non-Uniform Memory Access)
500 or have huge holes in the physical address space for other reasons.
501 See <file:Documentation/vm/numa> for more.
502
503source "mm/Kconfig" 493source "mm/Kconfig"
504 494
505config ZERO_PAGE_OFFSET 495config ZERO_PAGE_OFFSET
@@ -770,24 +760,6 @@ source "fs/Kconfig.binfmt"
770 760
771endmenu 761endmenu
772 762
773menu "SH initrd options"
774 depends on BLK_DEV_INITRD
775
776config EMBEDDED_RAMDISK
777 bool "Embed root filesystem ramdisk into the kernel"
778
779config EMBEDDED_RAMDISK_IMAGE
780 string "Filename of gziped ramdisk image"
781 depends on EMBEDDED_RAMDISK
782 default "ramdisk.gz"
783 help
784 This is the filename of the ramdisk image to be built into the
785 kernel. Relative pathnames are relative to arch/sh/ramdisk/.
786 The ramdisk image is not part of the kernel distribution; you must
787 provide one yourself.
788
789endmenu
790
791source "net/Kconfig" 763source "net/Kconfig"
792 764
793source "drivers/Kconfig" 765source "drivers/Kconfig"
diff --git a/arch/sh/Makefile b/arch/sh/Makefile
index 4a3049080b41..67192d6b00d8 100644
--- a/arch/sh/Makefile
+++ b/arch/sh/Makefile
@@ -60,14 +60,6 @@ LIBGCC := $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
60 60
61core-y += arch/sh/kernel/ arch/sh/mm/ 61core-y += arch/sh/kernel/ arch/sh/mm/
62 62
63#
64# ramdisk/initrd support
65# You need a compressed ramdisk image, named
66# CONFIG_EMBEDDED_RAMDISK_IMAGE. Relative pathnames
67# are relative to arch/sh/ramdisk/.
68#
69core-$(CONFIG_EMBEDDED_RAMDISK) += arch/sh/ramdisk/
70
71# Boards 63# Boards
72machdir-$(CONFIG_SH_SOLUTION_ENGINE) := se/770x 64machdir-$(CONFIG_SH_SOLUTION_ENGINE) := se/770x
73machdir-$(CONFIG_SH_7751_SOLUTION_ENGINE) := se/7751 65machdir-$(CONFIG_SH_7751_SOLUTION_ENGINE) := se/7751
diff --git a/arch/sh/drivers/Makefile b/arch/sh/drivers/Makefile
index bd6726cde398..338c3729d270 100644
--- a/arch/sh/drivers/Makefile
+++ b/arch/sh/drivers/Makefile
@@ -2,6 +2,7 @@
2# Makefile for the Linux SuperH-specific device drivers. 2# Makefile for the Linux SuperH-specific device drivers.
3# 3#
4 4
5obj-$(CONFIG_PCI) += pci/ 5obj-$(CONFIG_PCI) += pci/
6obj-$(CONFIG_SH_DMA) += dma/ 6obj-$(CONFIG_SH_DMA) += dma/
7obj-$(CONFIG_SUPERHYWAY) += superhyway/
7 8
diff --git a/arch/sh/drivers/superhyway/Makefile b/arch/sh/drivers/superhyway/Makefile
new file mode 100644
index 000000000000..5b8e0c7ca3a5
--- /dev/null
+++ b/arch/sh/drivers/superhyway/Makefile
@@ -0,0 +1,6 @@
1#
2# Makefile for the SuperHyway specific kernel interface routines under Linux.
3#
4
5obj-$(CONFIG_CPU_SUBTYPE_SH4_202) += ops-sh4-202.o
6
diff --git a/arch/sh/drivers/superhyway/ops-sh4-202.c b/arch/sh/drivers/superhyway/ops-sh4-202.c
new file mode 100644
index 000000000000..a55c98a9052b
--- /dev/null
+++ b/arch/sh/drivers/superhyway/ops-sh4-202.c
@@ -0,0 +1,171 @@
1/*
2 * arch/sh/drivers/superhyway/ops-sh4-202.c
3 *
4 * SuperHyway bus support for SH4-202
5 *
6 * Copyright (C) 2005 Paul Mundt
7 *
8 * This file is subject to the terms and conditions of the GNU
9 * General Public License. See the file "COPYING" in the main
10 * directory of this archive for more details.
11 */
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/superhyway.h>
15#include <linux/string.h>
16#include <asm/addrspace.h>
17#include <asm/io.h>
18
19#define PHYS_EMI_CBLOCK P4SEGADDR(0x1ec00000)
20#define PHYS_EMI_DBLOCK P4SEGADDR(0x08000000)
21#define PHYS_FEMI_CBLOCK P4SEGADDR(0x1f800000)
22#define PHYS_FEMI_DBLOCK P4SEGADDR(0x00000000)
23
24#define PHYS_EPBR_BLOCK P4SEGADDR(0x1de00000)
25#define PHYS_DMAC_BLOCK P4SEGADDR(0x1fa00000)
26#define PHYS_PBR_BLOCK P4SEGADDR(0x1fc00000)
27
28static struct resource emi_resources[] = {
29 [0] = {
30 .start = PHYS_EMI_CBLOCK,
31 .end = PHYS_EMI_CBLOCK + 0x00300000 - 1,
32 .flags = IORESOURCE_MEM,
33 },
34 [1] = {
35 .start = PHYS_EMI_DBLOCK,
36 .end = PHYS_EMI_DBLOCK + 0x08000000 - 1,
37 .flags = IORESOURCE_MEM,
38 },
39};
40
41static struct superhyway_device emi_device = {
42 .name = "emi",
43 .num_resources = ARRAY_SIZE(emi_resources),
44 .resource = emi_resources,
45};
46
47static struct resource femi_resources[] = {
48 [0] = {
49 .start = PHYS_FEMI_CBLOCK,
50 .end = PHYS_FEMI_CBLOCK + 0x00100000 - 1,
51 .flags = IORESOURCE_MEM,
52 },
53 [1] = {
54 .start = PHYS_FEMI_DBLOCK,
55 .end = PHYS_FEMI_DBLOCK + 0x08000000 - 1,
56 .flags = IORESOURCE_MEM,
57 },
58};
59
60static struct superhyway_device femi_device = {
61 .name = "femi",
62 .num_resources = ARRAY_SIZE(femi_resources),
63 .resource = femi_resources,
64};
65
66static struct resource epbr_resources[] = {
67 [0] = {
68 .start = P4SEGADDR(0x1e7ffff8),
69 .end = P4SEGADDR(0x1e7ffff8 + (sizeof(u32) * 2) - 1),
70 .flags = IORESOURCE_MEM,
71 },
72 [1] = {
73 .start = PHYS_EPBR_BLOCK,
74 .end = PHYS_EPBR_BLOCK + 0x00a00000 - 1,
75 .flags = IORESOURCE_MEM,
76 },
77};
78
79static struct superhyway_device epbr_device = {
80 .name = "epbr",
81 .num_resources = ARRAY_SIZE(epbr_resources),
82 .resource = epbr_resources,
83};
84
85static struct resource dmac_resource = {
86 .start = PHYS_DMAC_BLOCK,
87 .end = PHYS_DMAC_BLOCK + 0x00100000 - 1,
88 .flags = IORESOURCE_MEM,
89};
90
91static struct superhyway_device dmac_device = {
92 .name = "dmac",
93 .num_resources = 1,
94 .resource = &dmac_resource,
95};
96
97static struct resource pbr_resources[] = {
98 [0] = {
99 .start = P4SEGADDR(0x1ffffff8),
100 .end = P4SEGADDR(0x1ffffff8 + (sizeof(u32) * 2) - 1),
101 .flags = IORESOURCE_MEM,
102 },
103 [1] = {
104 .start = PHYS_PBR_BLOCK,
105 .end = PHYS_PBR_BLOCK + 0x00400000 - (sizeof(u32) * 2) - 1,
106 .flags = IORESOURCE_MEM,
107 },
108};
109
110static struct superhyway_device pbr_device = {
111 .name = "pbr",
112 .num_resources = ARRAY_SIZE(pbr_resources),
113 .resource = pbr_resources,
114};
115
116static struct superhyway_device *sh4202_devices[] __initdata = {
117 &emi_device, &femi_device, &epbr_device, &dmac_device, &pbr_device,
118};
119
120static int sh4202_read_vcr(unsigned long base, struct superhyway_vcr_info *vcr)
121{
122 u32 vcrh, vcrl;
123 u64 tmp;
124
125 /*
126 * XXX: Even though the SH4-202 Evaluation Device documentation
127 * indicates that VCRL is mapped first with VCRH at a + 0x04
128 * offset, the opposite seems to be true.
129 *
130 * Some modules (PBR and ePBR for instance) also appear to have
131 * VCRL/VCRH flipped in the documentation, but on the SH4-202
132 * itself it appears that these are all consistently mapped with
133 * VCRH preceeding VCRL.
134 *
135 * Do not trust the documentation, for it is evil.
136 */
137 vcrh = ctrl_inl(base);
138 vcrl = ctrl_inl(base + sizeof(u32));
139
140 tmp = ((u64)vcrh << 32) | vcrl;
141 memcpy(vcr, &tmp, sizeof(u64));
142
143 return 0;
144}
145
146static int sh4202_write_vcr(unsigned long base, struct superhyway_vcr_info vcr)
147{
148 u64 tmp = *(u64 *)&vcr;
149
150 ctrl_outl((tmp >> 32) & 0xffffffff, base);
151 ctrl_outl(tmp & 0xffffffff, base + sizeof(u32));
152
153 return 0;
154}
155
156static struct superhyway_ops sh4202_superhyway_ops = {
157 .read_vcr = sh4202_read_vcr,
158 .write_vcr = sh4202_write_vcr,
159};
160
161struct superhyway_bus superhyway_channels[] = {
162 { &sh4202_superhyway_ops, },
163 { 0, },
164};
165
166int __init superhyway_scan_bus(struct superhyway_bus *bus)
167{
168 return superhyway_add_devices(bus, sh4202_devices,
169 ARRAY_SIZE(sh4202_devices));
170}
171
diff --git a/arch/sh/kernel/ptrace.c b/arch/sh/kernel/ptrace.c
index 1fbe5a428e31..1a8be06519ec 100644
--- a/arch/sh/kernel/ptrace.c
+++ b/arch/sh/kernel/ptrace.c
@@ -80,48 +80,11 @@ void ptrace_disable(struct task_struct *child)
80 /* nothing to do.. */ 80 /* nothing to do.. */
81} 81}
82 82
83asmlinkage long sys_ptrace(long request, long pid, long addr, long data) 83long arch_ptrace(struct task_struct *child, long request, long addr, long data)
84{ 84{
85 struct task_struct *child;
86 struct user * dummy = NULL; 85 struct user * dummy = NULL;
87 int ret; 86 int ret;
88 87
89 lock_kernel();
90 ret = -EPERM;
91 if (request == PTRACE_TRACEME) {
92 /* are we already being traced? */
93 if (current->ptrace & PT_PTRACED)
94 goto out;
95 ret = security_ptrace(current->parent, current);
96 if (ret)
97 goto out;
98 /* set the ptrace bit in the process flags. */
99 current->ptrace |= PT_PTRACED;
100 ret = 0;
101 goto out;
102 }
103 ret = -ESRCH;
104 read_lock(&tasklist_lock);
105 child = find_task_by_pid(pid);
106 if (child)
107 get_task_struct(child);
108 read_unlock(&tasklist_lock);
109 if (!child)
110 goto out;
111
112 ret = -EPERM;
113 if (pid == 1) /* you may not mess with init */
114 goto out_tsk;
115
116 if (request == PTRACE_ATTACH) {
117 ret = ptrace_attach(child);
118 goto out_tsk;
119 }
120
121 ret = ptrace_check_attach(child, request == PTRACE_KILL);
122 if (ret < 0)
123 goto out_tsk;
124
125 switch (request) { 88 switch (request) {
126 /* when I and D space are separate, these will need to be fixed. */ 89 /* when I and D space are separate, these will need to be fixed. */
127 case PTRACE_PEEKTEXT: /* read word at location addr. */ 90 case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -289,10 +252,7 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
289 ret = ptrace_request(child, request, addr, data); 252 ret = ptrace_request(child, request, addr, data);
290 break; 253 break;
291 } 254 }
292out_tsk: 255
293 put_task_struct(child);
294out:
295 unlock_kernel();
296 return ret; 256 return ret;
297} 257}
298 258
diff --git a/arch/sh/kernel/setup.c b/arch/sh/kernel/setup.c
index 25b9d9ebe858..036050b377cd 100644
--- a/arch/sh/kernel/setup.c
+++ b/arch/sh/kernel/setup.c
@@ -83,9 +83,9 @@ static struct sh_machine_vector* __init get_mv_byname(const char* name);
83/* ... */ 83/* ... */
84#define COMMAND_LINE ((char *) (PARAM+0x100)) 84#define COMMAND_LINE ((char *) (PARAM+0x100))
85 85
86#define RAMDISK_IMAGE_START_MASK 0x07FF 86#define RAMDISK_IMAGE_START_MASK 0x07FF
87#define RAMDISK_PROMPT_FLAG 0x8000 87#define RAMDISK_PROMPT_FLAG 0x8000
88#define RAMDISK_LOAD_FLAG 0x4000 88#define RAMDISK_LOAD_FLAG 0x4000
89 89
90static char command_line[COMMAND_LINE_SIZE] = { 0, }; 90static char command_line[COMMAND_LINE_SIZE] = { 0, };
91 91
@@ -284,18 +284,6 @@ void __init setup_arch(char **cmdline_p)
284#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) 284#define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
285#define PFN_PHYS(x) ((x) << PAGE_SHIFT) 285#define PFN_PHYS(x) ((x) << PAGE_SHIFT)
286 286
287#ifdef CONFIG_DISCONTIGMEM
288 NODE_DATA(0)->bdata = &discontig_node_bdata[0];
289 NODE_DATA(1)->bdata = &discontig_node_bdata[1];
290
291 bootmap_size = init_bootmem_node(NODE_DATA(1),
292 PFN_UP(__MEMORY_START_2ND),
293 PFN_UP(__MEMORY_START_2ND),
294 PFN_DOWN(__MEMORY_START_2ND+__MEMORY_SIZE_2ND));
295 free_bootmem_node(NODE_DATA(1), __MEMORY_START_2ND, __MEMORY_SIZE_2ND);
296 reserve_bootmem_node(NODE_DATA(1), __MEMORY_START_2ND, bootmap_size);
297#endif
298
299 /* 287 /*
300 * Find the highest page frame number we have available 288 * Find the highest page frame number we have available
301 */ 289 */
@@ -306,10 +294,10 @@ void __init setup_arch(char **cmdline_p)
306 */ 294 */
307 max_low_pfn = max_pfn; 295 max_low_pfn = max_pfn;
308 296
309 /* 297 /*
310 * Partially used pages are not usable - thus 298 * Partially used pages are not usable - thus
311 * we are rounding upwards: 299 * we are rounding upwards:
312 */ 300 */
313 start_pfn = PFN_UP(__pa(_end)); 301 start_pfn = PFN_UP(__pa(_end));
314 302
315 /* 303 /*
@@ -360,12 +348,12 @@ void __init setup_arch(char **cmdline_p)
360 reserve_bootmem_node(NODE_DATA(0), __MEMORY_START, PAGE_SIZE); 348 reserve_bootmem_node(NODE_DATA(0), __MEMORY_START, PAGE_SIZE);
361 349
362#ifdef CONFIG_BLK_DEV_INITRD 350#ifdef CONFIG_BLK_DEV_INITRD
363 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0); 351 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
364 if (&__rd_start != &__rd_end) { 352 if (&__rd_start != &__rd_end) {
365 LOADER_TYPE = 1; 353 LOADER_TYPE = 1;
366 INITRD_START = PHYSADDR((unsigned long)&__rd_start) - __MEMORY_START; 354 INITRD_START = PHYSADDR((unsigned long)&__rd_start) - __MEMORY_START;
367 INITRD_SIZE = (unsigned long)&__rd_end - (unsigned long)&__rd_start; 355 INITRD_SIZE = (unsigned long)&__rd_end - (unsigned long)&__rd_start;
368 } 356 }
369 357
370 if (LOADER_TYPE && INITRD_START) { 358 if (LOADER_TYPE && INITRD_START) {
371 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) { 359 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c
index 4e9c854845a4..e342565f75fb 100644
--- a/arch/sh/mm/init.c
+++ b/arch/sh/mm/init.c
@@ -51,11 +51,6 @@ unsigned long mmu_context_cache = NO_CONTEXT;
51#define MAX_LOW_PFN (NODE_DATA(0)->bdata->node_low_pfn) 51#define MAX_LOW_PFN (NODE_DATA(0)->bdata->node_low_pfn)
52#endif 52#endif
53 53
54#ifdef CONFIG_DISCONTIGMEM
55pg_data_t discontig_page_data[MAX_NUMNODES];
56bootmem_data_t discontig_node_bdata[MAX_NUMNODES];
57#endif
58
59void (*copy_page)(void *from, void *to); 54void (*copy_page)(void *from, void *to);
60void (*clear_page)(void *to); 55void (*clear_page)(void *to);
61 56
@@ -216,15 +211,6 @@ void __init paging_init(void)
216#endif 211#endif
217 NODE_DATA(0)->node_mem_map = NULL; 212 NODE_DATA(0)->node_mem_map = NULL;
218 free_area_init_node(0, NODE_DATA(0), zones_size, __MEMORY_START >> PAGE_SHIFT, 0); 213 free_area_init_node(0, NODE_DATA(0), zones_size, __MEMORY_START >> PAGE_SHIFT, 0);
219
220#ifdef CONFIG_DISCONTIGMEM
221 /*
222 * And for discontig, do some more fixups on the zone sizes..
223 */
224 zones_size[ZONE_DMA] = __MEMORY_SIZE_2ND >> PAGE_SHIFT;
225 zones_size[ZONE_NORMAL] = 0;
226 free_area_init_node(1, NODE_DATA(1), zones_size, __MEMORY_START_2ND >> PAGE_SHIFT, 0);
227#endif
228} 214}
229 215
230void __init mem_init(void) 216void __init mem_init(void)
@@ -248,7 +234,7 @@ void __init mem_init(void)
248 memset(empty_zero_page, 0, PAGE_SIZE); 234 memset(empty_zero_page, 0, PAGE_SIZE);
249 __flush_wback_region(empty_zero_page, PAGE_SIZE); 235 __flush_wback_region(empty_zero_page, PAGE_SIZE);
250 236
251 /* 237 /*
252 * Setup wrappers for copy/clear_page(), these will get overridden 238 * Setup wrappers for copy/clear_page(), these will get overridden
253 * later in the boot process if a better method is available. 239 * later in the boot process if a better method is available.
254 */ 240 */
@@ -257,9 +243,6 @@ void __init mem_init(void)
257 243
258 /* this will put all low memory onto the freelists */ 244 /* this will put all low memory onto the freelists */
259 totalram_pages += free_all_bootmem_node(NODE_DATA(0)); 245 totalram_pages += free_all_bootmem_node(NODE_DATA(0));
260#ifdef CONFIG_DISCONTIGMEM
261 totalram_pages += free_all_bootmem_node(NODE_DATA(1));
262#endif
263 reservedpages = 0; 246 reservedpages = 0;
264 for (tmp = 0; tmp < num_physpages; tmp++) 247 for (tmp = 0; tmp < num_physpages; tmp++)
265 /* 248 /*
@@ -286,7 +269,7 @@ void __init mem_init(void)
286void free_initmem(void) 269void free_initmem(void)
287{ 270{
288 unsigned long addr; 271 unsigned long addr;
289 272
290 addr = (unsigned long)(&__init_begin); 273 addr = (unsigned long)(&__init_begin);
291 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { 274 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
292 ClearPageReserved(virt_to_page(addr)); 275 ClearPageReserved(virt_to_page(addr));
diff --git a/arch/sh/mm/tlb-sh3.c b/arch/sh/mm/tlb-sh3.c
index 7a0d5c10bf20..46b09e26e082 100644
--- a/arch/sh/mm/tlb-sh3.c
+++ b/arch/sh/mm/tlb-sh3.c
@@ -40,12 +40,17 @@ void update_mmu_cache(struct vm_area_struct * vma,
40 return; 40 return;
41 41
42#if defined(CONFIG_SH7705_CACHE_32KB) 42#if defined(CONFIG_SH7705_CACHE_32KB)
43 struct page *page; 43 {
44 page = pte_page(pte); 44 struct page *page = pte_page(pte);
45 if (VALID_PAGE(page) && !test_bit(PG_mapped, &page->flags)) { 45 unsigned long pfn = pte_pfn(pte);
46 unsigned long phys = pte_val(pte) & PTE_PHYS_MASK; 46
47 __flush_wback_region((void *)P1SEGADDR(phys), PAGE_SIZE); 47 if (pfn_valid(pfn) && !test_bit(PG_mapped, &page->flags)) {
48 __set_bit(PG_mapped, &page->flags); 48 unsigned long phys = pte_val(pte) & PTE_PHYS_MASK;
49
50 __flush_wback_region((void *)P1SEGADDR(phys),
51 PAGE_SIZE);
52 __set_bit(PG_mapped, &page->flags);
53 }
49 } 54 }
50#endif 55#endif
51 56
@@ -80,7 +85,7 @@ void __flush_tlb_page(unsigned long asid, unsigned long page)
80 */ 85 */
81 addr = MMU_TLB_ADDRESS_ARRAY | (page & 0x1F000); 86 addr = MMU_TLB_ADDRESS_ARRAY | (page & 0x1F000);
82 data = (page & 0xfffe0000) | asid; /* VALID bit is off */ 87 data = (page & 0xfffe0000) | asid; /* VALID bit is off */
83 88
84 if ((cpu_data->flags & CPU_HAS_MMU_PAGE_ASSOC)) { 89 if ((cpu_data->flags & CPU_HAS_MMU_PAGE_ASSOC)) {
85 addr |= MMU_PAGE_ASSOC_BIT; 90 addr |= MMU_PAGE_ASSOC_BIT;
86 ways = 1; /* we already know the way .. */ 91 ways = 1; /* we already know the way .. */
diff --git a/arch/sh/ramdisk/Makefile b/arch/sh/ramdisk/Makefile
deleted file mode 100644
index 99e1c68673cf..000000000000
--- a/arch/sh/ramdisk/Makefile
+++ /dev/null
@@ -1,20 +0,0 @@
1#
2# Makefile for a ramdisk image
3#
4
5obj-y += ramdisk.o
6
7
8O_FORMAT = $(shell $(OBJDUMP) -i | head -n 2 | grep elf32)
9img := $(subst ",,$(CONFIG_EMBEDDED_RAMDISK_IMAGE))
10# add $(src) when $(img) is relative
11img := $(subst $(src)//,/,$(src)/$(img))
12
13quiet_cmd_ramdisk = LD $@
14define cmd_ramdisk
15 $(LD) -T $(srctree)/$(src)/ld.script -b binary --oformat $(O_FORMAT) \
16 -o $@ $(img)
17endef
18
19$(obj)/ramdisk.o: $(img) $(srctree)/$(src)/ld.script
20 $(call cmd,ramdisk)
diff --git a/arch/sh/ramdisk/ld.script b/arch/sh/ramdisk/ld.script
deleted file mode 100644
index 94beee248c04..000000000000
--- a/arch/sh/ramdisk/ld.script
+++ /dev/null
@@ -1,9 +0,0 @@
1OUTPUT_ARCH(sh)
2SECTIONS
3{
4 .initrd :
5 {
6 *(.data)
7 }
8}
9
diff --git a/arch/sh64/kernel/ptrace.c b/arch/sh64/kernel/ptrace.c
index 71f2eec00b99..cd22e9471316 100644
--- a/arch/sh64/kernel/ptrace.c
+++ b/arch/sh64/kernel/ptrace.c
@@ -28,6 +28,7 @@
28#include <linux/ptrace.h> 28#include <linux/ptrace.h>
29#include <linux/user.h> 29#include <linux/user.h>
30#include <linux/signal.h> 30#include <linux/signal.h>
31#include <linux/syscalls.h>
31 32
32#include <asm/io.h> 33#include <asm/io.h>
33#include <asm/uaccess.h> 34#include <asm/uaccess.h>
@@ -121,61 +122,11 @@ put_fpu_long(struct task_struct *task, unsigned long addr, unsigned long data)
121 return 0; 122 return 0;
122} 123}
123 124
124asmlinkage long sys_ptrace(long request, long pid, long addr, long data) 125
126long arch_ptrace(struct task_struct *child, long request, long addr, long data)
125{ 127{
126 struct task_struct *child;
127 extern void poke_real_address_q(unsigned long long addr, unsigned long long data);
128#define WPC_DBRMODE 0x0d104008
129 static int first_call = 1;
130 int ret; 128 int ret;
131 129
132 lock_kernel();
133
134 if (first_call) {
135 /* Set WPC.DBRMODE to 0. This makes all debug events get
136 * delivered through RESVEC, i.e. into the handlers in entry.S.
137 * (If the kernel was downloaded using a remote gdb, WPC.DBRMODE
138 * would normally be left set to 1, which makes debug events get
139 * delivered through DBRVEC, i.e. into the remote gdb's
140 * handlers. This prevents ptrace getting them, and confuses
141 * the remote gdb.) */
142 printk("DBRMODE set to 0 to permit native debugging\n");
143 poke_real_address_q(WPC_DBRMODE, 0);
144 first_call = 0;
145 }
146
147 ret = -EPERM;
148 if (request == PTRACE_TRACEME) {
149 /* are we already being traced? */
150 if (current->ptrace & PT_PTRACED)
151 goto out;
152 /* set the ptrace bit in the process flags. */
153 current->ptrace |= PT_PTRACED;
154 ret = 0;
155 goto out;
156 }
157 ret = -ESRCH;
158 read_lock(&tasklist_lock);
159 child = find_task_by_pid(pid);
160 if (child)
161 get_task_struct(child);
162 read_unlock(&tasklist_lock);
163 if (!child)
164 goto out;
165
166 ret = -EPERM;
167 if (pid == 1) /* you may not mess with init */
168 goto out_tsk;
169
170 if (request == PTRACE_ATTACH) {
171 ret = ptrace_attach(child);
172 goto out_tsk;
173 }
174
175 ret = ptrace_check_attach(child, request == PTRACE_KILL);
176 if (ret < 0)
177 goto out_tsk;
178
179 switch (request) { 130 switch (request) {
180 /* when I and D space are separate, these will need to be fixed. */ 131 /* when I and D space are separate, these will need to be fixed. */
181 case PTRACE_PEEKTEXT: /* read word at location addr. */ 132 case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -313,13 +264,33 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
313 ret = ptrace_request(child, request, addr, data); 264 ret = ptrace_request(child, request, addr, data);
314 break; 265 break;
315 } 266 }
316out_tsk:
317 put_task_struct(child);
318out:
319 unlock_kernel();
320 return ret; 267 return ret;
321} 268}
322 269
270asmlinkage int sh64_ptrace(long request, long pid, long addr, long data)
271{
272 extern void poke_real_address_q(unsigned long long addr, unsigned long long data);
273#define WPC_DBRMODE 0x0d104008
274 static int first_call = 1;
275
276 lock_kernel();
277 if (first_call) {
278 /* Set WPC.DBRMODE to 0. This makes all debug events get
279 * delivered through RESVEC, i.e. into the handlers in entry.S.
280 * (If the kernel was downloaded using a remote gdb, WPC.DBRMODE
281 * would normally be left set to 1, which makes debug events get
282 * delivered through DBRVEC, i.e. into the remote gdb's
283 * handlers. This prevents ptrace getting them, and confuses
284 * the remote gdb.) */
285 printk("DBRMODE set to 0 to permit native debugging\n");
286 poke_real_address_q(WPC_DBRMODE, 0);
287 first_call = 0;
288 }
289 unlock_kernel();
290
291 return sys_ptrace(request, pid, addr, data);
292}
293
323asmlinkage void syscall_trace(void) 294asmlinkage void syscall_trace(void)
324{ 295{
325 struct task_struct *tsk = current; 296 struct task_struct *tsk = current;
diff --git a/arch/sh64/kernel/syscalls.S b/arch/sh64/kernel/syscalls.S
index a3d037805f1c..c0079d54c850 100644
--- a/arch/sh64/kernel/syscalls.S
+++ b/arch/sh64/kernel/syscalls.S
@@ -46,7 +46,7 @@ sys_call_table:
46 .long sys_setuid16 46 .long sys_setuid16
47 .long sys_getuid16 47 .long sys_getuid16
48 .long sys_stime /* 25 */ 48 .long sys_stime /* 25 */
49 .long sys_ptrace 49 .long sh64_ptrace
50 .long sys_alarm 50 .long sys_alarm
51 .long sys_fstat 51 .long sys_fstat
52 .long sys_pause 52 .long sys_pause
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 6537445dac0e..3cfb8be3ff6d 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -201,6 +201,14 @@ config SUN_OPENPROMFS
201 Only choose N if you know in advance that you will not need to modify 201 Only choose N if you know in advance that you will not need to modify
202 OpenPROM settings on the running system. 202 OpenPROM settings on the running system.
203 203
204config SPARC_LED
205 tristate "Sun4m LED driver"
206 help
207 This driver toggles the front-panel LED on sun4m systems
208 in a user-specifyable manner. It's state can be probed
209 by reading /proc/led and it's blinking mode can be changed
210 via writes to /proc/led
211
204source "fs/Kconfig.binfmt" 212source "fs/Kconfig.binfmt"
205 213
206config SUNOS_EMUL 214config SUNOS_EMUL
diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
index 3d22ba2af01c..1b83e21841b5 100644
--- a/arch/sparc/kernel/Makefile
+++ b/arch/sparc/kernel/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_SUN_AUXIO) += auxio.o
21obj-$(CONFIG_PCI) += ebus.o 21obj-$(CONFIG_PCI) += ebus.o
22obj-$(CONFIG_SUN_PM) += apc.o pmc.o 22obj-$(CONFIG_SUN_PM) += apc.o pmc.o
23obj-$(CONFIG_MODULES) += module.o sparc_ksyms.o 23obj-$(CONFIG_MODULES) += module.o sparc_ksyms.o
24obj-$(CONFIG_SPARC_LED) += led.o
24 25
25ifdef CONFIG_SUNOS_EMUL 26ifdef CONFIG_SUNOS_EMUL
26obj-y += sys_sunos.o sunos_ioctl.o 27obj-y += sys_sunos.o sunos_ioctl.o
diff --git a/arch/sparc/kernel/led.c b/arch/sparc/kernel/led.c
new file mode 100644
index 000000000000..2a3afca453c9
--- /dev/null
+++ b/arch/sparc/kernel/led.c
@@ -0,0 +1,139 @@
1#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/init.h>
4#include <linux/proc_fs.h>
5#include <linux/string.h>
6
7#include <asm/auxio.h>
8
9#define LED_MAX_LENGTH 8 /* maximum chars written to proc file */
10
11static inline void led_toggle(void)
12{
13 unsigned char val = get_auxio();
14 unsigned char on, off;
15
16 if (val & AUXIO_LED) {
17 on = 0;
18 off = AUXIO_LED;
19 } else {
20 on = AUXIO_LED;
21 off = 0;
22 }
23
24 set_auxio(on, off);
25}
26
27static struct timer_list led_blink_timer;
28
29static void led_blink(unsigned long timeout)
30{
31 led_toggle();
32
33 /* reschedule */
34 if (!timeout) { /* blink according to load */
35 led_blink_timer.expires = jiffies +
36 ((1 + (avenrun[0] >> FSHIFT)) * HZ);
37 led_blink_timer.data = 0;
38 } else { /* blink at user specified interval */
39 led_blink_timer.expires = jiffies + (timeout * HZ);
40 led_blink_timer.data = timeout;
41 }
42 add_timer(&led_blink_timer);
43}
44
45static int led_read_proc(char *buf, char **start, off_t offset, int count,
46 int *eof, void *data)
47{
48 int len = 0;
49
50 if (get_auxio() & AUXIO_LED)
51 len = sprintf(buf, "on\n");
52 else
53 len = sprintf(buf, "off\n");
54
55 return len;
56}
57
58static int led_write_proc(struct file *file, const char *buffer,
59 unsigned long count, void *data)
60{
61 char *buf = NULL;
62
63 if (count > LED_MAX_LENGTH)
64 count = LED_MAX_LENGTH;
65
66 buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL);
67 if (!buf)
68 return -ENOMEM;
69
70 if (copy_from_user(buf, buffer, count)) {
71 kfree(buf);
72 return -EFAULT;
73 }
74
75 buf[count] = '\0';
76
77 /* work around \n when echo'ing into proc */
78 if (buf[count - 1] == '\n')
79 buf[count - 1] = '\0';
80
81 /* before we change anything we want to stop any running timers,
82 * otherwise calls such as on will have no persistent effect
83 */
84 del_timer_sync(&led_blink_timer);
85
86 if (!strcmp(buf, "on")) {
87 auxio_set_led(AUXIO_LED_ON);
88 } else if (!strcmp(buf, "toggle")) {
89 led_toggle();
90 } else if ((*buf > '0') && (*buf <= '9')) {
91 led_blink(simple_strtoul(buf, NULL, 10));
92 } else if (!strcmp(buf, "load")) {
93 led_blink(0);
94 } else {
95 auxio_set_led(AUXIO_LED_OFF);
96 }
97
98 kfree(buf);
99
100 return count;
101}
102
103static struct proc_dir_entry *led;
104
105#define LED_VERSION "0.1"
106
107static int __init led_init(void)
108{
109 init_timer(&led_blink_timer);
110 led_blink_timer.function = led_blink;
111
112 led = create_proc_entry("led", 0, NULL);
113 if (!led)
114 return -ENOMEM;
115
116 led->read_proc = led_read_proc; /* reader function */
117 led->write_proc = led_write_proc; /* writer function */
118 led->owner = THIS_MODULE;
119
120 printk(KERN_INFO
121 "led: version %s, Lars Kotthoff <metalhead@metalhead.ws>\n",
122 LED_VERSION);
123
124 return 0;
125}
126
127static void __exit led_exit(void)
128{
129 remove_proc_entry("led", NULL);
130 del_timer_sync(&led_blink_timer);
131}
132
133module_init(led_init);
134module_exit(led_exit);
135
136MODULE_AUTHOR("Lars Kotthoff <metalhead@metalhead.ws>");
137MODULE_DESCRIPTION("Provides control of the front LED on SPARC systems.");
138MODULE_LICENSE("GPL");
139MODULE_VERSION(LED_VERSION);
diff --git a/arch/sparc/kernel/sunos_ioctl.c b/arch/sparc/kernel/sunos_ioctl.c
index df1c0b31a930..a6ba3d26222c 100644
--- a/arch/sparc/kernel/sunos_ioctl.c
+++ b/arch/sparc/kernel/sunos_ioctl.c
@@ -23,7 +23,6 @@
23#include <linux/smp_lock.h> 23#include <linux/smp_lock.h>
24#include <linux/syscalls.h> 24#include <linux/syscalls.h>
25#include <linux/file.h> 25#include <linux/file.h>
26#include <asm/kbio.h>
27 26
28#if 0 27#if 0
29extern char sunkbd_type; 28extern char sunkbd_type;
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index 1e9d8638a28a..3fded69b1922 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -377,8 +377,21 @@ source "drivers/fc4/Kconfig"
377 377
378source "fs/Kconfig" 378source "fs/Kconfig"
379 379
380menu "Instrumentation Support"
381 depends on EXPERIMENTAL
382
380source "arch/sparc64/oprofile/Kconfig" 383source "arch/sparc64/oprofile/Kconfig"
381 384
385config KPROBES
386 bool "Kprobes (EXPERIMENTAL)"
387 help
388 Kprobes allows you to trap at almost any kernel address and
389 execute a callback function. register_kprobe() establishes
390 a probepoint and specifies the callback. Kprobes is useful
391 for kernel debugging, non-intrusive instrumentation and testing.
392 If in doubt, say "N".
393endmenu
394
382source "arch/sparc64/Kconfig.debug" 395source "arch/sparc64/Kconfig.debug"
383 396
384source "security/Kconfig" 397source "security/Kconfig"
diff --git a/arch/sparc64/Kconfig.debug b/arch/sparc64/Kconfig.debug
index fa06ea04837b..3e31be494e54 100644
--- a/arch/sparc64/Kconfig.debug
+++ b/arch/sparc64/Kconfig.debug
@@ -11,16 +11,6 @@ config DEBUG_STACK_USAGE
11 11
12 This option will slow down process creation somewhat. 12 This option will slow down process creation somewhat.
13 13
14config KPROBES
15 bool "Kprobes"
16 depends on DEBUG_KERNEL
17 help
18 Kprobes allows you to trap at almost any kernel address and
19 execute a callback function. register_kprobe() establishes
20 a probepoint and specifies the callback. Kprobes is useful
21 for kernel debugging, non-intrusive instrumentation and testing.
22 If in doubt, say "N".
23
24config DEBUG_DCFLUSH 14config DEBUG_DCFLUSH
25 bool "D-cache flush debugging" 15 bool "D-cache flush debugging"
26 depends on DEBUG_KERNEL 16 depends on DEBUG_KERNEL
diff --git a/arch/sparc64/kernel/ioctl32.c b/arch/sparc64/kernel/ioctl32.c
index e6a00325075a..92e26304de90 100644
--- a/arch/sparc64/kernel/ioctl32.c
+++ b/arch/sparc64/kernel/ioctl32.c
@@ -11,33 +11,14 @@
11 11
12#define INCLUDES 12#define INCLUDES
13#include "compat_ioctl.c" 13#include "compat_ioctl.c"
14#include <linux/ncp_fs.h>
15#include <linux/syscalls.h> 14#include <linux/syscalls.h>
16#include <asm/fbio.h> 15#include <asm/fbio.h>
17#include <asm/kbio.h>
18#include <asm/vuid_event.h>
19#include <asm/envctrl.h>
20#include <asm/display7seg.h>
21#include <asm/openpromio.h>
22#include <asm/audioio.h>
23#include <asm/watchdog.h>
24 16
25/* Use this to get at 32-bit user passed pointers. 17/* Use this to get at 32-bit user passed pointers.
26 * See sys_sparc32.c for description about it. 18 * See sys_sparc32.c for description about it.
27 */ 19 */
28#define A(__x) compat_ptr(__x) 20#define A(__x) compat_ptr(__x)
29 21
30static __inline__ void *alloc_user_space(long len)
31{
32 struct pt_regs *regs = current_thread_info()->kregs;
33 unsigned long usp = regs->u_regs[UREG_I6];
34
35 if (!(test_thread_flag(TIF_32BIT)))
36 usp += STACK_BIAS;
37
38 return (void *) (usp - len);
39}
40
41#define CODE 22#define CODE
42#include "compat_ioctl.c" 23#include "compat_ioctl.c"
43 24
@@ -111,357 +92,6 @@ static int fbiogscursor(unsigned int fd, unsigned int cmd, unsigned long arg)
111 return sys_ioctl (fd, FBIOSCURSOR, (unsigned long)p); 92 return sys_ioctl (fd, FBIOSCURSOR, (unsigned long)p);
112} 93}
113 94
114#if defined(CONFIG_DRM) || defined(CONFIG_DRM_MODULE)
115/* This really belongs in include/linux/drm.h -DaveM */
116#include "../../../drivers/char/drm/drm.h"
117
118typedef struct drm32_version {
119 int version_major; /* Major version */
120 int version_minor; /* Minor version */
121 int version_patchlevel;/* Patch level */
122 int name_len; /* Length of name buffer */
123 u32 name; /* Name of driver */
124 int date_len; /* Length of date buffer */
125 u32 date; /* User-space buffer to hold date */
126 int desc_len; /* Length of desc buffer */
127 u32 desc; /* User-space buffer to hold desc */
128} drm32_version_t;
129#define DRM32_IOCTL_VERSION DRM_IOWR(0x00, drm32_version_t)
130
131static int drm32_version(unsigned int fd, unsigned int cmd, unsigned long arg)
132{
133 drm32_version_t __user *uversion = (drm32_version_t __user *)arg;
134 drm_version_t __user *p = compat_alloc_user_space(sizeof(*p));
135 compat_uptr_t addr;
136 int n;
137 int ret;
138
139 if (clear_user(p, 3 * sizeof(int)) ||
140 get_user(n, &uversion->name_len) ||
141 put_user(n, &p->name_len) ||
142 get_user(addr, &uversion->name) ||
143 put_user(compat_ptr(addr), &p->name) ||
144 get_user(n, &uversion->date_len) ||
145 put_user(n, &p->date_len) ||
146 get_user(addr, &uversion->date) ||
147 put_user(compat_ptr(addr), &p->date) ||
148 get_user(n, &uversion->desc_len) ||
149 put_user(n, &p->desc_len) ||
150 get_user(addr, &uversion->desc) ||
151 put_user(compat_ptr(addr), &p->desc))
152 return -EFAULT;
153
154 ret = sys_ioctl(fd, DRM_IOCTL_VERSION, (unsigned long)p);
155 if (ret)
156 return ret;
157
158 if (copy_in_user(uversion, p, 3 * sizeof(int)) ||
159 get_user(n, &p->name_len) ||
160 put_user(n, &uversion->name_len) ||
161 get_user(n, &p->date_len) ||
162 put_user(n, &uversion->date_len) ||
163 get_user(n, &p->desc_len) ||
164 put_user(n, &uversion->desc_len))
165 return -EFAULT;
166
167 return 0;
168}
169
170typedef struct drm32_unique {
171 int unique_len; /* Length of unique */
172 u32 unique; /* Unique name for driver instantiation */
173} drm32_unique_t;
174#define DRM32_IOCTL_GET_UNIQUE DRM_IOWR(0x01, drm32_unique_t)
175#define DRM32_IOCTL_SET_UNIQUE DRM_IOW( 0x10, drm32_unique_t)
176
177static int drm32_getsetunique(unsigned int fd, unsigned int cmd, unsigned long arg)
178{
179 drm32_unique_t __user *uarg = (drm32_unique_t __user *)arg;
180 drm_unique_t __user *p = compat_alloc_user_space(sizeof(*p));
181 compat_uptr_t addr;
182 int n;
183 int ret;
184
185 if (get_user(n, &uarg->unique_len) ||
186 put_user(n, &p->unique_len) ||
187 get_user(addr, &uarg->unique) ||
188 put_user(compat_ptr(addr), &p->unique))
189 return -EFAULT;
190
191 if (cmd == DRM32_IOCTL_GET_UNIQUE)
192 ret = sys_ioctl (fd, DRM_IOCTL_GET_UNIQUE, (unsigned long)p);
193 else
194 ret = sys_ioctl (fd, DRM_IOCTL_SET_UNIQUE, (unsigned long)p);
195
196 if (ret)
197 return ret;
198
199 if (get_user(n, &p->unique_len) || put_user(n, &uarg->unique_len))
200 return -EFAULT;
201
202 return 0;
203}
204
205typedef struct drm32_map {
206 u32 offset; /* Requested physical address (0 for SAREA)*/
207 u32 size; /* Requested physical size (bytes) */
208 drm_map_type_t type; /* Type of memory to map */
209 drm_map_flags_t flags; /* Flags */
210 u32 handle; /* User-space: "Handle" to pass to mmap */
211 /* Kernel-space: kernel-virtual address */
212 int mtrr; /* MTRR slot used */
213 /* Private data */
214} drm32_map_t;
215#define DRM32_IOCTL_ADD_MAP DRM_IOWR(0x15, drm32_map_t)
216
217static int drm32_addmap(unsigned int fd, unsigned int cmd, unsigned long arg)
218{
219 drm32_map_t __user *uarg = (drm32_map_t __user *) arg;
220 drm_map_t karg;
221 mm_segment_t old_fs;
222 u32 tmp;
223 int ret;
224
225 ret = get_user(karg.offset, &uarg->offset);
226 ret |= get_user(karg.size, &uarg->size);
227 ret |= get_user(karg.type, &uarg->type);
228 ret |= get_user(karg.flags, &uarg->flags);
229 ret |= get_user(tmp, &uarg->handle);
230 ret |= get_user(karg.mtrr, &uarg->mtrr);
231 if (ret)
232 return -EFAULT;
233
234 karg.handle = (void *) (unsigned long) tmp;
235
236 old_fs = get_fs();
237 set_fs(KERNEL_DS);
238 ret = sys_ioctl(fd, DRM_IOCTL_ADD_MAP, (unsigned long) &karg);
239 set_fs(old_fs);
240
241 if (!ret) {
242 ret = put_user(karg.offset, &uarg->offset);
243 ret |= put_user(karg.size, &uarg->size);
244 ret |= put_user(karg.type, &uarg->type);
245 ret |= put_user(karg.flags, &uarg->flags);
246 tmp = (u32) (long)karg.handle;
247 ret |= put_user(tmp, &uarg->handle);
248 ret |= put_user(karg.mtrr, &uarg->mtrr);
249 if (ret)
250 ret = -EFAULT;
251 }
252
253 return ret;
254}
255
256typedef struct drm32_buf_info {
257 int count; /* Entries in list */
258 u32 list; /* (drm_buf_desc_t *) */
259} drm32_buf_info_t;
260#define DRM32_IOCTL_INFO_BUFS DRM_IOWR(0x18, drm32_buf_info_t)
261
262static int drm32_info_bufs(unsigned int fd, unsigned int cmd, unsigned long arg)
263{
264 drm32_buf_info_t __user *uarg = (drm32_buf_info_t __user *)arg;
265 drm_buf_info_t __user *p = compat_alloc_user_space(sizeof(*p));
266 compat_uptr_t addr;
267 int n;
268 int ret;
269
270 if (get_user(n, &uarg->count) || put_user(n, &p->count) ||
271 get_user(addr, &uarg->list) || put_user(compat_ptr(addr), &p->list))
272 return -EFAULT;
273
274 ret = sys_ioctl(fd, DRM_IOCTL_INFO_BUFS, (unsigned long)p);
275 if (ret)
276 return ret;
277
278 if (get_user(n, &p->count) || put_user(n, &uarg->count))
279 return -EFAULT;
280
281 return 0;
282}
283
284typedef struct drm32_buf_free {
285 int count;
286 u32 list; /* (int *) */
287} drm32_buf_free_t;
288#define DRM32_IOCTL_FREE_BUFS DRM_IOW( 0x1a, drm32_buf_free_t)
289
290static int drm32_free_bufs(unsigned int fd, unsigned int cmd, unsigned long arg)
291{
292 drm32_buf_free_t __user *uarg = (drm32_buf_free_t __user *)arg;
293 drm_buf_free_t __user *p = compat_alloc_user_space(sizeof(*p));
294 compat_uptr_t addr;
295 int n;
296
297 if (get_user(n, &uarg->count) || put_user(n, &p->count) ||
298 get_user(addr, &uarg->list) || put_user(compat_ptr(addr), &p->list))
299 return -EFAULT;
300
301 return sys_ioctl(fd, DRM_IOCTL_FREE_BUFS, (unsigned long)p);
302}
303
304typedef struct drm32_buf_pub {
305 int idx; /* Index into master buflist */
306 int total; /* Buffer size */
307 int used; /* Amount of buffer in use (for DMA) */
308 u32 address; /* Address of buffer (void *) */
309} drm32_buf_pub_t;
310
311typedef struct drm32_buf_map {
312 int count; /* Length of buflist */
313 u32 virtual; /* Mmaped area in user-virtual (void *) */
314 u32 list; /* Buffer information (drm_buf_pub_t *) */
315} drm32_buf_map_t;
316#define DRM32_IOCTL_MAP_BUFS DRM_IOWR(0x19, drm32_buf_map_t)
317
318static int drm32_map_bufs(unsigned int fd, unsigned int cmd, unsigned long arg)
319{
320 drm32_buf_map_t __user *uarg = (drm32_buf_map_t __user *)arg;
321 drm32_buf_pub_t __user *ulist;
322 drm_buf_map_t __user *arg64;
323 drm_buf_pub_t __user *list;
324 int orig_count, ret, i;
325 int n;
326 compat_uptr_t addr;
327
328 if (get_user(orig_count, &uarg->count))
329 return -EFAULT;
330
331 arg64 = compat_alloc_user_space(sizeof(drm_buf_map_t) +
332 (size_t)orig_count * sizeof(drm_buf_pub_t));
333 list = (void __user *)(arg64 + 1);
334
335 if (put_user(orig_count, &arg64->count) ||
336 put_user(list, &arg64->list) ||
337 get_user(addr, &uarg->virtual) ||
338 put_user(compat_ptr(addr), &arg64->virtual) ||
339 get_user(addr, &uarg->list))
340 return -EFAULT;
341
342 ulist = compat_ptr(addr);
343
344 for (i = 0; i < orig_count; i++) {
345 if (get_user(n, &ulist[i].idx) ||
346 put_user(n, &list[i].idx) ||
347 get_user(n, &ulist[i].total) ||
348 put_user(n, &list[i].total) ||
349 get_user(n, &ulist[i].used) ||
350 put_user(n, &list[i].used) ||
351 get_user(addr, &ulist[i].address) ||
352 put_user(compat_ptr(addr), &list[i].address))
353 return -EFAULT;
354 }
355
356 ret = sys_ioctl(fd, DRM_IOCTL_MAP_BUFS, (unsigned long) arg64);
357 if (ret)
358 return ret;
359
360 for (i = 0; i < orig_count; i++) {
361 void __user *p;
362 if (get_user(n, &list[i].idx) ||
363 put_user(n, &ulist[i].idx) ||
364 get_user(n, &list[i].total) ||
365 put_user(n, &ulist[i].total) ||
366 get_user(n, &list[i].used) ||
367 put_user(n, &ulist[i].used) ||
368 get_user(p, &list[i].address) ||
369 put_user((unsigned long)p, &ulist[i].address))
370 return -EFAULT;
371 }
372
373 if (get_user(n, &arg64->count) || put_user(n, &uarg->count))
374 return -EFAULT;
375
376 return 0;
377}
378
379typedef struct drm32_dma {
380 /* Indices here refer to the offset into
381 buflist in drm_buf_get_t. */
382 int context; /* Context handle */
383 int send_count; /* Number of buffers to send */
384 u32 send_indices; /* List of handles to buffers (int *) */
385 u32 send_sizes; /* Lengths of data to send (int *) */
386 drm_dma_flags_t flags; /* Flags */
387 int request_count; /* Number of buffers requested */
388 int request_size; /* Desired size for buffers */
389 u32 request_indices; /* Buffer information (int *) */
390 u32 request_sizes; /* (int *) */
391 int granted_count; /* Number of buffers granted */
392} drm32_dma_t;
393#define DRM32_IOCTL_DMA DRM_IOWR(0x29, drm32_dma_t)
394
395/* RED PEN The DRM layer blindly dereferences the send/request
396 * index/size arrays even though they are userland
397 * pointers. -DaveM
398 */
399static int drm32_dma(unsigned int fd, unsigned int cmd, unsigned long arg)
400{
401 drm32_dma_t __user *uarg = (drm32_dma_t __user *) arg;
402 drm_dma_t __user *p = compat_alloc_user_space(sizeof(*p));
403 compat_uptr_t addr;
404 int ret;
405
406 if (copy_in_user(p, uarg, 2 * sizeof(int)) ||
407 get_user(addr, &uarg->send_indices) ||
408 put_user(compat_ptr(addr), &p->send_indices) ||
409 get_user(addr, &uarg->send_sizes) ||
410 put_user(compat_ptr(addr), &p->send_sizes) ||
411 copy_in_user(&p->flags, &uarg->flags, sizeof(drm_dma_flags_t)) ||
412 copy_in_user(&p->request_count, &uarg->request_count, sizeof(int))||
413 copy_in_user(&p->request_size, &uarg->request_size, sizeof(int)) ||
414 get_user(addr, &uarg->request_indices) ||
415 put_user(compat_ptr(addr), &p->request_indices) ||
416 get_user(addr, &uarg->request_sizes) ||
417 put_user(compat_ptr(addr), &p->request_sizes) ||
418 copy_in_user(&p->granted_count, &uarg->granted_count, sizeof(int)))
419 return -EFAULT;
420
421 ret = sys_ioctl(fd, DRM_IOCTL_DMA, (unsigned long)p);
422 if (ret)
423 return ret;
424
425 if (copy_in_user(uarg, p, 2 * sizeof(int)) ||
426 copy_in_user(&uarg->flags, &p->flags, sizeof(drm_dma_flags_t)) ||
427 copy_in_user(&uarg->request_count, &p->request_count, sizeof(int))||
428 copy_in_user(&uarg->request_size, &p->request_size, sizeof(int)) ||
429 copy_in_user(&uarg->granted_count, &p->granted_count, sizeof(int)))
430 return -EFAULT;
431
432 return 0;
433}
434
435typedef struct drm32_ctx_res {
436 int count;
437 u32 contexts; /* (drm_ctx_t *) */
438} drm32_ctx_res_t;
439#define DRM32_IOCTL_RES_CTX DRM_IOWR(0x26, drm32_ctx_res_t)
440
441static int drm32_res_ctx(unsigned int fd, unsigned int cmd, unsigned long arg)
442{
443 drm32_ctx_res_t __user *uarg = (drm32_ctx_res_t __user *) arg;
444 drm_ctx_res_t __user *p = compat_alloc_user_space(sizeof(*p));
445 compat_uptr_t addr;
446 int ret;
447
448 if (copy_in_user(p, uarg, sizeof(int)) ||
449 get_user(addr, &uarg->contexts) ||
450 put_user(compat_ptr(addr), &p->contexts))
451 return -EFAULT;
452
453 ret = sys_ioctl(fd, DRM_IOCTL_RES_CTX, (unsigned long)p);
454 if (ret)
455 return ret;
456
457 if (copy_in_user(uarg, p, sizeof(int)))
458 return -EFAULT;
459
460 return 0;
461}
462
463#endif
464
465typedef int (* ioctl32_handler_t)(unsigned int, unsigned int, unsigned long, struct file *); 95typedef int (* ioctl32_handler_t)(unsigned int, unsigned int, unsigned long, struct file *);
466 96
467#define COMPATIBLE_IOCTL(cmd) HANDLE_IOCTL((cmd),sys_ioctl) 97#define COMPATIBLE_IOCTL(cmd) HANDLE_IOCTL((cmd),sys_ioctl)
@@ -485,103 +115,14 @@ COMPATIBLE_IOCTL(FBIOSCURPOS)
485COMPATIBLE_IOCTL(FBIOGCURPOS) 115COMPATIBLE_IOCTL(FBIOGCURPOS)
486COMPATIBLE_IOCTL(FBIOGCURMAX) 116COMPATIBLE_IOCTL(FBIOGCURMAX)
487/* Little k */ 117/* Little k */
488COMPATIBLE_IOCTL(KIOCTYPE)
489COMPATIBLE_IOCTL(KIOCLAYOUT)
490COMPATIBLE_IOCTL(KIOCGTRANS)
491COMPATIBLE_IOCTL(KIOCTRANS)
492COMPATIBLE_IOCTL(KIOCCMD)
493COMPATIBLE_IOCTL(KIOCSDIRECT)
494COMPATIBLE_IOCTL(KIOCSLED)
495COMPATIBLE_IOCTL(KIOCGLED)
496COMPATIBLE_IOCTL(KIOCSRATE)
497COMPATIBLE_IOCTL(KIOCGRATE)
498COMPATIBLE_IOCTL(VUIDSFORMAT)
499COMPATIBLE_IOCTL(VUIDGFORMAT)
500/* Little v, the video4linux ioctls */ 118/* Little v, the video4linux ioctls */
501COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */ 119COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */
502COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */ 120COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */
503COMPATIBLE_IOCTL(ENVCTRL_RD_WARNING_TEMPERATURE)
504COMPATIBLE_IOCTL(ENVCTRL_RD_SHUTDOWN_TEMPERATURE)
505COMPATIBLE_IOCTL(ENVCTRL_RD_CPU_TEMPERATURE)
506COMPATIBLE_IOCTL(ENVCTRL_RD_FAN_STATUS)
507COMPATIBLE_IOCTL(ENVCTRL_RD_VOLTAGE_STATUS)
508COMPATIBLE_IOCTL(ENVCTRL_RD_SCSI_TEMPERATURE)
509COMPATIBLE_IOCTL(ENVCTRL_RD_ETHERNET_TEMPERATURE)
510COMPATIBLE_IOCTL(ENVCTRL_RD_MTHRBD_TEMPERATURE)
511COMPATIBLE_IOCTL(ENVCTRL_RD_CPU_VOLTAGE)
512COMPATIBLE_IOCTL(ENVCTRL_RD_GLOBALADDRESS)
513/* COMPATIBLE_IOCTL(D7SIOCRD) same value as ENVCTRL_RD_VOLTAGE_STATUS */
514COMPATIBLE_IOCTL(D7SIOCWR)
515COMPATIBLE_IOCTL(D7SIOCTM)
516/* OPENPROMIO, SunOS/Solaris only, the NetBSD one's have
517 * embedded pointers in the arg which we'd need to clean up...
518 */
519COMPATIBLE_IOCTL(OPROMGETOPT)
520COMPATIBLE_IOCTL(OPROMSETOPT)
521COMPATIBLE_IOCTL(OPROMNXTOPT)
522COMPATIBLE_IOCTL(OPROMSETOPT2)
523COMPATIBLE_IOCTL(OPROMNEXT)
524COMPATIBLE_IOCTL(OPROMCHILD)
525COMPATIBLE_IOCTL(OPROMGETPROP)
526COMPATIBLE_IOCTL(OPROMNXTPROP)
527COMPATIBLE_IOCTL(OPROMU2P)
528COMPATIBLE_IOCTL(OPROMGETCONS)
529COMPATIBLE_IOCTL(OPROMGETFBNAME)
530COMPATIBLE_IOCTL(OPROMGETBOOTARGS)
531COMPATIBLE_IOCTL(OPROMSETCUR)
532COMPATIBLE_IOCTL(OPROMPCI2NODE)
533COMPATIBLE_IOCTL(OPROMPATH2NODE)
534/* Big L */
535COMPATIBLE_IOCTL(LOOP_SET_STATUS64)
536COMPATIBLE_IOCTL(LOOP_GET_STATUS64)
537/* Big A */
538COMPATIBLE_IOCTL(AUDIO_GETINFO)
539COMPATIBLE_IOCTL(AUDIO_SETINFO)
540COMPATIBLE_IOCTL(AUDIO_DRAIN)
541COMPATIBLE_IOCTL(AUDIO_GETDEV)
542COMPATIBLE_IOCTL(AUDIO_GETDEV_SUNOS)
543COMPATIBLE_IOCTL(AUDIO_FLUSH)
544COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
545#if defined(CONFIG_DRM) || defined(CONFIG_DRM_MODULE)
546COMPATIBLE_IOCTL(DRM_IOCTL_GET_MAGIC)
547COMPATIBLE_IOCTL(DRM_IOCTL_IRQ_BUSID)
548COMPATIBLE_IOCTL(DRM_IOCTL_AUTH_MAGIC)
549COMPATIBLE_IOCTL(DRM_IOCTL_BLOCK)
550COMPATIBLE_IOCTL(DRM_IOCTL_UNBLOCK)
551COMPATIBLE_IOCTL(DRM_IOCTL_CONTROL)
552COMPATIBLE_IOCTL(DRM_IOCTL_ADD_BUFS)
553COMPATIBLE_IOCTL(DRM_IOCTL_MARK_BUFS)
554COMPATIBLE_IOCTL(DRM_IOCTL_ADD_CTX)
555COMPATIBLE_IOCTL(DRM_IOCTL_RM_CTX)
556COMPATIBLE_IOCTL(DRM_IOCTL_MOD_CTX)
557COMPATIBLE_IOCTL(DRM_IOCTL_GET_CTX)
558COMPATIBLE_IOCTL(DRM_IOCTL_SWITCH_CTX)
559COMPATIBLE_IOCTL(DRM_IOCTL_NEW_CTX)
560COMPATIBLE_IOCTL(DRM_IOCTL_ADD_DRAW)
561COMPATIBLE_IOCTL(DRM_IOCTL_RM_DRAW)
562COMPATIBLE_IOCTL(DRM_IOCTL_LOCK)
563COMPATIBLE_IOCTL(DRM_IOCTL_UNLOCK)
564COMPATIBLE_IOCTL(DRM_IOCTL_FINISH)
565#endif /* DRM */
566COMPATIBLE_IOCTL(WIOCSTART)
567COMPATIBLE_IOCTL(WIOCSTOP)
568COMPATIBLE_IOCTL(WIOCGSTAT)
569/* And these ioctls need translation */ 121/* And these ioctls need translation */
570/* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */ 122/* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
571HANDLE_IOCTL(FBIOPUTCMAP32, fbiogetputcmap) 123HANDLE_IOCTL(FBIOPUTCMAP32, fbiogetputcmap)
572HANDLE_IOCTL(FBIOGETCMAP32, fbiogetputcmap) 124HANDLE_IOCTL(FBIOGETCMAP32, fbiogetputcmap)
573HANDLE_IOCTL(FBIOSCURSOR32, fbiogscursor) 125HANDLE_IOCTL(FBIOSCURSOR32, fbiogscursor)
574#if defined(CONFIG_DRM) || defined(CONFIG_DRM_MODULE)
575HANDLE_IOCTL(DRM32_IOCTL_VERSION, drm32_version)
576HANDLE_IOCTL(DRM32_IOCTL_GET_UNIQUE, drm32_getsetunique)
577HANDLE_IOCTL(DRM32_IOCTL_SET_UNIQUE, drm32_getsetunique)
578HANDLE_IOCTL(DRM32_IOCTL_ADD_MAP, drm32_addmap)
579HANDLE_IOCTL(DRM32_IOCTL_INFO_BUFS, drm32_info_bufs)
580HANDLE_IOCTL(DRM32_IOCTL_FREE_BUFS, drm32_free_bufs)
581HANDLE_IOCTL(DRM32_IOCTL_MAP_BUFS, drm32_map_bufs)
582HANDLE_IOCTL(DRM32_IOCTL_DMA, drm32_dma)
583HANDLE_IOCTL(DRM32_IOCTL_RES_CTX, drm32_res_ctx)
584#endif /* DRM */
585#if 0 126#if 0
586HANDLE_IOCTL(RTC32_IRQP_READ, do_rtc_ioctl) 127HANDLE_IOCTL(RTC32_IRQP_READ, do_rtc_ioctl)
587HANDLE_IOCTL(RTC32_IRQP_SET, do_rtc_ioctl) 128HANDLE_IOCTL(RTC32_IRQP_SET, do_rtc_ioctl)
diff --git a/arch/sparc64/kernel/kprobes.c b/arch/sparc64/kernel/kprobes.c
index 0d66d07c8c6e..96bd09b098f4 100644
--- a/arch/sparc64/kernel/kprobes.c
+++ b/arch/sparc64/kernel/kprobes.c
@@ -38,6 +38,9 @@
38 * - Mark that we are no longer actively in a kprobe. 38 * - Mark that we are no longer actively in a kprobe.
39 */ 39 */
40 40
41DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
42DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
43
41int __kprobes arch_prepare_kprobe(struct kprobe *p) 44int __kprobes arch_prepare_kprobe(struct kprobe *p)
42{ 45{
43 return 0; 46 return 0;
@@ -66,46 +69,39 @@ void __kprobes arch_remove_kprobe(struct kprobe *p)
66{ 69{
67} 70}
68 71
69static struct kprobe *current_kprobe; 72static inline void save_previous_kprobe(struct kprobe_ctlblk *kcb)
70static unsigned long current_kprobe_orig_tnpc;
71static unsigned long current_kprobe_orig_tstate_pil;
72static unsigned int kprobe_status;
73static struct kprobe *kprobe_prev;
74static unsigned long kprobe_orig_tnpc_prev;
75static unsigned long kprobe_orig_tstate_pil_prev;
76static unsigned int kprobe_status_prev;
77
78static inline void save_previous_kprobe(void)
79{ 73{
80 kprobe_status_prev = kprobe_status; 74 kcb->prev_kprobe.kp = kprobe_running();
81 kprobe_orig_tnpc_prev = current_kprobe_orig_tnpc; 75 kcb->prev_kprobe.status = kcb->kprobe_status;
82 kprobe_orig_tstate_pil_prev = current_kprobe_orig_tstate_pil; 76 kcb->prev_kprobe.orig_tnpc = kcb->kprobe_orig_tnpc;
83 kprobe_prev = current_kprobe; 77 kcb->prev_kprobe.orig_tstate_pil = kcb->kprobe_orig_tstate_pil;
84} 78}
85 79
86static inline void restore_previous_kprobe(void) 80static inline void restore_previous_kprobe(struct kprobe_ctlblk *kcb)
87{ 81{
88 kprobe_status = kprobe_status_prev; 82 __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
89 current_kprobe_orig_tnpc = kprobe_orig_tnpc_prev; 83 kcb->kprobe_status = kcb->prev_kprobe.status;
90 current_kprobe_orig_tstate_pil = kprobe_orig_tstate_pil_prev; 84 kcb->kprobe_orig_tnpc = kcb->prev_kprobe.orig_tnpc;
91 current_kprobe = kprobe_prev; 85 kcb->kprobe_orig_tstate_pil = kcb->prev_kprobe.orig_tstate_pil;
92} 86}
93 87
94static inline void set_current_kprobe(struct kprobe *p, struct pt_regs *regs) 88static inline void set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
89 struct kprobe_ctlblk *kcb)
95{ 90{
96 current_kprobe_orig_tnpc = regs->tnpc; 91 __get_cpu_var(current_kprobe) = p;
97 current_kprobe_orig_tstate_pil = (regs->tstate & TSTATE_PIL); 92 kcb->kprobe_orig_tnpc = regs->tnpc;
98 current_kprobe = p; 93 kcb->kprobe_orig_tstate_pil = (regs->tstate & TSTATE_PIL);
99} 94}
100 95
101static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs) 96static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs,
97 struct kprobe_ctlblk *kcb)
102{ 98{
103 regs->tstate |= TSTATE_PIL; 99 regs->tstate |= TSTATE_PIL;
104 100
105 /*single step inline, if it a breakpoint instruction*/ 101 /*single step inline, if it a breakpoint instruction*/
106 if (p->opcode == BREAKPOINT_INSTRUCTION) { 102 if (p->opcode == BREAKPOINT_INSTRUCTION) {
107 regs->tpc = (unsigned long) p->addr; 103 regs->tpc = (unsigned long) p->addr;
108 regs->tnpc = current_kprobe_orig_tnpc; 104 regs->tnpc = kcb->kprobe_orig_tnpc;
109 } else { 105 } else {
110 regs->tpc = (unsigned long) &p->ainsn.insn[0]; 106 regs->tpc = (unsigned long) &p->ainsn.insn[0];
111 regs->tnpc = (unsigned long) &p->ainsn.insn[1]; 107 regs->tnpc = (unsigned long) &p->ainsn.insn[1];
@@ -117,19 +113,21 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
117 struct kprobe *p; 113 struct kprobe *p;
118 void *addr = (void *) regs->tpc; 114 void *addr = (void *) regs->tpc;
119 int ret = 0; 115 int ret = 0;
116 struct kprobe_ctlblk *kcb;
120 117
118 /*
119 * We don't want to be preempted for the entire
120 * duration of kprobe processing
121 */
121 preempt_disable(); 122 preempt_disable();
123 kcb = get_kprobe_ctlblk();
122 124
123 if (kprobe_running()) { 125 if (kprobe_running()) {
124 /* We *are* holding lock here, so this is safe.
125 * Disarm the probe we just hit, and ignore it.
126 */
127 p = get_kprobe(addr); 126 p = get_kprobe(addr);
128 if (p) { 127 if (p) {
129 if (kprobe_status == KPROBE_HIT_SS) { 128 if (kcb->kprobe_status == KPROBE_HIT_SS) {
130 regs->tstate = ((regs->tstate & ~TSTATE_PIL) | 129 regs->tstate = ((regs->tstate & ~TSTATE_PIL) |
131 current_kprobe_orig_tstate_pil); 130 kcb->kprobe_orig_tstate_pil);
132 unlock_kprobes();
133 goto no_kprobe; 131 goto no_kprobe;
134 } 132 }
135 /* We have reentered the kprobe_handler(), since 133 /* We have reentered the kprobe_handler(), since
@@ -138,25 +136,22 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
138 * just single step on the instruction of the new probe 136 * just single step on the instruction of the new probe
139 * without calling any user handlers. 137 * without calling any user handlers.
140 */ 138 */
141 save_previous_kprobe(); 139 save_previous_kprobe(kcb);
142 set_current_kprobe(p, regs); 140 set_current_kprobe(p, regs, kcb);
143 p->nmissed++; 141 p->nmissed++;
144 kprobe_status = KPROBE_REENTER; 142 kcb->kprobe_status = KPROBE_REENTER;
145 prepare_singlestep(p, regs); 143 prepare_singlestep(p, regs, kcb);
146 return 1; 144 return 1;
147 } else { 145 } else {
148 p = current_kprobe; 146 p = __get_cpu_var(current_kprobe);
149 if (p->break_handler && p->break_handler(p, regs)) 147 if (p->break_handler && p->break_handler(p, regs))
150 goto ss_probe; 148 goto ss_probe;
151 } 149 }
152 /* If it's not ours, can't be delete race, (we hold lock). */
153 goto no_kprobe; 150 goto no_kprobe;
154 } 151 }
155 152
156 lock_kprobes();
157 p = get_kprobe(addr); 153 p = get_kprobe(addr);
158 if (!p) { 154 if (!p) {
159 unlock_kprobes();
160 if (*(u32 *)addr != BREAKPOINT_INSTRUCTION) { 155 if (*(u32 *)addr != BREAKPOINT_INSTRUCTION) {
161 /* 156 /*
162 * The breakpoint instruction was removed right 157 * The breakpoint instruction was removed right
@@ -171,14 +166,14 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
171 goto no_kprobe; 166 goto no_kprobe;
172 } 167 }
173 168
174 set_current_kprobe(p, regs); 169 set_current_kprobe(p, regs, kcb);
175 kprobe_status = KPROBE_HIT_ACTIVE; 170 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
176 if (p->pre_handler && p->pre_handler(p, regs)) 171 if (p->pre_handler && p->pre_handler(p, regs))
177 return 1; 172 return 1;
178 173
179ss_probe: 174ss_probe:
180 prepare_singlestep(p, regs); 175 prepare_singlestep(p, regs, kcb);
181 kprobe_status = KPROBE_HIT_SS; 176 kcb->kprobe_status = KPROBE_HIT_SS;
182 return 1; 177 return 1;
183 178
184no_kprobe: 179no_kprobe:
@@ -260,11 +255,12 @@ static void __kprobes retpc_fixup(struct pt_regs *regs, u32 insn,
260 * This function prepares to return from the post-single-step 255 * This function prepares to return from the post-single-step
261 * breakpoint trap. 256 * breakpoint trap.
262 */ 257 */
263static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs) 258static void __kprobes resume_execution(struct kprobe *p,
259 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
264{ 260{
265 u32 insn = p->ainsn.insn[0]; 261 u32 insn = p->ainsn.insn[0];
266 262
267 regs->tpc = current_kprobe_orig_tnpc; 263 regs->tpc = kcb->kprobe_orig_tnpc;
268 regs->tnpc = relbranch_fixup(insn, 264 regs->tnpc = relbranch_fixup(insn,
269 (unsigned long) p->addr, 265 (unsigned long) p->addr,
270 (unsigned long) &p->ainsn.insn[0], 266 (unsigned long) &p->ainsn.insn[0],
@@ -272,44 +268,48 @@ static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
272 retpc_fixup(regs, insn, (unsigned long) p->addr); 268 retpc_fixup(regs, insn, (unsigned long) p->addr);
273 269
274 regs->tstate = ((regs->tstate & ~TSTATE_PIL) | 270 regs->tstate = ((regs->tstate & ~TSTATE_PIL) |
275 current_kprobe_orig_tstate_pil); 271 kcb->kprobe_orig_tstate_pil);
276} 272}
277 273
278static inline int post_kprobe_handler(struct pt_regs *regs) 274static inline int post_kprobe_handler(struct pt_regs *regs)
279{ 275{
280 if (!kprobe_running()) 276 struct kprobe *cur = kprobe_running();
277 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
278
279 if (!cur)
281 return 0; 280 return 0;
282 281
283 if ((kprobe_status != KPROBE_REENTER) && current_kprobe->post_handler) { 282 if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
284 kprobe_status = KPROBE_HIT_SSDONE; 283 kcb->kprobe_status = KPROBE_HIT_SSDONE;
285 current_kprobe->post_handler(current_kprobe, regs, 0); 284 cur->post_handler(cur, regs, 0);
286 } 285 }
287 286
288 resume_execution(current_kprobe, regs); 287 resume_execution(cur, regs, kcb);
289 288
290 /*Restore back the original saved kprobes variables and continue. */ 289 /*Restore back the original saved kprobes variables and continue. */
291 if (kprobe_status == KPROBE_REENTER) { 290 if (kcb->kprobe_status == KPROBE_REENTER) {
292 restore_previous_kprobe(); 291 restore_previous_kprobe(kcb);
293 goto out; 292 goto out;
294 } 293 }
295 unlock_kprobes(); 294 reset_current_kprobe();
296out: 295out:
297 preempt_enable_no_resched(); 296 preempt_enable_no_resched();
298 297
299 return 1; 298 return 1;
300} 299}
301 300
302/* Interrupts disabled, kprobe_lock held. */
303static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr) 301static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
304{ 302{
305 if (current_kprobe->fault_handler 303 struct kprobe *cur = kprobe_running();
306 && current_kprobe->fault_handler(current_kprobe, regs, trapnr)) 304 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
305
306 if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
307 return 1; 307 return 1;
308 308
309 if (kprobe_status & KPROBE_HIT_SS) { 309 if (kcb->kprobe_status & KPROBE_HIT_SS) {
310 resume_execution(current_kprobe, regs); 310 resume_execution(cur, regs, kcb);
311 311
312 unlock_kprobes(); 312 reset_current_kprobe();
313 preempt_enable_no_resched(); 313 preempt_enable_no_resched();
314 } 314 }
315 return 0; 315 return 0;
@@ -322,29 +322,30 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
322 unsigned long val, void *data) 322 unsigned long val, void *data)
323{ 323{
324 struct die_args *args = (struct die_args *)data; 324 struct die_args *args = (struct die_args *)data;
325 int ret = NOTIFY_DONE;
326
325 switch (val) { 327 switch (val) {
326 case DIE_DEBUG: 328 case DIE_DEBUG:
327 if (kprobe_handler(args->regs)) 329 if (kprobe_handler(args->regs))
328 return NOTIFY_STOP; 330 ret = NOTIFY_STOP;
329 break; 331 break;
330 case DIE_DEBUG_2: 332 case DIE_DEBUG_2:
331 if (post_kprobe_handler(args->regs)) 333 if (post_kprobe_handler(args->regs))
332 return NOTIFY_STOP; 334 ret = NOTIFY_STOP;
333 break; 335 break;
334 case DIE_GPF: 336 case DIE_GPF:
335 if (kprobe_running() &&
336 kprobe_fault_handler(args->regs, args->trapnr))
337 return NOTIFY_STOP;
338 break;
339 case DIE_PAGE_FAULT: 337 case DIE_PAGE_FAULT:
338 /* kprobe_running() needs smp_processor_id() */
339 preempt_disable();
340 if (kprobe_running() && 340 if (kprobe_running() &&
341 kprobe_fault_handler(args->regs, args->trapnr)) 341 kprobe_fault_handler(args->regs, args->trapnr))
342 return NOTIFY_STOP; 342 ret = NOTIFY_STOP;
343 preempt_enable();
343 break; 344 break;
344 default: 345 default:
345 break; 346 break;
346 } 347 }
347 return NOTIFY_DONE; 348 return ret;
348} 349}
349 350
350asmlinkage void __kprobes kprobe_trap(unsigned long trap_level, 351asmlinkage void __kprobes kprobe_trap(unsigned long trap_level,
@@ -368,24 +369,21 @@ asmlinkage void __kprobes kprobe_trap(unsigned long trap_level,
368} 369}
369 370
370/* Jprobes support. */ 371/* Jprobes support. */
371static struct pt_regs jprobe_saved_regs;
372static struct pt_regs *jprobe_saved_regs_location;
373static struct sparc_stackf jprobe_saved_stack;
374
375int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) 372int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
376{ 373{
377 struct jprobe *jp = container_of(p, struct jprobe, kp); 374 struct jprobe *jp = container_of(p, struct jprobe, kp);
375 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
378 376
379 jprobe_saved_regs_location = regs; 377 kcb->jprobe_saved_regs_location = regs;
380 memcpy(&jprobe_saved_regs, regs, sizeof(*regs)); 378 memcpy(&(kcb->jprobe_saved_regs), regs, sizeof(*regs));
381 379
382 /* Save a whole stack frame, this gets arguments 380 /* Save a whole stack frame, this gets arguments
383 * pushed onto the stack after using up all the 381 * pushed onto the stack after using up all the
384 * arg registers. 382 * arg registers.
385 */ 383 */
386 memcpy(&jprobe_saved_stack, 384 memcpy(&(kcb->jprobe_saved_stack),
387 (char *) (regs->u_regs[UREG_FP] + STACK_BIAS), 385 (char *) (regs->u_regs[UREG_FP] + STACK_BIAS),
388 sizeof(jprobe_saved_stack)); 386 sizeof(kcb->jprobe_saved_stack));
389 387
390 regs->tpc = (unsigned long) jp->entry; 388 regs->tpc = (unsigned long) jp->entry;
391 regs->tnpc = ((unsigned long) jp->entry) + 0x4UL; 389 regs->tnpc = ((unsigned long) jp->entry) + 0x4UL;
@@ -396,7 +394,6 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
396 394
397void __kprobes jprobe_return(void) 395void __kprobes jprobe_return(void)
398{ 396{
399 preempt_enable_no_resched();
400 __asm__ __volatile__( 397 __asm__ __volatile__(
401 ".globl jprobe_return_trap_instruction\n" 398 ".globl jprobe_return_trap_instruction\n"
402"jprobe_return_trap_instruction:\n\t" 399"jprobe_return_trap_instruction:\n\t"
@@ -410,14 +407,15 @@ extern void __show_regs(struct pt_regs * regs);
410int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) 407int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
411{ 408{
412 u32 *addr = (u32 *) regs->tpc; 409 u32 *addr = (u32 *) regs->tpc;
410 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
413 411
414 if (addr == (u32 *) jprobe_return_trap_instruction) { 412 if (addr == (u32 *) jprobe_return_trap_instruction) {
415 if (jprobe_saved_regs_location != regs) { 413 if (kcb->jprobe_saved_regs_location != regs) {
416 printk("JPROBE: Current regs (%p) does not match " 414 printk("JPROBE: Current regs (%p) does not match "
417 "saved regs (%p).\n", 415 "saved regs (%p).\n",
418 regs, jprobe_saved_regs_location); 416 regs, kcb->jprobe_saved_regs_location);
419 printk("JPROBE: Saved registers\n"); 417 printk("JPROBE: Saved registers\n");
420 __show_regs(jprobe_saved_regs_location); 418 __show_regs(kcb->jprobe_saved_regs_location);
421 printk("JPROBE: Current registers\n"); 419 printk("JPROBE: Current registers\n");
422 __show_regs(regs); 420 __show_regs(regs);
423 BUG(); 421 BUG();
@@ -426,12 +424,13 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
426 * first so that UREG_FP is the original one for 424 * first so that UREG_FP is the original one for
427 * the stack frame restore. 425 * the stack frame restore.
428 */ 426 */
429 memcpy(regs, &jprobe_saved_regs, sizeof(*regs)); 427 memcpy(regs, &(kcb->jprobe_saved_regs), sizeof(*regs));
430 428
431 memcpy((char *) (regs->u_regs[UREG_FP] + STACK_BIAS), 429 memcpy((char *) (regs->u_regs[UREG_FP] + STACK_BIAS),
432 &jprobe_saved_stack, 430 &(kcb->jprobe_saved_stack),
433 sizeof(jprobe_saved_stack)); 431 sizeof(kcb->jprobe_saved_stack));
434 432
433 preempt_enable_no_resched();
435 return 1; 434 return 1;
436 } 435 }
437 return 0; 436 return 0;
diff --git a/arch/sparc64/kernel/setup.c b/arch/sparc64/kernel/setup.c
index c1f34237cdf2..bf1849dd9c49 100644
--- a/arch/sparc64/kernel/setup.c
+++ b/arch/sparc64/kernel/setup.c
@@ -154,6 +154,7 @@ int prom_callback(long *args)
154 pud_t *pudp; 154 pud_t *pudp;
155 pmd_t *pmdp; 155 pmd_t *pmdp;
156 pte_t *ptep; 156 pte_t *ptep;
157 pte_t pte;
157 158
158 for_each_process(p) { 159 for_each_process(p) {
159 mm = p->mm; 160 mm = p->mm;
@@ -178,8 +179,9 @@ int prom_callback(long *args)
178 * being called from inside OBP. 179 * being called from inside OBP.
179 */ 180 */
180 ptep = pte_offset_map(pmdp, va); 181 ptep = pte_offset_map(pmdp, va);
181 if (pte_present(*ptep)) { 182 pte = *ptep;
182 tte = pte_val(*ptep); 183 if (pte_present(pte)) {
184 tte = pte_val(pte);
183 res = PROM_TRUE; 185 res = PROM_TRUE;
184 } 186 }
185 pte_unmap(ptep); 187 pte_unmap(ptep);
@@ -218,6 +220,7 @@ int prom_callback(long *args)
218 pud_t *pudp; 220 pud_t *pudp;
219 pmd_t *pmdp; 221 pmd_t *pmdp;
220 pte_t *ptep; 222 pte_t *ptep;
223 pte_t pte;
221 int error; 224 int error;
222 225
223 if ((va >= LOW_OBP_ADDRESS) && (va < HI_OBP_ADDRESS)) { 226 if ((va >= LOW_OBP_ADDRESS) && (va < HI_OBP_ADDRESS)) {
@@ -240,8 +243,9 @@ int prom_callback(long *args)
240 * being called from inside OBP. 243 * being called from inside OBP.
241 */ 244 */
242 ptep = pte_offset_kernel(pmdp, va); 245 ptep = pte_offset_kernel(pmdp, va);
243 if (pte_present(*ptep)) { 246 pte = *ptep;
244 tte = pte_val(*ptep); 247 if (pte_present(pte)) {
248 tte = pte_val(pte);
245 res = PROM_TRUE; 249 res = PROM_TRUE;
246 } 250 }
247 goto done; 251 goto done;
diff --git a/arch/sparc64/kernel/signal32.c b/arch/sparc64/kernel/signal32.c
index aecccd0df1d1..009a86e5ded4 100644
--- a/arch/sparc64/kernel/signal32.c
+++ b/arch/sparc64/kernel/signal32.c
@@ -863,6 +863,7 @@ static void new_setup_frame32(struct k_sigaction *ka, struct pt_regs *regs,
863 pud_t *pudp = pud_offset(pgdp, address); 863 pud_t *pudp = pud_offset(pgdp, address);
864 pmd_t *pmdp = pmd_offset(pudp, address); 864 pmd_t *pmdp = pmd_offset(pudp, address);
865 pte_t *ptep; 865 pte_t *ptep;
866 pte_t pte;
866 867
867 regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2); 868 regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2);
868 869
@@ -873,9 +874,10 @@ static void new_setup_frame32(struct k_sigaction *ka, struct pt_regs *regs,
873 874
874 preempt_disable(); 875 preempt_disable();
875 ptep = pte_offset_map(pmdp, address); 876 ptep = pte_offset_map(pmdp, address);
876 if (pte_present(*ptep)) { 877 pte = *ptep;
878 if (pte_present(pte)) {
877 unsigned long page = (unsigned long) 879 unsigned long page = (unsigned long)
878 page_address(pte_page(*ptep)); 880 page_address(pte_page(pte));
879 881
880 wmb(); 882 wmb();
881 __asm__ __volatile__("flush %0 + %1" 883 __asm__ __volatile__("flush %0 + %1"
diff --git a/arch/sparc64/kernel/smp.c b/arch/sparc64/kernel/smp.c
index b137fd63f5e1..5d90ee9aebf1 100644
--- a/arch/sparc64/kernel/smp.c
+++ b/arch/sparc64/kernel/smp.c
@@ -839,43 +839,29 @@ void smp_flush_tlb_all(void)
839 * questionable (in theory the big win for threads is the massive sharing of 839 * questionable (in theory the big win for threads is the massive sharing of
840 * address space state across processors). 840 * address space state across processors).
841 */ 841 */
842
843/* This currently is only used by the hugetlb arch pre-fault
844 * hook on UltraSPARC-III+ and later when changing the pagesize
845 * bits of the context register for an address space.
846 */
842void smp_flush_tlb_mm(struct mm_struct *mm) 847void smp_flush_tlb_mm(struct mm_struct *mm)
843{ 848{
844 /* 849 u32 ctx = CTX_HWBITS(mm->context);
845 * This code is called from two places, dup_mmap and exit_mmap. In the 850 int cpu = get_cpu();
846 * former case, we really need a flush. In the later case, the callers
847 * are single threaded exec_mmap (really need a flush), multithreaded
848 * exec_mmap case (do not need to flush, since the caller gets a new
849 * context via activate_mm), and all other callers of mmput() whence
850 * the flush can be optimized since the associated threads are dead and
851 * the mm is being torn down (__exit_mm and other mmput callers) or the
852 * owning thread is dissociating itself from the mm. The
853 * (atomic_read(&mm->mm_users) == 0) check ensures real work is done
854 * for single thread exec and dup_mmap cases. An alternate check might
855 * have been (current->mm != mm).
856 * Kanoj Sarcar
857 */
858 if (atomic_read(&mm->mm_users) == 0)
859 return;
860
861 {
862 u32 ctx = CTX_HWBITS(mm->context);
863 int cpu = get_cpu();
864 851
865 if (atomic_read(&mm->mm_users) == 1) { 852 if (atomic_read(&mm->mm_users) == 1) {
866 mm->cpu_vm_mask = cpumask_of_cpu(cpu); 853 mm->cpu_vm_mask = cpumask_of_cpu(cpu);
867 goto local_flush_and_out; 854 goto local_flush_and_out;
868 } 855 }
869 856
870 smp_cross_call_masked(&xcall_flush_tlb_mm, 857 smp_cross_call_masked(&xcall_flush_tlb_mm,
871 ctx, 0, 0, 858 ctx, 0, 0,
872 mm->cpu_vm_mask); 859 mm->cpu_vm_mask);
873 860
874 local_flush_and_out: 861local_flush_and_out:
875 __flush_tlb_mm(ctx, SECONDARY_CONTEXT); 862 __flush_tlb_mm(ctx, SECONDARY_CONTEXT);
876 863
877 put_cpu(); 864 put_cpu();
878 }
879} 865}
880 866
881void smp_flush_tlb_pending(struct mm_struct *mm, unsigned long nr, unsigned long *vaddrs) 867void smp_flush_tlb_pending(struct mm_struct *mm, unsigned long nr, unsigned long *vaddrs)
@@ -883,34 +869,13 @@ void smp_flush_tlb_pending(struct mm_struct *mm, unsigned long nr, unsigned long
883 u32 ctx = CTX_HWBITS(mm->context); 869 u32 ctx = CTX_HWBITS(mm->context);
884 int cpu = get_cpu(); 870 int cpu = get_cpu();
885 871
886 if (mm == current->active_mm && atomic_read(&mm->mm_users) == 1) { 872 if (mm == current->active_mm && atomic_read(&mm->mm_users) == 1)
887 mm->cpu_vm_mask = cpumask_of_cpu(cpu); 873 mm->cpu_vm_mask = cpumask_of_cpu(cpu);
888 goto local_flush_and_out; 874 else
889 } else { 875 smp_cross_call_masked(&xcall_flush_tlb_pending,
890 /* This optimization is not valid. Normally 876 ctx, nr, (unsigned long) vaddrs,
891 * we will be holding the page_table_lock, but 877 mm->cpu_vm_mask);
892 * there is an exception which is copy_page_range()
893 * when forking. The lock is held during the individual
894 * page table updates in the parent, but not at the
895 * top level, which is where we are invoked.
896 */
897 if (0) {
898 cpumask_t this_cpu_mask = cpumask_of_cpu(cpu);
899
900 /* By virtue of running under the mm->page_table_lock,
901 * and mmu_context.h:switch_mm doing the same, the
902 * following operation is safe.
903 */
904 if (cpus_equal(mm->cpu_vm_mask, this_cpu_mask))
905 goto local_flush_and_out;
906 }
907 }
908
909 smp_cross_call_masked(&xcall_flush_tlb_pending,
910 ctx, nr, (unsigned long) vaddrs,
911 mm->cpu_vm_mask);
912 878
913local_flush_and_out:
914 __flush_tlb_pending(ctx, nr, vaddrs); 879 __flush_tlb_pending(ctx, nr, vaddrs);
915 880
916 put_cpu(); 881 put_cpu();
diff --git a/arch/sparc64/kernel/sunos_ioctl32.c b/arch/sparc64/kernel/sunos_ioctl32.c
index 7654b8a7f03a..3f619ead22cc 100644
--- a/arch/sparc64/kernel/sunos_ioctl32.c
+++ b/arch/sparc64/kernel/sunos_ioctl32.c
@@ -24,7 +24,6 @@
24#include <linux/smp_lock.h> 24#include <linux/smp_lock.h>
25#include <linux/syscalls.h> 25#include <linux/syscalls.h>
26#include <linux/compat.h> 26#include <linux/compat.h>
27#include <asm/kbio.h>
28 27
29#define SUNOS_NR_OPEN 256 28#define SUNOS_NR_OPEN 256
30 29
diff --git a/arch/sparc64/kernel/time.c b/arch/sparc64/kernel/time.c
index 38c5525087a2..459c8fbe02b4 100644
--- a/arch/sparc64/kernel/time.c
+++ b/arch/sparc64/kernel/time.c
@@ -60,17 +60,6 @@ static void __iomem *mstk48t59_regs;
60 60
61static int set_rtc_mmss(unsigned long); 61static int set_rtc_mmss(unsigned long);
62 62
63static __init unsigned long dummy_get_tick(void)
64{
65 return 0;
66}
67
68static __initdata struct sparc64_tick_ops dummy_tick_ops = {
69 .get_tick = dummy_get_tick,
70};
71
72struct sparc64_tick_ops *tick_ops __read_mostly = &dummy_tick_ops;
73
74#define TICK_PRIV_BIT (1UL << 63) 63#define TICK_PRIV_BIT (1UL << 63)
75 64
76#ifdef CONFIG_SMP 65#ifdef CONFIG_SMP
@@ -200,6 +189,8 @@ static struct sparc64_tick_ops tick_operations __read_mostly = {
200 .softint_mask = 1UL << 0, 189 .softint_mask = 1UL << 0,
201}; 190};
202 191
192struct sparc64_tick_ops *tick_ops __read_mostly = &tick_operations;
193
203static void stick_init_tick(unsigned long offset) 194static void stick_init_tick(unsigned long offset)
204{ 195{
205 tick_disable_protection(); 196 tick_disable_protection();
diff --git a/arch/sparc64/kernel/us2e_cpufreq.c b/arch/sparc64/kernel/us2e_cpufreq.c
index 686e526bec04..b35dc8dc995a 100644
--- a/arch/sparc64/kernel/us2e_cpufreq.c
+++ b/arch/sparc64/kernel/us2e_cpufreq.c
@@ -388,10 +388,8 @@ err_out:
388 kfree(driver); 388 kfree(driver);
389 cpufreq_us2e_driver = NULL; 389 cpufreq_us2e_driver = NULL;
390 } 390 }
391 if (us2e_freq_table) { 391 kfree(us2e_freq_table);
392 kfree(us2e_freq_table); 392 us2e_freq_table = NULL;
393 us2e_freq_table = NULL;
394 }
395 return ret; 393 return ret;
396 } 394 }
397 395
@@ -402,7 +400,6 @@ static void __exit us2e_freq_exit(void)
402{ 400{
403 if (cpufreq_us2e_driver) { 401 if (cpufreq_us2e_driver) {
404 cpufreq_unregister_driver(cpufreq_us2e_driver); 402 cpufreq_unregister_driver(cpufreq_us2e_driver);
405
406 kfree(cpufreq_us2e_driver); 403 kfree(cpufreq_us2e_driver);
407 cpufreq_us2e_driver = NULL; 404 cpufreq_us2e_driver = NULL;
408 kfree(us2e_freq_table); 405 kfree(us2e_freq_table);
diff --git a/arch/sparc64/kernel/us3_cpufreq.c b/arch/sparc64/kernel/us3_cpufreq.c
index 0340041f6143..6d1f9a3c464f 100644
--- a/arch/sparc64/kernel/us3_cpufreq.c
+++ b/arch/sparc64/kernel/us3_cpufreq.c
@@ -249,10 +249,8 @@ err_out:
249 kfree(driver); 249 kfree(driver);
250 cpufreq_us3_driver = NULL; 250 cpufreq_us3_driver = NULL;
251 } 251 }
252 if (us3_freq_table) { 252 kfree(us3_freq_table);
253 kfree(us3_freq_table); 253 us3_freq_table = NULL;
254 us3_freq_table = NULL;
255 }
256 return ret; 254 return ret;
257 } 255 }
258 256
@@ -263,7 +261,6 @@ static void __exit us3_freq_exit(void)
263{ 261{
264 if (cpufreq_us3_driver) { 262 if (cpufreq_us3_driver) {
265 cpufreq_unregister_driver(cpufreq_us3_driver); 263 cpufreq_unregister_driver(cpufreq_us3_driver);
266
267 kfree(cpufreq_us3_driver); 264 kfree(cpufreq_us3_driver);
268 cpufreq_us3_driver = NULL; 265 cpufreq_us3_driver = NULL;
269 kfree(us3_freq_table); 266 kfree(us3_freq_table);
diff --git a/arch/sparc64/oprofile/Kconfig b/arch/sparc64/oprofile/Kconfig
index 5ade19801b97..d8a84088471a 100644
--- a/arch/sparc64/oprofile/Kconfig
+++ b/arch/sparc64/oprofile/Kconfig
@@ -1,7 +1,3 @@
1
2menu "Profiling support"
3 depends on EXPERIMENTAL
4
5config PROFILING 1config PROFILING
6 bool "Profiling support (EXPERIMENTAL)" 2 bool "Profiling support (EXPERIMENTAL)"
7 help 3 help
@@ -19,5 +15,3 @@ config OPROFILE
19 15
20 If unsure, say N. 16 If unsure, say N.
21 17
22endmenu
23
diff --git a/arch/um/Kconfig b/arch/um/Kconfig
index cd06ed7d842d..3b5f47c46907 100644
--- a/arch/um/Kconfig
+++ b/arch/um/Kconfig
@@ -65,6 +65,30 @@ config STATIC_LINK
65 chroot, and you disable CONFIG_MODE_TT, you probably want to say Y 65 chroot, and you disable CONFIG_MODE_TT, you probably want to say Y
66 here. 66 here.
67 67
68config HOST_2G_2G
69 bool "2G/2G host address space split"
70 default n
71 depends on MODE_TT
72 help
73 This is needed when the host on which you run has a 2G/2G memory
74 split, instead of the customary 3G/1G.
75
76 Note that to enable such a host
77 configuration, which makes sense only in some cases, you need special
78 host patches.
79
80 So, if you do not know what to do here, say 'N'.
81
82config KERNEL_HALF_GIGS
83 int "Kernel address space size (in .5G units)"
84 default "1"
85 depends on MODE_TT
86 help
87 This determines the amount of address space that UML will allocate for
88 its own, measured in half Gigabyte units. The default is 1.
89 Change this only if you need to boot UML with an unusually large amount
90 of physical memory.
91
68config MODE_SKAS 92config MODE_SKAS
69 bool "Separate Kernel Address Space support" 93 bool "Separate Kernel Address Space support"
70 default y 94 default y
@@ -182,19 +206,6 @@ config MAGIC_SYSRQ
182 The keys are documented in <file:Documentation/sysrq.txt>. Don't say Y 206 The keys are documented in <file:Documentation/sysrq.txt>. Don't say Y
183 unless you really know what this hack does. 207 unless you really know what this hack does.
184 208
185config HOST_2G_2G
186 bool "2G/2G host address space split"
187 default n
188 help
189 This is needed when the host on which you run has a 2G/2G memory
190 split, instead of the customary 3G/1G.
191
192 Note that to enable such a host
193 configuration, which makes sense only in some cases, you need special
194 host patches.
195
196 So, if you do not know what to do here, say 'N'.
197
198config SMP 209config SMP
199 bool "Symmetric multi-processing support (EXPERIMENTAL)" 210 bool "Symmetric multi-processing support (EXPERIMENTAL)"
200 default n 211 default n
@@ -241,15 +252,6 @@ config NEST_LEVEL
241 set to the host's CONFIG_NEST_LEVEL + CONFIG_KERNEL_HALF_GIGS. 252 set to the host's CONFIG_NEST_LEVEL + CONFIG_KERNEL_HALF_GIGS.
242 Only change this if you are running nested UMLs. 253 Only change this if you are running nested UMLs.
243 254
244config KERNEL_HALF_GIGS
245 int "Kernel address space size (in .5G units)"
246 default "1"
247 help
248 This determines the amount of address space that UML will allocate for
249 its own, measured in half Gigabyte units. The default is 1.
250 Change this only if you need to boot UML with an unusually large amount
251 of physical memory.
252
253config HIGHMEM 255config HIGHMEM
254 bool "Highmem support" 256 bool "Highmem support"
255 depends on !64BIT 257 depends on !64BIT
diff --git a/arch/um/Makefile b/arch/um/Makefile
index e1ffad224605..e55d32e903bc 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -60,7 +60,7 @@ AFLAGS += $(ARCH_INCLUDE)
60 60
61USER_CFLAGS := $(patsubst -I%,,$(CFLAGS)) 61USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
62USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \ 62USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
63 $(MODE_INCLUDE) 63 $(MODE_INCLUDE) -D_FILE_OFFSET_BITS=64
64 64
65# -Derrno=kernel_errno - This turns all kernel references to errno into 65# -Derrno=kernel_errno - This turns all kernel references to errno into
66# kernel_errno to separate them from the libc errno. This allows -fno-common 66# kernel_errno to separate them from the libc errno. This allows -fno-common
diff --git a/arch/um/Makefile-i386 b/arch/um/Makefile-i386
index aef7c50f8e13..1f7dcb064aee 100644
--- a/arch/um/Makefile-i386
+++ b/arch/um/Makefile-i386
@@ -17,8 +17,6 @@ ifeq ("$(origin SUBARCH)", "command line")
17ifneq ("$(shell uname -m | sed -e s/i.86/i386/)", "$(SUBARCH)") 17ifneq ("$(shell uname -m | sed -e s/i.86/i386/)", "$(SUBARCH)")
18CFLAGS += $(call cc-option,-m32) 18CFLAGS += $(call cc-option,-m32)
19USER_CFLAGS += $(call cc-option,-m32) 19USER_CFLAGS += $(call cc-option,-m32)
20HOSTCFLAGS += $(call cc-option,-m32)
21HOSTLDFLAGS += $(call cc-option,-m32)
22AFLAGS += $(call cc-option,-m32) 20AFLAGS += $(call cc-option,-m32)
23LINK-y += $(call cc-option,-m32) 21LINK-y += $(call cc-option,-m32)
24UML_OBJCOPYFLAGS += -F $(ELF_FORMAT) 22UML_OBJCOPYFLAGS += -F $(ELF_FORMAT)
diff --git a/arch/um/drivers/chan_user.c b/arch/um/drivers/chan_user.c
index de3bce71aeb3..1c55d5802489 100644
--- a/arch/um/drivers/chan_user.c
+++ b/arch/um/drivers/chan_user.c
@@ -16,7 +16,6 @@
16#include "user_util.h" 16#include "user_util.h"
17#include "chan_user.h" 17#include "chan_user.h"
18#include "user.h" 18#include "user.h"
19#include "helper.h"
20#include "os.h" 19#include "os.h"
21#include "choose-mode.h" 20#include "choose-mode.h"
22#include "mode.h" 21#include "mode.h"
diff --git a/arch/um/drivers/harddog_kern.c b/arch/um/drivers/harddog_kern.c
index 147ec19f6bb9..49acb2badf32 100644
--- a/arch/um/drivers/harddog_kern.c
+++ b/arch/um/drivers/harddog_kern.c
@@ -46,7 +46,6 @@
46#include <linux/smp_lock.h> 46#include <linux/smp_lock.h>
47#include <linux/init.h> 47#include <linux/init.h>
48#include <asm/uaccess.h> 48#include <asm/uaccess.h>
49#include "helper.h"
50#include "mconsole.h" 49#include "mconsole.h"
51 50
52MODULE_LICENSE("GPL"); 51MODULE_LICENSE("GPL");
diff --git a/arch/um/drivers/harddog_user.c b/arch/um/drivers/harddog_user.c
index d934181b8d4c..def013b5a3c7 100644
--- a/arch/um/drivers/harddog_user.c
+++ b/arch/um/drivers/harddog_user.c
@@ -8,7 +8,6 @@
8#include <errno.h> 8#include <errno.h>
9#include "user_util.h" 9#include "user_util.h"
10#include "user.h" 10#include "user.h"
11#include "helper.h"
12#include "mconsole.h" 11#include "mconsole.h"
13#include "os.h" 12#include "os.h"
14#include "choose-mode.h" 13#include "choose-mode.h"
diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
index 721e2601a75d..fe865d9a3721 100644
--- a/arch/um/drivers/net_kern.c
+++ b/arch/um/drivers/net_kern.c
@@ -96,7 +96,6 @@ irqreturn_t uml_net_interrupt(int irq, void *dev_id, struct pt_regs *regs)
96static int uml_net_open(struct net_device *dev) 96static int uml_net_open(struct net_device *dev)
97{ 97{
98 struct uml_net_private *lp = dev->priv; 98 struct uml_net_private *lp = dev->priv;
99 char addr[sizeof("255.255.255.255\0")];
100 int err; 99 int err;
101 100
102 spin_lock(&lp->lock); 101 spin_lock(&lp->lock);
@@ -107,7 +106,7 @@ static int uml_net_open(struct net_device *dev)
107 } 106 }
108 107
109 if(!lp->have_mac){ 108 if(!lp->have_mac){
110 dev_ip_addr(dev, addr, &lp->mac[2]); 109 dev_ip_addr(dev, &lp->mac[2]);
111 set_ether_mac(dev, lp->mac); 110 set_ether_mac(dev, lp->mac);
112 } 111 }
113 112
@@ -664,8 +663,6 @@ static int uml_inetaddr_event(struct notifier_block *this, unsigned long event,
664 void *ptr) 663 void *ptr)
665{ 664{
666 struct in_ifaddr *ifa = ptr; 665 struct in_ifaddr *ifa = ptr;
667 u32 addr = ifa->ifa_address;
668 u32 netmask = ifa->ifa_mask;
669 struct net_device *dev = ifa->ifa_dev->dev; 666 struct net_device *dev = ifa->ifa_dev->dev;
670 struct uml_net_private *lp; 667 struct uml_net_private *lp;
671 void (*proc)(unsigned char *, unsigned char *, void *); 668 void (*proc)(unsigned char *, unsigned char *, void *);
@@ -685,14 +682,8 @@ static int uml_inetaddr_event(struct notifier_block *this, unsigned long event,
685 break; 682 break;
686 } 683 }
687 if(proc != NULL){ 684 if(proc != NULL){
688 addr_buf[0] = addr & 0xff; 685 memcpy(addr_buf, &ifa->ifa_address, sizeof(addr_buf));
689 addr_buf[1] = (addr >> 8) & 0xff; 686 memcpy(netmask_buf, &ifa->ifa_mask, sizeof(netmask_buf));
690 addr_buf[2] = (addr >> 16) & 0xff;
691 addr_buf[3] = addr >> 24;
692 netmask_buf[0] = netmask & 0xff;
693 netmask_buf[1] = (netmask >> 8) & 0xff;
694 netmask_buf[2] = (netmask >> 16) & 0xff;
695 netmask_buf[3] = netmask >> 24;
696 (*proc)(addr_buf, netmask_buf, &lp->user); 687 (*proc)(addr_buf, netmask_buf, &lp->user);
697 } 688 }
698 return(NOTIFY_DONE); 689 return(NOTIFY_DONE);
@@ -774,27 +765,18 @@ int setup_etheraddr(char *str, unsigned char *addr)
774 return(1); 765 return(1);
775} 766}
776 767
777void dev_ip_addr(void *d, char *buf, char *bin_buf) 768void dev_ip_addr(void *d, unsigned char *bin_buf)
778{ 769{
779 struct net_device *dev = d; 770 struct net_device *dev = d;
780 struct in_device *ip = dev->ip_ptr; 771 struct in_device *ip = dev->ip_ptr;
781 struct in_ifaddr *in; 772 struct in_ifaddr *in;
782 u32 addr;
783 773
784 if((ip == NULL) || ((in = ip->ifa_list) == NULL)){ 774 if((ip == NULL) || ((in = ip->ifa_list) == NULL)){
785 printk(KERN_WARNING "dev_ip_addr - device not assigned an " 775 printk(KERN_WARNING "dev_ip_addr - device not assigned an "
786 "IP address\n"); 776 "IP address\n");
787 return; 777 return;
788 } 778 }
789 addr = in->ifa_address; 779 memcpy(bin_buf, &in->ifa_address, sizeof(in->ifa_address));
790 sprintf(buf, "%d.%d.%d.%d", addr & 0xff, (addr >> 8) & 0xff,
791 (addr >> 16) & 0xff, addr >> 24);
792 if(bin_buf){
793 bin_buf[0] = addr & 0xff;
794 bin_buf[1] = (addr >> 8) & 0xff;
795 bin_buf[2] = (addr >> 16) & 0xff;
796 bin_buf[3] = addr >> 24;
797 }
798} 780}
799 781
800void set_ether_mac(void *d, unsigned char *addr) 782void set_ether_mac(void *d, unsigned char *addr)
@@ -829,14 +811,8 @@ void iter_addresses(void *d, void (*cb)(unsigned char *, unsigned char *,
829 if(ip == NULL) return; 811 if(ip == NULL) return;
830 in = ip->ifa_list; 812 in = ip->ifa_list;
831 while(in != NULL){ 813 while(in != NULL){
832 address[0] = in->ifa_address & 0xff; 814 memcpy(address, &in->ifa_address, sizeof(address));
833 address[1] = (in->ifa_address >> 8) & 0xff; 815 memcpy(netmask, &in->ifa_mask, sizeof(netmask));
834 address[2] = (in->ifa_address >> 16) & 0xff;
835 address[3] = in->ifa_address >> 24;
836 netmask[0] = in->ifa_mask & 0xff;
837 netmask[1] = (in->ifa_mask >> 8) & 0xff;
838 netmask[2] = (in->ifa_mask >> 16) & 0xff;
839 netmask[3] = in->ifa_mask >> 24;
840 (*cb)(address, netmask, arg); 816 (*cb)(address, netmask, arg);
841 in = in->ifa_next; 817 in = in->ifa_next;
842 } 818 }
diff --git a/arch/um/drivers/net_user.c b/arch/um/drivers/net_user.c
index 3730d4f12713..098fa65981ab 100644
--- a/arch/um/drivers/net_user.c
+++ b/arch/um/drivers/net_user.c
@@ -16,7 +16,6 @@
16#include "user_util.h" 16#include "user_util.h"
17#include "kern_util.h" 17#include "kern_util.h"
18#include "net_user.h" 18#include "net_user.h"
19#include "helper.h"
20#include "os.h" 19#include "os.h"
21 20
22int tap_open_common(void *dev, char *gate_addr) 21int tap_open_common(void *dev, char *gate_addr)
diff --git a/arch/um/drivers/port_user.c b/arch/um/drivers/port_user.c
index 14dd2002d2da..ed4a1a6c5d83 100644
--- a/arch/um/drivers/port_user.c
+++ b/arch/um/drivers/port_user.c
@@ -18,7 +18,6 @@
18#include "user.h" 18#include "user.h"
19#include "chan_user.h" 19#include "chan_user.h"
20#include "port.h" 20#include "port.h"
21#include "helper.h"
22#include "os.h" 21#include "os.h"
23 22
24struct port_chan { 23struct port_chan {
diff --git a/arch/um/drivers/random.c b/arch/um/drivers/random.c
index f9e22198e011..ba471f5864a6 100644
--- a/arch/um/drivers/random.c
+++ b/arch/um/drivers/random.c
@@ -58,10 +58,8 @@ static ssize_t rng_dev_read (struct file *filp, char __user *buf, size_t size,
58 if (filp->f_flags & O_NONBLOCK) 58 if (filp->f_flags & O_NONBLOCK)
59 return ret ? : -EAGAIN; 59 return ret ? : -EAGAIN;
60 60
61 if(need_resched()){ 61 if(need_resched())
62 current->state = TASK_INTERRUPTIBLE; 62 schedule_timeout_interruptible(1);
63 schedule_timeout(1);
64 }
65 } 63 }
66 else return n; 64 else return n;
67 if (signal_pending (current)) 65 if (signal_pending (current))
diff --git a/arch/um/drivers/slip_user.c b/arch/um/drivers/slip_user.c
index 71af444e591f..89fbec185cc1 100644
--- a/arch/um/drivers/slip_user.c
+++ b/arch/um/drivers/slip_user.c
@@ -14,7 +14,6 @@
14#include "net_user.h" 14#include "net_user.h"
15#include "slip.h" 15#include "slip.h"
16#include "slip_common.h" 16#include "slip_common.h"
17#include "helper.h"
18#include "os.h" 17#include "os.h"
19 18
20void slip_user_init(void *data, void *dev) 19void slip_user_init(void *data, void *dev)
diff --git a/arch/um/drivers/slirp_user.c b/arch/um/drivers/slirp_user.c
index 8d91f663d82c..b94c66114bc8 100644
--- a/arch/um/drivers/slirp_user.c
+++ b/arch/um/drivers/slirp_user.c
@@ -13,7 +13,6 @@
13#include "net_user.h" 13#include "net_user.h"
14#include "slirp.h" 14#include "slirp.h"
15#include "slip_common.h" 15#include "slip_common.h"
16#include "helper.h"
17#include "os.h" 16#include "os.h"
18 17
19void slirp_user_init(void *data, void *dev) 18void slirp_user_init(void *data, void *dev)
diff --git a/arch/um/drivers/xterm.c b/arch/um/drivers/xterm.c
index 90e0e5ff451e..b530f1a6540d 100644
--- a/arch/um/drivers/xterm.c
+++ b/arch/um/drivers/xterm.c
@@ -14,7 +14,6 @@
14#include <sys/socket.h> 14#include <sys/socket.h>
15#include "kern_util.h" 15#include "kern_util.h"
16#include "chan_user.h" 16#include "chan_user.h"
17#include "helper.h"
18#include "user_util.h" 17#include "user_util.h"
19#include "user.h" 18#include "user.h"
20#include "os.h" 19#include "os.h"
diff --git a/arch/um/include/helper.h b/arch/um/include/helper.h
deleted file mode 100644
index 162ac31192fd..000000000000
--- a/arch/um/include/helper.h
+++ /dev/null
@@ -1,27 +0,0 @@
1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __HELPER_H__
7#define __HELPER_H__
8
9extern int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv,
10 unsigned long *stack_out);
11extern int run_helper_thread(int (*proc)(void *), void *arg,
12 unsigned int flags, unsigned long *stack_out,
13 int stack_order);
14extern int helper_wait(int pid);
15
16#endif
17
18/*
19 * Overrides for Emacs so that we follow Linus's tabbing style.
20 * Emacs will notice this stuff at the end of the file and automatically
21 * adjust the settings for this buffer only. This must remain at the end
22 * of the file.
23 * ---------------------------------------------------------------------------
24 * Local variables:
25 * c-file-style: "linux"
26 * End:
27 */
diff --git a/arch/um/include/mem_user.h b/arch/um/include/mem_user.h
index 9fef4123a65a..a1064c5823bf 100644
--- a/arch/um/include/mem_user.h
+++ b/arch/um/include/mem_user.h
@@ -57,7 +57,7 @@ extern int init_maps(unsigned long physmem, unsigned long iomem,
57 unsigned long highmem); 57 unsigned long highmem);
58extern unsigned long get_vm(unsigned long len); 58extern unsigned long get_vm(unsigned long len);
59extern void setup_physmem(unsigned long start, unsigned long usable, 59extern void setup_physmem(unsigned long start, unsigned long usable,
60 unsigned long len, unsigned long highmem); 60 unsigned long len, unsigned long long highmem);
61extern void add_iomem(char *name, int fd, unsigned long size); 61extern void add_iomem(char *name, int fd, unsigned long size);
62extern unsigned long phys_offset(unsigned long phys); 62extern unsigned long phys_offset(unsigned long phys);
63extern void unmap_physmem(void); 63extern void unmap_physmem(void);
diff --git a/arch/um/include/net_user.h b/arch/um/include/net_user.h
index 89885a77a771..800c403920bc 100644
--- a/arch/um/include/net_user.h
+++ b/arch/um/include/net_user.h
@@ -25,7 +25,7 @@ struct net_user_info {
25}; 25};
26 26
27extern void ether_user_init(void *data, void *dev); 27extern void ether_user_init(void *data, void *dev);
28extern void dev_ip_addr(void *d, char *buf, char *bin_buf); 28extern void dev_ip_addr(void *d, unsigned char *bin_buf);
29extern void set_ether_mac(void *d, unsigned char *addr); 29extern void set_ether_mac(void *d, unsigned char *addr);
30extern void iter_addresses(void *d, void (*cb)(unsigned char *, 30extern void iter_addresses(void *d, void (*cb)(unsigned char *,
31 unsigned char *, void *), 31 unsigned char *, void *),
diff --git a/arch/um/include/os.h b/arch/um/include/os.h
index 2e58e304b8be..2cccfa5b8ab5 100644
--- a/arch/um/include/os.h
+++ b/arch/um/include/os.h
@@ -167,7 +167,7 @@ extern int can_do_skas(void);
167#endif 167#endif
168 168
169/* mem.c */ 169/* mem.c */
170extern int create_mem_file(unsigned long len); 170extern int create_mem_file(unsigned long long len);
171 171
172/* process.c */ 172/* process.c */
173extern unsigned long os_process_pc(int pid); 173extern unsigned long os_process_pc(int pid);
@@ -199,6 +199,20 @@ extern void forward_pending_sigio(int target);
199extern int start_fork_tramp(void *arg, unsigned long temp_stack, 199extern int start_fork_tramp(void *arg, unsigned long temp_stack,
200 int clone_flags, int (*tramp)(void *)); 200 int clone_flags, int (*tramp)(void *));
201 201
202/* uaccess.c */
203extern unsigned long __do_user_copy(void *to, const void *from, int n,
204 void **fault_addr, void **fault_catcher,
205 void (*op)(void *to, const void *from,
206 int n), int *faulted_out);
207
208/* helper.c */
209extern int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv,
210 unsigned long *stack_out);
211extern int run_helper_thread(int (*proc)(void *), void *arg,
212 unsigned int flags, unsigned long *stack_out,
213 int stack_order);
214extern int helper_wait(int pid);
215
202#endif 216#endif
203 217
204/* 218/*
diff --git a/arch/um/include/sysdep-i386/stub.h b/arch/um/include/sysdep-i386/stub.h
index d3699fe1c613..a49ceb199ee5 100644
--- a/arch/um/include/sysdep-i386/stub.h
+++ b/arch/um/include/sysdep-i386/stub.h
@@ -16,45 +16,69 @@ extern void stub_clone_handler(void);
16#define STUB_MMAP_NR __NR_mmap2 16#define STUB_MMAP_NR __NR_mmap2
17#define MMAP_OFFSET(o) ((o) >> PAGE_SHIFT) 17#define MMAP_OFFSET(o) ((o) >> PAGE_SHIFT)
18 18
19static inline long stub_syscall1(long syscall, long arg1)
20{
21 long ret;
22
23 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1));
24
25 return ret;
26}
27
19static inline long stub_syscall2(long syscall, long arg1, long arg2) 28static inline long stub_syscall2(long syscall, long arg1, long arg2)
20{ 29{
21 long ret; 30 long ret;
22 31
23 __asm__("movl %0, %%ecx; " : : "g" (arg2) : "%ecx"); 32 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
24 __asm__("movl %0, %%ebx; " : : "g" (arg1) : "%ebx"); 33 "c" (arg2));
25 __asm__("movl %0, %%eax; " : : "g" (syscall) : "%eax"); 34
26 __asm__("int $0x80;" : : : "%eax"); 35 return ret;
27 __asm__ __volatile__("movl %%eax, %0; " : "=g" (ret) :);
28 return(ret);
29} 36}
30 37
31static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3) 38static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
32{ 39{
33 __asm__("movl %0, %%edx; " : : "g" (arg3) : "%edx"); 40 long ret;
34 return(stub_syscall2(syscall, arg1, arg2)); 41
42 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
43 "c" (arg2), "d" (arg3));
44
45 return ret;
35} 46}
36 47
37static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3, 48static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
38 long arg4) 49 long arg4)
39{ 50{
40 __asm__("movl %0, %%esi; " : : "g" (arg4) : "%esi"); 51 long ret;
41 return(stub_syscall3(syscall, arg1, arg2, arg3)); 52
53 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
54 "c" (arg2), "d" (arg3), "S" (arg4));
55
56 return ret;
57}
58
59static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
60 long arg4, long arg5)
61{
62 long ret;
63
64 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
65 "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5));
66
67 return ret;
42} 68}
43 69
44static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3, 70static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3,
45 long arg4, long arg5, long arg6) 71 long arg4, long arg5, long arg6)
46{ 72{
47 long ret; 73 long ret;
48 __asm__("movl %0, %%eax; " : : "g" (syscall) : "%eax"); 74
49 __asm__("movl %0, %%ebx; " : : "g" (arg1) : "%ebx"); 75 __asm__ volatile ("push %%ebp ; movl %%eax,%%ebp ; movl %1,%%eax ; "
50 __asm__("movl %0, %%ecx; " : : "g" (arg2) : "%ecx"); 76 "int $0x80 ; pop %%ebp"
51 __asm__("movl %0, %%edx; " : : "g" (arg3) : "%edx"); 77 : "=a" (ret)
52 __asm__("movl %0, %%esi; " : : "g" (arg4) : "%esi"); 78 : "g" (syscall), "b" (arg1), "c" (arg2), "d" (arg3),
53 __asm__("movl %0, %%edi; " : : "g" (arg5) : "%edi"); 79 "S" (arg4), "D" (arg5), "0" (arg6));
54 __asm__ __volatile__("pushl %%ebp ; movl %1, %%ebp; " 80
55 "int $0x80; popl %%ebp ; " 81 return ret;
56 "movl %%eax, %0; " : "=g" (ret) : "g" (arg6) : "%eax");
57 return(ret);
58} 82}
59 83
60static inline void trap_myself(void) 84static inline void trap_myself(void)
diff --git a/arch/um/include/sysdep-x86_64/stub.h b/arch/um/include/sysdep-x86_64/stub.h
index f599058d8263..2bd6e7a97286 100644
--- a/arch/um/include/sysdep-x86_64/stub.h
+++ b/arch/um/include/sysdep-x86_64/stub.h
@@ -17,37 +17,72 @@ extern void stub_clone_handler(void);
17#define STUB_MMAP_NR __NR_mmap 17#define STUB_MMAP_NR __NR_mmap
18#define MMAP_OFFSET(o) (o) 18#define MMAP_OFFSET(o) (o)
19 19
20#define __syscall_clobber "r11","rcx","memory"
21#define __syscall "syscall"
22
20static inline long stub_syscall2(long syscall, long arg1, long arg2) 23static inline long stub_syscall2(long syscall, long arg1, long arg2)
21{ 24{
22 long ret; 25 long ret;
23 26
24 __asm__("movq %0, %%rsi; " : : "g" (arg2) : "%rsi"); 27 __asm__ volatile (__syscall
25 __asm__("movq %0, %%rdi; " : : "g" (arg1) : "%rdi"); 28 : "=a" (ret)
26 __asm__("movq %0, %%rax; " : : "g" (syscall) : "%rax"); 29 : "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber );
27 __asm__("syscall;" : : : "%rax", "%r11", "%rcx"); 30
28 __asm__ __volatile__("movq %%rax, %0; " : "=g" (ret) :); 31 return ret;
29 return(ret);
30} 32}
31 33
32static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3) 34static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
33{ 35{
34 __asm__("movq %0, %%rdx; " : : "g" (arg3) : "%rdx"); 36 long ret;
35 return(stub_syscall2(syscall, arg1, arg2)); 37
38 __asm__ volatile (__syscall
39 : "=a" (ret)
40 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3)
41 : __syscall_clobber );
42
43 return ret;
36} 44}
37 45
38static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3, 46static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
39 long arg4) 47 long arg4)
40{ 48{
41 __asm__("movq %0, %%r10; " : : "g" (arg4) : "%r10"); 49 long ret;
42 return(stub_syscall3(syscall, arg1, arg2, arg3)); 50
51 __asm__ volatile ("movq %5,%%r10 ; " __syscall
52 : "=a" (ret)
53 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
54 "g" (arg4)
55 : __syscall_clobber, "r10" );
56
57 return ret;
58}
59
60static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
61 long arg4, long arg5)
62{
63 long ret;
64
65 __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall
66 : "=a" (ret)
67 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
68 "g" (arg4), "g" (arg5)
69 : __syscall_clobber, "r10", "r8" );
70
71 return ret;
43} 72}
44 73
45static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3, 74static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3,
46 long arg4, long arg5, long arg6) 75 long arg4, long arg5, long arg6)
47{ 76{
48 __asm__("movq %0, %%r9; " : : "g" (arg6) : "%r9"); 77 long ret;
49 __asm__("movq %0, %%r8; " : : "g" (arg5) : "%r8"); 78
50 return(stub_syscall4(syscall, arg1, arg2, arg3, arg4)); 79 __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; "
80 "movq %7, %%r9; " __syscall : "=a" (ret)
81 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
82 "g" (arg4), "g" (arg5), "g" (arg6)
83 : __syscall_clobber, "r10", "r8", "r9" );
84
85 return ret;
51} 86}
52 87
53static inline void trap_myself(void) 88static inline void trap_myself(void)
diff --git a/arch/um/include/uml_uaccess.h b/arch/um/include/uml_uaccess.h
index f77eb6428453..c0df11d06f5e 100644
--- a/arch/um/include/uml_uaccess.h
+++ b/arch/um/include/uml_uaccess.h
@@ -8,10 +8,6 @@
8 8
9extern int __do_copy_to_user(void *to, const void *from, int n, 9extern int __do_copy_to_user(void *to, const void *from, int n,
10 void **fault_addr, void **fault_catcher); 10 void **fault_addr, void **fault_catcher);
11extern unsigned long __do_user_copy(void *to, const void *from, int n,
12 void **fault_addr, void **fault_catcher,
13 void (*op)(void *to, const void *from,
14 int n), int *faulted_out);
15void __do_copy(void *to, const void *from, int n); 11void __do_copy(void *to, const void *from, int n);
16 12
17#endif 13#endif
diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile
index 1a0001b3850c..3de9d21e36bf 100644
--- a/arch/um/kernel/Makefile
+++ b/arch/um/kernel/Makefile
@@ -7,10 +7,10 @@ extra-y := vmlinux.lds
7clean-files := 7clean-files :=
8 8
9obj-y = config.o exec_kern.o exitcode.o \ 9obj-y = config.o exec_kern.o exitcode.o \
10 helper.o init_task.o irq.o irq_user.o ksyms.o main.o mem.o physmem.o \ 10 init_task.o irq.o irq_user.o ksyms.o mem.o physmem.o \
11 process_kern.o ptrace.o reboot.o resource.o sigio_user.o sigio_kern.o \ 11 process_kern.o ptrace.o reboot.o resource.o sigio_user.o sigio_kern.o \
12 signal_kern.o signal_user.o smp.o syscall_kern.o sysrq.o time.o \ 12 signal_kern.o signal_user.o smp.o syscall_kern.o sysrq.o time.o \
13 time_kern.o tlb.o trap_kern.o trap_user.o uaccess_user.o um_arch.o \ 13 time_kern.o tlb.o trap_kern.o trap_user.o uaccess.o um_arch.o \
14 umid.o user_util.o 14 umid.o user_util.o
15 15
16obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o 16obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o
@@ -24,8 +24,7 @@ obj-$(CONFIG_MODE_SKAS) += skas/
24 24
25user-objs-$(CONFIG_TTY_LOG) += tty_log.o 25user-objs-$(CONFIG_TTY_LOG) += tty_log.o
26 26
27USER_OBJS := $(user-objs-y) config.o helper.o main.o time.o tty_log.o umid.o \ 27USER_OBJS := $(user-objs-y) config.o time.o tty_log.o umid.o user_util.o
28 user_util.o
29 28
30include arch/um/scripts/Makefile.rules 29include arch/um/scripts/Makefile.rules
31 30
diff --git a/arch/um/kernel/ksyms.c b/arch/um/kernel/ksyms.c
index a97a72e516aa..7713e7a6f476 100644
--- a/arch/um/kernel/ksyms.c
+++ b/arch/um/kernel/ksyms.c
@@ -20,7 +20,6 @@
20#include "user_util.h" 20#include "user_util.h"
21#include "mem_user.h" 21#include "mem_user.h"
22#include "os.h" 22#include "os.h"
23#include "helper.h"
24 23
25EXPORT_SYMBOL(stop); 24EXPORT_SYMBOL(stop);
26EXPORT_SYMBOL(uml_physmem); 25EXPORT_SYMBOL(uml_physmem);
diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c
index 462cc9d65386..fa4f915be5c5 100644
--- a/arch/um/kernel/mem.c
+++ b/arch/um/kernel/mem.c
@@ -234,8 +234,8 @@ void paging_init(void)
234 empty_bad_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE); 234 empty_bad_page = (unsigned long *) alloc_bootmem_low_pages(PAGE_SIZE);
235 for(i=0;i<sizeof(zones_size)/sizeof(zones_size[0]);i++) 235 for(i=0;i<sizeof(zones_size)/sizeof(zones_size[0]);i++)
236 zones_size[i] = 0; 236 zones_size[i] = 0;
237 zones_size[0] = (end_iomem >> PAGE_SHIFT) - (uml_physmem >> PAGE_SHIFT); 237 zones_size[ZONE_DMA] = (end_iomem >> PAGE_SHIFT) - (uml_physmem >> PAGE_SHIFT);
238 zones_size[2] = highmem >> PAGE_SHIFT; 238 zones_size[ZONE_HIGHMEM] = highmem >> PAGE_SHIFT;
239 free_area_init(zones_size); 239 free_area_init(zones_size);
240 240
241 /* 241 /*
diff --git a/arch/um/kernel/physmem.c b/arch/um/kernel/physmem.c
index ea670fcc8af5..f3b583a878a6 100644
--- a/arch/um/kernel/physmem.c
+++ b/arch/um/kernel/physmem.c
@@ -246,7 +246,7 @@ int is_remapped(void *virt)
246/* Changed during early boot */ 246/* Changed during early boot */
247unsigned long high_physmem; 247unsigned long high_physmem;
248 248
249extern unsigned long physmem_size; 249extern unsigned long long physmem_size;
250 250
251int init_maps(unsigned long physmem, unsigned long iomem, unsigned long highmem) 251int init_maps(unsigned long physmem, unsigned long iomem, unsigned long highmem)
252{ 252{
@@ -321,7 +321,7 @@ void map_memory(unsigned long virt, unsigned long phys, unsigned long len,
321extern int __syscall_stub_start, __binary_start; 321extern int __syscall_stub_start, __binary_start;
322 322
323void setup_physmem(unsigned long start, unsigned long reserve_end, 323void setup_physmem(unsigned long start, unsigned long reserve_end,
324 unsigned long len, unsigned long highmem) 324 unsigned long len, unsigned long long highmem)
325{ 325{
326 unsigned long reserve = reserve_end - start; 326 unsigned long reserve = reserve_end - start;
327 int pfn = PFN_UP(__pa(reserve_end)); 327 int pfn = PFN_UP(__pa(reserve_end));
diff --git a/arch/um/kernel/ptrace.c b/arch/um/kernel/ptrace.c
index 71af4d503899..98e09395c093 100644
--- a/arch/um/kernel/ptrace.c
+++ b/arch/um/kernel/ptrace.c
@@ -43,53 +43,10 @@ void ptrace_disable(struct task_struct *child)
43extern int peek_user(struct task_struct * child, long addr, long data); 43extern int peek_user(struct task_struct * child, long addr, long data);
44extern int poke_user(struct task_struct * child, long addr, long data); 44extern int poke_user(struct task_struct * child, long addr, long data);
45 45
46long sys_ptrace(long request, long pid, long addr, long data) 46long arch_ptrace(struct task_struct *child, long request, long addr, long data)
47{ 47{
48 struct task_struct *child;
49 int i, ret; 48 int i, ret;
50 49
51 lock_kernel();
52 ret = -EPERM;
53 if (request == PTRACE_TRACEME) {
54 /* are we already being traced? */
55 if (current->ptrace & PT_PTRACED)
56 goto out;
57
58 ret = security_ptrace(current->parent, current);
59 if (ret)
60 goto out;
61
62 /* set the ptrace bit in the process flags. */
63 current->ptrace |= PT_PTRACED;
64 ret = 0;
65 goto out;
66 }
67 ret = -ESRCH;
68 read_lock(&tasklist_lock);
69 child = find_task_by_pid(pid);
70 if (child)
71 get_task_struct(child);
72 read_unlock(&tasklist_lock);
73 if (!child)
74 goto out;
75
76 ret = -EPERM;
77 if (pid == 1) /* you may not mess with init */
78 goto out_tsk;
79
80 if (request == PTRACE_ATTACH) {
81 ret = ptrace_attach(child);
82 goto out_tsk;
83 }
84
85#ifdef SUBACH_PTRACE_SPECIAL
86 SUBARCH_PTRACE_SPECIAL(child,request,addr,data);
87#endif
88
89 ret = ptrace_check_attach(child, request == PTRACE_KILL);
90 if (ret < 0)
91 goto out_tsk;
92
93 switch (request) { 50 switch (request) {
94 /* when I and D space are separate, these will need to be fixed. */ 51 /* when I and D space are separate, these will need to be fixed. */
95 case PTRACE_PEEKTEXT: /* read word at location addr. */ 52 case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -282,10 +239,7 @@ long sys_ptrace(long request, long pid, long addr, long data)
282 ret = ptrace_request(child, request, addr, data); 239 ret = ptrace_request(child, request, addr, data);
283 break; 240 break;
284 } 241 }
285 out_tsk: 242
286 put_task_struct(child);
287 out:
288 unlock_kernel();
289 return ret; 243 return ret;
290} 244}
291 245
diff --git a/arch/um/kernel/sigio_user.c b/arch/um/kernel/sigio_user.c
index a52751108aa1..48b1f644b9a6 100644
--- a/arch/um/kernel/sigio_user.c
+++ b/arch/um/kernel/sigio_user.c
@@ -18,7 +18,6 @@
18#include "kern_util.h" 18#include "kern_util.h"
19#include "user_util.h" 19#include "user_util.h"
20#include "sigio.h" 20#include "sigio.h"
21#include "helper.h"
22#include "os.h" 21#include "os.h"
23 22
24/* Changed during early boot */ 23/* Changed during early boot */
@@ -225,7 +224,7 @@ static int need_poll(int n)
225 next_poll.used = n; 224 next_poll.used = n;
226 return(0); 225 return(0);
227 } 226 }
228 if(next_poll.poll != NULL) kfree(next_poll.poll); 227 kfree(next_poll.poll);
229 next_poll.poll = um_kmalloc_atomic(n * sizeof(struct pollfd)); 228 next_poll.poll = um_kmalloc_atomic(n * sizeof(struct pollfd));
230 if(next_poll.poll == NULL){ 229 if(next_poll.poll == NULL){
231 printk("need_poll : failed to allocate new pollfds\n"); 230 printk("need_poll : failed to allocate new pollfds\n");
diff --git a/arch/um/kernel/skas/include/mmu-skas.h b/arch/um/kernel/skas/include/mmu-skas.h
index 09536f81ee42..44110c521e49 100644
--- a/arch/um/kernel/skas/include/mmu-skas.h
+++ b/arch/um/kernel/skas/include/mmu-skas.h
@@ -8,6 +8,7 @@
8 8
9#include "linux/config.h" 9#include "linux/config.h"
10#include "mm_id.h" 10#include "mm_id.h"
11#include "asm/ldt.h"
11 12
12struct mmu_context_skas { 13struct mmu_context_skas {
13 struct mm_id id; 14 struct mm_id id;
@@ -15,6 +16,7 @@ struct mmu_context_skas {
15#ifdef CONFIG_3_LEVEL_PGTABLES 16#ifdef CONFIG_3_LEVEL_PGTABLES
16 unsigned long last_pmd; 17 unsigned long last_pmd;
17#endif 18#endif
19 uml_ldt_t ldt;
18}; 20};
19 21
20extern void switch_mm_skas(struct mm_id * mm_idp); 22extern void switch_mm_skas(struct mm_id * mm_idp);
diff --git a/arch/um/kernel/skas/include/skas.h b/arch/um/kernel/skas/include/skas.h
index 060934740f9f..daa2f85b684c 100644
--- a/arch/um/kernel/skas/include/skas.h
+++ b/arch/um/kernel/skas/include/skas.h
@@ -10,7 +10,8 @@
10#include "sysdep/ptrace.h" 10#include "sysdep/ptrace.h"
11 11
12extern int userspace_pid[]; 12extern int userspace_pid[];
13extern int proc_mm, ptrace_faultinfo; 13extern int proc_mm, ptrace_faultinfo, ptrace_ldt;
14extern int skas_needs_stub;
14 15
15extern void switch_threads(void *me, void *next); 16extern void switch_threads(void *me, void *next);
16extern void thread_wait(void *sw, void *fb); 17extern void thread_wait(void *sw, void *fb);
diff --git a/arch/um/kernel/skas/mem.c b/arch/um/kernel/skas/mem.c
index 147466d7ff4f..88ab96c609ce 100644
--- a/arch/um/kernel/skas/mem.c
+++ b/arch/um/kernel/skas/mem.c
@@ -20,7 +20,7 @@ unsigned long set_task_sizes_skas(int arg, unsigned long *host_size_out,
20 *task_size_out = CONFIG_HOST_TASK_SIZE; 20 *task_size_out = CONFIG_HOST_TASK_SIZE;
21#else 21#else
22 *host_size_out = top; 22 *host_size_out = top;
23 if (proc_mm && ptrace_faultinfo) 23 if (!skas_needs_stub)
24 *task_size_out = top; 24 *task_size_out = top;
25 else *task_size_out = CONFIG_STUB_START & PGDIR_MASK; 25 else *task_size_out = CONFIG_STUB_START & PGDIR_MASK;
26#endif 26#endif
diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c
index 9e5e39cea821..677871f1b37c 100644
--- a/arch/um/kernel/skas/mmu.c
+++ b/arch/um/kernel/skas/mmu.c
@@ -15,6 +15,7 @@
15#include "asm/mmu.h" 15#include "asm/mmu.h"
16#include "asm/pgalloc.h" 16#include "asm/pgalloc.h"
17#include "asm/pgtable.h" 17#include "asm/pgtable.h"
18#include "asm/ldt.h"
18#include "os.h" 19#include "os.h"
19#include "skas.h" 20#include "skas.h"
20 21
@@ -74,13 +75,12 @@ static int init_stub_pte(struct mm_struct *mm, unsigned long proc,
74 75
75int init_new_context_skas(struct task_struct *task, struct mm_struct *mm) 76int init_new_context_skas(struct task_struct *task, struct mm_struct *mm)
76{ 77{
77 struct mm_struct *cur_mm = current->mm; 78 struct mmu_context_skas *from_mm = NULL;
78 struct mm_id *cur_mm_id = &cur_mm->context.skas.id; 79 struct mmu_context_skas *to_mm = &mm->context.skas;
79 struct mm_id *mm_id = &mm->context.skas.id;
80 unsigned long stack = 0; 80 unsigned long stack = 0;
81 int from, ret = -ENOMEM; 81 int from_fd, ret = -ENOMEM;
82 82
83 if(!proc_mm || !ptrace_faultinfo){ 83 if(skas_needs_stub){
84 stack = get_zeroed_page(GFP_KERNEL); 84 stack = get_zeroed_page(GFP_KERNEL);
85 if(stack == 0) 85 if(stack == 0)
86 goto out; 86 goto out;
@@ -102,33 +102,43 @@ int init_new_context_skas(struct task_struct *task, struct mm_struct *mm)
102 102
103 mm->nr_ptes--; 103 mm->nr_ptes--;
104 } 104 }
105 mm_id->stack = stack; 105
106 to_mm->id.stack = stack;
107 if(current->mm != NULL && current->mm != &init_mm)
108 from_mm = &current->mm->context.skas;
106 109
107 if(proc_mm){ 110 if(proc_mm){
108 if((cur_mm != NULL) && (cur_mm != &init_mm)) 111 if(from_mm)
109 from = cur_mm_id->u.mm_fd; 112 from_fd = from_mm->id.u.mm_fd;
110 else from = -1; 113 else from_fd = -1;
111 114
112 ret = new_mm(from, stack); 115 ret = new_mm(from_fd, stack);
113 if(ret < 0){ 116 if(ret < 0){
114 printk("init_new_context_skas - new_mm failed, " 117 printk("init_new_context_skas - new_mm failed, "
115 "errno = %d\n", ret); 118 "errno = %d\n", ret);
116 goto out_free; 119 goto out_free;
117 } 120 }
118 mm_id->u.mm_fd = ret; 121 to_mm->id.u.mm_fd = ret;
119 } 122 }
120 else { 123 else {
121 if((cur_mm != NULL) && (cur_mm != &init_mm)) 124 if(from_mm)
122 mm_id->u.pid = copy_context_skas0(stack, 125 to_mm->id.u.pid = copy_context_skas0(stack,
123 cur_mm_id->u.pid); 126 from_mm->id.u.pid);
124 else mm_id->u.pid = start_userspace(stack); 127 else to_mm->id.u.pid = start_userspace(stack);
128 }
129
130 ret = init_new_ldt(to_mm, from_mm);
131 if(ret < 0){
132 printk("init_new_context_skas - init_ldt"
133 " failed, errno = %d\n", ret);
134 goto out_free;
125 } 135 }
126 136
127 return 0; 137 return 0;
128 138
129 out_free: 139 out_free:
130 if(mm_id->stack != 0) 140 if(to_mm->id.stack != 0)
131 free_page(mm_id->stack); 141 free_page(to_mm->id.stack);
132 out: 142 out:
133 return ret; 143 return ret;
134} 144}
diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c
index 5cd0e9929789..599d679bd4fc 100644
--- a/arch/um/kernel/skas/process.c
+++ b/arch/um/kernel/skas/process.c
@@ -69,6 +69,17 @@ void wait_stub_done(int pid, int sig, char * fname)
69 69
70 if((n < 0) || !WIFSTOPPED(status) || 70 if((n < 0) || !WIFSTOPPED(status) ||
71 (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGTRAP)){ 71 (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGTRAP)){
72 unsigned long regs[FRAME_SIZE];
73 if(ptrace(PTRACE_GETREGS, pid, 0, regs) < 0)
74 printk("Failed to get registers from stub, "
75 "errno = %d\n", errno);
76 else {
77 int i;
78
79 printk("Stub registers -\n");
80 for(i = 0; i < FRAME_SIZE; i++)
81 printk("\t%d - %lx\n", i, regs[i]);
82 }
72 panic("%s : failed to wait for SIGUSR1/SIGTRAP, " 83 panic("%s : failed to wait for SIGUSR1/SIGTRAP, "
73 "pid = %d, n = %d, errno = %d, status = 0x%x\n", 84 "pid = %d, n = %d, errno = %d, status = 0x%x\n",
74 fname, pid, n, errno, status); 85 fname, pid, n, errno, status);
@@ -370,9 +381,9 @@ int copy_context_skas0(unsigned long new_stack, int pid)
370} 381}
371 382
372/* 383/*
373 * This is used only, if proc_mm is available, while PTRACE_FAULTINFO 384 * This is used only, if stub pages are needed, while proc_mm is
374 * isn't. Opening /proc/mm creates a new mm_context, which lacks the stub-pages 385 * availabl. Opening /proc/mm creates a new mm_context, which lacks
375 * Thus, we map them using /proc/mm-fd 386 * the stub-pages. Thus, we map them using /proc/mm-fd
376 */ 387 */
377void map_stub_pages(int fd, unsigned long code, 388void map_stub_pages(int fd, unsigned long code,
378 unsigned long data, unsigned long stack) 389 unsigned long data, unsigned long stack)
diff --git a/arch/um/kernel/skas/process_kern.c b/arch/um/kernel/skas/process_kern.c
index efe92e8aa2a9..9c990253966c 100644
--- a/arch/um/kernel/skas/process_kern.c
+++ b/arch/um/kernel/skas/process_kern.c
@@ -145,7 +145,7 @@ int new_mm(int from, unsigned long stack)
145 "err = %d\n", -n); 145 "err = %d\n", -n);
146 } 146 }
147 147
148 if(!ptrace_faultinfo) 148 if(skas_needs_stub)
149 map_stub_pages(fd, CONFIG_STUB_CODE, CONFIG_STUB_DATA, stack); 149 map_stub_pages(fd, CONFIG_STUB_CODE, CONFIG_STUB_DATA, stack);
150 150
151 return(fd); 151 return(fd);
diff --git a/arch/um/kernel/tt/uaccess_user.c b/arch/um/kernel/tt/uaccess_user.c
index 8c220f054b61..6c92bbccb49c 100644
--- a/arch/um/kernel/tt/uaccess_user.c
+++ b/arch/um/kernel/tt/uaccess_user.c
@@ -10,6 +10,7 @@
10#include "uml_uaccess.h" 10#include "uml_uaccess.h"
11#include "task.h" 11#include "task.h"
12#include "kern_util.h" 12#include "kern_util.h"
13#include "os.h"
13 14
14int __do_copy_from_user(void *to, const void *from, int n, 15int __do_copy_from_user(void *to, const void *from, int n,
15 void **fault_addr, void **fault_catcher) 16 void **fault_addr, void **fault_catcher)
diff --git a/arch/um/kernel/uaccess.c b/arch/um/kernel/uaccess.c
new file mode 100644
index 000000000000..054e3de0784e
--- /dev/null
+++ b/arch/um/kernel/uaccess.c
@@ -0,0 +1,30 @@
1/*
2 * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk)
3 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
4 * Licensed under the GPL
5 */
6
7/* These are here rather than tt/uaccess.c because skas mode needs them in
8 * order to do SIGBUS recovery when a tmpfs mount runs out of room.
9 */
10
11#include <linux/string.h>
12#include "os.h"
13
14void __do_copy(void *to, const void *from, int n)
15{
16 memcpy(to, from, n);
17}
18
19
20int __do_copy_to_user(void *to, const void *from, int n,
21 void **fault_addr, void **fault_catcher)
22{
23 unsigned long fault;
24 int faulted;
25
26 fault = __do_user_copy(to, from, n, fault_addr, fault_catcher,
27 __do_copy, &faulted);
28 if(!faulted) return(0);
29 else return(n - (fault - (unsigned long) to));
30}
diff --git a/arch/um/kernel/uaccess_user.c b/arch/um/kernel/uaccess_user.c
deleted file mode 100644
index d035257ed0af..000000000000
--- a/arch/um/kernel/uaccess_user.c
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk)
3 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
4 * Licensed under the GPL
5 */
6
7#include <setjmp.h>
8#include <string.h>
9
10/* These are here rather than tt/uaccess.c because skas mode needs them in
11 * order to do SIGBUS recovery when a tmpfs mount runs out of room.
12 */
13
14unsigned long __do_user_copy(void *to, const void *from, int n,
15 void **fault_addr, void **fault_catcher,
16 void (*op)(void *to, const void *from,
17 int n), int *faulted_out)
18{
19 unsigned long *faddrp = (unsigned long *) fault_addr, ret;
20
21 sigjmp_buf jbuf;
22 *fault_catcher = &jbuf;
23 if(sigsetjmp(jbuf, 1) == 0){
24 (*op)(to, from, n);
25 ret = 0;
26 *faulted_out = 0;
27 }
28 else {
29 ret = *faddrp;
30 *faulted_out = 1;
31 }
32 *fault_addr = NULL;
33 *fault_catcher = NULL;
34 return ret;
35}
36
37void __do_copy(void *to, const void *from, int n)
38{
39 memcpy(to, from, n);
40}
41
42
43int __do_copy_to_user(void *to, const void *from, int n,
44 void **fault_addr, void **fault_catcher)
45{
46 unsigned long fault;
47 int faulted;
48
49 fault = __do_user_copy(to, from, n, fault_addr, fault_catcher,
50 __do_copy, &faulted);
51 if(!faulted) return(0);
52 else return(n - (fault - (unsigned long) to));
53}
54
55/*
56 * Overrides for Emacs so that we follow Linus's tabbing style.
57 * Emacs will notice this stuff at the end of the file and automatically
58 * adjust the settings for this buffer only. This must remain at the end
59 * of the file.
60 * ---------------------------------------------------------------------------
61 * Local variables:
62 * c-file-style: "linux"
63 * End:
64 */
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c
index 93dc782dc1cc..142a9493912b 100644
--- a/arch/um/kernel/um_arch.c
+++ b/arch/um/kernel/um_arch.c
@@ -137,7 +137,7 @@ static char *argv1_end = NULL;
137 137
138/* Set in early boot */ 138/* Set in early boot */
139static int have_root __initdata = 0; 139static int have_root __initdata = 0;
140long physmem_size = 32 * 1024 * 1024; 140long long physmem_size = 32 * 1024 * 1024;
141 141
142void set_cmdline(char *cmd) 142void set_cmdline(char *cmd)
143{ 143{
@@ -402,7 +402,7 @@ int linux_main(int argc, char **argv)
402#ifndef CONFIG_HIGHMEM 402#ifndef CONFIG_HIGHMEM
403 highmem = 0; 403 highmem = 0;
404 printf("CONFIG_HIGHMEM not enabled - physical memory shrunk " 404 printf("CONFIG_HIGHMEM not enabled - physical memory shrunk "
405 "to %ld bytes\n", physmem_size); 405 "to %lu bytes\n", physmem_size);
406#endif 406#endif
407 } 407 }
408 408
@@ -414,8 +414,8 @@ int linux_main(int argc, char **argv)
414 414
415 setup_physmem(uml_physmem, uml_reserved, physmem_size, highmem); 415 setup_physmem(uml_physmem, uml_reserved, physmem_size, highmem);
416 if(init_maps(physmem_size, iomem_size, highmem)){ 416 if(init_maps(physmem_size, iomem_size, highmem)){
417 printf("Failed to allocate mem_map for %ld bytes of physical " 417 printf("Failed to allocate mem_map for %lu bytes of physical "
418 "memory and %ld bytes of highmem\n", physmem_size, 418 "memory and %lu bytes of highmem\n", physmem_size,
419 highmem); 419 highmem);
420 exit(1); 420 exit(1);
421 } 421 }
@@ -426,7 +426,7 @@ int linux_main(int argc, char **argv)
426 end_vm = start_vm + virtmem_size; 426 end_vm = start_vm + virtmem_size;
427 427
428 if(virtmem_size < physmem_size) 428 if(virtmem_size < physmem_size)
429 printf("Kernel virtual memory size shrunk to %ld bytes\n", 429 printf("Kernel virtual memory size shrunk to %lu bytes\n",
430 virtmem_size); 430 virtmem_size);
431 431
432 uml_postsetup(); 432 uml_postsetup();
diff --git a/arch/um/kernel/user_util.c b/arch/um/kernel/user_util.c
index 41d17c71511c..4c231161f257 100644
--- a/arch/um/kernel/user_util.c
+++ b/arch/um/kernel/user_util.c
@@ -27,7 +27,6 @@
27#include "user.h" 27#include "user.h"
28#include "mem_user.h" 28#include "mem_user.h"
29#include "init.h" 29#include "init.h"
30#include "helper.h"
31#include "ptrace_user.h" 30#include "ptrace_user.h"
32#include "uml-config.h" 31#include "uml-config.h"
33 32
diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile
index d15ec2af6a22..b83ac8e21c35 100644
--- a/arch/um/os-Linux/Makefile
+++ b/arch/um/os-Linux/Makefile
@@ -3,11 +3,12 @@
3# Licensed under the GPL 3# Licensed under the GPL
4# 4#
5 5
6obj-y = aio.o elf_aux.o file.o mem.o process.o signal.o start_up.o time.o \ 6obj-y = aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \
7 tt.o tty.o user_syms.o drivers/ sys-$(SUBARCH)/ 7 start_up.o time.o tt.o tty.o uaccess.o user_syms.o drivers/ \
8 sys-$(SUBARCH)/
8 9
9USER_OBJS := aio.o elf_aux.o file.o mem.o process.o signal.o start_up.o \ 10USER_OBJS := aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \
10 time.o tt.o tty.o 11 start_up.o time.o tt.o tty.o uaccess.o
11 12
12elf_aux.o: $(ARCH_DIR)/kernel-offsets.h 13elf_aux.o: $(ARCH_DIR)/kernel-offsets.h
13CFLAGS_elf_aux.o += -I$(objtree)/arch/um 14CFLAGS_elf_aux.o += -I$(objtree)/arch/um
diff --git a/arch/um/os-Linux/aio.c b/arch/um/os-Linux/aio.c
index 41cfb0944201..ffa759addd3c 100644
--- a/arch/um/os-Linux/aio.c
+++ b/arch/um/os-Linux/aio.c
@@ -10,7 +10,6 @@
10#include <sched.h> 10#include <sched.h>
11#include <sys/syscall.h> 11#include <sys/syscall.h>
12#include "os.h" 12#include "os.h"
13#include "helper.h"
14#include "aio.h" 13#include "aio.h"
15#include "init.h" 14#include "init.h"
16#include "user.h" 15#include "user.h"
diff --git a/arch/um/os-Linux/drivers/ethertap_user.c b/arch/um/os-Linux/drivers/ethertap_user.c
index cd4d6544da71..901b85e8a1c6 100644
--- a/arch/um/os-Linux/drivers/ethertap_user.c
+++ b/arch/um/os-Linux/drivers/ethertap_user.c
@@ -19,7 +19,6 @@
19#include "user_util.h" 19#include "user_util.h"
20#include "net_user.h" 20#include "net_user.h"
21#include "etap.h" 21#include "etap.h"
22#include "helper.h"
23#include "os.h" 22#include "os.h"
24 23
25#define MAX_PACKET ETH_MAX_PACKET 24#define MAX_PACKET ETH_MAX_PACKET
diff --git a/arch/um/os-Linux/drivers/tuntap_user.c b/arch/um/os-Linux/drivers/tuntap_user.c
index 4ba9b17adf13..52945338b64d 100644
--- a/arch/um/os-Linux/drivers/tuntap_user.c
+++ b/arch/um/os-Linux/drivers/tuntap_user.c
@@ -20,7 +20,6 @@
20#include "kern_util.h" 20#include "kern_util.h"
21#include "user_util.h" 21#include "user_util.h"
22#include "user.h" 22#include "user.h"
23#include "helper.h"
24#include "os.h" 23#include "os.h"
25 24
26#define MAX_PACKET ETH_MAX_PACKET 25#define MAX_PACKET ETH_MAX_PACKET
diff --git a/arch/um/kernel/helper.c b/arch/um/os-Linux/helper.c
index 33fb0bd3b11a..36cc8475bcda 100644
--- a/arch/um/kernel/helper.c
+++ b/arch/um/os-Linux/helper.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL 3 * Licensed under the GPL
4 */ 4 */
@@ -13,7 +13,6 @@
13#include "user.h" 13#include "user.h"
14#include "kern_util.h" 14#include "kern_util.h"
15#include "user_util.h" 15#include "user_util.h"
16#include "helper.h"
17#include "os.h" 16#include "os.h"
18 17
19struct helper_data { 18struct helper_data {
@@ -46,7 +45,7 @@ static int helper_child(void *arg)
46 errval = errno; 45 errval = errno;
47 printk("execvp of '%s' failed - errno = %d\n", argv[0], errno); 46 printk("execvp of '%s' failed - errno = %d\n", argv[0], errno);
48 os_write_file(data->fd, &errval, sizeof(errval)); 47 os_write_file(data->fd, &errval, sizeof(errval));
49 os_kill_process(os_getpid(), 0); 48 kill(os_getpid(), SIGKILL);
50 return(0); 49 return(0);
51} 50}
52 51
@@ -90,7 +89,7 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv,
90 goto out_close; 89 goto out_close;
91 } 90 }
92 91
93 os_close_file(fds[1]); 92 close(fds[1]);
94 fds[1] = -1; 93 fds[1] = -1;
95 94
96 /*Read the errno value from the child.*/ 95 /*Read the errno value from the child.*/
@@ -98,7 +97,8 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv,
98 if(n < 0){ 97 if(n < 0){
99 printk("run_helper : read on pipe failed, ret = %d\n", -n); 98 printk("run_helper : read on pipe failed, ret = %d\n", -n);
100 ret = n; 99 ret = n;
101 os_kill_process(pid, 1); 100 kill(pid, SIGKILL);
101 CATCH_EINTR(waitpid(pid, NULL, 0));
102 } 102 }
103 else if(n != 0){ 103 else if(n != 0){
104 CATCH_EINTR(n = waitpid(pid, NULL, 0)); 104 CATCH_EINTR(n = waitpid(pid, NULL, 0));
@@ -109,8 +109,8 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv,
109 109
110out_close: 110out_close:
111 if (fds[1] != -1) 111 if (fds[1] != -1)
112 os_close_file(fds[1]); 112 close(fds[1]);
113 os_close_file(fds[0]); 113 close(fds[0]);
114out_free: 114out_free:
115 if(stack_out == NULL) 115 if(stack_out == NULL)
116 free_stack(stack, 0); 116 free_stack(stack, 0);
@@ -118,7 +118,7 @@ out_free:
118 return(ret); 118 return(ret);
119} 119}
120 120
121int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags, 121int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags,
122 unsigned long *stack_out, int stack_order) 122 unsigned long *stack_out, int stack_order)
123{ 123{
124 unsigned long stack, sp; 124 unsigned long stack, sp;
@@ -131,7 +131,7 @@ int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags,
131 pid = clone(proc, (void *) sp, flags | SIGCHLD, arg); 131 pid = clone(proc, (void *) sp, flags | SIGCHLD, arg);
132 if(pid < 0){ 132 if(pid < 0){
133 err = -errno; 133 err = -errno;
134 printk("run_helper_thread : clone failed, errno = %d\n", 134 printk("run_helper_thread : clone failed, errno = %d\n",
135 errno); 135 errno);
136 return err; 136 return err;
137 } 137 }
diff --git a/arch/um/kernel/main.c b/arch/um/os-Linux/main.c
index d31027f0fe39..23da27d22569 100644
--- a/arch/um/kernel/main.c
+++ b/arch/um/os-Linux/main.c
@@ -157,25 +157,25 @@ int main(int argc, char **argv, char **envp)
157 */ 157 */
158 change_sig(SIGPROF, 0); 158 change_sig(SIGPROF, 0);
159 159
160 /* This signal stuff used to be in the reboot case. However, 160 /* This signal stuff used to be in the reboot case. However,
161 * sometimes a SIGVTALRM can come in when we're halting (reproducably 161 * sometimes a SIGVTALRM can come in when we're halting (reproducably
162 * when writing out gcov information, presumably because that takes 162 * when writing out gcov information, presumably because that takes
163 * some time) and cause a segfault. 163 * some time) and cause a segfault.
164 */ 164 */
165 165
166 /* stop timers and set SIG*ALRM to be ignored */ 166 /* stop timers and set SIG*ALRM to be ignored */
167 disable_timer(); 167 disable_timer();
168 168
169 /* disable SIGIO for the fds and set SIGIO to be ignored */ 169 /* disable SIGIO for the fds and set SIGIO to be ignored */
170 err = deactivate_all_fds(); 170 err = deactivate_all_fds();
171 if(err) 171 if(err)
172 printf("deactivate_all_fds failed, errno = %d\n", -err); 172 printf("deactivate_all_fds failed, errno = %d\n", -err);
173 173
174 /* Let any pending signals fire now. This ensures 174 /* Let any pending signals fire now. This ensures
175 * that they won't be delivered after the exec, when 175 * that they won't be delivered after the exec, when
176 * they are definitely not expected. 176 * they are definitely not expected.
177 */ 177 */
178 unblock_signals(); 178 unblock_signals();
179 179
180 /* Reboot */ 180 /* Reboot */
181 if(ret){ 181 if(ret){
@@ -257,14 +257,3 @@ void __wrap_free(void *ptr)
257 } 257 }
258 else __real_free(ptr); 258 else __real_free(ptr);
259} 259}
260
261/*
262 * Overrides for Emacs so that we follow Linus's tabbing style.
263 * Emacs will notice this stuff at the end of the file and automatically
264 * adjust the settings for this buffer only. This must remain at the end
265 * of the file.
266 * ---------------------------------------------------------------------------
267 * Local variables:
268 * c-file-style: "linux"
269 * End:
270 */
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c
index 8e71edaaf80b..9d7d69a523bb 100644
--- a/arch/um/os-Linux/mem.c
+++ b/arch/um/os-Linux/mem.c
@@ -88,7 +88,7 @@ int make_tempfile(const char *template, char **out_tempname, int do_unlink)
88 * This proc is used in start_up.c 88 * This proc is used in start_up.c
89 * So it isn't 'static'. 89 * So it isn't 'static'.
90 */ 90 */
91int create_tmp_file(unsigned long len) 91int create_tmp_file(unsigned long long len)
92{ 92{
93 int fd, err; 93 int fd, err;
94 char zero; 94 char zero;
@@ -121,7 +121,7 @@ int create_tmp_file(unsigned long len)
121 return(fd); 121 return(fd);
122} 122}
123 123
124static int create_anon_file(unsigned long len) 124static int create_anon_file(unsigned long long len)
125{ 125{
126 void *addr; 126 void *addr;
127 int fd; 127 int fd;
@@ -144,7 +144,7 @@ static int create_anon_file(unsigned long len)
144 144
145extern int have_devanon; 145extern int have_devanon;
146 146
147int create_mem_file(unsigned long len) 147int create_mem_file(unsigned long long len)
148{ 148{
149 int err, fd; 149 int err, fd;
150 150
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c
index b99ab414542f..37517d49c4ae 100644
--- a/arch/um/os-Linux/start_up.c
+++ b/arch/um/os-Linux/start_up.c
@@ -135,7 +135,9 @@ static int stop_ptraced_child(int pid, void *stack, int exitcode,
135} 135}
136 136
137int ptrace_faultinfo = 1; 137int ptrace_faultinfo = 1;
138int ptrace_ldt = 1;
138int proc_mm = 1; 139int proc_mm = 1;
140int skas_needs_stub = 0;
139 141
140static int __init skas0_cmd_param(char *str, int* add) 142static int __init skas0_cmd_param(char *str, int* add)
141{ 143{
@@ -294,7 +296,7 @@ static void __init check_ptrace(void)
294 check_sysemu(); 296 check_sysemu();
295} 297}
296 298
297extern int create_tmp_file(unsigned long len); 299extern int create_tmp_file(unsigned long long len);
298 300
299static void check_tmpexec(void) 301static void check_tmpexec(void)
300{ 302{
@@ -352,14 +354,26 @@ __uml_setup("noptracefaultinfo", noptracefaultinfo_cmd_param,
352" it. To support PTRACE_FAULTINFO, the host needs to be patched\n" 354" it. To support PTRACE_FAULTINFO, the host needs to be patched\n"
353" using the current skas3 patch.\n\n"); 355" using the current skas3 patch.\n\n");
354 356
357static int __init noptraceldt_cmd_param(char *str, int* add)
358{
359 ptrace_ldt = 0;
360 return 0;
361}
362
363__uml_setup("noptraceldt", noptraceldt_cmd_param,
364"noptraceldt\n"
365" Turns off usage of PTRACE_LDT, even if host supports it.\n"
366" To support PTRACE_LDT, the host needs to be patched using\n"
367" the current skas3 patch.\n\n");
368
355#ifdef UML_CONFIG_MODE_SKAS 369#ifdef UML_CONFIG_MODE_SKAS
356static inline void check_skas3_ptrace_support(void) 370static inline void check_skas3_ptrace_faultinfo(void)
357{ 371{
358 struct ptrace_faultinfo fi; 372 struct ptrace_faultinfo fi;
359 void *stack; 373 void *stack;
360 int pid, n; 374 int pid, n;
361 375
362 printf("Checking for the skas3 patch in the host..."); 376 printf(" - PTRACE_FAULTINFO...");
363 pid = start_ptraced_child(&stack); 377 pid = start_ptraced_child(&stack);
364 378
365 n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi); 379 n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi);
@@ -381,9 +395,49 @@ static inline void check_skas3_ptrace_support(void)
381 stop_ptraced_child(pid, stack, 1, 1); 395 stop_ptraced_child(pid, stack, 1, 1);
382} 396}
383 397
384int can_do_skas(void) 398static inline void check_skas3_ptrace_ldt(void)
399{
400#ifdef PTRACE_LDT
401 void *stack;
402 int pid, n;
403 unsigned char ldtbuf[40];
404 struct ptrace_ldt ldt_op = (struct ptrace_ldt) {
405 .func = 2, /* read default ldt */
406 .ptr = ldtbuf,
407 .bytecount = sizeof(ldtbuf)};
408
409 printf(" - PTRACE_LDT...");
410 pid = start_ptraced_child(&stack);
411
412 n = ptrace(PTRACE_LDT, pid, 0, (unsigned long) &ldt_op);
413 if (n < 0) {
414 if(errno == EIO)
415 printf("not found\n");
416 else {
417 perror("not found");
418 }
419 ptrace_ldt = 0;
420 }
421 else {
422 if(ptrace_ldt)
423 printf("found\n");
424 else
425 printf("found, but use is disabled\n");
426 }
427
428 stop_ptraced_child(pid, stack, 1, 1);
429#else
430 /* PTRACE_LDT might be disabled via cmdline option.
431 * We want to override this, else we might use the stub
432 * without real need
433 */
434 ptrace_ldt = 1;
435#endif
436}
437
438static inline void check_skas3_proc_mm(void)
385{ 439{
386 printf("Checking for /proc/mm..."); 440 printf(" - /proc/mm...");
387 if (os_access("/proc/mm", OS_ACC_W_OK) < 0) { 441 if (os_access("/proc/mm", OS_ACC_W_OK) < 0) {
388 proc_mm = 0; 442 proc_mm = 0;
389 printf("not found\n"); 443 printf("not found\n");
@@ -394,8 +448,19 @@ int can_do_skas(void)
394 else 448 else
395 printf("found\n"); 449 printf("found\n");
396 } 450 }
451}
452
453int can_do_skas(void)
454{
455 printf("Checking for the skas3 patch in the host:\n");
456
457 check_skas3_proc_mm();
458 check_skas3_ptrace_faultinfo();
459 check_skas3_ptrace_ldt();
460
461 if(!proc_mm || !ptrace_faultinfo || !ptrace_ldt)
462 skas_needs_stub = 1;
397 463
398 check_skas3_ptrace_support();
399 return 1; 464 return 1;
400} 465}
401#else 466#else
diff --git a/arch/um/os-Linux/uaccess.c b/arch/um/os-Linux/uaccess.c
new file mode 100644
index 000000000000..38d710158c3d
--- /dev/null
+++ b/arch/um/os-Linux/uaccess.c
@@ -0,0 +1,32 @@
1/*
2 * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk)
3 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
4 * Licensed under the GPL
5 */
6
7#include <setjmp.h>
8#include <string.h>
9
10unsigned long __do_user_copy(void *to, const void *from, int n,
11 void **fault_addr, void **fault_catcher,
12 void (*op)(void *to, const void *from,
13 int n), int *faulted_out)
14{
15 unsigned long *faddrp = (unsigned long *) fault_addr, ret;
16
17 sigjmp_buf jbuf;
18 *fault_catcher = &jbuf;
19 if(sigsetjmp(jbuf, 1) == 0){
20 (*op)(to, from, n);
21 ret = 0;
22 *faulted_out = 0;
23 }
24 else {
25 ret = *faddrp;
26 *faulted_out = 1;
27 }
28 *fault_addr = NULL;
29 *fault_catcher = NULL;
30 return ret;
31}
32
diff --git a/arch/um/scripts/Makefile.rules b/arch/um/scripts/Makefile.rules
index 651d9d88b656..b3fbf125709b 100644
--- a/arch/um/scripts/Makefile.rules
+++ b/arch/um/scripts/Makefile.rules
@@ -26,8 +26,13 @@ define unprofile
26 $(patsubst -pg,,$(patsubst -fprofile-arcs -ftest-coverage,,$(1))) 26 $(patsubst -pg,,$(patsubst -fprofile-arcs -ftest-coverage,,$(1)))
27endef 27endef
28 28
29# cmd_make_link checks to see if the $(foo-dir) variable starts with a /. If
30# so, it's considered to be a path relative to $(srcdir) rather than
31# $(srcdir)/arch/$(SUBARCH). This is because x86_64 wants to get ldt.c from
32# arch/um/sys-i386 rather than arch/i386 like the other borrowed files. So,
33# it sets $(ldt.c-dir) to /arch/um/sys-i386.
29quiet_cmd_make_link = SYMLINK $@ 34quiet_cmd_make_link = SYMLINK $@
30cmd_make_link = ln -sf $(srctree)/arch/$(SUBARCH)/$($(notdir $@)-dir)/$(notdir $@) $@ 35cmd_make_link = rm -f $@; ln -sf $(srctree)$(if $(filter-out /%,$($(notdir $@)-dir)),/arch/$(SUBARCH))/$($(notdir $@)-dir)/$(notdir $@) $@
31 36
32# this needs to be before the foreach, because targets does not accept 37# this needs to be before the foreach, because targets does not accept
33# complete paths like $(obj)/$(f). To make sure this works, use a := assignment 38# complete paths like $(obj)/$(f). To make sure this works, use a := assignment
diff --git a/arch/um/sys-i386/ldt.c b/arch/um/sys-i386/ldt.c
index 36b5c2c13289..6360f1c958d0 100644
--- a/arch/um/sys-i386/ldt.c
+++ b/arch/um/sys-i386/ldt.c
@@ -3,53 +3,26 @@
3 * Licensed under the GPL 3 * Licensed under the GPL
4 */ 4 */
5 5
6#include "linux/stddef.h"
6#include "linux/config.h" 7#include "linux/config.h"
7#include "linux/sched.h" 8#include "linux/sched.h"
8#include "linux/slab.h" 9#include "linux/slab.h"
9#include "linux/types.h" 10#include "linux/types.h"
11#include "linux/errno.h"
10#include "asm/uaccess.h" 12#include "asm/uaccess.h"
11#include "asm/ptrace.h"
12#include "asm/smp.h" 13#include "asm/smp.h"
13#include "asm/ldt.h" 14#include "asm/ldt.h"
15#include "asm/unistd.h"
14#include "choose-mode.h" 16#include "choose-mode.h"
15#include "kern.h" 17#include "kern.h"
16#include "mode_kern.h" 18#include "mode_kern.h"
17 19
18#ifdef CONFIG_MODE_TT
19
20extern int modify_ldt(int func, void *ptr, unsigned long bytecount); 20extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
21 21
22static int do_modify_ldt_tt(int func, void *ptr, unsigned long bytecount) 22#ifdef CONFIG_MODE_TT
23{
24 return modify_ldt(func, ptr, bytecount);
25}
26
27#endif
28
29#ifdef CONFIG_MODE_SKAS
30
31#include "skas.h"
32#include "skas_ptrace.h"
33
34static int do_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
35{
36 struct ptrace_ldt ldt;
37 u32 cpu;
38 int res;
39
40 ldt = ((struct ptrace_ldt) { .func = func,
41 .ptr = ptr,
42 .bytecount = bytecount });
43
44 cpu = get_cpu();
45 res = ptrace(PTRACE_LDT, userspace_pid[cpu], 0, (unsigned long) &ldt);
46 put_cpu();
47
48 return res;
49}
50#endif
51 23
52int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount) 24static long do_modify_ldt_tt(int func, void __user *ptr,
25 unsigned long bytecount)
53{ 26{
54 struct user_desc info; 27 struct user_desc info;
55 int res = 0; 28 int res = 0;
@@ -89,8 +62,7 @@ int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
89 goto out; 62 goto out;
90 } 63 }
91 64
92 res = CHOOSE_MODE_PROC(do_modify_ldt_tt, do_modify_ldt_skas, func, 65 res = modify_ldt(func, p, bytecount);
93 p, bytecount);
94 if(res < 0) 66 if(res < 0)
95 goto out; 67 goto out;
96 68
@@ -108,3 +80,467 @@ out:
108 kfree(buf); 80 kfree(buf);
109 return res; 81 return res;
110} 82}
83
84#endif
85
86#ifdef CONFIG_MODE_SKAS
87
88#include "skas.h"
89#include "skas_ptrace.h"
90#include "asm/mmu_context.h"
91
92long write_ldt_entry(struct mm_id * mm_idp, int func, struct user_desc * desc,
93 void **addr, int done)
94{
95 long res;
96
97 if(proc_mm){
98 /* This is a special handling for the case, that the mm to
99 * modify isn't current->active_mm.
100 * If this is called directly by modify_ldt,
101 * (current->active_mm->context.skas.u == mm_idp)
102 * will be true. So no call to switch_mm_skas(mm_idp) is done.
103 * If this is called in case of init_new_ldt or PTRACE_LDT,
104 * mm_idp won't belong to current->active_mm, but child->mm.
105 * So we need to switch child's mm into our userspace, then
106 * later switch back.
107 *
108 * Note: I'm unshure: should interrupts be disabled here?
109 */
110 if(!current->active_mm || current->active_mm == &init_mm ||
111 mm_idp != &current->active_mm->context.skas.id)
112 switch_mm_skas(mm_idp);
113 }
114
115 if(ptrace_ldt) {
116 struct ptrace_ldt ldt_op = (struct ptrace_ldt) {
117 .func = func,
118 .ptr = desc,
119 .bytecount = sizeof(*desc)};
120 u32 cpu;
121 int pid;
122
123 if(!proc_mm)
124 pid = mm_idp->u.pid;
125 else {
126 cpu = get_cpu();
127 pid = userspace_pid[cpu];
128 }
129
130 res = ptrace(PTRACE_LDT, pid, 0, (unsigned long) &ldt_op);
131 if(res)
132 res = errno;
133
134 if(proc_mm)
135 put_cpu();
136 }
137 else {
138 void *stub_addr;
139 res = syscall_stub_data(mm_idp, (unsigned long *)desc,
140 (sizeof(*desc) + sizeof(long) - 1) &
141 ~(sizeof(long) - 1),
142 addr, &stub_addr);
143 if(!res){
144 unsigned long args[] = { func,
145 (unsigned long)stub_addr,
146 sizeof(*desc),
147 0, 0, 0 };
148 res = run_syscall_stub(mm_idp, __NR_modify_ldt, args,
149 0, addr, done);
150 }
151 }
152
153 if(proc_mm){
154 /* This is the second part of special handling, that makes
155 * PTRACE_LDT possible to implement.
156 */
157 if(current->active_mm && current->active_mm != &init_mm &&
158 mm_idp != &current->active_mm->context.skas.id)
159 switch_mm_skas(&current->active_mm->context.skas.id);
160 }
161
162 return res;
163}
164
165static long read_ldt_from_host(void __user * ptr, unsigned long bytecount)
166{
167 int res, n;
168 struct ptrace_ldt ptrace_ldt = (struct ptrace_ldt) {
169 .func = 0,
170 .bytecount = bytecount,
171 .ptr = (void *)kmalloc(bytecount, GFP_KERNEL)};
172 u32 cpu;
173
174 if(ptrace_ldt.ptr == NULL)
175 return -ENOMEM;
176
177 /* This is called from sys_modify_ldt only, so userspace_pid gives
178 * us the right number
179 */
180
181 cpu = get_cpu();
182 res = ptrace(PTRACE_LDT, userspace_pid[cpu], 0,
183 (unsigned long) &ptrace_ldt);
184 put_cpu();
185 if(res < 0)
186 goto out;
187
188 n = copy_to_user(ptr, ptrace_ldt.ptr, res);
189 if(n != 0)
190 res = -EFAULT;
191
192 out:
193 kfree(ptrace_ldt.ptr);
194
195 return res;
196}
197
198/*
199 * In skas mode, we hold our own ldt data in UML.
200 * Thus, the code implementing sys_modify_ldt_skas
201 * is very similar to (and mostly stolen from) sys_modify_ldt
202 * for arch/i386/kernel/ldt.c
203 * The routines copied and modified in part are:
204 * - read_ldt
205 * - read_default_ldt
206 * - write_ldt
207 * - sys_modify_ldt_skas
208 */
209
210static int read_ldt(void __user * ptr, unsigned long bytecount)
211{
212 int i, err = 0;
213 unsigned long size;
214 uml_ldt_t * ldt = &current->mm->context.skas.ldt;
215
216 if(!ldt->entry_count)
217 goto out;
218 if(bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES)
219 bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES;
220 err = bytecount;
221
222 if(ptrace_ldt){
223 return read_ldt_from_host(ptr, bytecount);
224 }
225
226 down(&ldt->semaphore);
227 if(ldt->entry_count <= LDT_DIRECT_ENTRIES){
228 size = LDT_ENTRY_SIZE*LDT_DIRECT_ENTRIES;
229 if(size > bytecount)
230 size = bytecount;
231 if(copy_to_user(ptr, ldt->entries, size))
232 err = -EFAULT;
233 bytecount -= size;
234 ptr += size;
235 }
236 else {
237 for(i=0; i<ldt->entry_count/LDT_ENTRIES_PER_PAGE && bytecount;
238 i++){
239 size = PAGE_SIZE;
240 if(size > bytecount)
241 size = bytecount;
242 if(copy_to_user(ptr, ldt->pages[i], size)){
243 err = -EFAULT;
244 break;
245 }
246 bytecount -= size;
247 ptr += size;
248 }
249 }
250 up(&ldt->semaphore);
251
252 if(bytecount == 0 || err == -EFAULT)
253 goto out;
254
255 if(clear_user(ptr, bytecount))
256 err = -EFAULT;
257
258out:
259 return err;
260}
261
262static int read_default_ldt(void __user * ptr, unsigned long bytecount)
263{
264 int err;
265
266 if(bytecount > 5*LDT_ENTRY_SIZE)
267 bytecount = 5*LDT_ENTRY_SIZE;
268
269 err = bytecount;
270 /* UML doesn't support lcall7 and lcall27.
271 * So, we don't really have a default ldt, but emulate
272 * an empty ldt of common host default ldt size.
273 */
274 if(clear_user(ptr, bytecount))
275 err = -EFAULT;
276
277 return err;
278}
279
280static int write_ldt(void __user * ptr, unsigned long bytecount, int func)
281{
282 uml_ldt_t * ldt = &current->mm->context.skas.ldt;
283 struct mm_id * mm_idp = &current->mm->context.skas.id;
284 int i, err;
285 struct user_desc ldt_info;
286 struct ldt_entry entry0, *ldt_p;
287 void *addr = NULL;
288
289 err = -EINVAL;
290 if(bytecount != sizeof(ldt_info))
291 goto out;
292 err = -EFAULT;
293 if(copy_from_user(&ldt_info, ptr, sizeof(ldt_info)))
294 goto out;
295
296 err = -EINVAL;
297 if(ldt_info.entry_number >= LDT_ENTRIES)
298 goto out;
299 if(ldt_info.contents == 3){
300 if (func == 1)
301 goto out;
302 if (ldt_info.seg_not_present == 0)
303 goto out;
304 }
305
306 if(!ptrace_ldt)
307 down(&ldt->semaphore);
308
309 err = write_ldt_entry(mm_idp, func, &ldt_info, &addr, 1);
310 if(err)
311 goto out_unlock;
312 else if(ptrace_ldt) {
313 /* With PTRACE_LDT available, this is used as a flag only */
314 ldt->entry_count = 1;
315 goto out;
316 }
317
318 if(ldt_info.entry_number >= ldt->entry_count &&
319 ldt_info.entry_number >= LDT_DIRECT_ENTRIES){
320 for(i=ldt->entry_count/LDT_ENTRIES_PER_PAGE;
321 i*LDT_ENTRIES_PER_PAGE <= ldt_info.entry_number;
322 i++){
323 if(i == 0)
324 memcpy(&entry0, ldt->entries, sizeof(entry0));
325 ldt->pages[i] = (struct ldt_entry *)
326 __get_free_page(GFP_KERNEL|__GFP_ZERO);
327 if(!ldt->pages[i]){
328 err = -ENOMEM;
329 /* Undo the change in host */
330 memset(&ldt_info, 0, sizeof(ldt_info));
331 write_ldt_entry(mm_idp, 1, &ldt_info, &addr, 1);
332 goto out_unlock;
333 }
334 if(i == 0) {
335 memcpy(ldt->pages[0], &entry0, sizeof(entry0));
336 memcpy(ldt->pages[0]+1, ldt->entries+1,
337 sizeof(entry0)*(LDT_DIRECT_ENTRIES-1));
338 }
339 ldt->entry_count = (i + 1) * LDT_ENTRIES_PER_PAGE;
340 }
341 }
342 if(ldt->entry_count <= ldt_info.entry_number)
343 ldt->entry_count = ldt_info.entry_number + 1;
344
345 if(ldt->entry_count <= LDT_DIRECT_ENTRIES)
346 ldt_p = ldt->entries + ldt_info.entry_number;
347 else
348 ldt_p = ldt->pages[ldt_info.entry_number/LDT_ENTRIES_PER_PAGE] +
349 ldt_info.entry_number%LDT_ENTRIES_PER_PAGE;
350
351 if(ldt_info.base_addr == 0 && ldt_info.limit == 0 &&
352 (func == 1 || LDT_empty(&ldt_info))){
353 ldt_p->a = 0;
354 ldt_p->b = 0;
355 }
356 else{
357 if (func == 1)
358 ldt_info.useable = 0;
359 ldt_p->a = LDT_entry_a(&ldt_info);
360 ldt_p->b = LDT_entry_b(&ldt_info);
361 }
362 err = 0;
363
364out_unlock:
365 up(&ldt->semaphore);
366out:
367 return err;
368}
369
370static long do_modify_ldt_skas(int func, void __user *ptr,
371 unsigned long bytecount)
372{
373 int ret = -ENOSYS;
374
375 switch (func) {
376 case 0:
377 ret = read_ldt(ptr, bytecount);
378 break;
379 case 1:
380 case 0x11:
381 ret = write_ldt(ptr, bytecount, func);
382 break;
383 case 2:
384 ret = read_default_ldt(ptr, bytecount);
385 break;
386 }
387 return ret;
388}
389
390short dummy_list[9] = {0, -1};
391short * host_ldt_entries = NULL;
392
393void ldt_get_host_info(void)
394{
395 long ret;
396 struct ldt_entry * ldt;
397 int i, size, k, order;
398
399 host_ldt_entries = dummy_list+1;
400
401 for(i = LDT_PAGES_MAX-1, order=0; i; i>>=1, order++);
402
403 ldt = (struct ldt_entry *)
404 __get_free_pages(GFP_KERNEL|__GFP_ZERO, order);
405 if(ldt == NULL) {
406 printk("ldt_get_host_info: couldn't allocate buffer for host ldt\n");
407 return;
408 }
409
410 ret = modify_ldt(0, ldt, (1<<order)*PAGE_SIZE);
411 if(ret < 0) {
412 printk("ldt_get_host_info: couldn't read host ldt\n");
413 goto out_free;
414 }
415 if(ret == 0) {
416 /* default_ldt is active, simply write an empty entry 0 */
417 host_ldt_entries = dummy_list;
418 goto out_free;
419 }
420
421 for(i=0, size=0; i<ret/LDT_ENTRY_SIZE; i++){
422 if(ldt[i].a != 0 || ldt[i].b != 0)
423 size++;
424 }
425
426 if(size < sizeof(dummy_list)/sizeof(dummy_list[0])) {
427 host_ldt_entries = dummy_list;
428 }
429 else {
430 size = (size + 1) * sizeof(dummy_list[0]);
431 host_ldt_entries = (short *)kmalloc(size, GFP_KERNEL);
432 if(host_ldt_entries == NULL) {
433 printk("ldt_get_host_info: couldn't allocate host ldt list\n");
434 goto out_free;
435 }
436 }
437
438 for(i=0, k=0; i<ret/LDT_ENTRY_SIZE; i++){
439 if(ldt[i].a != 0 || ldt[i].b != 0) {
440 host_ldt_entries[k++] = i;
441 }
442 }
443 host_ldt_entries[k] = -1;
444
445out_free:
446 free_pages((unsigned long)ldt, order);
447}
448
449long init_new_ldt(struct mmu_context_skas * new_mm,
450 struct mmu_context_skas * from_mm)
451{
452 struct user_desc desc;
453 short * num_p;
454 int i;
455 long page, err=0;
456 void *addr = NULL;
457
458 memset(&desc, 0, sizeof(desc));
459
460 if(!ptrace_ldt)
461 init_MUTEX(&new_mm->ldt.semaphore);
462
463 if(!from_mm){
464 /*
465 * We have to initialize a clean ldt.
466 */
467 if(proc_mm) {
468 /*
469 * If the new mm was created using proc_mm, host's
470 * default-ldt currently is assigned, which normally
471 * contains the call-gates for lcall7 and lcall27.
472 * To remove these gates, we simply write an empty
473 * entry as number 0 to the host.
474 */
475 err = write_ldt_entry(&new_mm->id, 1, &desc,
476 &addr, 1);
477 }
478 else{
479 /*
480 * Now we try to retrieve info about the ldt, we
481 * inherited from the host. All ldt-entries found
482 * will be reset in the following loop
483 */
484 if(host_ldt_entries == NULL)
485 ldt_get_host_info();
486 for(num_p=host_ldt_entries; *num_p != -1; num_p++){
487 desc.entry_number = *num_p;
488 err = write_ldt_entry(&new_mm->id, 1, &desc,
489 &addr, *(num_p + 1) == -1);
490 if(err)
491 break;
492 }
493 }
494 new_mm->ldt.entry_count = 0;
495 }
496 else if (!ptrace_ldt) {
497 /* Our local LDT is used to supply the data for
498 * modify_ldt(READLDT), if PTRACE_LDT isn't available,
499 * i.e., we have to use the stub for modify_ldt, which
500 * can't handle the big read buffer of up to 64kB.
501 */
502 down(&from_mm->ldt.semaphore);
503 if(from_mm->ldt.entry_count <= LDT_DIRECT_ENTRIES){
504 memcpy(new_mm->ldt.entries, from_mm->ldt.entries,
505 sizeof(new_mm->ldt.entries));
506 }
507 else{
508 i = from_mm->ldt.entry_count / LDT_ENTRIES_PER_PAGE;
509 while(i-->0){
510 page = __get_free_page(GFP_KERNEL|__GFP_ZERO);
511 if (!page){
512 err = -ENOMEM;
513 break;
514 }
515 new_mm->ldt.pages[i] = (struct ldt_entry*)page;
516 memcpy(new_mm->ldt.pages[i],
517 from_mm->ldt.pages[i], PAGE_SIZE);
518 }
519 }
520 new_mm->ldt.entry_count = from_mm->ldt.entry_count;
521 up(&from_mm->ldt.semaphore);
522 }
523
524 return err;
525}
526
527
528void free_ldt(struct mmu_context_skas * mm)
529{
530 int i;
531
532 if(!ptrace_ldt && mm->ldt.entry_count > LDT_DIRECT_ENTRIES){
533 i = mm->ldt.entry_count / LDT_ENTRIES_PER_PAGE;
534 while(i-- > 0){
535 free_page((long )mm->ldt.pages[i]);
536 }
537 }
538 mm->ldt.entry_count = 0;
539}
540#endif
541
542int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
543{
544 return(CHOOSE_MODE_PROC(do_modify_ldt_tt, do_modify_ldt_skas, func,
545 ptr, bytecount));
546}
diff --git a/arch/um/sys-x86_64/Makefile b/arch/um/sys-x86_64/Makefile
index 06c3633457a2..ea977df395a1 100644
--- a/arch/um/sys-x86_64/Makefile
+++ b/arch/um/sys-x86_64/Makefile
@@ -5,7 +5,7 @@
5# 5#
6 6
7#XXX: why into lib-y? 7#XXX: why into lib-y?
8lib-y = bitops.o bugs.o csum-partial.o delay.o fault.o mem.o memcpy.o \ 8lib-y = bitops.o bugs.o csum-partial.o delay.o fault.o ldt.o mem.o memcpy.o \
9 ptrace.o ptrace_user.o sigcontext.o signal.o stub.o \ 9 ptrace.o ptrace_user.o sigcontext.o signal.o stub.o \
10 stub_segv.o syscalls.o syscall_table.o sysrq.o thunk.o 10 stub_segv.o syscalls.o syscall_table.o sysrq.o thunk.o
11 11
@@ -14,7 +14,7 @@ obj-$(CONFIG_MODULES) += module.o um_module.o
14 14
15USER_OBJS := ptrace_user.o sigcontext.o 15USER_OBJS := ptrace_user.o sigcontext.o
16 16
17SYMLINKS = bitops.c csum-copy.S csum-partial.c csum-wrappers.c memcpy.S \ 17SYMLINKS = bitops.c csum-copy.S csum-partial.c csum-wrappers.c ldt.c memcpy.S \
18 thunk.S module.c 18 thunk.S module.c
19 19
20include arch/um/scripts/Makefile.rules 20include arch/um/scripts/Makefile.rules
@@ -23,6 +23,7 @@ bitops.c-dir = lib
23csum-copy.S-dir = lib 23csum-copy.S-dir = lib
24csum-partial.c-dir = lib 24csum-partial.c-dir = lib
25csum-wrappers.c-dir = lib 25csum-wrappers.c-dir = lib
26ldt.c-dir = /arch/um/sys-i386
26memcpy.S-dir = lib 27memcpy.S-dir = lib
27thunk.S-dir = lib 28thunk.S-dir = lib
28module.c-dir = kernel 29module.c-dir = kernel
diff --git a/arch/um/sys-x86_64/syscalls.c b/arch/um/sys-x86_64/syscalls.c
index 3259a4db4534..6acee5c4ada6 100644
--- a/arch/um/sys-x86_64/syscalls.c
+++ b/arch/um/sys-x86_64/syscalls.c
@@ -29,81 +29,6 @@ asmlinkage long sys_uname64(struct new_utsname __user * name)
29} 29}
30 30
31#ifdef CONFIG_MODE_TT 31#ifdef CONFIG_MODE_TT
32extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
33
34long sys_modify_ldt_tt(int func, void *ptr, unsigned long bytecount)
35{
36 /* XXX This should check VERIFY_WRITE depending on func, check this
37 * in i386 as well.
38 */
39 if (!access_ok(VERIFY_READ, ptr, bytecount))
40 return -EFAULT;
41 return(modify_ldt(func, ptr, bytecount));
42}
43#endif
44
45#ifdef CONFIG_MODE_SKAS
46extern int userspace_pid[];
47
48#include "skas_ptrace.h"
49
50long sys_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
51{
52 struct ptrace_ldt ldt;
53 void *buf;
54 int res, n;
55
56 buf = kmalloc(bytecount, GFP_KERNEL);
57 if(buf == NULL)
58 return(-ENOMEM);
59
60 res = 0;
61
62 switch(func){
63 case 1:
64 case 0x11:
65 res = copy_from_user(buf, ptr, bytecount);
66 break;
67 }
68
69 if(res != 0){
70 res = -EFAULT;
71 goto out;
72 }
73
74 ldt = ((struct ptrace_ldt) { .func = func,
75 .ptr = buf,
76 .bytecount = bytecount });
77#warning Need to look up userspace_pid by cpu
78 res = ptrace(PTRACE_LDT, userspace_pid[0], 0, (unsigned long) &ldt);
79 if(res < 0)
80 goto out;
81
82 switch(func){
83 case 0:
84 case 2:
85 n = res;
86 res = copy_to_user(ptr, buf, n);
87 if(res != 0)
88 res = -EFAULT;
89 else
90 res = n;
91 break;
92 }
93
94 out:
95 kfree(buf);
96 return(res);
97}
98#endif
99
100long sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
101{
102 return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func,
103 ptr, bytecount));
104}
105
106#ifdef CONFIG_MODE_TT
107extern long arch_prctl(int code, unsigned long addr); 32extern long arch_prctl(int code, unsigned long addr);
108 33
109static long arch_prctl_tt(int code, unsigned long addr) 34static long arch_prctl_tt(int code, unsigned long addr)
diff --git a/arch/v850/kernel/ptrace.c b/arch/v850/kernel/ptrace.c
index d6077ff47d22..18492d02aaf6 100644
--- a/arch/v850/kernel/ptrace.c
+++ b/arch/v850/kernel/ptrace.c
@@ -113,45 +113,10 @@ static int set_single_step (struct task_struct *t, int val)
113 return 1; 113 return 1;
114} 114}
115 115
116long sys_ptrace(long request, long pid, long addr, long data) 116long arch_ptrace(struct task_struct *child, long request, long addr, long data)
117{ 117{
118 struct task_struct *child;
119 int rval; 118 int rval;
120 119
121 lock_kernel();
122
123 if (request == PTRACE_TRACEME) {
124 /* are we already being traced? */
125 if (current->ptrace & PT_PTRACED) {
126 rval = -EPERM;
127 goto out;
128 }
129 /* set the ptrace bit in the process flags. */
130 current->ptrace |= PT_PTRACED;
131 rval = 0;
132 goto out;
133 }
134 rval = -ESRCH;
135 read_lock(&tasklist_lock);
136 child = find_task_by_pid(pid);
137 if (child)
138 get_task_struct(child);
139 read_unlock(&tasklist_lock);
140 if (!child)
141 goto out;
142
143 rval = -EPERM;
144 if (pid == 1) /* you may not mess with init */
145 goto out_tsk;
146
147 if (request == PTRACE_ATTACH) {
148 rval = ptrace_attach(child);
149 goto out_tsk;
150 }
151 rval = ptrace_check_attach(child, request == PTRACE_KILL);
152 if (rval < 0)
153 goto out_tsk;
154
155 switch (request) { 120 switch (request) {
156 unsigned long val, copied; 121 unsigned long val, copied;
157 122
@@ -248,11 +213,7 @@ long sys_ptrace(long request, long pid, long addr, long data)
248 rval = -EIO; 213 rval = -EIO;
249 goto out; 214 goto out;
250 } 215 }
251 216 out:
252out_tsk:
253 put_task_struct(child);
254out:
255 unlock_kernel();
256 return rval; 217 return rval;
257} 218}
258 219
diff --git a/arch/x86_64/Kconfig b/arch/x86_64/Kconfig
index 21afa69a086d..4cce2f6f170c 100644
--- a/arch/x86_64/Kconfig
+++ b/arch/x86_64/Kconfig
@@ -532,8 +532,21 @@ source "drivers/firmware/Kconfig"
532 532
533source fs/Kconfig 533source fs/Kconfig
534 534
535menu "Instrumentation Support"
536 depends on EXPERIMENTAL
537
535source "arch/x86_64/oprofile/Kconfig" 538source "arch/x86_64/oprofile/Kconfig"
536 539
540config KPROBES
541 bool "Kprobes (EXPERIMENTAL)"
542 help
543 Kprobes allows you to trap at almost any kernel address and
544 execute a callback function. register_kprobe() establishes
545 a probepoint and specifies the callback. Kprobes is useful
546 for kernel debugging, non-intrusive instrumentation and testing.
547 If in doubt, say "N".
548endmenu
549
537source "arch/x86_64/Kconfig.debug" 550source "arch/x86_64/Kconfig.debug"
538 551
539source "security/Kconfig" 552source "security/Kconfig"
diff --git a/arch/x86_64/Kconfig.debug b/arch/x86_64/Kconfig.debug
index 9cf1410d2f5a..d584ecc27ea1 100644
--- a/arch/x86_64/Kconfig.debug
+++ b/arch/x86_64/Kconfig.debug
@@ -33,16 +33,6 @@ config IOMMU_DEBUG
33 options. See Documentation/x86_64/boot-options.txt for more 33 options. See Documentation/x86_64/boot-options.txt for more
34 details. 34 details.
35 35
36config KPROBES
37 bool "Kprobes"
38 depends on DEBUG_KERNEL
39 help
40 Kprobes allows you to trap at almost any kernel address and
41 execute a callback function. register_kprobe() establishes
42 a probepoint and specifies the callback. Kprobes is useful
43 for kernel debugging, non-intrusive instrumentation and testing.
44 If in doubt, say "N".
45
46config IOMMU_LEAK 36config IOMMU_LEAK
47 bool "IOMMU leak tracing" 37 bool "IOMMU leak tracing"
48 depends on DEBUG_KERNEL 38 depends on DEBUG_KERNEL
diff --git a/arch/x86_64/kernel/kprobes.c b/arch/x86_64/kernel/kprobes.c
index 76a28b007be9..dddeb678b440 100644
--- a/arch/x86_64/kernel/kprobes.c
+++ b/arch/x86_64/kernel/kprobes.c
@@ -34,7 +34,6 @@
34#include <linux/config.h> 34#include <linux/config.h>
35#include <linux/kprobes.h> 35#include <linux/kprobes.h>
36#include <linux/ptrace.h> 36#include <linux/ptrace.h>
37#include <linux/spinlock.h>
38#include <linux/string.h> 37#include <linux/string.h>
39#include <linux/slab.h> 38#include <linux/slab.h>
40#include <linux/preempt.h> 39#include <linux/preempt.h>
@@ -44,17 +43,10 @@
44#include <asm/kdebug.h> 43#include <asm/kdebug.h>
45 44
46static DECLARE_MUTEX(kprobe_mutex); 45static DECLARE_MUTEX(kprobe_mutex);
47
48static struct kprobe *current_kprobe;
49static unsigned long kprobe_status, kprobe_old_rflags, kprobe_saved_rflags;
50static struct kprobe *kprobe_prev;
51static unsigned long kprobe_status_prev, kprobe_old_rflags_prev, kprobe_saved_rflags_prev;
52static struct pt_regs jprobe_saved_regs;
53static long *jprobe_saved_rsp;
54void jprobe_return_end(void); 46void jprobe_return_end(void);
55 47
56/* copy of the kernel stack at the probe fire time */ 48DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
57static kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE]; 49DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
58 50
59/* 51/*
60 * returns non-zero if opcode modifies the interrupt flag. 52 * returns non-zero if opcode modifies the interrupt flag.
@@ -236,29 +228,30 @@ void __kprobes arch_remove_kprobe(struct kprobe *p)
236 up(&kprobe_mutex); 228 up(&kprobe_mutex);
237} 229}
238 230
239static inline void save_previous_kprobe(void) 231static inline void save_previous_kprobe(struct kprobe_ctlblk *kcb)
240{ 232{
241 kprobe_prev = current_kprobe; 233 kcb->prev_kprobe.kp = kprobe_running();
242 kprobe_status_prev = kprobe_status; 234 kcb->prev_kprobe.status = kcb->kprobe_status;
243 kprobe_old_rflags_prev = kprobe_old_rflags; 235 kcb->prev_kprobe.old_rflags = kcb->kprobe_old_rflags;
244 kprobe_saved_rflags_prev = kprobe_saved_rflags; 236 kcb->prev_kprobe.saved_rflags = kcb->kprobe_saved_rflags;
245} 237}
246 238
247static inline void restore_previous_kprobe(void) 239static inline void restore_previous_kprobe(struct kprobe_ctlblk *kcb)
248{ 240{
249 current_kprobe = kprobe_prev; 241 __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
250 kprobe_status = kprobe_status_prev; 242 kcb->kprobe_status = kcb->prev_kprobe.status;
251 kprobe_old_rflags = kprobe_old_rflags_prev; 243 kcb->kprobe_old_rflags = kcb->prev_kprobe.old_rflags;
252 kprobe_saved_rflags = kprobe_saved_rflags_prev; 244 kcb->kprobe_saved_rflags = kcb->prev_kprobe.saved_rflags;
253} 245}
254 246
255static inline void set_current_kprobe(struct kprobe *p, struct pt_regs *regs) 247static inline void set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
248 struct kprobe_ctlblk *kcb)
256{ 249{
257 current_kprobe = p; 250 __get_cpu_var(current_kprobe) = p;
258 kprobe_saved_rflags = kprobe_old_rflags 251 kcb->kprobe_saved_rflags = kcb->kprobe_old_rflags
259 = (regs->eflags & (TF_MASK | IF_MASK)); 252 = (regs->eflags & (TF_MASK | IF_MASK));
260 if (is_IF_modifier(p->ainsn.insn)) 253 if (is_IF_modifier(p->ainsn.insn))
261 kprobe_saved_rflags &= ~IF_MASK; 254 kcb->kprobe_saved_rflags &= ~IF_MASK;
262} 255}
263 256
264static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs) 257static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
@@ -272,6 +265,7 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
272 regs->rip = (unsigned long)p->ainsn.insn; 265 regs->rip = (unsigned long)p->ainsn.insn;
273} 266}
274 267
268/* Called with kretprobe_lock held */
275void __kprobes arch_prepare_kretprobe(struct kretprobe *rp, 269void __kprobes arch_prepare_kretprobe(struct kretprobe *rp,
276 struct pt_regs *regs) 270 struct pt_regs *regs)
277{ 271{
@@ -292,32 +286,30 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe *rp,
292 } 286 }
293} 287}
294 288
295/*
296 * Interrupts are disabled on entry as trap3 is an interrupt gate and they
297 * remain disabled thorough out this function.
298 */
299int __kprobes kprobe_handler(struct pt_regs *regs) 289int __kprobes kprobe_handler(struct pt_regs *regs)
300{ 290{
301 struct kprobe *p; 291 struct kprobe *p;
302 int ret = 0; 292 int ret = 0;
303 kprobe_opcode_t *addr = (kprobe_opcode_t *)(regs->rip - sizeof(kprobe_opcode_t)); 293 kprobe_opcode_t *addr = (kprobe_opcode_t *)(regs->rip - sizeof(kprobe_opcode_t));
294 struct kprobe_ctlblk *kcb;
304 295
305 /* We're in an interrupt, but this is clear and BUG()-safe. */ 296 /*
297 * We don't want to be preempted for the entire
298 * duration of kprobe processing
299 */
306 preempt_disable(); 300 preempt_disable();
301 kcb = get_kprobe_ctlblk();
307 302
308 /* Check we're not actually recursing */ 303 /* Check we're not actually recursing */
309 if (kprobe_running()) { 304 if (kprobe_running()) {
310 /* We *are* holding lock here, so this is safe.
311 Disarm the probe we just hit, and ignore it. */
312 p = get_kprobe(addr); 305 p = get_kprobe(addr);
313 if (p) { 306 if (p) {
314 if (kprobe_status == KPROBE_HIT_SS && 307 if (kcb->kprobe_status == KPROBE_HIT_SS &&
315 *p->ainsn.insn == BREAKPOINT_INSTRUCTION) { 308 *p->ainsn.insn == BREAKPOINT_INSTRUCTION) {
316 regs->eflags &= ~TF_MASK; 309 regs->eflags &= ~TF_MASK;
317 regs->eflags |= kprobe_saved_rflags; 310 regs->eflags |= kcb->kprobe_saved_rflags;
318 unlock_kprobes();
319 goto no_kprobe; 311 goto no_kprobe;
320 } else if (kprobe_status == KPROBE_HIT_SSDONE) { 312 } else if (kcb->kprobe_status == KPROBE_HIT_SSDONE) {
321 /* TODO: Provide re-entrancy from 313 /* TODO: Provide re-entrancy from
322 * post_kprobes_handler() and avoid exception 314 * post_kprobes_handler() and avoid exception
323 * stack corruption while single-stepping on 315 * stack corruption while single-stepping on
@@ -325,6 +317,7 @@ int __kprobes kprobe_handler(struct pt_regs *regs)
325 */ 317 */
326 arch_disarm_kprobe(p); 318 arch_disarm_kprobe(p);
327 regs->rip = (unsigned long)p->addr; 319 regs->rip = (unsigned long)p->addr;
320 reset_current_kprobe();
328 ret = 1; 321 ret = 1;
329 } else { 322 } else {
330 /* We have reentered the kprobe_handler(), since 323 /* We have reentered the kprobe_handler(), since
@@ -334,27 +327,24 @@ int __kprobes kprobe_handler(struct pt_regs *regs)
334 * of the new probe without calling any user 327 * of the new probe without calling any user
335 * handlers. 328 * handlers.
336 */ 329 */
337 save_previous_kprobe(); 330 save_previous_kprobe(kcb);
338 set_current_kprobe(p, regs); 331 set_current_kprobe(p, regs, kcb);
339 p->nmissed++; 332 p->nmissed++;
340 prepare_singlestep(p, regs); 333 prepare_singlestep(p, regs);
341 kprobe_status = KPROBE_REENTER; 334 kcb->kprobe_status = KPROBE_REENTER;
342 return 1; 335 return 1;
343 } 336 }
344 } else { 337 } else {
345 p = current_kprobe; 338 p = __get_cpu_var(current_kprobe);
346 if (p->break_handler && p->break_handler(p, regs)) { 339 if (p->break_handler && p->break_handler(p, regs)) {
347 goto ss_probe; 340 goto ss_probe;
348 } 341 }
349 } 342 }
350 /* If it's not ours, can't be delete race, (we hold lock). */
351 goto no_kprobe; 343 goto no_kprobe;
352 } 344 }
353 345
354 lock_kprobes();
355 p = get_kprobe(addr); 346 p = get_kprobe(addr);
356 if (!p) { 347 if (!p) {
357 unlock_kprobes();
358 if (*addr != BREAKPOINT_INSTRUCTION) { 348 if (*addr != BREAKPOINT_INSTRUCTION) {
359 /* 349 /*
360 * The breakpoint instruction was removed right 350 * The breakpoint instruction was removed right
@@ -372,8 +362,8 @@ int __kprobes kprobe_handler(struct pt_regs *regs)
372 goto no_kprobe; 362 goto no_kprobe;
373 } 363 }
374 364
375 kprobe_status = KPROBE_HIT_ACTIVE; 365 set_current_kprobe(p, regs, kcb);
376 set_current_kprobe(p, regs); 366 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
377 367
378 if (p->pre_handler && p->pre_handler(p, regs)) 368 if (p->pre_handler && p->pre_handler(p, regs))
379 /* handler has already set things up, so skip ss setup */ 369 /* handler has already set things up, so skip ss setup */
@@ -381,7 +371,7 @@ int __kprobes kprobe_handler(struct pt_regs *regs)
381 371
382ss_probe: 372ss_probe:
383 prepare_singlestep(p, regs); 373 prepare_singlestep(p, regs);
384 kprobe_status = KPROBE_HIT_SS; 374 kcb->kprobe_status = KPROBE_HIT_SS;
385 return 1; 375 return 1;
386 376
387no_kprobe: 377no_kprobe:
@@ -409,9 +399,10 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
409 struct kretprobe_instance *ri = NULL; 399 struct kretprobe_instance *ri = NULL;
410 struct hlist_head *head; 400 struct hlist_head *head;
411 struct hlist_node *node, *tmp; 401 struct hlist_node *node, *tmp;
412 unsigned long orig_ret_address = 0; 402 unsigned long flags, orig_ret_address = 0;
413 unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline; 403 unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline;
414 404
405 spin_lock_irqsave(&kretprobe_lock, flags);
415 head = kretprobe_inst_table_head(current); 406 head = kretprobe_inst_table_head(current);
416 407
417 /* 408 /*
@@ -450,13 +441,14 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
450 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address)); 441 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
451 regs->rip = orig_ret_address; 442 regs->rip = orig_ret_address;
452 443
453 unlock_kprobes(); 444 reset_current_kprobe();
445 spin_unlock_irqrestore(&kretprobe_lock, flags);
454 preempt_enable_no_resched(); 446 preempt_enable_no_resched();
455 447
456 /* 448 /*
457 * By returning a non-zero value, we are telling 449 * By returning a non-zero value, we are telling
458 * kprobe_handler() that we have handled unlocking 450 * kprobe_handler() that we don't want the post_handler
459 * and re-enabling preemption. 451 * to run (and have re-enabled preemption)
460 */ 452 */
461 return 1; 453 return 1;
462} 454}
@@ -483,7 +475,8 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
483 * that is atop the stack is the address following the copied instruction. 475 * that is atop the stack is the address following the copied instruction.
484 * We need to make it the address following the original instruction. 476 * We need to make it the address following the original instruction.
485 */ 477 */
486static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs) 478static void __kprobes resume_execution(struct kprobe *p,
479 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
487{ 480{
488 unsigned long *tos = (unsigned long *)regs->rsp; 481 unsigned long *tos = (unsigned long *)regs->rsp;
489 unsigned long next_rip = 0; 482 unsigned long next_rip = 0;
@@ -498,7 +491,7 @@ static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
498 switch (*insn) { 491 switch (*insn) {
499 case 0x9c: /* pushfl */ 492 case 0x9c: /* pushfl */
500 *tos &= ~(TF_MASK | IF_MASK); 493 *tos &= ~(TF_MASK | IF_MASK);
501 *tos |= kprobe_old_rflags; 494 *tos |= kcb->kprobe_old_rflags;
502 break; 495 break;
503 case 0xc3: /* ret/lret */ 496 case 0xc3: /* ret/lret */
504 case 0xcb: 497 case 0xcb:
@@ -537,30 +530,28 @@ static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
537 } 530 }
538} 531}
539 532
540/*
541 * Interrupts are disabled on entry as trap1 is an interrupt gate and they
542 * remain disabled thoroughout this function. And we hold kprobe lock.
543 */
544int __kprobes post_kprobe_handler(struct pt_regs *regs) 533int __kprobes post_kprobe_handler(struct pt_regs *regs)
545{ 534{
546 if (!kprobe_running()) 535 struct kprobe *cur = kprobe_running();
536 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
537
538 if (!cur)
547 return 0; 539 return 0;
548 540
549 if ((kprobe_status != KPROBE_REENTER) && current_kprobe->post_handler) { 541 if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
550 kprobe_status = KPROBE_HIT_SSDONE; 542 kcb->kprobe_status = KPROBE_HIT_SSDONE;
551 current_kprobe->post_handler(current_kprobe, regs, 0); 543 cur->post_handler(cur, regs, 0);
552 } 544 }
553 545
554 resume_execution(current_kprobe, regs); 546 resume_execution(cur, regs, kcb);
555 regs->eflags |= kprobe_saved_rflags; 547 regs->eflags |= kcb->kprobe_saved_rflags;
556 548
557 /* Restore the original saved kprobes variables and continue. */ 549 /* Restore the original saved kprobes variables and continue. */
558 if (kprobe_status == KPROBE_REENTER) { 550 if (kcb->kprobe_status == KPROBE_REENTER) {
559 restore_previous_kprobe(); 551 restore_previous_kprobe(kcb);
560 goto out; 552 goto out;
561 } else {
562 unlock_kprobes();
563 } 553 }
554 reset_current_kprobe();
564out: 555out:
565 preempt_enable_no_resched(); 556 preempt_enable_no_resched();
566 557
@@ -575,18 +566,19 @@ out:
575 return 1; 566 return 1;
576} 567}
577 568
578/* Interrupts disabled, kprobe_lock held. */
579int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr) 569int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
580{ 570{
581 if (current_kprobe->fault_handler 571 struct kprobe *cur = kprobe_running();
582 && current_kprobe->fault_handler(current_kprobe, regs, trapnr)) 572 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
573
574 if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
583 return 1; 575 return 1;
584 576
585 if (kprobe_status & KPROBE_HIT_SS) { 577 if (kcb->kprobe_status & KPROBE_HIT_SS) {
586 resume_execution(current_kprobe, regs); 578 resume_execution(cur, regs, kcb);
587 regs->eflags |= kprobe_old_rflags; 579 regs->eflags |= kcb->kprobe_old_rflags;
588 580
589 unlock_kprobes(); 581 reset_current_kprobe();
590 preempt_enable_no_resched(); 582 preempt_enable_no_resched();
591 } 583 }
592 return 0; 584 return 0;
@@ -599,39 +591,41 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
599 unsigned long val, void *data) 591 unsigned long val, void *data)
600{ 592{
601 struct die_args *args = (struct die_args *)data; 593 struct die_args *args = (struct die_args *)data;
594 int ret = NOTIFY_DONE;
595
602 switch (val) { 596 switch (val) {
603 case DIE_INT3: 597 case DIE_INT3:
604 if (kprobe_handler(args->regs)) 598 if (kprobe_handler(args->regs))
605 return NOTIFY_STOP; 599 ret = NOTIFY_STOP;
606 break; 600 break;
607 case DIE_DEBUG: 601 case DIE_DEBUG:
608 if (post_kprobe_handler(args->regs)) 602 if (post_kprobe_handler(args->regs))
609 return NOTIFY_STOP; 603 ret = NOTIFY_STOP;
610 break; 604 break;
611 case DIE_GPF: 605 case DIE_GPF:
612 if (kprobe_running() &&
613 kprobe_fault_handler(args->regs, args->trapnr))
614 return NOTIFY_STOP;
615 break;
616 case DIE_PAGE_FAULT: 606 case DIE_PAGE_FAULT:
607 /* kprobe_running() needs smp_processor_id() */
608 preempt_disable();
617 if (kprobe_running() && 609 if (kprobe_running() &&
618 kprobe_fault_handler(args->regs, args->trapnr)) 610 kprobe_fault_handler(args->regs, args->trapnr))
619 return NOTIFY_STOP; 611 ret = NOTIFY_STOP;
612 preempt_enable();
620 break; 613 break;
621 default: 614 default:
622 break; 615 break;
623 } 616 }
624 return NOTIFY_DONE; 617 return ret;
625} 618}
626 619
627int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) 620int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
628{ 621{
629 struct jprobe *jp = container_of(p, struct jprobe, kp); 622 struct jprobe *jp = container_of(p, struct jprobe, kp);
630 unsigned long addr; 623 unsigned long addr;
624 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
631 625
632 jprobe_saved_regs = *regs; 626 kcb->jprobe_saved_regs = *regs;
633 jprobe_saved_rsp = (long *) regs->rsp; 627 kcb->jprobe_saved_rsp = (long *) regs->rsp;
634 addr = (unsigned long)jprobe_saved_rsp; 628 addr = (unsigned long)(kcb->jprobe_saved_rsp);
635 /* 629 /*
636 * As Linus pointed out, gcc assumes that the callee 630 * As Linus pointed out, gcc assumes that the callee
637 * owns the argument space and could overwrite it, e.g. 631 * owns the argument space and could overwrite it, e.g.
@@ -639,7 +633,8 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
639 * we also save and restore enough stack bytes to cover 633 * we also save and restore enough stack bytes to cover
640 * the argument area. 634 * the argument area.
641 */ 635 */
642 memcpy(jprobes_stack, (kprobe_opcode_t *) addr, MIN_STACK_SIZE(addr)); 636 memcpy(kcb->jprobes_stack, (kprobe_opcode_t *)addr,
637 MIN_STACK_SIZE(addr));
643 regs->eflags &= ~IF_MASK; 638 regs->eflags &= ~IF_MASK;
644 regs->rip = (unsigned long)(jp->entry); 639 regs->rip = (unsigned long)(jp->entry);
645 return 1; 640 return 1;
@@ -647,36 +642,40 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
647 642
648void __kprobes jprobe_return(void) 643void __kprobes jprobe_return(void)
649{ 644{
650 preempt_enable_no_resched(); 645 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
646
651 asm volatile (" xchg %%rbx,%%rsp \n" 647 asm volatile (" xchg %%rbx,%%rsp \n"
652 " int3 \n" 648 " int3 \n"
653 " .globl jprobe_return_end \n" 649 " .globl jprobe_return_end \n"
654 " jprobe_return_end: \n" 650 " jprobe_return_end: \n"
655 " nop \n"::"b" 651 " nop \n"::"b"
656 (jprobe_saved_rsp):"memory"); 652 (kcb->jprobe_saved_rsp):"memory");
657} 653}
658 654
659int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) 655int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
660{ 656{
657 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
661 u8 *addr = (u8 *) (regs->rip - 1); 658 u8 *addr = (u8 *) (regs->rip - 1);
662 unsigned long stack_addr = (unsigned long)jprobe_saved_rsp; 659 unsigned long stack_addr = (unsigned long)(kcb->jprobe_saved_rsp);
663 struct jprobe *jp = container_of(p, struct jprobe, kp); 660 struct jprobe *jp = container_of(p, struct jprobe, kp);
664 661
665 if ((addr > (u8 *) jprobe_return) && (addr < (u8 *) jprobe_return_end)) { 662 if ((addr > (u8 *) jprobe_return) && (addr < (u8 *) jprobe_return_end)) {
666 if ((long *)regs->rsp != jprobe_saved_rsp) { 663 if ((long *)regs->rsp != kcb->jprobe_saved_rsp) {
667 struct pt_regs *saved_regs = 664 struct pt_regs *saved_regs =
668 container_of(jprobe_saved_rsp, struct pt_regs, rsp); 665 container_of(kcb->jprobe_saved_rsp,
666 struct pt_regs, rsp);
669 printk("current rsp %p does not match saved rsp %p\n", 667 printk("current rsp %p does not match saved rsp %p\n",
670 (long *)regs->rsp, jprobe_saved_rsp); 668 (long *)regs->rsp, kcb->jprobe_saved_rsp);
671 printk("Saved registers for jprobe %p\n", jp); 669 printk("Saved registers for jprobe %p\n", jp);
672 show_registers(saved_regs); 670 show_registers(saved_regs);
673 printk("Current registers\n"); 671 printk("Current registers\n");
674 show_registers(regs); 672 show_registers(regs);
675 BUG(); 673 BUG();
676 } 674 }
677 *regs = jprobe_saved_regs; 675 *regs = kcb->jprobe_saved_regs;
678 memcpy((kprobe_opcode_t *) stack_addr, jprobes_stack, 676 memcpy((kprobe_opcode_t *) stack_addr, kcb->jprobes_stack,
679 MIN_STACK_SIZE(stack_addr)); 677 MIN_STACK_SIZE(stack_addr));
678 preempt_enable_no_resched();
680 return 1; 679 return 1;
681 } 680 }
682 return 0; 681 return 0;
diff --git a/arch/x86_64/kernel/ptrace.c b/arch/x86_64/kernel/ptrace.c
index bbf64b59a21e..a87b6cebe80f 100644
--- a/arch/x86_64/kernel/ptrace.c
+++ b/arch/x86_64/kernel/ptrace.c
@@ -313,48 +313,11 @@ static unsigned long getreg(struct task_struct *child, unsigned long regno)
313 313
314} 314}
315 315
316asmlinkage long sys_ptrace(long request, long pid, unsigned long addr, long data) 316long arch_ptrace(struct task_struct *child, long request, long addr, long data)
317{ 317{
318 struct task_struct *child;
319 long i, ret; 318 long i, ret;
320 unsigned ui; 319 unsigned ui;
321 320
322 /* This lock_kernel fixes a subtle race with suid exec */
323 lock_kernel();
324 ret = -EPERM;
325 if (request == PTRACE_TRACEME) {
326 /* are we already being traced? */
327 if (current->ptrace & PT_PTRACED)
328 goto out;
329 ret = security_ptrace(current->parent, current);
330 if (ret)
331 goto out;
332 /* set the ptrace bit in the process flags. */
333 current->ptrace |= PT_PTRACED;
334 ret = 0;
335 goto out;
336 }
337 ret = -ESRCH;
338 read_lock(&tasklist_lock);
339 child = find_task_by_pid(pid);
340 if (child)
341 get_task_struct(child);
342 read_unlock(&tasklist_lock);
343 if (!child)
344 goto out;
345
346 ret = -EPERM;
347 if (pid == 1) /* you may not mess with init */
348 goto out_tsk;
349
350 if (request == PTRACE_ATTACH) {
351 ret = ptrace_attach(child);
352 goto out_tsk;
353 }
354 ret = ptrace_check_attach(child, request == PTRACE_KILL);
355 if (ret < 0)
356 goto out_tsk;
357
358 switch (request) { 321 switch (request) {
359 /* when I and D space are separate, these will need to be fixed. */ 322 /* when I and D space are separate, these will need to be fixed. */
360 case PTRACE_PEEKTEXT: /* read word at location addr. */ 323 case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -608,10 +571,6 @@ asmlinkage long sys_ptrace(long request, long pid, unsigned long addr, long data
608 ret = ptrace_request(child, request, addr, data); 571 ret = ptrace_request(child, request, addr, data);
609 break; 572 break;
610 } 573 }
611out_tsk:
612 put_task_struct(child);
613out:
614 unlock_kernel();
615 return ret; 574 return ret;
616} 575}
617 576
diff --git a/arch/x86_64/kernel/smpboot.c b/arch/x86_64/kernel/smpboot.c
index 658a81b33f3b..4b5b088ec102 100644
--- a/arch/x86_64/kernel/smpboot.c
+++ b/arch/x86_64/kernel/smpboot.c
@@ -65,8 +65,6 @@ int smp_num_siblings = 1;
65/* Package ID of each logical CPU */ 65/* Package ID of each logical CPU */
66u8 phys_proc_id[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID }; 66u8 phys_proc_id[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID };
67u8 cpu_core_id[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID }; 67u8 cpu_core_id[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID };
68EXPORT_SYMBOL(phys_proc_id);
69EXPORT_SYMBOL(cpu_core_id);
70 68
71/* Bitmask of currently online CPUs */ 69/* Bitmask of currently online CPUs */
72cpumask_t cpu_online_map __read_mostly; 70cpumask_t cpu_online_map __read_mostly;
diff --git a/arch/x86_64/oprofile/Kconfig b/arch/x86_64/oprofile/Kconfig
index 5ade19801b97..d8a84088471a 100644
--- a/arch/x86_64/oprofile/Kconfig
+++ b/arch/x86_64/oprofile/Kconfig
@@ -1,7 +1,3 @@
1
2menu "Profiling support"
3 depends on EXPERIMENTAL
4
5config PROFILING 1config PROFILING
6 bool "Profiling support (EXPERIMENTAL)" 2 bool "Profiling support (EXPERIMENTAL)"
7 help 3 help
@@ -19,5 +15,3 @@ config OPROFILE
19 15
20 If unsure, say N. 16 If unsure, say N.
21 17
22endmenu
23
diff --git a/arch/xtensa/kernel/ptrace.c b/arch/xtensa/kernel/ptrace.c
index 14460743de07..ab5c4c65b5c4 100644
--- a/arch/xtensa/kernel/ptrace.c
+++ b/arch/xtensa/kernel/ptrace.c
@@ -45,58 +45,10 @@ void ptrace_disable(struct task_struct *child)
45 /* Nothing to do.. */ 45 /* Nothing to do.. */
46} 46}
47 47
48long sys_ptrace(long request, long pid, long addr, long data) 48long arch_ptrace(struct task_struct *child, long request, long addr, long data)
49{ 49{
50 struct task_struct *child;
51 int ret = -EPERM; 50 int ret = -EPERM;
52 51
53 lock_kernel();
54
55#if 0
56 if ((int)request != 1)
57 printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
58 (int) request, (int) pid, (unsigned long) addr,
59 (unsigned long) data);
60#endif
61
62 if (request == PTRACE_TRACEME) {
63
64 /* Are we already being traced? */
65
66 if (current->ptrace & PT_PTRACED)
67 goto out;
68
69 if ((ret = security_ptrace(current->parent, current)))
70 goto out;
71
72 /* Set the ptrace bit in the process flags. */
73
74 current->ptrace |= PT_PTRACED;
75 ret = 0;
76 goto out;
77 }
78
79 ret = -ESRCH;
80 read_lock(&tasklist_lock);
81 child = find_task_by_pid(pid);
82 if (child)
83 get_task_struct(child);
84 read_unlock(&tasklist_lock);
85 if (!child)
86 goto out;
87
88 ret = -EPERM;
89 if (pid == 1) /* you may not mess with init */
90 goto out;
91
92 if (request == PTRACE_ATTACH) {
93 ret = ptrace_attach(child);
94 goto out_tsk;
95 }
96
97 if ((ret = ptrace_check_attach(child, request == PTRACE_KILL)) < 0)
98 goto out_tsk;
99
100 switch (request) { 52 switch (request) {
101 case PTRACE_PEEKTEXT: /* read word at location addr. */ 53 case PTRACE_PEEKTEXT: /* read word at location addr. */
102 case PTRACE_PEEKDATA: 54 case PTRACE_PEEKDATA:
@@ -375,10 +327,7 @@ long sys_ptrace(long request, long pid, long addr, long data)
375 ret = ptrace_request(child, request, addr, data); 327 ret = ptrace_request(child, request, addr, data);
376 goto out; 328 goto out;
377 } 329 }
378out_tsk: 330 out:
379 put_task_struct(child);
380out:
381 unlock_kernel();
382 return ret; 331 return ret;
383} 332}
384 333
diff --git a/block/Kconfig b/block/Kconfig
new file mode 100644
index 000000000000..eb48edb80c1d
--- /dev/null
+++ b/block/Kconfig
@@ -0,0 +1,14 @@
1#
2# Block layer core configuration
3#
4#XXX - it makes sense to enable this only for 32-bit subarch's, not for x86_64
5#for instance.
6config LBD
7 bool "Support for Large Block Devices"
8 depends on X86 || (MIPS && 32BIT) || PPC32 || ARCH_S390_31 || SUPERH || UML
9 help
10 Say Y here if you want to attach large (bigger than 2TB) discs to
11 your machine, or if you want to have a raid or loopback device
12 bigger than 2TB. Otherwise say N.
13
14source block/Kconfig.iosched
diff --git a/drivers/block/Kconfig.iosched b/block/Kconfig.iosched
index 5b90d2fa63b8..f3b7753aac99 100644
--- a/drivers/block/Kconfig.iosched
+++ b/block/Kconfig.iosched
@@ -46,13 +46,13 @@ choice
46 block devices. 46 block devices.
47 47
48 config DEFAULT_AS 48 config DEFAULT_AS
49 bool "Anticipatory" if IOSCHED_AS 49 bool "Anticipatory" if IOSCHED_AS=y
50 50
51 config DEFAULT_DEADLINE 51 config DEFAULT_DEADLINE
52 bool "Deadline" if IOSCHED_DEADLINE 52 bool "Deadline" if IOSCHED_DEADLINE=y
53 53
54 config DEFAULT_CFQ 54 config DEFAULT_CFQ
55 bool "CFQ" if IOSCHED_CFQ 55 bool "CFQ" if IOSCHED_CFQ=y
56 56
57 config DEFAULT_NOOP 57 config DEFAULT_NOOP
58 bool "No-op" 58 bool "No-op"
diff --git a/block/Makefile b/block/Makefile
new file mode 100644
index 000000000000..7e4f93e2b44e
--- /dev/null
+++ b/block/Makefile
@@ -0,0 +1,10 @@
1#
2# Makefile for the kernel block layer
3#
4
5obj-y := elevator.o ll_rw_blk.o ioctl.o genhd.o scsi_ioctl.o
6
7obj-$(CONFIG_IOSCHED_NOOP) += noop-iosched.o
8obj-$(CONFIG_IOSCHED_AS) += as-iosched.o
9obj-$(CONFIG_IOSCHED_DEADLINE) += deadline-iosched.o
10obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o
diff --git a/drivers/block/as-iosched.c b/block/as-iosched.c
index c6744ff38294..a78e160b59a3 100644
--- a/drivers/block/as-iosched.c
+++ b/block/as-iosched.c
@@ -4,7 +4,7 @@
4 * Anticipatory & deadline i/o scheduler. 4 * Anticipatory & deadline i/o scheduler.
5 * 5 *
6 * Copyright (C) 2002 Jens Axboe <axboe@suse.de> 6 * Copyright (C) 2002 Jens Axboe <axboe@suse.de>
7 * Nick Piggin <piggin@cyberone.com.au> 7 * Nick Piggin <nickpiggin@yahoo.com.au>
8 * 8 *
9 */ 9 */
10#include <linux/kernel.h> 10#include <linux/kernel.h>
@@ -69,7 +69,7 @@
69 69
70/* Bits in as_io_context.state */ 70/* Bits in as_io_context.state */
71enum as_io_states { 71enum as_io_states {
72 AS_TASK_RUNNING=0, /* Process has not exitted */ 72 AS_TASK_RUNNING=0, /* Process has not exited */
73 AS_TASK_IOSTARTED, /* Process has started some IO */ 73 AS_TASK_IOSTARTED, /* Process has started some IO */
74 AS_TASK_IORUNNING, /* Process has completed some IO */ 74 AS_TASK_IORUNNING, /* Process has completed some IO */
75}; 75};
@@ -102,6 +102,9 @@ struct as_data {
102 102
103 unsigned long exit_prob; /* probability a task will exit while 103 unsigned long exit_prob; /* probability a task will exit while
104 being waited on */ 104 being waited on */
105 unsigned long exit_no_coop; /* probablility an exited task will
106 not be part of a later cooperating
107 request */
105 unsigned long new_ttime_total; /* mean thinktime on new proc */ 108 unsigned long new_ttime_total; /* mean thinktime on new proc */
106 unsigned long new_ttime_mean; 109 unsigned long new_ttime_mean;
107 u64 new_seek_total; /* mean seek on new proc */ 110 u64 new_seek_total; /* mean seek on new proc */
@@ -636,37 +639,152 @@ static void as_antic_timeout(unsigned long data)
636 kblockd_schedule_work(&ad->antic_work); 639 kblockd_schedule_work(&ad->antic_work);
637 640
638 if (aic->ttime_samples == 0) { 641 if (aic->ttime_samples == 0) {
639 /* process anticipated on has exitted or timed out*/ 642 /* process anticipated on has exited or timed out*/
640 ad->exit_prob = (7*ad->exit_prob + 256)/8; 643 ad->exit_prob = (7*ad->exit_prob + 256)/8;
641 } 644 }
645 if (!test_bit(AS_TASK_RUNNING, &aic->state)) {
646 /* process not "saved" by a cooperating request */
647 ad->exit_no_coop = (7*ad->exit_no_coop + 256)/8;
648 }
642 } 649 }
643 spin_unlock_irqrestore(q->queue_lock, flags); 650 spin_unlock_irqrestore(q->queue_lock, flags);
644} 651}
645 652
653static void as_update_thinktime(struct as_data *ad, struct as_io_context *aic,
654 unsigned long ttime)
655{
656 /* fixed point: 1.0 == 1<<8 */
657 if (aic->ttime_samples == 0) {
658 ad->new_ttime_total = (7*ad->new_ttime_total + 256*ttime) / 8;
659 ad->new_ttime_mean = ad->new_ttime_total / 256;
660
661 ad->exit_prob = (7*ad->exit_prob)/8;
662 }
663 aic->ttime_samples = (7*aic->ttime_samples + 256) / 8;
664 aic->ttime_total = (7*aic->ttime_total + 256*ttime) / 8;
665 aic->ttime_mean = (aic->ttime_total + 128) / aic->ttime_samples;
666}
667
668static void as_update_seekdist(struct as_data *ad, struct as_io_context *aic,
669 sector_t sdist)
670{
671 u64 total;
672
673 if (aic->seek_samples == 0) {
674 ad->new_seek_total = (7*ad->new_seek_total + 256*(u64)sdist)/8;
675 ad->new_seek_mean = ad->new_seek_total / 256;
676 }
677
678 /*
679 * Don't allow the seek distance to get too large from the
680 * odd fragment, pagein, etc
681 */
682 if (aic->seek_samples <= 60) /* second&third seek */
683 sdist = min(sdist, (aic->seek_mean * 4) + 2*1024*1024);
684 else
685 sdist = min(sdist, (aic->seek_mean * 4) + 2*1024*64);
686
687 aic->seek_samples = (7*aic->seek_samples + 256) / 8;
688 aic->seek_total = (7*aic->seek_total + (u64)256*sdist) / 8;
689 total = aic->seek_total + (aic->seek_samples/2);
690 do_div(total, aic->seek_samples);
691 aic->seek_mean = (sector_t)total;
692}
693
694/*
695 * as_update_iohist keeps a decaying histogram of IO thinktimes, and
696 * updates @aic->ttime_mean based on that. It is called when a new
697 * request is queued.
698 */
699static void as_update_iohist(struct as_data *ad, struct as_io_context *aic,
700 struct request *rq)
701{
702 struct as_rq *arq = RQ_DATA(rq);
703 int data_dir = arq->is_sync;
704 unsigned long thinktime = 0;
705 sector_t seek_dist;
706
707 if (aic == NULL)
708 return;
709
710 if (data_dir == REQ_SYNC) {
711 unsigned long in_flight = atomic_read(&aic->nr_queued)
712 + atomic_read(&aic->nr_dispatched);
713 spin_lock(&aic->lock);
714 if (test_bit(AS_TASK_IORUNNING, &aic->state) ||
715 test_bit(AS_TASK_IOSTARTED, &aic->state)) {
716 /* Calculate read -> read thinktime */
717 if (test_bit(AS_TASK_IORUNNING, &aic->state)
718 && in_flight == 0) {
719 thinktime = jiffies - aic->last_end_request;
720 thinktime = min(thinktime, MAX_THINKTIME-1);
721 }
722 as_update_thinktime(ad, aic, thinktime);
723
724 /* Calculate read -> read seek distance */
725 if (aic->last_request_pos < rq->sector)
726 seek_dist = rq->sector - aic->last_request_pos;
727 else
728 seek_dist = aic->last_request_pos - rq->sector;
729 as_update_seekdist(ad, aic, seek_dist);
730 }
731 aic->last_request_pos = rq->sector + rq->nr_sectors;
732 set_bit(AS_TASK_IOSTARTED, &aic->state);
733 spin_unlock(&aic->lock);
734 }
735}
736
646/* 737/*
647 * as_close_req decides if one request is considered "close" to the 738 * as_close_req decides if one request is considered "close" to the
648 * previous one issued. 739 * previous one issued.
649 */ 740 */
650static int as_close_req(struct as_data *ad, struct as_rq *arq) 741static int as_close_req(struct as_data *ad, struct as_io_context *aic,
742 struct as_rq *arq)
651{ 743{
652 unsigned long delay; /* milliseconds */ 744 unsigned long delay; /* milliseconds */
653 sector_t last = ad->last_sector[ad->batch_data_dir]; 745 sector_t last = ad->last_sector[ad->batch_data_dir];
654 sector_t next = arq->request->sector; 746 sector_t next = arq->request->sector;
655 sector_t delta; /* acceptable close offset (in sectors) */ 747 sector_t delta; /* acceptable close offset (in sectors) */
748 sector_t s;
656 749
657 if (ad->antic_status == ANTIC_OFF || !ad->ioc_finished) 750 if (ad->antic_status == ANTIC_OFF || !ad->ioc_finished)
658 delay = 0; 751 delay = 0;
659 else 752 else
660 delay = ((jiffies - ad->antic_start) * 1000) / HZ; 753 delay = ((jiffies - ad->antic_start) * 1000) / HZ;
661 754
662 if (delay <= 1) 755 if (delay == 0)
663 delta = 64; 756 delta = 8192;
664 else if (delay <= 20 && delay <= ad->antic_expire) 757 else if (delay <= 20 && delay <= ad->antic_expire)
665 delta = 64 << (delay-1); 758 delta = 8192 << delay;
666 else 759 else
667 return 1; 760 return 1;
668 761
669 return (last - (delta>>1) <= next) && (next <= last + delta); 762 if ((last <= next + (delta>>1)) && (next <= last + delta))
763 return 1;
764
765 if (last < next)
766 s = next - last;
767 else
768 s = last - next;
769
770 if (aic->seek_samples == 0) {
771 /*
772 * Process has just started IO. Use past statistics to
773 * gauge success possibility
774 */
775 if (ad->new_seek_mean > s) {
776 /* this request is better than what we're expecting */
777 return 1;
778 }
779
780 } else {
781 if (aic->seek_mean > s) {
782 /* this request is better than what we're expecting */
783 return 1;
784 }
785 }
786
787 return 0;
670} 788}
671 789
672/* 790/*
@@ -678,7 +796,7 @@ static int as_close_req(struct as_data *ad, struct as_rq *arq)
678 * dispatch it ASAP, because we know that application will not be submitting 796 * dispatch it ASAP, because we know that application will not be submitting
679 * any new reads. 797 * any new reads.
680 * 798 *
681 * If the task which has submitted the request has exitted, break anticipation. 799 * If the task which has submitted the request has exited, break anticipation.
682 * 800 *
683 * If this task has queued some other IO, do not enter enticipation. 801 * If this task has queued some other IO, do not enter enticipation.
684 */ 802 */
@@ -686,7 +804,6 @@ static int as_can_break_anticipation(struct as_data *ad, struct as_rq *arq)
686{ 804{
687 struct io_context *ioc; 805 struct io_context *ioc;
688 struct as_io_context *aic; 806 struct as_io_context *aic;
689 sector_t s;
690 807
691 ioc = ad->io_context; 808 ioc = ad->io_context;
692 BUG_ON(!ioc); 809 BUG_ON(!ioc);
@@ -708,13 +825,6 @@ static int as_can_break_anticipation(struct as_data *ad, struct as_rq *arq)
708 if (!aic) 825 if (!aic)
709 return 0; 826 return 0;
710 827
711 if (!test_bit(AS_TASK_RUNNING, &aic->state)) {
712 /* process anticipated on has exitted */
713 if (aic->ttime_samples == 0)
714 ad->exit_prob = (7*ad->exit_prob + 256)/8;
715 return 1;
716 }
717
718 if (atomic_read(&aic->nr_queued) > 0) { 828 if (atomic_read(&aic->nr_queued) > 0) {
719 /* process has more requests queued */ 829 /* process has more requests queued */
720 return 1; 830 return 1;
@@ -725,57 +835,45 @@ static int as_can_break_anticipation(struct as_data *ad, struct as_rq *arq)
725 return 1; 835 return 1;
726 } 836 }
727 837
728 if (arq && arq->is_sync == REQ_SYNC && as_close_req(ad, arq)) { 838 if (arq && arq->is_sync == REQ_SYNC && as_close_req(ad, aic, arq)) {
729 /* 839 /*
730 * Found a close request that is not one of ours. 840 * Found a close request that is not one of ours.
731 * 841 *
732 * This makes close requests from another process reset 842 * This makes close requests from another process update
733 * our thinktime delay. Is generally useful when there are 843 * our IO history. Is generally useful when there are
734 * two or more cooperating processes working in the same 844 * two or more cooperating processes working in the same
735 * area. 845 * area.
736 */ 846 */
737 spin_lock(&aic->lock); 847 if (!test_bit(AS_TASK_RUNNING, &aic->state)) {
738 aic->last_end_request = jiffies; 848 if (aic->ttime_samples == 0)
739 spin_unlock(&aic->lock); 849 ad->exit_prob = (7*ad->exit_prob + 256)/8;
850
851 ad->exit_no_coop = (7*ad->exit_no_coop)/8;
852 }
853
854 as_update_iohist(ad, aic, arq->request);
740 return 1; 855 return 1;
741 } 856 }
742 857
858 if (!test_bit(AS_TASK_RUNNING, &aic->state)) {
859 /* process anticipated on has exited */
860 if (aic->ttime_samples == 0)
861 ad->exit_prob = (7*ad->exit_prob + 256)/8;
862
863 if (ad->exit_no_coop > 128)
864 return 1;
865 }
743 866
744 if (aic->ttime_samples == 0) { 867 if (aic->ttime_samples == 0) {
745 if (ad->new_ttime_mean > ad->antic_expire) 868 if (ad->new_ttime_mean > ad->antic_expire)
746 return 1; 869 return 1;
747 if (ad->exit_prob > 128) 870 if (ad->exit_prob * ad->exit_no_coop > 128*256)
748 return 1; 871 return 1;
749 } else if (aic->ttime_mean > ad->antic_expire) { 872 } else if (aic->ttime_mean > ad->antic_expire) {
750 /* the process thinks too much between requests */ 873 /* the process thinks too much between requests */
751 return 1; 874 return 1;
752 } 875 }
753 876
754 if (!arq)
755 return 0;
756
757 if (ad->last_sector[REQ_SYNC] < arq->request->sector)
758 s = arq->request->sector - ad->last_sector[REQ_SYNC];
759 else
760 s = ad->last_sector[REQ_SYNC] - arq->request->sector;
761
762 if (aic->seek_samples == 0) {
763 /*
764 * Process has just started IO. Use past statistics to
765 * guage success possibility
766 */
767 if (ad->new_seek_mean > s) {
768 /* this request is better than what we're expecting */
769 return 1;
770 }
771
772 } else {
773 if (aic->seek_mean > s) {
774 /* this request is better than what we're expecting */
775 return 1;
776 }
777 }
778
779 return 0; 877 return 0;
780} 878}
781 879
@@ -809,94 +907,11 @@ static int as_can_anticipate(struct as_data *ad, struct as_rq *arq)
809 * Status is either ANTIC_OFF so start waiting, 907 * Status is either ANTIC_OFF so start waiting,
810 * ANTIC_WAIT_REQ so continue waiting for request to finish 908 * ANTIC_WAIT_REQ so continue waiting for request to finish
811 * or ANTIC_WAIT_NEXT so continue waiting for an acceptable request. 909 * or ANTIC_WAIT_NEXT so continue waiting for an acceptable request.
812 *
813 */ 910 */
814 911
815 return 1; 912 return 1;
816} 913}
817 914
818static void as_update_thinktime(struct as_data *ad, struct as_io_context *aic, unsigned long ttime)
819{
820 /* fixed point: 1.0 == 1<<8 */
821 if (aic->ttime_samples == 0) {
822 ad->new_ttime_total = (7*ad->new_ttime_total + 256*ttime) / 8;
823 ad->new_ttime_mean = ad->new_ttime_total / 256;
824
825 ad->exit_prob = (7*ad->exit_prob)/8;
826 }
827 aic->ttime_samples = (7*aic->ttime_samples + 256) / 8;
828 aic->ttime_total = (7*aic->ttime_total + 256*ttime) / 8;
829 aic->ttime_mean = (aic->ttime_total + 128) / aic->ttime_samples;
830}
831
832static void as_update_seekdist(struct as_data *ad, struct as_io_context *aic, sector_t sdist)
833{
834 u64 total;
835
836 if (aic->seek_samples == 0) {
837 ad->new_seek_total = (7*ad->new_seek_total + 256*(u64)sdist)/8;
838 ad->new_seek_mean = ad->new_seek_total / 256;
839 }
840
841 /*
842 * Don't allow the seek distance to get too large from the
843 * odd fragment, pagein, etc
844 */
845 if (aic->seek_samples <= 60) /* second&third seek */
846 sdist = min(sdist, (aic->seek_mean * 4) + 2*1024*1024);
847 else
848 sdist = min(sdist, (aic->seek_mean * 4) + 2*1024*64);
849
850 aic->seek_samples = (7*aic->seek_samples + 256) / 8;
851 aic->seek_total = (7*aic->seek_total + (u64)256*sdist) / 8;
852 total = aic->seek_total + (aic->seek_samples/2);
853 do_div(total, aic->seek_samples);
854 aic->seek_mean = (sector_t)total;
855}
856
857/*
858 * as_update_iohist keeps a decaying histogram of IO thinktimes, and
859 * updates @aic->ttime_mean based on that. It is called when a new
860 * request is queued.
861 */
862static void as_update_iohist(struct as_data *ad, struct as_io_context *aic, struct request *rq)
863{
864 struct as_rq *arq = RQ_DATA(rq);
865 int data_dir = arq->is_sync;
866 unsigned long thinktime;
867 sector_t seek_dist;
868
869 if (aic == NULL)
870 return;
871
872 if (data_dir == REQ_SYNC) {
873 unsigned long in_flight = atomic_read(&aic->nr_queued)
874 + atomic_read(&aic->nr_dispatched);
875 spin_lock(&aic->lock);
876 if (test_bit(AS_TASK_IORUNNING, &aic->state) ||
877 test_bit(AS_TASK_IOSTARTED, &aic->state)) {
878 /* Calculate read -> read thinktime */
879 if (test_bit(AS_TASK_IORUNNING, &aic->state)
880 && in_flight == 0) {
881 thinktime = jiffies - aic->last_end_request;
882 thinktime = min(thinktime, MAX_THINKTIME-1);
883 } else
884 thinktime = 0;
885 as_update_thinktime(ad, aic, thinktime);
886
887 /* Calculate read -> read seek distance */
888 if (aic->last_request_pos < rq->sector)
889 seek_dist = rq->sector - aic->last_request_pos;
890 else
891 seek_dist = aic->last_request_pos - rq->sector;
892 as_update_seekdist(ad, aic, seek_dist);
893 }
894 aic->last_request_pos = rq->sector + rq->nr_sectors;
895 set_bit(AS_TASK_IOSTARTED, &aic->state);
896 spin_unlock(&aic->lock);
897 }
898}
899
900/* 915/*
901 * as_update_arq must be called whenever a request (arq) is added to 916 * as_update_arq must be called whenever a request (arq) is added to
902 * the sort_list. This function keeps caches up to date, and checks if the 917 * the sort_list. This function keeps caches up to date, and checks if the
@@ -1201,7 +1216,7 @@ static int as_dispatch_request(request_queue_t *q, int force)
1201 || ad->changed_batch) 1216 || ad->changed_batch)
1202 return 0; 1217 return 0;
1203 1218
1204 if (!(reads && writes && as_batch_expired(ad)) ) { 1219 if (!(reads && writes && as_batch_expired(ad))) {
1205 /* 1220 /*
1206 * batch is still running or no reads or no writes 1221 * batch is still running or no reads or no writes
1207 */ 1222 */
@@ -1316,7 +1331,8 @@ fifo_expired:
1316 * Add arq to a list behind alias 1331 * Add arq to a list behind alias
1317 */ 1332 */
1318static inline void 1333static inline void
1319as_add_aliased_request(struct as_data *ad, struct as_rq *arq, struct as_rq *alias) 1334as_add_aliased_request(struct as_data *ad, struct as_rq *arq,
1335 struct as_rq *alias)
1320{ 1336{
1321 struct request *req = arq->request; 1337 struct request *req = arq->request;
1322 struct list_head *insert = alias->request->queuelist.prev; 1338 struct list_head *insert = alias->request->queuelist.prev;
@@ -1441,8 +1457,8 @@ static int as_queue_empty(request_queue_t *q)
1441 && list_empty(&ad->fifo_list[REQ_SYNC]); 1457 && list_empty(&ad->fifo_list[REQ_SYNC]);
1442} 1458}
1443 1459
1444static struct request * 1460static struct request *as_former_request(request_queue_t *q,
1445as_former_request(request_queue_t *q, struct request *rq) 1461 struct request *rq)
1446{ 1462{
1447 struct as_rq *arq = RQ_DATA(rq); 1463 struct as_rq *arq = RQ_DATA(rq);
1448 struct rb_node *rbprev = rb_prev(&arq->rb_node); 1464 struct rb_node *rbprev = rb_prev(&arq->rb_node);
@@ -1454,8 +1470,8 @@ as_former_request(request_queue_t *q, struct request *rq)
1454 return ret; 1470 return ret;
1455} 1471}
1456 1472
1457static struct request * 1473static struct request *as_latter_request(request_queue_t *q,
1458as_latter_request(request_queue_t *q, struct request *rq) 1474 struct request *rq)
1459{ 1475{
1460 struct as_rq *arq = RQ_DATA(rq); 1476 struct as_rq *arq = RQ_DATA(rq);
1461 struct rb_node *rbnext = rb_next(&arq->rb_node); 1477 struct rb_node *rbnext = rb_next(&arq->rb_node);
@@ -1537,7 +1553,7 @@ static void as_merged_request(request_queue_t *q, struct request *req)
1537 * currently don't bother. Ditto the next function. 1553 * currently don't bother. Ditto the next function.
1538 */ 1554 */
1539 as_del_arq_rb(ad, arq); 1555 as_del_arq_rb(ad, arq);
1540 if ((alias = as_add_arq_rb(ad, arq)) ) { 1556 if ((alias = as_add_arq_rb(ad, arq))) {
1541 list_del_init(&arq->fifo); 1557 list_del_init(&arq->fifo);
1542 as_add_aliased_request(ad, arq, alias); 1558 as_add_aliased_request(ad, arq, alias);
1543 if (next_arq) 1559 if (next_arq)
@@ -1551,9 +1567,8 @@ static void as_merged_request(request_queue_t *q, struct request *req)
1551 } 1567 }
1552} 1568}
1553 1569
1554static void 1570static void as_merged_requests(request_queue_t *q, struct request *req,
1555as_merged_requests(request_queue_t *q, struct request *req, 1571 struct request *next)
1556 struct request *next)
1557{ 1572{
1558 struct as_data *ad = q->elevator->elevator_data; 1573 struct as_data *ad = q->elevator->elevator_data;
1559 struct as_rq *arq = RQ_DATA(req); 1574 struct as_rq *arq = RQ_DATA(req);
@@ -1576,7 +1591,7 @@ as_merged_requests(request_queue_t *q, struct request *req,
1576 next_arq = as_find_next_arq(ad, arq); 1591 next_arq = as_find_next_arq(ad, arq);
1577 1592
1578 as_del_arq_rb(ad, arq); 1593 as_del_arq_rb(ad, arq);
1579 if ((alias = as_add_arq_rb(ad, arq)) ) { 1594 if ((alias = as_add_arq_rb(ad, arq))) {
1580 list_del_init(&arq->fifo); 1595 list_del_init(&arq->fifo);
1581 as_add_aliased_request(ad, arq, alias); 1596 as_add_aliased_request(ad, arq, alias);
1582 if (next_arq) 1597 if (next_arq)
@@ -1806,9 +1821,14 @@ static ssize_t as_est_show(struct as_data *ad, char *page)
1806{ 1821{
1807 int pos = 0; 1822 int pos = 0;
1808 1823
1809 pos += sprintf(page+pos, "%lu %% exit probability\n", 100*ad->exit_prob/256); 1824 pos += sprintf(page+pos, "%lu %% exit probability\n",
1825 100*ad->exit_prob/256);
1826 pos += sprintf(page+pos, "%lu %% probability of exiting without a "
1827 "cooperating process submitting IO\n",
1828 100*ad->exit_no_coop/256);
1810 pos += sprintf(page+pos, "%lu ms new thinktime\n", ad->new_ttime_mean); 1829 pos += sprintf(page+pos, "%lu ms new thinktime\n", ad->new_ttime_mean);
1811 pos += sprintf(page+pos, "%llu sectors new seek distance\n", (unsigned long long)ad->new_seek_mean); 1830 pos += sprintf(page+pos, "%llu sectors new seek distance\n",
1831 (unsigned long long)ad->new_seek_mean);
1812 1832
1813 return pos; 1833 return pos;
1814} 1834}
diff --git a/drivers/block/cfq-iosched.c b/block/cfq-iosched.c
index ecacca9c877e..ecacca9c877e 100644
--- a/drivers/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
diff --git a/drivers/block/deadline-iosched.c b/block/deadline-iosched.c
index 7929471d7df7..7929471d7df7 100644
--- a/drivers/block/deadline-iosched.c
+++ b/block/deadline-iosched.c
diff --git a/drivers/block/elevator.c b/block/elevator.c
index d4a49a3df829..d4a49a3df829 100644
--- a/drivers/block/elevator.c
+++ b/block/elevator.c
diff --git a/drivers/block/genhd.c b/block/genhd.c
index 54aec4a1ae13..54aec4a1ae13 100644
--- a/drivers/block/genhd.c
+++ b/block/genhd.c
diff --git a/drivers/block/ioctl.c b/block/ioctl.c
index 6e278474f9a8..6e278474f9a8 100644
--- a/drivers/block/ioctl.c
+++ b/block/ioctl.c
diff --git a/drivers/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 2747741677fb..5f52e30b43f8 100644
--- a/drivers/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -706,7 +706,6 @@ EXPORT_SYMBOL(blk_queue_dma_alignment);
706 706
707/** 707/**
708 * blk_queue_find_tag - find a request by its tag and queue 708 * blk_queue_find_tag - find a request by its tag and queue
709 *
710 * @q: The request queue for the device 709 * @q: The request queue for the device
711 * @tag: The tag of the request 710 * @tag: The tag of the request
712 * 711 *
diff --git a/drivers/block/noop-iosched.c b/block/noop-iosched.c
index e54f006e7e60..e54f006e7e60 100644
--- a/drivers/block/noop-iosched.c
+++ b/block/noop-iosched.c
diff --git a/drivers/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 382dea7b224c..382dea7b224c 100644
--- a/drivers/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
diff --git a/drivers/Makefile b/drivers/Makefile
index 65670be6ff1a..fac1e1603097 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -7,6 +7,7 @@
7 7
8obj-$(CONFIG_PCI) += pci/ usb/ 8obj-$(CONFIG_PCI) += pci/ usb/
9obj-$(CONFIG_PARISC) += parisc/ 9obj-$(CONFIG_PARISC) += parisc/
10obj-$(CONFIG_RAPIDIO) += rapidio/
10obj-y += video/ 11obj-y += video/
11obj-$(CONFIG_ACPI) += acpi/ 12obj-$(CONFIG_ACPI) += acpi/
12# PnP must come after ACPI since it will eventually need to check if acpi 13# PnP must come after ACPI since it will eventually need to check if acpi
@@ -67,3 +68,4 @@ obj-$(CONFIG_INFINIBAND) += infiniband/
67obj-$(CONFIG_SGI_IOC4) += sn/ 68obj-$(CONFIG_SGI_IOC4) += sn/
68obj-y += firmware/ 69obj-y += firmware/
69obj-$(CONFIG_CRYPTO) += crypto/ 70obj-$(CONFIG_CRYPTO) += crypto/
71obj-$(CONFIG_SUPERH) += sh/
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 10dd695a1dd9..27ec12c1fab0 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -118,11 +118,9 @@ static int acpi_container_remove(struct acpi_device *device, int type)
118{ 118{
119 acpi_status status = AE_OK; 119 acpi_status status = AE_OK;
120 struct acpi_container *pc = NULL; 120 struct acpi_container *pc = NULL;
121 pc = (struct acpi_container *)acpi_driver_data(device);
122
123 if (pc)
124 kfree(pc);
125 121
122 pc = (struct acpi_container *)acpi_driver_data(device);
123 kfree(pc);
126 return status; 124 return status;
127} 125}
128 126
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index d528c750a380..e3cd0b16031a 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -313,8 +313,7 @@ acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
313 313
314void acpi_os_sleep(acpi_integer ms) 314void acpi_os_sleep(acpi_integer ms)
315{ 315{
316 current->state = TASK_INTERRUPTIBLE; 316 schedule_timeout_interruptible(msecs_to_jiffies(ms));
317 schedule_timeout(((signed long)ms * HZ) / 1000);
318} 317}
319 318
320EXPORT_SYMBOL(acpi_os_sleep); 319EXPORT_SYMBOL(acpi_os_sleep);
@@ -838,8 +837,7 @@ acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
838 837
839 ret = down_trylock(sem); 838 ret = down_trylock(sem);
840 for (i = timeout; (i > 0 && ret < 0); i -= quantum_ms) { 839 for (i = timeout; (i > 0 && ret < 0); i -= quantum_ms) {
841 current->state = TASK_INTERRUPTIBLE; 840 schedule_timeout_interruptible(1);
842 schedule_timeout(1);
843 ret = down_trylock(sem); 841 ret = down_trylock(sem);
844 } 842 }
845 843
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index c6db591479de..23e2c6968a11 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -28,8 +28,7 @@ static int acpi_bus_trim(struct acpi_device *start, int rmdevice);
28static void acpi_device_release(struct kobject *kobj) 28static void acpi_device_release(struct kobject *kobj)
29{ 29{
30 struct acpi_device *dev = container_of(kobj, struct acpi_device, kobj); 30 struct acpi_device *dev = container_of(kobj, struct acpi_device, kobj);
31 if (dev->pnp.cid_list) 31 kfree(dev->pnp.cid_list);
32 kfree(dev->pnp.cid_list);
33 kfree(dev); 32 kfree(dev);
34} 33}
35 34
@@ -1117,8 +1116,7 @@ acpi_add_single_object(struct acpi_device **child,
1117 if (!result) 1116 if (!result)
1118 *child = device; 1117 *child = device;
1119 else { 1118 else {
1120 if (device->pnp.cid_list) 1119 kfree(device->pnp.cid_list);
1121 kfree(device->pnp.cid_list);
1122 kfree(device); 1120 kfree(device);
1123 } 1121 }
1124 1122
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index e383d6109ae1..f051b151580d 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -334,8 +334,7 @@ acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
334 return_VALUE(0); 334 return_VALUE(0);
335 335
336 err: 336 err:
337 if (buffer.pointer) 337 kfree(buffer.pointer);
338 kfree(buffer.pointer);
339 338
340 return_VALUE(status); 339 return_VALUE(status);
341} 340}
@@ -1488,8 +1487,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1488 } 1487 }
1489 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END; 1488 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1490 1489
1491 if (video->attached_array) 1490 kfree(video->attached_array);
1492 kfree(video->attached_array);
1493 1491
1494 video->attached_array = active_device_list; 1492 video->attached_array = active_device_list;
1495 video->attached_count = count; 1493 video->attached_count = count;
@@ -1645,8 +1643,7 @@ static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1645 printk(KERN_WARNING PREFIX 1643 printk(KERN_WARNING PREFIX
1646 "hhuuhhuu bug in acpi video driver.\n"); 1644 "hhuuhhuu bug in acpi video driver.\n");
1647 1645
1648 if (data->brightness) 1646 kfree(data->brightness);
1649 kfree(data->brightness);
1650 1647
1651 kfree(data); 1648 kfree(data);
1652 } 1649 }
@@ -1831,8 +1828,7 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type)
1831 acpi_video_bus_put_devices(video); 1828 acpi_video_bus_put_devices(video);
1832 acpi_video_bus_remove_fs(device); 1829 acpi_video_bus_remove_fs(device);
1833 1830
1834 if (video->attached_array) 1831 kfree(video->attached_array);
1835 kfree(video->attached_array);
1836 kfree(video); 1832 kfree(video);
1837 1833
1838 return_VALUE(0); 1834 return_VALUE(0);
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 89c57875f3e5..f3a0c562bcb5 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -3,6 +3,7 @@
3 */ 3 */
4 4
5#include <linux/device.h> 5#include <linux/device.h>
6#include <linux/string.h>
6#include "power.h" 7#include "power.h"
7 8
8 9
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index 3760edfdc65c..70eaa5c7ac08 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -417,14 +417,12 @@ static void DAC960_DestroyAuxiliaryStructures(DAC960_Controller_T *Controller)
417 * Remember the beginning of the group, but don't free it 417 * Remember the beginning of the group, but don't free it
418 * until we've reached the beginning of the next group. 418 * until we've reached the beginning of the next group.
419 */ 419 */
420 if (CommandGroup != NULL) 420 kfree(CommandGroup);
421 kfree(CommandGroup); 421 CommandGroup = Command;
422 CommandGroup = Command;
423 } 422 }
424 Controller->Commands[i] = NULL; 423 Controller->Commands[i] = NULL;
425 } 424 }
426 if (CommandGroup != NULL) 425 kfree(CommandGroup);
427 kfree(CommandGroup);
428 426
429 if (Controller->CombinedStatusBuffer != NULL) 427 if (Controller->CombinedStatusBuffer != NULL)
430 { 428 {
@@ -435,30 +433,23 @@ static void DAC960_DestroyAuxiliaryStructures(DAC960_Controller_T *Controller)
435 433
436 if (ScatterGatherPool != NULL) 434 if (ScatterGatherPool != NULL)
437 pci_pool_destroy(ScatterGatherPool); 435 pci_pool_destroy(ScatterGatherPool);
438 if (Controller->FirmwareType == DAC960_V1_Controller) return; 436 if (Controller->FirmwareType == DAC960_V1_Controller)
437 return;
439 438
440 if (RequestSensePool != NULL) 439 if (RequestSensePool != NULL)
441 pci_pool_destroy(RequestSensePool); 440 pci_pool_destroy(RequestSensePool);
442 441
443 for (i = 0; i < DAC960_MaxLogicalDrives; i++) 442 for (i = 0; i < DAC960_MaxLogicalDrives; i++) {
444 if (Controller->V2.LogicalDeviceInformation[i] != NULL)
445 {
446 kfree(Controller->V2.LogicalDeviceInformation[i]); 443 kfree(Controller->V2.LogicalDeviceInformation[i]);
447 Controller->V2.LogicalDeviceInformation[i] = NULL; 444 Controller->V2.LogicalDeviceInformation[i] = NULL;
448 } 445 }
449 446
450 for (i = 0; i < DAC960_V2_MaxPhysicalDevices; i++) 447 for (i = 0; i < DAC960_V2_MaxPhysicalDevices; i++)
451 { 448 {
452 if (Controller->V2.PhysicalDeviceInformation[i] != NULL) 449 kfree(Controller->V2.PhysicalDeviceInformation[i]);
453 { 450 Controller->V2.PhysicalDeviceInformation[i] = NULL;
454 kfree(Controller->V2.PhysicalDeviceInformation[i]); 451 kfree(Controller->V2.InquiryUnitSerialNumber[i]);
455 Controller->V2.PhysicalDeviceInformation[i] = NULL; 452 Controller->V2.InquiryUnitSerialNumber[i] = NULL;
456 }
457 if (Controller->V2.InquiryUnitSerialNumber[i] != NULL)
458 {
459 kfree(Controller->V2.InquiryUnitSerialNumber[i]);
460 Controller->V2.InquiryUnitSerialNumber[i] = NULL;
461 }
462 } 453 }
463} 454}
464 455
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 51b0af1cebee..7b1cd93892be 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -409,16 +409,6 @@ config BLK_DEV_INITRD
409 for details. 409 for details.
410 410
411 411
412#XXX - it makes sense to enable this only for 32-bit subarch's, not for x86_64
413#for instance.
414config LBD
415 bool "Support for Large Block Devices"
416 depends on X86 || (MIPS && 32BIT) || PPC32 || ARCH_S390_31 || SUPERH || UML
417 help
418 Say Y here if you want to attach large (bigger than 2TB) discs to
419 your machine, or if you want to have a raid or loopback device
420 bigger than 2TB. Otherwise say N.
421
422config CDROM_PKTCDVD 412config CDROM_PKTCDVD
423 tristate "Packet writing on CD/DVD media" 413 tristate "Packet writing on CD/DVD media"
424 depends on !UML 414 depends on !UML
@@ -455,8 +445,6 @@ config CDROM_PKTCDVD_WCACHE
455 445
456source "drivers/s390/block/Kconfig" 446source "drivers/s390/block/Kconfig"
457 447
458source "drivers/block/Kconfig.iosched"
459
460config ATA_OVER_ETH 448config ATA_OVER_ETH
461 tristate "ATA over Ethernet support" 449 tristate "ATA over Ethernet support"
462 depends on NET 450 depends on NET
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index 1cf09a1c065b..3ec1f8df87b1 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -4,21 +4,7 @@
4# 12 June 2000, Christoph Hellwig <hch@infradead.org> 4# 12 June 2000, Christoph Hellwig <hch@infradead.org>
5# Rewritten to use lists instead of if-statements. 5# Rewritten to use lists instead of if-statements.
6# 6#
7# Note : at this point, these files are compiled on all systems.
8# In the future, some of these should be built conditionally.
9#
10
11#
12# NOTE that ll_rw_blk.c must come early in linkage order - it starts the
13# kblockd threads
14#
15
16obj-y := elevator.o ll_rw_blk.o ioctl.o genhd.o scsi_ioctl.o
17 7
18obj-$(CONFIG_IOSCHED_NOOP) += noop-iosched.o
19obj-$(CONFIG_IOSCHED_AS) += as-iosched.o
20obj-$(CONFIG_IOSCHED_DEADLINE) += deadline-iosched.o
21obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o
22obj-$(CONFIG_MAC_FLOPPY) += swim3.o 8obj-$(CONFIG_MAC_FLOPPY) += swim3.o
23obj-$(CONFIG_BLK_DEV_FD) += floppy.o 9obj-$(CONFIG_BLK_DEV_FD) += floppy.o
24obj-$(CONFIG_BLK_DEV_FD98) += floppy98.o 10obj-$(CONFIG_BLK_DEV_FD98) += floppy98.o
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 486b6e1c7dfb..a97c80b57737 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -1096,14 +1096,11 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
1096cleanup1: 1096cleanup1:
1097 if (buff) { 1097 if (buff) {
1098 for(i=0; i<sg_used; i++) 1098 for(i=0; i<sg_used; i++)
1099 if(buff[i] != NULL) 1099 kfree(buff[i]);
1100 kfree(buff[i]);
1101 kfree(buff); 1100 kfree(buff);
1102 } 1101 }
1103 if (buff_size) 1102 kfree(buff_size);
1104 kfree(buff_size); 1103 kfree(ioc);
1105 if (ioc)
1106 kfree(ioc);
1107 return(status); 1104 return(status);
1108 } 1105 }
1109 default: 1106 default:
@@ -3034,8 +3031,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3034 return(1); 3031 return(1);
3035 3032
3036clean4: 3033clean4:
3037 if(hba[i]->cmd_pool_bits) 3034 kfree(hba[i]->cmd_pool_bits);
3038 kfree(hba[i]->cmd_pool_bits);
3039 if(hba[i]->cmd_pool) 3035 if(hba[i]->cmd_pool)
3040 pci_free_consistent(hba[i]->pdev, 3036 pci_free_consistent(hba[i]->pdev,
3041 NR_CMDS * sizeof(CommandList_struct), 3037 NR_CMDS * sizeof(CommandList_struct),
diff --git a/drivers/bluetooth/bcm203x.c b/drivers/bluetooth/bcm203x.c
index 5fd3e4cb7525..8e7fb3551775 100644
--- a/drivers/bluetooth/bcm203x.c
+++ b/drivers/bluetooth/bcm203x.c
@@ -179,14 +179,12 @@ static int bcm203x_probe(struct usb_interface *intf, const struct usb_device_id
179 if (ignore || (intf->cur_altsetting->desc.bInterfaceNumber != 0)) 179 if (ignore || (intf->cur_altsetting->desc.bInterfaceNumber != 0))
180 return -ENODEV; 180 return -ENODEV;
181 181
182 data = kmalloc(sizeof(*data), GFP_KERNEL); 182 data = kzalloc(sizeof(*data), GFP_KERNEL);
183 if (!data) { 183 if (!data) {
184 BT_ERR("Can't allocate memory for data structure"); 184 BT_ERR("Can't allocate memory for data structure");
185 return -ENOMEM; 185 return -ENOMEM;
186 } 186 }
187 187
188 memset(data, 0, sizeof(*data));
189
190 data->udev = udev; 188 data->udev = udev;
191 data->state = BCM203X_LOAD_MINIDRV; 189 data->state = BCM203X_LOAD_MINIDRV;
192 190
diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
index 1e9db0156ea7..067e27893e4a 100644
--- a/drivers/bluetooth/bfusb.c
+++ b/drivers/bluetooth/bfusb.c
@@ -673,13 +673,11 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
673 } 673 }
674 674
675 /* Initialize control structure and load firmware */ 675 /* Initialize control structure and load firmware */
676 if (!(bfusb = kmalloc(sizeof(struct bfusb), GFP_KERNEL))) { 676 if (!(bfusb = kzalloc(sizeof(struct bfusb), GFP_KERNEL))) {
677 BT_ERR("Can't allocate memory for control structure"); 677 BT_ERR("Can't allocate memory for control structure");
678 goto done; 678 goto done;
679 } 679 }
680 680
681 memset(bfusb, 0, sizeof(struct bfusb));
682
683 bfusb->udev = udev; 681 bfusb->udev = udev;
684 bfusb->bulk_in_ep = bulk_in_ep->desc.bEndpointAddress; 682 bfusb->bulk_in_ep = bulk_in_ep->desc.bEndpointAddress;
685 bfusb->bulk_out_ep = bulk_out_ep->desc.bEndpointAddress; 683 bfusb->bulk_out_ep = bulk_out_ep->desc.bEndpointAddress;
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index 26fe9c0e1d20..f36c563d72c4 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -870,10 +870,9 @@ static dev_link_t *bluecard_attach(void)
870 int ret; 870 int ret;
871 871
872 /* Create new info device */ 872 /* Create new info device */
873 info = kmalloc(sizeof(*info), GFP_KERNEL); 873 info = kzalloc(sizeof(*info), GFP_KERNEL);
874 if (!info) 874 if (!info)
875 return NULL; 875 return NULL;
876 memset(info, 0, sizeof(*info));
877 876
878 link = &info->link; 877 link = &info->link;
879 link->priv = info; 878 link->priv = info;
diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c
index 0db0400519c9..ecbeb7eaba8e 100644
--- a/drivers/bluetooth/bpa10x.c
+++ b/drivers/bluetooth/bpa10x.c
@@ -553,14 +553,12 @@ static int bpa10x_probe(struct usb_interface *intf, const struct usb_device_id *
553 if (intf->cur_altsetting->desc.bInterfaceNumber > 0) 553 if (intf->cur_altsetting->desc.bInterfaceNumber > 0)
554 return -ENODEV; 554 return -ENODEV;
555 555
556 data = kmalloc(sizeof(*data), GFP_KERNEL); 556 data = kzalloc(sizeof(*data), GFP_KERNEL);
557 if (!data) { 557 if (!data) {
558 BT_ERR("Can't allocate data structure"); 558 BT_ERR("Can't allocate data structure");
559 return -ENOMEM; 559 return -ENOMEM;
560 } 560 }
561 561
562 memset(data, 0, sizeof(*data));
563
564 data->udev = udev; 562 data->udev = udev;
565 563
566 rwlock_init(&data->lock); 564 rwlock_init(&data->lock);
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index 2e0338d80f32..d2a0add19cc8 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -671,10 +671,9 @@ static dev_link_t *bt3c_attach(void)
671 int ret; 671 int ret;
672 672
673 /* Create new info device */ 673 /* Create new info device */
674 info = kmalloc(sizeof(*info), GFP_KERNEL); 674 info = kzalloc(sizeof(*info), GFP_KERNEL);
675 if (!info) 675 if (!info)
676 return NULL; 676 return NULL;
677 memset(info, 0, sizeof(*info));
678 677
679 link = &info->link; 678 link = &info->link;
680 link->priv = info; 679 link->priv = info;
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index 89486ea7a021..529a28a3209d 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -590,10 +590,9 @@ static dev_link_t *btuart_attach(void)
590 int ret; 590 int ret;
591 591
592 /* Create new info device */ 592 /* Create new info device */
593 info = kmalloc(sizeof(*info), GFP_KERNEL); 593 info = kzalloc(sizeof(*info), GFP_KERNEL);
594 if (!info) 594 if (!info)
595 return NULL; 595 return NULL;
596 memset(info, 0, sizeof(*info));
597 596
598 link = &info->link; 597 link = &info->link;
599 link->priv = info; 598 link->priv = info;
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index 84c1f8839422..dec5980a1cd6 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -569,10 +569,9 @@ static dev_link_t *dtl1_attach(void)
569 int ret; 569 int ret;
570 570
571 /* Create new info device */ 571 /* Create new info device */
572 info = kmalloc(sizeof(*info), GFP_KERNEL); 572 info = kzalloc(sizeof(*info), GFP_KERNEL);
573 if (!info) 573 if (!info)
574 return NULL; 574 return NULL;
575 memset(info, 0, sizeof(*info));
576 575
577 link = &info->link; 576 link = &info->link;
578 link->priv = info; 577 link->priv = info;
diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
index 0a4761415ac3..8fddfdfd0fbd 100644
--- a/drivers/bluetooth/hci_bcsp.c
+++ b/drivers/bluetooth/hci_bcsp.c
@@ -715,10 +715,9 @@ static int bcsp_open(struct hci_uart *hu)
715 715
716 BT_DBG("hu %p", hu); 716 BT_DBG("hu %p", hu);
717 717
718 bcsp = kmalloc(sizeof(*bcsp), GFP_ATOMIC); 718 bcsp = kzalloc(sizeof(*bcsp), GFP_ATOMIC);
719 if (!bcsp) 719 if (!bcsp)
720 return -ENOMEM; 720 return -ENOMEM;
721 memset(bcsp, 0, sizeof(*bcsp));
722 721
723 hu->priv = bcsp; 722 hu->priv = bcsp;
724 skb_queue_head_init(&bcsp->unack); 723 skb_queue_head_init(&bcsp->unack);
diff --git a/drivers/bluetooth/hci_h4.c b/drivers/bluetooth/hci_h4.c
index 12e369a66fc2..4804d474dc87 100644
--- a/drivers/bluetooth/hci_h4.c
+++ b/drivers/bluetooth/hci_h4.c
@@ -76,12 +76,10 @@ static int h4_open(struct hci_uart *hu)
76 76
77 BT_DBG("hu %p", hu); 77 BT_DBG("hu %p", hu);
78 78
79 h4 = kmalloc(sizeof(*h4), GFP_ATOMIC); 79 h4 = kzalloc(sizeof(*h4), GFP_ATOMIC);
80 if (!h4) 80 if (!h4)
81 return -ENOMEM; 81 return -ENOMEM;
82 82
83 memset(h4, 0, sizeof(*h4));
84
85 skb_queue_head_init(&h4->txq); 83 skb_queue_head_init(&h4->txq);
86 84
87 hu->priv = h4; 85 hu->priv = h4;
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 4a775f6ea390..573ff6c1be5f 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -272,13 +272,11 @@ static int hci_uart_tty_open(struct tty_struct *tty)
272 if (hu) 272 if (hu)
273 return -EEXIST; 273 return -EEXIST;
274 274
275 if (!(hu = kmalloc(sizeof(struct hci_uart), GFP_KERNEL))) { 275 if (!(hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL))) {
276 BT_ERR("Can't allocate controll structure"); 276 BT_ERR("Can't allocate controll structure");
277 return -ENFILE; 277 return -ENFILE;
278 } 278 }
279 279
280 memset(hu, 0, sizeof(struct hci_uart));
281
282 tty->disc_data = hu; 280 tty->disc_data = hu;
283 hu->tty = tty; 281 hu->tty = tty;
284 282
diff --git a/drivers/bluetooth/hci_usb.c b/drivers/bluetooth/hci_usb.c
index 6756cb20b753..f510b25b2c59 100644
--- a/drivers/bluetooth/hci_usb.c
+++ b/drivers/bluetooth/hci_usb.c
@@ -875,13 +875,11 @@ static int hci_usb_probe(struct usb_interface *intf, const struct usb_device_id
875 goto done; 875 goto done;
876 } 876 }
877 877
878 if (!(husb = kmalloc(sizeof(struct hci_usb), GFP_KERNEL))) { 878 if (!(husb = kzalloc(sizeof(struct hci_usb), GFP_KERNEL))) {
879 BT_ERR("Can't allocate: control structure"); 879 BT_ERR("Can't allocate: control structure");
880 goto done; 880 goto done;
881 } 881 }
882 882
883 memset(husb, 0, sizeof(struct hci_usb));
884
885 husb->udev = udev; 883 husb->udev = udev;
886 husb->bulk_out_ep = bulk_out_ep; 884 husb->bulk_out_ep = bulk_out_ep;
887 husb->bulk_in_ep = bulk_in_ep; 885 husb->bulk_in_ep = bulk_in_ep;
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 52cbd45c308f..85738223ff0c 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -261,12 +261,10 @@ static int vhci_open(struct inode *inode, struct file *file)
261 struct vhci_data *vhci; 261 struct vhci_data *vhci;
262 struct hci_dev *hdev; 262 struct hci_dev *hdev;
263 263
264 vhci = kmalloc(sizeof(struct vhci_data), GFP_KERNEL); 264 vhci = kzalloc(sizeof(struct vhci_data), GFP_KERNEL);
265 if (!vhci) 265 if (!vhci)
266 return -ENOMEM; 266 return -ENOMEM;
267 267
268 memset(vhci, 0, sizeof(struct vhci_data));
269
270 skb_queue_head_init(&vhci->readq); 268 skb_queue_head_init(&vhci->readq);
271 init_waitqueue_head(&vhci->read_wait); 269 init_waitqueue_head(&vhci->read_wait);
272 270
diff --git a/drivers/cdrom/mcdx.c b/drivers/cdrom/mcdx.c
index b89420e6d704..a0b580c22d80 100644
--- a/drivers/cdrom/mcdx.c
+++ b/drivers/cdrom/mcdx.c
@@ -1085,7 +1085,7 @@ static int __init mcdx_init_drive(int drive)
1085 1085
1086 xtrace(INIT, "kmalloc space for stuffpt's\n"); 1086 xtrace(INIT, "kmalloc space for stuffpt's\n");
1087 xtrace(MALLOC, "init() malloc %d bytes\n", size); 1087 xtrace(MALLOC, "init() malloc %d bytes\n", size);
1088 if (!(stuffp = kmalloc(size, GFP_KERNEL))) { 1088 if (!(stuffp = kzalloc(size, GFP_KERNEL))) {
1089 xwarn("init() malloc failed\n"); 1089 xwarn("init() malloc failed\n");
1090 return 1; 1090 return 1;
1091 } 1091 }
@@ -1101,8 +1101,6 @@ static int __init mcdx_init_drive(int drive)
1101 sizeof(*stuffp), stuffp); 1101 sizeof(*stuffp), stuffp);
1102 1102
1103 /* set default values */ 1103 /* set default values */
1104 memset(stuffp, 0, sizeof(*stuffp));
1105
1106 stuffp->present = 0; /* this should be 0 already */ 1104 stuffp->present = 0; /* this should be 0 already */
1107 stuffp->toc = NULL; /* this should be NULL already */ 1105 stuffp->toc = NULL; /* this should be NULL already */
1108 1106
diff --git a/drivers/char/agp/ali-agp.c b/drivers/char/agp/ali-agp.c
index b02fc2267159..ba54b5872578 100644
--- a/drivers/char/agp/ali-agp.c
+++ b/drivers/char/agp/ali-agp.c
@@ -389,6 +389,7 @@ static struct pci_device_id agp_ali_pci_table[] = {
389MODULE_DEVICE_TABLE(pci, agp_ali_pci_table); 389MODULE_DEVICE_TABLE(pci, agp_ali_pci_table);
390 390
391static struct pci_driver agp_ali_pci_driver = { 391static struct pci_driver agp_ali_pci_driver = {
392 .owner = THIS_MODULE,
392 .name = "agpgart-ali", 393 .name = "agpgart-ali",
393 .id_table = agp_ali_pci_table, 394 .id_table = agp_ali_pci_table,
394 .probe = agp_ali_probe, 395 .probe = agp_ali_probe,
diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c
index 3a41672e4d66..40fcd88b2cea 100644
--- a/drivers/char/agp/amd-k7-agp.c
+++ b/drivers/char/agp/amd-k7-agp.c
@@ -94,19 +94,16 @@ static int amd_create_gatt_pages(int nr_tables)
94 int retval = 0; 94 int retval = 0;
95 int i; 95 int i;
96 96
97 tables = kmalloc((nr_tables + 1) * sizeof(struct amd_page_map *), 97 tables = kzalloc((nr_tables + 1) * sizeof(struct amd_page_map *),GFP_KERNEL);
98 GFP_KERNEL);
99 if (tables == NULL) 98 if (tables == NULL)
100 return -ENOMEM; 99 return -ENOMEM;
101 100
102 memset (tables, 0, sizeof(struct amd_page_map *) * (nr_tables + 1));
103 for (i = 0; i < nr_tables; i++) { 101 for (i = 0; i < nr_tables; i++) {
104 entry = kmalloc(sizeof(struct amd_page_map), GFP_KERNEL); 102 entry = kzalloc(sizeof(struct amd_page_map), GFP_KERNEL);
105 if (entry == NULL) { 103 if (entry == NULL) {
106 retval = -ENOMEM; 104 retval = -ENOMEM;
107 break; 105 break;
108 } 106 }
109 memset (entry, 0, sizeof(struct amd_page_map));
110 tables[i] = entry; 107 tables[i] = entry;
111 retval = amd_create_page_map(entry); 108 retval = amd_create_page_map(entry);
112 if (retval != 0) 109 if (retval != 0)
@@ -518,6 +515,7 @@ static struct pci_device_id agp_amdk7_pci_table[] = {
518MODULE_DEVICE_TABLE(pci, agp_amdk7_pci_table); 515MODULE_DEVICE_TABLE(pci, agp_amdk7_pci_table);
519 516
520static struct pci_driver agp_amdk7_pci_driver = { 517static struct pci_driver agp_amdk7_pci_driver = {
518 .owner = THIS_MODULE,
521 .name = "agpgart-amdk7", 519 .name = "agpgart-amdk7",
522 .id_table = agp_amdk7_pci_table, 520 .id_table = agp_amdk7_pci_table,
523 .probe = agp_amdk7_probe, 521 .probe = agp_amdk7_probe,
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 0e6c3a31d344..8f748fddca94 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -13,6 +13,7 @@
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/agp_backend.h> 15#include <linux/agp_backend.h>
16#include <linux/mmzone.h>
16#include <asm/page.h> /* PAGE_SIZE */ 17#include <asm/page.h> /* PAGE_SIZE */
17#include "agp.h" 18#include "agp.h"
18 19
@@ -702,6 +703,7 @@ static struct pci_device_id agp_amd64_pci_table[] = {
702MODULE_DEVICE_TABLE(pci, agp_amd64_pci_table); 703MODULE_DEVICE_TABLE(pci, agp_amd64_pci_table);
703 704
704static struct pci_driver agp_amd64_pci_driver = { 705static struct pci_driver agp_amd64_pci_driver = {
706 .owner = THIS_MODULE,
705 .name = "agpgart-amd64", 707 .name = "agpgart-amd64",
706 .id_table = agp_amd64_pci_table, 708 .id_table = agp_amd64_pci_table,
707 .probe = agp_amd64_probe, 709 .probe = agp_amd64_probe,
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c
index 0b6e72642d6e..fbd415565463 100644
--- a/drivers/char/agp/ati-agp.c
+++ b/drivers/char/agp/ati-agp.c
@@ -118,14 +118,12 @@ static int ati_create_gatt_pages(int nr_tables)
118 int retval = 0; 118 int retval = 0;
119 int i; 119 int i;
120 120
121 tables = kmalloc((nr_tables + 1) * sizeof(ati_page_map *), 121 tables = kzalloc((nr_tables + 1) * sizeof(ati_page_map *),GFP_KERNEL);
122 GFP_KERNEL);
123 if (tables == NULL) 122 if (tables == NULL)
124 return -ENOMEM; 123 return -ENOMEM;
125 124
126 memset(tables, 0, sizeof(ati_page_map *) * (nr_tables + 1));
127 for (i = 0; i < nr_tables; i++) { 125 for (i = 0; i < nr_tables; i++) {
128 entry = kmalloc(sizeof(ati_page_map), GFP_KERNEL); 126 entry = kzalloc(sizeof(ati_page_map), GFP_KERNEL);
129 if (entry == NULL) { 127 if (entry == NULL) {
130 while (i>0) { 128 while (i>0) {
131 kfree (tables[i-1]); 129 kfree (tables[i-1]);
@@ -136,7 +134,6 @@ static int ati_create_gatt_pages(int nr_tables)
136 retval = -ENOMEM; 134 retval = -ENOMEM;
137 break; 135 break;
138 } 136 }
139 memset(entry, 0, sizeof(ati_page_map));
140 tables[i] = entry; 137 tables[i] = entry;
141 retval = ati_create_page_map(entry); 138 retval = ati_create_page_map(entry);
142 if (retval != 0) break; 139 if (retval != 0) break;
@@ -524,6 +521,7 @@ static struct pci_device_id agp_ati_pci_table[] = {
524MODULE_DEVICE_TABLE(pci, agp_ati_pci_table); 521MODULE_DEVICE_TABLE(pci, agp_ati_pci_table);
525 522
526static struct pci_driver agp_ati_pci_driver = { 523static struct pci_driver agp_ati_pci_driver = {
524 .owner = THIS_MODULE,
527 .name = "agpgart-ati", 525 .name = "agpgart-ati",
528 .id_table = agp_ati_pci_table, 526 .id_table = agp_ati_pci_table,
529 .probe = agp_ati_probe, 527 .probe = agp_ati_probe,
diff --git a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
index 82b43c541c8d..73f333f491bd 100644
--- a/drivers/char/agp/backend.c
+++ b/drivers/char/agp/backend.c
@@ -222,12 +222,12 @@ static void agp_backend_cleanup(struct agp_bridge_data *bridge)
222 222
223struct agp_bridge_data *agp_alloc_bridge(void) 223struct agp_bridge_data *agp_alloc_bridge(void)
224{ 224{
225 struct agp_bridge_data *bridge = kmalloc(sizeof(*bridge), GFP_KERNEL); 225 struct agp_bridge_data *bridge;
226 226
227 bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
227 if (!bridge) 228 if (!bridge)
228 return NULL; 229 return NULL;
229 230
230 memset(bridge, 0, sizeof(*bridge));
231 atomic_set(&bridge->agp_in_use, 0); 231 atomic_set(&bridge->agp_in_use, 0);
232 atomic_set(&bridge->current_memory_agp, 0); 232 atomic_set(&bridge->current_memory_agp, 0);
233 233
diff --git a/drivers/char/agp/efficeon-agp.c b/drivers/char/agp/efficeon-agp.c
index ac19fdcd21c1..d41e0a62e32e 100644
--- a/drivers/char/agp/efficeon-agp.c
+++ b/drivers/char/agp/efficeon-agp.c
@@ -219,7 +219,7 @@ static int efficeon_create_gatt_table(struct agp_bridge_data *bridge)
219 219
220 efficeon_private.l1_table[index] = page; 220 efficeon_private.l1_table[index] = page;
221 221
222 value = virt_to_gart(page) | pati | present | index; 222 value = virt_to_gart((unsigned long *)page) | pati | present | index;
223 223
224 pci_write_config_dword(agp_bridge->dev, 224 pci_write_config_dword(agp_bridge->dev,
225 EFFICEON_ATTPAGE, value); 225 EFFICEON_ATTPAGE, value);
@@ -429,6 +429,7 @@ static struct pci_device_id agp_efficeon_pci_table[] = {
429MODULE_DEVICE_TABLE(pci, agp_efficeon_pci_table); 429MODULE_DEVICE_TABLE(pci, agp_efficeon_pci_table);
430 430
431static struct pci_driver agp_efficeon_pci_driver = { 431static struct pci_driver agp_efficeon_pci_driver = {
432 .owner = THIS_MODULE,
432 .name = "agpgart-efficeon", 433 .name = "agpgart-efficeon",
433 .id_table = agp_efficeon_pci_table, 434 .id_table = agp_efficeon_pci_table,
434 .probe = agp_efficeon_probe, 435 .probe = agp_efficeon_probe,
diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
index 3dfb6648547b..17f520c9d471 100644
--- a/drivers/char/agp/frontend.c
+++ b/drivers/char/agp/frontend.c
@@ -189,13 +189,12 @@ static int agp_create_segment(struct agp_client *client, struct agp_region *regi
189 struct agp_segment *user_seg; 189 struct agp_segment *user_seg;
190 size_t i; 190 size_t i;
191 191
192 seg = kmalloc((sizeof(struct agp_segment_priv) * region->seg_count), GFP_KERNEL); 192 seg = kzalloc((sizeof(struct agp_segment_priv) * region->seg_count), GFP_KERNEL);
193 if (seg == NULL) { 193 if (seg == NULL) {
194 kfree(region->seg_list); 194 kfree(region->seg_list);
195 region->seg_list = NULL; 195 region->seg_list = NULL;
196 return -ENOMEM; 196 return -ENOMEM;
197 } 197 }
198 memset(seg, 0, (sizeof(struct agp_segment_priv) * region->seg_count));
199 user_seg = region->seg_list; 198 user_seg = region->seg_list;
200 199
201 for (i = 0; i < region->seg_count; i++) { 200 for (i = 0; i < region->seg_count; i++) {
@@ -332,14 +331,11 @@ static struct agp_controller *agp_create_controller(pid_t id)
332{ 331{
333 struct agp_controller *controller; 332 struct agp_controller *controller;
334 333
335 controller = kmalloc(sizeof(struct agp_controller), GFP_KERNEL); 334 controller = kzalloc(sizeof(struct agp_controller), GFP_KERNEL);
336
337 if (controller == NULL) 335 if (controller == NULL)
338 return NULL; 336 return NULL;
339 337
340 memset(controller, 0, sizeof(struct agp_controller));
341 controller->pid = id; 338 controller->pid = id;
342
343 return controller; 339 return controller;
344} 340}
345 341
@@ -540,12 +536,10 @@ static struct agp_client *agp_create_client(pid_t id)
540{ 536{
541 struct agp_client *new_client; 537 struct agp_client *new_client;
542 538
543 new_client = kmalloc(sizeof(struct agp_client), GFP_KERNEL); 539 new_client = kzalloc(sizeof(struct agp_client), GFP_KERNEL);
544
545 if (new_client == NULL) 540 if (new_client == NULL)
546 return NULL; 541 return NULL;
547 542
548 memset(new_client, 0, sizeof(struct agp_client));
549 new_client->pid = id; 543 new_client->pid = id;
550 agp_insert_client(new_client); 544 agp_insert_client(new_client);
551 return new_client; 545 return new_client;
@@ -709,11 +703,10 @@ static int agp_open(struct inode *inode, struct file *file)
709 if (minor != AGPGART_MINOR) 703 if (minor != AGPGART_MINOR)
710 goto err_out; 704 goto err_out;
711 705
712 priv = kmalloc(sizeof(struct agp_file_private), GFP_KERNEL); 706 priv = kzalloc(sizeof(struct agp_file_private), GFP_KERNEL);
713 if (priv == NULL) 707 if (priv == NULL)
714 goto err_out_nomem; 708 goto err_out_nomem;
715 709
716 memset(priv, 0, sizeof(struct agp_file_private));
717 set_bit(AGP_FF_ALLOW_CLIENT, &priv->access_flags); 710 set_bit(AGP_FF_ALLOW_CLIENT, &priv->access_flags);
718 priv->my_pid = current->pid; 711 priv->my_pid = current->pid;
719 712
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index ac9da0ca36b7..c4a38715c6f9 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -105,12 +105,10 @@ struct agp_memory *agp_create_memory(int scratch_pages)
105{ 105{
106 struct agp_memory *new; 106 struct agp_memory *new;
107 107
108 new = kmalloc(sizeof(struct agp_memory), GFP_KERNEL); 108 new = kzalloc(sizeof(struct agp_memory), GFP_KERNEL);
109
110 if (new == NULL) 109 if (new == NULL)
111 return NULL; 110 return NULL;
112 111
113 memset(new, 0, sizeof(struct agp_memory));
114 new->key = agp_get_key(); 112 new->key = agp_get_key();
115 113
116 if (new->key < 0) { 114 if (new->key < 0) {
@@ -414,7 +412,8 @@ static void agp_v2_parse_one(u32 *requested_mode, u32 *bridge_agpstat, u32 *vga_
414 u32 tmp; 412 u32 tmp;
415 413
416 if (*requested_mode & AGP2_RESERVED_MASK) { 414 if (*requested_mode & AGP2_RESERVED_MASK) {
417 printk(KERN_INFO PFX "reserved bits set in mode 0x%x. Fixed.\n", *requested_mode); 415 printk(KERN_INFO PFX "reserved bits set (%x) in mode 0x%x. Fixed.\n",
416 *requested_mode & AGP2_RESERVED_MASK, *requested_mode);
418 *requested_mode &= ~AGP2_RESERVED_MASK; 417 *requested_mode &= ~AGP2_RESERVED_MASK;
419 } 418 }
420 419
@@ -492,7 +491,8 @@ static void agp_v3_parse_one(u32 *requested_mode, u32 *bridge_agpstat, u32 *vga_
492 u32 tmp; 491 u32 tmp;
493 492
494 if (*requested_mode & AGP3_RESERVED_MASK) { 493 if (*requested_mode & AGP3_RESERVED_MASK) {
495 printk(KERN_INFO PFX "reserved bits set in mode 0x%x. Fixed.\n", *requested_mode); 494 printk(KERN_INFO PFX "reserved bits set (%x) in mode 0x%x. Fixed.\n",
495 *requested_mode & AGP3_RESERVED_MASK, *requested_mode);
496 *requested_mode &= ~AGP3_RESERVED_MASK; 496 *requested_mode &= ~AGP3_RESERVED_MASK;
497 } 497 }
498 498
diff --git a/drivers/char/agp/i460-agp.c b/drivers/char/agp/i460-agp.c
index a2d9e5e48bbe..58944cd271ea 100644
--- a/drivers/char/agp/i460-agp.c
+++ b/drivers/char/agp/i460-agp.c
@@ -227,10 +227,9 @@ static int i460_configure (void)
227 */ 227 */
228 if (I460_IO_PAGE_SHIFT > PAGE_SHIFT) { 228 if (I460_IO_PAGE_SHIFT > PAGE_SHIFT) {
229 size = current_size->num_entries * sizeof(i460.lp_desc[0]); 229 size = current_size->num_entries * sizeof(i460.lp_desc[0]);
230 i460.lp_desc = kmalloc(size, GFP_KERNEL); 230 i460.lp_desc = kzalloc(size, GFP_KERNEL);
231 if (!i460.lp_desc) 231 if (!i460.lp_desc)
232 return -ENOMEM; 232 return -ENOMEM;
233 memset(i460.lp_desc, 0, size);
234 } 233 }
235 return 0; 234 return 0;
236} 235}
@@ -366,13 +365,12 @@ static int i460_alloc_large_page (struct lp_desc *lp)
366 } 365 }
367 366
368 map_size = ((I460_KPAGES_PER_IOPAGE + BITS_PER_LONG - 1) & -BITS_PER_LONG)/8; 367 map_size = ((I460_KPAGES_PER_IOPAGE + BITS_PER_LONG - 1) & -BITS_PER_LONG)/8;
369 lp->alloced_map = kmalloc(map_size, GFP_KERNEL); 368 lp->alloced_map = kzalloc(map_size, GFP_KERNEL);
370 if (!lp->alloced_map) { 369 if (!lp->alloced_map) {
371 free_pages((unsigned long) lpage, order); 370 free_pages((unsigned long) lpage, order);
372 printk(KERN_ERR PFX "Out of memory, we're in trouble...\n"); 371 printk(KERN_ERR PFX "Out of memory, we're in trouble...\n");
373 return -ENOMEM; 372 return -ENOMEM;
374 } 373 }
375 memset(lp->alloced_map, 0, map_size);
376 374
377 lp->paddr = virt_to_gart(lpage); 375 lp->paddr = virt_to_gart(lpage);
378 lp->refcount = 0; 376 lp->refcount = 0;
@@ -619,6 +617,7 @@ static struct pci_device_id agp_intel_i460_pci_table[] = {
619MODULE_DEVICE_TABLE(pci, agp_intel_i460_pci_table); 617MODULE_DEVICE_TABLE(pci, agp_intel_i460_pci_table);
620 618
621static struct pci_driver agp_intel_i460_pci_driver = { 619static struct pci_driver agp_intel_i460_pci_driver = {
620 .owner = THIS_MODULE,
622 .name = "agpgart-intel-i460", 621 .name = "agpgart-intel-i460",
623 .id_table = agp_intel_i460_pci_table, 622 .id_table = agp_intel_i460_pci_table,
624 .probe = agp_intel_i460_probe, 623 .probe = agp_intel_i460_probe,
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 1f7d415f432c..bf4cc9ffd5b1 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -1824,6 +1824,7 @@ static struct pci_device_id agp_intel_pci_table[] = {
1824MODULE_DEVICE_TABLE(pci, agp_intel_pci_table); 1824MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
1825 1825
1826static struct pci_driver agp_intel_pci_driver = { 1826static struct pci_driver agp_intel_pci_driver = {
1827 .owner = THIS_MODULE,
1827 .name = "agpgart-intel", 1828 .name = "agpgart-intel",
1828 .id_table = agp_intel_pci_table, 1829 .id_table = agp_intel_pci_table,
1829 .probe = agp_intel_probe, 1830 .probe = agp_intel_probe,
diff --git a/drivers/char/agp/nvidia-agp.c b/drivers/char/agp/nvidia-agp.c
index 80dafa3030bd..3aed0c5e2f92 100644
--- a/drivers/char/agp/nvidia-agp.c
+++ b/drivers/char/agp/nvidia-agp.c
@@ -398,6 +398,7 @@ static struct pci_device_id agp_nvidia_pci_table[] = {
398MODULE_DEVICE_TABLE(pci, agp_nvidia_pci_table); 398MODULE_DEVICE_TABLE(pci, agp_nvidia_pci_table);
399 399
400static struct pci_driver agp_nvidia_pci_driver = { 400static struct pci_driver agp_nvidia_pci_driver = {
401 .owner = THIS_MODULE,
401 .name = "agpgart-nvidia", 402 .name = "agpgart-nvidia",
402 .id_table = agp_nvidia_pci_table, 403 .id_table = agp_nvidia_pci_table,
403 .probe = agp_nvidia_probe, 404 .probe = agp_nvidia_probe,
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index 7957fc91f6ad..4df7734b51c2 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -289,6 +289,8 @@ static int __devinit agp_sgi_init(void)
289 j = 0; 289 j = 0;
290 list_for_each_entry(info, &tioca_list, ca_list) { 290 list_for_each_entry(info, &tioca_list, ca_list) {
291 struct list_head *tmp; 291 struct list_head *tmp;
292 if (list_empty(info->ca_devices))
293 continue;
292 list_for_each(tmp, info->ca_devices) { 294 list_for_each(tmp, info->ca_devices) {
293 u8 cap_ptr; 295 u8 cap_ptr;
294 pdev = pci_dev_b(tmp); 296 pdev = pci_dev_b(tmp);
diff --git a/drivers/char/agp/sis-agp.c b/drivers/char/agp/sis-agp.c
index ebc05554045c..a701361a8890 100644
--- a/drivers/char/agp/sis-agp.c
+++ b/drivers/char/agp/sis-agp.c
@@ -332,6 +332,7 @@ static struct pci_device_id agp_sis_pci_table[] = {
332MODULE_DEVICE_TABLE(pci, agp_sis_pci_table); 332MODULE_DEVICE_TABLE(pci, agp_sis_pci_table);
333 333
334static struct pci_driver agp_sis_pci_driver = { 334static struct pci_driver agp_sis_pci_driver = {
335 .owner = THIS_MODULE,
335 .name = "agpgart-sis", 336 .name = "agpgart-sis",
336 .id_table = agp_sis_pci_table, 337 .id_table = agp_sis_pci_table,
337 .probe = agp_sis_probe, 338 .probe = agp_sis_probe,
diff --git a/drivers/char/agp/sworks-agp.c b/drivers/char/agp/sworks-agp.c
index 71ea59a1dbeb..5a5392dd1254 100644
--- a/drivers/char/agp/sworks-agp.c
+++ b/drivers/char/agp/sworks-agp.c
@@ -102,19 +102,17 @@ static int serverworks_create_gatt_pages(int nr_tables)
102 int retval = 0; 102 int retval = 0;
103 int i; 103 int i;
104 104
105 tables = kmalloc((nr_tables + 1) * sizeof(struct serverworks_page_map *), 105 tables = kzalloc((nr_tables + 1) * sizeof(struct serverworks_page_map *),
106 GFP_KERNEL); 106 GFP_KERNEL);
107 if (tables == NULL) { 107 if (tables == NULL)
108 return -ENOMEM; 108 return -ENOMEM;
109 } 109
110 memset(tables, 0, sizeof(struct serverworks_page_map *) * (nr_tables + 1));
111 for (i = 0; i < nr_tables; i++) { 110 for (i = 0; i < nr_tables; i++) {
112 entry = kmalloc(sizeof(struct serverworks_page_map), GFP_KERNEL); 111 entry = kzalloc(sizeof(struct serverworks_page_map), GFP_KERNEL);
113 if (entry == NULL) { 112 if (entry == NULL) {
114 retval = -ENOMEM; 113 retval = -ENOMEM;
115 break; 114 break;
116 } 115 }
117 memset(entry, 0, sizeof(struct serverworks_page_map));
118 tables[i] = entry; 116 tables[i] = entry;
119 retval = serverworks_create_page_map(entry); 117 retval = serverworks_create_page_map(entry);
120 if (retval != 0) break; 118 if (retval != 0) break;
@@ -244,13 +242,27 @@ static int serverworks_fetch_size(void)
244 */ 242 */
245static void serverworks_tlbflush(struct agp_memory *temp) 243static void serverworks_tlbflush(struct agp_memory *temp)
246{ 244{
245 unsigned long timeout;
246
247 writeb(1, serverworks_private.registers+SVWRKS_POSTFLUSH); 247 writeb(1, serverworks_private.registers+SVWRKS_POSTFLUSH);
248 while (readb(serverworks_private.registers+SVWRKS_POSTFLUSH) == 1) 248 timeout = jiffies + 3*HZ;
249 while (readb(serverworks_private.registers+SVWRKS_POSTFLUSH) == 1) {
249 cpu_relax(); 250 cpu_relax();
251 if (time_after(jiffies, timeout)) {
252 printk(KERN_ERR PFX "TLB post flush took more than 3 seconds\n");
253 break;
254 }
255 }
250 256
251 writel(1, serverworks_private.registers+SVWRKS_DIRFLUSH); 257 writel(1, serverworks_private.registers+SVWRKS_DIRFLUSH);
252 while(readl(serverworks_private.registers+SVWRKS_DIRFLUSH) == 1) 258 timeout = jiffies + 3*HZ;
259 while (readl(serverworks_private.registers+SVWRKS_DIRFLUSH) == 1) {
253 cpu_relax(); 260 cpu_relax();
261 if (time_after(jiffies, timeout)) {
262 printk(KERN_ERR PFX "TLB Dir flush took more than 3 seconds\n");
263 break;
264 }
265 }
254} 266}
255 267
256static int serverworks_configure(void) 268static int serverworks_configure(void)
@@ -533,6 +545,7 @@ static struct pci_device_id agp_serverworks_pci_table[] = {
533MODULE_DEVICE_TABLE(pci, agp_serverworks_pci_table); 545MODULE_DEVICE_TABLE(pci, agp_serverworks_pci_table);
534 546
535static struct pci_driver agp_serverworks_pci_driver = { 547static struct pci_driver agp_serverworks_pci_driver = {
548 .owner = THIS_MODULE,
536 .name = "agpgart-serverworks", 549 .name = "agpgart-serverworks",
537 .id_table = agp_serverworks_pci_table, 550 .id_table = agp_serverworks_pci_table,
538 .probe = agp_serverworks_probe, 551 .probe = agp_serverworks_probe,
diff --git a/drivers/char/agp/uninorth-agp.c b/drivers/char/agp/uninorth-agp.c
index c8255312b8c1..183c50acab27 100644
--- a/drivers/char/agp/uninorth-agp.c
+++ b/drivers/char/agp/uninorth-agp.c
@@ -658,6 +658,7 @@ static struct pci_device_id agp_uninorth_pci_table[] = {
658MODULE_DEVICE_TABLE(pci, agp_uninorth_pci_table); 658MODULE_DEVICE_TABLE(pci, agp_uninorth_pci_table);
659 659
660static struct pci_driver agp_uninorth_pci_driver = { 660static struct pci_driver agp_uninorth_pci_driver = {
661 .owner = THIS_MODULE,
661 .name = "agpgart-uninorth", 662 .name = "agpgart-uninorth",
662 .id_table = agp_uninorth_pci_table, 663 .id_table = agp_uninorth_pci_table,
663 .probe = agp_uninorth_probe, 664 .probe = agp_uninorth_probe,
diff --git a/drivers/char/agp/via-agp.c b/drivers/char/agp/via-agp.c
index c847df575cf5..5d9a13700074 100644
--- a/drivers/char/agp/via-agp.c
+++ b/drivers/char/agp/via-agp.c
@@ -518,6 +518,7 @@ MODULE_DEVICE_TABLE(pci, agp_via_pci_table);
518 518
519 519
520static struct pci_driver agp_via_pci_driver = { 520static struct pci_driver agp_via_pci_driver = {
521 .owner = THIS_MODULE,
521 .name = "agpgart-via", 522 .name = "agpgart-via",
522 .id_table = agp_via_pci_table, 523 .id_table = agp_via_pci_table,
523 .probe = agp_via_probe, 524 .probe = agp_via_probe,
diff --git a/drivers/char/consolemap.c b/drivers/char/consolemap.c
index 406dea914635..c85a4fa60da7 100644
--- a/drivers/char/consolemap.c
+++ b/drivers/char/consolemap.c
@@ -345,17 +345,15 @@ static void con_release_unimap(struct uni_pagedir *p)
345 for (i = 0; i < 32; i++) { 345 for (i = 0; i < 32; i++) {
346 if ((p1 = p->uni_pgdir[i]) != NULL) { 346 if ((p1 = p->uni_pgdir[i]) != NULL) {
347 for (j = 0; j < 32; j++) 347 for (j = 0; j < 32; j++)
348 if (p1[j]) 348 kfree(p1[j]);
349 kfree(p1[j]);
350 kfree(p1); 349 kfree(p1);
351 } 350 }
352 p->uni_pgdir[i] = NULL; 351 p->uni_pgdir[i] = NULL;
353 } 352 }
354 for (i = 0; i < 4; i++) 353 for (i = 0; i < 4; i++) {
355 if (p->inverse_translations[i]) { 354 kfree(p->inverse_translations[i]);
356 kfree(p->inverse_translations[i]); 355 p->inverse_translations[i] = NULL;
357 p->inverse_translations[i] = NULL; 356 }
358 }
359} 357}
360 358
361void con_free_unimap(struct vc_data *vc) 359void con_free_unimap(struct vc_data *vc)
diff --git a/drivers/char/drm/ffb_context.c b/drivers/char/drm/ffb_context.c
index 8a6cc2751bc9..1383727b443a 100644
--- a/drivers/char/drm/ffb_context.c
+++ b/drivers/char/drm/ffb_context.c
@@ -526,10 +526,8 @@ int ffb_driver_rmctx(struct inode *inode, struct file *filp, unsigned int cmd,
526 if (idx < 0 || idx >= FFB_MAX_CTXS) 526 if (idx < 0 || idx >= FFB_MAX_CTXS)
527 return -EINVAL; 527 return -EINVAL;
528 528
529 if (fpriv->hw_state[idx] != NULL) { 529 kfree(fpriv->hw_state[idx]);
530 kfree(fpriv->hw_state[idx]); 530 fpriv->hw_state[idx] = NULL;
531 fpriv->hw_state[idx] = NULL;
532 }
533 return 0; 531 return 0;
534} 532}
535 533
diff --git a/drivers/char/drm/ffb_drv.c b/drivers/char/drm/ffb_drv.c
index 5c121d6df9f2..c13f9abb41e9 100644
--- a/drivers/char/drm/ffb_drv.c
+++ b/drivers/char/drm/ffb_drv.c
@@ -245,14 +245,12 @@ static void ffb_driver_release(drm_device_t * dev, struct file *filp)
245 245
246static void ffb_driver_pretakedown(drm_device_t * dev) 246static void ffb_driver_pretakedown(drm_device_t * dev)
247{ 247{
248 if (dev->dev_private) 248 kfree(dev->dev_private);
249 kfree(dev->dev_private);
250} 249}
251 250
252static int ffb_driver_postcleanup(drm_device_t * dev) 251static int ffb_driver_postcleanup(drm_device_t * dev)
253{ 252{
254 if (ffb_position != NULL) 253 kfree(ffb_position);
255 kfree(ffb_position);
256 return 0; 254 return 0;
257} 255}
258 256
diff --git a/drivers/char/ip2/i2ellis.c b/drivers/char/ip2/i2ellis.c
index f834d05ccc97..dd761a1e4f08 100644
--- a/drivers/char/ip2/i2ellis.c
+++ b/drivers/char/ip2/i2ellis.c
@@ -106,9 +106,7 @@ iiEllisInit(void)
106static void 106static void
107iiEllisCleanup(void) 107iiEllisCleanup(void)
108{ 108{
109 if ( pDelayTimer != NULL ) { 109 kfree(pDelayTimer);
110 kfree ( pDelayTimer );
111 }
112} 110}
113 111
114//****************************************************************************** 112//******************************************************************************
diff --git a/drivers/char/ipmi/ipmi_bt_sm.c b/drivers/char/ipmi/ipmi_bt_sm.c
index 33862670e285..58dcdee1cd71 100644
--- a/drivers/char/ipmi/ipmi_bt_sm.c
+++ b/drivers/char/ipmi/ipmi_bt_sm.c
@@ -28,6 +28,8 @@
28 28
29#include <linux/kernel.h> /* For printk. */ 29#include <linux/kernel.h> /* For printk. */
30#include <linux/string.h> 30#include <linux/string.h>
31#include <linux/module.h>
32#include <linux/moduleparam.h>
31#include <linux/ipmi_msgdefs.h> /* for completion codes */ 33#include <linux/ipmi_msgdefs.h> /* for completion codes */
32#include "ipmi_si_sm.h" 34#include "ipmi_si_sm.h"
33 35
@@ -36,6 +38,8 @@ static int bt_debug = 0x00; /* Production value 0, see following flags */
36#define BT_DEBUG_ENABLE 1 38#define BT_DEBUG_ENABLE 1
37#define BT_DEBUG_MSG 2 39#define BT_DEBUG_MSG 2
38#define BT_DEBUG_STATES 4 40#define BT_DEBUG_STATES 4
41module_param(bt_debug, int, 0644);
42MODULE_PARM_DESC(bt_debug, "debug bitmask, 1=enable, 2=messages, 4=states");
39 43
40/* Typical "Get BT Capabilities" values are 2-3 retries, 5-10 seconds, 44/* Typical "Get BT Capabilities" values are 2-3 retries, 5-10 seconds,
41 and 64 byte buffers. However, one HP implementation wants 255 bytes of 45 and 64 byte buffers. However, one HP implementation wants 255 bytes of
@@ -43,7 +47,7 @@ static int bt_debug = 0x00; /* Production value 0, see following flags */
43 Since the Open IPMI architecture is single-message oriented at this 47 Since the Open IPMI architecture is single-message oriented at this
44 stage, the queue depth of BT is of no concern. */ 48 stage, the queue depth of BT is of no concern. */
45 49
46#define BT_NORMAL_TIMEOUT 2000000 /* seconds in microseconds */ 50#define BT_NORMAL_TIMEOUT 5000000 /* seconds in microseconds */
47#define BT_RETRY_LIMIT 2 51#define BT_RETRY_LIMIT 2
48#define BT_RESET_DELAY 6000000 /* 6 seconds after warm reset */ 52#define BT_RESET_DELAY 6000000 /* 6 seconds after warm reset */
49 53
@@ -202,7 +206,7 @@ static int bt_get_result(struct si_sm_data *bt,
202 msg_len = bt->read_count - 2; /* account for length & seq */ 206 msg_len = bt->read_count - 2; /* account for length & seq */
203 /* Always NetFn, Cmd, cCode */ 207 /* Always NetFn, Cmd, cCode */
204 if (msg_len < 3 || msg_len > IPMI_MAX_MSG_LENGTH) { 208 if (msg_len < 3 || msg_len > IPMI_MAX_MSG_LENGTH) {
205 printk(KERN_WARNING "BT results: bad msg_len = %d\n", msg_len); 209 printk(KERN_DEBUG "BT results: bad msg_len = %d\n", msg_len);
206 data[0] = bt->write_data[1] | 0x4; /* Kludge a response */ 210 data[0] = bt->write_data[1] | 0x4; /* Kludge a response */
207 data[1] = bt->write_data[3]; 211 data[1] = bt->write_data[3];
208 data[2] = IPMI_ERR_UNSPECIFIED; 212 data[2] = IPMI_ERR_UNSPECIFIED;
@@ -240,7 +244,7 @@ static void reset_flags(struct si_sm_data *bt)
240 BT_CONTROL(BT_B_BUSY); 244 BT_CONTROL(BT_B_BUSY);
241 BT_CONTROL(BT_CLR_WR_PTR); 245 BT_CONTROL(BT_CLR_WR_PTR);
242 BT_CONTROL(BT_SMS_ATN); 246 BT_CONTROL(BT_SMS_ATN);
243#ifdef DEVELOPMENT_ONLY_NOT_FOR_PRODUCTION 247
244 if (BT_STATUS & BT_B2H_ATN) { 248 if (BT_STATUS & BT_B2H_ATN) {
245 int i; 249 int i;
246 BT_CONTROL(BT_H_BUSY); 250 BT_CONTROL(BT_H_BUSY);
@@ -250,7 +254,6 @@ static void reset_flags(struct si_sm_data *bt)
250 BMC2HOST; 254 BMC2HOST;
251 BT_CONTROL(BT_H_BUSY); 255 BT_CONTROL(BT_H_BUSY);
252 } 256 }
253#endif
254} 257}
255 258
256static inline void write_all_bytes(struct si_sm_data *bt) 259static inline void write_all_bytes(struct si_sm_data *bt)
@@ -295,7 +298,7 @@ static inline int read_all_bytes(struct si_sm_data *bt)
295 printk ("\n"); 298 printk ("\n");
296 } 299 }
297 if (bt->seq != bt->write_data[2]) /* idiot check */ 300 if (bt->seq != bt->write_data[2]) /* idiot check */
298 printk(KERN_WARNING "BT: internal error: sequence mismatch\n"); 301 printk(KERN_DEBUG "BT: internal error: sequence mismatch\n");
299 302
300 /* per the spec, the (NetFn, Seq, Cmd) tuples should match */ 303 /* per the spec, the (NetFn, Seq, Cmd) tuples should match */
301 if ((bt->read_data[3] == bt->write_data[3]) && /* Cmd */ 304 if ((bt->read_data[3] == bt->write_data[3]) && /* Cmd */
@@ -321,18 +324,17 @@ static void error_recovery(struct si_sm_data *bt, char *reason)
321 bt->timeout = BT_NORMAL_TIMEOUT; /* various places want to retry */ 324 bt->timeout = BT_NORMAL_TIMEOUT; /* various places want to retry */
322 325
323 status = BT_STATUS; 326 status = BT_STATUS;
324 printk(KERN_WARNING "BT: %s in %s %s ", reason, STATE2TXT, 327 printk(KERN_DEBUG "BT: %s in %s %s\n", reason, STATE2TXT,
325 STATUS2TXT(buf)); 328 STATUS2TXT(buf));
326 329
327 (bt->error_retries)++; 330 (bt->error_retries)++;
328 if (bt->error_retries > BT_RETRY_LIMIT) { 331 if (bt->error_retries > BT_RETRY_LIMIT) {
329 printk("retry limit (%d) exceeded\n", BT_RETRY_LIMIT); 332 printk(KERN_DEBUG "retry limit (%d) exceeded\n", BT_RETRY_LIMIT);
330 bt->state = BT_STATE_HOSED; 333 bt->state = BT_STATE_HOSED;
331 if (!bt->nonzero_status) 334 if (!bt->nonzero_status)
332 printk(KERN_ERR "IPMI: BT stuck, try power cycle\n"); 335 printk(KERN_ERR "IPMI: BT stuck, try power cycle\n");
333 else if (bt->seq == FIRST_SEQ + BT_RETRY_LIMIT) { 336 else if (bt->error_retries <= BT_RETRY_LIMIT + 1) {
334 /* most likely during insmod */ 337 printk(KERN_DEBUG "IPMI: BT reset (takes 5 secs)\n");
335 printk(KERN_WARNING "IPMI: BT reset (takes 5 secs)\n");
336 bt->state = BT_STATE_RESET1; 338 bt->state = BT_STATE_RESET1;
337 } 339 }
338 return; 340 return;
@@ -340,11 +342,11 @@ static void error_recovery(struct si_sm_data *bt, char *reason)
340 342
341 /* Sometimes the BMC queues get in an "off-by-one" state...*/ 343 /* Sometimes the BMC queues get in an "off-by-one" state...*/
342 if ((bt->state == BT_STATE_B2H_WAIT) && (status & BT_B2H_ATN)) { 344 if ((bt->state == BT_STATE_B2H_WAIT) && (status & BT_B2H_ATN)) {
343 printk("retry B2H_WAIT\n"); 345 printk(KERN_DEBUG "retry B2H_WAIT\n");
344 return; 346 return;
345 } 347 }
346 348
347 printk("restart command\n"); 349 printk(KERN_DEBUG "restart command\n");
348 bt->state = BT_STATE_RESTART; 350 bt->state = BT_STATE_RESTART;
349} 351}
350 352
@@ -372,17 +374,6 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
372 return SI_SM_HOSED; 374 return SI_SM_HOSED;
373 375
374 if (bt->state != BT_STATE_IDLE) { /* do timeout test */ 376 if (bt->state != BT_STATE_IDLE) { /* do timeout test */
375
376 /* Certain states, on error conditions, can lock up a CPU
377 because they are effectively in an infinite loop with
378 CALL_WITHOUT_DELAY (right back here with time == 0).
379 Prevent infinite lockup by ALWAYS decrementing timeout. */
380
381 /* FIXME: bt_event is sometimes called with time > BT_NORMAL_TIMEOUT
382 (noticed in ipmi_smic_sm.c January 2004) */
383
384 if ((time <= 0) || (time >= BT_NORMAL_TIMEOUT))
385 time = 100;
386 bt->timeout -= time; 377 bt->timeout -= time;
387 if ((bt->timeout < 0) && (bt->state < BT_STATE_RESET1)) { 378 if ((bt->timeout < 0) && (bt->state < BT_STATE_RESET1)) {
388 error_recovery(bt, "timed out"); 379 error_recovery(bt, "timed out");
@@ -483,6 +474,7 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
483 break; 474 break;
484 475
485 case BT_STATE_RESTART: /* don't reset retries! */ 476 case BT_STATE_RESTART: /* don't reset retries! */
477 reset_flags(bt);
486 bt->write_data[2] = ++bt->seq; 478 bt->write_data[2] = ++bt->seq;
487 bt->read_count = 0; 479 bt->read_count = 0;
488 bt->nonzero_status = 0; 480 bt->nonzero_status = 0;
diff --git a/drivers/char/ipmi/ipmi_kcs_sm.c b/drivers/char/ipmi/ipmi_kcs_sm.c
index d21853a594a3..da1554194d3d 100644
--- a/drivers/char/ipmi/ipmi_kcs_sm.c
+++ b/drivers/char/ipmi/ipmi_kcs_sm.c
@@ -38,16 +38,25 @@
38 */ 38 */
39 39
40#include <linux/kernel.h> /* For printk. */ 40#include <linux/kernel.h> /* For printk. */
41#include <linux/module.h>
42#include <linux/moduleparam.h>
41#include <linux/string.h> 43#include <linux/string.h>
44#include <linux/jiffies.h>
42#include <linux/ipmi_msgdefs.h> /* for completion codes */ 45#include <linux/ipmi_msgdefs.h> /* for completion codes */
43#include "ipmi_si_sm.h" 46#include "ipmi_si_sm.h"
44 47
45/* Set this if you want a printout of why the state machine was hosed 48/* kcs_debug is a bit-field
46 when it gets hosed. */ 49 * KCS_DEBUG_ENABLE - turned on for now
47#define DEBUG_HOSED_REASON 50 * KCS_DEBUG_MSG - commands and their responses
51 * KCS_DEBUG_STATES - state machine
52 */
53#define KCS_DEBUG_STATES 4
54#define KCS_DEBUG_MSG 2
55#define KCS_DEBUG_ENABLE 1
48 56
49/* Print the state machine state on entry every time. */ 57static int kcs_debug;
50#undef DEBUG_STATE 58module_param(kcs_debug, int, 0644);
59MODULE_PARM_DESC(kcs_debug, "debug bitmask, 1=enable, 2=messages, 4=states");
51 60
52/* The states the KCS driver may be in. */ 61/* The states the KCS driver may be in. */
53enum kcs_states { 62enum kcs_states {
@@ -91,6 +100,7 @@ enum kcs_states {
91#define IBF_RETRY_TIMEOUT 1000000 100#define IBF_RETRY_TIMEOUT 1000000
92#define OBF_RETRY_TIMEOUT 1000000 101#define OBF_RETRY_TIMEOUT 1000000
93#define MAX_ERROR_RETRIES 10 102#define MAX_ERROR_RETRIES 10
103#define ERROR0_OBF_WAIT_JIFFIES (2*HZ)
94 104
95struct si_sm_data 105struct si_sm_data
96{ 106{
@@ -107,6 +117,7 @@ struct si_sm_data
107 unsigned int error_retries; 117 unsigned int error_retries;
108 long ibf_timeout; 118 long ibf_timeout;
109 long obf_timeout; 119 long obf_timeout;
120 unsigned long error0_timeout;
110}; 121};
111 122
112static unsigned int init_kcs_data(struct si_sm_data *kcs, 123static unsigned int init_kcs_data(struct si_sm_data *kcs,
@@ -175,11 +186,11 @@ static inline void start_error_recovery(struct si_sm_data *kcs, char *reason)
175{ 186{
176 (kcs->error_retries)++; 187 (kcs->error_retries)++;
177 if (kcs->error_retries > MAX_ERROR_RETRIES) { 188 if (kcs->error_retries > MAX_ERROR_RETRIES) {
178#ifdef DEBUG_HOSED_REASON 189 if (kcs_debug & KCS_DEBUG_ENABLE)
179 printk("ipmi_kcs_sm: kcs hosed: %s\n", reason); 190 printk(KERN_DEBUG "ipmi_kcs_sm: kcs hosed: %s\n", reason);
180#endif
181 kcs->state = KCS_HOSED; 191 kcs->state = KCS_HOSED;
182 } else { 192 } else {
193 kcs->error0_timeout = jiffies + ERROR0_OBF_WAIT_JIFFIES;
183 kcs->state = KCS_ERROR0; 194 kcs->state = KCS_ERROR0;
184 } 195 }
185} 196}
@@ -248,14 +259,21 @@ static void restart_kcs_transaction(struct si_sm_data *kcs)
248static int start_kcs_transaction(struct si_sm_data *kcs, unsigned char *data, 259static int start_kcs_transaction(struct si_sm_data *kcs, unsigned char *data,
249 unsigned int size) 260 unsigned int size)
250{ 261{
262 unsigned int i;
263
251 if ((size < 2) || (size > MAX_KCS_WRITE_SIZE)) { 264 if ((size < 2) || (size > MAX_KCS_WRITE_SIZE)) {
252 return -1; 265 return -1;
253 } 266 }
254
255 if ((kcs->state != KCS_IDLE) && (kcs->state != KCS_HOSED)) { 267 if ((kcs->state != KCS_IDLE) && (kcs->state != KCS_HOSED)) {
256 return -2; 268 return -2;
257 } 269 }
258 270 if (kcs_debug & KCS_DEBUG_MSG) {
271 printk(KERN_DEBUG "start_kcs_transaction -");
272 for (i = 0; i < size; i ++) {
273 printk(" %02x", (unsigned char) (data [i]));
274 }
275 printk ("\n");
276 }
259 kcs->error_retries = 0; 277 kcs->error_retries = 0;
260 memcpy(kcs->write_data, data, size); 278 memcpy(kcs->write_data, data, size);
261 kcs->write_count = size; 279 kcs->write_count = size;
@@ -305,9 +323,9 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
305 323
306 status = read_status(kcs); 324 status = read_status(kcs);
307 325
308#ifdef DEBUG_STATE 326 if (kcs_debug & KCS_DEBUG_STATES)
309 printk(" State = %d, %x\n", kcs->state, status); 327 printk(KERN_DEBUG "KCS: State = %d, %x\n", kcs->state, status);
310#endif 328
311 /* All states wait for ibf, so just do it here. */ 329 /* All states wait for ibf, so just do it here. */
312 if (!check_ibf(kcs, status, time)) 330 if (!check_ibf(kcs, status, time))
313 return SI_SM_CALL_WITH_DELAY; 331 return SI_SM_CALL_WITH_DELAY;
@@ -409,6 +427,10 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
409 427
410 case KCS_ERROR0: 428 case KCS_ERROR0:
411 clear_obf(kcs, status); 429 clear_obf(kcs, status);
430 status = read_status(kcs);
431 if (GET_STATUS_OBF(status)) /* controller isn't responding */
432 if (time_before(jiffies, kcs->error0_timeout))
433 return SI_SM_CALL_WITH_TICK_DELAY;
412 write_cmd(kcs, KCS_GET_STATUS_ABORT); 434 write_cmd(kcs, KCS_GET_STATUS_ABORT);
413 kcs->state = KCS_ERROR1; 435 kcs->state = KCS_ERROR1;
414 break; 436 break;
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 32fa82c78c73..c1d06ba449b6 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -38,13 +38,13 @@
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/poll.h> 39#include <linux/poll.h>
40#include <linux/spinlock.h> 40#include <linux/spinlock.h>
41#include <linux/rwsem.h>
42#include <linux/slab.h> 41#include <linux/slab.h>
43#include <linux/ipmi.h> 42#include <linux/ipmi.h>
44#include <linux/ipmi_smi.h> 43#include <linux/ipmi_smi.h>
45#include <linux/notifier.h> 44#include <linux/notifier.h>
46#include <linux/init.h> 45#include <linux/init.h>
47#include <linux/proc_fs.h> 46#include <linux/proc_fs.h>
47#include <linux/rcupdate.h>
48 48
49#define PFX "IPMI message handler: " 49#define PFX "IPMI message handler: "
50 50
@@ -65,10 +65,19 @@ struct proc_dir_entry *proc_ipmi_root = NULL;
65 the max message timer. This is in milliseconds. */ 65 the max message timer. This is in milliseconds. */
66#define MAX_MSG_TIMEOUT 60000 66#define MAX_MSG_TIMEOUT 60000
67 67
68
69/*
70 * The main "user" data structure.
71 */
68struct ipmi_user 72struct ipmi_user
69{ 73{
70 struct list_head link; 74 struct list_head link;
71 75
76 /* Set to "0" when the user is destroyed. */
77 int valid;
78
79 struct kref refcount;
80
72 /* The upper layer that handles receive messages. */ 81 /* The upper layer that handles receive messages. */
73 struct ipmi_user_hndl *handler; 82 struct ipmi_user_hndl *handler;
74 void *handler_data; 83 void *handler_data;
@@ -87,6 +96,15 @@ struct cmd_rcvr
87 ipmi_user_t user; 96 ipmi_user_t user;
88 unsigned char netfn; 97 unsigned char netfn;
89 unsigned char cmd; 98 unsigned char cmd;
99
100 /*
101 * This is used to form a linked lised during mass deletion.
102 * Since this is in an RCU list, we cannot use the link above
103 * or change any data until the RCU period completes. So we
104 * use this next variable during mass deletion so we can have
105 * a list and don't have to wait and restart the search on
106 * every individual deletion of a command. */
107 struct cmd_rcvr *next;
90}; 108};
91 109
92struct seq_table 110struct seq_table
@@ -150,13 +168,11 @@ struct ipmi_smi
150 /* What interface number are we? */ 168 /* What interface number are we? */
151 int intf_num; 169 int intf_num;
152 170
153 /* The list of upper layers that are using me. We read-lock 171 struct kref refcount;
154 this when delivering messages to the upper layer to keep 172
155 the user from going away while we are processing the 173 /* The list of upper layers that are using me. seq_lock
156 message. This means that you cannot add or delete a user 174 * protects this. */
157 from the receive callback. */ 175 struct list_head users;
158 rwlock_t users_lock;
159 struct list_head users;
160 176
161 /* Used for wake ups at startup. */ 177 /* Used for wake ups at startup. */
162 wait_queue_head_t waitq; 178 wait_queue_head_t waitq;
@@ -193,7 +209,7 @@ struct ipmi_smi
193 209
194 /* The list of command receivers that are registered for commands 210 /* The list of command receivers that are registered for commands
195 on this interface. */ 211 on this interface. */
196 rwlock_t cmd_rcvr_lock; 212 struct semaphore cmd_rcvrs_lock;
197 struct list_head cmd_rcvrs; 213 struct list_head cmd_rcvrs;
198 214
199 /* Events that were queues because no one was there to receive 215 /* Events that were queues because no one was there to receive
@@ -296,16 +312,17 @@ struct ipmi_smi
296 unsigned int events; 312 unsigned int events;
297}; 313};
298 314
315/* Used to mark an interface entry that cannot be used but is not a
316 * free entry, either, primarily used at creation and deletion time so
317 * a slot doesn't get reused too quickly. */
318#define IPMI_INVALID_INTERFACE_ENTRY ((ipmi_smi_t) ((long) 1))
319#define IPMI_INVALID_INTERFACE(i) (((i) == NULL) \
320 || (i == IPMI_INVALID_INTERFACE_ENTRY))
321
299#define MAX_IPMI_INTERFACES 4 322#define MAX_IPMI_INTERFACES 4
300static ipmi_smi_t ipmi_interfaces[MAX_IPMI_INTERFACES]; 323static ipmi_smi_t ipmi_interfaces[MAX_IPMI_INTERFACES];
301 324
302/* Used to keep interfaces from going away while operations are 325/* Directly protects the ipmi_interfaces data structure. */
303 operating on interfaces. Grab read if you are not modifying the
304 interfaces, write if you are. */
305static DECLARE_RWSEM(interfaces_sem);
306
307/* Directly protects the ipmi_interfaces data structure. This is
308 claimed in the timer interrupt. */
309static DEFINE_SPINLOCK(interfaces_lock); 326static DEFINE_SPINLOCK(interfaces_lock);
310 327
311/* List of watchers that want to know when smi's are added and 328/* List of watchers that want to know when smi's are added and
@@ -313,20 +330,72 @@ static DEFINE_SPINLOCK(interfaces_lock);
313static struct list_head smi_watchers = LIST_HEAD_INIT(smi_watchers); 330static struct list_head smi_watchers = LIST_HEAD_INIT(smi_watchers);
314static DECLARE_RWSEM(smi_watchers_sem); 331static DECLARE_RWSEM(smi_watchers_sem);
315 332
333
334static void free_recv_msg_list(struct list_head *q)
335{
336 struct ipmi_recv_msg *msg, *msg2;
337
338 list_for_each_entry_safe(msg, msg2, q, link) {
339 list_del(&msg->link);
340 ipmi_free_recv_msg(msg);
341 }
342}
343
344static void clean_up_interface_data(ipmi_smi_t intf)
345{
346 int i;
347 struct cmd_rcvr *rcvr, *rcvr2;
348 struct list_head list;
349
350 free_recv_msg_list(&intf->waiting_msgs);
351 free_recv_msg_list(&intf->waiting_events);
352
353 /* Wholesale remove all the entries from the list in the
354 * interface and wait for RCU to know that none are in use. */
355 down(&intf->cmd_rcvrs_lock);
356 list_add_rcu(&list, &intf->cmd_rcvrs);
357 list_del_rcu(&intf->cmd_rcvrs);
358 up(&intf->cmd_rcvrs_lock);
359 synchronize_rcu();
360
361 list_for_each_entry_safe(rcvr, rcvr2, &list, link)
362 kfree(rcvr);
363
364 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
365 if ((intf->seq_table[i].inuse)
366 && (intf->seq_table[i].recv_msg))
367 {
368 ipmi_free_recv_msg(intf->seq_table[i].recv_msg);
369 }
370 }
371}
372
373static void intf_free(struct kref *ref)
374{
375 ipmi_smi_t intf = container_of(ref, struct ipmi_smi, refcount);
376
377 clean_up_interface_data(intf);
378 kfree(intf);
379}
380
316int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher) 381int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
317{ 382{
318 int i; 383 int i;
384 unsigned long flags;
319 385
320 down_read(&interfaces_sem);
321 down_write(&smi_watchers_sem); 386 down_write(&smi_watchers_sem);
322 list_add(&(watcher->link), &smi_watchers); 387 list_add(&(watcher->link), &smi_watchers);
388 up_write(&smi_watchers_sem);
389 spin_lock_irqsave(&interfaces_lock, flags);
323 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 390 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
324 if (ipmi_interfaces[i] != NULL) { 391 ipmi_smi_t intf = ipmi_interfaces[i];
325 watcher->new_smi(i); 392 if (IPMI_INVALID_INTERFACE(intf))
326 } 393 continue;
394 spin_unlock_irqrestore(&interfaces_lock, flags);
395 watcher->new_smi(i);
396 spin_lock_irqsave(&interfaces_lock, flags);
327 } 397 }
328 up_write(&smi_watchers_sem); 398 spin_unlock_irqrestore(&interfaces_lock, flags);
329 up_read(&interfaces_sem);
330 return 0; 399 return 0;
331} 400}
332 401
@@ -471,8 +540,8 @@ static void deliver_response(struct ipmi_recv_msg *msg)
471 } 540 }
472 ipmi_free_recv_msg(msg); 541 ipmi_free_recv_msg(msg);
473 } else { 542 } else {
474 msg->user->handler->ipmi_recv_hndl(msg, 543 ipmi_user_t user = msg->user;
475 msg->user->handler_data); 544 user->handler->ipmi_recv_hndl(msg, user->handler_data);
476 } 545 }
477} 546}
478 547
@@ -662,15 +731,18 @@ int ipmi_create_user(unsigned int if_num,
662 if (! new_user) 731 if (! new_user)
663 return -ENOMEM; 732 return -ENOMEM;
664 733
665 down_read(&interfaces_sem); 734 spin_lock_irqsave(&interfaces_lock, flags);
666 if ((if_num >= MAX_IPMI_INTERFACES) || ipmi_interfaces[if_num] == NULL) 735 intf = ipmi_interfaces[if_num];
667 { 736 if ((if_num >= MAX_IPMI_INTERFACES) || IPMI_INVALID_INTERFACE(intf)) {
668 rv = -EINVAL; 737 spin_unlock_irqrestore(&interfaces_lock, flags);
669 goto out_unlock; 738 return -EINVAL;
670 } 739 }
671 740
672 intf = ipmi_interfaces[if_num]; 741 /* Note that each existing user holds a refcount to the interface. */
742 kref_get(&intf->refcount);
743 spin_unlock_irqrestore(&interfaces_lock, flags);
673 744
745 kref_init(&new_user->refcount);
674 new_user->handler = handler; 746 new_user->handler = handler;
675 new_user->handler_data = handler_data; 747 new_user->handler_data = handler_data;
676 new_user->intf = intf; 748 new_user->intf = intf;
@@ -678,98 +750,92 @@ int ipmi_create_user(unsigned int if_num,
678 750
679 if (!try_module_get(intf->handlers->owner)) { 751 if (!try_module_get(intf->handlers->owner)) {
680 rv = -ENODEV; 752 rv = -ENODEV;
681 goto out_unlock; 753 goto out_err;
682 } 754 }
683 755
684 if (intf->handlers->inc_usecount) { 756 if (intf->handlers->inc_usecount) {
685 rv = intf->handlers->inc_usecount(intf->send_info); 757 rv = intf->handlers->inc_usecount(intf->send_info);
686 if (rv) { 758 if (rv) {
687 module_put(intf->handlers->owner); 759 module_put(intf->handlers->owner);
688 goto out_unlock; 760 goto out_err;
689 } 761 }
690 } 762 }
691 763
692 write_lock_irqsave(&intf->users_lock, flags); 764 new_user->valid = 1;
693 list_add_tail(&new_user->link, &intf->users); 765 spin_lock_irqsave(&intf->seq_lock, flags);
694 write_unlock_irqrestore(&intf->users_lock, flags); 766 list_add_rcu(&new_user->link, &intf->users);
695 767 spin_unlock_irqrestore(&intf->seq_lock, flags);
696 out_unlock: 768 *user = new_user;
697 if (rv) { 769 return 0;
698 kfree(new_user);
699 } else {
700 *user = new_user;
701 }
702 770
703 up_read(&interfaces_sem); 771 out_err:
772 kfree(new_user);
773 kref_put(&intf->refcount, intf_free);
704 return rv; 774 return rv;
705} 775}
706 776
707static int ipmi_destroy_user_nolock(ipmi_user_t user) 777static void free_user(struct kref *ref)
778{
779 ipmi_user_t user = container_of(ref, struct ipmi_user, refcount);
780 kfree(user);
781}
782
783int ipmi_destroy_user(ipmi_user_t user)
708{ 784{
709 int rv = -ENODEV; 785 int rv = -ENODEV;
710 ipmi_user_t t_user; 786 ipmi_smi_t intf = user->intf;
711 struct cmd_rcvr *rcvr, *rcvr2;
712 int i; 787 int i;
713 unsigned long flags; 788 unsigned long flags;
789 struct cmd_rcvr *rcvr;
790 struct list_head *entry1, *entry2;
791 struct cmd_rcvr *rcvrs = NULL;
714 792
715 /* Find the user and delete them from the list. */ 793 user->valid = 1;
716 list_for_each_entry(t_user, &(user->intf->users), link) {
717 if (t_user == user) {
718 list_del(&t_user->link);
719 rv = 0;
720 break;
721 }
722 }
723 794
724 if (rv) { 795 /* Remove the user from the interface's sequence table. */
725 goto out_unlock; 796 spin_lock_irqsave(&intf->seq_lock, flags);
726 } 797 list_del_rcu(&user->link);
727 798
728 /* Remove the user from the interfaces sequence table. */
729 spin_lock_irqsave(&(user->intf->seq_lock), flags);
730 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { 799 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
731 if (user->intf->seq_table[i].inuse 800 if (intf->seq_table[i].inuse
732 && (user->intf->seq_table[i].recv_msg->user == user)) 801 && (intf->seq_table[i].recv_msg->user == user))
733 { 802 {
734 user->intf->seq_table[i].inuse = 0; 803 intf->seq_table[i].inuse = 0;
735 } 804 }
736 } 805 }
737 spin_unlock_irqrestore(&(user->intf->seq_lock), flags); 806 spin_unlock_irqrestore(&intf->seq_lock, flags);
738 807
739 /* Remove the user from the command receiver's table. */ 808 /*
740 write_lock_irqsave(&(user->intf->cmd_rcvr_lock), flags); 809 * Remove the user from the command receiver's table. First
741 list_for_each_entry_safe(rcvr, rcvr2, &(user->intf->cmd_rcvrs), link) { 810 * we build a list of everything (not using the standard link,
811 * since other things may be using it till we do
812 * synchronize_rcu()) then free everything in that list.
813 */
814 down(&intf->cmd_rcvrs_lock);
815 list_for_each_safe_rcu(entry1, entry2, &intf->cmd_rcvrs) {
816 rcvr = list_entry(entry1, struct cmd_rcvr, link);
742 if (rcvr->user == user) { 817 if (rcvr->user == user) {
743 list_del(&rcvr->link); 818 list_del_rcu(&rcvr->link);
744 kfree(rcvr); 819 rcvr->next = rcvrs;
820 rcvrs = rcvr;
745 } 821 }
746 } 822 }
747 write_unlock_irqrestore(&(user->intf->cmd_rcvr_lock), flags); 823 up(&intf->cmd_rcvrs_lock);
824 synchronize_rcu();
825 while (rcvrs) {
826 rcvr = rcvrs;
827 rcvrs = rcvr->next;
828 kfree(rcvr);
829 }
748 830
749 kfree(user); 831 module_put(intf->handlers->owner);
832 if (intf->handlers->dec_usecount)
833 intf->handlers->dec_usecount(intf->send_info);
750 834
751 out_unlock: 835 kref_put(&intf->refcount, intf_free);
752 836
753 return rv; 837 kref_put(&user->refcount, free_user);
754}
755
756int ipmi_destroy_user(ipmi_user_t user)
757{
758 int rv;
759 ipmi_smi_t intf = user->intf;
760 unsigned long flags;
761 838
762 down_read(&interfaces_sem);
763 write_lock_irqsave(&intf->users_lock, flags);
764 rv = ipmi_destroy_user_nolock(user);
765 if (!rv) {
766 module_put(intf->handlers->owner);
767 if (intf->handlers->dec_usecount)
768 intf->handlers->dec_usecount(intf->send_info);
769 }
770
771 write_unlock_irqrestore(&intf->users_lock, flags);
772 up_read(&interfaces_sem);
773 return rv; 839 return rv;
774} 840}
775 841
@@ -823,62 +889,78 @@ int ipmi_get_my_LUN(ipmi_user_t user,
823 889
824int ipmi_set_gets_events(ipmi_user_t user, int val) 890int ipmi_set_gets_events(ipmi_user_t user, int val)
825{ 891{
826 unsigned long flags; 892 unsigned long flags;
827 struct ipmi_recv_msg *msg, *msg2; 893 ipmi_smi_t intf = user->intf;
894 struct ipmi_recv_msg *msg, *msg2;
895 struct list_head msgs;
828 896
829 read_lock(&(user->intf->users_lock)); 897 INIT_LIST_HEAD(&msgs);
830 spin_lock_irqsave(&(user->intf->events_lock), flags); 898
899 spin_lock_irqsave(&intf->events_lock, flags);
831 user->gets_events = val; 900 user->gets_events = val;
832 901
833 if (val) { 902 if (val) {
834 /* Deliver any queued events. */ 903 /* Deliver any queued events. */
835 list_for_each_entry_safe(msg, msg2, &(user->intf->waiting_events), link) { 904 list_for_each_entry_safe(msg, msg2, &intf->waiting_events, link) {
836 list_del(&msg->link); 905 list_del(&msg->link);
837 msg->user = user; 906 list_add_tail(&msg->link, &msgs);
838 deliver_response(msg);
839 } 907 }
840 } 908 }
841 909
842 spin_unlock_irqrestore(&(user->intf->events_lock), flags); 910 /* Hold the events lock while doing this to preserve order. */
843 read_unlock(&(user->intf->users_lock)); 911 list_for_each_entry_safe(msg, msg2, &msgs, link) {
912 msg->user = user;
913 kref_get(&user->refcount);
914 deliver_response(msg);
915 }
916
917 spin_unlock_irqrestore(&intf->events_lock, flags);
844 918
845 return 0; 919 return 0;
846} 920}
847 921
922static struct cmd_rcvr *find_cmd_rcvr(ipmi_smi_t intf,
923 unsigned char netfn,
924 unsigned char cmd)
925{
926 struct cmd_rcvr *rcvr;
927
928 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) {
929 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd))
930 return rcvr;
931 }
932 return NULL;
933}
934
848int ipmi_register_for_cmd(ipmi_user_t user, 935int ipmi_register_for_cmd(ipmi_user_t user,
849 unsigned char netfn, 936 unsigned char netfn,
850 unsigned char cmd) 937 unsigned char cmd)
851{ 938{
852 struct cmd_rcvr *cmp; 939 ipmi_smi_t intf = user->intf;
853 unsigned long flags; 940 struct cmd_rcvr *rcvr;
854 struct cmd_rcvr *rcvr; 941 struct cmd_rcvr *entry;
855 int rv = 0; 942 int rv = 0;
856 943
857 944
858 rcvr = kmalloc(sizeof(*rcvr), GFP_KERNEL); 945 rcvr = kmalloc(sizeof(*rcvr), GFP_KERNEL);
859 if (! rcvr) 946 if (! rcvr)
860 return -ENOMEM; 947 return -ENOMEM;
948 rcvr->cmd = cmd;
949 rcvr->netfn = netfn;
950 rcvr->user = user;
861 951
862 read_lock(&(user->intf->users_lock)); 952 down(&intf->cmd_rcvrs_lock);
863 write_lock_irqsave(&(user->intf->cmd_rcvr_lock), flags);
864 /* Make sure the command/netfn is not already registered. */ 953 /* Make sure the command/netfn is not already registered. */
865 list_for_each_entry(cmp, &(user->intf->cmd_rcvrs), link) { 954 entry = find_cmd_rcvr(intf, netfn, cmd);
866 if ((cmp->netfn == netfn) && (cmp->cmd == cmd)) { 955 if (entry) {
867 rv = -EBUSY; 956 rv = -EBUSY;
868 break; 957 goto out_unlock;
869 }
870 }
871
872 if (! rv) {
873 rcvr->cmd = cmd;
874 rcvr->netfn = netfn;
875 rcvr->user = user;
876 list_add_tail(&(rcvr->link), &(user->intf->cmd_rcvrs));
877 } 958 }
878 959
879 write_unlock_irqrestore(&(user->intf->cmd_rcvr_lock), flags); 960 list_add_rcu(&rcvr->link, &intf->cmd_rcvrs);
880 read_unlock(&(user->intf->users_lock));
881 961
962 out_unlock:
963 up(&intf->cmd_rcvrs_lock);
882 if (rv) 964 if (rv)
883 kfree(rcvr); 965 kfree(rcvr);
884 966
@@ -889,31 +971,28 @@ int ipmi_unregister_for_cmd(ipmi_user_t user,
889 unsigned char netfn, 971 unsigned char netfn,
890 unsigned char cmd) 972 unsigned char cmd)
891{ 973{
892 unsigned long flags; 974 ipmi_smi_t intf = user->intf;
893 struct cmd_rcvr *rcvr; 975 struct cmd_rcvr *rcvr;
894 int rv = -ENOENT;
895 976
896 read_lock(&(user->intf->users_lock)); 977 down(&intf->cmd_rcvrs_lock);
897 write_lock_irqsave(&(user->intf->cmd_rcvr_lock), flags);
898 /* Make sure the command/netfn is not already registered. */ 978 /* Make sure the command/netfn is not already registered. */
899 list_for_each_entry(rcvr, &(user->intf->cmd_rcvrs), link) { 979 rcvr = find_cmd_rcvr(intf, netfn, cmd);
900 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) { 980 if ((rcvr) && (rcvr->user == user)) {
901 rv = 0; 981 list_del_rcu(&rcvr->link);
902 list_del(&rcvr->link); 982 up(&intf->cmd_rcvrs_lock);
903 kfree(rcvr); 983 synchronize_rcu();
904 break; 984 kfree(rcvr);
905 } 985 return 0;
986 } else {
987 up(&intf->cmd_rcvrs_lock);
988 return -ENOENT;
906 } 989 }
907 write_unlock_irqrestore(&(user->intf->cmd_rcvr_lock), flags);
908 read_unlock(&(user->intf->users_lock));
909
910 return rv;
911} 990}
912 991
913void ipmi_user_set_run_to_completion(ipmi_user_t user, int val) 992void ipmi_user_set_run_to_completion(ipmi_user_t user, int val)
914{ 993{
915 user->intf->handlers->set_run_to_completion(user->intf->send_info, 994 ipmi_smi_t intf = user->intf;
916 val); 995 intf->handlers->set_run_to_completion(intf->send_info, val);
917} 996}
918 997
919static unsigned char 998static unsigned char
@@ -1010,19 +1089,19 @@ static inline void format_lan_msg(struct ipmi_smi_msg *smi_msg,
1010 supplied in certain circumstances (mainly at panic time). If 1089 supplied in certain circumstances (mainly at panic time). If
1011 messages are supplied, they will be freed, even if an error 1090 messages are supplied, they will be freed, even if an error
1012 occurs. */ 1091 occurs. */
1013static inline int i_ipmi_request(ipmi_user_t user, 1092static int i_ipmi_request(ipmi_user_t user,
1014 ipmi_smi_t intf, 1093 ipmi_smi_t intf,
1015 struct ipmi_addr *addr, 1094 struct ipmi_addr *addr,
1016 long msgid, 1095 long msgid,
1017 struct kernel_ipmi_msg *msg, 1096 struct kernel_ipmi_msg *msg,
1018 void *user_msg_data, 1097 void *user_msg_data,
1019 void *supplied_smi, 1098 void *supplied_smi,
1020 struct ipmi_recv_msg *supplied_recv, 1099 struct ipmi_recv_msg *supplied_recv,
1021 int priority, 1100 int priority,
1022 unsigned char source_address, 1101 unsigned char source_address,
1023 unsigned char source_lun, 1102 unsigned char source_lun,
1024 int retries, 1103 int retries,
1025 unsigned int retry_time_ms) 1104 unsigned int retry_time_ms)
1026{ 1105{
1027 int rv = 0; 1106 int rv = 0;
1028 struct ipmi_smi_msg *smi_msg; 1107 struct ipmi_smi_msg *smi_msg;
@@ -1051,6 +1130,8 @@ static inline int i_ipmi_request(ipmi_user_t user,
1051 } 1130 }
1052 1131
1053 recv_msg->user = user; 1132 recv_msg->user = user;
1133 if (user)
1134 kref_get(&user->refcount);
1054 recv_msg->msgid = msgid; 1135 recv_msg->msgid = msgid;
1055 /* Store the message to send in the receive message so timeout 1136 /* Store the message to send in the receive message so timeout
1056 responses can get the proper response data. */ 1137 responses can get the proper response data. */
@@ -1725,11 +1806,11 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1725 unsigned char version_major, 1806 unsigned char version_major,
1726 unsigned char version_minor, 1807 unsigned char version_minor,
1727 unsigned char slave_addr, 1808 unsigned char slave_addr,
1728 ipmi_smi_t *intf) 1809 ipmi_smi_t *new_intf)
1729{ 1810{
1730 int i, j; 1811 int i, j;
1731 int rv; 1812 int rv;
1732 ipmi_smi_t new_intf; 1813 ipmi_smi_t intf;
1733 unsigned long flags; 1814 unsigned long flags;
1734 1815
1735 1816
@@ -1745,189 +1826,142 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1745 return -ENODEV; 1826 return -ENODEV;
1746 } 1827 }
1747 1828
1748 new_intf = kmalloc(sizeof(*new_intf), GFP_KERNEL); 1829 intf = kmalloc(sizeof(*intf), GFP_KERNEL);
1749 if (!new_intf) 1830 if (!intf)
1750 return -ENOMEM; 1831 return -ENOMEM;
1751 memset(new_intf, 0, sizeof(*new_intf)); 1832 memset(intf, 0, sizeof(*intf));
1752 1833 intf->intf_num = -1;
1753 new_intf->proc_dir = NULL; 1834 kref_init(&intf->refcount);
1835 intf->version_major = version_major;
1836 intf->version_minor = version_minor;
1837 for (j = 0; j < IPMI_MAX_CHANNELS; j++) {
1838 intf->channels[j].address = IPMI_BMC_SLAVE_ADDR;
1839 intf->channels[j].lun = 2;
1840 }
1841 if (slave_addr != 0)
1842 intf->channels[0].address = slave_addr;
1843 INIT_LIST_HEAD(&intf->users);
1844 intf->handlers = handlers;
1845 intf->send_info = send_info;
1846 spin_lock_init(&intf->seq_lock);
1847 for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) {
1848 intf->seq_table[j].inuse = 0;
1849 intf->seq_table[j].seqid = 0;
1850 }
1851 intf->curr_seq = 0;
1852#ifdef CONFIG_PROC_FS
1853 spin_lock_init(&intf->proc_entry_lock);
1854#endif
1855 spin_lock_init(&intf->waiting_msgs_lock);
1856 INIT_LIST_HEAD(&intf->waiting_msgs);
1857 spin_lock_init(&intf->events_lock);
1858 INIT_LIST_HEAD(&intf->waiting_events);
1859 intf->waiting_events_count = 0;
1860 init_MUTEX(&intf->cmd_rcvrs_lock);
1861 INIT_LIST_HEAD(&intf->cmd_rcvrs);
1862 init_waitqueue_head(&intf->waitq);
1863
1864 spin_lock_init(&intf->counter_lock);
1865 intf->proc_dir = NULL;
1754 1866
1755 rv = -ENOMEM; 1867 rv = -ENOMEM;
1756 1868 spin_lock_irqsave(&interfaces_lock, flags);
1757 down_write(&interfaces_sem);
1758 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 1869 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
1759 if (ipmi_interfaces[i] == NULL) { 1870 if (ipmi_interfaces[i] == NULL) {
1760 new_intf->intf_num = i; 1871 intf->intf_num = i;
1761 new_intf->version_major = version_major; 1872 /* Reserve the entry till we are done. */
1762 new_intf->version_minor = version_minor; 1873 ipmi_interfaces[i] = IPMI_INVALID_INTERFACE_ENTRY;
1763 for (j = 0; j < IPMI_MAX_CHANNELS; j++) {
1764 new_intf->channels[j].address
1765 = IPMI_BMC_SLAVE_ADDR;
1766 new_intf->channels[j].lun = 2;
1767 }
1768 if (slave_addr != 0)
1769 new_intf->channels[0].address = slave_addr;
1770 rwlock_init(&(new_intf->users_lock));
1771 INIT_LIST_HEAD(&(new_intf->users));
1772 new_intf->handlers = handlers;
1773 new_intf->send_info = send_info;
1774 spin_lock_init(&(new_intf->seq_lock));
1775 for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) {
1776 new_intf->seq_table[j].inuse = 0;
1777 new_intf->seq_table[j].seqid = 0;
1778 }
1779 new_intf->curr_seq = 0;
1780#ifdef CONFIG_PROC_FS
1781 spin_lock_init(&(new_intf->proc_entry_lock));
1782#endif
1783 spin_lock_init(&(new_intf->waiting_msgs_lock));
1784 INIT_LIST_HEAD(&(new_intf->waiting_msgs));
1785 spin_lock_init(&(new_intf->events_lock));
1786 INIT_LIST_HEAD(&(new_intf->waiting_events));
1787 new_intf->waiting_events_count = 0;
1788 rwlock_init(&(new_intf->cmd_rcvr_lock));
1789 init_waitqueue_head(&new_intf->waitq);
1790 INIT_LIST_HEAD(&(new_intf->cmd_rcvrs));
1791
1792 spin_lock_init(&(new_intf->counter_lock));
1793
1794 spin_lock_irqsave(&interfaces_lock, flags);
1795 ipmi_interfaces[i] = new_intf;
1796 spin_unlock_irqrestore(&interfaces_lock, flags);
1797
1798 rv = 0; 1874 rv = 0;
1799 *intf = new_intf;
1800 break; 1875 break;
1801 } 1876 }
1802 } 1877 }
1878 spin_unlock_irqrestore(&interfaces_lock, flags);
1879 if (rv)
1880 goto out;
1803 1881
1804 downgrade_write(&interfaces_sem); 1882 /* FIXME - this is an ugly kludge, this sets the intf for the
1805 1883 caller before sending any messages with it. */
1806 if (rv == 0) 1884 *new_intf = intf;
1807 rv = add_proc_entries(*intf, i);
1808
1809 if (rv == 0) {
1810 if ((version_major > 1)
1811 || ((version_major == 1) && (version_minor >= 5)))
1812 {
1813 /* Start scanning the channels to see what is
1814 available. */
1815 (*intf)->null_user_handler = channel_handler;
1816 (*intf)->curr_channel = 0;
1817 rv = send_channel_info_cmd(*intf, 0);
1818 if (rv)
1819 goto out;
1820 1885
1821 /* Wait for the channel info to be read. */ 1886 if ((version_major > 1)
1822 up_read(&interfaces_sem); 1887 || ((version_major == 1) && (version_minor >= 5)))
1823 wait_event((*intf)->waitq, 1888 {
1824 ((*intf)->curr_channel>=IPMI_MAX_CHANNELS)); 1889 /* Start scanning the channels to see what is
1825 down_read(&interfaces_sem); 1890 available. */
1891 intf->null_user_handler = channel_handler;
1892 intf->curr_channel = 0;
1893 rv = send_channel_info_cmd(intf, 0);
1894 if (rv)
1895 goto out;
1826 1896
1827 if (ipmi_interfaces[i] != new_intf) 1897 /* Wait for the channel info to be read. */
1828 /* Well, it went away. Just return. */ 1898 wait_event(intf->waitq,
1829 goto out; 1899 intf->curr_channel >= IPMI_MAX_CHANNELS);
1830 } else { 1900 } else {
1831 /* Assume a single IPMB channel at zero. */ 1901 /* Assume a single IPMB channel at zero. */
1832 (*intf)->channels[0].medium = IPMI_CHANNEL_MEDIUM_IPMB; 1902 intf->channels[0].medium = IPMI_CHANNEL_MEDIUM_IPMB;
1833 (*intf)->channels[0].protocol 1903 intf->channels[0].protocol = IPMI_CHANNEL_PROTOCOL_IPMB;
1834 = IPMI_CHANNEL_PROTOCOL_IPMB;
1835 }
1836
1837 /* Call all the watcher interfaces to tell
1838 them that a new interface is available. */
1839 call_smi_watchers(i);
1840 } 1904 }
1841 1905
1842 out: 1906 if (rv == 0)
1843 up_read(&interfaces_sem); 1907 rv = add_proc_entries(intf, i);
1844 1908
1909 out:
1845 if (rv) { 1910 if (rv) {
1846 if (new_intf->proc_dir) 1911 if (intf->proc_dir)
1847 remove_proc_entries(new_intf); 1912 remove_proc_entries(intf);
1848 kfree(new_intf); 1913 kref_put(&intf->refcount, intf_free);
1914 if (i < MAX_IPMI_INTERFACES) {
1915 spin_lock_irqsave(&interfaces_lock, flags);
1916 ipmi_interfaces[i] = NULL;
1917 spin_unlock_irqrestore(&interfaces_lock, flags);
1918 }
1919 } else {
1920 spin_lock_irqsave(&interfaces_lock, flags);
1921 ipmi_interfaces[i] = intf;
1922 spin_unlock_irqrestore(&interfaces_lock, flags);
1923 call_smi_watchers(i);
1849 } 1924 }
1850 1925
1851 return rv; 1926 return rv;
1852} 1927}
1853 1928
1854static void free_recv_msg_list(struct list_head *q)
1855{
1856 struct ipmi_recv_msg *msg, *msg2;
1857
1858 list_for_each_entry_safe(msg, msg2, q, link) {
1859 list_del(&msg->link);
1860 ipmi_free_recv_msg(msg);
1861 }
1862}
1863
1864static void free_cmd_rcvr_list(struct list_head *q)
1865{
1866 struct cmd_rcvr *rcvr, *rcvr2;
1867
1868 list_for_each_entry_safe(rcvr, rcvr2, q, link) {
1869 list_del(&rcvr->link);
1870 kfree(rcvr);
1871 }
1872}
1873
1874static void clean_up_interface_data(ipmi_smi_t intf)
1875{
1876 int i;
1877
1878 free_recv_msg_list(&(intf->waiting_msgs));
1879 free_recv_msg_list(&(intf->waiting_events));
1880 free_cmd_rcvr_list(&(intf->cmd_rcvrs));
1881
1882 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
1883 if ((intf->seq_table[i].inuse)
1884 && (intf->seq_table[i].recv_msg))
1885 {
1886 ipmi_free_recv_msg(intf->seq_table[i].recv_msg);
1887 }
1888 }
1889}
1890
1891int ipmi_unregister_smi(ipmi_smi_t intf) 1929int ipmi_unregister_smi(ipmi_smi_t intf)
1892{ 1930{
1893 int rv = -ENODEV;
1894 int i; 1931 int i;
1895 struct ipmi_smi_watcher *w; 1932 struct ipmi_smi_watcher *w;
1896 unsigned long flags; 1933 unsigned long flags;
1897 1934
1898 down_write(&interfaces_sem); 1935 spin_lock_irqsave(&interfaces_lock, flags);
1899 if (list_empty(&(intf->users))) 1936 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
1900 { 1937 if (ipmi_interfaces[i] == intf) {
1901 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 1938 /* Set the interface number reserved until we
1902 if (ipmi_interfaces[i] == intf) { 1939 * are done. */
1903 remove_proc_entries(intf); 1940 ipmi_interfaces[i] = IPMI_INVALID_INTERFACE_ENTRY;
1904 spin_lock_irqsave(&interfaces_lock, flags); 1941 intf->intf_num = -1;
1905 ipmi_interfaces[i] = NULL; 1942 break;
1906 clean_up_interface_data(intf);
1907 spin_unlock_irqrestore(&interfaces_lock,flags);
1908 kfree(intf);
1909 rv = 0;
1910 goto out_call_watcher;
1911 }
1912 } 1943 }
1913 } else {
1914 rv = -EBUSY;
1915 } 1944 }
1916 up_write(&interfaces_sem); 1945 spin_unlock_irqrestore(&interfaces_lock,flags);
1917 1946
1918 return rv; 1947 if (i == MAX_IPMI_INTERFACES)
1948 return -ENODEV;
1919 1949
1920 out_call_watcher: 1950 remove_proc_entries(intf);
1921 downgrade_write(&interfaces_sem);
1922 1951
1923 /* Call all the watcher interfaces to tell them that 1952 /* Call all the watcher interfaces to tell them that
1924 an interface is gone. */ 1953 an interface is gone. */
1925 down_read(&smi_watchers_sem); 1954 down_read(&smi_watchers_sem);
1926 list_for_each_entry(w, &smi_watchers, link) { 1955 list_for_each_entry(w, &smi_watchers, link)
1927 w->smi_gone(i); 1956 w->smi_gone(i);
1928 }
1929 up_read(&smi_watchers_sem); 1957 up_read(&smi_watchers_sem);
1930 up_read(&interfaces_sem); 1958
1959 /* Allow the entry to be reused now. */
1960 spin_lock_irqsave(&interfaces_lock, flags);
1961 ipmi_interfaces[i] = NULL;
1962 spin_unlock_irqrestore(&interfaces_lock,flags);
1963
1964 kref_put(&intf->refcount, intf_free);
1931 return 0; 1965 return 0;
1932} 1966}
1933 1967
@@ -1998,14 +2032,14 @@ static int handle_ipmb_get_msg_rsp(ipmi_smi_t intf,
1998static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf, 2032static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
1999 struct ipmi_smi_msg *msg) 2033 struct ipmi_smi_msg *msg)
2000{ 2034{
2001 struct cmd_rcvr *rcvr; 2035 struct cmd_rcvr *rcvr;
2002 int rv = 0; 2036 int rv = 0;
2003 unsigned char netfn; 2037 unsigned char netfn;
2004 unsigned char cmd; 2038 unsigned char cmd;
2005 ipmi_user_t user = NULL; 2039 ipmi_user_t user = NULL;
2006 struct ipmi_ipmb_addr *ipmb_addr; 2040 struct ipmi_ipmb_addr *ipmb_addr;
2007 struct ipmi_recv_msg *recv_msg; 2041 struct ipmi_recv_msg *recv_msg;
2008 unsigned long flags; 2042 unsigned long flags;
2009 2043
2010 if (msg->rsp_size < 10) { 2044 if (msg->rsp_size < 10) {
2011 /* Message not big enough, just ignore it. */ 2045 /* Message not big enough, just ignore it. */
@@ -2023,16 +2057,14 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
2023 netfn = msg->rsp[4] >> 2; 2057 netfn = msg->rsp[4] >> 2;
2024 cmd = msg->rsp[8]; 2058 cmd = msg->rsp[8];
2025 2059
2026 read_lock(&(intf->cmd_rcvr_lock)); 2060 rcu_read_lock();
2027 2061 rcvr = find_cmd_rcvr(intf, netfn, cmd);
2028 /* Find the command/netfn. */ 2062 if (rcvr) {
2029 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) { 2063 user = rcvr->user;
2030 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) { 2064 kref_get(&user->refcount);
2031 user = rcvr->user; 2065 } else
2032 break; 2066 user = NULL;
2033 } 2067 rcu_read_unlock();
2034 }
2035 read_unlock(&(intf->cmd_rcvr_lock));
2036 2068
2037 if (user == NULL) { 2069 if (user == NULL) {
2038 /* We didn't find a user, deliver an error response. */ 2070 /* We didn't find a user, deliver an error response. */
@@ -2079,6 +2111,7 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
2079 message, so requeue it for handling 2111 message, so requeue it for handling
2080 later. */ 2112 later. */
2081 rv = 1; 2113 rv = 1;
2114 kref_put(&user->refcount, free_user);
2082 } else { 2115 } else {
2083 /* Extract the source address from the data. */ 2116 /* Extract the source address from the data. */
2084 ipmb_addr = (struct ipmi_ipmb_addr *) &recv_msg->addr; 2117 ipmb_addr = (struct ipmi_ipmb_addr *) &recv_msg->addr;
@@ -2179,14 +2212,14 @@ static int handle_lan_get_msg_rsp(ipmi_smi_t intf,
2179static int handle_lan_get_msg_cmd(ipmi_smi_t intf, 2212static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2180 struct ipmi_smi_msg *msg) 2213 struct ipmi_smi_msg *msg)
2181{ 2214{
2182 struct cmd_rcvr *rcvr; 2215 struct cmd_rcvr *rcvr;
2183 int rv = 0; 2216 int rv = 0;
2184 unsigned char netfn; 2217 unsigned char netfn;
2185 unsigned char cmd; 2218 unsigned char cmd;
2186 ipmi_user_t user = NULL; 2219 ipmi_user_t user = NULL;
2187 struct ipmi_lan_addr *lan_addr; 2220 struct ipmi_lan_addr *lan_addr;
2188 struct ipmi_recv_msg *recv_msg; 2221 struct ipmi_recv_msg *recv_msg;
2189 unsigned long flags; 2222 unsigned long flags;
2190 2223
2191 if (msg->rsp_size < 12) { 2224 if (msg->rsp_size < 12) {
2192 /* Message not big enough, just ignore it. */ 2225 /* Message not big enough, just ignore it. */
@@ -2204,19 +2237,17 @@ static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2204 netfn = msg->rsp[6] >> 2; 2237 netfn = msg->rsp[6] >> 2;
2205 cmd = msg->rsp[10]; 2238 cmd = msg->rsp[10];
2206 2239
2207 read_lock(&(intf->cmd_rcvr_lock)); 2240 rcu_read_lock();
2208 2241 rcvr = find_cmd_rcvr(intf, netfn, cmd);
2209 /* Find the command/netfn. */ 2242 if (rcvr) {
2210 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) { 2243 user = rcvr->user;
2211 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) { 2244 kref_get(&user->refcount);
2212 user = rcvr->user; 2245 } else
2213 break; 2246 user = NULL;
2214 } 2247 rcu_read_unlock();
2215 }
2216 read_unlock(&(intf->cmd_rcvr_lock));
2217 2248
2218 if (user == NULL) { 2249 if (user == NULL) {
2219 /* We didn't find a user, deliver an error response. */ 2250 /* We didn't find a user, just give up. */
2220 spin_lock_irqsave(&intf->counter_lock, flags); 2251 spin_lock_irqsave(&intf->counter_lock, flags);
2221 intf->unhandled_commands++; 2252 intf->unhandled_commands++;
2222 spin_unlock_irqrestore(&intf->counter_lock, flags); 2253 spin_unlock_irqrestore(&intf->counter_lock, flags);
@@ -2235,6 +2266,7 @@ static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2235 message, so requeue it for handling 2266 message, so requeue it for handling
2236 later. */ 2267 later. */
2237 rv = 1; 2268 rv = 1;
2269 kref_put(&user->refcount, free_user);
2238 } else { 2270 } else {
2239 /* Extract the source address from the data. */ 2271 /* Extract the source address from the data. */
2240 lan_addr = (struct ipmi_lan_addr *) &recv_msg->addr; 2272 lan_addr = (struct ipmi_lan_addr *) &recv_msg->addr;
@@ -2286,8 +2318,6 @@ static void copy_event_into_recv_msg(struct ipmi_recv_msg *recv_msg,
2286 recv_msg->msg.data_len = msg->rsp_size - 3; 2318 recv_msg->msg.data_len = msg->rsp_size - 3;
2287} 2319}
2288 2320
2289/* This will be called with the intf->users_lock read-locked, so no need
2290 to do that here. */
2291static int handle_read_event_rsp(ipmi_smi_t intf, 2321static int handle_read_event_rsp(ipmi_smi_t intf,
2292 struct ipmi_smi_msg *msg) 2322 struct ipmi_smi_msg *msg)
2293{ 2323{
@@ -2313,7 +2343,7 @@ static int handle_read_event_rsp(ipmi_smi_t intf,
2313 2343
2314 INIT_LIST_HEAD(&msgs); 2344 INIT_LIST_HEAD(&msgs);
2315 2345
2316 spin_lock_irqsave(&(intf->events_lock), flags); 2346 spin_lock_irqsave(&intf->events_lock, flags);
2317 2347
2318 spin_lock(&intf->counter_lock); 2348 spin_lock(&intf->counter_lock);
2319 intf->events++; 2349 intf->events++;
@@ -2321,12 +2351,14 @@ static int handle_read_event_rsp(ipmi_smi_t intf,
2321 2351
2322 /* Allocate and fill in one message for every user that is getting 2352 /* Allocate and fill in one message for every user that is getting
2323 events. */ 2353 events. */
2324 list_for_each_entry(user, &(intf->users), link) { 2354 rcu_read_lock();
2355 list_for_each_entry_rcu(user, &intf->users, link) {
2325 if (! user->gets_events) 2356 if (! user->gets_events)
2326 continue; 2357 continue;
2327 2358
2328 recv_msg = ipmi_alloc_recv_msg(); 2359 recv_msg = ipmi_alloc_recv_msg();
2329 if (! recv_msg) { 2360 if (! recv_msg) {
2361 rcu_read_unlock();
2330 list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, link) { 2362 list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, link) {
2331 list_del(&recv_msg->link); 2363 list_del(&recv_msg->link);
2332 ipmi_free_recv_msg(recv_msg); 2364 ipmi_free_recv_msg(recv_msg);
@@ -2342,8 +2374,10 @@ static int handle_read_event_rsp(ipmi_smi_t intf,
2342 2374
2343 copy_event_into_recv_msg(recv_msg, msg); 2375 copy_event_into_recv_msg(recv_msg, msg);
2344 recv_msg->user = user; 2376 recv_msg->user = user;
2377 kref_get(&user->refcount);
2345 list_add_tail(&(recv_msg->link), &msgs); 2378 list_add_tail(&(recv_msg->link), &msgs);
2346 } 2379 }
2380 rcu_read_unlock();
2347 2381
2348 if (deliver_count) { 2382 if (deliver_count) {
2349 /* Now deliver all the messages. */ 2383 /* Now deliver all the messages. */
@@ -2382,9 +2416,8 @@ static int handle_bmc_rsp(ipmi_smi_t intf,
2382 struct ipmi_smi_msg *msg) 2416 struct ipmi_smi_msg *msg)
2383{ 2417{
2384 struct ipmi_recv_msg *recv_msg; 2418 struct ipmi_recv_msg *recv_msg;
2385 int found = 0;
2386 struct ipmi_user *user;
2387 unsigned long flags; 2419 unsigned long flags;
2420 struct ipmi_user *user;
2388 2421
2389 recv_msg = (struct ipmi_recv_msg *) msg->user_data; 2422 recv_msg = (struct ipmi_recv_msg *) msg->user_data;
2390 if (recv_msg == NULL) 2423 if (recv_msg == NULL)
@@ -2396,16 +2429,9 @@ static int handle_bmc_rsp(ipmi_smi_t intf,
2396 return 0; 2429 return 0;
2397 } 2430 }
2398 2431
2432 user = recv_msg->user;
2399 /* Make sure the user still exists. */ 2433 /* Make sure the user still exists. */
2400 list_for_each_entry(user, &(intf->users), link) { 2434 if (user && !user->valid) {
2401 if (user == recv_msg->user) {
2402 /* Found it, so we can deliver it */
2403 found = 1;
2404 break;
2405 }
2406 }
2407
2408 if ((! found) && recv_msg->user) {
2409 /* The user for the message went away, so give up. */ 2435 /* The user for the message went away, so give up. */
2410 spin_lock_irqsave(&intf->counter_lock, flags); 2436 spin_lock_irqsave(&intf->counter_lock, flags);
2411 intf->unhandled_local_responses++; 2437 intf->unhandled_local_responses++;
@@ -2486,7 +2512,7 @@ static int handle_new_recv_msg(ipmi_smi_t intf,
2486 { 2512 {
2487 /* It's a response to a response we sent. For this we 2513 /* It's a response to a response we sent. For this we
2488 deliver a send message response to the user. */ 2514 deliver a send message response to the user. */
2489 struct ipmi_recv_msg *recv_msg = msg->user_data; 2515 struct ipmi_recv_msg *recv_msg = msg->user_data;
2490 2516
2491 requeue = 0; 2517 requeue = 0;
2492 if (msg->rsp_size < 2) 2518 if (msg->rsp_size < 2)
@@ -2498,13 +2524,18 @@ static int handle_new_recv_msg(ipmi_smi_t intf,
2498 /* Invalid channel number */ 2524 /* Invalid channel number */
2499 goto out; 2525 goto out;
2500 2526
2501 if (recv_msg) { 2527 if (!recv_msg)
2502 recv_msg->recv_type = IPMI_RESPONSE_RESPONSE_TYPE; 2528 goto out;
2503 recv_msg->msg.data = recv_msg->msg_data; 2529
2504 recv_msg->msg.data_len = 1; 2530 /* Make sure the user still exists. */
2505 recv_msg->msg_data[0] = msg->rsp[2]; 2531 if (!recv_msg->user || !recv_msg->user->valid)
2506 deliver_response(recv_msg); 2532 goto out;
2507 } 2533
2534 recv_msg->recv_type = IPMI_RESPONSE_RESPONSE_TYPE;
2535 recv_msg->msg.data = recv_msg->msg_data;
2536 recv_msg->msg.data_len = 1;
2537 recv_msg->msg_data[0] = msg->rsp[2];
2538 deliver_response(recv_msg);
2508 } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) 2539 } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2))
2509 && (msg->rsp[1] == IPMI_GET_MSG_CMD)) 2540 && (msg->rsp[1] == IPMI_GET_MSG_CMD))
2510 { 2541 {
@@ -2570,14 +2601,11 @@ void ipmi_smi_msg_received(ipmi_smi_t intf,
2570 int rv; 2601 int rv;
2571 2602
2572 2603
2573 /* Lock the user lock so the user can't go away while we are
2574 working on it. */
2575 read_lock(&(intf->users_lock));
2576
2577 if ((msg->data_size >= 2) 2604 if ((msg->data_size >= 2)
2578 && (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2)) 2605 && (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2))
2579 && (msg->data[1] == IPMI_SEND_MSG_CMD) 2606 && (msg->data[1] == IPMI_SEND_MSG_CMD)
2580 && (msg->user_data == NULL)) { 2607 && (msg->user_data == NULL))
2608 {
2581 /* This is the local response to a command send, start 2609 /* This is the local response to a command send, start
2582 the timer for these. The user_data will not be 2610 the timer for these. The user_data will not be
2583 NULL if this is a response send, and we will let 2611 NULL if this is a response send, and we will let
@@ -2612,46 +2640,46 @@ void ipmi_smi_msg_received(ipmi_smi_t intf,
2612 } 2640 }
2613 2641
2614 ipmi_free_smi_msg(msg); 2642 ipmi_free_smi_msg(msg);
2615 goto out_unlock; 2643 goto out;
2616 } 2644 }
2617 2645
2618 /* To preserve message order, if the list is not empty, we 2646 /* To preserve message order, if the list is not empty, we
2619 tack this message onto the end of the list. */ 2647 tack this message onto the end of the list. */
2620 spin_lock_irqsave(&(intf->waiting_msgs_lock), flags); 2648 spin_lock_irqsave(&intf->waiting_msgs_lock, flags);
2621 if (!list_empty(&(intf->waiting_msgs))) { 2649 if (!list_empty(&intf->waiting_msgs)) {
2622 list_add_tail(&(msg->link), &(intf->waiting_msgs)); 2650 list_add_tail(&msg->link, &intf->waiting_msgs);
2623 spin_unlock_irqrestore(&(intf->waiting_msgs_lock), flags); 2651 spin_unlock(&intf->waiting_msgs_lock);
2624 goto out_unlock; 2652 goto out;
2625 } 2653 }
2626 spin_unlock_irqrestore(&(intf->waiting_msgs_lock), flags); 2654 spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags);
2627 2655
2628 rv = handle_new_recv_msg(intf, msg); 2656 rv = handle_new_recv_msg(intf, msg);
2629 if (rv > 0) { 2657 if (rv > 0) {
2630 /* Could not handle the message now, just add it to a 2658 /* Could not handle the message now, just add it to a
2631 list to handle later. */ 2659 list to handle later. */
2632 spin_lock_irqsave(&(intf->waiting_msgs_lock), flags); 2660 spin_lock(&intf->waiting_msgs_lock);
2633 list_add_tail(&(msg->link), &(intf->waiting_msgs)); 2661 list_add_tail(&msg->link, &intf->waiting_msgs);
2634 spin_unlock_irqrestore(&(intf->waiting_msgs_lock), flags); 2662 spin_unlock(&intf->waiting_msgs_lock);
2635 } else if (rv == 0) { 2663 } else if (rv == 0) {
2636 ipmi_free_smi_msg(msg); 2664 ipmi_free_smi_msg(msg);
2637 } 2665 }
2638 2666
2639 out_unlock: 2667 out:
2640 read_unlock(&(intf->users_lock)); 2668 return;
2641} 2669}
2642 2670
2643void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf) 2671void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf)
2644{ 2672{
2645 ipmi_user_t user; 2673 ipmi_user_t user;
2646 2674
2647 read_lock(&(intf->users_lock)); 2675 rcu_read_lock();
2648 list_for_each_entry(user, &(intf->users), link) { 2676 list_for_each_entry_rcu(user, &intf->users, link) {
2649 if (! user->handler->ipmi_watchdog_pretimeout) 2677 if (! user->handler->ipmi_watchdog_pretimeout)
2650 continue; 2678 continue;
2651 2679
2652 user->handler->ipmi_watchdog_pretimeout(user->handler_data); 2680 user->handler->ipmi_watchdog_pretimeout(user->handler_data);
2653 } 2681 }
2654 read_unlock(&(intf->users_lock)); 2682 rcu_read_unlock();
2655} 2683}
2656 2684
2657static void 2685static void
@@ -2691,8 +2719,65 @@ smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg,
2691 return smi_msg; 2719 return smi_msg;
2692} 2720}
2693 2721
2694static void 2722static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent,
2695ipmi_timeout_handler(long timeout_period) 2723 struct list_head *timeouts, long timeout_period,
2724 int slot, unsigned long *flags)
2725{
2726 struct ipmi_recv_msg *msg;
2727
2728 if (!ent->inuse)
2729 return;
2730
2731 ent->timeout -= timeout_period;
2732 if (ent->timeout > 0)
2733 return;
2734
2735 if (ent->retries_left == 0) {
2736 /* The message has used all its retries. */
2737 ent->inuse = 0;
2738 msg = ent->recv_msg;
2739 list_add_tail(&msg->link, timeouts);
2740 spin_lock(&intf->counter_lock);
2741 if (ent->broadcast)
2742 intf->timed_out_ipmb_broadcasts++;
2743 else if (ent->recv_msg->addr.addr_type == IPMI_LAN_ADDR_TYPE)
2744 intf->timed_out_lan_commands++;
2745 else
2746 intf->timed_out_ipmb_commands++;
2747 spin_unlock(&intf->counter_lock);
2748 } else {
2749 struct ipmi_smi_msg *smi_msg;
2750 /* More retries, send again. */
2751
2752 /* Start with the max timer, set to normal
2753 timer after the message is sent. */
2754 ent->timeout = MAX_MSG_TIMEOUT;
2755 ent->retries_left--;
2756 spin_lock(&intf->counter_lock);
2757 if (ent->recv_msg->addr.addr_type == IPMI_LAN_ADDR_TYPE)
2758 intf->retransmitted_lan_commands++;
2759 else
2760 intf->retransmitted_ipmb_commands++;
2761 spin_unlock(&intf->counter_lock);
2762
2763 smi_msg = smi_from_recv_msg(intf, ent->recv_msg, slot,
2764 ent->seqid);
2765 if (! smi_msg)
2766 return;
2767
2768 spin_unlock_irqrestore(&intf->seq_lock, *flags);
2769 /* Send the new message. We send with a zero
2770 * priority. It timed out, I doubt time is
2771 * that critical now, and high priority
2772 * messages are really only for messages to the
2773 * local MC, which don't get resent. */
2774 intf->handlers->sender(intf->send_info,
2775 smi_msg, 0);
2776 spin_lock_irqsave(&intf->seq_lock, *flags);
2777 }
2778}
2779
2780static void ipmi_timeout_handler(long timeout_period)
2696{ 2781{
2697 ipmi_smi_t intf; 2782 ipmi_smi_t intf;
2698 struct list_head timeouts; 2783 struct list_head timeouts;
@@ -2706,14 +2791,14 @@ ipmi_timeout_handler(long timeout_period)
2706 spin_lock(&interfaces_lock); 2791 spin_lock(&interfaces_lock);
2707 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 2792 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
2708 intf = ipmi_interfaces[i]; 2793 intf = ipmi_interfaces[i];
2709 if (intf == NULL) 2794 if (IPMI_INVALID_INTERFACE(intf))
2710 continue; 2795 continue;
2711 2796 kref_get(&intf->refcount);
2712 read_lock(&(intf->users_lock)); 2797 spin_unlock(&interfaces_lock);
2713 2798
2714 /* See if any waiting messages need to be processed. */ 2799 /* See if any waiting messages need to be processed. */
2715 spin_lock_irqsave(&(intf->waiting_msgs_lock), flags); 2800 spin_lock_irqsave(&intf->waiting_msgs_lock, flags);
2716 list_for_each_entry_safe(smi_msg, smi_msg2, &(intf->waiting_msgs), link) { 2801 list_for_each_entry_safe(smi_msg, smi_msg2, &intf->waiting_msgs, link) {
2717 if (! handle_new_recv_msg(intf, smi_msg)) { 2802 if (! handle_new_recv_msg(intf, smi_msg)) {
2718 list_del(&smi_msg->link); 2803 list_del(&smi_msg->link);
2719 ipmi_free_smi_msg(smi_msg); 2804 ipmi_free_smi_msg(smi_msg);
@@ -2723,73 +2808,23 @@ ipmi_timeout_handler(long timeout_period)
2723 break; 2808 break;
2724 } 2809 }
2725 } 2810 }
2726 spin_unlock_irqrestore(&(intf->waiting_msgs_lock), flags); 2811 spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags);
2727 2812
2728 /* Go through the seq table and find any messages that 2813 /* Go through the seq table and find any messages that
2729 have timed out, putting them in the timeouts 2814 have timed out, putting them in the timeouts
2730 list. */ 2815 list. */
2731 spin_lock_irqsave(&(intf->seq_lock), flags); 2816 spin_lock_irqsave(&intf->seq_lock, flags);
2732 for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) { 2817 for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++)
2733 struct seq_table *ent = &(intf->seq_table[j]); 2818 check_msg_timeout(intf, &(intf->seq_table[j]),
2734 if (!ent->inuse) 2819 &timeouts, timeout_period, j,
2735 continue; 2820 &flags);
2736 2821 spin_unlock_irqrestore(&intf->seq_lock, flags);
2737 ent->timeout -= timeout_period; 2822
2738 if (ent->timeout > 0) 2823 list_for_each_entry_safe(msg, msg2, &timeouts, link)
2739 continue;
2740
2741 if (ent->retries_left == 0) {
2742 /* The message has used all its retries. */
2743 ent->inuse = 0;
2744 msg = ent->recv_msg;
2745 list_add_tail(&(msg->link), &timeouts);
2746 spin_lock(&intf->counter_lock);
2747 if (ent->broadcast)
2748 intf->timed_out_ipmb_broadcasts++;
2749 else if (ent->recv_msg->addr.addr_type
2750 == IPMI_LAN_ADDR_TYPE)
2751 intf->timed_out_lan_commands++;
2752 else
2753 intf->timed_out_ipmb_commands++;
2754 spin_unlock(&intf->counter_lock);
2755 } else {
2756 struct ipmi_smi_msg *smi_msg;
2757 /* More retries, send again. */
2758
2759 /* Start with the max timer, set to normal
2760 timer after the message is sent. */
2761 ent->timeout = MAX_MSG_TIMEOUT;
2762 ent->retries_left--;
2763 spin_lock(&intf->counter_lock);
2764 if (ent->recv_msg->addr.addr_type
2765 == IPMI_LAN_ADDR_TYPE)
2766 intf->retransmitted_lan_commands++;
2767 else
2768 intf->retransmitted_ipmb_commands++;
2769 spin_unlock(&intf->counter_lock);
2770 smi_msg = smi_from_recv_msg(intf,
2771 ent->recv_msg, j, ent->seqid);
2772 if (! smi_msg)
2773 continue;
2774
2775 spin_unlock_irqrestore(&(intf->seq_lock),flags);
2776 /* Send the new message. We send with a zero
2777 * priority. It timed out, I doubt time is
2778 * that critical now, and high priority
2779 * messages are really only for messages to the
2780 * local MC, which don't get resent. */
2781 intf->handlers->sender(intf->send_info,
2782 smi_msg, 0);
2783 spin_lock_irqsave(&(intf->seq_lock), flags);
2784 }
2785 }
2786 spin_unlock_irqrestore(&(intf->seq_lock), flags);
2787
2788 list_for_each_entry_safe(msg, msg2, &timeouts, link) {
2789 handle_msg_timeout(msg); 2824 handle_msg_timeout(msg);
2790 }
2791 2825
2792 read_unlock(&(intf->users_lock)); 2826 kref_put(&intf->refcount, intf_free);
2827 spin_lock(&interfaces_lock);
2793 } 2828 }
2794 spin_unlock(&interfaces_lock); 2829 spin_unlock(&interfaces_lock);
2795} 2830}
@@ -2802,7 +2837,7 @@ static void ipmi_request_event(void)
2802 spin_lock(&interfaces_lock); 2837 spin_lock(&interfaces_lock);
2803 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 2838 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
2804 intf = ipmi_interfaces[i]; 2839 intf = ipmi_interfaces[i];
2805 if (intf == NULL) 2840 if (IPMI_INVALID_INTERFACE(intf))
2806 continue; 2841 continue;
2807 2842
2808 intf->handlers->request_events(intf->send_info); 2843 intf->handlers->request_events(intf->send_info);
@@ -2884,6 +2919,13 @@ struct ipmi_recv_msg *ipmi_alloc_recv_msg(void)
2884 return rv; 2919 return rv;
2885} 2920}
2886 2921
2922void ipmi_free_recv_msg(struct ipmi_recv_msg *msg)
2923{
2924 if (msg->user)
2925 kref_put(&msg->user->refcount, free_user);
2926 msg->done(msg);
2927}
2928
2887#ifdef CONFIG_IPMI_PANIC_EVENT 2929#ifdef CONFIG_IPMI_PANIC_EVENT
2888 2930
2889static void dummy_smi_done_handler(struct ipmi_smi_msg *msg) 2931static void dummy_smi_done_handler(struct ipmi_smi_msg *msg)
@@ -2964,7 +3006,7 @@ static void send_panic_events(char *str)
2964 /* For every registered interface, send the event. */ 3006 /* For every registered interface, send the event. */
2965 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3007 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
2966 intf = ipmi_interfaces[i]; 3008 intf = ipmi_interfaces[i];
2967 if (intf == NULL) 3009 if (IPMI_INVALID_INTERFACE(intf))
2968 continue; 3010 continue;
2969 3011
2970 /* Send the event announcing the panic. */ 3012 /* Send the event announcing the panic. */
@@ -2995,7 +3037,7 @@ static void send_panic_events(char *str)
2995 int j; 3037 int j;
2996 3038
2997 intf = ipmi_interfaces[i]; 3039 intf = ipmi_interfaces[i];
2998 if (intf == NULL) 3040 if (IPMI_INVALID_INTERFACE(intf))
2999 continue; 3041 continue;
3000 3042
3001 /* First job here is to figure out where to send the 3043 /* First job here is to figure out where to send the
@@ -3131,7 +3173,7 @@ static int panic_event(struct notifier_block *this,
3131 /* For every registered interface, set it to run to completion. */ 3173 /* For every registered interface, set it to run to completion. */
3132 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3174 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
3133 intf = ipmi_interfaces[i]; 3175 intf = ipmi_interfaces[i];
3134 if (intf == NULL) 3176 if (IPMI_INVALID_INTERFACE(intf))
3135 continue; 3177 continue;
3136 3178
3137 intf->handlers->set_run_to_completion(intf->send_info, 1); 3179 intf->handlers->set_run_to_completion(intf->send_info, 1);
@@ -3160,9 +3202,8 @@ static int ipmi_init_msghandler(void)
3160 printk(KERN_INFO "ipmi message handler version " 3202 printk(KERN_INFO "ipmi message handler version "
3161 IPMI_DRIVER_VERSION "\n"); 3203 IPMI_DRIVER_VERSION "\n");
3162 3204
3163 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3205 for (i = 0; i < MAX_IPMI_INTERFACES; i++)
3164 ipmi_interfaces[i] = NULL; 3206 ipmi_interfaces[i] = NULL;
3165 }
3166 3207
3167#ifdef CONFIG_PROC_FS 3208#ifdef CONFIG_PROC_FS
3168 proc_ipmi_root = proc_mkdir("ipmi", NULL); 3209 proc_ipmi_root = proc_mkdir("ipmi", NULL);
@@ -3258,3 +3299,4 @@ EXPORT_SYMBOL(ipmi_get_my_LUN);
3258EXPORT_SYMBOL(ipmi_smi_add_proc_entry); 3299EXPORT_SYMBOL(ipmi_smi_add_proc_entry);
3259EXPORT_SYMBOL(proc_ipmi_root); 3300EXPORT_SYMBOL(proc_ipmi_root);
3260EXPORT_SYMBOL(ipmi_user_set_run_to_completion); 3301EXPORT_SYMBOL(ipmi_user_set_run_to_completion);
3302EXPORT_SYMBOL(ipmi_free_recv_msg);
diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index f66947722e12..e053eade0366 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -56,7 +56,7 @@ static int poweroff_powercycle;
56 56
57/* parameter definition to allow user to flag power cycle */ 57/* parameter definition to allow user to flag power cycle */
58module_param(poweroff_powercycle, int, 0644); 58module_param(poweroff_powercycle, int, 0644);
59MODULE_PARM_DESC(poweroff_powercycles, " Set to non-zero to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down."); 59MODULE_PARM_DESC(poweroff_powercycle, " Set to non-zero to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down.");
60 60
61/* Stuff from the get device id command. */ 61/* Stuff from the get device id command. */
62static unsigned int mfg_id; 62static unsigned int mfg_id;
@@ -611,9 +611,7 @@ static int ipmi_poweroff_init (void)
611 } 611 }
612#endif 612#endif
613 613
614#ifdef CONFIG_PROC_FS
615 rv = ipmi_smi_watcher_register(&smi_watcher); 614 rv = ipmi_smi_watcher_register(&smi_watcher);
616#endif
617 if (rv) { 615 if (rv) {
618 unregister_sysctl_table(ipmi_table_header); 616 unregister_sysctl_table(ipmi_table_header);
619 printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv); 617 printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv);
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index b6e5cbfb09f8..ea89dca3dbb5 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -51,6 +51,8 @@
51#include <linux/list.h> 51#include <linux/list.h>
52#include <linux/pci.h> 52#include <linux/pci.h>
53#include <linux/ioport.h> 53#include <linux/ioport.h>
54#include <linux/notifier.h>
55#include <linux/kthread.h>
54#include <asm/irq.h> 56#include <asm/irq.h>
55#ifdef CONFIG_HIGH_RES_TIMERS 57#ifdef CONFIG_HIGH_RES_TIMERS
56#include <linux/hrtime.h> 58#include <linux/hrtime.h>
@@ -125,6 +127,7 @@ struct ipmi_device_id {
125 127
126struct smi_info 128struct smi_info
127{ 129{
130 int intf_num;
128 ipmi_smi_t intf; 131 ipmi_smi_t intf;
129 struct si_sm_data *si_sm; 132 struct si_sm_data *si_sm;
130 struct si_sm_handlers *handlers; 133 struct si_sm_handlers *handlers;
@@ -192,8 +195,7 @@ struct smi_info
192 unsigned long last_timeout_jiffies; 195 unsigned long last_timeout_jiffies;
193 196
194 /* Used to gracefully stop the timer without race conditions. */ 197 /* Used to gracefully stop the timer without race conditions. */
195 volatile int stop_operation; 198 atomic_t stop_operation;
196 volatile int timer_stopped;
197 199
198 /* The driver will disable interrupts when it gets into a 200 /* The driver will disable interrupts when it gets into a
199 situation where it cannot handle messages due to lack of 201 situation where it cannot handle messages due to lack of
@@ -220,8 +222,16 @@ struct smi_info
220 unsigned long events; 222 unsigned long events;
221 unsigned long watchdog_pretimeouts; 223 unsigned long watchdog_pretimeouts;
222 unsigned long incoming_messages; 224 unsigned long incoming_messages;
225
226 struct task_struct *thread;
223}; 227};
224 228
229static struct notifier_block *xaction_notifier_list;
230static int register_xaction_notifier(struct notifier_block * nb)
231{
232 return notifier_chain_register(&xaction_notifier_list, nb);
233}
234
225static void si_restart_short_timer(struct smi_info *smi_info); 235static void si_restart_short_timer(struct smi_info *smi_info);
226 236
227static void deliver_recv_msg(struct smi_info *smi_info, 237static void deliver_recv_msg(struct smi_info *smi_info,
@@ -281,6 +291,11 @@ static enum si_sm_result start_next_msg(struct smi_info *smi_info)
281 do_gettimeofday(&t); 291 do_gettimeofday(&t);
282 printk("**Start2: %d.%9.9d\n", t.tv_sec, t.tv_usec); 292 printk("**Start2: %d.%9.9d\n", t.tv_sec, t.tv_usec);
283#endif 293#endif
294 err = notifier_call_chain(&xaction_notifier_list, 0, smi_info);
295 if (err & NOTIFY_STOP_MASK) {
296 rv = SI_SM_CALL_WITHOUT_DELAY;
297 goto out;
298 }
284 err = smi_info->handlers->start_transaction( 299 err = smi_info->handlers->start_transaction(
285 smi_info->si_sm, 300 smi_info->si_sm,
286 smi_info->curr_msg->data, 301 smi_info->curr_msg->data,
@@ -291,6 +306,7 @@ static enum si_sm_result start_next_msg(struct smi_info *smi_info)
291 306
292 rv = SI_SM_CALL_WITHOUT_DELAY; 307 rv = SI_SM_CALL_WITHOUT_DELAY;
293 } 308 }
309 out:
294 spin_unlock(&(smi_info->msg_lock)); 310 spin_unlock(&(smi_info->msg_lock));
295 311
296 return rv; 312 return rv;
@@ -766,6 +782,29 @@ static void set_run_to_completion(void *send_info, int i_run_to_completion)
766 spin_unlock_irqrestore(&(smi_info->si_lock), flags); 782 spin_unlock_irqrestore(&(smi_info->si_lock), flags);
767} 783}
768 784
785static int ipmi_thread(void *data)
786{
787 struct smi_info *smi_info = data;
788 unsigned long flags;
789 enum si_sm_result smi_result;
790
791 set_user_nice(current, 19);
792 while (!kthread_should_stop()) {
793 spin_lock_irqsave(&(smi_info->si_lock), flags);
794 smi_result=smi_event_handler(smi_info, 0);
795 spin_unlock_irqrestore(&(smi_info->si_lock), flags);
796 if (smi_result == SI_SM_CALL_WITHOUT_DELAY) {
797 /* do nothing */
798 }
799 else if (smi_result == SI_SM_CALL_WITH_DELAY)
800 udelay(1);
801 else
802 schedule_timeout_interruptible(1);
803 }
804 return 0;
805}
806
807
769static void poll(void *send_info) 808static void poll(void *send_info)
770{ 809{
771 struct smi_info *smi_info = send_info; 810 struct smi_info *smi_info = send_info;
@@ -819,15 +858,13 @@ static void smi_timeout(unsigned long data)
819 enum si_sm_result smi_result; 858 enum si_sm_result smi_result;
820 unsigned long flags; 859 unsigned long flags;
821 unsigned long jiffies_now; 860 unsigned long jiffies_now;
822 unsigned long time_diff; 861 long time_diff;
823#ifdef DEBUG_TIMING 862#ifdef DEBUG_TIMING
824 struct timeval t; 863 struct timeval t;
825#endif 864#endif
826 865
827 if (smi_info->stop_operation) { 866 if (atomic_read(&smi_info->stop_operation))
828 smi_info->timer_stopped = 1;
829 return; 867 return;
830 }
831 868
832 spin_lock_irqsave(&(smi_info->si_lock), flags); 869 spin_lock_irqsave(&(smi_info->si_lock), flags);
833#ifdef DEBUG_TIMING 870#ifdef DEBUG_TIMING
@@ -835,7 +872,7 @@ static void smi_timeout(unsigned long data)
835 printk("**Timer: %d.%9.9d\n", t.tv_sec, t.tv_usec); 872 printk("**Timer: %d.%9.9d\n", t.tv_sec, t.tv_usec);
836#endif 873#endif
837 jiffies_now = jiffies; 874 jiffies_now = jiffies;
838 time_diff = ((jiffies_now - smi_info->last_timeout_jiffies) 875 time_diff = (((long)jiffies_now - (long)smi_info->last_timeout_jiffies)
839 * SI_USEC_PER_JIFFY); 876 * SI_USEC_PER_JIFFY);
840 smi_result = smi_event_handler(smi_info, time_diff); 877 smi_result = smi_event_handler(smi_info, time_diff);
841 878
@@ -900,7 +937,7 @@ static irqreturn_t si_irq_handler(int irq, void *data, struct pt_regs *regs)
900 smi_info->interrupts++; 937 smi_info->interrupts++;
901 spin_unlock(&smi_info->count_lock); 938 spin_unlock(&smi_info->count_lock);
902 939
903 if (smi_info->stop_operation) 940 if (atomic_read(&smi_info->stop_operation))
904 goto out; 941 goto out;
905 942
906#ifdef DEBUG_TIMING 943#ifdef DEBUG_TIMING
@@ -1419,7 +1456,7 @@ static u32 ipmi_acpi_gpe(void *context)
1419 smi_info->interrupts++; 1456 smi_info->interrupts++;
1420 spin_unlock(&smi_info->count_lock); 1457 spin_unlock(&smi_info->count_lock);
1421 1458
1422 if (smi_info->stop_operation) 1459 if (atomic_read(&smi_info->stop_operation))
1423 goto out; 1460 goto out;
1424 1461
1425#ifdef DEBUG_TIMING 1462#ifdef DEBUG_TIMING
@@ -1919,7 +1956,8 @@ static int try_get_dev_id(struct smi_info *smi_info)
1919 smi_result = smi_info->handlers->event(smi_info->si_sm, 0); 1956 smi_result = smi_info->handlers->event(smi_info->si_sm, 0);
1920 for (;;) 1957 for (;;)
1921 { 1958 {
1922 if (smi_result == SI_SM_CALL_WITH_DELAY) { 1959 if (smi_result == SI_SM_CALL_WITH_DELAY ||
1960 smi_result == SI_SM_CALL_WITH_TICK_DELAY) {
1923 schedule_timeout_uninterruptible(1); 1961 schedule_timeout_uninterruptible(1);
1924 smi_result = smi_info->handlers->event( 1962 smi_result = smi_info->handlers->event(
1925 smi_info->si_sm, 100); 1963 smi_info->si_sm, 100);
@@ -2052,6 +2090,9 @@ static int oem_data_avail_to_receive_msg_avail(struct smi_info *smi_info)
2052 * IPMI Version = 0x51 IPMI 1.5 2090 * IPMI Version = 0x51 IPMI 1.5
2053 * Manufacturer ID = A2 02 00 Dell IANA 2091 * Manufacturer ID = A2 02 00 Dell IANA
2054 * 2092 *
2093 * Additionally, PowerEdge systems with IPMI < 1.5 may also assert
2094 * OEM0_DATA_AVAIL and needs to be treated as RECEIVE_MSG_AVAIL.
2095 *
2055 */ 2096 */
2056#define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20 2097#define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20
2057#define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80 2098#define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80
@@ -2061,16 +2102,87 @@ static void setup_dell_poweredge_oem_data_handler(struct smi_info *smi_info)
2061{ 2102{
2062 struct ipmi_device_id *id = &smi_info->device_id; 2103 struct ipmi_device_id *id = &smi_info->device_id;
2063 const char mfr[3]=DELL_IANA_MFR_ID; 2104 const char mfr[3]=DELL_IANA_MFR_ID;
2064 if (! memcmp(mfr, id->manufacturer_id, sizeof(mfr)) 2105 if (! memcmp(mfr, id->manufacturer_id, sizeof(mfr))) {
2065 && (id->device_id == DELL_POWEREDGE_8G_BMC_DEVICE_ID) 2106 if (id->device_id == DELL_POWEREDGE_8G_BMC_DEVICE_ID &&
2066 && (id->device_revision == DELL_POWEREDGE_8G_BMC_DEVICE_REV) 2107 id->device_revision == DELL_POWEREDGE_8G_BMC_DEVICE_REV &&
2067 && (id->ipmi_version == DELL_POWEREDGE_8G_BMC_IPMI_VERSION)) 2108 id->ipmi_version == DELL_POWEREDGE_8G_BMC_IPMI_VERSION) {
2068 { 2109 smi_info->oem_data_avail_handler =
2069 smi_info->oem_data_avail_handler = 2110 oem_data_avail_to_receive_msg_avail;
2070 oem_data_avail_to_receive_msg_avail; 2111 }
2112 else if (ipmi_version_major(id) < 1 ||
2113 (ipmi_version_major(id) == 1 &&
2114 ipmi_version_minor(id) < 5)) {
2115 smi_info->oem_data_avail_handler =
2116 oem_data_avail_to_receive_msg_avail;
2117 }
2071 } 2118 }
2072} 2119}
2073 2120
2121#define CANNOT_RETURN_REQUESTED_LENGTH 0xCA
2122static void return_hosed_msg_badsize(struct smi_info *smi_info)
2123{
2124 struct ipmi_smi_msg *msg = smi_info->curr_msg;
2125
2126 /* Make it a reponse */
2127 msg->rsp[0] = msg->data[0] | 4;
2128 msg->rsp[1] = msg->data[1];
2129 msg->rsp[2] = CANNOT_RETURN_REQUESTED_LENGTH;
2130 msg->rsp_size = 3;
2131 smi_info->curr_msg = NULL;
2132 deliver_recv_msg(smi_info, msg);
2133}
2134
2135/*
2136 * dell_poweredge_bt_xaction_handler
2137 * @info - smi_info.device_id must be populated
2138 *
2139 * Dell PowerEdge servers with the BT interface (x6xx and 1750) will
2140 * not respond to a Get SDR command if the length of the data
2141 * requested is exactly 0x3A, which leads to command timeouts and no
2142 * data returned. This intercepts such commands, and causes userspace
2143 * callers to try again with a different-sized buffer, which succeeds.
2144 */
2145
2146#define STORAGE_NETFN 0x0A
2147#define STORAGE_CMD_GET_SDR 0x23
2148static int dell_poweredge_bt_xaction_handler(struct notifier_block *self,
2149 unsigned long unused,
2150 void *in)
2151{
2152 struct smi_info *smi_info = in;
2153 unsigned char *data = smi_info->curr_msg->data;
2154 unsigned int size = smi_info->curr_msg->data_size;
2155 if (size >= 8 &&
2156 (data[0]>>2) == STORAGE_NETFN &&
2157 data[1] == STORAGE_CMD_GET_SDR &&
2158 data[7] == 0x3A) {
2159 return_hosed_msg_badsize(smi_info);
2160 return NOTIFY_STOP;
2161 }
2162 return NOTIFY_DONE;
2163}
2164
2165static struct notifier_block dell_poweredge_bt_xaction_notifier = {
2166 .notifier_call = dell_poweredge_bt_xaction_handler,
2167};
2168
2169/*
2170 * setup_dell_poweredge_bt_xaction_handler
2171 * @info - smi_info.device_id must be filled in already
2172 *
2173 * Fills in smi_info.device_id.start_transaction_pre_hook
2174 * when we know what function to use there.
2175 */
2176static void
2177setup_dell_poweredge_bt_xaction_handler(struct smi_info *smi_info)
2178{
2179 struct ipmi_device_id *id = &smi_info->device_id;
2180 const char mfr[3]=DELL_IANA_MFR_ID;
2181 if (! memcmp(mfr, id->manufacturer_id, sizeof(mfr)) &&
2182 smi_info->si_type == SI_BT)
2183 register_xaction_notifier(&dell_poweredge_bt_xaction_notifier);
2184}
2185
2074/* 2186/*
2075 * setup_oem_data_handler 2187 * setup_oem_data_handler
2076 * @info - smi_info.device_id must be filled in already 2188 * @info - smi_info.device_id must be filled in already
@@ -2084,6 +2196,18 @@ static void setup_oem_data_handler(struct smi_info *smi_info)
2084 setup_dell_poweredge_oem_data_handler(smi_info); 2196 setup_dell_poweredge_oem_data_handler(smi_info);
2085} 2197}
2086 2198
2199static void setup_xaction_handlers(struct smi_info *smi_info)
2200{
2201 setup_dell_poweredge_bt_xaction_handler(smi_info);
2202}
2203
2204static inline void wait_for_timer_and_thread(struct smi_info *smi_info)
2205{
2206 if (smi_info->thread != ERR_PTR(-ENOMEM))
2207 kthread_stop(smi_info->thread);
2208 del_timer_sync(&smi_info->si_timer);
2209}
2210
2087/* Returns 0 if initialized, or negative on an error. */ 2211/* Returns 0 if initialized, or negative on an error. */
2088static int init_one_smi(int intf_num, struct smi_info **smi) 2212static int init_one_smi(int intf_num, struct smi_info **smi)
2089{ 2213{
@@ -2179,6 +2303,7 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2179 goto out_err; 2303 goto out_err;
2180 2304
2181 setup_oem_data_handler(new_smi); 2305 setup_oem_data_handler(new_smi);
2306 setup_xaction_handlers(new_smi);
2182 2307
2183 /* Try to claim any interrupts. */ 2308 /* Try to claim any interrupts. */
2184 new_smi->irq_setup(new_smi); 2309 new_smi->irq_setup(new_smi);
@@ -2190,8 +2315,8 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2190 new_smi->run_to_completion = 0; 2315 new_smi->run_to_completion = 0;
2191 2316
2192 new_smi->interrupt_disabled = 0; 2317 new_smi->interrupt_disabled = 0;
2193 new_smi->timer_stopped = 0; 2318 atomic_set(&new_smi->stop_operation, 0);
2194 new_smi->stop_operation = 0; 2319 new_smi->intf_num = intf_num;
2195 2320
2196 /* Start clearing the flags before we enable interrupts or the 2321 /* Start clearing the flags before we enable interrupts or the
2197 timer to avoid racing with the timer. */ 2322 timer to avoid racing with the timer. */
@@ -2209,7 +2334,11 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2209 new_smi->si_timer.function = smi_timeout; 2334 new_smi->si_timer.function = smi_timeout;
2210 new_smi->last_timeout_jiffies = jiffies; 2335 new_smi->last_timeout_jiffies = jiffies;
2211 new_smi->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES; 2336 new_smi->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES;
2337
2212 add_timer(&(new_smi->si_timer)); 2338 add_timer(&(new_smi->si_timer));
2339 if (new_smi->si_type != SI_BT)
2340 new_smi->thread = kthread_run(ipmi_thread, new_smi,
2341 "kipmi%d", new_smi->intf_num);
2213 2342
2214 rv = ipmi_register_smi(&handlers, 2343 rv = ipmi_register_smi(&handlers,
2215 new_smi, 2344 new_smi,
@@ -2251,12 +2380,8 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2251 return 0; 2380 return 0;
2252 2381
2253 out_err_stop_timer: 2382 out_err_stop_timer:
2254 new_smi->stop_operation = 1; 2383 atomic_inc(&new_smi->stop_operation);
2255 2384 wait_for_timer_and_thread(new_smi);
2256 /* Wait for the timer to stop. This avoids problems with race
2257 conditions removing the timer here. */
2258 while (!new_smi->timer_stopped)
2259 schedule_timeout_uninterruptible(1);
2260 2385
2261 out_err: 2386 out_err:
2262 if (new_smi->intf) 2387 if (new_smi->intf)
@@ -2362,8 +2487,7 @@ static void __exit cleanup_one_si(struct smi_info *to_clean)
2362 spin_lock_irqsave(&(to_clean->si_lock), flags); 2487 spin_lock_irqsave(&(to_clean->si_lock), flags);
2363 spin_lock(&(to_clean->msg_lock)); 2488 spin_lock(&(to_clean->msg_lock));
2364 2489
2365 to_clean->stop_operation = 1; 2490 atomic_inc(&to_clean->stop_operation);
2366
2367 to_clean->irq_cleanup(to_clean); 2491 to_clean->irq_cleanup(to_clean);
2368 2492
2369 spin_unlock(&(to_clean->msg_lock)); 2493 spin_unlock(&(to_clean->msg_lock));
@@ -2374,10 +2498,7 @@ static void __exit cleanup_one_si(struct smi_info *to_clean)
2374 interrupt. */ 2498 interrupt. */
2375 synchronize_sched(); 2499 synchronize_sched();
2376 2500
2377 /* Wait for the timer to stop. This avoids problems with race 2501 wait_for_timer_and_thread(to_clean);
2378 conditions removing the timer here. */
2379 while (!to_clean->timer_stopped)
2380 schedule_timeout_uninterruptible(1);
2381 2502
2382 /* Interrupts and timeouts are stopped, now make sure the 2503 /* Interrupts and timeouts are stopped, now make sure the
2383 interface is in a clean state. */ 2504 interface is in a clean state. */
diff --git a/drivers/char/ipmi/ipmi_si_sm.h b/drivers/char/ipmi/ipmi_si_sm.h
index 62791dd42985..bf3d4962d6a5 100644
--- a/drivers/char/ipmi/ipmi_si_sm.h
+++ b/drivers/char/ipmi/ipmi_si_sm.h
@@ -62,6 +62,7 @@ enum si_sm_result
62{ 62{
63 SI_SM_CALL_WITHOUT_DELAY, /* Call the driver again immediately */ 63 SI_SM_CALL_WITHOUT_DELAY, /* Call the driver again immediately */
64 SI_SM_CALL_WITH_DELAY, /* Delay some before calling again. */ 64 SI_SM_CALL_WITH_DELAY, /* Delay some before calling again. */
65 SI_SM_CALL_WITH_TICK_DELAY, /* Delay at least 1 tick before calling again. */
65 SI_SM_TRANSACTION_COMPLETE, /* A transaction is finished. */ 66 SI_SM_TRANSACTION_COMPLETE, /* A transaction is finished. */
66 SI_SM_IDLE, /* The SM is in idle state. */ 67 SI_SM_IDLE, /* The SM is in idle state. */
67 SI_SM_HOSED, /* The hardware violated the state machine. */ 68 SI_SM_HOSED, /* The hardware violated the state machine. */
diff --git a/drivers/char/ipmi/ipmi_smic_sm.c b/drivers/char/ipmi/ipmi_smic_sm.c
index add2aa2732f0..39d7e5ef1a2b 100644
--- a/drivers/char/ipmi/ipmi_smic_sm.c
+++ b/drivers/char/ipmi/ipmi_smic_sm.c
@@ -43,6 +43,8 @@
43 43
44#include <linux/kernel.h> /* For printk. */ 44#include <linux/kernel.h> /* For printk. */
45#include <linux/string.h> 45#include <linux/string.h>
46#include <linux/module.h>
47#include <linux/moduleparam.h>
46#include <linux/ipmi_msgdefs.h> /* for completion codes */ 48#include <linux/ipmi_msgdefs.h> /* for completion codes */
47#include "ipmi_si_sm.h" 49#include "ipmi_si_sm.h"
48 50
@@ -56,6 +58,8 @@
56#define SMIC_DEBUG_ENABLE 1 58#define SMIC_DEBUG_ENABLE 1
57 59
58static int smic_debug = 1; 60static int smic_debug = 1;
61module_param(smic_debug, int, 0644);
62MODULE_PARM_DESC(smic_debug, "debug bitmask, 1=enable, 2=messages, 4=states");
59 63
60enum smic_states { 64enum smic_states {
61 SMIC_IDLE, 65 SMIC_IDLE,
@@ -76,11 +80,17 @@ enum smic_states {
76#define SMIC_MAX_ERROR_RETRIES 3 80#define SMIC_MAX_ERROR_RETRIES 3
77 81
78/* Timeouts in microseconds. */ 82/* Timeouts in microseconds. */
79#define SMIC_RETRY_TIMEOUT 100000 83#define SMIC_RETRY_TIMEOUT 2000000
80 84
81/* SMIC Flags Register Bits */ 85/* SMIC Flags Register Bits */
82#define SMIC_RX_DATA_READY 0x80 86#define SMIC_RX_DATA_READY 0x80
83#define SMIC_TX_DATA_READY 0x40 87#define SMIC_TX_DATA_READY 0x40
88/*
89 * SMIC_SMI and SMIC_EVM_DATA_AVAIL are only used by
90 * a few systems, and then only by Systems Management
91 * Interrupts, not by the OS. Always ignore these bits.
92 *
93 */
84#define SMIC_SMI 0x10 94#define SMIC_SMI 0x10
85#define SMIC_EVM_DATA_AVAIL 0x08 95#define SMIC_EVM_DATA_AVAIL 0x08
86#define SMIC_SMS_DATA_AVAIL 0x04 96#define SMIC_SMS_DATA_AVAIL 0x04
@@ -364,8 +374,7 @@ static enum si_sm_result smic_event (struct si_sm_data *smic, long time)
364 switch (smic->state) { 374 switch (smic->state) {
365 case SMIC_IDLE: 375 case SMIC_IDLE:
366 /* in IDLE we check for available messages */ 376 /* in IDLE we check for available messages */
367 if (flags & (SMIC_SMI | 377 if (flags & SMIC_SMS_DATA_AVAIL)
368 SMIC_EVM_DATA_AVAIL | SMIC_SMS_DATA_AVAIL))
369 { 378 {
370 return SI_SM_ATTN; 379 return SI_SM_ATTN;
371 } 380 }
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 2da64bf7469c..1f3159eb1ede 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -47,6 +47,9 @@
47#include <linux/reboot.h> 47#include <linux/reboot.h>
48#include <linux/wait.h> 48#include <linux/wait.h>
49#include <linux/poll.h> 49#include <linux/poll.h>
50#include <linux/string.h>
51#include <linux/ctype.h>
52#include <asm/atomic.h>
50#ifdef CONFIG_X86_LOCAL_APIC 53#ifdef CONFIG_X86_LOCAL_APIC
51#include <asm/apic.h> 54#include <asm/apic.h>
52#endif 55#endif
@@ -158,27 +161,120 @@ static struct fasync_struct *fasync_q = NULL;
158static char pretimeout_since_last_heartbeat = 0; 161static char pretimeout_since_last_heartbeat = 0;
159static char expect_close; 162static char expect_close;
160 163
164static DECLARE_RWSEM(register_sem);
165
166/* Parameters to ipmi_set_timeout */
167#define IPMI_SET_TIMEOUT_NO_HB 0
168#define IPMI_SET_TIMEOUT_HB_IF_NECESSARY 1
169#define IPMI_SET_TIMEOUT_FORCE_HB 2
170
171static int ipmi_set_timeout(int do_heartbeat);
172
161/* If true, the driver will start running as soon as it is configured 173/* If true, the driver will start running as soon as it is configured
162 and ready. */ 174 and ready. */
163static int start_now = 0; 175static int start_now = 0;
164 176
165module_param(timeout, int, 0); 177static int set_param_int(const char *val, struct kernel_param *kp)
178{
179 char *endp;
180 int l;
181 int rv = 0;
182
183 if (!val)
184 return -EINVAL;
185 l = simple_strtoul(val, &endp, 0);
186 if (endp == val)
187 return -EINVAL;
188
189 down_read(&register_sem);
190 *((int *)kp->arg) = l;
191 if (watchdog_user)
192 rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY);
193 up_read(&register_sem);
194
195 return rv;
196}
197
198static int get_param_int(char *buffer, struct kernel_param *kp)
199{
200 return sprintf(buffer, "%i", *((int *)kp->arg));
201}
202
203typedef int (*action_fn)(const char *intval, char *outval);
204
205static int action_op(const char *inval, char *outval);
206static int preaction_op(const char *inval, char *outval);
207static int preop_op(const char *inval, char *outval);
208static void check_parms(void);
209
210static int set_param_str(const char *val, struct kernel_param *kp)
211{
212 action_fn fn = (action_fn) kp->arg;
213 int rv = 0;
214 const char *end;
215 char valcp[16];
216 int len;
217
218 /* Truncate leading and trailing spaces. */
219 while (isspace(*val))
220 val++;
221 end = val + strlen(val) - 1;
222 while ((end >= val) && isspace(*end))
223 end--;
224 len = end - val + 1;
225 if (len > sizeof(valcp) - 1)
226 return -EINVAL;
227 memcpy(valcp, val, len);
228 valcp[len] = '\0';
229
230 down_read(&register_sem);
231 rv = fn(valcp, NULL);
232 if (rv)
233 goto out_unlock;
234
235 check_parms();
236 if (watchdog_user)
237 rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY);
238
239 out_unlock:
240 up_read(&register_sem);
241 return rv;
242}
243
244static int get_param_str(char *buffer, struct kernel_param *kp)
245{
246 action_fn fn = (action_fn) kp->arg;
247 int rv;
248
249 rv = fn(NULL, buffer);
250 if (rv)
251 return rv;
252 return strlen(buffer);
253}
254
255module_param_call(timeout, set_param_int, get_param_int, &timeout, 0644);
166MODULE_PARM_DESC(timeout, "Timeout value in seconds."); 256MODULE_PARM_DESC(timeout, "Timeout value in seconds.");
167module_param(pretimeout, int, 0); 257
258module_param_call(pretimeout, set_param_int, get_param_int, &pretimeout, 0644);
168MODULE_PARM_DESC(pretimeout, "Pretimeout value in seconds."); 259MODULE_PARM_DESC(pretimeout, "Pretimeout value in seconds.");
169module_param_string(action, action, sizeof(action), 0); 260
261module_param_call(action, set_param_str, get_param_str, action_op, 0644);
170MODULE_PARM_DESC(action, "Timeout action. One of: " 262MODULE_PARM_DESC(action, "Timeout action. One of: "
171 "reset, none, power_cycle, power_off."); 263 "reset, none, power_cycle, power_off.");
172module_param_string(preaction, preaction, sizeof(preaction), 0); 264
265module_param_call(preaction, set_param_str, get_param_str, preaction_op, 0644);
173MODULE_PARM_DESC(preaction, "Pretimeout action. One of: " 266MODULE_PARM_DESC(preaction, "Pretimeout action. One of: "
174 "pre_none, pre_smi, pre_nmi, pre_int."); 267 "pre_none, pre_smi, pre_nmi, pre_int.");
175module_param_string(preop, preop, sizeof(preop), 0); 268
269module_param_call(preop, set_param_str, get_param_str, preop_op, 0644);
176MODULE_PARM_DESC(preop, "Pretimeout driver operation. One of: " 270MODULE_PARM_DESC(preop, "Pretimeout driver operation. One of: "
177 "preop_none, preop_panic, preop_give_data."); 271 "preop_none, preop_panic, preop_give_data.");
272
178module_param(start_now, int, 0); 273module_param(start_now, int, 0);
179MODULE_PARM_DESC(start_now, "Set to 1 to start the watchdog as" 274MODULE_PARM_DESC(start_now, "Set to 1 to start the watchdog as"
180 "soon as the driver is loaded."); 275 "soon as the driver is loaded.");
181module_param(nowayout, int, 0); 276
277module_param(nowayout, int, 0644);
182MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 278MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
183 279
184/* Default state of the timer. */ 280/* Default state of the timer. */
@@ -200,6 +296,8 @@ static int ipmi_start_timer_on_heartbeat = 0;
200static unsigned char ipmi_version_major; 296static unsigned char ipmi_version_major;
201static unsigned char ipmi_version_minor; 297static unsigned char ipmi_version_minor;
202 298
299/* If a pretimeout occurs, this is used to allow only one panic to happen. */
300static atomic_t preop_panic_excl = ATOMIC_INIT(-1);
203 301
204static int ipmi_heartbeat(void); 302static int ipmi_heartbeat(void);
205static void panic_halt_ipmi_heartbeat(void); 303static void panic_halt_ipmi_heartbeat(void);
@@ -294,11 +392,6 @@ static int i_ipmi_set_timeout(struct ipmi_smi_msg *smi_msg,
294 return rv; 392 return rv;
295} 393}
296 394
297/* Parameters to ipmi_set_timeout */
298#define IPMI_SET_TIMEOUT_NO_HB 0
299#define IPMI_SET_TIMEOUT_HB_IF_NECESSARY 1
300#define IPMI_SET_TIMEOUT_FORCE_HB 2
301
302static int ipmi_set_timeout(int do_heartbeat) 395static int ipmi_set_timeout(int do_heartbeat)
303{ 396{
304 int send_heartbeat_now; 397 int send_heartbeat_now;
@@ -732,8 +825,6 @@ static struct miscdevice ipmi_wdog_miscdev = {
732 .fops = &ipmi_wdog_fops 825 .fops = &ipmi_wdog_fops
733}; 826};
734 827
735static DECLARE_RWSEM(register_sem);
736
737static void ipmi_wdog_msg_handler(struct ipmi_recv_msg *msg, 828static void ipmi_wdog_msg_handler(struct ipmi_recv_msg *msg,
738 void *handler_data) 829 void *handler_data)
739{ 830{
@@ -749,9 +840,10 @@ static void ipmi_wdog_msg_handler(struct ipmi_recv_msg *msg,
749static void ipmi_wdog_pretimeout_handler(void *handler_data) 840static void ipmi_wdog_pretimeout_handler(void *handler_data)
750{ 841{
751 if (preaction_val != WDOG_PRETIMEOUT_NONE) { 842 if (preaction_val != WDOG_PRETIMEOUT_NONE) {
752 if (preop_val == WDOG_PREOP_PANIC) 843 if (preop_val == WDOG_PREOP_PANIC) {
753 panic("Watchdog pre-timeout"); 844 if (atomic_inc_and_test(&preop_panic_excl))
754 else if (preop_val == WDOG_PREOP_GIVE_DATA) { 845 panic("Watchdog pre-timeout");
846 } else if (preop_val == WDOG_PREOP_GIVE_DATA) {
755 spin_lock(&ipmi_read_lock); 847 spin_lock(&ipmi_read_lock);
756 data_to_read = 1; 848 data_to_read = 1;
757 wake_up_interruptible(&read_q); 849 wake_up_interruptible(&read_q);
@@ -825,7 +917,8 @@ ipmi_nmi(void *dev_id, struct pt_regs *regs, int cpu, int handled)
825 an error and not work unless we re-enable 917 an error and not work unless we re-enable
826 the timer. So do so. */ 918 the timer. So do so. */
827 pretimeout_since_last_heartbeat = 1; 919 pretimeout_since_last_heartbeat = 1;
828 panic(PFX "pre-timeout"); 920 if (atomic_inc_and_test(&preop_panic_excl))
921 panic(PFX "pre-timeout");
829 } 922 }
830 923
831 return NOTIFY_DONE; 924 return NOTIFY_DONE;
@@ -839,6 +932,7 @@ static struct nmi_handler ipmi_nmi_handler =
839 .handler = ipmi_nmi, 932 .handler = ipmi_nmi,
840 .priority = 0, /* Call us last. */ 933 .priority = 0, /* Call us last. */
841}; 934};
935int nmi_handler_registered;
842#endif 936#endif
843 937
844static int wdog_reboot_handler(struct notifier_block *this, 938static int wdog_reboot_handler(struct notifier_block *this,
@@ -921,59 +1015,86 @@ static struct ipmi_smi_watcher smi_watcher =
921 .smi_gone = ipmi_smi_gone 1015 .smi_gone = ipmi_smi_gone
922}; 1016};
923 1017
924static int __init ipmi_wdog_init(void) 1018static int action_op(const char *inval, char *outval)
925{ 1019{
926 int rv; 1020 if (outval)
1021 strcpy(outval, action);
1022
1023 if (!inval)
1024 return 0;
927 1025
928 if (strcmp(action, "reset") == 0) { 1026 if (strcmp(inval, "reset") == 0)
929 action_val = WDOG_TIMEOUT_RESET; 1027 action_val = WDOG_TIMEOUT_RESET;
930 } else if (strcmp(action, "none") == 0) { 1028 else if (strcmp(inval, "none") == 0)
931 action_val = WDOG_TIMEOUT_NONE; 1029 action_val = WDOG_TIMEOUT_NONE;
932 } else if (strcmp(action, "power_cycle") == 0) { 1030 else if (strcmp(inval, "power_cycle") == 0)
933 action_val = WDOG_TIMEOUT_POWER_CYCLE; 1031 action_val = WDOG_TIMEOUT_POWER_CYCLE;
934 } else if (strcmp(action, "power_off") == 0) { 1032 else if (strcmp(inval, "power_off") == 0)
935 action_val = WDOG_TIMEOUT_POWER_DOWN; 1033 action_val = WDOG_TIMEOUT_POWER_DOWN;
936 } else { 1034 else
937 action_val = WDOG_TIMEOUT_RESET; 1035 return -EINVAL;
938 printk(KERN_INFO PFX "Unknown action '%s', defaulting to" 1036 strcpy(action, inval);
939 " reset\n", action); 1037 return 0;
940 } 1038}
1039
1040static int preaction_op(const char *inval, char *outval)
1041{
1042 if (outval)
1043 strcpy(outval, preaction);
941 1044
942 if (strcmp(preaction, "pre_none") == 0) { 1045 if (!inval)
1046 return 0;
1047
1048 if (strcmp(inval, "pre_none") == 0)
943 preaction_val = WDOG_PRETIMEOUT_NONE; 1049 preaction_val = WDOG_PRETIMEOUT_NONE;
944 } else if (strcmp(preaction, "pre_smi") == 0) { 1050 else if (strcmp(inval, "pre_smi") == 0)
945 preaction_val = WDOG_PRETIMEOUT_SMI; 1051 preaction_val = WDOG_PRETIMEOUT_SMI;
946#ifdef HAVE_NMI_HANDLER 1052#ifdef HAVE_NMI_HANDLER
947 } else if (strcmp(preaction, "pre_nmi") == 0) { 1053 else if (strcmp(inval, "pre_nmi") == 0)
948 preaction_val = WDOG_PRETIMEOUT_NMI; 1054 preaction_val = WDOG_PRETIMEOUT_NMI;
949#endif 1055#endif
950 } else if (strcmp(preaction, "pre_int") == 0) { 1056 else if (strcmp(inval, "pre_int") == 0)
951 preaction_val = WDOG_PRETIMEOUT_MSG_INT; 1057 preaction_val = WDOG_PRETIMEOUT_MSG_INT;
952 } else { 1058 else
953 preaction_val = WDOG_PRETIMEOUT_NONE; 1059 return -EINVAL;
954 printk(KERN_INFO PFX "Unknown preaction '%s', defaulting to" 1060 strcpy(preaction, inval);
955 " none\n", preaction); 1061 return 0;
956 } 1062}
1063
1064static int preop_op(const char *inval, char *outval)
1065{
1066 if (outval)
1067 strcpy(outval, preop);
957 1068
958 if (strcmp(preop, "preop_none") == 0) { 1069 if (!inval)
1070 return 0;
1071
1072 if (strcmp(inval, "preop_none") == 0)
959 preop_val = WDOG_PREOP_NONE; 1073 preop_val = WDOG_PREOP_NONE;
960 } else if (strcmp(preop, "preop_panic") == 0) { 1074 else if (strcmp(inval, "preop_panic") == 0)
961 preop_val = WDOG_PREOP_PANIC; 1075 preop_val = WDOG_PREOP_PANIC;
962 } else if (strcmp(preop, "preop_give_data") == 0) { 1076 else if (strcmp(inval, "preop_give_data") == 0)
963 preop_val = WDOG_PREOP_GIVE_DATA; 1077 preop_val = WDOG_PREOP_GIVE_DATA;
964 } else { 1078 else
965 preop_val = WDOG_PREOP_NONE; 1079 return -EINVAL;
966 printk(KERN_INFO PFX "Unknown preop '%s', defaulting to" 1080 strcpy(preop, inval);
967 " none\n", preop); 1081 return 0;
968 } 1082}
969 1083
1084static void check_parms(void)
1085{
970#ifdef HAVE_NMI_HANDLER 1086#ifdef HAVE_NMI_HANDLER
1087 int do_nmi = 0;
1088 int rv;
1089
971 if (preaction_val == WDOG_PRETIMEOUT_NMI) { 1090 if (preaction_val == WDOG_PRETIMEOUT_NMI) {
1091 do_nmi = 1;
972 if (preop_val == WDOG_PREOP_GIVE_DATA) { 1092 if (preop_val == WDOG_PREOP_GIVE_DATA) {
973 printk(KERN_WARNING PFX "Pretimeout op is to give data" 1093 printk(KERN_WARNING PFX "Pretimeout op is to give data"
974 " but NMI pretimeout is enabled, setting" 1094 " but NMI pretimeout is enabled, setting"
975 " pretimeout op to none\n"); 1095 " pretimeout op to none\n");
976 preop_val = WDOG_PREOP_NONE; 1096 preop_op("preop_none", NULL);
1097 do_nmi = 0;
977 } 1098 }
978#ifdef CONFIG_X86_LOCAL_APIC 1099#ifdef CONFIG_X86_LOCAL_APIC
979 if (nmi_watchdog == NMI_IO_APIC) { 1100 if (nmi_watchdog == NMI_IO_APIC) {
@@ -983,18 +1104,48 @@ static int __init ipmi_wdog_init(void)
983 " Disabling IPMI nmi pretimeout.\n", 1104 " Disabling IPMI nmi pretimeout.\n",
984 nmi_watchdog); 1105 nmi_watchdog);
985 preaction_val = WDOG_PRETIMEOUT_NONE; 1106 preaction_val = WDOG_PRETIMEOUT_NONE;
986 } else { 1107 do_nmi = 0;
1108 }
987#endif 1109#endif
1110 }
1111 if (do_nmi && !nmi_handler_registered) {
988 rv = request_nmi(&ipmi_nmi_handler); 1112 rv = request_nmi(&ipmi_nmi_handler);
989 if (rv) { 1113 if (rv) {
990 printk(KERN_WARNING PFX "Can't register nmi handler\n"); 1114 printk(KERN_WARNING PFX
991 return rv; 1115 "Can't register nmi handler\n");
992 } 1116 return;
993#ifdef CONFIG_X86_LOCAL_APIC 1117 } else
994 } 1118 nmi_handler_registered = 1;
995#endif 1119 } else if (!do_nmi && nmi_handler_registered) {
1120 release_nmi(&ipmi_nmi_handler);
1121 nmi_handler_registered = 0;
996 } 1122 }
997#endif 1123#endif
1124}
1125
1126static int __init ipmi_wdog_init(void)
1127{
1128 int rv;
1129
1130 if (action_op(action, NULL)) {
1131 action_op("reset", NULL);
1132 printk(KERN_INFO PFX "Unknown action '%s', defaulting to"
1133 " reset\n", action);
1134 }
1135
1136 if (preaction_op(preaction, NULL)) {
1137 preaction_op("pre_none", NULL);
1138 printk(KERN_INFO PFX "Unknown preaction '%s', defaulting to"
1139 " none\n", preaction);
1140 }
1141
1142 if (preop_op(preop, NULL)) {
1143 preop_op("preop_none", NULL);
1144 printk(KERN_INFO PFX "Unknown preop '%s', defaulting to"
1145 " none\n", preop);
1146 }
1147
1148 check_parms();
998 1149
999 rv = ipmi_smi_watcher_register(&smi_watcher); 1150 rv = ipmi_smi_watcher_register(&smi_watcher);
1000 if (rv) { 1151 if (rv) {
@@ -1021,7 +1172,7 @@ static __exit void ipmi_unregister_watchdog(void)
1021 down_write(&register_sem); 1172 down_write(&register_sem);
1022 1173
1023#ifdef HAVE_NMI_HANDLER 1174#ifdef HAVE_NMI_HANDLER
1024 if (preaction_val == WDOG_PRETIMEOUT_NMI) 1175 if (nmi_handler_registered)
1025 release_nmi(&ipmi_nmi_handler); 1176 release_nmi(&ipmi_nmi_handler);
1026#endif 1177#endif
1027 1178
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index e3ddbdb85a2f..ce3bc0d45f1f 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -860,10 +860,9 @@ static void __exit istallion_module_exit(void)
860 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem"))) 860 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
861 printk("STALLION: failed to un-register serial memory device, " 861 printk("STALLION: failed to un-register serial memory device, "
862 "errno=%d\n", -i); 862 "errno=%d\n", -i);
863 if (stli_tmpwritebuf != (char *) NULL) 863
864 kfree(stli_tmpwritebuf); 864 kfree(stli_tmpwritebuf);
865 if (stli_txcookbuf != (char *) NULL) 865 kfree(stli_txcookbuf);
866 kfree(stli_txcookbuf);
867 866
868 for (i = 0; (i < stli_nrbrds); i++) { 867 for (i = 0; (i < stli_nrbrds); i++) {
869 if ((brdp = stli_brds[i]) == (stlibrd_t *) NULL) 868 if ((brdp = stli_brds[i]) == (stlibrd_t *) NULL)
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 45d012d85e8c..3b965a651da4 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -470,6 +470,8 @@ static struct tty_operations mxser_ops = {
470 .stop = mxser_stop, 470 .stop = mxser_stop,
471 .start = mxser_start, 471 .start = mxser_start,
472 .hangup = mxser_hangup, 472 .hangup = mxser_hangup,
473 .break_ctl = mxser_rs_break,
474 .wait_until_sent = mxser_wait_until_sent,
473 .tiocmget = mxser_tiocmget, 475 .tiocmget = mxser_tiocmget,
474 .tiocmset = mxser_tiocmset, 476 .tiocmset = mxser_tiocmset,
475}; 477};
@@ -492,14 +494,18 @@ static int __init mxser_module_init(void)
492 494
493static void __exit mxser_module_exit(void) 495static void __exit mxser_module_exit(void)
494{ 496{
495 int i, err = 0; 497 int i, err;
496 498
497 if (verbose) 499 if (verbose)
498 printk(KERN_DEBUG "Unloading module mxser ...\n"); 500 printk(KERN_DEBUG "Unloading module mxser ...\n");
499 501
500 if ((err |= tty_unregister_driver(mxvar_sdriver))) 502 err = tty_unregister_driver(mxvar_sdriver);
503 if (!err)
504 put_tty_driver(mxvar_sdriver);
505 else
501 printk(KERN_ERR "Couldn't unregister MOXA Smartio/Industio family serial driver\n"); 506 printk(KERN_ERR "Couldn't unregister MOXA Smartio/Industio family serial driver\n");
502 507
508
503 for (i = 0; i < MXSER_BOARDS; i++) { 509 for (i = 0; i < MXSER_BOARDS; i++) {
504 struct pci_dev *pdev; 510 struct pci_dev *pdev;
505 511
@@ -688,7 +694,6 @@ static int mxser_get_PCI_conf(int busnum, int devnum, int board_type, struct mxs
688static int mxser_init(void) 694static int mxser_init(void)
689{ 695{
690 int i, m, retval, b, n; 696 int i, m, retval, b, n;
691 int ret1;
692 struct pci_dev *pdev = NULL; 697 struct pci_dev *pdev = NULL;
693 int index; 698 int index;
694 unsigned char busnum, devnum; 699 unsigned char busnum, devnum;
@@ -722,24 +727,6 @@ static int mxser_init(void)
722 mxvar_sdriver->termios = mxvar_termios; 727 mxvar_sdriver->termios = mxvar_termios;
723 mxvar_sdriver->termios_locked = mxvar_termios_locked; 728 mxvar_sdriver->termios_locked = mxvar_termios_locked;
724 729
725 mxvar_sdriver->open = mxser_open;
726 mxvar_sdriver->close = mxser_close;
727 mxvar_sdriver->write = mxser_write;
728 mxvar_sdriver->put_char = mxser_put_char;
729 mxvar_sdriver->flush_chars = mxser_flush_chars;
730 mxvar_sdriver->write_room = mxser_write_room;
731 mxvar_sdriver->chars_in_buffer = mxser_chars_in_buffer;
732 mxvar_sdriver->flush_buffer = mxser_flush_buffer;
733 mxvar_sdriver->ioctl = mxser_ioctl;
734 mxvar_sdriver->throttle = mxser_throttle;
735 mxvar_sdriver->unthrottle = mxser_unthrottle;
736 mxvar_sdriver->set_termios = mxser_set_termios;
737 mxvar_sdriver->stop = mxser_stop;
738 mxvar_sdriver->start = mxser_start;
739 mxvar_sdriver->hangup = mxser_hangup;
740 mxvar_sdriver->break_ctl = mxser_rs_break;
741 mxvar_sdriver->wait_until_sent = mxser_wait_until_sent;
742
743 mxvar_diagflag = 0; 730 mxvar_diagflag = 0;
744 memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct)); 731 memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
745 memset(&mxvar_log, 0, sizeof(struct mxser_log)); 732 memset(&mxvar_log, 0, sizeof(struct mxser_log));
@@ -870,14 +857,11 @@ static int mxser_init(void)
870 } 857 }
871#endif 858#endif
872 859
873 ret1 = 0; 860 retval = tty_register_driver(mxvar_sdriver);
874 if (!(ret1 = tty_register_driver(mxvar_sdriver))) { 861 if (retval) {
875 return 0;
876 } else
877 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family driver !\n"); 862 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family driver !\n");
863 put_tty_driver(mxvar_sdriver);
878 864
879
880 if (ret1) {
881 for (i = 0; i < MXSER_BOARDS; i++) { 865 for (i = 0; i < MXSER_BOARDS; i++) {
882 if (mxsercfg[i].board_type == -1) 866 if (mxsercfg[i].board_type == -1)
883 continue; 867 continue;
@@ -886,10 +870,10 @@ static int mxser_init(void)
886 //todo: release io, vector 870 //todo: release io, vector
887 } 871 }
888 } 872 }
889 return -1; 873 return retval;
890 } 874 }
891 875
892 return (0); 876 return 0;
893} 877}
894 878
895static void mxser_do_softint(void *private_) 879static void mxser_do_softint(void *private_)
@@ -933,6 +917,9 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
933 struct mxser_struct *info; 917 struct mxser_struct *info;
934 int retval, line; 918 int retval, line;
935 919
920 /* initialize driver_data in case something fails */
921 tty->driver_data = NULL;
922
936 line = tty->index; 923 line = tty->index;
937 if (line == MXSER_PORTS) 924 if (line == MXSER_PORTS)
938 return 0; 925 return 0;
@@ -995,7 +982,7 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
995 if (tty->index == MXSER_PORTS) 982 if (tty->index == MXSER_PORTS)
996 return; 983 return;
997 if (!info) 984 if (!info)
998 BUG(); 985 return;
999 986
1000 spin_lock_irqsave(&info->slock, flags); 987 spin_lock_irqsave(&info->slock, flags);
1001 988
diff --git a/drivers/char/n_hdlc.c b/drivers/char/n_hdlc.c
index 5079beda69b5..c3660d8781a4 100644
--- a/drivers/char/n_hdlc.c
+++ b/drivers/char/n_hdlc.c
@@ -264,8 +264,7 @@ static void n_hdlc_release(struct n_hdlc *n_hdlc)
264 } else 264 } else
265 break; 265 break;
266 } 266 }
267 if (n_hdlc->tbuf) 267 kfree(n_hdlc->tbuf);
268 kfree(n_hdlc->tbuf);
269 kfree(n_hdlc); 268 kfree(n_hdlc);
270 269
271} /* end of n_hdlc_release() */ 270} /* end of n_hdlc_release() */
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 02d7f046c10a..2c326ea53421 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -2994,8 +2994,7 @@ int rx_alloc_buffers(MGSLPC_INFO *info)
2994 2994
2995void rx_free_buffers(MGSLPC_INFO *info) 2995void rx_free_buffers(MGSLPC_INFO *info)
2996{ 2996{
2997 if (info->rx_buf) 2997 kfree(info->rx_buf);
2998 kfree(info->rx_buf);
2999 info->rx_buf = NULL; 2998 info->rx_buf = NULL;
3000} 2999}
3001 3000
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index 928b850cc679..d3bc731fbb27 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -2512,10 +2512,8 @@ static void rp_cleanup_module(void)
2512 "rocketport driver\n", -retval); 2512 "rocketport driver\n", -retval);
2513 put_tty_driver(rocket_driver); 2513 put_tty_driver(rocket_driver);
2514 2514
2515 for (i = 0; i < MAX_RP_PORTS; i++) { 2515 for (i = 0; i < MAX_RP_PORTS; i++)
2516 if (rp_table[i]) 2516 kfree(rp_table[i]);
2517 kfree(rp_table[i]);
2518 }
2519 2517
2520 for (i = 0; i < NUM_BOARDS; i++) { 2518 for (i = 0; i < NUM_BOARDS; i++) {
2521 if (rcktpt_io_addr[i] <= 0 || is_PCI[i]) 2519 if (rcktpt_io_addr[i] <= 0 || is_PCI[i])
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index 63fff7c1244a..a7f099fb7dfe 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -149,8 +149,22 @@ static void get_rtc_alm_time (struct rtc_time *alm_tm);
149#ifdef RTC_IRQ 149#ifdef RTC_IRQ
150static void rtc_dropped_irq(unsigned long data); 150static void rtc_dropped_irq(unsigned long data);
151 151
152static void set_rtc_irq_bit(unsigned char bit); 152static void set_rtc_irq_bit_locked(unsigned char bit);
153static void mask_rtc_irq_bit(unsigned char bit); 153static void mask_rtc_irq_bit_locked(unsigned char bit);
154
155static inline void set_rtc_irq_bit(unsigned char bit)
156{
157 spin_lock_irq(&rtc_lock);
158 set_rtc_irq_bit_locked(bit);
159 spin_unlock_irq(&rtc_lock);
160}
161
162static void mask_rtc_irq_bit(unsigned char bit)
163{
164 spin_lock_irq(&rtc_lock);
165 mask_rtc_irq_bit_locked(bit);
166 spin_unlock_irq(&rtc_lock);
167}
154#endif 168#endif
155 169
156static int rtc_proc_open(struct inode *inode, struct file *file); 170static int rtc_proc_open(struct inode *inode, struct file *file);
@@ -401,18 +415,19 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
401 } 415 }
402 case RTC_PIE_OFF: /* Mask periodic int. enab. bit */ 416 case RTC_PIE_OFF: /* Mask periodic int. enab. bit */
403 { 417 {
404 mask_rtc_irq_bit(RTC_PIE); 418 unsigned long flags; /* can be called from isr via rtc_control() */
419 spin_lock_irqsave (&rtc_lock, flags);
420 mask_rtc_irq_bit_locked(RTC_PIE);
405 if (rtc_status & RTC_TIMER_ON) { 421 if (rtc_status & RTC_TIMER_ON) {
406 spin_lock_irq (&rtc_lock);
407 rtc_status &= ~RTC_TIMER_ON; 422 rtc_status &= ~RTC_TIMER_ON;
408 del_timer(&rtc_irq_timer); 423 del_timer(&rtc_irq_timer);
409 spin_unlock_irq (&rtc_lock);
410 } 424 }
425 spin_unlock_irqrestore (&rtc_lock, flags);
411 return 0; 426 return 0;
412 } 427 }
413 case RTC_PIE_ON: /* Allow periodic ints */ 428 case RTC_PIE_ON: /* Allow periodic ints */
414 { 429 {
415 430 unsigned long flags; /* can be called from isr via rtc_control() */
416 /* 431 /*
417 * We don't really want Joe User enabling more 432 * We don't really want Joe User enabling more
418 * than 64Hz of interrupts on a multi-user machine. 433 * than 64Hz of interrupts on a multi-user machine.
@@ -421,14 +436,14 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
421 (!capable(CAP_SYS_RESOURCE))) 436 (!capable(CAP_SYS_RESOURCE)))
422 return -EACCES; 437 return -EACCES;
423 438
439 spin_lock_irqsave (&rtc_lock, flags);
424 if (!(rtc_status & RTC_TIMER_ON)) { 440 if (!(rtc_status & RTC_TIMER_ON)) {
425 spin_lock_irq (&rtc_lock);
426 rtc_irq_timer.expires = jiffies + HZ/rtc_freq + 2*HZ/100; 441 rtc_irq_timer.expires = jiffies + HZ/rtc_freq + 2*HZ/100;
427 add_timer(&rtc_irq_timer); 442 add_timer(&rtc_irq_timer);
428 rtc_status |= RTC_TIMER_ON; 443 rtc_status |= RTC_TIMER_ON;
429 spin_unlock_irq (&rtc_lock);
430 } 444 }
431 set_rtc_irq_bit(RTC_PIE); 445 set_rtc_irq_bit_locked(RTC_PIE);
446 spin_unlock_irqrestore (&rtc_lock, flags);
432 return 0; 447 return 0;
433 } 448 }
434 case RTC_UIE_OFF: /* Mask ints from RTC updates. */ 449 case RTC_UIE_OFF: /* Mask ints from RTC updates. */
@@ -609,6 +624,7 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
609 { 624 {
610 int tmp = 0; 625 int tmp = 0;
611 unsigned char val; 626 unsigned char val;
627 unsigned long flags; /* can be called from isr via rtc_control() */
612 628
613 /* 629 /*
614 * The max we can do is 8192Hz. 630 * The max we can do is 8192Hz.
@@ -631,9 +647,9 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
631 if (arg != (1<<tmp)) 647 if (arg != (1<<tmp))
632 return -EINVAL; 648 return -EINVAL;
633 649
634 spin_lock_irq(&rtc_lock); 650 spin_lock_irqsave(&rtc_lock, flags);
635 if (hpet_set_periodic_freq(arg)) { 651 if (hpet_set_periodic_freq(arg)) {
636 spin_unlock_irq(&rtc_lock); 652 spin_unlock_irqrestore(&rtc_lock, flags);
637 return 0; 653 return 0;
638 } 654 }
639 rtc_freq = arg; 655 rtc_freq = arg;
@@ -641,7 +657,7 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
641 val = CMOS_READ(RTC_FREQ_SELECT) & 0xf0; 657 val = CMOS_READ(RTC_FREQ_SELECT) & 0xf0;
642 val |= (16 - tmp); 658 val |= (16 - tmp);
643 CMOS_WRITE(val, RTC_FREQ_SELECT); 659 CMOS_WRITE(val, RTC_FREQ_SELECT);
644 spin_unlock_irq(&rtc_lock); 660 spin_unlock_irqrestore(&rtc_lock, flags);
645 return 0; 661 return 0;
646 } 662 }
647#endif 663#endif
@@ -844,12 +860,15 @@ int rtc_control(rtc_task_t *task, unsigned int cmd, unsigned long arg)
844#ifndef RTC_IRQ 860#ifndef RTC_IRQ
845 return -EIO; 861 return -EIO;
846#else 862#else
847 spin_lock_irq(&rtc_task_lock); 863 unsigned long flags;
864 if (cmd != RTC_PIE_ON && cmd != RTC_PIE_OFF && cmd != RTC_IRQP_SET)
865 return -EINVAL;
866 spin_lock_irqsave(&rtc_task_lock, flags);
848 if (rtc_callback != task) { 867 if (rtc_callback != task) {
849 spin_unlock_irq(&rtc_task_lock); 868 spin_unlock_irqrestore(&rtc_task_lock, flags);
850 return -ENXIO; 869 return -ENXIO;
851 } 870 }
852 spin_unlock_irq(&rtc_task_lock); 871 spin_unlock_irqrestore(&rtc_task_lock, flags);
853 return rtc_do_ioctl(cmd, arg, 1); 872 return rtc_do_ioctl(cmd, arg, 1);
854#endif 873#endif
855} 874}
@@ -1306,40 +1325,32 @@ static void get_rtc_alm_time(struct rtc_time *alm_tm)
1306 * meddles with the interrupt enable/disable bits. 1325 * meddles with the interrupt enable/disable bits.
1307 */ 1326 */
1308 1327
1309static void mask_rtc_irq_bit(unsigned char bit) 1328static void mask_rtc_irq_bit_locked(unsigned char bit)
1310{ 1329{
1311 unsigned char val; 1330 unsigned char val;
1312 1331
1313 spin_lock_irq(&rtc_lock); 1332 if (hpet_mask_rtc_irq_bit(bit))
1314 if (hpet_mask_rtc_irq_bit(bit)) {
1315 spin_unlock_irq(&rtc_lock);
1316 return; 1333 return;
1317 }
1318 val = CMOS_READ(RTC_CONTROL); 1334 val = CMOS_READ(RTC_CONTROL);
1319 val &= ~bit; 1335 val &= ~bit;
1320 CMOS_WRITE(val, RTC_CONTROL); 1336 CMOS_WRITE(val, RTC_CONTROL);
1321 CMOS_READ(RTC_INTR_FLAGS); 1337 CMOS_READ(RTC_INTR_FLAGS);
1322 1338
1323 rtc_irq_data = 0; 1339 rtc_irq_data = 0;
1324 spin_unlock_irq(&rtc_lock);
1325} 1340}
1326 1341
1327static void set_rtc_irq_bit(unsigned char bit) 1342static void set_rtc_irq_bit_locked(unsigned char bit)
1328{ 1343{
1329 unsigned char val; 1344 unsigned char val;
1330 1345
1331 spin_lock_irq(&rtc_lock); 1346 if (hpet_set_rtc_irq_bit(bit))
1332 if (hpet_set_rtc_irq_bit(bit)) {
1333 spin_unlock_irq(&rtc_lock);
1334 return; 1347 return;
1335 }
1336 val = CMOS_READ(RTC_CONTROL); 1348 val = CMOS_READ(RTC_CONTROL);
1337 val |= bit; 1349 val |= bit;
1338 CMOS_WRITE(val, RTC_CONTROL); 1350 CMOS_WRITE(val, RTC_CONTROL);
1339 CMOS_READ(RTC_INTR_FLAGS); 1351 CMOS_READ(RTC_INTR_FLAGS);
1340 1352
1341 rtc_irq_data = 0; 1353 rtc_irq_data = 0;
1342 spin_unlock_irq(&rtc_lock);
1343} 1354}
1344#endif 1355#endif
1345 1356
diff --git a/drivers/char/selection.c b/drivers/char/selection.c
index 16d630f58bb4..5b187c895c18 100644
--- a/drivers/char/selection.c
+++ b/drivers/char/selection.c
@@ -246,8 +246,7 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t
246 clear_selection(); 246 clear_selection();
247 return -ENOMEM; 247 return -ENOMEM;
248 } 248 }
249 if (sel_buffer) 249 kfree(sel_buffer);
250 kfree(sel_buffer);
251 sel_buffer = bp; 250 sel_buffer = bp;
252 251
253 obp = bp; 252 obp = bp;
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 1c686414e0a1..95af2a941595 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -785,8 +785,7 @@ static void __exit stallion_module_exit(void)
785 "errno=%d\n", -i); 785 "errno=%d\n", -i);
786 class_destroy(stallion_class); 786 class_destroy(stallion_class);
787 787
788 if (stl_tmpwritebuf != (char *) NULL) 788 kfree(stl_tmpwritebuf);
789 kfree(stl_tmpwritebuf);
790 789
791 for (i = 0; (i < stl_nrbrds); i++) { 790 for (i = 0; (i < stl_nrbrds); i++) {
792 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL) 791 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
@@ -804,8 +803,7 @@ static void __exit stallion_module_exit(void)
804 continue; 803 continue;
805 if (portp->tty != (struct tty_struct *) NULL) 804 if (portp->tty != (struct tty_struct *) NULL)
806 stl_hangup(portp->tty); 805 stl_hangup(portp->tty);
807 if (portp->tx.buf != (char *) NULL) 806 kfree(portp->tx.buf);
808 kfree(portp->tx.buf);
809 kfree(portp); 807 kfree(portp);
810 } 808 }
811 kfree(panelp); 809 kfree(panelp);
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 0133dc0e25d0..5d1ffa3bd4c3 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -4016,9 +4016,7 @@ static int mgsl_alloc_intermediate_rxbuffer_memory(struct mgsl_struct *info)
4016 */ 4016 */
4017static void mgsl_free_intermediate_rxbuffer_memory(struct mgsl_struct *info) 4017static void mgsl_free_intermediate_rxbuffer_memory(struct mgsl_struct *info)
4018{ 4018{
4019 if ( info->intermediate_rxbuffer ) 4019 kfree(info->intermediate_rxbuffer);
4020 kfree(info->intermediate_rxbuffer);
4021
4022 info->intermediate_rxbuffer = NULL; 4020 info->intermediate_rxbuffer = NULL;
4023 4021
4024} /* end of mgsl_free_intermediate_rxbuffer_memory() */ 4022} /* end of mgsl_free_intermediate_rxbuffer_memory() */
@@ -4072,10 +4070,8 @@ static void mgsl_free_intermediate_txbuffer_memory(struct mgsl_struct *info)
4072 int i; 4070 int i;
4073 4071
4074 for ( i=0; i<info->num_tx_holding_buffers; ++i ) { 4072 for ( i=0; i<info->num_tx_holding_buffers; ++i ) {
4075 if ( info->tx_holding_buffers[i].buffer ) { 4073 kfree(info->tx_holding_buffers[i].buffer);
4076 kfree(info->tx_holding_buffers[i].buffer); 4074 info->tx_holding_buffers[i].buffer = NULL;
4077 info->tx_holding_buffers[i].buffer=NULL;
4078 }
4079 } 4075 }
4080 4076
4081 info->get_tx_holding_index = 0; 4077 info->get_tx_holding_index = 0;
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index f185724448b1..7c063c5abc55 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -2788,10 +2788,8 @@ static void shutdown(SLMP_INFO * info)
2788 del_timer(&info->tx_timer); 2788 del_timer(&info->tx_timer);
2789 del_timer(&info->status_timer); 2789 del_timer(&info->status_timer);
2790 2790
2791 if (info->tx_buf) { 2791 kfree(info->tx_buf);
2792 kfree(info->tx_buf); 2792 info->tx_buf = NULL;
2793 info->tx_buf = NULL;
2794 }
2795 2793
2796 spin_lock_irqsave(&info->lock,flags); 2794 spin_lock_irqsave(&info->lock,flags);
2797 2795
@@ -3611,8 +3609,7 @@ int alloc_tmp_rx_buf(SLMP_INFO *info)
3611 3609
3612void free_tmp_rx_buf(SLMP_INFO *info) 3610void free_tmp_rx_buf(SLMP_INFO *info)
3613{ 3611{
3614 if (info->tmp_rx_buf) 3612 kfree(info->tmp_rx_buf);
3615 kfree(info->tmp_rx_buf);
3616 info->tmp_rx_buf = NULL; 3613 info->tmp_rx_buf = NULL;
3617} 3614}
3618 3615
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index 8d125c974a2d..680a8e331887 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -287,10 +287,6 @@ static int __init init_nsc(void)
287 int lo, hi; 287 int lo, hi;
288 int nscAddrBase = TPM_ADDR; 288 int nscAddrBase = TPM_ADDR;
289 289
290 driver_register(&nsc_drv);
291
292 /* select PM channel 1 */
293 tpm_write_index(nscAddrBase,NSC_LDN_INDEX, 0x12);
294 290
295 /* verify that it is a National part (SID) */ 291 /* verify that it is a National part (SID) */
296 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) { 292 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
@@ -300,6 +296,8 @@ static int __init init_nsc(void)
300 return -ENODEV; 296 return -ENODEV;
301 } 297 }
302 298
299 driver_register(&nsc_drv);
300
303 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI); 301 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
304 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO); 302 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
305 tpm_nsc.base = (hi<<8) | lo; 303 tpm_nsc.base = (hi<<8) | lo;
@@ -307,11 +305,11 @@ static int __init init_nsc(void)
307 /* enable the DPM module */ 305 /* enable the DPM module */
308 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01); 306 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
309 307
310 pdev = kmalloc(sizeof(struct platform_device), GFP_KERNEL); 308 pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
311 if ( !pdev ) 309 if (!pdev) {
312 return -ENOMEM; 310 rc = -ENOMEM;
313 311 goto err_unreg_drv;
314 memset(pdev, 0, sizeof(struct platform_device)); 312 }
315 313
316 pdev->name = "tpm_nscl0"; 314 pdev->name = "tpm_nscl0";
317 pdev->id = -1; 315 pdev->id = -1;
@@ -319,26 +317,16 @@ static int __init init_nsc(void)
319 pdev->dev.release = tpm_nsc_remove; 317 pdev->dev.release = tpm_nsc_remove;
320 pdev->dev.driver = &nsc_drv; 318 pdev->dev.driver = &nsc_drv;
321 319
322 if ((rc=platform_device_register(pdev)) < 0) { 320 if ((rc = platform_device_register(pdev)) < 0)
323 kfree(pdev); 321 goto err_free_dev;
324 pdev = NULL;
325 return rc;
326 }
327 322
328 if (request_region(tpm_nsc.base, 2, "tpm_nsc0") == NULL ) { 323 if (request_region(tpm_nsc.base, 2, "tpm_nsc0") == NULL ) {
329 platform_device_unregister(pdev); 324 rc = -EBUSY;
330 kfree(pdev); 325 goto err_unreg_dev;
331 pdev = NULL;
332 return -EBUSY;
333 } 326 }
334 327
335 if ((rc = tpm_register_hardware(&pdev->dev, &tpm_nsc)) < 0) { 328 if ((rc = tpm_register_hardware(&pdev->dev, &tpm_nsc)) < 0)
336 release_region(tpm_nsc.base, 2); 329 goto err_rel_reg;
337 platform_device_unregister(pdev);
338 kfree(pdev);
339 pdev = NULL;
340 return rc;
341 }
342 330
343 dev_dbg(&pdev->dev, "NSC TPM detected\n"); 331 dev_dbg(&pdev->dev, "NSC TPM detected\n");
344 dev_dbg(&pdev->dev, 332 dev_dbg(&pdev->dev,
@@ -374,6 +362,16 @@ static int __init init_nsc(void)
374 tpm_read_index(nscAddrBase, 0x27) & 0x1F); 362 tpm_read_index(nscAddrBase, 0x27) & 0x1F);
375 363
376 return 0; 364 return 0;
365
366err_rel_reg:
367 release_region(tpm_nsc.base, 2);
368err_unreg_dev:
369 platform_device_unregister(pdev);
370err_free_dev:
371 kfree(pdev);
372err_unreg_drv:
373 driver_unregister(&nsc_drv);
374 return rc;
377} 375}
378 376
379static void __exit cleanup_nsc(void) 377static void __exit cleanup_nsc(void)
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index c586bfa852ee..4b1eef51ec59 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -1416,14 +1416,11 @@ end_init:
1416 1416
1417 /* Release locally allocated memory ... nothing placed in slots */ 1417 /* Release locally allocated memory ... nothing placed in slots */
1418free_mem_out: 1418free_mem_out:
1419 if (o_tp) 1419 kfree(o_tp);
1420 kfree(o_tp);
1421 if (o_tty) 1420 if (o_tty)
1422 free_tty_struct(o_tty); 1421 free_tty_struct(o_tty);
1423 if (ltp) 1422 kfree(ltp);
1424 kfree(ltp); 1423 kfree(tp);
1425 if (tp)
1426 kfree(tp);
1427 free_tty_struct(tty); 1424 free_tty_struct(tty);
1428 1425
1429fail_no_mem: 1426fail_no_mem:
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index 003dda147cd0..24011e7c81ff 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -80,6 +80,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
80 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry))) 80 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
81 return -EFAULT; 81 return -EFAULT;
82 82
83 if (!capable(CAP_SYS_TTY_CONFIG))
84 perm = 0;
85
83 switch (cmd) { 86 switch (cmd) {
84 case KDGKBENT: 87 case KDGKBENT:
85 key_map = key_maps[s]; 88 key_map = key_maps[s];
@@ -193,7 +196,7 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
193 int ret; 196 int ret;
194 197
195 if (!capable(CAP_SYS_TTY_CONFIG)) 198 if (!capable(CAP_SYS_TTY_CONFIG))
196 return -EPERM; 199 perm = 0;
197 200
198 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL); 201 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
199 if (!kbs) { 202 if (!kbs) {
diff --git a/drivers/connector/Kconfig b/drivers/connector/Kconfig
index 0bc2059c1e08..e0bdc0db9640 100644
--- a/drivers/connector/Kconfig
+++ b/drivers/connector/Kconfig
@@ -10,4 +10,12 @@ config CONNECTOR
10 Connector support can also be built as a module. If so, the module 10 Connector support can also be built as a module. If so, the module
11 will be called cn.ko. 11 will be called cn.ko.
12 12
13config PROC_EVENTS
14 boolean "Report process events to userspace"
15 depends on CONNECTOR=y
16 default y
17 ---help---
18 Provide a connector that reports process events to userspace. Send
19 events such as fork, exec, id change (uid, gid, suid, etc), and exit.
20
13endmenu 21endmenu
diff --git a/drivers/connector/Makefile b/drivers/connector/Makefile
index 12ca79e8234d..1f255e46e916 100644
--- a/drivers/connector/Makefile
+++ b/drivers/connector/Makefile
@@ -1,3 +1,4 @@
1obj-$(CONFIG_CONNECTOR) += cn.o 1obj-$(CONFIG_CONNECTOR) += cn.o
2obj-$(CONFIG_PROC_EVENTS) += cn_proc.o
2 3
3cn-y += cn_queue.o connector.o 4cn-y += cn_queue.o connector.o
diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
new file mode 100644
index 000000000000..fcdf0fff13a6
--- /dev/null
+++ b/drivers/connector/cn_proc.c
@@ -0,0 +1,222 @@
1/*
2 * cn_proc.c - process events connector
3 *
4 * Copyright (C) Matt Helsley, IBM Corp. 2005
5 * Based on cn_fork.c by Guillaume Thouvenin <guillaume.thouvenin@bull.net>
6 * Original copyright notice follows:
7 * Copyright (C) 2005 BULL SA.
8 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <asm/atomic.h>
29
30#include <linux/cn_proc.h>
31
32#define CN_PROC_MSG_SIZE (sizeof(struct cn_msg) + sizeof(struct proc_event))
33
34static atomic_t proc_event_num_listeners = ATOMIC_INIT(0);
35static struct cb_id cn_proc_event_id = { CN_IDX_PROC, CN_VAL_PROC };
36
37/* proc_counts is used as the sequence number of the netlink message */
38static DEFINE_PER_CPU(__u32, proc_event_counts) = { 0 };
39
40static inline void get_seq(__u32 *ts, int *cpu)
41{
42 *ts = get_cpu_var(proc_event_counts)++;
43 *cpu = smp_processor_id();
44 put_cpu_var(proc_counts);
45}
46
47void proc_fork_connector(struct task_struct *task)
48{
49 struct cn_msg *msg;
50 struct proc_event *ev;
51 __u8 buffer[CN_PROC_MSG_SIZE];
52
53 if (atomic_read(&proc_event_num_listeners) < 1)
54 return;
55
56 msg = (struct cn_msg*)buffer;
57 ev = (struct proc_event*)msg->data;
58 get_seq(&msg->seq, &ev->cpu);
59 ev->what = PROC_EVENT_FORK;
60 ev->event_data.fork.parent_pid = task->real_parent->pid;
61 ev->event_data.fork.parent_tgid = task->real_parent->tgid;
62 ev->event_data.fork.child_pid = task->pid;
63 ev->event_data.fork.child_tgid = task->tgid;
64
65 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
66 msg->ack = 0; /* not used */
67 msg->len = sizeof(*ev);
68 /* If cn_netlink_send() failed, the data is not sent */
69 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
70}
71
72void proc_exec_connector(struct task_struct *task)
73{
74 struct cn_msg *msg;
75 struct proc_event *ev;
76 __u8 buffer[CN_PROC_MSG_SIZE];
77
78 if (atomic_read(&proc_event_num_listeners) < 1)
79 return;
80
81 msg = (struct cn_msg*)buffer;
82 ev = (struct proc_event*)msg->data;
83 get_seq(&msg->seq, &ev->cpu);
84 ev->what = PROC_EVENT_EXEC;
85 ev->event_data.exec.process_pid = task->pid;
86 ev->event_data.exec.process_tgid = task->tgid;
87
88 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
89 msg->ack = 0; /* not used */
90 msg->len = sizeof(*ev);
91 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
92}
93
94void proc_id_connector(struct task_struct *task, int which_id)
95{
96 struct cn_msg *msg;
97 struct proc_event *ev;
98 __u8 buffer[CN_PROC_MSG_SIZE];
99
100 if (atomic_read(&proc_event_num_listeners) < 1)
101 return;
102
103 msg = (struct cn_msg*)buffer;
104 ev = (struct proc_event*)msg->data;
105 ev->what = which_id;
106 ev->event_data.id.process_pid = task->pid;
107 ev->event_data.id.process_tgid = task->tgid;
108 if (which_id == PROC_EVENT_UID) {
109 ev->event_data.id.r.ruid = task->uid;
110 ev->event_data.id.e.euid = task->euid;
111 } else if (which_id == PROC_EVENT_GID) {
112 ev->event_data.id.r.rgid = task->gid;
113 ev->event_data.id.e.egid = task->egid;
114 } else
115 return;
116 get_seq(&msg->seq, &ev->cpu);
117
118 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
119 msg->ack = 0; /* not used */
120 msg->len = sizeof(*ev);
121 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
122}
123
124void proc_exit_connector(struct task_struct *task)
125{
126 struct cn_msg *msg;
127 struct proc_event *ev;
128 __u8 buffer[CN_PROC_MSG_SIZE];
129
130 if (atomic_read(&proc_event_num_listeners) < 1)
131 return;
132
133 msg = (struct cn_msg*)buffer;
134 ev = (struct proc_event*)msg->data;
135 get_seq(&msg->seq, &ev->cpu);
136 ev->what = PROC_EVENT_EXIT;
137 ev->event_data.exit.process_pid = task->pid;
138 ev->event_data.exit.process_tgid = task->tgid;
139 ev->event_data.exit.exit_code = task->exit_code;
140 ev->event_data.exit.exit_signal = task->exit_signal;
141
142 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
143 msg->ack = 0; /* not used */
144 msg->len = sizeof(*ev);
145 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
146}
147
148/*
149 * Send an acknowledgement message to userspace
150 *
151 * Use 0 for success, EFOO otherwise.
152 * Note: this is the negative of conventional kernel error
153 * values because it's not being returned via syscall return
154 * mechanisms.
155 */
156static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
157{
158 struct cn_msg *msg;
159 struct proc_event *ev;
160 __u8 buffer[CN_PROC_MSG_SIZE];
161
162 if (atomic_read(&proc_event_num_listeners) < 1)
163 return;
164
165 msg = (struct cn_msg*)buffer;
166 ev = (struct proc_event*)msg->data;
167 msg->seq = rcvd_seq;
168 ev->cpu = -1;
169 ev->what = PROC_EVENT_NONE;
170 ev->event_data.ack.err = err;
171 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
172 msg->ack = rcvd_ack + 1;
173 msg->len = sizeof(*ev);
174 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
175}
176
177/**
178 * cn_proc_mcast_ctl
179 * @data: message sent from userspace via the connector
180 */
181static void cn_proc_mcast_ctl(void *data)
182{
183 struct cn_msg *msg = data;
184 enum proc_cn_mcast_op *mc_op = NULL;
185 int err = 0;
186
187 if (msg->len != sizeof(*mc_op))
188 return;
189
190 mc_op = (enum proc_cn_mcast_op*)msg->data;
191 switch (*mc_op) {
192 case PROC_CN_MCAST_LISTEN:
193 atomic_inc(&proc_event_num_listeners);
194 break;
195 case PROC_CN_MCAST_IGNORE:
196 atomic_dec(&proc_event_num_listeners);
197 break;
198 default:
199 err = EINVAL;
200 break;
201 }
202 cn_proc_ack(err, msg->seq, msg->ack);
203}
204
205/*
206 * cn_proc_init - initialization entry point
207 *
208 * Adds the connector callback to the connector driver.
209 */
210static int __init cn_proc_init(void)
211{
212 int err;
213
214 if ((err = cn_add_callback(&cn_proc_event_id, "cn_proc",
215 &cn_proc_mcast_ctl))) {
216 printk(KERN_WARNING "cn_proc failed to register\n");
217 return err;
218 }
219 return 0;
220}
221
222module_init(cn_proc_init);
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 6c6121b85a54..25acf478c9e8 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -593,12 +593,11 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
593 goto module_out; 593 goto module_out;
594 } 594 }
595 595
596 policy = kmalloc(sizeof(struct cpufreq_policy), GFP_KERNEL); 596 policy = kzalloc(sizeof(struct cpufreq_policy), GFP_KERNEL);
597 if (!policy) { 597 if (!policy) {
598 ret = -ENOMEM; 598 ret = -ENOMEM;
599 goto nomem_out; 599 goto nomem_out;
600 } 600 }
601 memset(policy, 0, sizeof(struct cpufreq_policy));
602 601
603 policy->cpu = cpu; 602 policy->cpu = cpu;
604 policy->cpus = cpumask_of_cpu(cpu); 603 policy->cpus = cpumask_of_cpu(cpu);
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index c1fc9c62bb51..17741111246b 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -48,7 +48,10 @@
48 * All times here are in uS. 48 * All times here are in uS.
49 */ 49 */
50static unsigned int def_sampling_rate; 50static unsigned int def_sampling_rate;
51#define MIN_SAMPLING_RATE (def_sampling_rate / 2) 51#define MIN_SAMPLING_RATE_RATIO (2)
52/* for correct statistics, we need at least 10 ticks between each measure */
53#define MIN_STAT_SAMPLING_RATE (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10))
54#define MIN_SAMPLING_RATE (def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
52#define MAX_SAMPLING_RATE (500 * def_sampling_rate) 55#define MAX_SAMPLING_RATE (500 * def_sampling_rate)
53#define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) 56#define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000)
54#define DEF_SAMPLING_DOWN_FACTOR (1) 57#define DEF_SAMPLING_DOWN_FACTOR (1)
@@ -416,13 +419,16 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
416 if (dbs_enable == 1) { 419 if (dbs_enable == 1) {
417 unsigned int latency; 420 unsigned int latency;
418 /* policy latency is in nS. Convert it to uS first */ 421 /* policy latency is in nS. Convert it to uS first */
422 latency = policy->cpuinfo.transition_latency / 1000;
423 if (latency == 0)
424 latency = 1;
419 425
420 latency = policy->cpuinfo.transition_latency; 426 def_sampling_rate = latency *
421 if (latency < 1000)
422 latency = 1000;
423
424 def_sampling_rate = (latency / 1000) *
425 DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; 427 DEF_SAMPLING_RATE_LATENCY_MULTIPLIER;
428
429 if (def_sampling_rate < MIN_STAT_SAMPLING_RATE)
430 def_sampling_rate = MIN_STAT_SAMPLING_RATE;
431
426 dbs_tuners_ins.sampling_rate = def_sampling_rate; 432 dbs_tuners_ins.sampling_rate = def_sampling_rate;
427 dbs_tuners_ins.ignore_nice = 0; 433 dbs_tuners_ins.ignore_nice = 0;
428 434
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 3597f25d5efa..0bddb8e694d9 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -193,11 +193,15 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
193 unsigned int cpu = policy->cpu; 193 unsigned int cpu = policy->cpu;
194 if (cpufreq_stats_table[cpu]) 194 if (cpufreq_stats_table[cpu])
195 return -EBUSY; 195 return -EBUSY;
196 if ((stat = kmalloc(sizeof(struct cpufreq_stats), GFP_KERNEL)) == NULL) 196 if ((stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL)) == NULL)
197 return -ENOMEM; 197 return -ENOMEM;
198 memset(stat, 0, sizeof (struct cpufreq_stats));
199 198
200 data = cpufreq_cpu_get(cpu); 199 data = cpufreq_cpu_get(cpu);
200 if (data == NULL) {
201 ret = -EINVAL;
202 goto error_get_fail;
203 }
204
201 if ((ret = sysfs_create_group(&data->kobj, &stats_attr_group))) 205 if ((ret = sysfs_create_group(&data->kobj, &stats_attr_group)))
202 goto error_out; 206 goto error_out;
203 207
@@ -217,12 +221,11 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
217 alloc_size += count * count * sizeof(int); 221 alloc_size += count * count * sizeof(int);
218#endif 222#endif
219 stat->max_state = count; 223 stat->max_state = count;
220 stat->time_in_state = kmalloc(alloc_size, GFP_KERNEL); 224 stat->time_in_state = kzalloc(alloc_size, GFP_KERNEL);
221 if (!stat->time_in_state) { 225 if (!stat->time_in_state) {
222 ret = -ENOMEM; 226 ret = -ENOMEM;
223 goto error_out; 227 goto error_out;
224 } 228 }
225 memset(stat->time_in_state, 0, alloc_size);
226 stat->freq_table = (unsigned int *)(stat->time_in_state + count); 229 stat->freq_table = (unsigned int *)(stat->time_in_state + count);
227 230
228#ifdef CONFIG_CPU_FREQ_STAT_DETAILS 231#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
@@ -245,6 +248,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
245 return 0; 248 return 0;
246error_out: 249error_out:
247 cpufreq_cpu_put(data); 250 cpufreq_cpu_put(data);
251error_get_fail:
248 kfree(stat); 252 kfree(stat);
249 cpufreq_stats_table[cpu] = NULL; 253 cpufreq_stats_table[cpu] = NULL;
250 return ret; 254 return ret;
diff --git a/drivers/dio/dio.c b/drivers/dio/dio.c
index a620f7d9ac8e..17502d6efae7 100644
--- a/drivers/dio/dio.c
+++ b/drivers/dio/dio.c
@@ -224,11 +224,10 @@ static int __init dio_init(void)
224 set_fs(fs); 224 set_fs(fs);
225 225
226 /* Found a board, allocate it an entry in the list */ 226 /* Found a board, allocate it an entry in the list */
227 dev = kmalloc(sizeof(struct dio_dev), GFP_KERNEL); 227 dev = kzalloc(sizeof(struct dio_dev), GFP_KERNEL);
228 if (!dev) 228 if (!dev)
229 return 0; 229 return 0;
230 230
231 memset(dev, 0, sizeof(struct dio_dev));
232 dev->bus = &dio_bus; 231 dev->bus = &dio_bus;
233 dev->dev.parent = &dio_bus.dev; 232 dev->dev.parent = &dio_bus.dev;
234 dev->dev.bus = &dio_bus_type; 233 dev->dev.bus = &dio_bus_type;
diff --git a/drivers/eisa/eisa-bus.c b/drivers/eisa/eisa-bus.c
index 1937743c8e29..4196137e66de 100644
--- a/drivers/eisa/eisa-bus.c
+++ b/drivers/eisa/eisa-bus.c
@@ -281,13 +281,11 @@ static int __init eisa_probe (struct eisa_root_device *root)
281 /* First try to get hold of slot 0. If there is no device 281 /* First try to get hold of slot 0. If there is no device
282 * here, simply fail, unless root->force_probe is set. */ 282 * here, simply fail, unless root->force_probe is set. */
283 283
284 if (!(edev = kmalloc (sizeof (*edev), GFP_KERNEL))) { 284 if (!(edev = kzalloc (sizeof (*edev), GFP_KERNEL))) {
285 printk (KERN_ERR "EISA: Couldn't allocate mainboard slot\n"); 285 printk (KERN_ERR "EISA: Couldn't allocate mainboard slot\n");
286 return -ENOMEM; 286 return -ENOMEM;
287 } 287 }
288 288
289 memset (edev, 0, sizeof (*edev));
290
291 if (eisa_request_resources (root, edev, 0)) { 289 if (eisa_request_resources (root, edev, 0)) {
292 printk (KERN_WARNING \ 290 printk (KERN_WARNING \
293 "EISA: Cannot allocate resource for mainboard\n"); 291 "EISA: Cannot allocate resource for mainboard\n");
@@ -317,13 +315,11 @@ static int __init eisa_probe (struct eisa_root_device *root)
317 force_probe: 315 force_probe:
318 316
319 for (c = 0, i = 1; i <= root->slots; i++) { 317 for (c = 0, i = 1; i <= root->slots; i++) {
320 if (!(edev = kmalloc (sizeof (*edev), GFP_KERNEL))) { 318 if (!(edev = kzalloc (sizeof (*edev), GFP_KERNEL))) {
321 printk (KERN_ERR "EISA: Out of memory for slot %d\n", 319 printk (KERN_ERR "EISA: Out of memory for slot %d\n",
322 i); 320 i);
323 continue; 321 continue;
324 } 322 }
325
326 memset (edev, 0, sizeof (*edev));
327 323
328 if (eisa_request_resources (root, edev, i)) { 324 if (eisa_request_resources (root, edev, i)) {
329 printk (KERN_WARNING \ 325 printk (KERN_WARNING \
diff --git a/drivers/fc4/fc.c b/drivers/fc4/fc.c
index e4710d1d1f9d..5c8943509cc1 100644
--- a/drivers/fc4/fc.c
+++ b/drivers/fc4/fc.c
@@ -266,13 +266,12 @@ static void fcp_report_map_done(fc_channel *fc, int i, int status)
266 printk ("FC: Bad magic from REPORT_AL_MAP on %s - %08x\n", fc->name, p->magic); 266 printk ("FC: Bad magic from REPORT_AL_MAP on %s - %08x\n", fc->name, p->magic);
267 fc->state = FC_STATE_OFFLINE; 267 fc->state = FC_STATE_OFFLINE;
268 } else { 268 } else {
269 fc->posmap = (fcp_posmap *)kmalloc(sizeof(fcp_posmap)+p->len, GFP_KERNEL); 269 fc->posmap = (fcp_posmap *)kzalloc(sizeof(fcp_posmap)+p->len, GFP_KERNEL);
270 if (!fc->posmap) { 270 if (!fc->posmap) {
271 printk("FC: Not enough memory, offlining channel\n"); 271 printk("FC: Not enough memory, offlining channel\n");
272 fc->state = FC_STATE_OFFLINE; 272 fc->state = FC_STATE_OFFLINE;
273 } else { 273 } else {
274 int k; 274 int k;
275 memset(fc->posmap, 0, sizeof(fcp_posmap)+p->len);
276 /* FIXME: This is where SOCAL transfers our AL-PA. 275 /* FIXME: This is where SOCAL transfers our AL-PA.
277 Keep it here till we found out what other cards do... */ 276 Keep it here till we found out what other cards do... */
278 fc->sid = (p->magic & 0xff); 277 fc->sid = (p->magic & 0xff);
@@ -351,14 +350,12 @@ void fcp_register(fc_channel *fc, u8 type, int unregister)
351 fc->dma_scsi_rsp = fc->dma_scsi_cmd + slots * sizeof (fcp_cmd); 350 fc->dma_scsi_rsp = fc->dma_scsi_cmd + slots * sizeof (fcp_cmd);
352 fc->scsi_bitmap_end = (slots + 63) & ~63; 351 fc->scsi_bitmap_end = (slots + 63) & ~63;
353 size = fc->scsi_bitmap_end / 8; 352 size = fc->scsi_bitmap_end / 8;
354 fc->scsi_bitmap = kmalloc (size, GFP_KERNEL); 353 fc->scsi_bitmap = kzalloc (size, GFP_KERNEL);
355 memset (fc->scsi_bitmap, 0, size);
356 set_bit (0, fc->scsi_bitmap); 354 set_bit (0, fc->scsi_bitmap);
357 for (i = fc->can_queue; i < fc->scsi_bitmap_end; i++) 355 for (i = fc->can_queue; i < fc->scsi_bitmap_end; i++)
358 set_bit (i, fc->scsi_bitmap); 356 set_bit (i, fc->scsi_bitmap);
359 fc->scsi_free = fc->can_queue; 357 fc->scsi_free = fc->can_queue;
360 fc->cmd_slots = (fcp_cmnd **)kmalloc(slots * sizeof(fcp_cmnd*), GFP_KERNEL); 358 fc->cmd_slots = (fcp_cmnd **)kzalloc(slots * sizeof(fcp_cmnd*), GFP_KERNEL);
361 memset(fc->cmd_slots, 0, slots * sizeof(fcp_cmnd*));
362 fc->abort_count = 0; 359 fc->abort_count = 0;
363 } else { 360 } else {
364 fc->scsi_name[0] = 0; 361 fc->scsi_name[0] = 0;
@@ -541,12 +538,11 @@ int fcp_initialize(fc_channel *fcchain, int count)
541 FCND(("fcp_inititialize %08lx\n", (long)fcp_init)) 538 FCND(("fcp_inititialize %08lx\n", (long)fcp_init))
542 FCND(("fc_channels %08lx\n", (long)fc_channels)) 539 FCND(("fc_channels %08lx\n", (long)fc_channels))
543 FCND((" SID %d DID %d\n", fcchain->sid, fcchain->did)) 540 FCND((" SID %d DID %d\n", fcchain->sid, fcchain->did))
544 l = kmalloc(sizeof (ls) + count, GFP_KERNEL); 541 l = kzalloc(sizeof (ls) + count, GFP_KERNEL);
545 if (!l) { 542 if (!l) {
546 printk ("FC: Cannot allocate memory for initialization\n"); 543 printk ("FC: Cannot allocate memory for initialization\n");
547 return -ENOMEM; 544 return -ENOMEM;
548 } 545 }
549 memset (l, 0, sizeof(ls) + count);
550 l->magic = LSMAGIC; 546 l->magic = LSMAGIC;
551 l->count = count; 547 l->count = count;
552 FCND(("FCP Init for %d channels\n", count)) 548 FCND(("FCP Init for %d channels\n", count))
@@ -555,17 +551,15 @@ int fcp_initialize(fc_channel *fcchain, int count)
555 l->timer.function = fcp_login_timeout; 551 l->timer.function = fcp_login_timeout;
556 l->timer.data = (unsigned long)l; 552 l->timer.data = (unsigned long)l;
557 atomic_set (&l->todo, count); 553 atomic_set (&l->todo, count);
558 l->logi = kmalloc (count * 3 * sizeof(logi), GFP_KERNEL); 554 l->logi = kzalloc (count * 3 * sizeof(logi), GFP_KERNEL);
559 l->fcmds = kmalloc (count * sizeof(fcp_cmnd), GFP_KERNEL); 555 l->fcmds = kzalloc (count * sizeof(fcp_cmnd), GFP_KERNEL);
560 if (!l->logi || !l->fcmds) { 556 if (!l->logi || !l->fcmds) {
561 if (l->logi) kfree (l->logi); 557 kfree (l->logi);
562 if (l->fcmds) kfree (l->fcmds); 558 kfree (l->fcmds);
563 kfree (l); 559 kfree (l);
564 printk ("FC: Cannot allocate DMA memory for initialization\n"); 560 printk ("FC: Cannot allocate DMA memory for initialization\n");
565 return -ENOMEM; 561 return -ENOMEM;
566 } 562 }
567 memset (l->logi, 0, count * 3 * sizeof(logi));
568 memset (l->fcmds, 0, count * sizeof(fcp_cmnd));
569 for (fc = fcchain, i = 0; fc && i < count; fc = fc->next, i++) { 563 for (fc = fcchain, i = 0; fc && i < count; fc = fc->next, i++) {
570 fc->state = FC_STATE_UNINITED; 564 fc->state = FC_STATE_UNINITED;
571 fc->rst_pkt = NULL; /* kmalloc when first used */ 565 fc->rst_pkt = NULL; /* kmalloc when first used */
@@ -678,13 +672,11 @@ int fcp_forceoffline(fc_channel *fcchain, int count)
678 l.timer.function = fcp_login_timeout; 672 l.timer.function = fcp_login_timeout;
679 l.timer.data = (unsigned long)&l; 673 l.timer.data = (unsigned long)&l;
680 atomic_set (&l.todo, count); 674 atomic_set (&l.todo, count);
681 l.fcmds = kmalloc (count * sizeof(fcp_cmnd), GFP_KERNEL); 675 l.fcmds = kzalloc (count * sizeof(fcp_cmnd), GFP_KERNEL);
682 if (!l.fcmds) { 676 if (!l.fcmds) {
683 kfree (l.fcmds);
684 printk ("FC: Cannot allocate memory for forcing offline\n"); 677 printk ("FC: Cannot allocate memory for forcing offline\n");
685 return -ENOMEM; 678 return -ENOMEM;
686 } 679 }
687 memset (l.fcmds, 0, count * sizeof(fcp_cmnd));
688 FCND(("Initializing OFFLINE packets\n")) 680 FCND(("Initializing OFFLINE packets\n"))
689 for (fc = fcchain, i = 0; fc && i < count; fc = fc->next, i++) { 681 for (fc = fcchain, i = 0; fc && i < count; fc = fc->next, i++) {
690 fc->state = FC_STATE_UNINITED; 682 fc->state = FC_STATE_UNINITED;
@@ -1114,9 +1106,8 @@ int fc_do_plogi(fc_channel *fc, unsigned char alpa, fc_wwn *node, fc_wwn *nport)
1114 logi *l; 1106 logi *l;
1115 int status; 1107 int status;
1116 1108
1117 l = (logi *)kmalloc(2 * sizeof(logi), GFP_KERNEL); 1109 l = (logi *)kzalloc(2 * sizeof(logi), GFP_KERNEL);
1118 if (!l) return -ENOMEM; 1110 if (!l) return -ENOMEM;
1119 memset(l, 0, 2 * sizeof(logi));
1120 l->code = LS_PLOGI; 1111 l->code = LS_PLOGI;
1121 memcpy (&l->nport_wwn, &fc->wwn_nport, sizeof(fc_wwn)); 1112 memcpy (&l->nport_wwn, &fc->wwn_nport, sizeof(fc_wwn));
1122 memcpy (&l->node_wwn, &fc->wwn_node, sizeof(fc_wwn)); 1113 memcpy (&l->node_wwn, &fc->wwn_node, sizeof(fc_wwn));
@@ -1149,9 +1140,8 @@ int fc_do_prli(fc_channel *fc, unsigned char alpa)
1149 prli *p; 1140 prli *p;
1150 int status; 1141 int status;
1151 1142
1152 p = (prli *)kmalloc(2 * sizeof(prli), GFP_KERNEL); 1143 p = (prli *)kzalloc(2 * sizeof(prli), GFP_KERNEL);
1153 if (!p) return -ENOMEM; 1144 if (!p) return -ENOMEM;
1154 memset(p, 0, 2 * sizeof(prli));
1155 p->code = LS_PRLI; 1145 p->code = LS_PRLI;
1156 p->params[0] = 0x08002000; 1146 p->params[0] = 0x08002000;
1157 p->params[3] = 0x00000022; 1147 p->params[3] = 0x00000022;
diff --git a/drivers/fc4/soc.c b/drivers/fc4/soc.c
index 247b46302777..ec1f94738c59 100644
--- a/drivers/fc4/soc.c
+++ b/drivers/fc4/soc.c
@@ -556,10 +556,9 @@ static inline void soc_init(struct sbus_dev *sdev, int no)
556 int size, i; 556 int size, i;
557 int irq; 557 int irq;
558 558
559 s = kmalloc (sizeof (struct soc), GFP_KERNEL); 559 s = kzalloc (sizeof (struct soc), GFP_KERNEL);
560 if (s == NULL) 560 if (s == NULL)
561 return; 561 return;
562 memset (s, 0, sizeof(struct soc));
563 spin_lock_init(&s->lock); 562 spin_lock_init(&s->lock);
564 s->soc_no = no; 563 s->soc_no = no;
565 564
diff --git a/drivers/fc4/socal.c b/drivers/fc4/socal.c
index b2377dbd84a1..922e9613b2cf 100644
--- a/drivers/fc4/socal.c
+++ b/drivers/fc4/socal.c
@@ -665,9 +665,8 @@ static inline void socal_init(struct sbus_dev *sdev, int no)
665 int size, i; 665 int size, i;
666 int irq, node; 666 int irq, node;
667 667
668 s = kmalloc (sizeof (struct socal), GFP_KERNEL); 668 s = kzalloc (sizeof (struct socal), GFP_KERNEL);
669 if (!s) return; 669 if (!s) return;
670 memset (s, 0, sizeof(struct socal));
671 spin_lock_init(&s->lock); 670 spin_lock_init(&s->lock);
672 s->socal_no = no; 671 s->socal_no = no;
673 672
diff --git a/drivers/firmware/dell_rbu.c b/drivers/firmware/dell_rbu.c
index 125929c9048f..ba17292eb290 100644
--- a/drivers/firmware/dell_rbu.c
+++ b/drivers/firmware/dell_rbu.c
@@ -50,7 +50,7 @@
50MODULE_AUTHOR("Abhay Salunke <abhay_salunke@dell.com>"); 50MODULE_AUTHOR("Abhay Salunke <abhay_salunke@dell.com>");
51MODULE_DESCRIPTION("Driver for updating BIOS image on DELL systems"); 51MODULE_DESCRIPTION("Driver for updating BIOS image on DELL systems");
52MODULE_LICENSE("GPL"); 52MODULE_LICENSE("GPL");
53MODULE_VERSION("3.0"); 53MODULE_VERSION("3.1");
54 54
55#define BIOS_SCAN_LIMIT 0xffffffff 55#define BIOS_SCAN_LIMIT 0xffffffff
56#define MAX_IMAGE_LENGTH 16 56#define MAX_IMAGE_LENGTH 16
@@ -73,6 +73,11 @@ module_param_string(image_type, image_type, sizeof (image_type), 0);
73MODULE_PARM_DESC(image_type, 73MODULE_PARM_DESC(image_type,
74 "BIOS image type. choose- mono or packet or init"); 74 "BIOS image type. choose- mono or packet or init");
75 75
76static unsigned long allocation_floor = 0x100000;
77module_param(allocation_floor, ulong, 0644);
78MODULE_PARM_DESC(allocation_floor,
79 "Minimum address for allocations when using Packet mode");
80
76struct packet_data { 81struct packet_data {
77 struct list_head list; 82 struct list_head list;
78 size_t length; 83 size_t length;
@@ -99,61 +104,122 @@ static int create_packet(void *data, size_t length)
99{ 104{
100 struct packet_data *newpacket; 105 struct packet_data *newpacket;
101 int ordernum = 0; 106 int ordernum = 0;
107 int retval = 0;
108 unsigned int packet_array_size = 0;
109 void **invalid_addr_packet_array = 0;
110 void *packet_data_temp_buf = 0;
111 unsigned int idx = 0;
102 112
103 pr_debug("create_packet: entry \n"); 113 pr_debug("create_packet: entry \n");
104 114
105 if (!rbu_data.packetsize) { 115 if (!rbu_data.packetsize) {
106 pr_debug("create_packet: packetsize not specified\n"); 116 pr_debug("create_packet: packetsize not specified\n");
107 return -EINVAL; 117 retval = -EINVAL;
118 goto out_noalloc;
108 } 119 }
120
109 spin_unlock(&rbu_data.lock); 121 spin_unlock(&rbu_data.lock);
110 newpacket = kmalloc(sizeof (struct packet_data), GFP_KERNEL); 122
111 spin_lock(&rbu_data.lock); 123 newpacket = kzalloc(sizeof (struct packet_data), GFP_KERNEL);
112 124
113 if (!newpacket) { 125 if (!newpacket) {
114 printk(KERN_WARNING 126 printk(KERN_WARNING
115 "dell_rbu:%s: failed to allocate new " 127 "dell_rbu:%s: failed to allocate new "
116 "packet\n", __FUNCTION__); 128 "packet\n", __FUNCTION__);
117 return -ENOMEM; 129 retval = -ENOMEM;
130 spin_lock(&rbu_data.lock);
131 goto out_noalloc;
118 } 132 }
119 133
120 ordernum = get_order(length); 134 ordernum = get_order(length);
135
121 /* 136 /*
122 * there is no upper limit on memory 137 * BIOS errata mean we cannot allocate packets below 1MB or they will
123 * address for packetized mechanism 138 * be overwritten by BIOS.
139 *
140 * array to temporarily hold packets
141 * that are below the allocation floor
142 *
143 * NOTE: very simplistic because we only need the floor to be at 1MB
144 * due to BIOS errata. This shouldn't be used for higher floors
145 * or you will run out of mem trying to allocate the array.
124 */ 146 */
125 spin_unlock(&rbu_data.lock); 147 packet_array_size = max(
126 newpacket->data = (unsigned char *) __get_free_pages(GFP_KERNEL, 148 (unsigned int)(allocation_floor / rbu_data.packetsize),
127 ordernum); 149 (unsigned int)1);
128 spin_lock(&rbu_data.lock); 150 invalid_addr_packet_array = kzalloc(packet_array_size * sizeof(void*),
151 GFP_KERNEL);
129 152
130 pr_debug("create_packet: newpacket %p\n", newpacket->data); 153 if (!invalid_addr_packet_array) {
131
132 if (!newpacket->data) {
133 printk(KERN_WARNING 154 printk(KERN_WARNING
134 "dell_rbu:%s: failed to allocate new " 155 "dell_rbu:%s: failed to allocate "
135 "packet\n", __FUNCTION__); 156 "invalid_addr_packet_array \n",
136 kfree(newpacket); 157 __FUNCTION__);
137 return -ENOMEM; 158 retval = -ENOMEM;
159 spin_lock(&rbu_data.lock);
160 goto out_alloc_packet;
138 } 161 }
139 162
163 while (!packet_data_temp_buf) {
164 packet_data_temp_buf = (unsigned char *)
165 __get_free_pages(GFP_KERNEL, ordernum);
166 if (!packet_data_temp_buf) {
167 printk(KERN_WARNING
168 "dell_rbu:%s: failed to allocate new "
169 "packet\n", __FUNCTION__);
170 retval = -ENOMEM;
171 spin_lock(&rbu_data.lock);
172 goto out_alloc_packet_array;
173 }
174
175 if ((unsigned long)virt_to_phys(packet_data_temp_buf)
176 < allocation_floor) {
177 pr_debug("packet 0x%lx below floor at 0x%lx.\n",
178 (unsigned long)virt_to_phys(
179 packet_data_temp_buf),
180 allocation_floor);
181 invalid_addr_packet_array[idx++] = packet_data_temp_buf;
182 packet_data_temp_buf = 0;
183 }
184 }
185 spin_lock(&rbu_data.lock);
186
187 newpacket->data = packet_data_temp_buf;
188
189 pr_debug("create_packet: newpacket at physical addr %lx\n",
190 (unsigned long)virt_to_phys(newpacket->data));
191
192 /* packets may not have fixed size */
193 newpacket->length = length;
140 newpacket->ordernum = ordernum; 194 newpacket->ordernum = ordernum;
141 ++rbu_data.num_packets; 195 ++rbu_data.num_packets;
142 /* 196
143 * initialize the newly created packet headers 197 /* initialize the newly created packet headers */
144 */
145 INIT_LIST_HEAD(&newpacket->list); 198 INIT_LIST_HEAD(&newpacket->list);
146 list_add_tail(&newpacket->list, &packet_data_head.list); 199 list_add_tail(&newpacket->list, &packet_data_head.list);
147 /*
148 * packets may not have fixed size
149 */
150 newpacket->length = length;
151 200
152 memcpy(newpacket->data, data, length); 201 memcpy(newpacket->data, data, length);
153 202
154 pr_debug("create_packet: exit \n"); 203 pr_debug("create_packet: exit \n");
155 204
156 return 0; 205out_alloc_packet_array:
206 /* always free packet array */
207 for (;idx>0;idx--) {
208 pr_debug("freeing unused packet below floor 0x%lx.\n",
209 (unsigned long)virt_to_phys(
210 invalid_addr_packet_array[idx-1]));
211 free_pages((unsigned long)invalid_addr_packet_array[idx-1],
212 ordernum);
213 }
214 kfree(invalid_addr_packet_array);
215
216out_alloc_packet:
217 /* if error, free data */
218 if (retval)
219 kfree(newpacket);
220
221out_noalloc:
222 return retval;
157} 223}
158 224
159static int packetize_data(void *data, size_t length) 225static int packetize_data(void *data, size_t length)
@@ -693,3 +759,6 @@ static __exit void dcdrbu_exit(void)
693 759
694module_exit(dcdrbu_exit); 760module_exit(dcdrbu_exit);
695module_init(dcdrbu_init); 761module_init(dcdrbu_init);
762
763/* vim:noet:ts=8:sw=8
764*/
diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index 6996476669f1..b4502ed65793 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -715,7 +715,6 @@ edd_device_register(struct edd_device *edev, int i)
715 715
716 if (!edev) 716 if (!edev)
717 return 1; 717 return 1;
718 memset(edev, 0, sizeof (*edev));
719 edd_dev_set_info(edev, i); 718 edd_dev_set_info(edev, i);
720 kobject_set_name(&edev->kobj, "int13_dev%02x", 719 kobject_set_name(&edev->kobj, "int13_dev%02x",
721 0x80 + i); 720 0x80 + i);
@@ -756,7 +755,7 @@ edd_init(void)
756 return rc; 755 return rc;
757 756
758 for (i = 0; i < edd_num_devices() && !rc; i++) { 757 for (i = 0; i < edd_num_devices() && !rc; i++) {
759 edev = kmalloc(sizeof (*edev), GFP_KERNEL); 758 edev = kzalloc(sizeof (*edev), GFP_KERNEL);
760 if (!edev) 759 if (!edev)
761 return -ENOMEM; 760 return -ENOMEM;
762 761
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 33b17c6a46fb..bda5bce681b6 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -614,16 +614,14 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
614 char *short_name; 614 char *short_name;
615 struct efivar_entry *new_efivar; 615 struct efivar_entry *new_efivar;
616 616
617 short_name = kmalloc(short_name_size + 1, GFP_KERNEL); 617 short_name = kzalloc(short_name_size + 1, GFP_KERNEL);
618 new_efivar = kmalloc(sizeof(struct efivar_entry), GFP_KERNEL); 618 new_efivar = kzalloc(sizeof(struct efivar_entry), GFP_KERNEL);
619 619
620 if (!short_name || !new_efivar) { 620 if (!short_name || !new_efivar) {
621 kfree(short_name); 621 kfree(short_name);
622 kfree(new_efivar); 622 kfree(new_efivar);
623 return 1; 623 return 1;
624 } 624 }
625 memset(short_name, 0, short_name_size+1);
626 memset(new_efivar, 0, sizeof(struct efivar_entry));
627 625
628 memcpy(new_efivar->var.VariableName, variable_name, 626 memcpy(new_efivar->var.VariableName, variable_name,
629 variable_name_size); 627 variable_name_size);
@@ -674,14 +672,12 @@ efivars_init(void)
674 if (!efi_enabled) 672 if (!efi_enabled)
675 return -ENODEV; 673 return -ENODEV;
676 674
677 variable_name = kmalloc(variable_name_size, GFP_KERNEL); 675 variable_name = kzalloc(variable_name_size, GFP_KERNEL);
678 if (!variable_name) { 676 if (!variable_name) {
679 printk(KERN_ERR "efivars: Memory allocation failed.\n"); 677 printk(KERN_ERR "efivars: Memory allocation failed.\n");
680 return -ENOMEM; 678 return -ENOMEM;
681 } 679 }
682 680
683 memset(variable_name, 0, variable_name_size);
684
685 printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION, 681 printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION,
686 EFIVARS_DATE); 682 EFIVARS_DATE);
687 683
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 6f48579799b5..dddd3eb9b387 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -16,6 +16,7 @@
16#include <linux/kdev_t.h> 16#include <linux/kdev_t.h>
17#include <linux/idr.h> 17#include <linux/idr.h>
18#include <linux/hwmon.h> 18#include <linux/hwmon.h>
19#include <linux/gfp.h>
19 20
20#define HWMON_ID_PREFIX "hwmon" 21#define HWMON_ID_PREFIX "hwmon"
21#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" 22#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index 6a82ffae1bfd..69e7e125683b 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -193,7 +193,7 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
193 int err = 0; 193 int err = 0;
194 const char *name = ""; 194 const char *name = "";
195 u8 reg_config=0, reg_convrate=0, reg_status=0; 195 u8 reg_config=0, reg_convrate=0, reg_status=0;
196 u8 man_id, chip_id; 196
197 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 197 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
198 goto exit; 198 goto exit;
199 199
@@ -238,16 +238,15 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
238 } 238 }
239 239
240 if (kind <= 0) { /* identification */ 240 if (kind <= 0) { /* identification */
241 u8 man_id, chip_id;
241 242
242 man_id = i2c_smbus_read_byte_data(new_client, 243 man_id = i2c_smbus_read_byte_data(new_client,
243 MAX1619_REG_R_MAN_ID); 244 MAX1619_REG_R_MAN_ID);
244 chip_id = i2c_smbus_read_byte_data(new_client, 245 chip_id = i2c_smbus_read_byte_data(new_client,
245 MAX1619_REG_R_CHIP_ID); 246 MAX1619_REG_R_CHIP_ID);
246 247
247 if ((man_id == 0x4D) && (chip_id == 0x04)){ 248 if ((man_id == 0x4D) && (chip_id == 0x04))
248 kind = max1619; 249 kind = max1619;
249 }
250 }
251 250
252 if (kind <= 0) { /* identification failed */ 251 if (kind <= 0) { /* identification failed */
253 dev_info(&adapter->dev, 252 dev_info(&adapter->dev,
@@ -255,11 +254,10 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
255 "chip_id=0x%02X).\n", man_id, chip_id); 254 "chip_id=0x%02X).\n", man_id, chip_id);
256 goto exit_free; 255 goto exit_free;
257 } 256 }
258 257 }
259 258
260 if (kind == max1619){ 259 if (kind == max1619)
261 name = "max1619"; 260 name = "max1619";
262 }
263 261
264 /* We can fill in the remaining client fields */ 262 /* We can fill in the remaining client fields */
265 strlcpy(new_client->name, name, I2C_NAME_SIZE); 263 strlcpy(new_client->name, name, I2C_NAME_SIZE);
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 9265f32122fa..ffdb3a03e2b5 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -976,11 +976,9 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
976ERROR_SC_3: 976ERROR_SC_3:
977 i2c_detach_client(data->lm75[0]); 977 i2c_detach_client(data->lm75[0]);
978ERROR_SC_2: 978ERROR_SC_2:
979 if (data->lm75[1]) 979 kfree(data->lm75[1]);
980 kfree(data->lm75[1]);
981ERROR_SC_1: 980ERROR_SC_1:
982 if (data->lm75[0]) 981 kfree(data->lm75[0]);
983 kfree(data->lm75[0]);
984ERROR_SC_0: 982ERROR_SC_0:
985 return err; 983 return err;
986} 984}
diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
index f51ab652300a..56c7d987590f 100644
--- a/drivers/i2c/busses/i2c-amd756-s4882.c
+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
@@ -245,10 +245,8 @@ static void __exit amd756_s4882_exit(void)
245 kfree(s4882_adapter); 245 kfree(s4882_adapter);
246 s4882_adapter = NULL; 246 s4882_adapter = NULL;
247 } 247 }
248 if (s4882_algo) { 248 kfree(s4882_algo);
249 kfree(s4882_algo); 249 s4882_algo = NULL;
250 s4882_algo = NULL;
251 }
252 250
253 /* Restore physical bus */ 251 /* Restore physical bus */
254 if (i2c_add_adapter(&amd756_smbus)) 252 if (i2c_add_adapter(&amd756_smbus))
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 8b9d85526596..c2f47923d174 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -3292,12 +3292,9 @@ static void ide_cd_release(struct kref *kref)
3292 ide_drive_t *drive = info->drive; 3292 ide_drive_t *drive = info->drive;
3293 struct gendisk *g = info->disk; 3293 struct gendisk *g = info->disk;
3294 3294
3295 if (info->buffer != NULL) 3295 kfree(info->buffer);
3296 kfree(info->buffer); 3296 kfree(info->toc);
3297 if (info->toc != NULL) 3297 kfree(info->changer_info);
3298 kfree(info->toc);
3299 if (info->changer_info != NULL)
3300 kfree(info->changer_info);
3301 if (devinfo->handle == drive && unregister_cdrom(devinfo)) 3298 if (devinfo->handle == drive && unregister_cdrom(devinfo))
3302 printk(KERN_ERR "%s: %s failed to unregister device from the cdrom " 3299 printk(KERN_ERR "%s: %s failed to unregister device from the cdrom "
3303 "driver.\n", __FUNCTION__, drive->name); 3300 "driver.\n", __FUNCTION__, drive->name);
@@ -3455,7 +3452,7 @@ static int ide_cd_probe(struct device *dev)
3455 printk(KERN_INFO "ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name); 3452 printk(KERN_INFO "ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name);
3456 goto failed; 3453 goto failed;
3457 } 3454 }
3458 info = kmalloc(sizeof(struct cdrom_info), GFP_KERNEL); 3455 info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL);
3459 if (info == NULL) { 3456 if (info == NULL) {
3460 printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", drive->name); 3457 printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", drive->name);
3461 goto failed; 3458 goto failed;
@@ -3469,8 +3466,6 @@ static int ide_cd_probe(struct device *dev)
3469 3466
3470 ide_register_subdriver(drive, &ide_cdrom_driver); 3467 ide_register_subdriver(drive, &ide_cdrom_driver);
3471 3468
3472 memset(info, 0, sizeof (struct cdrom_info));
3473
3474 kref_init(&info->kref); 3469 kref_init(&info->kref);
3475 3470
3476 info->drive = drive; 3471 info->drive = drive;
@@ -3489,12 +3484,9 @@ static int ide_cd_probe(struct device *dev)
3489 if (ide_cdrom_setup(drive)) { 3484 if (ide_cdrom_setup(drive)) {
3490 struct cdrom_device_info *devinfo = &info->devinfo; 3485 struct cdrom_device_info *devinfo = &info->devinfo;
3491 ide_unregister_subdriver(drive, &ide_cdrom_driver); 3486 ide_unregister_subdriver(drive, &ide_cdrom_driver);
3492 if (info->buffer != NULL) 3487 kfree(info->buffer);
3493 kfree(info->buffer); 3488 kfree(info->toc);
3494 if (info->toc != NULL) 3489 kfree(info->changer_info);
3495 kfree(info->toc);
3496 if (info->changer_info != NULL)
3497 kfree(info->changer_info);
3498 if (devinfo->handle == drive && unregister_cdrom(devinfo)) 3490 if (devinfo->handle == drive && unregister_cdrom(devinfo))
3499 printk (KERN_ERR "%s: ide_cdrom_cleanup failed to unregister device from the cdrom driver.\n", drive->name); 3491 printk (KERN_ERR "%s: ide_cdrom_cleanup failed to unregister device from the cdrom driver.\n", drive->name);
3500 kfree(info); 3492 kfree(info);
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 234f5de3e929..e827b39e4b3c 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -1215,7 +1215,7 @@ static int ide_disk_probe(struct device *dev)
1215 if (drive->media != ide_disk) 1215 if (drive->media != ide_disk)
1216 goto failed; 1216 goto failed;
1217 1217
1218 idkp = kmalloc(sizeof(*idkp), GFP_KERNEL); 1218 idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
1219 if (!idkp) 1219 if (!idkp)
1220 goto failed; 1220 goto failed;
1221 1221
@@ -1228,8 +1228,6 @@ static int ide_disk_probe(struct device *dev)
1228 1228
1229 ide_register_subdriver(drive, &idedisk_driver); 1229 ide_register_subdriver(drive, &idedisk_driver);
1230 1230
1231 memset(idkp, 0, sizeof(*idkp));
1232
1233 kref_init(&idkp->kref); 1231 kref_init(&idkp->kref);
1234 1232
1235 idkp->drive = drive; 1233 idkp->drive = drive;
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 29c22fc278c6..e83f54d37f96 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -2146,7 +2146,7 @@ static int ide_floppy_probe(struct device *dev)
2146 printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name); 2146 printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name);
2147 goto failed; 2147 goto failed;
2148 } 2148 }
2149 if ((floppy = (idefloppy_floppy_t *) kmalloc (sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) { 2149 if ((floppy = (idefloppy_floppy_t *) kzalloc (sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) {
2150 printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name); 2150 printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name);
2151 goto failed; 2151 goto failed;
2152 } 2152 }
@@ -2159,8 +2159,6 @@ static int ide_floppy_probe(struct device *dev)
2159 2159
2160 ide_register_subdriver(drive, &idefloppy_driver); 2160 ide_register_subdriver(drive, &idefloppy_driver);
2161 2161
2162 memset(floppy, 0, sizeof(*floppy));
2163
2164 kref_init(&floppy->kref); 2162 kref_init(&floppy->kref);
2165 2163
2166 floppy->drive = drive; 2164 floppy->drive = drive;
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index c1128ae5cd2f..02167a5b751d 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -596,14 +596,13 @@ static inline u8 probe_for_drive (ide_drive_t *drive)
596 * Also note that 0 everywhere means "can't do X" 596 * Also note that 0 everywhere means "can't do X"
597 */ 597 */
598 598
599 drive->id = kmalloc(SECTOR_WORDS *4, GFP_KERNEL); 599 drive->id = kzalloc(SECTOR_WORDS *4, GFP_KERNEL);
600 drive->id_read = 0; 600 drive->id_read = 0;
601 if(drive->id == NULL) 601 if(drive->id == NULL)
602 { 602 {
603 printk(KERN_ERR "ide: out of memory for id data.\n"); 603 printk(KERN_ERR "ide: out of memory for id data.\n");
604 return 0; 604 return 0;
605 } 605 }
606 memset(drive->id, 0, SECTOR_WORDS * 4);
607 strcpy(drive->id->model, "UNKNOWN"); 606 strcpy(drive->id->model, "UNKNOWN");
608 607
609 /* skip probing? */ 608 /* skip probing? */
@@ -1316,10 +1315,8 @@ static void drive_release_dev (struct device *dev)
1316 drive->devfs_name[0] = '\0'; 1315 drive->devfs_name[0] = '\0';
1317 } 1316 }
1318 ide_remove_drive_from_hwgroup(drive); 1317 ide_remove_drive_from_hwgroup(drive);
1319 if (drive->id != NULL) { 1318 kfree(drive->id);
1320 kfree(drive->id); 1319 drive->id = NULL;
1321 drive->id = NULL;
1322 }
1323 drive->present = 0; 1320 drive->present = 0;
1324 /* Messed up locking ... */ 1321 /* Messed up locking ... */
1325 spin_unlock_irq(&ide_lock); 1322 spin_unlock_irq(&ide_lock);
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 47f2b832555f..0ac7eb8f40d5 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -4850,7 +4850,7 @@ static int ide_tape_probe(struct device *dev)
4850 printk(KERN_WARNING "ide-tape: Use drive %s with ide-scsi emulation and osst.\n", drive->name); 4850 printk(KERN_WARNING "ide-tape: Use drive %s with ide-scsi emulation and osst.\n", drive->name);
4851 printk(KERN_WARNING "ide-tape: OnStream support will be removed soon from ide-tape!\n"); 4851 printk(KERN_WARNING "ide-tape: OnStream support will be removed soon from ide-tape!\n");
4852 } 4852 }
4853 tape = (idetape_tape_t *) kmalloc (sizeof (idetape_tape_t), GFP_KERNEL); 4853 tape = (idetape_tape_t *) kzalloc (sizeof (idetape_tape_t), GFP_KERNEL);
4854 if (tape == NULL) { 4854 if (tape == NULL) {
4855 printk(KERN_ERR "ide-tape: %s: Can't allocate a tape structure\n", drive->name); 4855 printk(KERN_ERR "ide-tape: %s: Can't allocate a tape structure\n", drive->name);
4856 goto failed; 4856 goto failed;
@@ -4864,8 +4864,6 @@ static int ide_tape_probe(struct device *dev)
4864 4864
4865 ide_register_subdriver(drive, &idetape_driver); 4865 ide_register_subdriver(drive, &idetape_driver);
4866 4866
4867 memset(tape, 0, sizeof(*tape));
4868
4869 kref_init(&tape->kref); 4867 kref_init(&tape->kref);
4870 4868
4871 tape->drive = drive; 4869 tape->drive = drive;
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index ace8edad6e96..7ec18fa3b5ff 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -528,9 +528,8 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
528 528
529// printk("IDE Taskfile ...\n"); 529// printk("IDE Taskfile ...\n");
530 530
531 req_task = kmalloc(tasksize, GFP_KERNEL); 531 req_task = kzalloc(tasksize, GFP_KERNEL);
532 if (req_task == NULL) return -ENOMEM; 532 if (req_task == NULL) return -ENOMEM;
533 memset(req_task, 0, tasksize);
534 if (copy_from_user(req_task, buf, tasksize)) { 533 if (copy_from_user(req_task, buf, tasksize)) {
535 kfree(req_task); 534 kfree(req_task);
536 return -EFAULT; 535 return -EFAULT;
@@ -541,12 +540,11 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
541 540
542 if (taskout) { 541 if (taskout) {
543 int outtotal = tasksize; 542 int outtotal = tasksize;
544 outbuf = kmalloc(taskout, GFP_KERNEL); 543 outbuf = kzalloc(taskout, GFP_KERNEL);
545 if (outbuf == NULL) { 544 if (outbuf == NULL) {
546 err = -ENOMEM; 545 err = -ENOMEM;
547 goto abort; 546 goto abort;
548 } 547 }
549 memset(outbuf, 0, taskout);
550 if (copy_from_user(outbuf, buf + outtotal, taskout)) { 548 if (copy_from_user(outbuf, buf + outtotal, taskout)) {
551 err = -EFAULT; 549 err = -EFAULT;
552 goto abort; 550 goto abort;
@@ -555,12 +553,11 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
555 553
556 if (taskin) { 554 if (taskin) {
557 int intotal = tasksize + taskout; 555 int intotal = tasksize + taskout;
558 inbuf = kmalloc(taskin, GFP_KERNEL); 556 inbuf = kzalloc(taskin, GFP_KERNEL);
559 if (inbuf == NULL) { 557 if (inbuf == NULL) {
560 err = -ENOMEM; 558 err = -ENOMEM;
561 goto abort; 559 goto abort;
562 } 560 }
563 memset(inbuf, 0, taskin);
564 if (copy_from_user(inbuf, buf + intotal, taskin)) { 561 if (copy_from_user(inbuf, buf + intotal, taskin)) {
565 err = -EFAULT; 562 err = -EFAULT;
566 goto abort; 563 goto abort;
@@ -649,10 +646,8 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
649 } 646 }
650abort: 647abort:
651 kfree(req_task); 648 kfree(req_task);
652 if (outbuf != NULL) 649 kfree(outbuf);
653 kfree(outbuf); 650 kfree(inbuf);
654 if (inbuf != NULL)
655 kfree(inbuf);
656 651
657// printk("IDE Taskfile ioctl ended. rc = %i\n", err); 652// printk("IDE Taskfile ioctl ended. rc = %i\n", err);
658 653
@@ -709,10 +704,9 @@ int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
709 704
710 if (args[3]) { 705 if (args[3]) {
711 argsize = 4 + (SECTOR_WORDS * 4 * args[3]); 706 argsize = 4 + (SECTOR_WORDS * 4 * args[3]);
712 argbuf = kmalloc(argsize, GFP_KERNEL); 707 argbuf = kzalloc(argsize, GFP_KERNEL);
713 if (argbuf == NULL) 708 if (argbuf == NULL)
714 return -ENOMEM; 709 return -ENOMEM;
715 memcpy(argbuf, args, 4);
716 } 710 }
717 if (set_transfer(drive, &tfargs)) { 711 if (set_transfer(drive, &tfargs)) {
718 xfer_rate = args[1]; 712 xfer_rate = args[1];
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 73ca8f73917d..9fe19808d815 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -864,9 +864,8 @@ static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int r
864 down(&ide_setting_sem); 864 down(&ide_setting_sem);
865 while ((*p) && strcmp((*p)->name, name) < 0) 865 while ((*p) && strcmp((*p)->name, name) < 0)
866 p = &((*p)->next); 866 p = &((*p)->next);
867 if ((setting = kmalloc(sizeof(*setting), GFP_KERNEL)) == NULL) 867 if ((setting = kzalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
868 goto abort; 868 goto abort;
869 memset(setting, 0, sizeof(*setting));
870 if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL) 869 if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
871 goto abort; 870 goto abort;
872 strcpy(setting->name, name); 871 strcpy(setting->name, name);
@@ -889,8 +888,7 @@ static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int r
889 return 0; 888 return 0;
890abort: 889abort:
891 up(&ide_setting_sem); 890 up(&ide_setting_sem);
892 if (setting) 891 kfree(setting);
893 kfree(setting);
894 return -1; 892 return -1;
895} 893}
896 894
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index a35a58bef1a4..1dafffa7e513 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -116,9 +116,8 @@ static dev_link_t *ide_attach(void)
116 DEBUG(0, "ide_attach()\n"); 116 DEBUG(0, "ide_attach()\n");
117 117
118 /* Create new ide device */ 118 /* Create new ide device */
119 info = kmalloc(sizeof(*info), GFP_KERNEL); 119 info = kzalloc(sizeof(*info), GFP_KERNEL);
120 if (!info) return NULL; 120 if (!info) return NULL;
121 memset(info, 0, sizeof(*info));
122 link = &info->link; link->priv = info; 121 link = &info->link; link->priv = info;
123 122
124 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 123 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
@@ -221,9 +220,8 @@ static void ide_config(dev_link_t *link)
221 220
222 DEBUG(0, "ide_config(0x%p)\n", link); 221 DEBUG(0, "ide_config(0x%p)\n", link);
223 222
224 stk = kmalloc(sizeof(*stk), GFP_KERNEL); 223 stk = kzalloc(sizeof(*stk), GFP_KERNEL);
225 if (!stk) goto err_mem; 224 if (!stk) goto err_mem;
226 memset(stk, 0, sizeof(*stk));
227 cfg = &stk->parse.cftable_entry; 225 cfg = &stk->parse.cftable_entry;
228 226
229 tuple.TupleData = (cisdata_t *)&stk->buf; 227 tuple.TupleData = (cisdata_t *)&stk->buf;
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 127619a109ed..7b589d948bf9 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -1516,7 +1516,7 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1516 1516
1517static void __devinit init_iops_hpt366(ide_hwif_t *hwif) 1517static void __devinit init_iops_hpt366(ide_hwif_t *hwif)
1518{ 1518{
1519 struct hpt_info *info = kmalloc(sizeof(struct hpt_info), GFP_KERNEL); 1519 struct hpt_info *info = kzalloc(sizeof(struct hpt_info), GFP_KERNEL);
1520 unsigned long dmabase = pci_resource_start(hwif->pci_dev, 4); 1520 unsigned long dmabase = pci_resource_start(hwif->pci_dev, 4);
1521 u8 did, rid; 1521 u8 did, rid;
1522 1522
@@ -1524,7 +1524,6 @@ static void __devinit init_iops_hpt366(ide_hwif_t *hwif)
1524 printk(KERN_WARNING "hpt366: out of memory.\n"); 1524 printk(KERN_WARNING "hpt366: out of memory.\n");
1525 return; 1525 return;
1526 } 1526 }
1527 memset(info, 0, sizeof(struct hpt_info));
1528 ide_set_hwifdata(hwif, info); 1527 ide_set_hwifdata(hwif, info);
1529 1528
1530 if(dmabase) { 1529 if(dmabase) {
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index e440036e651f..108fda83fea4 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -642,14 +642,13 @@ static void __devinit it821x_fixups(ide_hwif_t *hwif)
642 642
643static void __devinit init_hwif_it821x(ide_hwif_t *hwif) 643static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
644{ 644{
645 struct it821x_dev *idev = kmalloc(sizeof(struct it821x_dev), GFP_KERNEL); 645 struct it821x_dev *idev = kzalloc(sizeof(struct it821x_dev), GFP_KERNEL);
646 u8 conf; 646 u8 conf;
647 647
648 if(idev == NULL) { 648 if(idev == NULL) {
649 printk(KERN_ERR "it821x: out of memory, falling back to legacy behaviour.\n"); 649 printk(KERN_ERR "it821x: out of memory, falling back to legacy behaviour.\n");
650 goto fallback; 650 goto fallback;
651 } 651 }
652 memset(idev, 0, sizeof(struct it821x_dev));
653 ide_set_hwifdata(hwif, idev); 652 ide_set_hwifdata(hwif, idev);
654 653
655 pci_read_config_byte(hwif->pci_dev, 0x50, &conf); 654 pci_read_config_byte(hwif->pci_dev, 0x50, &conf);
diff --git a/drivers/ieee1394/amdtp.c b/drivers/ieee1394/amdtp.c
index e8e28569a668..75897509c401 100644
--- a/drivers/ieee1394/amdtp.c
+++ b/drivers/ieee1394/amdtp.c
@@ -320,8 +320,7 @@ static void ohci1394_stop_it_ctx(struct ti_ohci *ohci, int ctx, int synchronous)
320 if ((control & OHCI1394_CONTEXT_ACTIVE) == 0) 320 if ((control & OHCI1394_CONTEXT_ACTIVE) == 0)
321 break; 321 break;
322 322
323 set_current_state(TASK_INTERRUPTIBLE); 323 schedule_timeout_interruptible(1);
324 schedule_timeout(1);
325 } 324 }
326 } 325 }
327} 326}
diff --git a/drivers/infiniband/core/agent.c b/drivers/infiniband/core/agent.c
index 7545775d38ef..34b724afd28d 100644
--- a/drivers/infiniband/core/agent.c
+++ b/drivers/infiniband/core/agent.c
@@ -37,6 +37,9 @@
37 * $Id: agent.c 1389 2004-12-27 22:56:47Z roland $ 37 * $Id: agent.c 1389 2004-12-27 22:56:47Z roland $
38 */ 38 */
39 39
40#include <linux/slab.h>
41#include <linux/string.h>
42
40#include "agent.h" 43#include "agent.h"
41#include "smi.h" 44#include "smi.h"
42 45
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index 3d8175e5f054..41d6b4017acb 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -508,8 +508,7 @@ static void unregister_mad_agent(struct ib_mad_agent_private *mad_agent_priv)
508 wait_event(mad_agent_priv->wait, 508 wait_event(mad_agent_priv->wait,
509 !atomic_read(&mad_agent_priv->refcount)); 509 !atomic_read(&mad_agent_priv->refcount));
510 510
511 if (mad_agent_priv->reg_req) 511 kfree(mad_agent_priv->reg_req);
512 kfree(mad_agent_priv->reg_req);
513 ib_dereg_mr(mad_agent_priv->agent.mr); 512 ib_dereg_mr(mad_agent_priv->agent.mr);
514 kfree(mad_agent_priv); 513 kfree(mad_agent_priv);
515} 514}
@@ -2500,8 +2499,7 @@ error:
2500static void destroy_mad_qp(struct ib_mad_qp_info *qp_info) 2499static void destroy_mad_qp(struct ib_mad_qp_info *qp_info)
2501{ 2500{
2502 ib_destroy_qp(qp_info->qp); 2501 ib_destroy_qp(qp_info->qp);
2503 if (qp_info->snoop_table) 2502 kfree(qp_info->snoop_table);
2504 kfree(qp_info->snoop_table);
2505} 2503}
2506 2504
2507/* 2505/*
diff --git a/drivers/infiniband/core/packer.c b/drivers/infiniband/core/packer.c
index 35df5010e723..c972d7235764 100644
--- a/drivers/infiniband/core/packer.c
+++ b/drivers/infiniband/core/packer.c
@@ -33,6 +33,8 @@
33 * $Id: packer.c 1349 2004-12-16 21:09:43Z roland $ 33 * $Id: packer.c 1349 2004-12-16 21:09:43Z roland $
34 */ 34 */
35 35
36#include <linux/string.h>
37
36#include <rdma/ib_pack.h> 38#include <rdma/ib_pack.h>
37 39
38static u64 value_read(int offset, int size, void *structure) 40static u64 value_read(int offset, int size, void *structure)
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index b8120650e711..08648b1a387e 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -36,6 +36,9 @@
36 36
37#include "core_priv.h" 37#include "core_priv.h"
38 38
39#include <linux/slab.h>
40#include <linux/string.h>
41
39#include <rdma/ib_mad.h> 42#include <rdma/ib_mad.h>
40 43
41struct ib_port { 44struct ib_port {
diff --git a/drivers/infiniband/core/ud_header.c b/drivers/infiniband/core/ud_header.c
index 527b23450ab3..997c07db6d8f 100644
--- a/drivers/infiniband/core/ud_header.c
+++ b/drivers/infiniband/core/ud_header.c
@@ -34,6 +34,7 @@
34 */ 34 */
35 35
36#include <linux/errno.h> 36#include <linux/errno.h>
37#include <linux/string.h>
37 38
38#include <rdma/ib_pack.h> 39#include <rdma/ib_pack.h>
39 40
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 72d3ef786db5..4186cc888ea5 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -40,6 +40,7 @@
40 40
41#include <linux/errno.h> 41#include <linux/errno.h>
42#include <linux/err.h> 42#include <linux/err.h>
43#include <linux/string.h>
43 44
44#include <rdma/ib_verbs.h> 45#include <rdma/ib_verbs.h>
45#include <rdma/ib_cache.h> 46#include <rdma/ib_cache.h>
diff --git a/drivers/infiniband/hw/mthca/mthca_catas.c b/drivers/infiniband/hw/mthca/mthca_catas.c
index 7ac52af43b99..25ebab64bc42 100644
--- a/drivers/infiniband/hw/mthca/mthca_catas.c
+++ b/drivers/infiniband/hw/mthca/mthca_catas.c
@@ -32,6 +32,9 @@
32 * $Id$ 32 * $Id$
33 */ 33 */
34 34
35#include <linux/jiffies.h>
36#include <linux/timer.h>
37
35#include "mthca_dev.h" 38#include "mthca_dev.h"
36 39
37enum { 40enum {
diff --git a/drivers/infiniband/hw/mthca/mthca_srq.c b/drivers/infiniband/hw/mthca/mthca_srq.c
index 292f55be8cbd..26d5161fde07 100644
--- a/drivers/infiniband/hw/mthca/mthca_srq.c
+++ b/drivers/infiniband/hw/mthca/mthca_srq.c
@@ -32,6 +32,9 @@
32 * $Id: mthca_srq.c 3047 2005-08-10 03:59:35Z roland $ 32 * $Id: mthca_srq.c 3047 2005-08-10 03:59:35Z roland $
33 */ 33 */
34 34
35#include <linux/slab.h>
36#include <linux/string.h>
37
35#include "mthca_dev.h" 38#include "mthca_dev.h"
36#include "mthca_cmd.h" 39#include "mthca_cmd.h"
37#include "mthca_memfree.h" 40#include "mthca_memfree.h"
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 1a1654caedd5..0879915b14d5 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -377,7 +377,7 @@ static int input_devices_read(char *buf, char **start, off_t pos, int count, int
377 377
378 list_for_each_entry(dev, &input_dev_list, node) { 378 list_for_each_entry(dev, &input_dev_list, node) {
379 379
380 path = dev->dynalloc ? kobject_get_path(&dev->cdev.kobj, GFP_KERNEL) : NULL; 380 path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
381 381
382 len = sprintf(buf, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n", 382 len = sprintf(buf, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
383 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); 383 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
@@ -741,15 +741,21 @@ static void input_register_classdevice(struct input_dev *dev)
741 sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group); 741 sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
742} 742}
743 743
744void input_register_device(struct input_dev *dev) 744int input_register_device(struct input_dev *dev)
745{ 745{
746 struct input_handle *handle; 746 struct input_handle *handle;
747 struct input_handler *handler; 747 struct input_handler *handler;
748 struct input_device_id *id; 748 struct input_device_id *id;
749 749
750 set_bit(EV_SYN, dev->evbit); 750 if (!dev->dynalloc) {
751 printk(KERN_WARNING "input: device %s is statically allocated, will not register\n"
752 "Please convert to input_allocate_device() or contact dtor_core@ameritech.net\n",
753 dev->name ? dev->name : "<Unknown>");
754 return -EINVAL;
755 }
751 756
752 init_MUTEX(&dev->sem); 757 init_MUTEX(&dev->sem);
758 set_bit(EV_SYN, dev->evbit);
753 759
754 /* 760 /*
755 * If delay and period are pre-set by the driver, then autorepeating 761 * If delay and period are pre-set by the driver, then autorepeating
@@ -767,8 +773,7 @@ void input_register_device(struct input_dev *dev)
767 INIT_LIST_HEAD(&dev->h_list); 773 INIT_LIST_HEAD(&dev->h_list);
768 list_add_tail(&dev->node, &input_dev_list); 774 list_add_tail(&dev->node, &input_dev_list);
769 775
770 if (dev->dynalloc) 776 input_register_classdevice(dev);
771 input_register_classdevice(dev);
772 777
773 list_for_each_entry(handler, &input_handler_list, node) 778 list_for_each_entry(handler, &input_handler_list, node)
774 if (!handler->blacklist || !input_match_device(handler->blacklist, dev)) 779 if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
@@ -776,8 +781,9 @@ void input_register_device(struct input_dev *dev)
776 if ((handle = handler->connect(handler, dev, id))) 781 if ((handle = handler->connect(handler, dev, id)))
777 input_link_handle(handle); 782 input_link_handle(handle);
778 783
779
780 input_wakeup_procfs_readers(); 784 input_wakeup_procfs_readers();
785
786 return 0;
781} 787}
782 788
783void input_unregister_device(struct input_dev *dev) 789void input_unregister_device(struct input_dev *dev)
@@ -797,11 +803,10 @@ void input_unregister_device(struct input_dev *dev)
797 803
798 list_del_init(&dev->node); 804 list_del_init(&dev->node);
799 805
800 if (dev->dynalloc) { 806 sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
801 sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group); 807 sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
802 sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group); 808 sysfs_remove_group(&dev->cdev.kobj, &input_dev_group);
803 class_device_unregister(&dev->cdev); 809 class_device_unregister(&dev->cdev);
804 }
805 810
806 input_wakeup_procfs_readers(); 811 input_wakeup_procfs_readers();
807} 812}
diff --git a/drivers/input/keyboard/lkkbd.c b/drivers/input/keyboard/lkkbd.c
index 9481132532d0..77c4d9669ad0 100644
--- a/drivers/input/keyboard/lkkbd.c
+++ b/drivers/input/keyboard/lkkbd.c
@@ -273,11 +273,11 @@ static lk_keycode_t lkkbd_keycode[LK_NUM_KEYCODES] = {
273 [0xfb] = KEY_APOSTROPHE, 273 [0xfb] = KEY_APOSTROPHE,
274}; 274};
275 275
276#define CHECK_LED(LED, BITS) do { \ 276#define CHECK_LED(LK, VAR_ON, VAR_OFF, LED, BITS) do { \
277 if (test_bit (LED, lk->dev->led)) \ 277 if (test_bit (LED, (LK)->dev->led)) \
278 leds_on |= BITS; \ 278 VAR_ON |= BITS; \
279 else \ 279 else \
280 leds_off |= BITS; \ 280 VAR_OFF |= BITS; \
281 } while (0) 281 } while (0)
282 282
283/* 283/*
@@ -298,6 +298,42 @@ struct lkkbd {
298 int ctrlclick_volume; 298 int ctrlclick_volume;
299}; 299};
300 300
301#ifdef LKKBD_DEBUG
302/*
303 * Responses from the keyboard and mapping back to their names.
304 */
305static struct {
306 unsigned char value;
307 unsigned char *name;
308} lk_response[] = {
309#define RESPONSE(x) { .value = (x), .name = #x, }
310 RESPONSE (LK_STUCK_KEY),
311 RESPONSE (LK_SELFTEST_FAILED),
312 RESPONSE (LK_ALL_KEYS_UP),
313 RESPONSE (LK_METRONOME),
314 RESPONSE (LK_OUTPUT_ERROR),
315 RESPONSE (LK_INPUT_ERROR),
316 RESPONSE (LK_KBD_LOCKED),
317 RESPONSE (LK_KBD_TEST_MODE_ACK),
318 RESPONSE (LK_PREFIX_KEY_DOWN),
319 RESPONSE (LK_MODE_CHANGE_ACK),
320 RESPONSE (LK_RESPONSE_RESERVED),
321#undef RESPONSE
322};
323
324static unsigned char *
325response_name (unsigned char value)
326{
327 int i;
328
329 for (i = 0; i < ARRAY_SIZE (lk_response); i++)
330 if (lk_response[i].value == value)
331 return lk_response[i].name;
332
333 return "<unknown>";
334}
335#endif /* LKKBD_DEBUG */
336
301/* 337/*
302 * Calculate volume parameter byte for a given volume. 338 * Calculate volume parameter byte for a given volume.
303 */ 339 */
@@ -440,43 +476,24 @@ lkkbd_interrupt (struct serio *serio, unsigned char data, unsigned int flags,
440 input_report_key (lk->dev, lk->keycode[i], 0); 476 input_report_key (lk->dev, lk->keycode[i], 0);
441 input_sync (lk->dev); 477 input_sync (lk->dev);
442 break; 478 break;
443 case LK_METRONOME: 479
444 DBG (KERN_INFO "Got LK_METRONOME and don't " 480 case 0x01:
445 "know how to handle...\n"); 481 DBG (KERN_INFO "Got 0x01, scheduling re-initialization\n");
482 lk->ignore_bytes = LK_NUM_IGNORE_BYTES;
483 lk->id[LK_NUM_IGNORE_BYTES - lk->ignore_bytes--] = data;
484 schedule_work (&lk->tq);
446 break; 485 break;
486
487 case LK_METRONOME:
447 case LK_OUTPUT_ERROR: 488 case LK_OUTPUT_ERROR:
448 DBG (KERN_INFO "Got LK_OUTPUT_ERROR and don't "
449 "know how to handle...\n");
450 break;
451 case LK_INPUT_ERROR: 489 case LK_INPUT_ERROR:
452 DBG (KERN_INFO "Got LK_INPUT_ERROR and don't "
453 "know how to handle...\n");
454 break;
455 case LK_KBD_LOCKED: 490 case LK_KBD_LOCKED:
456 DBG (KERN_INFO "Got LK_KBD_LOCKED and don't "
457 "know how to handle...\n");
458 break;
459 case LK_KBD_TEST_MODE_ACK: 491 case LK_KBD_TEST_MODE_ACK:
460 DBG (KERN_INFO "Got LK_KBD_TEST_MODE_ACK and don't "
461 "know how to handle...\n");
462 break;
463 case LK_PREFIX_KEY_DOWN: 492 case LK_PREFIX_KEY_DOWN:
464 DBG (KERN_INFO "Got LK_PREFIX_KEY_DOWN and don't "
465 "know how to handle...\n");
466 break;
467 case LK_MODE_CHANGE_ACK: 493 case LK_MODE_CHANGE_ACK:
468 DBG (KERN_INFO "Got LK_MODE_CHANGE_ACK and ignored "
469 "it properly...\n");
470 break;
471 case LK_RESPONSE_RESERVED: 494 case LK_RESPONSE_RESERVED:
472 DBG (KERN_INFO "Got LK_RESPONSE_RESERVED and don't " 495 DBG (KERN_INFO "Got %s and don't know how to handle...\n",
473 "know how to handle...\n"); 496 response_name (data));
474 break;
475 case 0x01:
476 DBG (KERN_INFO "Got 0x01, scheduling re-initialization\n");
477 lk->ignore_bytes = LK_NUM_IGNORE_BYTES;
478 lk->id[LK_NUM_IGNORE_BYTES - lk->ignore_bytes--] = data;
479 schedule_work (&lk->tq);
480 break; 497 break;
481 498
482 default: 499 default:
@@ -509,10 +526,10 @@ lkkbd_event (struct input_dev *dev, unsigned int type, unsigned int code,
509 526
510 switch (type) { 527 switch (type) {
511 case EV_LED: 528 case EV_LED:
512 CHECK_LED (LED_CAPSL, LK_LED_SHIFTLOCK); 529 CHECK_LED (lk, leds_on, leds_off, LED_CAPSL, LK_LED_SHIFTLOCK);
513 CHECK_LED (LED_COMPOSE, LK_LED_COMPOSE); 530 CHECK_LED (lk, leds_on, leds_off, LED_COMPOSE, LK_LED_COMPOSE);
514 CHECK_LED (LED_SCROLLL, LK_LED_SCROLLLOCK); 531 CHECK_LED (lk, leds_on, leds_off, LED_SCROLLL, LK_LED_SCROLLLOCK);
515 CHECK_LED (LED_SLEEP, LK_LED_WAIT); 532 CHECK_LED (lk, leds_on, leds_off, LED_SLEEP, LK_LED_WAIT);
516 if (leds_on != 0) { 533 if (leds_on != 0) {
517 lk->serio->write (lk->serio, LK_CMD_LED_ON); 534 lk->serio->write (lk->serio, LK_CMD_LED_ON);
518 lk->serio->write (lk->serio, leds_on); 535 lk->serio->write (lk->serio, leds_on);
@@ -574,10 +591,10 @@ lkkbd_reinit (void *data)
574 lk->serio->write (lk->serio, LK_CMD_SET_DEFAULTS); 591 lk->serio->write (lk->serio, LK_CMD_SET_DEFAULTS);
575 592
576 /* Set LEDs */ 593 /* Set LEDs */
577 CHECK_LED (LED_CAPSL, LK_LED_SHIFTLOCK); 594 CHECK_LED (lk, leds_on, leds_off, LED_CAPSL, LK_LED_SHIFTLOCK);
578 CHECK_LED (LED_COMPOSE, LK_LED_COMPOSE); 595 CHECK_LED (lk, leds_on, leds_off, LED_COMPOSE, LK_LED_COMPOSE);
579 CHECK_LED (LED_SCROLLL, LK_LED_SCROLLLOCK); 596 CHECK_LED (lk, leds_on, leds_off, LED_SCROLLL, LK_LED_SCROLLLOCK);
580 CHECK_LED (LED_SLEEP, LK_LED_WAIT); 597 CHECK_LED (lk, leds_on, leds_off, LED_SLEEP, LK_LED_WAIT);
581 if (leds_on != 0) { 598 if (leds_on != 0) {
582 lk->serio->write (lk->serio, LK_CMD_LED_ON); 599 lk->serio->write (lk->serio, LK_CMD_LED_ON);
583 lk->serio->write (lk->serio, leds_on); 600 lk->serio->write (lk->serio, leds_on);
diff --git a/drivers/input/keyboard/locomokbd.c b/drivers/input/keyboard/locomokbd.c
index 8935290256b3..2c510881874a 100644
--- a/drivers/input/keyboard/locomokbd.c
+++ b/drivers/input/keyboard/locomokbd.c
@@ -76,7 +76,7 @@ static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
76 76
77struct locomokbd { 77struct locomokbd {
78 unsigned char keycode[LOCOMOKBD_NUMKEYS]; 78 unsigned char keycode[LOCOMOKBD_NUMKEYS];
79 struct input_dev input; 79 struct input_dev *input;
80 char phys[32]; 80 char phys[32];
81 81
82 struct locomo_dev *ldev; 82 struct locomo_dev *ldev;
@@ -136,8 +136,7 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *
136 136
137 spin_lock_irqsave(&locomokbd->lock, flags); 137 spin_lock_irqsave(&locomokbd->lock, flags);
138 138
139 if (regs) 139 input_regs(locomokbd->input, regs);
140 input_regs(&locomokbd->input, regs);
141 140
142 locomokbd_charge_all(membase); 141 locomokbd_charge_all(membase);
143 142
@@ -152,16 +151,16 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *
152 scancode = SCANCODE(col, row); 151 scancode = SCANCODE(col, row);
153 if (rowd & KB_ROWMASK(row)) { 152 if (rowd & KB_ROWMASK(row)) {
154 num_pressed += 1; 153 num_pressed += 1;
155 input_report_key(&locomokbd->input, locomokbd->keycode[scancode], 1); 154 input_report_key(locomokbd->input, locomokbd->keycode[scancode], 1);
156 } else { 155 } else {
157 input_report_key(&locomokbd->input, locomokbd->keycode[scancode], 0); 156 input_report_key(locomokbd->input, locomokbd->keycode[scancode], 0);
158 } 157 }
159 } 158 }
160 locomokbd_reset_col(membase, col); 159 locomokbd_reset_col(membase, col);
161 } 160 }
162 locomokbd_activate_all(membase); 161 locomokbd_activate_all(membase);
163 162
164 input_sync(&locomokbd->input); 163 input_sync(locomokbd->input);
165 164
166 /* if any keys are pressed, enable the timer */ 165 /* if any keys are pressed, enable the timer */
167 if (num_pressed) 166 if (num_pressed)
@@ -196,13 +195,15 @@ static void locomokbd_timer_callback(unsigned long data)
196static int locomokbd_probe(struct locomo_dev *dev) 195static int locomokbd_probe(struct locomo_dev *dev)
197{ 196{
198 struct locomokbd *locomokbd; 197 struct locomokbd *locomokbd;
198 struct input_dev *input_dev;
199 int i, ret; 199 int i, ret;
200 200
201 locomokbd = kmalloc(sizeof(struct locomokbd), GFP_KERNEL); 201 locomokbd = kzalloc(sizeof(struct locomokbd), GFP_KERNEL);
202 if (!locomokbd) 202 input_dev = input_allocate_device();
203 return -ENOMEM; 203 if (!locomokbd || !input_dev) {
204 204 ret = -ENOMEM;
205 memset(locomokbd, 0, sizeof(struct locomokbd)); 205 goto free;
206 }
206 207
207 /* try and claim memory region */ 208 /* try and claim memory region */
208 if (!request_mem_region((unsigned long) dev->mapbase, 209 if (!request_mem_region((unsigned long) dev->mapbase,
@@ -224,27 +225,26 @@ static int locomokbd_probe(struct locomo_dev *dev)
224 locomokbd->timer.function = locomokbd_timer_callback; 225 locomokbd->timer.function = locomokbd_timer_callback;
225 locomokbd->timer.data = (unsigned long) locomokbd; 226 locomokbd->timer.data = (unsigned long) locomokbd;
226 227
227 locomokbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 228 locomokbd->input = input_dev;
229 strcpy(locomokbd->phys, "locomokbd/input0");
230
231 input_dev->name = "LoCoMo keyboard";
232 input_dev->phys = locomokbd->phys;
233 input_dev->id.bustype = BUS_HOST;
234 input_dev->id.vendor = 0x0001;
235 input_dev->id.product = 0x0001;
236 input_dev->id.version = 0x0100;
237 input_dev->private = locomokbd;
228 238
229 init_input_dev(&locomokbd->input); 239 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
230 locomokbd->input.keycode = locomokbd->keycode; 240 input_dev->keycode = locomokbd->keycode;
231 locomokbd->input.keycodesize = sizeof(unsigned char); 241 input_dev->keycodesize = sizeof(unsigned char);
232 locomokbd->input.keycodemax = ARRAY_SIZE(locomokbd_keycode); 242 input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode);
233 locomokbd->input.private = locomokbd;
234 243
235 memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode)); 244 memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode));
236 for (i = 0; i < LOCOMOKBD_NUMKEYS; i++) 245 for (i = 0; i < LOCOMOKBD_NUMKEYS; i++)
237 set_bit(locomokbd->keycode[i], locomokbd->input.keybit); 246 set_bit(locomokbd->keycode[i], input_dev->keybit);
238 clear_bit(0, locomokbd->input.keybit); 247 clear_bit(0, input_dev->keybit);
239
240 strcpy(locomokbd->phys, "locomokbd/input0");
241
242 locomokbd->input.name = "LoCoMo keyboard";
243 locomokbd->input.phys = locomokbd->phys;
244 locomokbd->input.id.bustype = BUS_XTKBD;
245 locomokbd->input.id.vendor = 0x0001;
246 locomokbd->input.id.product = 0x0001;
247 locomokbd->input.id.version = 0x0100;
248 248
249 /* attempt to get the interrupt */ 249 /* attempt to get the interrupt */
250 ret = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd); 250 ret = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd);
@@ -253,9 +253,7 @@ static int locomokbd_probe(struct locomo_dev *dev)
253 goto out; 253 goto out;
254 } 254 }
255 255
256 input_register_device(&locomokbd->input); 256 input_register_device(locomokbd->input);
257
258 printk(KERN_INFO "input: LoCoMo keyboard on locomokbd\n");
259 257
260 return 0; 258 return 0;
261 259
@@ -263,6 +261,7 @@ out:
263 release_mem_region((unsigned long) dev->mapbase, dev->length); 261 release_mem_region((unsigned long) dev->mapbase, dev->length);
264 locomo_set_drvdata(dev, NULL); 262 locomo_set_drvdata(dev, NULL);
265free: 263free:
264 input_free_device(input_dev);
266 kfree(locomokbd); 265 kfree(locomokbd);
267 266
268 return ret; 267 return ret;
@@ -276,7 +275,7 @@ static int locomokbd_remove(struct locomo_dev *dev)
276 275
277 del_timer_sync(&locomokbd->timer); 276 del_timer_sync(&locomokbd->timer);
278 277
279 input_unregister_device(&locomokbd->input); 278 input_unregister_device(locomokbd->input);
280 locomo_set_drvdata(dev, NULL); 279 locomo_set_drvdata(dev, NULL);
281 280
282 release_mem_region((unsigned long) dev->mapbase, dev->length); 281 release_mem_region((unsigned long) dev->mapbase, dev->length);
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 4015a91f4b6e..948c1cc01bc9 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -271,8 +271,7 @@ static int uinput_alloc_device(struct file *file, const char __user *buffer, siz
271 goto exit; 271 goto exit;
272 } 272 }
273 273
274 if (dev->name) 274 kfree(dev->name);
275 kfree(dev->name);
276 275
277 size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; 276 size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1;
278 dev->name = name = kmalloc(size, GFP_KERNEL); 277 dev->name = name = kmalloc(size, GFP_KERNEL);
@@ -372,11 +371,8 @@ static int uinput_burn_device(struct uinput_device *udev)
372 if (test_bit(UIST_CREATED, &udev->state)) 371 if (test_bit(UIST_CREATED, &udev->state))
373 uinput_destroy_device(udev); 372 uinput_destroy_device(udev);
374 373
375 if (udev->dev->name) 374 kfree(udev->dev->name);
376 kfree(udev->dev->name); 375 kfree(udev->dev->phys);
377 if (udev->dev->phys)
378 kfree(udev->dev->phys);
379
380 kfree(udev->dev); 376 kfree(udev->dev);
381 kfree(udev); 377 kfree(udev);
382 378
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index 0f69ff46c1ae..31a59f7abfaf 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -217,6 +217,9 @@ static struct ps2pp_info *get_model_info(unsigned char model)
217 { 61, PS2PP_KIND_MX, /* MX700 */ 217 { 61, PS2PP_KIND_MX, /* MX700 */
218 PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN | 218 PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN |
219 PS2PP_EXTRA_BTN | PS2PP_NAV_BTN }, 219 PS2PP_EXTRA_BTN | PS2PP_NAV_BTN },
220 { 66, PS2PP_KIND_MX, /* MX3100 reciver */
221 PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN |
222 PS2PP_EXTRA_BTN | PS2PP_NAV_BTN | PS2PP_HWHEEL },
220 { 73, 0, PS2PP_SIDE_BTN }, 223 { 73, 0, PS2PP_SIDE_BTN },
221 { 75, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, 224 { 75, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
222 { 76, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, 225 { 76, PS2PP_KIND_WHEEL, PS2PP_WHEEL },
diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c
index db9bad2b3d16..27391c32f3eb 100644
--- a/drivers/isdn/hardware/avm/avm_cs.c
+++ b/drivers/isdn/hardware/avm/avm_cs.c
@@ -212,11 +212,8 @@ static void avmcs_detach(dev_link_t *link)
212 212
213 /* Unlink device structure, free pieces */ 213 /* Unlink device structure, free pieces */
214 *linkp = link->next; 214 *linkp = link->next;
215 if (link->priv) { 215 kfree(link->priv);
216 kfree(link->priv);
217 }
218 kfree(link); 216 kfree(link);
219
220} /* avmcs_detach */ 217} /* avmcs_detach */
221 218
222/*====================================================================== 219/*======================================================================
diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
index 625799ab0d14..5d8ee7368f7b 100644
--- a/drivers/isdn/hisax/avm_pci.c
+++ b/drivers/isdn/hisax/avm_pci.c
@@ -552,14 +552,10 @@ close_hdlcstate(struct BCState *bcs)
552{ 552{
553 modehdlc(bcs, 0, 0); 553 modehdlc(bcs, 0, 0);
554 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) { 554 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
555 if (bcs->hw.hdlc.rcvbuf) { 555 kfree(bcs->hw.hdlc.rcvbuf);
556 kfree(bcs->hw.hdlc.rcvbuf); 556 bcs->hw.hdlc.rcvbuf = NULL;
557 bcs->hw.hdlc.rcvbuf = NULL; 557 kfree(bcs->blog);
558 } 558 bcs->blog = NULL;
559 if (bcs->blog) {
560 kfree(bcs->blog);
561 bcs->blog = NULL;
562 }
563 skb_queue_purge(&bcs->rqueue); 559 skb_queue_purge(&bcs->rqueue);
564 skb_queue_purge(&bcs->squeue); 560 skb_queue_purge(&bcs->squeue);
565 if (bcs->tx_skb) { 561 if (bcs->tx_skb) {
diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c
index 0e22991635e7..5f5a5ae740d2 100644
--- a/drivers/isdn/hisax/avma1_cs.c
+++ b/drivers/isdn/hisax/avma1_cs.c
@@ -236,9 +236,7 @@ static void avma1cs_detach(dev_link_t *link)
236 236
237 /* Unlink device structure, free pieces */ 237 /* Unlink device structure, free pieces */
238 *linkp = link->next; 238 *linkp = link->next;
239 if (link->priv) { 239 kfree(link->priv);
240 kfree(link->priv);
241 }
242 kfree(link); 240 kfree(link);
243 241
244} /* avma1cs_detach */ 242} /* avma1cs_detach */
diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
index fbaab4352902..8159bcecd0c2 100644
--- a/drivers/isdn/hisax/config.c
+++ b/drivers/isdn/hisax/config.c
@@ -787,8 +787,7 @@ static void ll_unload(struct IsdnCardState *cs)
787 ic.command = ISDN_STAT_UNLOAD; 787 ic.command = ISDN_STAT_UNLOAD;
788 ic.driver = cs->myid; 788 ic.driver = cs->myid;
789 cs->iif.statcallb(&ic); 789 cs->iif.statcallb(&ic);
790 if (cs->status_buf) 790 kfree(cs->status_buf);
791 kfree(cs->status_buf);
792 cs->status_read = NULL; 791 cs->status_read = NULL;
793 cs->status_write = NULL; 792 cs->status_write = NULL;
794 cs->status_end = NULL; 793 cs->status_end = NULL;
@@ -807,10 +806,8 @@ static void closecard(int cardnr)
807 806
808 skb_queue_purge(&csta->rq); 807 skb_queue_purge(&csta->rq);
809 skb_queue_purge(&csta->sq); 808 skb_queue_purge(&csta->sq);
810 if (csta->rcvbuf) { 809 kfree(csta->rcvbuf);
811 kfree(csta->rcvbuf); 810 csta->rcvbuf = NULL;
812 csta->rcvbuf = NULL;
813 }
814 if (csta->tx_skb) { 811 if (csta->tx_skb) {
815 dev_kfree_skb(csta->tx_skb); 812 dev_kfree_skb(csta->tx_skb);
816 csta->tx_skb = NULL; 813 csta->tx_skb = NULL;
diff --git a/drivers/isdn/hisax/hfc_2bds0.c b/drivers/isdn/hisax/hfc_2bds0.c
index 7cf87793e790..637a261c9312 100644
--- a/drivers/isdn/hisax/hfc_2bds0.c
+++ b/drivers/isdn/hisax/hfc_2bds0.c
@@ -1052,18 +1052,12 @@ init2bds0(struct IsdnCardState *cs)
1052void 1052void
1053release2bds0(struct IsdnCardState *cs) 1053release2bds0(struct IsdnCardState *cs)
1054{ 1054{
1055 if (cs->bcs[0].hw.hfc.send) { 1055 kfree(cs->bcs[0].hw.hfc.send);
1056 kfree(cs->bcs[0].hw.hfc.send); 1056 cs->bcs[0].hw.hfc.send = NULL;
1057 cs->bcs[0].hw.hfc.send = NULL; 1057 kfree(cs->bcs[1].hw.hfc.send);
1058 } 1058 cs->bcs[1].hw.hfc.send = NULL;
1059 if (cs->bcs[1].hw.hfc.send) { 1059 kfree(cs->hw.hfcD.send);
1060 kfree(cs->bcs[1].hw.hfc.send); 1060 cs->hw.hfcD.send = NULL;
1061 cs->bcs[1].hw.hfc.send = NULL;
1062 }
1063 if (cs->hw.hfcD.send) {
1064 kfree(cs->hw.hfcD.send);
1065 cs->hw.hfcD.send = NULL;
1066 }
1067} 1061}
1068 1062
1069void 1063void
diff --git a/drivers/isdn/hisax/hfc_2bs0.c b/drivers/isdn/hisax/hfc_2bs0.c
index f978a5af8662..c964539cc43e 100644
--- a/drivers/isdn/hisax/hfc_2bs0.c
+++ b/drivers/isdn/hisax/hfc_2bs0.c
@@ -582,12 +582,8 @@ inithfc(struct IsdnCardState *cs)
582void 582void
583releasehfc(struct IsdnCardState *cs) 583releasehfc(struct IsdnCardState *cs)
584{ 584{
585 if (cs->bcs[0].hw.hfc.send) { 585 kfree(cs->bcs[0].hw.hfc.send);
586 kfree(cs->bcs[0].hw.hfc.send); 586 cs->bcs[0].hw.hfc.send = NULL;
587 cs->bcs[0].hw.hfc.send = NULL; 587 kfree(cs->bcs[1].hw.hfc.send);
588 } 588 cs->bcs[1].hw.hfc.send = NULL;
589 if (cs->bcs[1].hw.hfc.send) {
590 kfree(cs->bcs[1].hw.hfc.send);
591 cs->bcs[1].hw.hfc.send = NULL;
592 }
593} 589}
diff --git a/drivers/isdn/hisax/hfc_usb.c b/drivers/isdn/hisax/hfc_usb.c
index e2c3af49d72b..32bf0d5d0f9a 100644
--- a/drivers/isdn/hisax/hfc_usb.c
+++ b/drivers/isdn/hisax/hfc_usb.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * hfc_usb.c 2 * hfc_usb.c
3 * 3 *
4 * $Id: hfc_usb.c,v 4.34 2005/01/26 17:25:53 martinb1 Exp $ 4 * $Id: hfc_usb.c,v 4.36 2005/04/08 09:55:13 martinb1 Exp $
5 * 5 *
6 * modular HiSax ISDN driver for Colognechip HFC-S USB chip 6 * modular HiSax ISDN driver for Colognechip HFC-S USB chip
7 * 7 *
@@ -44,12 +44,8 @@
44#include "hisax_if.h" 44#include "hisax_if.h"
45#include "hfc_usb.h" 45#include "hfc_usb.h"
46 46
47/*
48* Version Information
49* (do not modify the CVS Makros $Revision: 4.34 $ and $Date: 2005/01/26 17:25:53 $ !)
50*/
51static const char *hfcusb_revision = 47static const char *hfcusb_revision =
52 "Revision: 4.34 $ Date: 2005/01/26 17:25:53 $ "; 48 "$Revision: 4.36 $ $Date: 2005/04/08 09:55:13 $ ";
53 49
54/* Hisax debug support 50/* Hisax debug support
55* use "modprobe debug=x" where x is bitfield of USB_DBG & ISDN_DBG 51* use "modprobe debug=x" where x is bitfield of USB_DBG & ISDN_DBG
@@ -63,81 +59,89 @@ module_param(debug, uint, 0);
63static int hfc_debug; 59static int hfc_debug;
64#endif 60#endif
65 61
62/* private vendor specific data */
63typedef struct {
64 __u8 led_scheme; // led display scheme
65 signed short led_bits[8]; // array of 8 possible LED bitmask settings
66 char *vend_name; // device name
67} hfcsusb_vdata;
66 68
67/****************************************/ 69/****************************************/
68/* data defining the devices to be used */ 70/* data defining the devices to be used */
69/****************************************/ 71/****************************************/
70static struct usb_device_id hfc_usb_idtab[] = { 72static struct usb_device_id hfcusb_idtab[] = {
71 {USB_DEVICE(0x0959, 0x2bd0)}, /* Colognechip USB eval TA */ 73 {
72 {USB_DEVICE(0x0675, 0x1688)}, /* DrayTek miniVigor 128 USB ISDN TA */ 74 .idVendor = 0x0959,
73 {USB_DEVICE(0x07b0, 0x0007)}, /* Billion USB TA 2 */ 75 .idProduct = 0x2bd0,
74 {USB_DEVICE(0x0742, 0x2008)}, /* Stollmann USB TA */ 76 .driver_info = (unsigned long) &((hfcsusb_vdata)
75 {USB_DEVICE(0x0742, 0x2009)}, /* Aceex USB ISDN TA */ 77 {LED_OFF, {4, 0, 2, 1},
76 {USB_DEVICE(0x0742, 0x200A)}, /* OEM USB ISDN TA */ 78 "ISDN USB TA (Cologne Chip HFC-S USB based)"}),
77 {USB_DEVICE(0x08e3, 0x0301)}, /* OliTec ISDN USB */ 79 },
78 {USB_DEVICE(0x07fa, 0x0846)}, /* Bewan ISDN USB TA */ 80 {
79 {USB_DEVICE(0x07fa, 0x0847)}, /* Djinn Numeris USB */ 81 .idVendor = 0x0675,
80 {USB_DEVICE(0x07b0, 0x0006)}, /* Twister ISDN USB TA */ 82 .idProduct = 0x1688,
81 {} /* end with an all-zeroes entry */ 83 .driver_info = (unsigned long) &((hfcsusb_vdata)
84 {LED_SCHEME1, {1, 2, 0, 0},
85 "DrayTek miniVigor 128 USB ISDN TA"}),
86 },
87 {
88 .idVendor = 0x07b0,
89 .idProduct = 0x0007,
90 .driver_info = (unsigned long) &((hfcsusb_vdata)
91 {LED_SCHEME1, {0x80, -64, -32, -16},
92 "Billion tiny USB ISDN TA 128"}),
93 },
94 {
95 .idVendor = 0x0742,
96 .idProduct = 0x2008,
97 .driver_info = (unsigned long) &((hfcsusb_vdata)
98 {LED_SCHEME1, {4, 0, 2, 1},
99 "Stollmann USB TA"}),
100 },
101 {
102 .idVendor = 0x0742,
103 .idProduct = 0x2009,
104 .driver_info = (unsigned long) &((hfcsusb_vdata)
105 {LED_SCHEME1, {4, 0, 2, 1},
106 "Aceex USB ISDN TA"}),
107 },
108 {
109 .idVendor = 0x0742,
110 .idProduct = 0x200A,
111 .driver_info = (unsigned long) &((hfcsusb_vdata)
112 {LED_SCHEME1, {4, 0, 2, 1},
113 "OEM USB ISDN TA"}),
114 },
115 {
116 .idVendor = 0x08e3,
117 .idProduct = 0x0301,
118 .driver_info = (unsigned long) &((hfcsusb_vdata)
119 {LED_SCHEME1, {2, 0, 1, 4},
120 "Olitec USB RNIS"}),
121 },
122 {
123 .idVendor = 0x07fa,
124 .idProduct = 0x0846,
125 .driver_info = (unsigned long) &((hfcsusb_vdata)
126 {LED_SCHEME1, {0x80, -64, -32, -16},
127 "Bewan Modem RNIS USB"}),
128 },
129 {
130 .idVendor = 0x07fa,
131 .idProduct = 0x0847,
132 .driver_info = (unsigned long) &((hfcsusb_vdata)
133 {LED_SCHEME1, {0x80, -64, -32, -16},
134 "Djinn Numeris USB"}),
135 },
136 {
137 .idVendor = 0x07b0,
138 .idProduct = 0x0006,
139 .driver_info = (unsigned long) &((hfcsusb_vdata)
140 {LED_SCHEME1, {0x80, -64, -32, -16},
141 "Twister ISDN TA"}),
142 },
82}; 143};
83 144
84/* driver internal device specific data:
85* VendorID, ProductID, Devicename, LED_SCHEME,
86* LED's BitMask in HFCUSB_P_DATA Register : LED_USB, LED_S0, LED_B1, LED_B2
87*/
88static vendor_data vdata[] = {
89 /* CologneChip Eval TA */
90 {0x0959, 0x2bd0, "ISDN USB TA (Cologne Chip HFC-S USB based)",
91 LED_OFF, {4, 0, 2, 1}
92 }
93 ,
94 /* DrayTek miniVigor 128 USB ISDN TA */
95 {0x0675, 0x1688, "DrayTek miniVigor 128 USB ISDN TA",
96 LED_SCHEME1, {1, 2, 0, 0}
97 }
98 ,
99 /* Billion TA */
100 {0x07b0, 0x0007, "Billion tiny USB ISDN TA 128",
101 LED_SCHEME1, {0x80, -64, -32, -16}
102 }
103 ,
104 /* Stollmann TA */
105 {0x0742, 0x2008, "Stollmann USB TA",
106 LED_SCHEME1, {4, 0, 2, 1}
107 }
108 ,
109 /* Aceex USB ISDN TA */
110 {0x0742, 0x2009, "Aceex USB ISDN TA",
111 LED_SCHEME1, {4, 0, 2, 1}
112 }
113 ,
114 /* OEM USB ISDN TA */
115 {0x0742, 0x200A, "OEM USB ISDN TA",
116 LED_SCHEME1, {4, 0, 2, 1}
117 }
118 ,
119 /* Olitec TA */
120 {0x08e3, 0x0301, "Olitec USB RNIS",
121 LED_SCHEME1, {2, 0, 1, 4}
122 }
123 ,
124 /* Bewan TA */
125 {0x07fa, 0x0846, "Bewan Modem RNIS USB",
126 LED_SCHEME1, {0x80, -64, -32, -16}
127 }
128 ,
129 /* Bewan TA */
130 {0x07fa, 0x0847, "Djinn Numeris USB",
131 LED_SCHEME1, {0x80, -64, -32, -16}
132 }
133 ,
134 /* Twister ISDN TA */
135 {0x07b0, 0x0006, "Twister ISDN TA",
136 LED_SCHEME1, {0x80, -64, -32, -16}
137 }
138 ,
139 {0, 0, 0} /* EOL element */
140};
141 145
142/***************************************************************/ 146/***************************************************************/
143/* structure defining input+output fifos (interrupt/bulk mode) */ 147/* structure defining input+output fifos (interrupt/bulk mode) */
@@ -211,8 +215,6 @@ typedef struct hfcusb_data {
211 volatile __u8 l1_state; /* actual l1 state */ 215 volatile __u8 l1_state; /* actual l1 state */
212 struct timer_list t3_timer; /* timer 3 for activation/deactivation */ 216 struct timer_list t3_timer; /* timer 3 for activation/deactivation */
213 struct timer_list t4_timer; /* timer 4 for activation/deactivation */ 217 struct timer_list t4_timer; /* timer 4 for activation/deactivation */
214 struct timer_list led_timer; /* timer flashing leds */
215
216} hfcusb_data; 218} hfcusb_data;
217 219
218 220
@@ -227,7 +229,7 @@ symbolic(struct hfcusb_symbolic_list list[], const int num)
227 for (i = 0; list[i].name != NULL; i++) 229 for (i = 0; list[i].name != NULL; i++)
228 if (list[i].num == num) 230 if (list[i].num == num)
229 return (list[i].name); 231 return (list[i].name);
230 return "<unkown>"; 232 return "<unkown ERROR>";
231} 233}
232 234
233 235
@@ -335,93 +337,57 @@ set_led_bit(hfcusb_data * hfc, signed short led_bits, int unset)
335 } 337 }
336} 338}
337 339
338/******************************************/
339/* invert B-channel LEDs if data is sent */
340/******************************************/
341static void
342led_timer(hfcusb_data * hfc)
343{
344 static int cnt = 0;
345
346 if (cnt) {
347 if (hfc->led_b_active & 1)
348 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[2],
349 0);
350 if (hfc->led_b_active & 2)
351 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[3],
352 0);
353 } else {
354 if (!(hfc->led_b_active & 1) || hfc->led_new_data & 1)
355 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[2],
356 1);
357 if (!(hfc->led_b_active & 2) || hfc->led_new_data & 2)
358 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[3],
359 1);
360 }
361
362 write_led(hfc, hfc->led_state);
363 hfc->led_new_data = 0;
364
365 cnt = !cnt;
366
367 /* restart 4 hz timer */
368 if (!timer_pending(&hfc->led_timer)) {
369 add_timer(&hfc->led_timer);
370 hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
371 }
372}
373
374/**************************/ 340/**************************/
375/* handle LED requests */ 341/* handle LED requests */
376/**************************/ 342/**************************/
377static void 343static void
378handle_led(hfcusb_data * hfc, int event) 344handle_led(hfcusb_data * hfc, int event)
379{ 345{
346 hfcsusb_vdata *driver_info =
347 (hfcsusb_vdata *) hfcusb_idtab[hfc->vend_idx].driver_info;
348
380 /* if no scheme -> no LED action */ 349 /* if no scheme -> no LED action */
381 if (vdata[hfc->vend_idx].led_scheme == LED_OFF) 350 if (driver_info->led_scheme == LED_OFF)
382 return; 351 return;
383 352
384 switch (event) { 353 switch (event) {
385 case LED_POWER_ON: 354 case LED_POWER_ON:
386 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[0], 355 set_led_bit(hfc, driver_info->led_bits[0],
387 0); 356 0);
388 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[1], 357 set_led_bit(hfc, driver_info->led_bits[1],
389 1); 358 1);
390 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[2], 359 set_led_bit(hfc, driver_info->led_bits[2],
391 1); 360 1);
392 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[3], 361 set_led_bit(hfc, driver_info->led_bits[3],
393 1); 362 1);
394 break; 363 break;
395 case LED_POWER_OFF: /* no Power off handling */ 364 case LED_POWER_OFF: /* no Power off handling */
396 break; 365 break;
397 case LED_S0_ON: 366 case LED_S0_ON:
398 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[1], 367 set_led_bit(hfc, driver_info->led_bits[1],
399 0); 368 0);
400 break; 369 break;
401 case LED_S0_OFF: 370 case LED_S0_OFF:
402 set_led_bit(hfc, vdata[hfc->vend_idx].led_bits[1], 371 set_led_bit(hfc, driver_info->led_bits[1],
403 1); 372 1);
404 break; 373 break;
405 case LED_B1_ON: 374 case LED_B1_ON:
406 hfc->led_b_active |= 1; 375 set_led_bit(hfc, driver_info->led_bits[2],
376 0);
407 break; 377 break;
408 case LED_B1_OFF: 378 case LED_B1_OFF:
409 hfc->led_b_active &= ~1; 379 set_led_bit(hfc, driver_info->led_bits[2],
410 break; 380 1);
411 case LED_B1_DATA:
412 hfc->led_new_data |= 1;
413 break; 381 break;
414 case LED_B2_ON: 382 case LED_B2_ON:
415 hfc->led_b_active |= 2; 383 set_led_bit(hfc, driver_info->led_bits[3],
384 0);
416 break; 385 break;
417 case LED_B2_OFF: 386 case LED_B2_OFF:
418 hfc->led_b_active &= ~2; 387 set_led_bit(hfc, driver_info->led_bits[3],
419 break; 388 1);
420 case LED_B2_DATA:
421 hfc->led_new_data |= 2;
422 break; 389 break;
423 } 390 }
424
425 write_led(hfc, hfc->led_state); 391 write_led(hfc, hfc->led_state);
426} 392}
427 393
@@ -725,14 +691,6 @@ tx_iso_complete(struct urb *urb, struct pt_regs *regs)
725 current_len + 1; 691 current_len + 1;
726 692
727 tx_offset += (current_len + 1); 693 tx_offset += (current_len + 1);
728 if (!transp_mode) {
729 if (fifon == HFCUSB_B1_TX)
730 handle_led(hfc,
731 LED_B1_DATA);
732 if (fifon == HFCUSB_B2_TX)
733 handle_led(hfc,
734 LED_B2_DATA);
735 }
736 } else { 694 } else {
737 urb->iso_frame_desc[k].offset = 695 urb->iso_frame_desc[k].offset =
738 tx_offset++; 696 tx_offset++;
@@ -966,14 +924,6 @@ collect_rx_frame(usb_fifo * fifo, __u8 * data, int len, int finish)
966 skb_trim(fifo->skbuff, 0); 924 skb_trim(fifo->skbuff, 0);
967 } 925 }
968 } 926 }
969
970 /* LED flashing only in HDLC mode */
971 if (!transp_mode) {
972 if (fifon == HFCUSB_B1_RX)
973 handle_led(hfc, LED_B1_DATA);
974 if (fifon == HFCUSB_B2_RX)
975 handle_led(hfc, LED_B2_DATA);
976 }
977} 927}
978 928
979/***********************************************/ 929/***********************************************/
@@ -1339,17 +1289,6 @@ usb_init(hfcusb_data * hfc)
1339 hfc->t4_timer.data = (long) hfc; 1289 hfc->t4_timer.data = (long) hfc;
1340 hfc->t4_timer.function = (void *) l1_timer_expire_t4; 1290 hfc->t4_timer.function = (void *) l1_timer_expire_t4;
1341 1291
1342 /* init the led timer */
1343 init_timer(&hfc->led_timer);
1344 hfc->led_timer.data = (long) hfc;
1345 hfc->led_timer.function = (void *) led_timer;
1346
1347 /* trigger 4 hz led timer */
1348 if (!timer_pending(&hfc->led_timer)) {
1349 hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
1350 add_timer(&hfc->led_timer);
1351 }
1352
1353 /* init the background machinery for control requests */ 1292 /* init the background machinery for control requests */
1354 hfc->ctrl_read.bRequestType = 0xc0; 1293 hfc->ctrl_read.bRequestType = 0xc0;
1355 hfc->ctrl_read.bRequest = 1; 1294 hfc->ctrl_read.bRequest = 1;
@@ -1440,13 +1379,18 @@ hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1440 attr, cfg_found, cidx, ep_addr; 1379 attr, cfg_found, cidx, ep_addr;
1441 int cmptbl[16], small_match, iso_packet_size, packet_size, 1380 int cmptbl[16], small_match, iso_packet_size, packet_size,
1442 alt_used = 0; 1381 alt_used = 0;
1382 hfcsusb_vdata *driver_info;
1443 1383
1444 vend_idx = 0xffff; 1384 vend_idx = 0xffff;
1445 for (i = 0; vdata[i].vendor; i++) { 1385 for (i = 0; hfcusb_idtab[i].idVendor; i++) {
1446 if (dev->descriptor.idVendor == vdata[i].vendor 1386 if (dev->descriptor.idVendor == hfcusb_idtab[i].idVendor
1447 && dev->descriptor.idProduct == vdata[i].prod_id) 1387 && dev->descriptor.idProduct ==
1388 hfcusb_idtab[i].idProduct) {
1448 vend_idx = i; 1389 vend_idx = i;
1390 continue;
1391 }
1449 } 1392 }
1393
1450#ifdef CONFIG_HISAX_DEBUG 1394#ifdef CONFIG_HISAX_DEBUG
1451 DBG(USB_DBG, 1395 DBG(USB_DBG,
1452 "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n", ifnum, 1396 "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n", ifnum,
@@ -1457,10 +1401,6 @@ hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1457 ifnum, iface->desc.bAlternateSetting, intf->minor); 1401 ifnum, iface->desc.bAlternateSetting, intf->minor);
1458 1402
1459 if (vend_idx != 0xffff) { 1403 if (vend_idx != 0xffff) {
1460#ifdef CONFIG_HISAX_DEBUG
1461 DBG(USB_DBG, "HFC-S USB: found vendor idx:%d name:%s",
1462 vend_idx, vdata[vend_idx].vend_name);
1463#endif
1464 /* if vendor and product ID is OK, start probing alternate settings */ 1404 /* if vendor and product ID is OK, start probing alternate settings */
1465 alt_idx = 0; 1405 alt_idx = 0;
1466 small_match = 0xffff; 1406 small_match = 0xffff;
@@ -1687,9 +1627,11 @@ hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1687 usb_sndctrlpipe(context->dev, 0); 1627 usb_sndctrlpipe(context->dev, 0);
1688 context->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL); 1628 context->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
1689 1629
1690 printk(KERN_INFO 1630 driver_info =
1691 "HFC-S USB: detected \"%s\"\n", 1631 (hfcsusb_vdata *) hfcusb_idtab[vend_idx].
1692 vdata[vend_idx].vend_name); 1632 driver_info;
1633 printk(KERN_INFO "HFC-S USB: detected \"%s\"\n",
1634 driver_info->vend_name);
1693#ifdef CONFIG_HISAX_DEBUG 1635#ifdef CONFIG_HISAX_DEBUG
1694 DBG(USB_DBG, 1636 DBG(USB_DBG,
1695 "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d)\n", 1637 "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d)\n",
@@ -1740,8 +1682,6 @@ hfc_usb_disconnect(struct usb_interface
1740 del_timer(&context->t3_timer); 1682 del_timer(&context->t3_timer);
1741 if (timer_pending(&context->t4_timer)) 1683 if (timer_pending(&context->t4_timer))
1742 del_timer(&context->t4_timer); 1684 del_timer(&context->t4_timer);
1743 if (timer_pending(&context->led_timer))
1744 del_timer(&context->led_timer);
1745 /* tell all fifos to terminate */ 1685 /* tell all fifos to terminate */
1746 for (i = 0; i < HFCUSB_NUM_FIFOS; i++) { 1686 for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
1747 if (context->fifos[i].usb_transfer_mode == USB_ISOC) { 1687 if (context->fifos[i].usb_transfer_mode == USB_ISOC) {
@@ -1785,9 +1725,11 @@ hfc_usb_disconnect(struct usb_interface
1785/* our driver information structure */ 1725/* our driver information structure */
1786/************************************/ 1726/************************************/
1787static struct usb_driver hfc_drv = { 1727static struct usb_driver hfc_drv = {
1788 .owner = THIS_MODULE,.name = 1728 .owner = THIS_MODULE,
1789 "hfc_usb",.id_table = hfc_usb_idtab,.probe = 1729 .name = "hfc_usb",
1790 hfc_usb_probe,.disconnect = hfc_usb_disconnect, 1730 .id_table = hfcusb_idtab,
1731 .probe = hfc_usb_probe,
1732 .disconnect = hfc_usb_disconnect,
1791}; 1733};
1792static void __exit 1734static void __exit
1793hfc_usb_exit(void) 1735hfc_usb_exit(void)
@@ -1825,4 +1767,4 @@ module_exit(hfc_usb_exit);
1825MODULE_AUTHOR(DRIVER_AUTHOR); 1767MODULE_AUTHOR(DRIVER_AUTHOR);
1826MODULE_DESCRIPTION(DRIVER_DESC); 1768MODULE_DESCRIPTION(DRIVER_DESC);
1827MODULE_LICENSE("GPL"); 1769MODULE_LICENSE("GPL");
1828MODULE_DEVICE_TABLE(usb, hfc_usb_idtab); 1770MODULE_DEVICE_TABLE(usb, hfcusb_idtab);
diff --git a/drivers/isdn/hisax/hfc_usb.h b/drivers/isdn/hisax/hfc_usb.h
index 280dd29b30d6..ec52c1a7c22a 100644
--- a/drivers/isdn/hisax/hfc_usb.h
+++ b/drivers/isdn/hisax/hfc_usb.h
@@ -1,7 +1,7 @@
1/* 1/*
2* hfc_usb.h 2* hfc_usb.h
3* 3*
4* $Id: hfc_usb.h,v 4.1 2005/01/26 17:25:53 martinb1 Exp $ 4* $Id: hfc_usb.h,v 4.2 2005/04/07 15:27:17 martinb1 Exp $
5*/ 5*/
6 6
7#ifndef __HFC_USB_H__ 7#ifndef __HFC_USB_H__
@@ -91,7 +91,7 @@
91/**********/ 91/**********/
92/* macros */ 92/* macros */
93/**********/ 93/**********/
94#define write_usb(a,b,c)usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),0,0,HFC_CTRL_TIMEOUT) 94#define write_usb(a,b,c)usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),NULL,0,HFC_CTRL_TIMEOUT)
95#define read_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT) 95#define read_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT)
96 96
97 97
@@ -186,6 +186,7 @@ static int validconf[][19] = {
186 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} // EOL element 186 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} // EOL element
187}; 187};
188 188
189#ifdef CONFIG_HISAX_DEBUG
189// string description of chosen config 190// string description of chosen config
190static char *conf_str[] = { 191static char *conf_str[] = {
191 "4 Interrupt IN + 3 Isochron OUT", 192 "4 Interrupt IN + 3 Isochron OUT",
@@ -193,6 +194,7 @@ static char *conf_str[] = {
193 "4 Isochron IN + 3 Isochron OUT", 194 "4 Isochron IN + 3 Isochron OUT",
194 "3 Isochron IN + 3 Isochron OUT" 195 "3 Isochron IN + 3 Isochron OUT"
195}; 196};
197#endif
196 198
197 199
198typedef struct { 200typedef struct {
diff --git a/drivers/isdn/hisax/hscx.c b/drivers/isdn/hisax/hscx.c
index 66dbaee77bfb..c8f9951f7914 100644
--- a/drivers/isdn/hisax/hscx.c
+++ b/drivers/isdn/hisax/hscx.c
@@ -156,14 +156,10 @@ close_hscxstate(struct BCState *bcs)
156{ 156{
157 modehscx(bcs, 0, bcs->channel); 157 modehscx(bcs, 0, bcs->channel);
158 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) { 158 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
159 if (bcs->hw.hscx.rcvbuf) { 159 kfree(bcs->hw.hscx.rcvbuf);
160 kfree(bcs->hw.hscx.rcvbuf); 160 bcs->hw.hscx.rcvbuf = NULL;
161 bcs->hw.hscx.rcvbuf = NULL; 161 kfree(bcs->blog);
162 } 162 bcs->blog = NULL;
163 if (bcs->blog) {
164 kfree(bcs->blog);
165 bcs->blog = NULL;
166 }
167 skb_queue_purge(&bcs->rqueue); 163 skb_queue_purge(&bcs->rqueue);
168 skb_queue_purge(&bcs->squeue); 164 skb_queue_purge(&bcs->squeue);
169 if (bcs->tx_skb) { 165 if (bcs->tx_skb) {
diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
index b4ca5859b177..c615752b96aa 100644
--- a/drivers/isdn/hisax/icc.c
+++ b/drivers/isdn/hisax/icc.c
@@ -571,14 +571,10 @@ setstack_icc(struct PStack *st, struct IsdnCardState *cs)
571 571
572static void 572static void
573DC_Close_icc(struct IsdnCardState *cs) { 573DC_Close_icc(struct IsdnCardState *cs) {
574 if (cs->dc.icc.mon_rx) { 574 kfree(cs->dc.icc.mon_rx);
575 kfree(cs->dc.icc.mon_rx); 575 cs->dc.icc.mon_rx = NULL;
576 cs->dc.icc.mon_rx = NULL; 576 kfree(cs->dc.icc.mon_tx);
577 } 577 cs->dc.icc.mon_tx = NULL;
578 if (cs->dc.icc.mon_tx) {
579 kfree(cs->dc.icc.mon_tx);
580 cs->dc.icc.mon_tx = NULL;
581 }
582} 578}
583 579
584static void 580static void
diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
index efba2f448017..2e9afae1254a 100644
--- a/drivers/isdn/hisax/ipacx.c
+++ b/drivers/isdn/hisax/ipacx.c
@@ -762,14 +762,10 @@ bch_close_state(struct BCState *bcs)
762{ 762{
763 bch_mode(bcs, 0, bcs->channel); 763 bch_mode(bcs, 0, bcs->channel);
764 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) { 764 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
765 if (bcs->hw.hscx.rcvbuf) { 765 kfree(bcs->hw.hscx.rcvbuf);
766 kfree(bcs->hw.hscx.rcvbuf); 766 bcs->hw.hscx.rcvbuf = NULL;
767 bcs->hw.hscx.rcvbuf = NULL; 767 kfree(bcs->blog);
768 } 768 bcs->blog = NULL;
769 if (bcs->blog) {
770 kfree(bcs->blog);
771 bcs->blog = NULL;
772 }
773 skb_queue_purge(&bcs->rqueue); 769 skb_queue_purge(&bcs->rqueue);
774 skb_queue_purge(&bcs->squeue); 770 skb_queue_purge(&bcs->squeue);
775 if (bcs->tx_skb) { 771 if (bcs->tx_skb) {
diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
index 85e063a08d23..565b7892c267 100644
--- a/drivers/isdn/hisax/isac.c
+++ b/drivers/isdn/hisax/isac.c
@@ -570,15 +570,12 @@ setstack_isac(struct PStack *st, struct IsdnCardState *cs)
570} 570}
571 571
572static void 572static void
573DC_Close_isac(struct IsdnCardState *cs) { 573DC_Close_isac(struct IsdnCardState *cs)
574 if (cs->dc.isac.mon_rx) { 574{
575 kfree(cs->dc.isac.mon_rx); 575 kfree(cs->dc.isac.mon_rx);
576 cs->dc.isac.mon_rx = NULL; 576 cs->dc.isac.mon_rx = NULL;
577 } 577 kfree(cs->dc.isac.mon_tx);
578 if (cs->dc.isac.mon_tx) { 578 cs->dc.isac.mon_tx = NULL;
579 kfree(cs->dc.isac.mon_tx);
580 cs->dc.isac.mon_tx = NULL;
581 }
582} 579}
583 580
584static void 581static void
diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
index 642a87c51295..674af673ff96 100644
--- a/drivers/isdn/hisax/isar.c
+++ b/drivers/isdn/hisax/isar.c
@@ -1688,10 +1688,8 @@ close_isarstate(struct BCState *bcs)
1688{ 1688{
1689 modeisar(bcs, 0, bcs->channel); 1689 modeisar(bcs, 0, bcs->channel);
1690 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) { 1690 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
1691 if (bcs->hw.isar.rcvbuf) { 1691 kfree(bcs->hw.isar.rcvbuf);
1692 kfree(bcs->hw.isar.rcvbuf); 1692 bcs->hw.isar.rcvbuf = NULL;
1693 bcs->hw.isar.rcvbuf = NULL;
1694 }
1695 skb_queue_purge(&bcs->rqueue); 1693 skb_queue_purge(&bcs->rqueue);
1696 skb_queue_purge(&bcs->squeue); 1694 skb_queue_purge(&bcs->squeue);
1697 if (bcs->tx_skb) { 1695 if (bcs->tx_skb) {
diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
index 363ae3179bbd..2659fecc2674 100644
--- a/drivers/isdn/hisax/jade.c
+++ b/drivers/isdn/hisax/jade.c
@@ -195,14 +195,10 @@ close_jadestate(struct BCState *bcs)
195{ 195{
196 modejade(bcs, 0, bcs->channel); 196 modejade(bcs, 0, bcs->channel);
197 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) { 197 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
198 if (bcs->hw.hscx.rcvbuf) { 198 kfree(bcs->hw.hscx.rcvbuf);
199 kfree(bcs->hw.hscx.rcvbuf); 199 bcs->hw.hscx.rcvbuf = NULL;
200 bcs->hw.hscx.rcvbuf = NULL; 200 kfree(bcs->blog);
201 } 201 bcs->blog = NULL;
202 if (bcs->blog) {
203 kfree(bcs->blog);
204 bcs->blog = NULL;
205 }
206 skb_queue_purge(&bcs->rqueue); 202 skb_queue_purge(&bcs->rqueue);
207 skb_queue_purge(&bcs->squeue); 203 skb_queue_purge(&bcs->squeue);
208 if (bcs->tx_skb) { 204 if (bcs->tx_skb) {
diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
index 94da03c30c51..47a47ef0968b 100644
--- a/drivers/isdn/hisax/netjet.c
+++ b/drivers/isdn/hisax/netjet.c
@@ -855,14 +855,10 @@ close_tigerstate(struct BCState *bcs)
855{ 855{
856 mode_tiger(bcs, 0, bcs->channel); 856 mode_tiger(bcs, 0, bcs->channel);
857 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) { 857 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
858 if (bcs->hw.tiger.rcvbuf) { 858 kfree(bcs->hw.tiger.rcvbuf);
859 kfree(bcs->hw.tiger.rcvbuf); 859 bcs->hw.tiger.rcvbuf = NULL;
860 bcs->hw.tiger.rcvbuf = NULL; 860 kfree(bcs->hw.tiger.sendbuf);
861 } 861 bcs->hw.tiger.sendbuf = NULL;
862 if (bcs->hw.tiger.sendbuf) {
863 kfree(bcs->hw.tiger.sendbuf);
864 bcs->hw.tiger.sendbuf = NULL;
865 }
866 skb_queue_purge(&bcs->rqueue); 862 skb_queue_purge(&bcs->rqueue);
867 skb_queue_purge(&bcs->squeue); 863 skb_queue_purge(&bcs->squeue);
868 if (bcs->tx_skb) { 864 if (bcs->tx_skb) {
@@ -967,20 +963,12 @@ inittiger(struct IsdnCardState *cs)
967static void 963static void
968releasetiger(struct IsdnCardState *cs) 964releasetiger(struct IsdnCardState *cs)
969{ 965{
970 if (cs->bcs[0].hw.tiger.send) { 966 kfree(cs->bcs[0].hw.tiger.send);
971 kfree(cs->bcs[0].hw.tiger.send); 967 cs->bcs[0].hw.tiger.send = NULL;
972 cs->bcs[0].hw.tiger.send = NULL; 968 cs->bcs[1].hw.tiger.send = NULL;
973 } 969 kfree(cs->bcs[0].hw.tiger.rec);
974 if (cs->bcs[1].hw.tiger.send) { 970 cs->bcs[0].hw.tiger.rec = NULL;
975 cs->bcs[1].hw.tiger.send = NULL; 971 cs->bcs[1].hw.tiger.rec = NULL;
976 }
977 if (cs->bcs[0].hw.tiger.rec) {
978 kfree(cs->bcs[0].hw.tiger.rec);
979 cs->bcs[0].hw.tiger.rec = NULL;
980 }
981 if (cs->bcs[1].hw.tiger.rec) {
982 cs->bcs[1].hw.tiger.rec = NULL;
983 }
984} 972}
985 973
986void 974void
diff --git a/drivers/isdn/hisax/st5481_usb.c b/drivers/isdn/hisax/st5481_usb.c
index 89fbeb58485d..b096b64b0253 100644
--- a/drivers/isdn/hisax/st5481_usb.c
+++ b/drivers/isdn/hisax/st5481_usb.c
@@ -335,14 +335,12 @@ void st5481_release_usb(struct st5481_adapter *adapter)
335 335
336 // Stop and free Control and Interrupt URBs 336 // Stop and free Control and Interrupt URBs
337 usb_kill_urb(ctrl->urb); 337 usb_kill_urb(ctrl->urb);
338 if (ctrl->urb->transfer_buffer) 338 kfree(ctrl->urb->transfer_buffer);
339 kfree(ctrl->urb->transfer_buffer);
340 usb_free_urb(ctrl->urb); 339 usb_free_urb(ctrl->urb);
341 ctrl->urb = NULL; 340 ctrl->urb = NULL;
342 341
343 usb_kill_urb(intr->urb); 342 usb_kill_urb(intr->urb);
344 if (intr->urb->transfer_buffer) 343 kfree(intr->urb->transfer_buffer);
345 kfree(intr->urb->transfer_buffer);
346 usb_free_urb(intr->urb); 344 usb_free_urb(intr->urb);
347 ctrl->urb = NULL; 345 ctrl->urb = NULL;
348} 346}
@@ -457,8 +455,7 @@ st5481_setup_isocpipes(struct urb* urb[2], struct usb_device *dev,
457 err: 455 err:
458 for (j = 0; j < 2; j++) { 456 for (j = 0; j < 2; j++) {
459 if (urb[j]) { 457 if (urb[j]) {
460 if (urb[j]->transfer_buffer) 458 kfree(urb[j]->transfer_buffer);
461 kfree(urb[j]->transfer_buffer);
462 urb[j]->transfer_buffer = NULL; 459 urb[j]->transfer_buffer = NULL;
463 usb_free_urb(urb[j]); 460 usb_free_urb(urb[j]);
464 urb[j] = NULL; 461 urb[j] = NULL;
@@ -473,8 +470,7 @@ void st5481_release_isocpipes(struct urb* urb[2])
473 470
474 for (j = 0; j < 2; j++) { 471 for (j = 0; j < 2; j++) {
475 usb_kill_urb(urb[j]); 472 usb_kill_urb(urb[j]);
476 if (urb[j]->transfer_buffer) 473 kfree(urb[j]->transfer_buffer);
477 kfree(urb[j]->transfer_buffer);
478 usb_free_urb(urb[j]); 474 usb_free_urb(urb[j]);
479 urb[j] = NULL; 475 urb[j] = NULL;
480 } 476 }
diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
index 7baf8e488471..0352ee5f706c 100644
--- a/drivers/isdn/hisax/w6692.c
+++ b/drivers/isdn/hisax/w6692.c
@@ -819,14 +819,10 @@ close_w6692state(struct BCState *bcs)
819{ 819{
820 W6692Bmode(bcs, 0, bcs->channel); 820 W6692Bmode(bcs, 0, bcs->channel);
821 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) { 821 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
822 if (bcs->hw.w6692.rcvbuf) { 822 kfree(bcs->hw.w6692.rcvbuf);
823 kfree(bcs->hw.w6692.rcvbuf); 823 bcs->hw.w6692.rcvbuf = NULL;
824 bcs->hw.w6692.rcvbuf = NULL; 824 kfree(bcs->blog);
825 } 825 bcs->blog = NULL;
826 if (bcs->blog) {
827 kfree(bcs->blog);
828 bcs->blog = NULL;
829 }
830 skb_queue_purge(&bcs->rqueue); 826 skb_queue_purge(&bcs->rqueue);
831 skb_queue_purge(&bcs->squeue); 827 skb_queue_purge(&bcs->squeue);
832 if (bcs->tx_skb) { 828 if (bcs->tx_skb) {
diff --git a/drivers/isdn/hysdn/hysdn_procconf.c b/drivers/isdn/hysdn/hysdn_procconf.c
index 639582f61f41..87f59a0e2a95 100644
--- a/drivers/isdn/hysdn/hysdn_procconf.c
+++ b/drivers/isdn/hysdn/hysdn_procconf.c
@@ -359,8 +359,7 @@ hysdn_conf_close(struct inode *ino, struct file *filep)
359 } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { 359 } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
360 /* read access -> output card info data */ 360 /* read access -> output card info data */
361 361
362 if (filep->private_data) 362 kfree(filep->private_data); /* release memory */
363 kfree(filep->private_data); /* release memory */
364 } 363 }
365 unlock_kernel(); 364 unlock_kernel();
366 return (retval); 365 return (retval);
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index d97a9be5469c..1a19a0f89428 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -364,10 +364,8 @@ isdn_ppp_release(int min, struct file *file)
364 isdn_net_hangup(&p->dev); 364 isdn_net_hangup(&p->dev);
365 } 365 }
366 for (i = 0; i < NUM_RCV_BUFFS; i++) { 366 for (i = 0; i < NUM_RCV_BUFFS; i++) {
367 if (is->rq[i].buf) { 367 kfree(is->rq[i].buf);
368 kfree(is->rq[i].buf); 368 is->rq[i].buf = NULL;
369 is->rq[i].buf = NULL;
370 }
371 } 369 }
372 is->first = is->rq + NUM_RCV_BUFFS - 1; /* receive queue */ 370 is->first = is->rq + NUM_RCV_BUFFS - 1; /* receive queue */
373 is->last = is->rq; 371 is->last = is->rq;
@@ -378,14 +376,10 @@ isdn_ppp_release(int min, struct file *file)
378 is->slcomp = NULL; 376 is->slcomp = NULL;
379#endif 377#endif
380#ifdef CONFIG_IPPP_FILTER 378#ifdef CONFIG_IPPP_FILTER
381 if (is->pass_filter) { 379 kfree(is->pass_filter);
382 kfree(is->pass_filter); 380 is->pass_filter = NULL;
383 is->pass_filter = NULL; 381 kfree(is->active_filter);
384 } 382 is->active_filter = NULL;
385 if (is->active_filter) {
386 kfree(is->active_filter);
387 is->active_filter = NULL;
388 }
389#endif 383#endif
390 384
391/* TODO: if this was the previous master: link the stuff to the new master */ 385/* TODO: if this was the previous master: link the stuff to the new master */
@@ -914,8 +908,7 @@ isdn_ppp_cleanup(void)
914 kfree(ippp_table[i]); 908 kfree(ippp_table[i]);
915 909
916#ifdef CONFIG_ISDN_MPP 910#ifdef CONFIG_ISDN_MPP
917 if (isdn_ppp_bundle_arr) 911 kfree(isdn_ppp_bundle_arr);
918 kfree(isdn_ppp_bundle_arr);
919#endif /* CONFIG_ISDN_MPP */ 912#endif /* CONFIG_ISDN_MPP */
920 913
921} 914}
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index b37ef1f06b3d..8c404b4e2482 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -712,22 +712,14 @@ isdn_tty_modem_hup(modem_info * info, int local)
712#endif 712#endif
713 info->emu.vpar[4] = 0; 713 info->emu.vpar[4] = 0;
714 info->emu.vpar[5] = 8; 714 info->emu.vpar[5] = 8;
715 if (info->dtmf_state) { 715 kfree(info->dtmf_state);
716 kfree(info->dtmf_state); 716 info->dtmf_state = NULL;
717 info->dtmf_state = NULL; 717 kfree(info->silence_state);
718 } 718 info->silence_state = NULL;
719 if (info->silence_state) { 719 kfree(info->adpcms);
720 kfree(info->silence_state); 720 info->adpcms = NULL;
721 info->silence_state = NULL; 721 kfree(info->adpcmr);
722 } 722 info->adpcmr = NULL;
723 if (info->adpcms) {
724 kfree(info->adpcms);
725 info->adpcms = NULL;
726 }
727 if (info->adpcmr) {
728 kfree(info->adpcmr);
729 info->adpcmr = NULL;
730 }
731#endif 723#endif
732 if ((info->msr & UART_MSR_RI) && 724 if ((info->msr & UART_MSR_RI) &&
733 (info->emu.mdmreg[REG_RUNG] & BIT_RUNG)) 725 (info->emu.mdmreg[REG_RUNG] & BIT_RUNG))
@@ -1721,8 +1713,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
1721 */ 1713 */
1722 timeout = jiffies + HZ; 1714 timeout = jiffies + HZ;
1723 while (!(info->lsr & UART_LSR_TEMT)) { 1715 while (!(info->lsr & UART_LSR_TEMT)) {
1724 set_current_state(TASK_INTERRUPTIBLE); 1716 schedule_timeout_interruptible(20);
1725 schedule_timeout(20);
1726 if (time_after(jiffies,timeout)) 1717 if (time_after(jiffies,timeout))
1727 break; 1718 break;
1728 } 1719 }
diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
index 386df71eee74..6649f8bc9951 100644
--- a/drivers/isdn/icn/icn.c
+++ b/drivers/isdn/icn/icn.c
@@ -947,8 +947,7 @@ icn_loadproto(u_char __user * buffer, icn_card * card)
947 icn_maprelease_channel(card, 0); 947 icn_maprelease_channel(card, 0);
948 return -EIO; 948 return -EIO;
949 } 949 }
950 set_current_state(TASK_INTERRUPTIBLE); 950 schedule_timeout_interruptible(10);
951 schedule_timeout(10);
952 } 951 }
953 } 952 }
954 writeb(0x20, &sbuf_n); 953 writeb(0x20, &sbuf_n);
diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c
index 14e1f8fbc61f..33d339700411 100644
--- a/drivers/isdn/isdnloop/isdnloop.c
+++ b/drivers/isdn/isdnloop/isdnloop.c
@@ -1161,12 +1161,9 @@ isdnloop_command(isdn_ctrl * c, isdnloop_card * card)
1161 if (a) { 1161 if (a) {
1162 if (!card->leased) { 1162 if (!card->leased) {
1163 card->leased = 1; 1163 card->leased = 1;
1164 while (card->ptype == ISDN_PTYPE_UNKNOWN) { 1164 while (card->ptype == ISDN_PTYPE_UNKNOWN)
1165 set_current_state(TASK_INTERRUPTIBLE); 1165 schedule_timeout_interruptible(10);
1166 schedule_timeout(10); 1166 schedule_timeout_interruptible(10);
1167 }
1168 set_current_state(TASK_INTERRUPTIBLE);
1169 schedule_timeout(10);
1170 sprintf(cbuf, "00;FV2ON\n01;EAZ1\n02;EAZ2\n"); 1167 sprintf(cbuf, "00;FV2ON\n01;EAZ1\n02;EAZ2\n");
1171 i = isdnloop_writecmd(cbuf, strlen(cbuf), 0, card); 1168 i = isdnloop_writecmd(cbuf, strlen(cbuf), 0, card);
1172 printk(KERN_INFO 1169 printk(KERN_INFO
diff --git a/drivers/isdn/pcbit/drv.c b/drivers/isdn/pcbit/drv.c
index 5de861f40816..94f21486bb24 100644
--- a/drivers/isdn/pcbit/drv.c
+++ b/drivers/isdn/pcbit/drv.c
@@ -561,10 +561,8 @@ void pcbit_l3_receive(struct pcbit_dev * dev, ulong msg,
561 else 561 else
562 pcbit_fsm_event(dev, chan, EV_USR_RELEASE_REQ, NULL); 562 pcbit_fsm_event(dev, chan, EV_USR_RELEASE_REQ, NULL);
563 563
564 if (cbdata.data.setup.CalledPN) 564 kfree(cbdata.data.setup.CalledPN);
565 kfree(cbdata.data.setup.CalledPN); 565 kfree(cbdata.data.setup.CallingPN);
566 if (cbdata.data.setup.CallingPN)
567 kfree(cbdata.data.setup.CallingPN);
568 break; 566 break;
569 567
570 case MSG_CONN_CONF: 568 case MSG_CONN_CONF:
diff --git a/drivers/isdn/sc/init.c b/drivers/isdn/sc/init.c
index 1ebed041672d..62b7acfad8a4 100644
--- a/drivers/isdn/sc/init.c
+++ b/drivers/isdn/sc/init.c
@@ -529,8 +529,7 @@ static int identify_board(unsigned long rambase, unsigned int iobase)
529 */ 529 */
530 x = 0; 530 x = 0;
531 while((inb(iobase + FIFOSTAT_OFFSET) & RF_HAS_DATA) && x < 100) { 531 while((inb(iobase + FIFOSTAT_OFFSET) & RF_HAS_DATA) && x < 100) {
532 set_current_state(TASK_INTERRUPTIBLE); 532 schedule_timeout_interruptible(1);
533 schedule_timeout(1);
534 x++; 533 x++;
535 } 534 }
536 if(x == 100) { 535 if(x == 100) {
diff --git a/drivers/isdn/sc/message.c b/drivers/isdn/sc/message.c
index ca204da3257d..0a0fe6b8039b 100644
--- a/drivers/isdn/sc/message.c
+++ b/drivers/isdn/sc/message.c
@@ -208,8 +208,7 @@ int send_and_receive(int card,
208 tries = 0; 208 tries = 0;
209 /* wait for the response */ 209 /* wait for the response */
210 while (tries < timeout) { 210 while (tries < timeout) {
211 set_current_state(TASK_INTERRUPTIBLE); 211 schedule_timeout_interruptible(1);
212 schedule_timeout(1);
213 212
214 pr_debug("SAR waiting..\n"); 213 pr_debug("SAR waiting..\n");
215 214
diff --git a/drivers/macintosh/adbhid.c b/drivers/macintosh/adbhid.c
index 8f02c155fdc0..c0b46bceb5df 100644
--- a/drivers/macintosh/adbhid.c
+++ b/drivers/macintosh/adbhid.c
@@ -857,8 +857,7 @@ adbhid_input_register(int id, int default_id, int original_handler_id,
857static void adbhid_input_unregister(int id) 857static void adbhid_input_unregister(int id)
858{ 858{
859 input_unregister_device(adbhid[id]->input); 859 input_unregister_device(adbhid[id]->input);
860 if (adbhid[id]->keycode) 860 kfree(adbhid[id]->keycode);
861 kfree(adbhid[id]->keycode);
862 kfree(adbhid[id]); 861 kfree(adbhid[id]);
863 adbhid[id] = NULL; 862 adbhid[id] = NULL;
864} 863}
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c
index cc507ceef153..3fc8cdd94c3d 100644
--- a/drivers/macintosh/therm_pm72.c
+++ b/drivers/macintosh/therm_pm72.c
@@ -1678,10 +1678,9 @@ static int main_control_loop(void *x)
1678 } 1678 }
1679 1679
1680 // FIXME: Deal with signals 1680 // FIXME: Deal with signals
1681 set_current_state(TASK_INTERRUPTIBLE);
1682 elapsed = jiffies - start; 1681 elapsed = jiffies - start;
1683 if (elapsed < HZ) 1682 if (elapsed < HZ)
1684 schedule_timeout(HZ - elapsed); 1683 schedule_timeout_interruptible(HZ - elapsed);
1685 } 1684 }
1686 1685
1687 out: 1686 out:
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 6497295ebfb9..1223e98ecd70 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -1587,8 +1587,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1587 /* make sure we don't swamp the stripe cache if someone else 1587 /* make sure we don't swamp the stripe cache if someone else
1588 * is trying to get access 1588 * is trying to get access
1589 */ 1589 */
1590 set_current_state(TASK_UNINTERRUPTIBLE); 1590 schedule_timeout_uninterruptible(1);
1591 schedule_timeout(1);
1592 } 1591 }
1593 bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 0); 1592 bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 0);
1594 spin_lock(&sh->lock); 1593 spin_lock(&sh->lock);
diff --git a/drivers/md/raid6main.c b/drivers/md/raid6main.c
index 6437a95ffc1c..775786947701 100644
--- a/drivers/md/raid6main.c
+++ b/drivers/md/raid6main.c
@@ -1746,8 +1746,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1746 /* make sure we don't swamp the stripe cache if someone else 1746 /* make sure we don't swamp the stripe cache if someone else
1747 * is trying to get access 1747 * is trying to get access
1748 */ 1748 */
1749 set_current_state(TASK_UNINTERRUPTIBLE); 1749 schedule_timeout_uninterruptible(1);
1750 schedule_timeout(1);
1751 } 1750 }
1752 bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 0); 1751 bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 0);
1753 spin_lock(&sh->lock); 1752 spin_lock(&sh->lock);
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 34a837a1abf4..b3c9d7327ac1 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1331,9 +1331,7 @@ struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_ad
1331{ 1331{
1332 /* check if the ASIC is there */ 1332 /* check if the ASIC is there */
1333 if (dst_probe(state) < 0) { 1333 if (dst_probe(state) < 0) {
1334 if (state) 1334 kfree(state);
1335 kfree(state);
1336
1337 return NULL; 1335 return NULL;
1338 } 1336 }
1339 /* determine settings based on type */ 1337 /* determine settings based on type */
@@ -1349,9 +1347,7 @@ struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_ad
1349 break; 1347 break;
1350 default: 1348 default:
1351 dprintk(verbose, DST_ERROR, 1, "unknown DST type. please report to the LinuxTV.org DVB mailinglist."); 1349 dprintk(verbose, DST_ERROR, 1, "unknown DST type. please report to the LinuxTV.org DVB mailinglist.");
1352 if (state) 1350 kfree(state);
1353 kfree(state);
1354
1355 return NULL; 1351 return NULL;
1356 } 1352 }
1357 1353
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index d4b97989e3ed..654d7dc879d9 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -27,6 +27,7 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/jiffies.h>
30 31
31#include "dvb_frontend.h" 32#include "dvb_frontend.h"
32#include "cx24110.h" 33#include "cx24110.h"
diff --git a/drivers/media/dvb/frontends/dvb_dummy_fe.c b/drivers/media/dvb/frontends/dvb_dummy_fe.c
index 794be520d590..645946a992d9 100644
--- a/drivers/media/dvb/frontends/dvb_dummy_fe.c
+++ b/drivers/media/dvb/frontends/dvb_dummy_fe.c
@@ -148,7 +148,7 @@ struct dvb_frontend* dvb_dummy_fe_qpsk_attach()
148 return &state->frontend; 148 return &state->frontend;
149 149
150error: 150error:
151 if (state) kfree(state); 151 kfree(state);
152 return NULL; 152 return NULL;
153} 153}
154 154
@@ -171,7 +171,7 @@ struct dvb_frontend* dvb_dummy_fe_qam_attach()
171 return &state->frontend; 171 return &state->frontend;
172 172
173error: 173error:
174 if (state) kfree(state); 174 kfree(state);
175 return NULL; 175 return NULL;
176} 176}
177 177
diff --git a/drivers/media/dvb/frontends/l64781.c b/drivers/media/dvb/frontends/l64781.c
index faaad1ae8559..19b4bf7c21a7 100644
--- a/drivers/media/dvb/frontends/l64781.c
+++ b/drivers/media/dvb/frontends/l64781.c
@@ -559,7 +559,8 @@ struct dvb_frontend* l64781_attach(const struct l64781_config* config,
559 return &state->frontend; 559 return &state->frontend;
560 560
561error: 561error:
562 if (reg0x3e >= 0) l64781_writereg (state, 0x3e, reg0x3e); /* restore reg 0x3e */ 562 if (reg0x3e >= 0)
563 l64781_writereg (state, 0x3e, reg0x3e); /* restore reg 0x3e */
563 kfree(state); 564 kfree(state);
564 return NULL; 565 return NULL;
565} 566}
diff --git a/drivers/media/dvb/frontends/lgdt330x.c b/drivers/media/dvb/frontends/lgdt330x.c
index 8dde72bd1046..7852b83b82d4 100644
--- a/drivers/media/dvb/frontends/lgdt330x.c
+++ b/drivers/media/dvb/frontends/lgdt330x.c
@@ -731,8 +731,7 @@ struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config,
731 return &state->frontend; 731 return &state->frontend;
732 732
733error: 733error:
734 if (state) 734 kfree(state);
735 kfree(state);
736 dprintk("%s: ERROR\n",__FUNCTION__); 735 dprintk("%s: ERROR\n",__FUNCTION__);
737 return NULL; 736 return NULL;
738} 737}
diff --git a/drivers/media/dvb/frontends/mt312.c b/drivers/media/dvb/frontends/mt312.c
index e38454901dd1..9c67f406d581 100644
--- a/drivers/media/dvb/frontends/mt312.c
+++ b/drivers/media/dvb/frontends/mt312.c
@@ -677,8 +677,7 @@ struct dvb_frontend* mt312_attach(const struct mt312_config* config,
677 return &state->frontend; 677 return &state->frontend;
678 678
679error: 679error:
680 if (state) 680 kfree(state);
681 kfree(state);
682 return NULL; 681 return NULL;
683} 682}
684 683
diff --git a/drivers/media/dvb/frontends/or51132.c b/drivers/media/dvb/frontends/or51132.c
index 817b044c7fd1..fc74c40d6477 100644
--- a/drivers/media/dvb/frontends/or51132.c
+++ b/drivers/media/dvb/frontends/or51132.c
@@ -577,8 +577,7 @@ struct dvb_frontend* or51132_attach(const struct or51132_config* config,
577 return &state->frontend; 577 return &state->frontend;
578 578
579error: 579error:
580 if (state) 580 kfree(state);
581 kfree(state);
582 return NULL; 581 return NULL;
583} 582}
584 583
diff --git a/drivers/media/video/arv.c b/drivers/media/video/arv.c
index 87fd3a7bb392..0823ddaf7004 100644
--- a/drivers/media/video/arv.c
+++ b/drivers/media/video/arv.c
@@ -865,10 +865,8 @@ out_dev:
865 865
866out_irq: 866out_irq:
867#endif 867#endif
868 for (i = 0; i < MAX_AR_HEIGHT; i++) { 868 for (i = 0; i < MAX_AR_HEIGHT; i++)
869 if (ar->frame[i]) 869 kfree(ar->frame[i]);
870 kfree(ar->frame[i]);
871 }
872 870
873out_line_buff: 871out_line_buff:
874#if USE_INT 872#if USE_INT
@@ -899,10 +897,8 @@ static void __exit ar_cleanup_module(void)
899#if USE_INT 897#if USE_INT
900 free_irq(M32R_IRQ_INT3, ar); 898 free_irq(M32R_IRQ_INT3, ar);
901#endif 899#endif
902 for (i = 0; i < MAX_AR_HEIGHT; i++) { 900 for (i = 0; i < MAX_AR_HEIGHT; i++)
903 if (ar->frame[i]) 901 kfree(ar->frame[i]);
904 kfree(ar->frame[i]);
905 }
906#if USE_INT 902#if USE_INT
907 kfree(ar->line_buff); 903 kfree(ar->line_buff);
908#endif 904#endif
diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bttv-driver.c
index c062a017491e..d538a994ff04 100644
--- a/drivers/media/video/bttv-driver.c
+++ b/drivers/media/video/bttv-driver.c
@@ -1951,8 +1951,7 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv,
1951 } 1951 }
1952 1952
1953 down(&fh->cap.lock); 1953 down(&fh->cap.lock);
1954 if (fh->ov.clips) 1954 kfree(fh->ov.clips);
1955 kfree(fh->ov.clips);
1956 fh->ov.clips = clips; 1955 fh->ov.clips = clips;
1957 fh->ov.nclips = n; 1956 fh->ov.nclips = n;
1958 1957
@@ -2723,8 +2722,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2723 fh->ov.w.height = fb->fmt.height; 2722 fh->ov.w.height = fb->fmt.height;
2724 btv->init.ov.w.width = fb->fmt.width; 2723 btv->init.ov.w.width = fb->fmt.width;
2725 btv->init.ov.w.height = fb->fmt.height; 2724 btv->init.ov.w.height = fb->fmt.height;
2726 if (fh->ov.clips) 2725 kfree(fh->ov.clips);
2727 kfree(fh->ov.clips);
2728 fh->ov.clips = NULL; 2726 fh->ov.clips = NULL;
2729 fh->ov.nclips = 0; 2727 fh->ov.nclips = 0;
2730 2728
diff --git a/drivers/media/video/indycam.c b/drivers/media/video/indycam.c
index 26dd06ec89a2..deeef125eb92 100644
--- a/drivers/media/video/indycam.c
+++ b/drivers/media/video/indycam.c
@@ -27,15 +27,15 @@
27 27
28#include "indycam.h" 28#include "indycam.h"
29 29
30//#define INDYCAM_DEBUG 30#define INDYCAM_MODULE_VERSION "0.0.5"
31
32#define INDYCAM_MODULE_VERSION "0.0.3"
33 31
34MODULE_DESCRIPTION("SGI IndyCam driver"); 32MODULE_DESCRIPTION("SGI IndyCam driver");
35MODULE_VERSION(INDYCAM_MODULE_VERSION); 33MODULE_VERSION(INDYCAM_MODULE_VERSION);
36MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>"); 34MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
37MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
38 36
37// #define INDYCAM_DEBUG
38
39#ifdef INDYCAM_DEBUG 39#ifdef INDYCAM_DEBUG
40#define dprintk(x...) printk("IndyCam: " x); 40#define dprintk(x...) printk("IndyCam: " x);
41#define indycam_regdump(client) indycam_regdump_debug(client) 41#define indycam_regdump(client) indycam_regdump_debug(client)
@@ -46,14 +46,14 @@ MODULE_LICENSE("GPL");
46 46
47struct indycam { 47struct indycam {
48 struct i2c_client *client; 48 struct i2c_client *client;
49 int version; 49 u8 version;
50}; 50};
51 51
52static struct i2c_driver i2c_driver_indycam; 52static struct i2c_driver i2c_driver_indycam;
53 53
54static const unsigned char initseq[] = { 54static const u8 initseq[] = {
55 INDYCAM_CONTROL_AGCENA, /* INDYCAM_CONTROL */ 55 INDYCAM_CONTROL_AGCENA, /* INDYCAM_CONTROL */
56 INDYCAM_SHUTTER_DEFAULT, /* INDYCAM_SHUTTER */ 56 INDYCAM_SHUTTER_60, /* INDYCAM_SHUTTER */
57 INDYCAM_GAIN_DEFAULT, /* INDYCAM_GAIN */ 57 INDYCAM_GAIN_DEFAULT, /* INDYCAM_GAIN */
58 0x00, /* INDYCAM_BRIGHTNESS (read-only) */ 58 0x00, /* INDYCAM_BRIGHTNESS (read-only) */
59 INDYCAM_RED_BALANCE_DEFAULT, /* INDYCAM_RED_BALANCE */ 59 INDYCAM_RED_BALANCE_DEFAULT, /* INDYCAM_RED_BALANCE */
@@ -64,12 +64,11 @@ static const unsigned char initseq[] = {
64 64
65/* IndyCam register handling */ 65/* IndyCam register handling */
66 66
67static int indycam_read_reg(struct i2c_client *client, unsigned char reg, 67static int indycam_read_reg(struct i2c_client *client, u8 reg, u8 *value)
68 unsigned char *value)
69{ 68{
70 int ret; 69 int ret;
71 70
72 if (reg == INDYCAM_RESET) { 71 if (reg == INDYCAM_REG_RESET) {
73 dprintk("indycam_read_reg(): " 72 dprintk("indycam_read_reg(): "
74 "skipping write-only register %d\n", reg); 73 "skipping write-only register %d\n", reg);
75 *value = 0; 74 *value = 0;
@@ -77,24 +76,24 @@ static int indycam_read_reg(struct i2c_client *client, unsigned char reg,
77 } 76 }
78 77
79 ret = i2c_smbus_read_byte_data(client, reg); 78 ret = i2c_smbus_read_byte_data(client, reg);
79
80 if (ret < 0) { 80 if (ret < 0) {
81 printk(KERN_ERR "IndyCam: indycam_read_reg(): read failed, " 81 printk(KERN_ERR "IndyCam: indycam_read_reg(): read failed, "
82 "register = 0x%02x\n", reg); 82 "register = 0x%02x\n", reg);
83 return ret; 83 return ret;
84 } 84 }
85 85
86 *value = (unsigned char)ret; 86 *value = (u8)ret;
87 87
88 return 0; 88 return 0;
89} 89}
90 90
91static int indycam_write_reg(struct i2c_client *client, unsigned char reg, 91static int indycam_write_reg(struct i2c_client *client, u8 reg, u8 value)
92 unsigned char value)
93{ 92{
94 int err; 93 int err;
95 94
96 if ((reg == INDYCAM_BRIGHTNESS) 95 if ((reg == INDYCAM_REG_BRIGHTNESS)
97 || (reg == INDYCAM_VERSION)) { 96 || (reg == INDYCAM_REG_VERSION)) {
98 dprintk("indycam_write_reg(): " 97 dprintk("indycam_write_reg(): "
99 "skipping read-only register %d\n", reg); 98 "skipping read-only register %d\n", reg);
100 return 0; 99 return 0;
@@ -102,6 +101,7 @@ static int indycam_write_reg(struct i2c_client *client, unsigned char reg,
102 101
103 dprintk("Writing Reg %d = 0x%02x\n", reg, value); 102 dprintk("Writing Reg %d = 0x%02x\n", reg, value);
104 err = i2c_smbus_write_byte_data(client, reg, value); 103 err = i2c_smbus_write_byte_data(client, reg, value);
104
105 if (err) { 105 if (err) {
106 printk(KERN_ERR "IndyCam: indycam_write_reg(): write failed, " 106 printk(KERN_ERR "IndyCam: indycam_write_reg(): write failed, "
107 "register = 0x%02x, value = 0x%02x\n", reg, value); 107 "register = 0x%02x, value = 0x%02x\n", reg, value);
@@ -109,13 +109,12 @@ static int indycam_write_reg(struct i2c_client *client, unsigned char reg,
109 return err; 109 return err;
110} 110}
111 111
112static int indycam_write_block(struct i2c_client *client, unsigned char reg, 112static int indycam_write_block(struct i2c_client *client, u8 reg,
113 unsigned char length, unsigned char *data) 113 u8 length, u8 *data)
114{ 114{
115 unsigned char i; 115 int i, err;
116 int err;
117 116
118 for (i = reg; i < length; i++) { 117 for (i = 0; i < length; i++) {
119 err = indycam_write_reg(client, reg + i, data[i]); 118 err = indycam_write_reg(client, reg + i, data[i]);
120 if (err) 119 if (err)
121 return err; 120 return err;
@@ -130,7 +129,7 @@ static int indycam_write_block(struct i2c_client *client, unsigned char reg,
130static void indycam_regdump_debug(struct i2c_client *client) 129static void indycam_regdump_debug(struct i2c_client *client)
131{ 130{
132 int i; 131 int i;
133 unsigned char val; 132 u8 val;
134 133
135 for (i = 0; i < 9; i++) { 134 for (i = 0; i < 9; i++) {
136 indycam_read_reg(client, i, &val); 135 indycam_read_reg(client, i, &val);
@@ -139,76 +138,144 @@ static void indycam_regdump_debug(struct i2c_client *client)
139} 138}
140#endif 139#endif
141 140
142static int indycam_get_controls(struct i2c_client *client, 141static int indycam_get_control(struct i2c_client *client,
143 struct indycam_control *ctrl) 142 struct indycam_control *ctrl)
144{ 143{
145 unsigned char ctrl_reg; 144 struct indycam *camera = i2c_get_clientdata(client);
146 145 u8 reg;
147 indycam_read_reg(client, INDYCAM_CONTROL, &ctrl_reg); 146 int ret = 0;
148 ctrl->agc = (ctrl_reg & INDYCAM_CONTROL_AGCENA) 147
149 ? INDYCAM_VALUE_ENABLED 148 switch (ctrl->type) {
150 : INDYCAM_VALUE_DISABLED; 149 case INDYCAM_CONTROL_AGC:
151 ctrl->awb = (ctrl_reg & INDYCAM_CONTROL_AWBCTL) 150 case INDYCAM_CONTROL_AWB:
152 ? INDYCAM_VALUE_ENABLED 151 ret = indycam_read_reg(client, INDYCAM_REG_CONTROL, &reg);
153 : INDYCAM_VALUE_DISABLED; 152 if (ret)
154 indycam_read_reg(client, INDYCAM_SHUTTER, 153 return -EIO;
155 (unsigned char *)&ctrl->shutter); 154 if (ctrl->type == INDYCAM_CONTROL_AGC)
156 indycam_read_reg(client, INDYCAM_GAIN, 155 ctrl->value = (reg & INDYCAM_CONTROL_AGCENA)
157 (unsigned char *)&ctrl->gain); 156 ? 1 : 0;
158 indycam_read_reg(client, INDYCAM_RED_BALANCE, 157 else
159 (unsigned char *)&ctrl->red_balance); 158 ctrl->value = (reg & INDYCAM_CONTROL_AWBCTL)
160 indycam_read_reg(client, INDYCAM_BLUE_BALANCE, 159 ? 1 : 0;
161 (unsigned char *)&ctrl->blue_balance); 160 break;
162 indycam_read_reg(client, INDYCAM_RED_SATURATION, 161 case INDYCAM_CONTROL_SHUTTER:
163 (unsigned char *)&ctrl->red_saturation); 162 ret = indycam_read_reg(client, INDYCAM_REG_SHUTTER, &reg);
164 indycam_read_reg(client, INDYCAM_BLUE_SATURATION, 163 if (ret)
165 (unsigned char *)&ctrl->blue_saturation); 164 return -EIO;
166 indycam_read_reg(client, INDYCAM_GAMMA, 165 ctrl->value = ((s32)reg == 0x00) ? 0xff : ((s32)reg - 1);
167 (unsigned char *)&ctrl->gamma); 166 break;
167 case INDYCAM_CONTROL_GAIN:
168 ret = indycam_read_reg(client, INDYCAM_REG_GAIN, &reg);
169 if (ret)
170 return -EIO;
171 ctrl->value = (s32)reg;
172 break;
173 case INDYCAM_CONTROL_RED_BALANCE:
174 ret = indycam_read_reg(client, INDYCAM_REG_RED_BALANCE, &reg);
175 if (ret)
176 return -EIO;
177 ctrl->value = (s32)reg;
178 break;
179 case INDYCAM_CONTROL_BLUE_BALANCE:
180 ret = indycam_read_reg(client, INDYCAM_REG_BLUE_BALANCE, &reg);
181 if (ret)
182 return -EIO;
183 ctrl->value = (s32)reg;
184 break;
185 case INDYCAM_CONTROL_RED_SATURATION:
186 ret = indycam_read_reg(client,
187 INDYCAM_REG_RED_SATURATION, &reg);
188 if (ret)
189 return -EIO;
190 ctrl->value = (s32)reg;
191 break;
192 case INDYCAM_CONTROL_BLUE_SATURATION:
193 ret = indycam_read_reg(client,
194 INDYCAM_REG_BLUE_SATURATION, &reg);
195 if (ret)
196 return -EIO;
197 ctrl->value = (s32)reg;
198 break;
199 case INDYCAM_CONTROL_GAMMA:
200 if (camera->version == CAMERA_VERSION_MOOSE) {
201 ret = indycam_read_reg(client,
202 INDYCAM_REG_GAMMA, &reg);
203 if (ret)
204 return -EIO;
205 ctrl->value = (s32)reg;
206 } else {
207 ctrl->value = INDYCAM_GAMMA_DEFAULT;
208 }
209 break;
210 default:
211 ret = -EINVAL;
212 }
168 213
169 return 0; 214 return ret;
170} 215}
171 216
172static int indycam_set_controls(struct i2c_client *client, 217static int indycam_set_control(struct i2c_client *client,
173 struct indycam_control *ctrl) 218 struct indycam_control *ctrl)
174{ 219{
175 unsigned char ctrl_reg; 220 struct indycam *camera = i2c_get_clientdata(client);
221 u8 reg;
222 int ret = 0;
223
224 switch (ctrl->type) {
225 case INDYCAM_CONTROL_AGC:
226 case INDYCAM_CONTROL_AWB:
227 ret = indycam_read_reg(client, INDYCAM_REG_CONTROL, &reg);
228 if (ret)
229 break;
176 230
177 indycam_read_reg(client, INDYCAM_CONTROL, &ctrl_reg); 231 if (ctrl->type == INDYCAM_CONTROL_AGC) {
178 if (ctrl->agc != INDYCAM_VALUE_UNCHANGED) { 232 if (ctrl->value)
179 if (ctrl->agc) 233 reg |= INDYCAM_CONTROL_AGCENA;
180 ctrl_reg |= INDYCAM_CONTROL_AGCENA; 234 else
181 else 235 reg &= ~INDYCAM_CONTROL_AGCENA;
182 ctrl_reg &= ~INDYCAM_CONTROL_AGCENA; 236 } else {
183 } 237 if (ctrl->value)
184 if (ctrl->awb != INDYCAM_VALUE_UNCHANGED) { 238 reg |= INDYCAM_CONTROL_AWBCTL;
185 if (ctrl->awb) 239 else
186 ctrl_reg |= INDYCAM_CONTROL_AWBCTL; 240 reg &= ~INDYCAM_CONTROL_AWBCTL;
187 else 241 }
188 ctrl_reg &= ~INDYCAM_CONTROL_AWBCTL; 242
243 ret = indycam_write_reg(client, INDYCAM_REG_CONTROL, reg);
244 break;
245 case INDYCAM_CONTROL_SHUTTER:
246 reg = (ctrl->value == 0xff) ? 0x00 : (ctrl->value + 1);
247 ret = indycam_write_reg(client, INDYCAM_REG_SHUTTER, reg);
248 break;
249 case INDYCAM_CONTROL_GAIN:
250 ret = indycam_write_reg(client, INDYCAM_REG_GAIN, ctrl->value);
251 break;
252 case INDYCAM_CONTROL_RED_BALANCE:
253 ret = indycam_write_reg(client, INDYCAM_REG_RED_BALANCE,
254 ctrl->value);
255 break;
256 case INDYCAM_CONTROL_BLUE_BALANCE:
257 ret = indycam_write_reg(client, INDYCAM_REG_BLUE_BALANCE,
258 ctrl->value);
259 break;
260 case INDYCAM_CONTROL_RED_SATURATION:
261 ret = indycam_write_reg(client, INDYCAM_REG_RED_SATURATION,
262 ctrl->value);
263 break;
264 case INDYCAM_CONTROL_BLUE_SATURATION:
265 ret = indycam_write_reg(client, INDYCAM_REG_BLUE_SATURATION,
266 ctrl->value);
267 break;
268 case INDYCAM_CONTROL_GAMMA:
269 if (camera->version == CAMERA_VERSION_MOOSE) {
270 ret = indycam_write_reg(client, INDYCAM_REG_GAMMA,
271 ctrl->value);
272 }
273 break;
274 default:
275 ret = -EINVAL;
189 } 276 }
190 indycam_write_reg(client, INDYCAM_CONTROL, ctrl_reg);
191
192 if (ctrl->shutter >= 0)
193 indycam_write_reg(client, INDYCAM_SHUTTER, ctrl->shutter);
194 if (ctrl->gain >= 0)
195 indycam_write_reg(client, INDYCAM_GAIN, ctrl->gain);
196 if (ctrl->red_balance >= 0)
197 indycam_write_reg(client, INDYCAM_RED_BALANCE,
198 ctrl->red_balance);
199 if (ctrl->blue_balance >= 0)
200 indycam_write_reg(client, INDYCAM_BLUE_BALANCE,
201 ctrl->blue_balance);
202 if (ctrl->red_saturation >= 0)
203 indycam_write_reg(client, INDYCAM_RED_SATURATION,
204 ctrl->red_saturation);
205 if (ctrl->blue_saturation >= 0)
206 indycam_write_reg(client, INDYCAM_BLUE_SATURATION,
207 ctrl->blue_saturation);
208 if (ctrl->gamma >= 0)
209 indycam_write_reg(client, INDYCAM_GAMMA, ctrl->gamma);
210 277
211 return 0; 278 return ret;
212} 279}
213 280
214/* I2C-interface */ 281/* I2C-interface */
@@ -247,7 +314,8 @@ static int indycam_attach(struct i2c_adapter *adap, int addr, int kind)
247 if (err) 314 if (err)
248 goto out_free_camera; 315 goto out_free_camera;
249 316
250 camera->version = i2c_smbus_read_byte_data(client, INDYCAM_VERSION); 317 camera->version = i2c_smbus_read_byte_data(client,
318 INDYCAM_REG_VERSION);
251 if (camera->version != CAMERA_VERSION_INDY && 319 if (camera->version != CAMERA_VERSION_INDY &&
252 camera->version != CAMERA_VERSION_MOOSE) { 320 camera->version != CAMERA_VERSION_MOOSE) {
253 err = -ENODEV; 321 err = -ENODEV;
@@ -260,8 +328,7 @@ static int indycam_attach(struct i2c_adapter *adap, int addr, int kind)
260 indycam_regdump(client); 328 indycam_regdump(client);
261 329
262 // initialize 330 // initialize
263 err = indycam_write_block(client, 0, sizeof(initseq), 331 err = indycam_write_block(client, 0, sizeof(initseq), (u8 *)&initseq);
264 (unsigned char *)&initseq);
265 if (err) { 332 if (err) {
266 printk(KERN_ERR "IndyCam initalization failed\n"); 333 printk(KERN_ERR "IndyCam initalization failed\n");
267 err = -EIO; 334 err = -EIO;
@@ -271,11 +338,10 @@ static int indycam_attach(struct i2c_adapter *adap, int addr, int kind)
271 indycam_regdump(client); 338 indycam_regdump(client);
272 339
273 // white balance 340 // white balance
274 err = indycam_write_reg(client, INDYCAM_CONTROL, 341 err = indycam_write_reg(client, INDYCAM_REG_CONTROL,
275 INDYCAM_CONTROL_AGCENA | INDYCAM_CONTROL_AWBCTL); 342 INDYCAM_CONTROL_AGCENA | INDYCAM_CONTROL_AWBCTL);
276 if (err) { 343 if (err) {
277 printk(KERN_ERR "IndyCam white balance " 344 printk(KERN_ERR "IndyCam: White balancing camera failed\n");
278 "initialization failed\n");
279 err = -EIO; 345 err = -EIO;
280 goto out_detach_client; 346 goto out_detach_client;
281 } 347 }
@@ -371,13 +437,11 @@ static int indycam_command(struct i2c_client *client, unsigned int cmd,
371 /* TODO: convert values for indycam_set_controls() */ 437 /* TODO: convert values for indycam_set_controls() */
372 break; 438 break;
373 } 439 }
374 case DECODER_INDYCAM_GET_CONTROLS: { 440 case DECODER_INDYCAM_GET_CONTROL: {
375 struct indycam_control *ctrl = arg; 441 return indycam_get_control(client, arg);
376 indycam_get_controls(client, ctrl);
377 } 442 }
378 case DECODER_INDYCAM_SET_CONTROLS: { 443 case DECODER_INDYCAM_SET_CONTROL: {
379 struct indycam_control *ctrl = arg; 444 return indycam_set_control(client, arg);
380 indycam_set_controls(client, ctrl);
381 } 445 }
382 default: 446 default:
383 return -EINVAL; 447 return -EINVAL;
@@ -388,12 +452,12 @@ static int indycam_command(struct i2c_client *client, unsigned int cmd,
388 452
389static struct i2c_driver i2c_driver_indycam = { 453static struct i2c_driver i2c_driver_indycam = {
390 .owner = THIS_MODULE, 454 .owner = THIS_MODULE,
391 .name = "indycam", 455 .name = "indycam",
392 .id = I2C_DRIVERID_INDYCAM, 456 .id = I2C_DRIVERID_INDYCAM,
393 .flags = I2C_DF_NOTIFY, 457 .flags = I2C_DF_NOTIFY,
394 .attach_adapter = indycam_probe, 458 .attach_adapter = indycam_probe,
395 .detach_client = indycam_detach, 459 .detach_client = indycam_detach,
396 .command = indycam_command, 460 .command = indycam_command,
397}; 461};
398 462
399static int __init indycam_init(void) 463static int __init indycam_init(void)
diff --git a/drivers/media/video/indycam.h b/drivers/media/video/indycam.h
index d9ddb6b79a03..e6ee82063ed8 100644
--- a/drivers/media/video/indycam.h
+++ b/drivers/media/video/indycam.h
@@ -22,21 +22,21 @@
22#define INDYCAM_VERSION_MINOR(x) ((x) & 0x0f) 22#define INDYCAM_VERSION_MINOR(x) ((x) & 0x0f)
23 23
24/* Register bus addresses */ 24/* Register bus addresses */
25#define INDYCAM_CONTROL 0x00 25#define INDYCAM_REG_CONTROL 0x00
26#define INDYCAM_SHUTTER 0x01 26#define INDYCAM_REG_SHUTTER 0x01
27#define INDYCAM_GAIN 0x02 27#define INDYCAM_REG_GAIN 0x02
28#define INDYCAM_BRIGHTNESS 0x03 /* read-only */ 28#define INDYCAM_REG_BRIGHTNESS 0x03 /* read-only */
29#define INDYCAM_RED_BALANCE 0x04 29#define INDYCAM_REG_RED_BALANCE 0x04
30#define INDYCAM_BLUE_BALANCE 0x05 30#define INDYCAM_REG_BLUE_BALANCE 0x05
31#define INDYCAM_RED_SATURATION 0x06 31#define INDYCAM_REG_RED_SATURATION 0x06
32#define INDYCAM_BLUE_SATURATION 0x07 32#define INDYCAM_REG_BLUE_SATURATION 0x07
33#define INDYCAM_GAMMA 0x08 33#define INDYCAM_REG_GAMMA 0x08
34#define INDYCAM_VERSION 0x0e /* read-only */ 34#define INDYCAM_REG_VERSION 0x0e /* read-only */
35#define INDYCAM_RESET 0x0f /* write-only */ 35#define INDYCAM_REG_RESET 0x0f /* write-only */
36 36
37#define INDYCAM_LED 0x46 37#define INDYCAM_REG_LED 0x46
38#define INDYCAM_ORIENTATION 0x47 38#define INDYCAM_REG_ORIENTATION 0x47
39#define INDYCAM_BUTTON 0x48 39#define INDYCAM_REG_BUTTON 0x48
40 40
41/* Field definitions of registers */ 41/* Field definitions of registers */
42#define INDYCAM_CONTROL_AGCENA (1<<0) /* automatic gain control */ 42#define INDYCAM_CONTROL_AGCENA (1<<0) /* automatic gain control */
@@ -59,13 +59,14 @@
59#define INDYCAM_ORIENTATION_BOTTOM_TO_TOP 0x40 59#define INDYCAM_ORIENTATION_BOTTOM_TO_TOP 0x40
60#define INDYCAM_BUTTON_RELEASED 0x10 60#define INDYCAM_BUTTON_RELEASED 0x10
61 61
62/* Values for controls */
62#define INDYCAM_SHUTTER_MIN 0x00 63#define INDYCAM_SHUTTER_MIN 0x00
63#define INDYCAM_SHUTTER_MAX 0xff 64#define INDYCAM_SHUTTER_MAX 0xff
64#define INDYCAM_GAIN_MIN 0x00 65#define INDYCAM_GAIN_MIN 0x00
65#define INDYCAM_GAIN_MAX 0xff 66#define INDYCAM_GAIN_MAX 0xff
66#define INDYCAM_RED_BALANCE_MIN 0x00 /* the effect is the opposite? */ 67#define INDYCAM_RED_BALANCE_MIN 0x00
67#define INDYCAM_RED_BALANCE_MAX 0xff 68#define INDYCAM_RED_BALANCE_MAX 0xff
68#define INDYCAM_BLUE_BALANCE_MIN 0x00 /* the effect is the opposite? */ 69#define INDYCAM_BLUE_BALANCE_MIN 0x00
69#define INDYCAM_BLUE_BALANCE_MAX 0xff 70#define INDYCAM_BLUE_BALANCE_MAX 0xff
70#define INDYCAM_RED_SATURATION_MIN 0x00 71#define INDYCAM_RED_SATURATION_MIN 0x00
71#define INDYCAM_RED_SATURATION_MAX 0xff 72#define INDYCAM_RED_SATURATION_MAX 0xff
@@ -74,34 +75,9 @@
74#define INDYCAM_GAMMA_MIN 0x00 75#define INDYCAM_GAMMA_MIN 0x00
75#define INDYCAM_GAMMA_MAX 0xff 76#define INDYCAM_GAMMA_MAX 0xff
76 77
77/* Driver interface definitions */ 78#define INDYCAM_AGC_DEFAULT 1
78 79#define INDYCAM_AWB_DEFAULT 0
79#define INDYCAM_VALUE_ENABLED 1 80#define INDYCAM_SHUTTER_DEFAULT 0xff
80#define INDYCAM_VALUE_DISABLED 0
81#define INDYCAM_VALUE_UNCHANGED -1
82
83/* When setting controls, a value of -1 leaves the control unchanged. */
84struct indycam_control {
85 int agc; /* boolean */
86 int awb; /* boolean */
87 int shutter;
88 int gain;
89 int red_balance;
90 int blue_balance;
91 int red_saturation;
92 int blue_saturation;
93 int gamma;
94};
95
96#define DECODER_INDYCAM_GET_CONTROLS _IOR('d', 193, struct indycam_control)
97#define DECODER_INDYCAM_SET_CONTROLS _IOW('d', 194, struct indycam_control)
98
99/* Default values for controls */
100
101#define INDYCAM_AGC_DEFAULT INDYCAM_VALUE_ENABLED
102#define INDYCAM_AWB_DEFAULT INDYCAM_VALUE_ENABLED
103
104#define INDYCAM_SHUTTER_DEFAULT INDYCAM_SHUTTER_60
105#define INDYCAM_GAIN_DEFAULT 0x80 81#define INDYCAM_GAIN_DEFAULT 0x80
106#define INDYCAM_RED_BALANCE_DEFAULT 0x18 82#define INDYCAM_RED_BALANCE_DEFAULT 0x18
107#define INDYCAM_BLUE_BALANCE_DEFAULT 0xa4 83#define INDYCAM_BLUE_BALANCE_DEFAULT 0xa4
@@ -109,4 +85,24 @@ struct indycam_control {
109#define INDYCAM_BLUE_SATURATION_DEFAULT 0xc0 85#define INDYCAM_BLUE_SATURATION_DEFAULT 0xc0
110#define INDYCAM_GAMMA_DEFAULT 0x80 86#define INDYCAM_GAMMA_DEFAULT 0x80
111 87
88/* Driver interface definitions */
89
90#define INDYCAM_CONTROL_AGC 0 /* boolean */
91#define INDYCAM_CONTROL_AWB 1 /* boolean */
92#define INDYCAM_CONTROL_SHUTTER 2
93#define INDYCAM_CONTROL_GAIN 3
94#define INDYCAM_CONTROL_RED_BALANCE 4
95#define INDYCAM_CONTROL_BLUE_BALANCE 5
96#define INDYCAM_CONTROL_RED_SATURATION 6
97#define INDYCAM_CONTROL_BLUE_SATURATION 7
98#define INDYCAM_CONTROL_GAMMA 8
99
100struct indycam_control {
101 u8 type;
102 s32 value;
103};
104
105#define DECODER_INDYCAM_GET_CONTROL _IOR('d', 193, struct indycam_control)
106#define DECODER_INDYCAM_SET_CONTROL _IOW('d', 194, struct indycam_control)
107
112#endif 108#endif
diff --git a/drivers/media/video/msp3400.c b/drivers/media/video/msp3400.c
index 262890cb20a7..e75e7948fd9d 100644
--- a/drivers/media/video/msp3400.c
+++ b/drivers/media/video/msp3400.c
@@ -741,8 +741,8 @@ static int msp34xx_sleep(struct msp3400c *msp, int timeout)
741 set_current_state(TASK_INTERRUPTIBLE); 741 set_current_state(TASK_INTERRUPTIBLE);
742 schedule(); 742 schedule();
743 } else { 743 } else {
744 set_current_state(TASK_INTERRUPTIBLE); 744 schedule_timeout_interruptible
745 schedule_timeout(msecs_to_jiffies(timeout)); 745 (msecs_to_jiffies(timeout));
746 } 746 }
747 } 747 }
748 748
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index badf2f9e3072..61a2d6b50eef 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -342,8 +342,8 @@ static int tvaudio_sleep(struct saa7134_dev *dev, int timeout)
342 set_current_state(TASK_INTERRUPTIBLE); 342 set_current_state(TASK_INTERRUPTIBLE);
343 schedule(); 343 schedule();
344 } else { 344 } else {
345 set_current_state(TASK_INTERRUPTIBLE); 345 schedule_timeout_interruptible
346 schedule_timeout(msecs_to_jiffies(timeout)); 346 (msecs_to_jiffies(timeout));
347 } 347 }
348 } 348 }
349 remove_wait_queue(&dev->thread.wq, &wait); 349 remove_wait_queue(&dev->thread.wq, &wait);
diff --git a/drivers/media/video/saa7191.c b/drivers/media/video/saa7191.c
index 3ddbb62312be..cbca896e8cfa 100644
--- a/drivers/media/video/saa7191.c
+++ b/drivers/media/video/saa7191.c
@@ -26,71 +26,95 @@
26 26
27#include "saa7191.h" 27#include "saa7191.h"
28 28
29#define SAA7191_MODULE_VERSION "0.0.3" 29#define SAA7191_MODULE_VERSION "0.0.5"
30 30
31MODULE_DESCRIPTION("Philips SAA7191 video decoder driver"); 31MODULE_DESCRIPTION("Philips SAA7191 video decoder driver");
32MODULE_VERSION(SAA7191_MODULE_VERSION); 32MODULE_VERSION(SAA7191_MODULE_VERSION);
33MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>"); 33MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35 35
36// #define SAA7191_DEBUG
37
38#ifdef SAA7191_DEBUG
39#define dprintk(x...) printk("SAA7191: " x);
40#else
41#define dprintk(x...)
42#endif
43
44#define SAA7191_SYNC_COUNT 30
45#define SAA7191_SYNC_DELAY 100 /* milliseconds */
46
36struct saa7191 { 47struct saa7191 {
37 struct i2c_client *client; 48 struct i2c_client *client;
38 49
39 /* the register values are stored here as the actual 50 /* the register values are stored here as the actual
40 * I2C-registers are write-only */ 51 * I2C-registers are write-only */
41 unsigned char reg[25]; 52 u8 reg[25];
42 53
43 unsigned char norm; 54 int input;
44 unsigned char input; 55 int norm;
45}; 56};
46 57
47static struct i2c_driver i2c_driver_saa7191; 58static struct i2c_driver i2c_driver_saa7191;
48 59
49static const unsigned char initseq[] = { 60static const u8 initseq[] = {
50 0, /* Subaddress */ 61 0, /* Subaddress */
51 0x50, /* SAA7191_REG_IDEL */ 62
52 0x30, /* SAA7191_REG_HSYB */ 63 0x50, /* (0x50) SAA7191_REG_IDEL */
53 0x00, /* SAA7191_REG_HSYS */ 64
54 0xe8, /* SAA7191_REG_HCLB */ 65 /* 50 Hz signal timing */
55 0xb6, /* SAA7191_REG_HCLS */ 66 0x30, /* (0x30) SAA7191_REG_HSYB */
56 0xf4, /* SAA7191_REG_HPHI */ 67 0x00, /* (0x00) SAA7191_REG_HSYS */
57 0x01, /* SAA7191_REG_LUMA - chrominance trap active (CVBS) */ 68 0xe8, /* (0xe8) SAA7191_REG_HCLB */
58 0x00, /* SAA7191_REG_HUEC */ 69 0xb6, /* (0xb6) SAA7191_REG_HCLS */
59 0xf8, /* SAA7191_REG_CKTQ */ 70 0xf4, /* (0xf4) SAA7191_REG_HPHI */
60 0xf8, /* SAA7191_REG_CKTS */ 71
61 0x90, /* SAA7191_REG_PLSE */ 72 /* control */
62 0x90, /* SAA7191_REG_SESE */ 73 SAA7191_LUMA_APER_1, /* (0x01) SAA7191_REG_LUMA - CVBS mode */
63 0x00, /* SAA7191_REG_GAIN */ 74 0x00, /* (0x00) SAA7191_REG_HUEC */
64 0x0c, /* SAA7191_REG_STDC - not SECAM, slow time constant */ 75 0xf8, /* (0xf8) SAA7191_REG_CKTQ */
65 0x78, /* SAA7191_REG_IOCK - chrominance from CVBS, GPSW1 & 2 off */ 76 0xf8, /* (0xf8) SAA7191_REG_CKTS */
66 0x99, /* SAA7191_REG_CTL3 - automatic field detection */ 77 0x90, /* (0x90) SAA7191_REG_PLSE */
67 0x00, /* SAA7191_REG_CTL4 */ 78 0x90, /* (0x90) SAA7191_REG_SESE */
68 0x2c, /* SAA7191_REG_CHCV */ 79 0x00, /* (0x00) SAA7191_REG_GAIN */
80 SAA7191_STDC_NFEN | SAA7191_STDC_HRMV, /* (0x0c) SAA7191_REG_STDC
81 * - not SECAM,
82 * slow time constant */
83 SAA7191_IOCK_OEDC | SAA7191_IOCK_OEHS | SAA7191_IOCK_OEVS
84 | SAA7191_IOCK_OEDY, /* (0x78) SAA7191_REG_IOCK
85 * - chroma from CVBS, GPSW1 & 2 off */
86 SAA7191_CTL3_AUFD | SAA7191_CTL3_SCEN | SAA7191_CTL3_OFTS
87 | SAA7191_CTL3_YDEL0, /* (0x99) SAA7191_REG_CTL3
88 * - automatic field detection */
89 0x00, /* (0x00) SAA7191_REG_CTL4 */
90 0x2c, /* (0x2c) SAA7191_REG_CHCV - PAL nominal value */
69 0x00, /* unused */ 91 0x00, /* unused */
70 0x00, /* unused */ 92 0x00, /* unused */
71 0x34, /* SAA7191_REG_HS6B */ 93
72 0x0a, /* SAA7191_REG_HS6S */ 94 /* 60 Hz signal timing */
73 0xf4, /* SAA7191_REG_HC6B */ 95 0x34, /* (0x34) SAA7191_REG_HS6B */
74 0xce, /* SAA7191_REG_HC6S */ 96 0x0a, /* (0x0a) SAA7191_REG_HS6S */
75 0xf4, /* SAA7191_REG_HP6I */ 97 0xf4, /* (0xf4) SAA7191_REG_HC6B */
98 0xce, /* (0xce) SAA7191_REG_HC6S */
99 0xf4, /* (0xf4) SAA7191_REG_HP6I */
76}; 100};
77 101
78/* SAA7191 register handling */ 102/* SAA7191 register handling */
79 103
80static unsigned char saa7191_read_reg(struct i2c_client *client, 104static u8 saa7191_read_reg(struct i2c_client *client,
81 unsigned char reg) 105 u8 reg)
82{ 106{
83 return ((struct saa7191 *)i2c_get_clientdata(client))->reg[reg]; 107 return ((struct saa7191 *)i2c_get_clientdata(client))->reg[reg];
84} 108}
85 109
86static int saa7191_read_status(struct i2c_client *client, 110static int saa7191_read_status(struct i2c_client *client,
87 unsigned char *value) 111 u8 *value)
88{ 112{
89 int ret; 113 int ret;
90 114
91 ret = i2c_master_recv(client, value, 1); 115 ret = i2c_master_recv(client, value, 1);
92 if (ret < 0) { 116 if (ret < 0) {
93 printk(KERN_ERR "SAA7191: saa7191_read_status(): read failed"); 117 printk(KERN_ERR "SAA7191: saa7191_read_status(): read failed\n");
94 return ret; 118 return ret;
95 } 119 }
96 120
@@ -98,17 +122,16 @@ static int saa7191_read_status(struct i2c_client *client,
98} 122}
99 123
100 124
101static int saa7191_write_reg(struct i2c_client *client, unsigned char reg, 125static int saa7191_write_reg(struct i2c_client *client, u8 reg,
102 unsigned char value) 126 u8 value)
103{ 127{
104
105 ((struct saa7191 *)i2c_get_clientdata(client))->reg[reg] = value; 128 ((struct saa7191 *)i2c_get_clientdata(client))->reg[reg] = value;
106 return i2c_smbus_write_byte_data(client, reg, value); 129 return i2c_smbus_write_byte_data(client, reg, value);
107} 130}
108 131
109/* the first byte of data must be the first subaddress number (register) */ 132/* the first byte of data must be the first subaddress number (register) */
110static int saa7191_write_block(struct i2c_client *client, 133static int saa7191_write_block(struct i2c_client *client,
111 unsigned char length, unsigned char *data) 134 u8 length, u8 *data)
112{ 135{
113 int i; 136 int i;
114 int ret; 137 int ret;
@@ -121,7 +144,7 @@ static int saa7191_write_block(struct i2c_client *client,
121 ret = i2c_master_send(client, data, length); 144 ret = i2c_master_send(client, data, length);
122 if (ret < 0) { 145 if (ret < 0) {
123 printk(KERN_ERR "SAA7191: saa7191_write_block(): " 146 printk(KERN_ERR "SAA7191: saa7191_write_block(): "
124 "write failed"); 147 "write failed\n");
125 return ret; 148 return ret;
126 } 149 }
127 150
@@ -132,8 +155,9 @@ static int saa7191_write_block(struct i2c_client *client,
132 155
133static int saa7191_set_input(struct i2c_client *client, int input) 156static int saa7191_set_input(struct i2c_client *client, int input)
134{ 157{
135 unsigned char luma = saa7191_read_reg(client, SAA7191_REG_LUMA); 158 struct saa7191 *decoder = i2c_get_clientdata(client);
136 unsigned char iock = saa7191_read_reg(client, SAA7191_REG_IOCK); 159 u8 luma = saa7191_read_reg(client, SAA7191_REG_LUMA);
160 u8 iock = saa7191_read_reg(client, SAA7191_REG_IOCK);
137 int err; 161 int err;
138 162
139 switch (input) { 163 switch (input) {
@@ -159,32 +183,20 @@ static int saa7191_set_input(struct i2c_client *client, int input)
159 if (err) 183 if (err)
160 return -EIO; 184 return -EIO;
161 185
186 decoder->input = input;
187
162 return 0; 188 return 0;
163} 189}
164 190
165static int saa7191_set_norm(struct i2c_client *client, int norm) 191static int saa7191_set_norm(struct i2c_client *client, int norm)
166{ 192{
167 struct saa7191 *decoder = i2c_get_clientdata(client); 193 struct saa7191 *decoder = i2c_get_clientdata(client);
168 unsigned char stdc = saa7191_read_reg(client, SAA7191_REG_STDC); 194 u8 stdc = saa7191_read_reg(client, SAA7191_REG_STDC);
169 unsigned char ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3); 195 u8 ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3);
170 unsigned char chcv = saa7191_read_reg(client, SAA7191_REG_CHCV); 196 u8 chcv = saa7191_read_reg(client, SAA7191_REG_CHCV);
171 int err; 197 int err;
172 198
173 switch(norm) { 199 switch(norm) {
174 case SAA7191_NORM_AUTO: {
175 unsigned char status;
176
177 // does status depend on current norm ?
178 if (saa7191_read_status(client, &status))
179 return -EIO;
180
181 stdc &= ~SAA7191_STDC_SECS;
182 ctl3 &= ~SAA7191_CTL3_FSEL;
183 ctl3 |= SAA7191_CTL3_AUFD;
184 chcv = (status & SAA7191_STATUS_FIDT)
185 ? SAA7191_CHCV_NTSC : SAA7191_CHCV_PAL;
186 break;
187 }
188 case SAA7191_NORM_PAL: 200 case SAA7191_NORM_PAL:
189 stdc &= ~SAA7191_STDC_SECS; 201 stdc &= ~SAA7191_STDC_SECS;
190 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL); 202 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL);
@@ -217,60 +229,335 @@ static int saa7191_set_norm(struct i2c_client *client, int norm)
217 229
218 decoder->norm = norm; 230 decoder->norm = norm;
219 231
232 dprintk("ctl3: %02x stdc: %02x chcv: %02x\n", ctl3,
233 stdc, chcv);
234 dprintk("norm: %d\n", norm);
235
220 return 0; 236 return 0;
221} 237}
222 238
223static int saa7191_get_controls(struct i2c_client *client, 239static int saa7191_wait_for_signal(struct i2c_client *client, u8 *status)
224 struct saa7191_control *ctrl)
225{ 240{
226 unsigned char hue = saa7191_read_reg(client, SAA7191_REG_HUEC); 241 int i = 0;
227 unsigned char stdc = saa7191_read_reg(client, SAA7191_REG_STDC);
228 242
229 if (hue < 0x80) { 243 dprintk("Checking for signal...\n");
230 hue += 0x80; 244
231 } else { 245 for (i = 0; i < SAA7191_SYNC_COUNT; i++) {
232 hue -= 0x80; 246 if (saa7191_read_status(client, status))
247 return -EIO;
248
249 if (((*status) & SAA7191_STATUS_HLCK) == 0) {
250 dprintk("Signal found\n");
251 return 0;
252 }
253
254 msleep(SAA7191_SYNC_DELAY);
233 } 255 }
234 ctrl->hue = hue;
235 256
236 ctrl->vtrc = (stdc & SAA7191_STDC_VTRC) 257 dprintk("No signal\n");
237 ? SAA7191_VALUE_ENABLED : SAA7191_VALUE_DISABLED;
238 258
239 return 0; 259 return -EBUSY;
240} 260}
241 261
242static int saa7191_set_controls(struct i2c_client *client, 262static int saa7191_autodetect_norm_extended(struct i2c_client *client)
243 struct saa7191_control *ctrl)
244{ 263{
245 int err; 264 u8 stdc = saa7191_read_reg(client, SAA7191_REG_STDC);
265 u8 ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3);
266 u8 status;
267 int err = 0;
246 268
247 if (ctrl->hue >= 0) { 269 dprintk("SAA7191 extended signal auto-detection...\n");
248 unsigned char hue = ctrl->hue & 0xff; 270
249 if (hue < 0x80) { 271 stdc &= ~SAA7191_STDC_SECS;
250 hue += 0x80; 272 ctl3 &= ~(SAA7191_CTL3_FSEL);
251 } else { 273
252 hue -= 0x80; 274 err = saa7191_write_reg(client, SAA7191_REG_STDC, stdc);
275 if (err) {
276 err = -EIO;
277 goto out;
278 }
279 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3);
280 if (err) {
281 err = -EIO;
282 goto out;
283 }
284
285 ctl3 |= SAA7191_CTL3_AUFD;
286 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3);
287 if (err) {
288 err = -EIO;
289 goto out;
290 }
291
292 msleep(SAA7191_SYNC_DELAY);
293
294 err = saa7191_wait_for_signal(client, &status);
295 if (err)
296 goto out;
297
298 if (status & SAA7191_STATUS_FIDT) {
299 /* 60Hz signal -> NTSC */
300 dprintk("60Hz signal: NTSC\n");
301 return saa7191_set_norm(client, SAA7191_NORM_NTSC);
302 }
303
304 /* 50Hz signal */
305 dprintk("50Hz signal: Trying PAL...\n");
306
307 /* try PAL first */
308 err = saa7191_set_norm(client, SAA7191_NORM_PAL);
309 if (err)
310 goto out;
311
312 msleep(SAA7191_SYNC_DELAY);
313
314 err = saa7191_wait_for_signal(client, &status);
315 if (err)
316 goto out;
317
318 /* not 50Hz ? */
319 if (status & SAA7191_STATUS_FIDT) {
320 dprintk("No 50Hz signal\n");
321 err = -EAGAIN;
322 goto out;
323 }
324
325 if (status & SAA7191_STATUS_CODE) {
326 dprintk("PAL\n");
327 return 0;
328 }
329
330 dprintk("No color detected with PAL - Trying SECAM...\n");
331
332 /* no color detected ? -> try SECAM */
333 err = saa7191_set_norm(client,
334 SAA7191_NORM_SECAM);
335 if (err)
336 goto out;
337
338 msleep(SAA7191_SYNC_DELAY);
339
340 err = saa7191_wait_for_signal(client, &status);
341 if (err)
342 goto out;
343
344 /* not 50Hz ? */
345 if (status & SAA7191_STATUS_FIDT) {
346 dprintk("No 50Hz signal\n");
347 err = -EAGAIN;
348 goto out;
349 }
350
351 if (status & SAA7191_STATUS_CODE) {
352 /* Color detected -> SECAM */
353 dprintk("SECAM\n");
354 return 0;
355 }
356
357 dprintk("No color detected with SECAM - Going back to PAL.\n");
358
359 /* still no color detected ?
360 * -> set norm back to PAL */
361 err = saa7191_set_norm(client,
362 SAA7191_NORM_PAL);
363 if (err)
364 goto out;
365
366out:
367 ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3);
368 if (ctl3 & SAA7191_CTL3_AUFD) {
369 ctl3 &= ~(SAA7191_CTL3_AUFD);
370 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3);
371 if (err) {
372 err = -EIO;
253 } 373 }
254 err = saa7191_write_reg(client, SAA7191_REG_HUEC, hue);
255 if (err)
256 return -EIO;
257 } 374 }
258 if (ctrl->vtrc >= 0) {
259 unsigned char stdc =
260 saa7191_read_reg(client, SAA7191_REG_STDC);
261 375
262 if (ctrl->vtrc) { 376 return err;
263 stdc |= SAA7191_STDC_VTRC; 377}
264 } else { 378
265 stdc &= ~SAA7191_STDC_VTRC; 379static int saa7191_autodetect_norm(struct i2c_client *client)
380{
381 u8 status;
382
383 dprintk("SAA7191 signal auto-detection...\n");
384
385 dprintk("Reading status...\n");
386
387 if (saa7191_read_status(client, &status))
388 return -EIO;
389
390 dprintk("Checking for signal...\n");
391
392 /* no signal ? */
393 if (status & SAA7191_STATUS_HLCK) {
394 dprintk("No signal\n");
395 return -EBUSY;
396 }
397
398 dprintk("Signal found\n");
399
400 if (status & SAA7191_STATUS_FIDT) {
401 /* 60hz signal -> NTSC */
402 dprintk("NTSC\n");
403 return saa7191_set_norm(client, SAA7191_NORM_NTSC);
404 } else {
405 /* 50hz signal -> PAL */
406 dprintk("PAL\n");
407 return saa7191_set_norm(client, SAA7191_NORM_PAL);
408 }
409}
410
411static int saa7191_get_control(struct i2c_client *client,
412 struct saa7191_control *ctrl)
413{
414 u8 reg;
415 int ret = 0;
416
417 switch (ctrl->type) {
418 case SAA7191_CONTROL_BANDPASS:
419 case SAA7191_CONTROL_BANDPASS_WEIGHT:
420 case SAA7191_CONTROL_CORING:
421 reg = saa7191_read_reg(client, SAA7191_REG_LUMA);
422 switch (ctrl->type) {
423 case SAA7191_CONTROL_BANDPASS:
424 ctrl->value = ((s32)reg & SAA7191_LUMA_BPSS_MASK)
425 >> SAA7191_LUMA_BPSS_SHIFT;
426 break;
427 case SAA7191_CONTROL_BANDPASS_WEIGHT:
428 ctrl->value = ((s32)reg & SAA7191_LUMA_APER_MASK)
429 >> SAA7191_LUMA_APER_SHIFT;
430 break;
431 case SAA7191_CONTROL_CORING:
432 ctrl->value = ((s32)reg & SAA7191_LUMA_CORI_MASK)
433 >> SAA7191_LUMA_CORI_SHIFT;
434 break;
266 } 435 }
436 break;
437 case SAA7191_CONTROL_FORCE_COLOUR:
438 case SAA7191_CONTROL_CHROMA_GAIN:
439 reg = saa7191_read_reg(client, SAA7191_REG_GAIN);
440 if (ctrl->type == SAA7191_CONTROL_FORCE_COLOUR)
441 ctrl->value = ((s32)reg & SAA7191_GAIN_COLO) ? 1 : 0;
442 else
443 ctrl->value = ((s32)reg & SAA7191_GAIN_LFIS_MASK)
444 >> SAA7191_GAIN_LFIS_SHIFT;
445 break;
446 case SAA7191_CONTROL_HUE:
447 reg = saa7191_read_reg(client, SAA7191_REG_HUEC);
448 if (reg < 0x80)
449 reg += 0x80;
450 else
451 reg -= 0x80;
452 ctrl->value = (s32)reg;
453 break;
454 case SAA7191_CONTROL_VTRC:
455 reg = saa7191_read_reg(client, SAA7191_REG_STDC);
456 ctrl->value = ((s32)reg & SAA7191_STDC_VTRC) ? 1 : 0;
457 break;
458 case SAA7191_CONTROL_LUMA_DELAY:
459 reg = saa7191_read_reg(client, SAA7191_REG_CTL3);
460 ctrl->value = ((s32)reg & SAA7191_CTL3_YDEL_MASK)
461 >> SAA7191_CTL3_YDEL_SHIFT;
462 if (ctrl->value >= 4)
463 ctrl->value -= 8;
464 break;
465 case SAA7191_CONTROL_VNR:
466 reg = saa7191_read_reg(client, SAA7191_REG_CTL4);
467 ctrl->value = ((s32)reg & SAA7191_CTL4_VNOI_MASK)
468 >> SAA7191_CTL4_VNOI_SHIFT;
469 break;
470 default:
471 ret = -EINVAL;
472 }
267 473
268 err = saa7191_write_reg(client, SAA7191_REG_STDC, stdc); 474 return ret;
269 if (err) 475}
270 return -EIO; 476
477static int saa7191_set_control(struct i2c_client *client,
478 struct saa7191_control *ctrl)
479{
480 u8 reg;
481 int ret = 0;
482
483 switch (ctrl->type) {
484 case SAA7191_CONTROL_BANDPASS:
485 case SAA7191_CONTROL_BANDPASS_WEIGHT:
486 case SAA7191_CONTROL_CORING:
487 reg = saa7191_read_reg(client, SAA7191_REG_LUMA);
488 switch (ctrl->type) {
489 case SAA7191_CONTROL_BANDPASS:
490 reg &= ~SAA7191_LUMA_BPSS_MASK;
491 reg |= (ctrl->value << SAA7191_LUMA_BPSS_SHIFT)
492 & SAA7191_LUMA_BPSS_MASK;
493 break;
494 case SAA7191_CONTROL_BANDPASS_WEIGHT:
495 reg &= ~SAA7191_LUMA_APER_MASK;
496 reg |= (ctrl->value << SAA7191_LUMA_APER_SHIFT)
497 & SAA7191_LUMA_APER_MASK;
498 break;
499 case SAA7191_CONTROL_CORING:
500 reg &= ~SAA7191_LUMA_CORI_MASK;
501 reg |= (ctrl->value << SAA7191_LUMA_CORI_SHIFT)
502 & SAA7191_LUMA_CORI_MASK;
503 break;
504 }
505 ret = saa7191_write_reg(client, SAA7191_REG_LUMA, reg);
506 break;
507 case SAA7191_CONTROL_FORCE_COLOUR:
508 case SAA7191_CONTROL_CHROMA_GAIN:
509 reg = saa7191_read_reg(client, SAA7191_REG_GAIN);
510 if (ctrl->type == SAA7191_CONTROL_FORCE_COLOUR) {
511 if (ctrl->value)
512 reg |= SAA7191_GAIN_COLO;
513 else
514 reg &= ~SAA7191_GAIN_COLO;
515 } else {
516 reg &= ~SAA7191_GAIN_LFIS_MASK;
517 reg |= (ctrl->value << SAA7191_GAIN_LFIS_SHIFT)
518 & SAA7191_GAIN_LFIS_MASK;
519 }
520 ret = saa7191_write_reg(client, SAA7191_REG_GAIN, reg);
521 break;
522 case SAA7191_CONTROL_HUE:
523 reg = ctrl->value & 0xff;
524 if (reg < 0x80)
525 reg += 0x80;
526 else
527 reg -= 0x80;
528 ret = saa7191_write_reg(client, SAA7191_REG_HUEC, reg);
529 break;
530 case SAA7191_CONTROL_VTRC:
531 reg = saa7191_read_reg(client, SAA7191_REG_STDC);
532 if (ctrl->value)
533 reg |= SAA7191_STDC_VTRC;
534 else
535 reg &= ~SAA7191_STDC_VTRC;
536 ret = saa7191_write_reg(client, SAA7191_REG_STDC, reg);
537 break;
538 case SAA7191_CONTROL_LUMA_DELAY: {
539 s32 value = ctrl->value;
540 if (value < 0)
541 value += 8;
542 reg = saa7191_read_reg(client, SAA7191_REG_CTL3);
543 reg &= ~SAA7191_CTL3_YDEL_MASK;
544 reg |= (value << SAA7191_CTL3_YDEL_SHIFT)
545 & SAA7191_CTL3_YDEL_MASK;
546 ret = saa7191_write_reg(client, SAA7191_REG_CTL3, reg);
547 break;
548 }
549 case SAA7191_CONTROL_VNR:
550 reg = saa7191_read_reg(client, SAA7191_REG_CTL4);
551 reg &= ~SAA7191_CTL4_VNOI_MASK;
552 reg |= (ctrl->value << SAA7191_CTL4_VNOI_SHIFT)
553 & SAA7191_CTL4_VNOI_MASK;
554 ret = saa7191_write_reg(client, SAA7191_REG_CTL4, reg);
555 break;
556 default:
557 ret = -EINVAL;
271 } 558 }
272 559
273 return 0; 560 return ret;
274} 561}
275 562
276/* I2C-interface */ 563/* I2C-interface */
@@ -309,11 +596,7 @@ static int saa7191_attach(struct i2c_adapter *adap, int addr, int kind)
309 if (err) 596 if (err)
310 goto out_free_decoder; 597 goto out_free_decoder;
311 598
312 decoder->input = SAA7191_INPUT_COMPOSITE; 599 err = saa7191_write_block(client, sizeof(initseq), (u8 *)initseq);
313 decoder->norm = SAA7191_NORM_AUTO;
314
315 err = saa7191_write_block(client, sizeof(initseq),
316 (unsigned char *)initseq);
317 if (err) { 600 if (err) {
318 printk(KERN_ERR "SAA7191 initialization failed\n"); 601 printk(KERN_ERR "SAA7191 initialization failed\n");
319 goto out_detach_client; 602 goto out_detach_client;
@@ -321,6 +604,14 @@ static int saa7191_attach(struct i2c_adapter *adap, int addr, int kind)
321 604
322 printk(KERN_INFO "SAA7191 initialized\n"); 605 printk(KERN_INFO "SAA7191 initialized\n");
323 606
607 decoder->input = SAA7191_INPUT_COMPOSITE;
608 decoder->norm = SAA7191_NORM_PAL;
609
610 err = saa7191_autodetect_norm(client);
611 if (err && (err != -EBUSY)) {
612 printk(KERN_ERR "SAA7191: Signal auto-detection failed\n");
613 }
614
324 return 0; 615 return 0;
325 616
326out_detach_client: 617out_detach_client:
@@ -368,7 +659,7 @@ static int saa7191_command(struct i2c_client *client, unsigned int cmd,
368 } 659 }
369 case DECODER_GET_STATUS: { 660 case DECODER_GET_STATUS: {
370 int *iarg = arg; 661 int *iarg = arg;
371 unsigned char status; 662 u8 status;
372 int res = 0; 663 int res = 0;
373 664
374 if (saa7191_read_status(client, &status)) { 665 if (saa7191_read_status(client, &status)) {
@@ -404,7 +695,7 @@ static int saa7191_command(struct i2c_client *client, unsigned int cmd,
404 695
405 switch (*iarg) { 696 switch (*iarg) {
406 case VIDEO_MODE_AUTO: 697 case VIDEO_MODE_AUTO:
407 return saa7191_set_norm(client, SAA7191_NORM_AUTO); 698 return saa7191_autodetect_norm(client);
408 case VIDEO_MODE_PAL: 699 case VIDEO_MODE_PAL:
409 return saa7191_set_norm(client, SAA7191_NORM_PAL); 700 return saa7191_set_norm(client, SAA7191_NORM_PAL);
410 case VIDEO_MODE_NTSC: 701 case VIDEO_MODE_NTSC:
@@ -446,38 +737,48 @@ static int saa7191_command(struct i2c_client *client, unsigned int cmd,
446 int err; 737 int err;
447 738
448 val = (pic->hue >> 8) - 0x80; 739 val = (pic->hue >> 8) - 0x80;
740
449 err = saa7191_write_reg(client, SAA7191_REG_HUEC, val); 741 err = saa7191_write_reg(client, SAA7191_REG_HUEC, val);
450 if (err) 742 if (err)
451 return -EIO; 743 return -EIO;
744
452 break; 745 break;
453 } 746 }
454 case DECODER_SAA7191_GET_STATUS: { 747 case DECODER_SAA7191_GET_STATUS: {
455 struct saa7191_status *status = arg; 748 struct saa7191_status *status = arg;
456 unsigned char status_reg; 749 u8 status_reg;
457 750
458 if (saa7191_read_status(client, &status_reg)) 751 if (saa7191_read_status(client, &status_reg))
459 return -EIO; 752 return -EIO;
753
460 status->signal = ((status_reg & SAA7191_STATUS_HLCK) == 0) 754 status->signal = ((status_reg & SAA7191_STATUS_HLCK) == 0)
461 ? SAA7191_VALUE_ENABLED : SAA7191_VALUE_DISABLED; 755 ? 1 : 0;
462 status->ntsc = (status_reg & SAA7191_STATUS_FIDT) 756 status->signal_60hz = (status_reg & SAA7191_STATUS_FIDT)
463 ? SAA7191_VALUE_ENABLED : SAA7191_VALUE_DISABLED; 757 ? 1 : 0;
464 status->color = (status_reg & SAA7191_STATUS_CODE) 758 status->color = (status_reg & SAA7191_STATUS_CODE) ? 1 : 0;
465 ? SAA7191_VALUE_ENABLED : SAA7191_VALUE_DISABLED;
466 759
467 status->input = decoder->input; 760 status->input = decoder->input;
468 status->norm = decoder->norm; 761 status->norm = decoder->norm;
762
763 break;
469 } 764 }
470 case DECODER_SAA7191_SET_NORM: { 765 case DECODER_SAA7191_SET_NORM: {
471 int *norm = arg; 766 int *norm = arg;
472 return saa7191_set_norm(client, *norm); 767
768 switch (*norm) {
769 case SAA7191_NORM_AUTO:
770 return saa7191_autodetect_norm(client);
771 case SAA7191_NORM_AUTO_EXT:
772 return saa7191_autodetect_norm_extended(client);
773 default:
774 return saa7191_set_norm(client, *norm);
775 }
473 } 776 }
474 case DECODER_SAA7191_GET_CONTROLS: { 777 case DECODER_SAA7191_GET_CONTROL: {
475 struct saa7191_control *ctrl = arg; 778 return saa7191_get_control(client, arg);
476 return saa7191_get_controls(client, ctrl);
477 } 779 }
478 case DECODER_SAA7191_SET_CONTROLS: { 780 case DECODER_SAA7191_SET_CONTROL: {
479 struct saa7191_control *ctrl = arg; 781 return saa7191_set_control(client, arg);
480 return saa7191_set_controls(client, ctrl);
481 } 782 }
482 default: 783 default:
483 return -EINVAL; 784 return -EINVAL;
@@ -488,12 +789,12 @@ static int saa7191_command(struct i2c_client *client, unsigned int cmd,
488 789
489static struct i2c_driver i2c_driver_saa7191 = { 790static struct i2c_driver i2c_driver_saa7191 = {
490 .owner = THIS_MODULE, 791 .owner = THIS_MODULE,
491 .name = "saa7191", 792 .name = "saa7191",
492 .id = I2C_DRIVERID_SAA7191, 793 .id = I2C_DRIVERID_SAA7191,
493 .flags = I2C_DF_NOTIFY, 794 .flags = I2C_DF_NOTIFY,
494 .attach_adapter = saa7191_probe, 795 .attach_adapter = saa7191_probe,
495 .detach_client = saa7191_detach, 796 .detach_client = saa7191_detach,
496 .command = saa7191_command 797 .command = saa7191_command
497}; 798};
498 799
499static int saa7191_init(void) 800static int saa7191_init(void)
diff --git a/drivers/media/video/saa7191.h b/drivers/media/video/saa7191.h
index 272045031435..a2310da1940d 100644
--- a/drivers/media/video/saa7191.h
+++ b/drivers/media/video/saa7191.h
@@ -24,8 +24,8 @@
24#define SAA7191_REG_HPHI 0x05 24#define SAA7191_REG_HPHI 0x05
25#define SAA7191_REG_LUMA 0x06 25#define SAA7191_REG_LUMA 0x06
26#define SAA7191_REG_HUEC 0x07 26#define SAA7191_REG_HUEC 0x07
27#define SAA7191_REG_CKTQ 0x08 27#define SAA7191_REG_CKTQ 0x08 /* bits 3-7 */
28#define SAA7191_REG_CKTS 0x09 28#define SAA7191_REG_CKTS 0x09 /* bits 3-7 */
29#define SAA7191_REG_PLSE 0x0a 29#define SAA7191_REG_PLSE 0x0a
30#define SAA7191_REG_SESE 0x0b 30#define SAA7191_REG_SESE 0x0b
31#define SAA7191_REG_GAIN 0x0c 31#define SAA7191_REG_GAIN 0x0c
@@ -43,30 +43,82 @@
43 43
44/* Status Register definitions */ 44/* Status Register definitions */
45#define SAA7191_STATUS_CODE 0x01 /* color detected flag */ 45#define SAA7191_STATUS_CODE 0x01 /* color detected flag */
46#define SAA7191_STATUS_FIDT 0x20 /* format type NTSC/PAL */ 46#define SAA7191_STATUS_FIDT 0x20 /* signal type 50/60 Hz */
47#define SAA7191_STATUS_HLCK 0x40 /* PLL unlocked/locked */ 47#define SAA7191_STATUS_HLCK 0x40 /* PLL unlocked(1)/locked(0) */
48#define SAA7191_STATUS_STTC 0x80 /* tv/vtr time constant */ 48#define SAA7191_STATUS_STTC 0x80 /* tv/vtr time constant */
49 49
50/* Luminance Control Register definitions */ 50/* Luminance Control Register definitions */
51/* input mode select bit:
52 * 0=CVBS (chrominance trap active), 1=S-Video (trap bypassed) */
51#define SAA7191_LUMA_BYPS 0x80 53#define SAA7191_LUMA_BYPS 0x80
52 54/* pre-filter (only when chrominance trap is active) */
53/* Chroma Gain Control Settings Register definitions */ 55#define SAA7191_LUMA_PREF 0x40
54/* 0=automatic colour-killer enabled, 1=forced colour on */ 56/* aperture bandpass to select different characteristics with maximums
57 * (bits 4-5) */
58#define SAA7191_LUMA_BPSS_MASK 0x30
59#define SAA7191_LUMA_BPSS_SHIFT 4
60#define SAA7191_LUMA_BPSS_3 0x30
61#define SAA7191_LUMA_BPSS_2 0x20
62#define SAA7191_LUMA_BPSS_1 0x10
63#define SAA7191_LUMA_BPSS_0 0x00
64/* coring range for high frequency components according to 8-bit luminance
65 * (bits 2-3)
66 * 0=coring off, n= (+-)n LSB */
67#define SAA7191_LUMA_CORI_MASK 0x0c
68#define SAA7191_LUMA_CORI_SHIFT 2
69#define SAA7191_LUMA_CORI_3 0x0c
70#define SAA7191_LUMA_CORI_2 0x08
71#define SAA7191_LUMA_CORI_1 0x04
72#define SAA7191_LUMA_CORI_0 0x00
73/* aperture bandpass filter weights high frequency components of luminance
74 * signal (bits 0-1)
75 * 0=factor 0, 1=0.25, 2=0.5, 3=1 */
76#define SAA7191_LUMA_APER_MASK 0x03
77#define SAA7191_LUMA_APER_SHIFT 0
78#define SAA7191_LUMA_APER_3 0x03
79#define SAA7191_LUMA_APER_2 0x02
80#define SAA7191_LUMA_APER_1 0x01
81#define SAA7191_LUMA_APER_0 0x00
82
83/* Chrominance Gain Control Settings Register definitions */
84/* colour on: 0=automatic colour-killer enabled, 1=forced colour on */
55#define SAA7191_GAIN_COLO 0x80 85#define SAA7191_GAIN_COLO 0x80
86/* chrominance gain control (AGC filter)
87 * 0=loop filter time constant slow, 1=medium, 2=fast, 3=actual gain */
88#define SAA7191_GAIN_LFIS_MASK 0x60
89#define SAA7191_GAIN_LFIS_SHIFT 5
90#define SAA7191_GAIN_LFIS_3 0x60
91#define SAA7191_GAIN_LFIS_2 0x40
92#define SAA7191_GAIN_LFIS_1 0x20
93#define SAA7191_GAIN_LFIS_0 0x00
56 94
57/* Standard/Mode Control Register definitions */ 95/* Standard/Mode Control Register definitions */
58/* tv/vtr mode bit: 0=TV mode (slow time constant), 96/* tv/vtr mode bit: 0=TV mode (slow time constant),
59 * 1=VTR mode (fast time constant) */ 97 * 1=VTR mode (fast time constant) */
60#define SAA7191_STDC_VTRC 0x80 98#define SAA7191_STDC_VTRC 0x80
99/* SAA7191B-specific functions enable (RTCO, ODD and GPSW0 outputs)
100 * 0=outputs set to high-impedance (circuit equals SAA7191), 1=enabled */
101#define SAA7191_STDC_NFEN 0x08
102/* HREF generation: 0=like SAA7191, 1=HREF is 8xLLC2 clocks earlier */
103#define SAA7191_STDC_HRMV 0x04
104/* general purpose switch 0
105 * (not used with VINO afaik) */
106#define SAA7191_STDC_GPSW0 0x02
61/* SECAM mode bit: 0=other standards, 1=SECAM */ 107/* SECAM mode bit: 0=other standards, 1=SECAM */
62#define SAA7191_STDC_SECS 0x01 108#define SAA7191_STDC_SECS 0x01
63/* the bit fields above must be or'd with this value */
64#define SAA7191_STDC_VALUE 0x0c
65 109
66/* I/O and Clock Control Register definitions */ 110/* I/O and Clock Control Register definitions */
67/* horizontal clock PLL: 0=PLL closed, 111/* horizontal clock PLL: 0=PLL closed,
68 * 1=PLL circuit open and horizontal freq fixed */ 112 * 1=PLL circuit open and horizontal freq fixed */
69#define SAA7191_IOCK_HPLL 0x80 113#define SAA7191_IOCK_HPLL 0x80
114/* colour-difference output enable (outputs UV0-UV7) */
115#define SAA7191_IOCK_OEDC 0x40
116/* H-sync output enable */
117#define SAA7191_IOCK_OEHS 0x20
118/* V-sync output enable */
119#define SAA7191_IOCK_OEVS 0x10
120/* luminance output enable (outputs Y0-Y7) */
121#define SAA7191_IOCK_OEDY 0x08
70/* S-VHS bit (chrominance from CVBS or from chrominance input): 122/* S-VHS bit (chrominance from CVBS or from chrominance input):
71 * 0=controlled by BYPS-bit, 1=from chrominance input */ 123 * 0=controlled by BYPS-bit, 1=from chrominance input */
72#define SAA7191_IOCK_CHRS 0x04 124#define SAA7191_IOCK_CHRS 0x04
@@ -83,11 +135,40 @@
83/* field select: (if AUFD=0) 135/* field select: (if AUFD=0)
84 * 0=50Hz (625 lines), 1=60Hz (525 lines) */ 136 * 0=50Hz (625 lines), 1=60Hz (525 lines) */
85#define SAA7191_CTL3_FSEL 0x40 137#define SAA7191_CTL3_FSEL 0x40
86/* the bit fields above must be or'd with this value */ 138/* SECAM cross-colour reduction enable */
87#define SAA7191_CTL3_VALUE 0x19 139#define SAA7191_CTL3_SXCR 0x20
140/* sync and clamping pulse enable (HCL and HSY outputs) */
141#define SAA7191_CTL3_SCEN 0x10
142/* output format: 0=4:1:1, 1=4:2:2 (4:2:2 for VINO) */
143#define SAA7191_CTL3_OFTS 0x08
144/* luminance delay compensation
145 * 0=0*2/LLC, 1=+1*2/LLC, 2=+2*2/LLC, 3=+3*2/LLC,
146 * 4=-4*2/LLC, 5=-3*2/LLC, 6=-2*2/LLC, 7=-1*2/LLC
147 * step size = 2/LLC = 67.8ns for 50Hz, 81.5ns for 60Hz */
148#define SAA7191_CTL3_YDEL_MASK 0x07
149#define SAA7191_CTL3_YDEL_SHIFT 0
150#define SAA7191_CTL3_YDEL2 0x04
151#define SAA7191_CTL3_YDEL1 0x02
152#define SAA7191_CTL3_YDEL0 0x01
153
154/* Miscellaneous Control #2 Register definitions */
155/* select HREF position
156 * 0=normal, HREF is matched to YUV output port,
157 * 1=HREF is matched to CVBS input port */
158#define SAA7191_CTL4_HRFS 0x04
159/* vertical noise reduction
160 * 0=normal, 1=searching window, 2=auto-deflection, 3=reduction bypassed */
161#define SAA7191_CTL4_VNOI_MASK 0x03
162#define SAA7191_CTL4_VNOI_SHIFT 0
163#define SAA7191_CTL4_VNOI_3 0x03
164#define SAA7191_CTL4_VNOI_2 0x02
165#define SAA7191_CTL4_VNOI_1 0x01
166#define SAA7191_CTL4_VNOI_0 0x00
88 167
89/* Chrominance Gain Control Register definitions 168/* Chrominance Gain Control Register definitions
90 * (nominal value for UV CCIR level) */ 169 * - for QAM-modulated input signals, effects output amplitude
170 * (SECAM gain fixed)
171 * (nominal values for UV CCIR level) */
91#define SAA7191_CHCV_NTSC 0x2c 172#define SAA7191_CHCV_NTSC 0x2c
92#define SAA7191_CHCV_PAL 0x59 173#define SAA7191_CHCV_PAL 0x59
93 174
@@ -99,16 +180,13 @@
99#define SAA7191_NORM_PAL 1 180#define SAA7191_NORM_PAL 1
100#define SAA7191_NORM_NTSC 2 181#define SAA7191_NORM_NTSC 2
101#define SAA7191_NORM_SECAM 3 182#define SAA7191_NORM_SECAM 3
102 183#define SAA7191_NORM_AUTO_EXT 4 /* extended auto-detection */
103#define SAA7191_VALUE_ENABLED 1
104#define SAA7191_VALUE_DISABLED 0
105#define SAA7191_VALUE_UNCHANGED -1
106 184
107struct saa7191_status { 185struct saa7191_status {
108 /* 0=no signal, 1=signal active*/ 186 /* 0=no signal, 1=signal detected */
109 int signal; 187 int signal;
110 /* 0=50hz (pal) signal, 1=60hz (ntsc) signal */ 188 /* 0=50hz (pal) signal, 1=60hz (ntsc) signal */
111 int ntsc; 189 int signal_60hz;
112 /* 0=no color detected, 1=color detected */ 190 /* 0=no color detected, 1=color detected */
113 int color; 191 int color;
114 192
@@ -118,22 +196,60 @@ struct saa7191_status {
118 int norm; 196 int norm;
119}; 197};
120 198
121#define SAA7191_HUE_MIN 0x00 199#define SAA7191_BANDPASS_MIN 0x00
122#define SAA7191_HUE_MAX 0xff 200#define SAA7191_BANDPASS_MAX 0x03
123#define SAA7191_HUE_DEFAULT 0x80 201#define SAA7191_BANDPASS_DEFAULT 0x00
202
203#define SAA7191_BANDPASS_WEIGHT_MIN 0x00
204#define SAA7191_BANDPASS_WEIGHT_MAX 0x03
205#define SAA7191_BANDPASS_WEIGHT_DEFAULT 0x01
206
207#define SAA7191_CORING_MIN 0x00
208#define SAA7191_CORING_MAX 0x03
209#define SAA7191_CORING_DEFAULT 0x00
210
211#define SAA7191_HUE_MIN 0x00
212#define SAA7191_HUE_MAX 0xff
213#define SAA7191_HUE_DEFAULT 0x80
214
215#define SAA7191_VTRC_MIN 0x00
216#define SAA7191_VTRC_MAX 0x01
217#define SAA7191_VTRC_DEFAULT 0x00
218
219#define SAA7191_FORCE_COLOUR_MIN 0x00
220#define SAA7191_FORCE_COLOUR_MAX 0x01
221#define SAA7191_FORCE_COLOUR_DEFAULT 0x00
222
223#define SAA7191_CHROMA_GAIN_MIN 0x00
224#define SAA7191_CHROMA_GAIN_MAX 0x03
225#define SAA7191_CHROMA_GAIN_DEFAULT 0x00
226
227#define SAA7191_LUMA_DELAY_MIN -0x04
228#define SAA7191_LUMA_DELAY_MAX 0x03
229#define SAA7191_LUMA_DELAY_DEFAULT 0x01
230
231#define SAA7191_VNR_MIN 0x00
232#define SAA7191_VNR_MAX 0x03
233#define SAA7191_VNR_DEFAULT 0x00
124 234
125#define SAA7191_VTRC_MIN 0x00 235#define SAA7191_CONTROL_BANDPASS 0
126#define SAA7191_VTRC_MAX 0x01 236#define SAA7191_CONTROL_BANDPASS_WEIGHT 1
127#define SAA7191_VTRC_DEFAULT 0x00 237#define SAA7191_CONTROL_CORING 2
238#define SAA7191_CONTROL_FORCE_COLOUR 3 /* boolean */
239#define SAA7191_CONTROL_CHROMA_GAIN 4
240#define SAA7191_CONTROL_HUE 5
241#define SAA7191_CONTROL_VTRC 6 /* boolean */
242#define SAA7191_CONTROL_LUMA_DELAY 7
243#define SAA7191_CONTROL_VNR 8
128 244
129struct saa7191_control { 245struct saa7191_control {
130 int hue; 246 u8 type;
131 int vtrc; 247 s32 value;
132}; 248};
133 249
134#define DECODER_SAA7191_GET_STATUS _IOR('d', 195, struct saa7191_status) 250#define DECODER_SAA7191_GET_STATUS _IOR('d', 195, struct saa7191_status)
135#define DECODER_SAA7191_SET_NORM _IOW('d', 196, int) 251#define DECODER_SAA7191_SET_NORM _IOW('d', 196, int)
136#define DECODER_SAA7191_GET_CONTROLS _IOR('d', 197, struct saa7191_control) 252#define DECODER_SAA7191_GET_CONTROL _IOR('d', 197, struct saa7191_control)
137#define DECODER_SAA7191_SET_CONTROLS _IOW('d', 198, struct saa7191_control) 253#define DECODER_SAA7191_SET_CONTROL _IOW('d', 198, struct saa7191_control)
138 254
139#endif 255#endif
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index 59bb71381a1b..d679ca23ded7 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -1006,10 +1006,8 @@ v4l_compat_translate_ioctl(struct inode *inode,
1006 break; 1006 break;
1007 } 1007 }
1008 1008
1009 if (cap2) 1009 kfree(cap2);
1010 kfree(cap2); 1010 kfree(fmt2);
1011 if (fmt2)
1012 kfree(fmt2);
1013 return err; 1011 return err;
1014} 1012}
1015 1013
diff --git a/drivers/media/video/videocodec.c b/drivers/media/video/videocodec.c
index c9d5f1a873cc..839db622040d 100644
--- a/drivers/media/video/videocodec.c
+++ b/drivers/media/video/videocodec.c
@@ -353,8 +353,7 @@ videocodec_build_table (void)
353 dprintk(3, "videocodec_build table: %d entries, %d bytes\n", i, 353 dprintk(3, "videocodec_build table: %d entries, %d bytes\n", i,
354 size); 354 size);
355 355
356 if (videocodec_buf) 356 kfree(videocodec_buf);
357 kfree(videocodec_buf);
358 videocodec_buf = (char *) kmalloc(size, GFP_KERNEL); 357 videocodec_buf = (char *) kmalloc(size, GFP_KERNEL);
359 358
360 i = 0; 359 i = 0;
@@ -471,8 +470,7 @@ videocodec_exit (void)
471{ 470{
472#ifdef CONFIG_PROC_FS 471#ifdef CONFIG_PROC_FS
473 remove_proc_entry("videocodecs", NULL); 472 remove_proc_entry("videocodecs", NULL);
474 if (videocodec_buf) 473 kfree(videocodec_buf);
475 kfree(videocodec_buf);
476#endif 474#endif
477} 475}
478 476
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index 06df15f75de9..83c49f9610d0 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -215,8 +215,7 @@ video_usercopy(struct inode *inode, struct file *file,
215 } 215 }
216 216
217out: 217out:
218 if (mbuf) 218 kfree(mbuf);
219 kfree(mbuf);
220 return err; 219 return err;
221} 220}
222 221
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index ed4394e854ab..71b28e9e0850 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -12,15 +12,11 @@
12 12
13/* 13/*
14 * TODO: 14 * TODO:
15 * - remove "hacks" from memory allocation code and implement nopage() 15 * - remove "mark pages reserved-hacks" from memory allocation code
16 * and implement nopage()
16 * - check decimation, calculating and reporting image size when 17 * - check decimation, calculating and reporting image size when
17 * using decimation 18 * using decimation
18 * - check vino_acquire_input(), vino_set_input() and channel 19 * - implement read(), user mode buffers and overlay (?)
19 * ownership handling
20 * - report VINO error-interrupts via ioctls ?
21 * - implement picture controls (all implemented?)
22 * - use macros for boolean values (?)
23 * - implement user mode buffers and overlay (?)
24 */ 20 */
25 21
26#include <linux/init.h> 22#include <linux/init.h>
@@ -60,18 +56,16 @@
60 * debug info. 56 * debug info.
61 * Note that the debug output also slows down the driver significantly */ 57 * Note that the debug output also slows down the driver significantly */
62// #define VINO_DEBUG 58// #define VINO_DEBUG
59// #define VINO_DEBUG_INT
63 60
64#define VINO_MODULE_VERSION "0.0.3" 61#define VINO_MODULE_VERSION "0.0.5"
65#define VINO_VERSION_CODE KERNEL_VERSION(0, 0, 3) 62#define VINO_VERSION_CODE KERNEL_VERSION(0, 0, 5)
66 63
67MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver"); 64MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
68MODULE_VERSION(VINO_MODULE_VERSION); 65MODULE_VERSION(VINO_MODULE_VERSION);
69MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>"); 66MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
70MODULE_LICENSE("GPL"); 67MODULE_LICENSE("GPL");
71 68
72#define mem_map_reserve(p) set_bit(PG_reserved, &((p)->flags))
73#define mem_map_unreserve(p) clear_bit(PG_reserved, &((p)->flags))
74
75#ifdef VINO_DEBUG 69#ifdef VINO_DEBUG
76#define dprintk(x...) printk("VINO: " x); 70#define dprintk(x...) printk("VINO: " x);
77#else 71#else
@@ -91,15 +85,16 @@ MODULE_LICENSE("GPL");
91#define VINO_MIN_HEIGHT 32 85#define VINO_MIN_HEIGHT 32
92 86
93#define VINO_CLIPPING_START_ODD_D1 1 87#define VINO_CLIPPING_START_ODD_D1 1
94#define VINO_CLIPPING_START_ODD_PAL 1 88#define VINO_CLIPPING_START_ODD_PAL 15
95#define VINO_CLIPPING_START_ODD_NTSC 1 89#define VINO_CLIPPING_START_ODD_NTSC 12
96 90
97#define VINO_CLIPPING_START_EVEN_D1 2 91#define VINO_CLIPPING_START_EVEN_D1 2
98#define VINO_CLIPPING_START_EVEN_PAL 2 92#define VINO_CLIPPING_START_EVEN_PAL 15
99#define VINO_CLIPPING_START_EVEN_NTSC 2 93#define VINO_CLIPPING_START_EVEN_NTSC 12
100 94
101#define VINO_INPUT_CHANNEL_COUNT 3 95#define VINO_INPUT_CHANNEL_COUNT 3
102 96
97/* the number is the index for vino_inputs */
103#define VINO_INPUT_NONE -1 98#define VINO_INPUT_NONE -1
104#define VINO_INPUT_COMPOSITE 0 99#define VINO_INPUT_COMPOSITE 0
105#define VINO_INPUT_SVIDEO 1 100#define VINO_INPUT_SVIDEO 1
@@ -107,15 +102,13 @@ MODULE_LICENSE("GPL");
107 102
108#define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE) 103#define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
109 104
110#define VINO_FIFO_THRESHOLD_DEFAULT 512 105#define VINO_FIFO_THRESHOLD_DEFAULT 16
111 106
112/*#define VINO_FRAMEBUFFER_SIZE (VINO_PAL_WIDTH * VINO_PAL_HEIGHT * 4 \
113 + 2 * PAGE_SIZE)*/
114#define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \ 107#define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
115 * VINO_PAL_HEIGHT * 4 \ 108 * VINO_PAL_HEIGHT * 4 \
116 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1)) 109 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
117 110
118#define VINO_FRAMEBUFFER_MAX_COUNT 8 111#define VINO_FRAMEBUFFER_COUNT_MAX 8
119 112
120#define VINO_FRAMEBUFFER_UNUSED 0 113#define VINO_FRAMEBUFFER_UNUSED 0
121#define VINO_FRAMEBUFFER_IN_USE 1 114#define VINO_FRAMEBUFFER_IN_USE 1
@@ -131,24 +124,27 @@ MODULE_LICENSE("GPL");
131#define VINO_DUMMY_DESC_COUNT 4 124#define VINO_DUMMY_DESC_COUNT 4
132#define VINO_DESC_FETCH_DELAY 5 /* microseconds */ 125#define VINO_DESC_FETCH_DELAY 5 /* microseconds */
133 126
127#define VINO_MAX_FRAME_SKIP_COUNT 128
128
134/* the number is the index for vino_data_formats */ 129/* the number is the index for vino_data_formats */
135#define VINO_DATA_FMT_NONE -1 130#define VINO_DATA_FMT_NONE -1
136#define VINO_DATA_FMT_GREY 0 131#define VINO_DATA_FMT_GREY 0
137#define VINO_DATA_FMT_RGB332 1 132#define VINO_DATA_FMT_RGB332 1
138#define VINO_DATA_FMT_RGB32 2 133#define VINO_DATA_FMT_RGB32 2
139#define VINO_DATA_FMT_YUV 3 134#define VINO_DATA_FMT_YUV 3
140//#define VINO_DATA_FMT_RGB24 4
141 135
142#define VINO_DATA_FMT_COUNT 4 136#define VINO_DATA_FMT_COUNT 4
143 137
138/* the number is the index for vino_data_norms */
144#define VINO_DATA_NORM_NONE -1 139#define VINO_DATA_NORM_NONE -1
145#define VINO_DATA_NORM_NTSC 0 140#define VINO_DATA_NORM_NTSC 0
146#define VINO_DATA_NORM_PAL 1 141#define VINO_DATA_NORM_PAL 1
147#define VINO_DATA_NORM_SECAM 2 142#define VINO_DATA_NORM_SECAM 2
148#define VINO_DATA_NORM_D1 3 143#define VINO_DATA_NORM_D1 3
149/* The following is a special entry that can be used to 144/* The following are special entries that can be used to
150 * autodetect the norm. */ 145 * autodetect the norm. */
151#define VINO_DATA_NORM_AUTO 0xff 146#define VINO_DATA_NORM_AUTO 0xfe
147#define VINO_DATA_NORM_AUTO_EXT 0xff
152 148
153#define VINO_DATA_NORM_COUNT 4 149#define VINO_DATA_NORM_COUNT 4
154 150
@@ -232,7 +228,7 @@ struct vino_framebuffer_fifo {
232 unsigned int head; 228 unsigned int head;
233 unsigned int tail; 229 unsigned int tail;
234 230
235 unsigned int data[VINO_FRAMEBUFFER_MAX_COUNT]; 231 unsigned int data[VINO_FRAMEBUFFER_COUNT_MAX];
236}; 232};
237 233
238struct vino_framebuffer_queue { 234struct vino_framebuffer_queue {
@@ -246,13 +242,20 @@ struct vino_framebuffer_queue {
246 struct vino_framebuffer_fifo in; 242 struct vino_framebuffer_fifo in;
247 struct vino_framebuffer_fifo out; 243 struct vino_framebuffer_fifo out;
248 244
249 struct vino_framebuffer *buffer[VINO_FRAMEBUFFER_MAX_COUNT]; 245 struct vino_framebuffer *buffer[VINO_FRAMEBUFFER_COUNT_MAX];
250 246
251 spinlock_t queue_lock; 247 spinlock_t queue_lock;
252 struct semaphore queue_sem; 248 struct semaphore queue_sem;
253 wait_queue_head_t frame_wait_queue; 249 wait_queue_head_t frame_wait_queue;
254}; 250};
255 251
252struct vino_interrupt_data {
253 struct timeval timestamp;
254 unsigned int frame_counter;
255 unsigned int skip_count;
256 unsigned int skip;
257};
258
256struct vino_channel_settings { 259struct vino_channel_settings {
257 unsigned int channel; 260 unsigned int channel;
258 261
@@ -285,6 +288,8 @@ struct vino_channel_settings {
285 288
286 unsigned int users; 289 unsigned int users;
287 290
291 struct vino_interrupt_data int_data;
292
288 /* V4L support */ 293 /* V4L support */
289 struct video_device *v4l_device; 294 struct video_device *v4l_device;
290}; 295};
@@ -315,7 +320,7 @@ struct vino_settings {
315/* Module parameters */ 320/* Module parameters */
316 321
317/* 322/*
318 * Using vino_pixel_conversion the ARGB32-format pixels supplied 323 * Using vino_pixel_conversion the ABGR32-format pixels supplied
319 * by the VINO chip can be converted to more common formats 324 * by the VINO chip can be converted to more common formats
320 * like RGBA32 (or probably RGB24 in the future). This way we 325 * like RGBA32 (or probably RGB24 in the future). This way we
321 * can give out data that can be specified correctly with 326 * can give out data that can be specified correctly with
@@ -329,7 +334,9 @@ struct vino_settings {
329 * Use non-zero value to enable conversion. 334 * Use non-zero value to enable conversion.
330 */ 335 */
331static int vino_pixel_conversion = 0; 336static int vino_pixel_conversion = 0;
337
332module_param_named(pixelconv, vino_pixel_conversion, int, 0); 338module_param_named(pixelconv, vino_pixel_conversion, int, 0);
339
333MODULE_PARM_DESC(pixelconv, 340MODULE_PARM_DESC(pixelconv,
334 "enable pixel conversion (non-zero value enables)"); 341 "enable pixel conversion (non-zero value enables)");
335 342
@@ -345,15 +352,22 @@ static const char *vino_bus_name = "GIO64 bus";
345static const char *vino_v4l_device_name_a = "SGI VINO Channel A"; 352static const char *vino_v4l_device_name_a = "SGI VINO Channel A";
346static const char *vino_v4l_device_name_b = "SGI VINO Channel B"; 353static const char *vino_v4l_device_name_b = "SGI VINO Channel B";
347 354
355static void vino_capture_tasklet(unsigned long channel);
356
357DECLARE_TASKLET(vino_tasklet_a, vino_capture_tasklet, VINO_CHANNEL_A);
358DECLARE_TASKLET(vino_tasklet_b, vino_capture_tasklet, VINO_CHANNEL_B);
359
348static const struct vino_input vino_inputs[] = { 360static const struct vino_input vino_inputs[] = {
349 { 361 {
350 .name = "Composite", 362 .name = "Composite",
351 .std = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM, 363 .std = V4L2_STD_NTSC | V4L2_STD_PAL
364 | V4L2_STD_SECAM,
352 },{ 365 },{
353 .name = "S-Video", 366 .name = "S-Video",
354 .std = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM, 367 .std = V4L2_STD_NTSC | V4L2_STD_PAL
368 | V4L2_STD_SECAM,
355 },{ 369 },{
356 .name = "D1 (IndyCam)", 370 .name = "D1/IndyCam",
357 .std = V4L2_STD_NTSC, 371 .std = V4L2_STD_NTSC,
358 } 372 }
359}; 373};
@@ -376,15 +390,10 @@ static const struct vino_data_format vino_data_formats[] = {
376 .colorspace = V4L2_COLORSPACE_SRGB, 390 .colorspace = V4L2_COLORSPACE_SRGB,
377 },{ 391 },{
378 .description = "YUV 4:2:2", 392 .description = "YUV 4:2:2",
379 .bpp = 4, 393 .bpp = 2,
380 .pixelformat = V4L2_PIX_FMT_YUYV, // XXX: swapped? 394 .pixelformat = V4L2_PIX_FMT_YUYV, // XXX: swapped?
381 .colorspace = V4L2_COLORSPACE_SMPTE170M, 395 .colorspace = V4L2_COLORSPACE_SMPTE170M,
382 }/*,{ 396 }
383 .description = "24-bit RGB",
384 .bpp = 3,
385 .pixelformat = V4L2_PIX_FMT_RGB24,
386 .colorspace = V4L2_COLORSPACE_SRGB,
387 }*/
388}; 397};
389 398
390static const struct vino_data_norm vino_data_norms[] = { 399static const struct vino_data_norm vino_data_norms[] = {
@@ -397,18 +406,18 @@ static const struct vino_data_norm vino_data_norms[] = {
397 .width = VINO_NTSC_WIDTH, 406 .width = VINO_NTSC_WIDTH,
398 .height = VINO_NTSC_HEIGHT, 407 .height = VINO_NTSC_HEIGHT,
399 .odd = { 408 .odd = {
400 .top = VINO_CLIPPING_START_ODD_NTSC, 409 .top = VINO_CLIPPING_START_ODD_NTSC,
401 .left = 0, 410 .left = 0,
402 .bottom = VINO_CLIPPING_START_ODD_NTSC 411 .bottom = VINO_CLIPPING_START_ODD_NTSC
403 + VINO_NTSC_HEIGHT / 2 - 1, 412 + VINO_NTSC_HEIGHT / 2 - 1,
404 .right = VINO_NTSC_WIDTH, 413 .right = VINO_NTSC_WIDTH,
405 }, 414 },
406 .even = { 415 .even = {
407 .top = VINO_CLIPPING_START_EVEN_NTSC, 416 .top = VINO_CLIPPING_START_EVEN_NTSC,
408 .left = 0, 417 .left = 0,
409 .bottom = VINO_CLIPPING_START_EVEN_NTSC 418 .bottom = VINO_CLIPPING_START_EVEN_NTSC
410 + VINO_NTSC_HEIGHT / 2 - 1, 419 + VINO_NTSC_HEIGHT / 2 - 1,
411 .right = VINO_NTSC_WIDTH, 420 .right = VINO_NTSC_WIDTH,
412 }, 421 },
413 },{ 422 },{
414 .description = "PAL", 423 .description = "PAL",
@@ -419,18 +428,18 @@ static const struct vino_data_norm vino_data_norms[] = {
419 .width = VINO_PAL_WIDTH, 428 .width = VINO_PAL_WIDTH,
420 .height = VINO_PAL_HEIGHT, 429 .height = VINO_PAL_HEIGHT,
421 .odd = { 430 .odd = {
422 .top = VINO_CLIPPING_START_ODD_PAL, 431 .top = VINO_CLIPPING_START_ODD_PAL,
423 .left = 0, 432 .left = 0,
424 .bottom = VINO_CLIPPING_START_ODD_PAL 433 .bottom = VINO_CLIPPING_START_ODD_PAL
425 + VINO_PAL_HEIGHT / 2 - 1, 434 + VINO_PAL_HEIGHT / 2 - 1,
426 .right = VINO_PAL_WIDTH, 435 .right = VINO_PAL_WIDTH,
427 }, 436 },
428 .even = { 437 .even = {
429 .top = VINO_CLIPPING_START_EVEN_PAL, 438 .top = VINO_CLIPPING_START_EVEN_PAL,
430 .left = 0, 439 .left = 0,
431 .bottom = VINO_CLIPPING_START_EVEN_PAL 440 .bottom = VINO_CLIPPING_START_EVEN_PAL
432 + VINO_PAL_HEIGHT / 2 - 1, 441 + VINO_PAL_HEIGHT / 2 - 1,
433 .right = VINO_PAL_WIDTH, 442 .right = VINO_PAL_WIDTH,
434 }, 443 },
435 },{ 444 },{
436 .description = "SECAM", 445 .description = "SECAM",
@@ -441,21 +450,21 @@ static const struct vino_data_norm vino_data_norms[] = {
441 .width = VINO_PAL_WIDTH, 450 .width = VINO_PAL_WIDTH,
442 .height = VINO_PAL_HEIGHT, 451 .height = VINO_PAL_HEIGHT,
443 .odd = { 452 .odd = {
444 .top = VINO_CLIPPING_START_ODD_PAL, 453 .top = VINO_CLIPPING_START_ODD_PAL,
445 .left = 0, 454 .left = 0,
446 .bottom = VINO_CLIPPING_START_ODD_PAL 455 .bottom = VINO_CLIPPING_START_ODD_PAL
447 + VINO_PAL_HEIGHT / 2 - 1, 456 + VINO_PAL_HEIGHT / 2 - 1,
448 .right = VINO_PAL_WIDTH, 457 .right = VINO_PAL_WIDTH,
449 }, 458 },
450 .even = { 459 .even = {
451 .top = VINO_CLIPPING_START_EVEN_PAL, 460 .top = VINO_CLIPPING_START_EVEN_PAL,
452 .left = 0, 461 .left = 0,
453 .bottom = VINO_CLIPPING_START_EVEN_PAL 462 .bottom = VINO_CLIPPING_START_EVEN_PAL
454 + VINO_PAL_HEIGHT / 2 - 1, 463 + VINO_PAL_HEIGHT / 2 - 1,
455 .right = VINO_PAL_WIDTH, 464 .right = VINO_PAL_WIDTH,
456 }, 465 },
457 },{ 466 },{
458 .description = "NTSC (D1 input)", 467 .description = "NTSC/D1",
459 .std = V4L2_STD_NTSC, 468 .std = V4L2_STD_NTSC,
460 .fps_min = 6, 469 .fps_min = 6,
461 .fps_max = 30, 470 .fps_max = 30,
@@ -463,18 +472,18 @@ static const struct vino_data_norm vino_data_norms[] = {
463 .width = VINO_NTSC_WIDTH, 472 .width = VINO_NTSC_WIDTH,
464 .height = VINO_NTSC_HEIGHT, 473 .height = VINO_NTSC_HEIGHT,
465 .odd = { 474 .odd = {
466 .top = VINO_CLIPPING_START_ODD_D1, 475 .top = VINO_CLIPPING_START_ODD_D1,
467 .left = 0, 476 .left = 0,
468 .bottom = VINO_CLIPPING_START_ODD_D1 477 .bottom = VINO_CLIPPING_START_ODD_D1
469 + VINO_NTSC_HEIGHT / 2 - 1, 478 + VINO_NTSC_HEIGHT / 2 - 1,
470 .right = VINO_NTSC_WIDTH, 479 .right = VINO_NTSC_WIDTH,
471 }, 480 },
472 .even = { 481 .even = {
473 .top = VINO_CLIPPING_START_EVEN_D1, 482 .top = VINO_CLIPPING_START_EVEN_D1,
474 .left = 0, 483 .left = 0,
475 .bottom = VINO_CLIPPING_START_EVEN_D1 484 .bottom = VINO_CLIPPING_START_EVEN_D1
476 + VINO_NTSC_HEIGHT / 2 - 1, 485 + VINO_NTSC_HEIGHT / 2 - 1,
477 .right = VINO_NTSC_WIDTH, 486 .right = VINO_NTSC_WIDTH,
478 }, 487 },
479 } 488 }
480}; 489};
@@ -491,7 +500,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
491 .step = 1, 500 .step = 1,
492 .default_value = INDYCAM_AGC_DEFAULT, 501 .default_value = INDYCAM_AGC_DEFAULT,
493 .flags = 0, 502 .flags = 0,
494 .reserved = { 0, 0 }, 503 .reserved = { INDYCAM_CONTROL_AGC, 0 },
495 },{ 504 },{
496 .id = V4L2_CID_AUTO_WHITE_BALANCE, 505 .id = V4L2_CID_AUTO_WHITE_BALANCE,
497 .type = V4L2_CTRL_TYPE_BOOLEAN, 506 .type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -501,7 +510,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
501 .step = 1, 510 .step = 1,
502 .default_value = INDYCAM_AWB_DEFAULT, 511 .default_value = INDYCAM_AWB_DEFAULT,
503 .flags = 0, 512 .flags = 0,
504 .reserved = { 0, 0 }, 513 .reserved = { INDYCAM_CONTROL_AWB, 0 },
505 },{ 514 },{
506 .id = V4L2_CID_GAIN, 515 .id = V4L2_CID_GAIN,
507 .type = V4L2_CTRL_TYPE_INTEGER, 516 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -511,7 +520,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
511 .step = 1, 520 .step = 1,
512 .default_value = INDYCAM_GAIN_DEFAULT, 521 .default_value = INDYCAM_GAIN_DEFAULT,
513 .flags = 0, 522 .flags = 0,
514 .reserved = { 0, 0 }, 523 .reserved = { INDYCAM_CONTROL_GAIN, 0 },
515 },{ 524 },{
516 .id = V4L2_CID_PRIVATE_BASE, 525 .id = V4L2_CID_PRIVATE_BASE,
517 .type = V4L2_CTRL_TYPE_INTEGER, 526 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -521,7 +530,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
521 .step = 1, 530 .step = 1,
522 .default_value = INDYCAM_RED_SATURATION_DEFAULT, 531 .default_value = INDYCAM_RED_SATURATION_DEFAULT,
523 .flags = 0, 532 .flags = 0,
524 .reserved = { 0, 0 }, 533 .reserved = { INDYCAM_CONTROL_RED_SATURATION, 0 },
525 },{ 534 },{
526 .id = V4L2_CID_PRIVATE_BASE + 1, 535 .id = V4L2_CID_PRIVATE_BASE + 1,
527 .type = V4L2_CTRL_TYPE_INTEGER, 536 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -531,7 +540,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
531 .step = 1, 540 .step = 1,
532 .default_value = INDYCAM_BLUE_SATURATION_DEFAULT, 541 .default_value = INDYCAM_BLUE_SATURATION_DEFAULT,
533 .flags = 0, 542 .flags = 0,
534 .reserved = { 0, 0 }, 543 .reserved = { INDYCAM_CONTROL_BLUE_SATURATION, 0 },
535 },{ 544 },{
536 .id = V4L2_CID_RED_BALANCE, 545 .id = V4L2_CID_RED_BALANCE,
537 .type = V4L2_CTRL_TYPE_INTEGER, 546 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -541,7 +550,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
541 .step = 1, 550 .step = 1,
542 .default_value = INDYCAM_RED_BALANCE_DEFAULT, 551 .default_value = INDYCAM_RED_BALANCE_DEFAULT,
543 .flags = 0, 552 .flags = 0,
544 .reserved = { 0, 0 }, 553 .reserved = { INDYCAM_CONTROL_RED_BALANCE, 0 },
545 },{ 554 },{
546 .id = V4L2_CID_BLUE_BALANCE, 555 .id = V4L2_CID_BLUE_BALANCE,
547 .type = V4L2_CTRL_TYPE_INTEGER, 556 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -551,7 +560,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
551 .step = 1, 560 .step = 1,
552 .default_value = INDYCAM_BLUE_BALANCE_DEFAULT, 561 .default_value = INDYCAM_BLUE_BALANCE_DEFAULT,
553 .flags = 0, 562 .flags = 0,
554 .reserved = { 0, 0 }, 563 .reserved = { INDYCAM_CONTROL_BLUE_BALANCE, 0 },
555 },{ 564 },{
556 .id = V4L2_CID_EXPOSURE, 565 .id = V4L2_CID_EXPOSURE,
557 .type = V4L2_CTRL_TYPE_INTEGER, 566 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -561,7 +570,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
561 .step = 1, 570 .step = 1,
562 .default_value = INDYCAM_SHUTTER_DEFAULT, 571 .default_value = INDYCAM_SHUTTER_DEFAULT,
563 .flags = 0, 572 .flags = 0,
564 .reserved = { 0, 0 }, 573 .reserved = { INDYCAM_CONTROL_SHUTTER, 0 },
565 },{ 574 },{
566 .id = V4L2_CID_GAMMA, 575 .id = V4L2_CID_GAMMA,
567 .type = V4L2_CTRL_TYPE_INTEGER, 576 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -571,11 +580,11 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
571 .step = 1, 580 .step = 1,
572 .default_value = INDYCAM_GAMMA_DEFAULT, 581 .default_value = INDYCAM_GAMMA_DEFAULT,
573 .flags = 0, 582 .flags = 0,
574 .reserved = { 0, 0 }, 583 .reserved = { INDYCAM_CONTROL_GAMMA, 0 },
575 } 584 }
576}; 585};
577 586
578#define VINO_SAA7191_V4L2_CONTROL_COUNT 2 587#define VINO_SAA7191_V4L2_CONTROL_COUNT 9
579 588
580struct v4l2_queryctrl vino_saa7191_v4l2_controls[] = { 589struct v4l2_queryctrl vino_saa7191_v4l2_controls[] = {
581 { 590 {
@@ -587,9 +596,59 @@ struct v4l2_queryctrl vino_saa7191_v4l2_controls[] = {
587 .step = 1, 596 .step = 1,
588 .default_value = SAA7191_HUE_DEFAULT, 597 .default_value = SAA7191_HUE_DEFAULT,
589 .flags = 0, 598 .flags = 0,
590 .reserved = { 0, 0 }, 599 .reserved = { SAA7191_CONTROL_HUE, 0 },
591 },{ 600 },{
592 .id = V4L2_CID_PRIVATE_BASE, 601 .id = V4L2_CID_PRIVATE_BASE,
602 .type = V4L2_CTRL_TYPE_INTEGER,
603 .name = "Luminance Bandpass",
604 .minimum = SAA7191_BANDPASS_MIN,
605 .maximum = SAA7191_BANDPASS_MAX,
606 .step = 1,
607 .default_value = SAA7191_BANDPASS_DEFAULT,
608 .flags = 0,
609 .reserved = { SAA7191_CONTROL_BANDPASS, 0 },
610 },{
611 .id = V4L2_CID_PRIVATE_BASE + 1,
612 .type = V4L2_CTRL_TYPE_INTEGER,
613 .name = "Luminance Bandpass Weight",
614 .minimum = SAA7191_BANDPASS_WEIGHT_MIN,
615 .maximum = SAA7191_BANDPASS_WEIGHT_MAX,
616 .step = 1,
617 .default_value = SAA7191_BANDPASS_WEIGHT_DEFAULT,
618 .flags = 0,
619 .reserved = { SAA7191_CONTROL_BANDPASS_WEIGHT, 0 },
620 },{
621 .id = V4L2_CID_PRIVATE_BASE + 2,
622 .type = V4L2_CTRL_TYPE_INTEGER,
623 .name = "HF Luminance Coring",
624 .minimum = SAA7191_CORING_MIN,
625 .maximum = SAA7191_CORING_MAX,
626 .step = 1,
627 .default_value = SAA7191_CORING_DEFAULT,
628 .flags = 0,
629 .reserved = { SAA7191_CONTROL_CORING, 0 },
630 },{
631 .id = V4L2_CID_PRIVATE_BASE + 3,
632 .type = V4L2_CTRL_TYPE_BOOLEAN,
633 .name = "Force Colour",
634 .minimum = SAA7191_FORCE_COLOUR_MIN,
635 .maximum = SAA7191_FORCE_COLOUR_MAX,
636 .step = 1,
637 .default_value = SAA7191_FORCE_COLOUR_DEFAULT,
638 .flags = 0,
639 .reserved = { SAA7191_CONTROL_FORCE_COLOUR, 0 },
640 },{
641 .id = V4L2_CID_PRIVATE_BASE + 4,
642 .type = V4L2_CTRL_TYPE_INTEGER,
643 .name = "Chrominance Gain Control",
644 .minimum = SAA7191_CHROMA_GAIN_MIN,
645 .maximum = SAA7191_CHROMA_GAIN_MAX,
646 .step = 1,
647 .default_value = SAA7191_CHROMA_GAIN_DEFAULT,
648 .flags = 0,
649 .reserved = { SAA7191_CONTROL_CHROMA_GAIN, 0 },
650 },{
651 .id = V4L2_CID_PRIVATE_BASE + 5,
593 .type = V4L2_CTRL_TYPE_BOOLEAN, 652 .type = V4L2_CTRL_TYPE_BOOLEAN,
594 .name = "VTR Time Constant", 653 .name = "VTR Time Constant",
595 .minimum = SAA7191_VTRC_MIN, 654 .minimum = SAA7191_VTRC_MIN,
@@ -597,7 +656,27 @@ struct v4l2_queryctrl vino_saa7191_v4l2_controls[] = {
597 .step = 1, 656 .step = 1,
598 .default_value = SAA7191_VTRC_DEFAULT, 657 .default_value = SAA7191_VTRC_DEFAULT,
599 .flags = 0, 658 .flags = 0,
600 .reserved = { 0, 0 }, 659 .reserved = { SAA7191_CONTROL_VTRC, 0 },
660 },{
661 .id = V4L2_CID_PRIVATE_BASE + 6,
662 .type = V4L2_CTRL_TYPE_INTEGER,
663 .name = "Luminance Delay Compensation",
664 .minimum = SAA7191_LUMA_DELAY_MIN,
665 .maximum = SAA7191_LUMA_DELAY_MAX,
666 .step = 1,
667 .default_value = SAA7191_LUMA_DELAY_DEFAULT,
668 .flags = 0,
669 .reserved = { SAA7191_CONTROL_LUMA_DELAY, 0 },
670 },{
671 .id = V4L2_CID_PRIVATE_BASE + 7,
672 .type = V4L2_CTRL_TYPE_INTEGER,
673 .name = "Vertical Noise Reduction",
674 .minimum = SAA7191_VNR_MIN,
675 .maximum = SAA7191_VNR_MAX,
676 .step = 1,
677 .default_value = SAA7191_VNR_DEFAULT,
678 .flags = 0,
679 .reserved = { SAA7191_CONTROL_VNR, 0 },
601 } 680 }
602}; 681};
603 682
@@ -639,9 +718,10 @@ static struct i2c_algo_sgi_data i2c_sgi_vino_data =
639 */ 718 */
640static int i2c_vino_client_reg(struct i2c_client *client) 719static int i2c_vino_client_reg(struct i2c_client *client)
641{ 720{
721 unsigned long flags;
642 int ret = 0; 722 int ret = 0;
643 723
644 spin_lock(&vino_drvdata->input_lock); 724 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
645 switch (client->driver->id) { 725 switch (client->driver->id) {
646 case I2C_DRIVERID_SAA7191: 726 case I2C_DRIVERID_SAA7191:
647 if (vino_drvdata->decoder.driver) 727 if (vino_drvdata->decoder.driver)
@@ -658,16 +738,17 @@ static int i2c_vino_client_reg(struct i2c_client *client)
658 default: 738 default:
659 ret = -ENODEV; 739 ret = -ENODEV;
660 } 740 }
661 spin_unlock(&vino_drvdata->input_lock); 741 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
662 742
663 return ret; 743 return ret;
664} 744}
665 745
666static int i2c_vino_client_unreg(struct i2c_client *client) 746static int i2c_vino_client_unreg(struct i2c_client *client)
667{ 747{
748 unsigned long flags;
668 int ret = 0; 749 int ret = 0;
669 750
670 spin_lock(&vino_drvdata->input_lock); 751 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
671 if (client == vino_drvdata->decoder.driver) { 752 if (client == vino_drvdata->decoder.driver) {
672 if (vino_drvdata->decoder.owner != VINO_NO_CHANNEL) 753 if (vino_drvdata->decoder.owner != VINO_NO_CHANNEL)
673 ret = -EBUSY; 754 ret = -EBUSY;
@@ -679,7 +760,7 @@ static int i2c_vino_client_unreg(struct i2c_client *client)
679 else 760 else
680 vino_drvdata->camera.driver = NULL; 761 vino_drvdata->camera.driver = NULL;
681 } 762 }
682 spin_unlock(&vino_drvdata->input_lock); 763 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
683 764
684 return ret; 765 return ret;
685} 766}
@@ -727,7 +808,7 @@ static void vino_free_buffer_with_count(struct vino_framebuffer *fb,
727 dprintk("vino_free_buffer_with_count(): count = %d\n", count); 808 dprintk("vino_free_buffer_with_count(): count = %d\n", count);
728 809
729 for (i = 0; i < count; i++) { 810 for (i = 0; i < count; i++) {
730 mem_map_unreserve(virt_to_page(fb->desc_table.virtual[i])); 811 ClearPageReserved(virt_to_page(fb->desc_table.virtual[i]));
731 dma_unmap_single(NULL, 812 dma_unmap_single(NULL,
732 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i], 813 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
733 PAGE_SIZE, DMA_FROM_DEVICE); 814 PAGE_SIZE, DMA_FROM_DEVICE);
@@ -805,7 +886,7 @@ static int vino_allocate_buffer(struct vino_framebuffer *fb,
805 dma_data_addr + VINO_PAGE_SIZE * j; 886 dma_data_addr + VINO_PAGE_SIZE * j;
806 } 887 }
807 888
808 mem_map_reserve(virt_to_page(fb->desc_table.virtual[i])); 889 SetPageReserved(virt_to_page(fb->desc_table.virtual[i]));
809 } 890 }
810 891
811 /* page_count needs to be set anyway, because the descriptor table has 892 /* page_count needs to be set anyway, because the descriptor table has
@@ -892,7 +973,7 @@ static int vino_prepare_user_buffer(struct vino_framebuffer *fb,
892 dma_data_addr + VINO_PAGE_SIZE * j; 973 dma_data_addr + VINO_PAGE_SIZE * j;
893 } 974 }
894 975
895 mem_map_reserve(virt_to_page(fb->desc_table.virtual[i])); 976 SetPageReserved(virt_to_page(fb->desc_table.virtual[i]));
896 } 977 }
897 978
898 /* page_count needs to be set anyway, because the descriptor table has 979 /* page_count needs to be set anyway, because the descriptor table has
@@ -933,7 +1014,7 @@ static void vino_sync_buffer(struct vino_framebuffer *fb)
933 1014
934/* Framebuffer fifo functions (need to be locked externally) */ 1015/* Framebuffer fifo functions (need to be locked externally) */
935 1016
936static void vino_fifo_init(struct vino_framebuffer_fifo *f, 1017static inline void vino_fifo_init(struct vino_framebuffer_fifo *f,
937 unsigned int length) 1018 unsigned int length)
938{ 1019{
939 f->length = 0; 1020 f->length = 0;
@@ -941,16 +1022,18 @@ static void vino_fifo_init(struct vino_framebuffer_fifo *f,
941 f->head = 0; 1022 f->head = 0;
942 f->tail = 0; 1023 f->tail = 0;
943 1024
944 if (length > VINO_FRAMEBUFFER_MAX_COUNT) 1025 if (length > VINO_FRAMEBUFFER_COUNT_MAX)
945 length = VINO_FRAMEBUFFER_MAX_COUNT; 1026 length = VINO_FRAMEBUFFER_COUNT_MAX;
946 1027
947 f->length = length; 1028 f->length = length;
948} 1029}
949 1030
950/* returns true/false */ 1031/* returns true/false */
951static int vino_fifo_has_id(struct vino_framebuffer_fifo *f, unsigned int id) 1032static inline int vino_fifo_has_id(struct vino_framebuffer_fifo *f,
1033 unsigned int id)
952{ 1034{
953 unsigned int i; 1035 unsigned int i;
1036
954 for (i = f->head; i == (f->tail - 1); i = (i + 1) % f->length) { 1037 for (i = f->head; i == (f->tail - 1); i = (i + 1) % f->length) {
955 if (f->data[i] == id) 1038 if (f->data[i] == id)
956 return 1; 1039 return 1;
@@ -959,13 +1042,15 @@ static int vino_fifo_has_id(struct vino_framebuffer_fifo *f, unsigned int id)
959 return 0; 1042 return 0;
960} 1043}
961 1044
1045#if 0
962/* returns true/false */ 1046/* returns true/false */
963static int vino_fifo_full(struct vino_framebuffer_fifo *f) 1047static inline int vino_fifo_full(struct vino_framebuffer_fifo *f)
964{ 1048{
965 return (f->used == f->length); 1049 return (f->used == f->length);
966} 1050}
1051#endif
967 1052
968static unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo *f) 1053static inline unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo *f)
969{ 1054{
970 return f->used; 1055 return f->used;
971} 1056}
@@ -1076,8 +1161,8 @@ static int vino_queue_init(struct vino_framebuffer_queue *q,
1076 1161
1077 down(&q->queue_sem); 1162 down(&q->queue_sem);
1078 1163
1079 if (*length > VINO_FRAMEBUFFER_MAX_COUNT) 1164 if (*length > VINO_FRAMEBUFFER_COUNT_MAX)
1080 *length = VINO_FRAMEBUFFER_MAX_COUNT; 1165 *length = VINO_FRAMEBUFFER_COUNT_MAX;
1081 1166
1082 q->length = 0; 1167 q->length = 0;
1083 1168
@@ -1313,6 +1398,7 @@ out:
1313 return ret; 1398 return ret;
1314} 1399}
1315 1400
1401#if 0
1316static int vino_queue_get_total(struct vino_framebuffer_queue *q, 1402static int vino_queue_get_total(struct vino_framebuffer_queue *q,
1317 unsigned int *total) 1403 unsigned int *total)
1318{ 1404{
@@ -1338,6 +1424,7 @@ out:
1338 1424
1339 return ret; 1425 return ret;
1340} 1426}
1427#endif
1341 1428
1342static struct vino_framebuffer *vino_queue_peek(struct 1429static struct vino_framebuffer *vino_queue_peek(struct
1343 vino_framebuffer_queue *q, 1430 vino_framebuffer_queue *q,
@@ -1471,12 +1558,14 @@ static void vino_update_line_size(struct vino_channel_settings *vcs)
1471 1558
1472 dprintk("update_line_size(): before: w = %d, d = %d, " 1559 dprintk("update_line_size(): before: w = %d, d = %d, "
1473 "line_size = %d\n", w, d, vcs->line_size); 1560 "line_size = %d\n", w, d, vcs->line_size);
1561
1474 /* line size must be multiple of 8 bytes */ 1562 /* line size must be multiple of 8 bytes */
1475 lsize = (bpp * (w / d)) & ~7; 1563 lsize = (bpp * (w / d)) & ~7;
1476 w = (lsize / bpp) * d; 1564 w = (lsize / bpp) * d;
1477 1565
1478 vcs->clipping.right = vcs->clipping.left + w; 1566 vcs->clipping.right = vcs->clipping.left + w;
1479 vcs->line_size = lsize; 1567 vcs->line_size = lsize;
1568
1480 dprintk("update_line_size(): after: w = %d, d = %d, " 1569 dprintk("update_line_size(): after: w = %d, d = %d, "
1481 "line_size = %d\n", w, d, vcs->line_size); 1570 "line_size = %d\n", w, d, vcs->line_size);
1482} 1571}
@@ -1532,7 +1621,7 @@ static void vino_set_clipping(struct vino_channel_settings *vcs,
1532} 1621}
1533 1622
1534/* execute with input_lock locked */ 1623/* execute with input_lock locked */
1535static void vino_set_default_clipping(struct vino_channel_settings *vcs) 1624static inline void vino_set_default_clipping(struct vino_channel_settings *vcs)
1536{ 1625{
1537 vino_set_clipping(vcs, 0, 0, vino_data_norms[vcs->data_norm].width, 1626 vino_set_clipping(vcs, 0, 0, vino_data_norms[vcs->data_norm].width,
1538 vino_data_norms[vcs->data_norm].height); 1627 vino_data_norms[vcs->data_norm].height);
@@ -1556,8 +1645,7 @@ static void vino_set_scaling(struct vino_channel_settings *vcs,
1556 1645
1557 if (d < 1) { 1646 if (d < 1) {
1558 d = 1; 1647 d = 1;
1559 } 1648 } else if (d > 8) {
1560 if (d > 8) {
1561 d = 8; 1649 d = 8;
1562 } 1650 }
1563 1651
@@ -1570,7 +1658,7 @@ static void vino_set_scaling(struct vino_channel_settings *vcs,
1570} 1658}
1571 1659
1572/* execute with input_lock locked */ 1660/* execute with input_lock locked */
1573static void vino_reset_scaling(struct vino_channel_settings *vcs) 1661static inline void vino_set_default_scaling(struct vino_channel_settings *vcs)
1574{ 1662{
1575 vino_set_scaling(vcs, vcs->clipping.right - vcs->clipping.left, 1663 vino_set_scaling(vcs, vcs->clipping.right - vcs->clipping.left,
1576 vcs->clipping.bottom - vcs->clipping.top); 1664 vcs->clipping.bottom - vcs->clipping.top);
@@ -1649,7 +1737,8 @@ static void vino_set_framerate(struct vino_channel_settings *vcs,
1649} 1737}
1650 1738
1651/* execute with input_lock locked */ 1739/* execute with input_lock locked */
1652static void vino_set_default_framerate(struct vino_channel_settings *vcs) 1740static inline void vino_set_default_framerate(struct
1741 vino_channel_settings *vcs)
1653{ 1742{
1654 vino_set_framerate(vcs, vino_data_norms[vcs->data_norm].fps_max); 1743 vino_set_framerate(vcs, vino_data_norms[vcs->data_norm].fps_max);
1655} 1744}
@@ -1687,6 +1776,9 @@ static int vino_dma_setup(struct vino_channel_settings *vcs,
1687 * should be more than enough time */ 1776 * should be more than enough time */
1688 udelay(VINO_DESC_FETCH_DELAY); 1777 udelay(VINO_DESC_FETCH_DELAY);
1689 1778
1779 dprintk("vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1780 ch->start_desc_tbl, ch->next_4_desc);
1781
1690 /* set the alpha register */ 1782 /* set the alpha register */
1691 ch->alpha = vcs->alpha; 1783 ch->alpha = vcs->alpha;
1692 1784
@@ -1700,9 +1792,6 @@ static int vino_dma_setup(struct vino_channel_settings *vcs,
1700 VINO_CLIP_EVEN(norm->even.top + 1792 VINO_CLIP_EVEN(norm->even.top +
1701 vcs->clipping.bottom / 2 - 1) | 1793 vcs->clipping.bottom / 2 - 1) |
1702 VINO_CLIP_X(vcs->clipping.right); 1794 VINO_CLIP_X(vcs->clipping.right);
1703 /* FIXME: end-of-field bug workaround
1704 VINO_CLIP_X(VINO_PAL_WIDTH);
1705 */
1706 1795
1707 /* set the size of actual content in the buffer (DECIMATION !) */ 1796 /* set the size of actual content in the buffer (DECIMATION !) */
1708 fb->data_size = ((vcs->clipping.right - vcs->clipping.left) / 1797 fb->data_size = ((vcs->clipping.right - vcs->clipping.left) /
@@ -1802,7 +1891,7 @@ static int vino_dma_setup(struct vino_channel_settings *vcs,
1802} 1891}
1803 1892
1804/* (execute only with vino_lock locked) */ 1893/* (execute only with vino_lock locked) */
1805static void vino_dma_start(struct vino_channel_settings *vcs) 1894static inline void vino_dma_start(struct vino_channel_settings *vcs)
1806{ 1895{
1807 u32 ctrl = vino->control; 1896 u32 ctrl = vino->control;
1808 1897
@@ -1813,12 +1902,14 @@ static void vino_dma_start(struct vino_channel_settings *vcs)
1813} 1902}
1814 1903
1815/* (execute only with vino_lock locked) */ 1904/* (execute only with vino_lock locked) */
1816static void vino_dma_stop(struct vino_channel_settings *vcs) 1905static inline void vino_dma_stop(struct vino_channel_settings *vcs)
1817{ 1906{
1818 u32 ctrl = vino->control; 1907 u32 ctrl = vino->control;
1819 1908
1820 ctrl &= (vcs->channel == VINO_CHANNEL_A) ? 1909 ctrl &= (vcs->channel == VINO_CHANNEL_A) ?
1821 ~VINO_CTRL_A_DMA_ENBL : ~VINO_CTRL_B_DMA_ENBL; 1910 ~VINO_CTRL_A_DMA_ENBL : ~VINO_CTRL_B_DMA_ENBL;
1911 ctrl &= (vcs->channel == VINO_CHANNEL_A) ?
1912 ~VINO_CTRL_A_INT : ~VINO_CTRL_B_INT;
1822 vino->control = ctrl; 1913 vino->control = ctrl;
1823 dprintk("vino_dma_stop():\n"); 1914 dprintk("vino_dma_stop():\n");
1824} 1915}
@@ -1902,7 +1993,7 @@ static int vino_capture_next(struct vino_channel_settings *vcs, int start)
1902 struct vino_framebuffer *fb; 1993 struct vino_framebuffer *fb;
1903 unsigned int incoming, id; 1994 unsigned int incoming, id;
1904 int err = 0; 1995 int err = 0;
1905 unsigned long flags, flags2; 1996 unsigned long flags;
1906 1997
1907 dprintk("vino_capture_next():\n"); 1998 dprintk("vino_capture_next():\n");
1908 1999
@@ -1943,10 +2034,6 @@ static int vino_capture_next(struct vino_channel_settings *vcs, int start)
1943 goto out; 2034 goto out;
1944 } 2035 }
1945 2036
1946 spin_lock_irqsave(&fb->state_lock, flags2);
1947 fb->state = VINO_FRAMEBUFFER_UNUSED;
1948 spin_unlock_irqrestore(&fb->state_lock, flags2);
1949
1950 if (start) { 2037 if (start) {
1951 vcs->capturing = 1; 2038 vcs->capturing = 1;
1952 } 2039 }
@@ -1964,7 +2051,7 @@ out:
1964 return err; 2051 return err;
1965} 2052}
1966 2053
1967static int vino_is_capturing(struct vino_channel_settings *vcs) 2054static inline int vino_is_capturing(struct vino_channel_settings *vcs)
1968{ 2055{
1969 int ret; 2056 int ret;
1970 unsigned long flags; 2057 unsigned long flags;
@@ -2076,6 +2163,7 @@ static void vino_capture_stop(struct vino_channel_settings *vcs)
2076 dprintk("vino_capture_stop():\n"); 2163 dprintk("vino_capture_stop():\n");
2077 2164
2078 spin_lock_irqsave(&vcs->capture_lock, flags); 2165 spin_lock_irqsave(&vcs->capture_lock, flags);
2166
2079 /* unset capturing to stop queue processing */ 2167 /* unset capturing to stop queue processing */
2080 vcs->capturing = 0; 2168 vcs->capturing = 0;
2081 2169
@@ -2121,6 +2209,7 @@ out:
2121 spin_unlock_irqrestore(&vcs->capture_lock, flags); 2209 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2122} 2210}
2123 2211
2212#if 0
2124static int vino_capture_failed(struct vino_channel_settings *vcs) 2213static int vino_capture_failed(struct vino_channel_settings *vcs)
2125{ 2214{
2126 struct vino_framebuffer *fb; 2215 struct vino_framebuffer *fb;
@@ -2165,9 +2254,31 @@ static int vino_capture_failed(struct vino_channel_settings *vcs)
2165 2254
2166 return 0; 2255 return 0;
2167} 2256}
2257#endif
2258
2259static void vino_skip_frame(struct vino_channel_settings *vcs)
2260{
2261 struct vino_framebuffer *fb;
2262 unsigned long flags;
2263 unsigned int id;
2264
2265 spin_lock_irqsave(&vcs->capture_lock, flags);
2266 fb = vino_queue_peek(&vcs->fb_queue, &id);
2267 if (!fb) {
2268 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2269 dprintk("vino_skip_frame(): vino_queue_peek() failed!\n");
2270 return;
2271 }
2272 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2273
2274 spin_lock_irqsave(&fb->state_lock, flags);
2275 fb->state = VINO_FRAMEBUFFER_UNUSED;
2276 spin_unlock_irqrestore(&fb->state_lock, flags);
2277
2278 vino_capture_next(vcs, 0);
2279}
2168 2280
2169static void vino_frame_done(struct vino_channel_settings *vcs, 2281static void vino_frame_done(struct vino_channel_settings *vcs)
2170 unsigned int fc)
2171{ 2282{
2172 struct vino_framebuffer *fb; 2283 struct vino_framebuffer *fb;
2173 unsigned long flags; 2284 unsigned long flags;
@@ -2181,8 +2292,9 @@ static void vino_frame_done(struct vino_channel_settings *vcs,
2181 } 2292 }
2182 spin_unlock_irqrestore(&vcs->capture_lock, flags); 2293 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2183 2294
2184 fb->frame_counter = fc; 2295 fb->frame_counter = vcs->int_data.frame_counter;
2185 do_gettimeofday(&fb->timestamp); 2296 memcpy(&fb->timestamp, &vcs->int_data.timestamp,
2297 sizeof(struct timeval));
2186 2298
2187 spin_lock_irqsave(&fb->state_lock, flags); 2299 spin_lock_irqsave(&fb->state_lock, flags);
2188 if (fb->state == VINO_FRAMEBUFFER_IN_USE) 2300 if (fb->state == VINO_FRAMEBUFFER_IN_USE)
@@ -2194,72 +2306,175 @@ static void vino_frame_done(struct vino_channel_settings *vcs,
2194 vino_capture_next(vcs, 0); 2306 vino_capture_next(vcs, 0);
2195} 2307}
2196 2308
2309static void vino_capture_tasklet(unsigned long channel) {
2310 struct vino_channel_settings *vcs;
2311
2312 vcs = (channel == VINO_CHANNEL_A)
2313 ? &vino_drvdata->a : &vino_drvdata->b;
2314
2315 if (vcs->int_data.skip)
2316 vcs->int_data.skip_count++;
2317
2318 if (vcs->int_data.skip && (vcs->int_data.skip_count
2319 <= VINO_MAX_FRAME_SKIP_COUNT)) {
2320 vino_skip_frame(vcs);
2321 } else {
2322 vcs->int_data.skip_count = 0;
2323 vino_frame_done(vcs);
2324 }
2325}
2326
2197static irqreturn_t vino_interrupt(int irq, void *dev_id, struct pt_regs *regs) 2327static irqreturn_t vino_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2198{ 2328{
2199 u32 intr; 2329 u32 ctrl, intr;
2200 unsigned int fc_a, fc_b; 2330 unsigned int fc_a, fc_b;
2201 int done_a = 0; 2331 int handled_a = 0, skip_a = 0, done_a = 0;
2202 int done_b = 0; 2332 int handled_b = 0, skip_b = 0, done_b = 0;
2333
2334#ifdef VINO_DEBUG_INT
2335 int loop = 0;
2336 unsigned int line_count = vino->a.line_count,
2337 page_index = vino->a.page_index,
2338 field_counter = vino->a.field_counter,
2339 start_desc_tbl = vino->a.start_desc_tbl,
2340 next_4_desc = vino->a.next_4_desc;
2341 unsigned int line_count_2,
2342 page_index_2,
2343 field_counter_2,
2344 start_desc_tbl_2,
2345 next_4_desc_2;
2346#endif
2203 2347
2204 spin_lock(&vino_drvdata->vino_lock); 2348 spin_lock(&vino_drvdata->vino_lock);
2205 2349
2206 intr = vino->intr_status; 2350 while ((intr = vino->intr_status)) {
2207 fc_a = vino->a.field_counter / 2; 2351 fc_a = vino->a.field_counter >> 1;
2208 fc_b = vino->b.field_counter / 2; 2352 fc_b = vino->b.field_counter >> 1;
2209 2353
2210 // TODO: handle error-interrupts in some special way ? 2354 /* handle error-interrupts in some special way ?
2211 2355 * --> skips frames */
2212 if (intr & VINO_INTSTAT_A) { 2356 if (intr & VINO_INTSTAT_A) {
2213 if (intr & VINO_INTSTAT_A_EOF) { 2357 if (intr & VINO_INTSTAT_A_EOF) {
2214 vino_drvdata->a.field++; 2358 vino_drvdata->a.field++;
2215 if (vino_drvdata->a.field > 1) { 2359 if (vino_drvdata->a.field > 1) {
2360 vino_dma_stop(&vino_drvdata->a);
2361 vino_clear_interrupt(&vino_drvdata->a);
2362 vino_drvdata->a.field = 0;
2363 done_a = 1;
2364 } else {
2365 if (vino->a.page_index
2366 != vino_drvdata->a.line_size) {
2367 vino->a.line_count = 0;
2368 vino->a.page_index =
2369 vino_drvdata->
2370 a.line_size;
2371 vino->a.next_4_desc =
2372 vino->a.start_desc_tbl;
2373 }
2374 }
2375 dprintk("channel A end-of-field "
2376 "interrupt: %04x\n", intr);
2377 } else {
2216 vino_dma_stop(&vino_drvdata->a); 2378 vino_dma_stop(&vino_drvdata->a);
2217 vino_clear_interrupt(&vino_drvdata->a); 2379 vino_clear_interrupt(&vino_drvdata->a);
2218 vino_drvdata->a.field = 0; 2380 vino_drvdata->a.field = 0;
2219 done_a = 1; 2381 skip_a = 1;
2382 dprintk("channel A error interrupt: %04x\n",
2383 intr);
2220 } 2384 }
2221 dprintk("intr: channel A end-of-field interrupt: " 2385
2222 "%04x\n", intr); 2386#ifdef VINO_DEBUG_INT
2223 } else { 2387 line_count_2 = vino->a.line_count;
2224 vino_dma_stop(&vino_drvdata->a); 2388 page_index_2 = vino->a.page_index;
2225 vino_clear_interrupt(&vino_drvdata->a); 2389 field_counter_2 = vino->a.field_counter;
2226 done_a = 1; 2390 start_desc_tbl_2 = vino->a.start_desc_tbl;
2227 dprintk("channel A error interrupt: %04x\n", intr); 2391 next_4_desc_2 = vino->a.next_4_desc;
2392
2393 printk("intr = %04x, loop = %d, field = %d\n",
2394 intr, loop, vino_drvdata->a.field);
2395 printk("1- line count = %04d, page index = %04d, "
2396 "start = %08x, next = %08x\n"
2397 " fieldc = %d, framec = %d\n",
2398 line_count, page_index, start_desc_tbl,
2399 next_4_desc, field_counter, fc_a);
2400 printk("12-line count = %04d, page index = %04d, "
2401 " start = %08x, next = %08x\n",
2402 line_count_2, page_index_2, start_desc_tbl_2,
2403 next_4_desc_2);
2404
2405 if (done_a)
2406 printk("\n");
2407#endif
2228 } 2408 }
2229 } 2409
2230 if (intr & VINO_INTSTAT_B) { 2410 if (intr & VINO_INTSTAT_B) {
2231 if (intr & VINO_INTSTAT_B_EOF) { 2411 if (intr & VINO_INTSTAT_B_EOF) {
2232 vino_drvdata->b.field++; 2412 vino_drvdata->b.field++;
2233 if (vino_drvdata->b.field > 1) { 2413 if (vino_drvdata->b.field > 1) {
2414 vino_dma_stop(&vino_drvdata->b);
2415 vino_clear_interrupt(&vino_drvdata->b);
2416 vino_drvdata->b.field = 0;
2417 done_b = 1;
2418 }
2419 dprintk("channel B end-of-field "
2420 "interrupt: %04x\n", intr);
2421 } else {
2234 vino_dma_stop(&vino_drvdata->b); 2422 vino_dma_stop(&vino_drvdata->b);
2235 vino_clear_interrupt(&vino_drvdata->b); 2423 vino_clear_interrupt(&vino_drvdata->b);
2236 vino_drvdata->b.field = 0; 2424 vino_drvdata->b.field = 0;
2237 done_b = 1; 2425 skip_b = 1;
2426 dprintk("channel B error interrupt: %04x\n",
2427 intr);
2238 } 2428 }
2239 dprintk("intr: channel B end-of-field interrupt: "
2240 "%04x\n", intr);
2241 } else {
2242 vino_dma_stop(&vino_drvdata->b);
2243 vino_clear_interrupt(&vino_drvdata->b);
2244 done_b = 1;
2245 dprintk("channel B error interrupt: %04x\n", intr);
2246 } 2429 }
2247 }
2248 2430
2249 /* always remember to clear interrupt status */ 2431 /* Always remember to clear interrupt status.
2250 vino->intr_status = ~intr; 2432 * Disable VINO interrupts while we do this. */
2433 ctrl = vino->control;
2434 vino->control = ctrl & ~(VINO_CTRL_A_INT | VINO_CTRL_B_INT);
2435 vino->intr_status = ~intr;
2436 vino->control = ctrl;
2251 2437
2252 spin_unlock(&vino_drvdata->vino_lock); 2438 spin_unlock(&vino_drvdata->vino_lock);
2253 2439
2254 if (done_a) { 2440 if ((!handled_a) && (done_a || skip_a)) {
2255 vino_frame_done(&vino_drvdata->a, fc_a); 2441 if (!skip_a) {
2256 dprintk("channel A frame done, interrupt: %d\n", intr); 2442 do_gettimeofday(&vino_drvdata->
2257 } 2443 a.int_data.timestamp);
2258 if (done_b) { 2444 vino_drvdata->a.int_data.frame_counter = fc_a;
2259 vino_frame_done(&vino_drvdata->b, fc_b); 2445 }
2260 dprintk("channel B frame done, interrupt: %d\n", intr); 2446 vino_drvdata->a.int_data.skip = skip_a;
2447
2448 dprintk("channel A %s, interrupt: %d\n",
2449 skip_a ? "skipping frame" : "frame done",
2450 intr);
2451 tasklet_hi_schedule(&vino_tasklet_a);
2452 handled_a = 1;
2453 }
2454
2455 if ((!handled_b) && (done_b || skip_b)) {
2456 if (!skip_b) {
2457 do_gettimeofday(&vino_drvdata->
2458 b.int_data.timestamp);
2459 vino_drvdata->b.int_data.frame_counter = fc_b;
2460 }
2461 vino_drvdata->b.int_data.skip = skip_b;
2462
2463 dprintk("channel B %s, interrupt: %d\n",
2464 skip_b ? "skipping frame" : "frame done",
2465 intr);
2466 tasklet_hi_schedule(&vino_tasklet_b);
2467 handled_b = 1;
2468 }
2469
2470#ifdef VINO_DEBUG_INT
2471 loop++;
2472#endif
2473 spin_lock(&vino_drvdata->vino_lock);
2261 } 2474 }
2262 2475
2476 spin_unlock(&vino_drvdata->vino_lock);
2477
2263 return IRQ_HANDLED; 2478 return IRQ_HANDLED;
2264} 2479}
2265 2480
@@ -2279,11 +2494,13 @@ static int vino_get_saa7191_input(int input)
2279 } 2494 }
2280} 2495}
2281 2496
2282static int vino_get_saa7191_norm(int norm) 2497static int vino_get_saa7191_norm(unsigned int data_norm)
2283{ 2498{
2284 switch (norm) { 2499 switch (data_norm) {
2285 case VINO_DATA_NORM_AUTO: 2500 case VINO_DATA_NORM_AUTO:
2286 return SAA7191_NORM_AUTO; 2501 return SAA7191_NORM_AUTO;
2502 case VINO_DATA_NORM_AUTO_EXT:
2503 return SAA7191_NORM_AUTO_EXT;
2287 case VINO_DATA_NORM_PAL: 2504 case VINO_DATA_NORM_PAL:
2288 return SAA7191_NORM_PAL; 2505 return SAA7191_NORM_PAL;
2289 case VINO_DATA_NORM_NTSC: 2506 case VINO_DATA_NORM_NTSC:
@@ -2297,6 +2514,57 @@ static int vino_get_saa7191_norm(int norm)
2297 } 2514 }
2298} 2515}
2299 2516
2517static int vino_get_from_saa7191_norm(int saa7191_norm)
2518{
2519 switch (saa7191_norm) {
2520 case SAA7191_NORM_PAL:
2521 return VINO_DATA_NORM_PAL;
2522 case SAA7191_NORM_NTSC:
2523 return VINO_DATA_NORM_NTSC;
2524 case SAA7191_NORM_SECAM:
2525 return VINO_DATA_NORM_SECAM;
2526 default:
2527 printk(KERN_ERR "VINO: vino_get_from_saa7191_norm(): "
2528 "invalid norm!\n");
2529 return VINO_DATA_NORM_NONE;
2530 }
2531}
2532
2533static int vino_saa7191_set_norm(unsigned int *data_norm)
2534{
2535 int saa7191_norm, new_data_norm;
2536 int err = 0;
2537
2538 saa7191_norm = vino_get_saa7191_norm(*data_norm);
2539
2540 err = i2c_decoder_command(DECODER_SAA7191_SET_NORM,
2541 &saa7191_norm);
2542 if (err)
2543 goto out;
2544
2545 if ((*data_norm == VINO_DATA_NORM_AUTO)
2546 || (*data_norm == VINO_DATA_NORM_AUTO_EXT)) {
2547 struct saa7191_status status;
2548
2549 err = i2c_decoder_command(DECODER_SAA7191_GET_STATUS,
2550 &status);
2551 if (err)
2552 goto out;
2553
2554 new_data_norm =
2555 vino_get_from_saa7191_norm(status.norm);
2556 if (new_data_norm == VINO_DATA_NORM_NONE) {
2557 err = -EINVAL;
2558 goto out;
2559 }
2560
2561 *data_norm = (unsigned int)new_data_norm;
2562 }
2563
2564out:
2565 return err;
2566}
2567
2300/* execute with input_lock locked */ 2568/* execute with input_lock locked */
2301static int vino_is_input_owner(struct vino_channel_settings *vcs) 2569static int vino_is_input_owner(struct vino_channel_settings *vcs)
2302{ 2570{
@@ -2313,11 +2581,12 @@ static int vino_is_input_owner(struct vino_channel_settings *vcs)
2313 2581
2314static int vino_acquire_input(struct vino_channel_settings *vcs) 2582static int vino_acquire_input(struct vino_channel_settings *vcs)
2315{ 2583{
2584 unsigned long flags;
2316 int ret = 0; 2585 int ret = 0;
2317 2586
2318 dprintk("vino_acquire_input():\n"); 2587 dprintk("vino_acquire_input():\n");
2319 2588
2320 spin_lock(&vino_drvdata->input_lock); 2589 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2321 2590
2322 /* First try D1 and then SAA7191 */ 2591 /* First try D1 and then SAA7191 */
2323 if (vino_drvdata->camera.driver 2592 if (vino_drvdata->camera.driver
@@ -2332,23 +2601,48 @@ static int vino_acquire_input(struct vino_channel_settings *vcs)
2332 vcs->data_norm = VINO_DATA_NORM_D1; 2601 vcs->data_norm = VINO_DATA_NORM_D1;
2333 } else if (vino_drvdata->decoder.driver 2602 } else if (vino_drvdata->decoder.driver
2334 && (vino_drvdata->decoder.owner == VINO_NO_CHANNEL)) { 2603 && (vino_drvdata->decoder.owner == VINO_NO_CHANNEL)) {
2604 int input, data_norm;
2335 int saa7191_input; 2605 int saa7191_input;
2336 int saa7191_norm;
2337 2606
2338 if (i2c_use_client(vino_drvdata->decoder.driver)) { 2607 if (i2c_use_client(vino_drvdata->decoder.driver)) {
2339 ret = -ENODEV; 2608 ret = -ENODEV;
2340 goto out; 2609 goto out;
2341 } 2610 }
2342 2611
2343 vino_drvdata->decoder.owner = vcs->channel; 2612 input = VINO_INPUT_COMPOSITE;
2344 vcs->input = VINO_INPUT_COMPOSITE; 2613
2345 vcs->data_norm = VINO_DATA_NORM_PAL; 2614 saa7191_input = vino_get_saa7191_input(input);
2615 ret = i2c_decoder_command(DECODER_SET_INPUT,
2616 &saa7191_input);
2617 if (ret) {
2618 ret = -EINVAL;
2619 goto out;
2620 }
2621
2622 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2346 2623
2347 saa7191_input = vino_get_saa7191_input(vcs->input); 2624 /* Don't hold spinlocks while auto-detecting norm
2348 i2c_decoder_command(DECODER_SET_INPUT, &saa7191_input); 2625 * as it may take a while... */
2349 2626
2350 saa7191_norm = vino_get_saa7191_norm(vcs->data_norm); 2627 data_norm = VINO_DATA_NORM_AUTO_EXT;
2351 i2c_decoder_command(DECODER_SAA7191_SET_NORM, &saa7191_norm); 2628
2629 ret = vino_saa7191_set_norm(&data_norm);
2630 if ((ret == -EBUSY) || (ret == -EAGAIN)) {
2631 data_norm = VINO_DATA_NORM_PAL;
2632 ret = vino_saa7191_set_norm(&data_norm);
2633 }
2634
2635 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2636
2637 if (ret) {
2638 ret = -EINVAL;
2639 goto out;
2640 }
2641
2642 vino_drvdata->decoder.owner = vcs->channel;
2643
2644 vcs->input = input;
2645 vcs->data_norm = data_norm;
2352 } else { 2646 } else {
2353 vcs->input = (vcs->channel == VINO_CHANNEL_A) ? 2647 vcs->input = (vcs->channel == VINO_CHANNEL_A) ?
2354 vino_drvdata->b.input : vino_drvdata->a.input; 2648 vino_drvdata->b.input : vino_drvdata->a.input;
@@ -2361,15 +2655,14 @@ static int vino_acquire_input(struct vino_channel_settings *vcs)
2361 goto out; 2655 goto out;
2362 } 2656 }
2363 2657
2364 if (vino_is_input_owner(vcs)) { 2658 vino_set_default_clipping(vcs);
2365 vino_set_default_clipping(vcs); 2659 vino_set_default_scaling(vcs);
2366 vino_set_default_framerate(vcs); 2660 vino_set_default_framerate(vcs);
2367 }
2368 2661
2369 dprintk("vino_acquire_input(): %s\n", vino_inputs[vcs->input].name); 2662 dprintk("vino_acquire_input(): %s\n", vino_inputs[vcs->input].name);
2370 2663
2371out: 2664out:
2372 spin_unlock(&vino_drvdata->input_lock); 2665 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2373 2666
2374 return ret; 2667 return ret;
2375} 2668}
@@ -2378,16 +2671,17 @@ static int vino_set_input(struct vino_channel_settings *vcs, int input)
2378{ 2671{
2379 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ? 2672 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
2380 &vino_drvdata->b : &vino_drvdata->a; 2673 &vino_drvdata->b : &vino_drvdata->a;
2674 unsigned long flags;
2381 int ret = 0; 2675 int ret = 0;
2382 2676
2383 dprintk("vino_set_input():\n"); 2677 dprintk("vino_set_input():\n");
2384 2678
2385 spin_lock(&vino_drvdata->input_lock); 2679 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2386 2680
2387 if (vcs->input == input) 2681 if (vcs->input == input)
2388 goto out; 2682 goto out;
2389 2683
2390 switch(input) { 2684 switch (input) {
2391 case VINO_INPUT_COMPOSITE: 2685 case VINO_INPUT_COMPOSITE:
2392 case VINO_INPUT_SVIDEO: 2686 case VINO_INPUT_SVIDEO:
2393 if (!vino_drvdata->decoder.driver) { 2687 if (!vino_drvdata->decoder.driver) {
@@ -2404,19 +2698,43 @@ static int vino_set_input(struct vino_channel_settings *vcs, int input)
2404 } 2698 }
2405 2699
2406 if (vino_drvdata->decoder.owner == vcs->channel) { 2700 if (vino_drvdata->decoder.owner == vcs->channel) {
2701 int data_norm;
2407 int saa7191_input; 2702 int saa7191_input;
2408 int saa7191_norm;
2409 2703
2410 vcs->input = input; 2704 saa7191_input = vino_get_saa7191_input(input);
2411 vcs->data_norm = VINO_DATA_NORM_PAL; 2705 ret = i2c_decoder_command(DECODER_SET_INPUT,
2706 &saa7191_input);
2707 if (ret) {
2708 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2709 ret = -EINVAL;
2710 goto out;
2711 }
2712
2713 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2714
2715 /* Don't hold spinlocks while auto-detecting norm
2716 * as it may take a while... */
2717
2718 data_norm = VINO_DATA_NORM_AUTO_EXT;
2719
2720 ret = vino_saa7191_set_norm(&data_norm);
2721 if ((ret == -EBUSY) || (ret == -EAGAIN)) {
2722 data_norm = VINO_DATA_NORM_PAL;
2723 ret = vino_saa7191_set_norm(&data_norm);
2724 }
2412 2725
2413 saa7191_input = vino_get_saa7191_input(vcs->input); 2726 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2414 i2c_decoder_command(DECODER_SET_INPUT, &saa7191_input); 2727
2415 saa7191_norm = vino_get_saa7191_norm(vcs->data_norm); 2728 if (ret) {
2416 i2c_decoder_command(DECODER_SAA7191_SET_NORM, 2729 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2417 &saa7191_norm); 2730 ret = -EINVAL;
2731 goto out;
2732 }
2733
2734 vcs->input = input;
2735 vcs->data_norm = data_norm;
2418 } else { 2736 } else {
2419 if (vcs2->input != input) { 2737 if (input != vcs2->input) {
2420 ret = -EBUSY; 2738 ret = -EBUSY;
2421 goto out; 2739 goto out;
2422 } 2740 }
@@ -2471,12 +2789,13 @@ static int vino_set_input(struct vino_channel_settings *vcs, int input)
2471 } 2789 }
2472 2790
2473 vino_set_default_clipping(vcs); 2791 vino_set_default_clipping(vcs);
2792 vino_set_default_scaling(vcs);
2474 vino_set_default_framerate(vcs); 2793 vino_set_default_framerate(vcs);
2475 2794
2476 dprintk("vino_set_input(): %s\n", vino_inputs[vcs->input].name); 2795 dprintk("vino_set_input(): %s\n", vino_inputs[vcs->input].name);
2477 2796
2478out: 2797out:
2479 spin_unlock(&vino_drvdata->input_lock); 2798 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2480 2799
2481 return ret; 2800 return ret;
2482} 2801}
@@ -2485,10 +2804,11 @@ static void vino_release_input(struct vino_channel_settings *vcs)
2485{ 2804{
2486 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ? 2805 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
2487 &vino_drvdata->b : &vino_drvdata->a; 2806 &vino_drvdata->b : &vino_drvdata->a;
2807 unsigned long flags;
2488 2808
2489 dprintk("vino_release_input():\n"); 2809 dprintk("vino_release_input():\n");
2490 2810
2491 spin_lock(&vino_drvdata->input_lock); 2811 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2492 2812
2493 /* Release ownership of the channel 2813 /* Release ownership of the channel
2494 * and if the other channel takes input from 2814 * and if the other channel takes input from
@@ -2511,34 +2831,61 @@ static void vino_release_input(struct vino_channel_settings *vcs)
2511 } 2831 }
2512 vcs->input = VINO_INPUT_NONE; 2832 vcs->input = VINO_INPUT_NONE;
2513 2833
2514 spin_unlock(&vino_drvdata->input_lock); 2834 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2515} 2835}
2516 2836
2517/* execute with input_lock locked */ 2837/* execute with input_lock locked */
2518static int vino_set_data_norm(struct vino_channel_settings *vcs, 2838static int vino_set_data_norm(struct vino_channel_settings *vcs,
2519 unsigned int data_norm) 2839 unsigned int data_norm,
2840 unsigned long *flags)
2520{ 2841{
2521 int saa7191_norm; 2842 int err = 0;
2843
2844 if (data_norm == vcs->data_norm)
2845 return 0;
2522 2846
2523 switch (vcs->input) { 2847 switch (vcs->input) {
2524 case VINO_INPUT_D1: 2848 case VINO_INPUT_D1:
2525 /* only one "norm" supported */ 2849 /* only one "norm" supported */
2526 if (data_norm != VINO_DATA_NORM_D1) 2850 if ((data_norm != VINO_DATA_NORM_D1)
2851 && (data_norm != VINO_DATA_NORM_AUTO)
2852 && (data_norm != VINO_DATA_NORM_AUTO_EXT))
2527 return -EINVAL; 2853 return -EINVAL;
2528 break; 2854 break;
2529 case VINO_INPUT_COMPOSITE: 2855 case VINO_INPUT_COMPOSITE:
2530 case VINO_INPUT_SVIDEO: 2856 case VINO_INPUT_SVIDEO: {
2857 if ((data_norm != VINO_DATA_NORM_PAL)
2858 && (data_norm != VINO_DATA_NORM_NTSC)
2859 && (data_norm != VINO_DATA_NORM_SECAM)
2860 && (data_norm != VINO_DATA_NORM_AUTO)
2861 && (data_norm != VINO_DATA_NORM_AUTO_EXT))
2862 return -EINVAL;
2531 2863
2532 saa7191_norm = vino_get_saa7191_norm(data_norm); 2864 spin_unlock_irqrestore(&vino_drvdata->input_lock, *flags);
2865
2866 /* Don't hold spinlocks while setting norm
2867 * as it may take a while... */
2868
2869 err = vino_saa7191_set_norm(&data_norm);
2870
2871 spin_lock_irqsave(&vino_drvdata->input_lock, *flags);
2872
2873 if (err)
2874 goto out;
2533 2875
2534 i2c_decoder_command(DECODER_SAA7191_SET_NORM, &saa7191_norm);
2535 vcs->data_norm = data_norm; 2876 vcs->data_norm = data_norm;
2877
2878 vino_set_default_clipping(vcs);
2879 vino_set_default_scaling(vcs);
2880 vino_set_default_framerate(vcs);
2536 break; 2881 break;
2882 }
2537 default: 2883 default:
2538 return -EINVAL; 2884 return -EINVAL;
2539 } 2885 }
2540 2886
2541 return 0; 2887out:
2888 return err;
2542} 2889}
2543 2890
2544/* V4L2 helper functions */ 2891/* V4L2 helper functions */
@@ -2558,8 +2905,9 @@ static int vino_find_data_format(__u32 pixelformat)
2558static int vino_enum_data_norm(struct vino_channel_settings *vcs, __u32 index) 2905static int vino_enum_data_norm(struct vino_channel_settings *vcs, __u32 index)
2559{ 2906{
2560 int data_norm = VINO_DATA_NORM_NONE; 2907 int data_norm = VINO_DATA_NORM_NONE;
2908 unsigned long flags;
2561 2909
2562 spin_lock(&vino_drvdata->input_lock); 2910 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2563 switch(vcs->input) { 2911 switch(vcs->input) {
2564 case VINO_INPUT_COMPOSITE: 2912 case VINO_INPUT_COMPOSITE:
2565 case VINO_INPUT_SVIDEO: 2913 case VINO_INPUT_SVIDEO:
@@ -2577,7 +2925,7 @@ static int vino_enum_data_norm(struct vino_channel_settings *vcs, __u32 index)
2577 } 2925 }
2578 break; 2926 break;
2579 } 2927 }
2580 spin_unlock(&vino_drvdata->input_lock); 2928 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2581 2929
2582 return data_norm; 2930 return data_norm;
2583} 2931}
@@ -2585,8 +2933,9 @@ static int vino_enum_data_norm(struct vino_channel_settings *vcs, __u32 index)
2585static int vino_enum_input(struct vino_channel_settings *vcs, __u32 index) 2933static int vino_enum_input(struct vino_channel_settings *vcs, __u32 index)
2586{ 2934{
2587 int input = VINO_INPUT_NONE; 2935 int input = VINO_INPUT_NONE;
2936 unsigned long flags;
2588 2937
2589 spin_lock(&vino_drvdata->input_lock); 2938 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2590 if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) { 2939 if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) {
2591 switch (index) { 2940 switch (index) {
2592 case 0: 2941 case 0:
@@ -2615,7 +2964,7 @@ static int vino_enum_input(struct vino_channel_settings *vcs, __u32 index)
2615 break; 2964 break;
2616 } 2965 }
2617 } 2966 }
2618 spin_unlock(&vino_drvdata->input_lock); 2967 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2619 2968
2620 return input; 2969 return input;
2621} 2970}
@@ -2704,15 +3053,16 @@ static int vino_v4l2_enuminput(struct vino_channel_settings *vcs,
2704} 3053}
2705 3054
2706static int vino_v4l2_g_input(struct vino_channel_settings *vcs, 3055static int vino_v4l2_g_input(struct vino_channel_settings *vcs,
2707 struct v4l2_input *i) 3056 unsigned int *i)
2708{ 3057{
2709 __u32 index; 3058 __u32 index;
2710 int input; 3059 int input;
3060 unsigned long flags;
2711 3061
2712 spin_lock(&vino_drvdata->input_lock); 3062 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2713 input = vcs->input; 3063 input = vcs->input;
2714 index = vino_find_input_index(vcs); 3064 index = vino_find_input_index(vcs);
2715 spin_unlock(&vino_drvdata->input_lock); 3065 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2716 3066
2717 dprintk("input = %d\n", input); 3067 dprintk("input = %d\n", input);
2718 3068
@@ -2720,23 +3070,18 @@ static int vino_v4l2_g_input(struct vino_channel_settings *vcs,
2720 return -EINVAL; 3070 return -EINVAL;
2721 } 3071 }
2722 3072
2723 memset(i, 0, sizeof(struct v4l2_input)); 3073 *i = index;
2724
2725 i->index = index;
2726 i->type = V4L2_INPUT_TYPE_CAMERA;
2727 i->std = vino_inputs[input].std;
2728 strcpy(i->name, vino_inputs[input].name);
2729 3074
2730 return 0; 3075 return 0;
2731} 3076}
2732 3077
2733static int vino_v4l2_s_input(struct vino_channel_settings *vcs, 3078static int vino_v4l2_s_input(struct vino_channel_settings *vcs,
2734 struct v4l2_input *i) 3079 unsigned int *i)
2735{ 3080{
2736 int input; 3081 int input;
2737 dprintk("requested input = %d\n", i->index); 3082 dprintk("requested input = %d\n", *i);
2738 3083
2739 input = vino_enum_input(vcs, i->index); 3084 input = vino_enum_input(vcs, *i);
2740 if (input == VINO_INPUT_NONE) 3085 if (input == VINO_INPUT_NONE)
2741 return -EINVAL; 3086 return -EINVAL;
2742 3087
@@ -2747,7 +3092,9 @@ static int vino_v4l2_enumstd(struct vino_channel_settings *vcs,
2747 struct v4l2_standard *s) 3092 struct v4l2_standard *s)
2748{ 3093{
2749 int index = s->index; 3094 int index = s->index;
2750 int data_norm = vino_enum_data_norm(vcs, index); 3095 int data_norm;
3096
3097 data_norm = vino_enum_data_norm(vcs, index);
2751 dprintk("standard index = %d\n", index); 3098 dprintk("standard index = %d\n", index);
2752 3099
2753 if (data_norm == VINO_DATA_NORM_NONE) 3100 if (data_norm == VINO_DATA_NORM_NONE)
@@ -2771,13 +3118,55 @@ static int vino_v4l2_enumstd(struct vino_channel_settings *vcs,
2771 return 0; 3118 return 0;
2772} 3119}
2773 3120
3121static int vino_v4l2_querystd(struct vino_channel_settings *vcs,
3122 v4l2_std_id *std)
3123{
3124 unsigned long flags;
3125 int err = 0;
3126
3127 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3128
3129 switch (vcs->input) {
3130 case VINO_INPUT_D1:
3131 *std = vino_inputs[vcs->input].std;
3132 break;
3133 case VINO_INPUT_COMPOSITE:
3134 case VINO_INPUT_SVIDEO: {
3135 struct saa7191_status status;
3136
3137 i2c_decoder_command(DECODER_SAA7191_GET_STATUS, &status);
3138
3139 if (status.signal) {
3140 if (status.signal_60hz) {
3141 *std = V4L2_STD_NTSC;
3142 } else {
3143 *std = V4L2_STD_PAL | V4L2_STD_SECAM;
3144 }
3145 } else {
3146 *std = vino_inputs[vcs->input].std;
3147 }
3148 break;
3149 }
3150 default:
3151 err = -EINVAL;
3152 }
3153
3154 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3155
3156 return err;
3157}
3158
2774static int vino_v4l2_g_std(struct vino_channel_settings *vcs, 3159static int vino_v4l2_g_std(struct vino_channel_settings *vcs,
2775 v4l2_std_id *std) 3160 v4l2_std_id *std)
2776{ 3161{
2777 spin_lock(&vino_drvdata->input_lock); 3162 unsigned long flags;
2778 dprintk("current standard = %d\n", vcs->data_norm); 3163
3164 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3165
2779 *std = vino_data_norms[vcs->data_norm].std; 3166 *std = vino_data_norms[vcs->data_norm].std;
2780 spin_unlock(&vino_drvdata->input_lock); 3167 dprintk("current standard = %d\n", vcs->data_norm);
3168
3169 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2781 3170
2782 return 0; 3171 return 0;
2783} 3172}
@@ -2785,13 +3174,18 @@ static int vino_v4l2_g_std(struct vino_channel_settings *vcs,
2785static int vino_v4l2_s_std(struct vino_channel_settings *vcs, 3174static int vino_v4l2_s_std(struct vino_channel_settings *vcs,
2786 v4l2_std_id *std) 3175 v4l2_std_id *std)
2787{ 3176{
3177 unsigned long flags;
2788 int ret = 0; 3178 int ret = 0;
2789 3179
2790 spin_lock(&vino_drvdata->input_lock); 3180 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3181
3182 if (!vino_is_input_owner(vcs)) {
3183 ret = -EBUSY;
3184 goto out;
3185 }
2791 3186
2792 /* check if the standard is valid for the current input */ 3187 /* check if the standard is valid for the current input */
2793 if (vino_is_input_owner(vcs) 3188 if ((*std) & vino_inputs[vcs->input].std) {
2794 && (vino_inputs[vcs->input].std & (*std))) {
2795 dprintk("standard accepted\n"); 3189 dprintk("standard accepted\n");
2796 3190
2797 /* change the video norm for SAA7191 3191 /* change the video norm for SAA7191
@@ -2800,24 +3194,33 @@ static int vino_v4l2_s_std(struct vino_channel_settings *vcs,
2800 if (vcs->input == VINO_INPUT_D1) 3194 if (vcs->input == VINO_INPUT_D1)
2801 goto out; 3195 goto out;
2802 3196
2803 if ((*std) & V4L2_STD_PAL) { 3197 if (((*std) & V4L2_STD_PAL)
2804 vino_set_data_norm(vcs, VINO_DATA_NORM_PAL); 3198 && ((*std) & V4L2_STD_NTSC)
2805 vcs->data_norm = VINO_DATA_NORM_PAL; 3199 && ((*std) & V4L2_STD_SECAM)) {
3200 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_AUTO_EXT,
3201 &flags);
3202 } else if ((*std) & V4L2_STD_PAL) {
3203 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_PAL,
3204 &flags);
2806 } else if ((*std) & V4L2_STD_NTSC) { 3205 } else if ((*std) & V4L2_STD_NTSC) {
2807 vino_set_data_norm(vcs, VINO_DATA_NORM_NTSC); 3206 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_NTSC,
2808 vcs->data_norm = VINO_DATA_NORM_NTSC; 3207 &flags);
2809 } else if ((*std) & V4L2_STD_SECAM) { 3208 } else if ((*std) & V4L2_STD_SECAM) {
2810 vino_set_data_norm(vcs, VINO_DATA_NORM_SECAM); 3209 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_SECAM,
2811 vcs->data_norm = VINO_DATA_NORM_SECAM; 3210 &flags);
2812 } else { 3211 } else {
2813 ret = -EINVAL; 3212 ret = -EINVAL;
2814 } 3213 }
3214
3215 if (ret) {
3216 ret = -EINVAL;
3217 }
2815 } else { 3218 } else {
2816 ret = -EINVAL; 3219 ret = -EINVAL;
2817 } 3220 }
2818 3221
2819out: 3222out:
2820 spin_unlock(&vino_drvdata->input_lock); 3223 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2821 3224
2822 return ret; 3225 return ret;
2823} 3226}
@@ -2855,6 +3258,7 @@ static int vino_v4l2_try_fmt(struct vino_channel_settings *vcs,
2855 struct v4l2_format *f) 3258 struct v4l2_format *f)
2856{ 3259{
2857 struct vino_channel_settings tempvcs; 3260 struct vino_channel_settings tempvcs;
3261 unsigned long flags;
2858 3262
2859 switch (f->type) { 3263 switch (f->type) {
2860 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 3264 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
@@ -2863,13 +3267,13 @@ static int vino_v4l2_try_fmt(struct vino_channel_settings *vcs,
2863 dprintk("requested: w = %d, h = %d\n", 3267 dprintk("requested: w = %d, h = %d\n",
2864 pf->width, pf->height); 3268 pf->width, pf->height);
2865 3269
2866 spin_lock(&vino_drvdata->input_lock); 3270 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2867 memcpy(&tempvcs, vcs, sizeof(struct vino_channel_settings)); 3271 memcpy(&tempvcs, vcs, sizeof(struct vino_channel_settings));
2868 spin_unlock(&vino_drvdata->input_lock); 3272 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2869 3273
2870 tempvcs.data_format = vino_find_data_format(pf->pixelformat); 3274 tempvcs.data_format = vino_find_data_format(pf->pixelformat);
2871 if (tempvcs.data_format == VINO_DATA_FMT_NONE) { 3275 if (tempvcs.data_format == VINO_DATA_FMT_NONE) {
2872 tempvcs.data_format = VINO_DATA_FMT_RGB32; 3276 tempvcs.data_format = VINO_DATA_FMT_GREY;
2873 pf->pixelformat = 3277 pf->pixelformat =
2874 vino_data_formats[tempvcs.data_format]. 3278 vino_data_formats[tempvcs.data_format].
2875 pixelformat; 3279 pixelformat;
@@ -2908,10 +3312,13 @@ static int vino_v4l2_try_fmt(struct vino_channel_settings *vcs,
2908static int vino_v4l2_g_fmt(struct vino_channel_settings *vcs, 3312static int vino_v4l2_g_fmt(struct vino_channel_settings *vcs,
2909 struct v4l2_format *f) 3313 struct v4l2_format *f)
2910{ 3314{
3315 unsigned long flags;
3316
2911 switch (f->type) { 3317 switch (f->type) {
2912 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 3318 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
2913 struct v4l2_pix_format *pf = &f->fmt.pix; 3319 struct v4l2_pix_format *pf = &f->fmt.pix;
2914 spin_lock(&vino_drvdata->input_lock); 3320
3321 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2915 3322
2916 pf->width = (vcs->clipping.right - vcs->clipping.left) / 3323 pf->width = (vcs->clipping.right - vcs->clipping.left) /
2917 vcs->decimation; 3324 vcs->decimation;
@@ -2930,7 +3337,7 @@ static int vino_v4l2_g_fmt(struct vino_channel_settings *vcs,
2930 3337
2931 pf->priv = 0; 3338 pf->priv = 0;
2932 3339
2933 spin_unlock(&vino_drvdata->input_lock); 3340 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2934 break; 3341 break;
2935 } 3342 }
2936 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 3343 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
@@ -2945,20 +3352,18 @@ static int vino_v4l2_s_fmt(struct vino_channel_settings *vcs,
2945 struct v4l2_format *f) 3352 struct v4l2_format *f)
2946{ 3353{
2947 int data_format; 3354 int data_format;
3355 unsigned long flags;
2948 3356
2949 switch (f->type) { 3357 switch (f->type) {
2950 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 3358 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
2951 struct v4l2_pix_format *pf = &f->fmt.pix; 3359 struct v4l2_pix_format *pf = &f->fmt.pix;
2952 spin_lock(&vino_drvdata->input_lock);
2953 3360
2954 if (!vino_is_input_owner(vcs)) { 3361 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2955 spin_unlock(&vino_drvdata->input_lock);
2956 return -EINVAL;
2957 }
2958 3362
2959 data_format = vino_find_data_format(pf->pixelformat); 3363 data_format = vino_find_data_format(pf->pixelformat);
3364
2960 if (data_format == VINO_DATA_FMT_NONE) { 3365 if (data_format == VINO_DATA_FMT_NONE) {
2961 vcs->data_format = VINO_DATA_FMT_RGB32; 3366 vcs->data_format = VINO_DATA_FMT_GREY;
2962 pf->pixelformat = 3367 pf->pixelformat =
2963 vino_data_formats[vcs->data_format]. 3368 vino_data_formats[vcs->data_format].
2964 pixelformat; 3369 pixelformat;
@@ -2985,7 +3390,7 @@ static int vino_v4l2_s_fmt(struct vino_channel_settings *vcs,
2985 3390
2986 pf->priv = 0; 3391 pf->priv = 0;
2987 3392
2988 spin_unlock(&vino_drvdata->input_lock); 3393 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2989 break; 3394 break;
2990 } 3395 }
2991 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 3396 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
@@ -3000,12 +3405,15 @@ static int vino_v4l2_cropcap(struct vino_channel_settings *vcs,
3000 struct v4l2_cropcap *ccap) 3405 struct v4l2_cropcap *ccap)
3001{ 3406{
3002 const struct vino_data_norm *norm; 3407 const struct vino_data_norm *norm;
3408 unsigned long flags;
3003 3409
3004 switch (ccap->type) { 3410 switch (ccap->type) {
3005 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 3411 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3006 spin_lock(&vino_drvdata->input_lock); 3412 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3413
3007 norm = &vino_data_norms[vcs->data_norm]; 3414 norm = &vino_data_norms[vcs->data_norm];
3008 spin_unlock(&vino_drvdata->input_lock); 3415
3416 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3009 3417
3010 ccap->bounds.left = 0; 3418 ccap->bounds.left = 0;
3011 ccap->bounds.top = 0; 3419 ccap->bounds.top = 0;
@@ -3028,16 +3436,18 @@ static int vino_v4l2_cropcap(struct vino_channel_settings *vcs,
3028static int vino_v4l2_g_crop(struct vino_channel_settings *vcs, 3436static int vino_v4l2_g_crop(struct vino_channel_settings *vcs,
3029 struct v4l2_crop *c) 3437 struct v4l2_crop *c)
3030{ 3438{
3439 unsigned long flags;
3440
3031 switch (c->type) { 3441 switch (c->type) {
3032 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 3442 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3033 spin_lock(&vino_drvdata->input_lock); 3443 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3034 3444
3035 c->c.left = vcs->clipping.left; 3445 c->c.left = vcs->clipping.left;
3036 c->c.top = vcs->clipping.top; 3446 c->c.top = vcs->clipping.top;
3037 c->c.width = vcs->clipping.right - vcs->clipping.left; 3447 c->c.width = vcs->clipping.right - vcs->clipping.left;
3038 c->c.height = vcs->clipping.bottom - vcs->clipping.top; 3448 c->c.height = vcs->clipping.bottom - vcs->clipping.top;
3039 3449
3040 spin_unlock(&vino_drvdata->input_lock); 3450 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3041 break; 3451 break;
3042 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 3452 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3043 default: 3453 default:
@@ -3050,18 +3460,16 @@ static int vino_v4l2_g_crop(struct vino_channel_settings *vcs,
3050static int vino_v4l2_s_crop(struct vino_channel_settings *vcs, 3460static int vino_v4l2_s_crop(struct vino_channel_settings *vcs,
3051 struct v4l2_crop *c) 3461 struct v4l2_crop *c)
3052{ 3462{
3463 unsigned long flags;
3464
3053 switch (c->type) { 3465 switch (c->type) {
3054 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 3466 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3055 spin_lock(&vino_drvdata->input_lock); 3467 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3056 3468
3057 if (!vino_is_input_owner(vcs)) {
3058 spin_unlock(&vino_drvdata->input_lock);
3059 return -EINVAL;
3060 }
3061 vino_set_clipping(vcs, c->c.left, c->c.top, 3469 vino_set_clipping(vcs, c->c.left, c->c.top,
3062 c->c.width, c->c.height); 3470 c->c.width, c->c.height);
3063 3471
3064 spin_unlock(&vino_drvdata->input_lock); 3472 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3065 break; 3473 break;
3066 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 3474 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3067 default: 3475 default:
@@ -3074,6 +3482,8 @@ static int vino_v4l2_s_crop(struct vino_channel_settings *vcs,
3074static int vino_v4l2_g_parm(struct vino_channel_settings *vcs, 3482static int vino_v4l2_g_parm(struct vino_channel_settings *vcs,
3075 struct v4l2_streamparm *sp) 3483 struct v4l2_streamparm *sp)
3076{ 3484{
3485 unsigned long flags;
3486
3077 switch (sp->type) { 3487 switch (sp->type) {
3078 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 3488 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3079 struct v4l2_captureparm *cp = &sp->parm.capture; 3489 struct v4l2_captureparm *cp = &sp->parm.capture;
@@ -3082,9 +3492,11 @@ static int vino_v4l2_g_parm(struct vino_channel_settings *vcs,
3082 cp->capability = V4L2_CAP_TIMEPERFRAME; 3492 cp->capability = V4L2_CAP_TIMEPERFRAME;
3083 cp->timeperframe.numerator = 1; 3493 cp->timeperframe.numerator = 1;
3084 3494
3085 spin_lock(&vino_drvdata->input_lock); 3495 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3496
3086 cp->timeperframe.denominator = vcs->fps; 3497 cp->timeperframe.denominator = vcs->fps;
3087 spin_unlock(&vino_drvdata->input_lock); 3498
3499 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3088 3500
3089 // TODO: cp->readbuffers = xxx; 3501 // TODO: cp->readbuffers = xxx;
3090 break; 3502 break;
@@ -3100,15 +3512,13 @@ static int vino_v4l2_g_parm(struct vino_channel_settings *vcs,
3100static int vino_v4l2_s_parm(struct vino_channel_settings *vcs, 3512static int vino_v4l2_s_parm(struct vino_channel_settings *vcs,
3101 struct v4l2_streamparm *sp) 3513 struct v4l2_streamparm *sp)
3102{ 3514{
3515 unsigned long flags;
3516
3103 switch (sp->type) { 3517 switch (sp->type) {
3104 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 3518 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3105 struct v4l2_captureparm *cp = &sp->parm.capture; 3519 struct v4l2_captureparm *cp = &sp->parm.capture;
3106 3520
3107 spin_lock(&vino_drvdata->input_lock); 3521 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3108 if (!vino_is_input_owner(vcs)) {
3109 spin_unlock(&vino_drvdata->input_lock);
3110 return -EINVAL;
3111 }
3112 3522
3113 if ((cp->timeperframe.numerator == 0) || 3523 if ((cp->timeperframe.numerator == 0) ||
3114 (cp->timeperframe.denominator == 0)) { 3524 (cp->timeperframe.denominator == 0)) {
@@ -3118,7 +3528,8 @@ static int vino_v4l2_s_parm(struct vino_channel_settings *vcs,
3118 vino_set_framerate(vcs, cp->timeperframe.denominator / 3528 vino_set_framerate(vcs, cp->timeperframe.denominator /
3119 cp->timeperframe.numerator); 3529 cp->timeperframe.numerator);
3120 } 3530 }
3121 spin_unlock(&vino_drvdata->input_lock); 3531
3532 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3122 3533
3123 // TODO: set buffers according to cp->readbuffers 3534 // TODO: set buffers according to cp->readbuffers
3124 break; 3535 break;
@@ -3145,21 +3556,23 @@ static int vino_v4l2_reqbufs(struct vino_channel_settings *vcs,
3145 return -EINVAL; 3556 return -EINVAL;
3146 } 3557 }
3147 3558
3148 if (vino_is_capturing(vcs)) {
3149 dprintk("busy, capturing\n");
3150 return -EBUSY;
3151 }
3152
3153 dprintk("count = %d\n", rb->count); 3559 dprintk("count = %d\n", rb->count);
3154 if (rb->count > 0) { 3560 if (rb->count > 0) {
3561 if (vino_is_capturing(vcs)) {
3562 dprintk("busy, capturing\n");
3563 return -EBUSY;
3564 }
3565
3155 if (vino_queue_has_mapped_buffers(&vcs->fb_queue)) { 3566 if (vino_queue_has_mapped_buffers(&vcs->fb_queue)) {
3156 dprintk("busy, buffers still mapped\n"); 3567 dprintk("busy, buffers still mapped\n");
3157 return -EBUSY; 3568 return -EBUSY;
3158 } else { 3569 } else {
3570 vcs->streaming = 0;
3159 vino_queue_free(&vcs->fb_queue); 3571 vino_queue_free(&vcs->fb_queue);
3160 vino_queue_init(&vcs->fb_queue, &rb->count); 3572 vino_queue_init(&vcs->fb_queue, &rb->count);
3161 } 3573 }
3162 } else { 3574 } else {
3575 vcs->streaming = 0;
3163 vino_capture_stop(vcs); 3576 vino_capture_stop(vcs);
3164 vino_queue_free(&vcs->fb_queue); 3577 vino_queue_free(&vcs->fb_queue);
3165 } 3578 }
@@ -3302,12 +3715,12 @@ static int vino_v4l2_dqbuf(struct vino_channel_settings *vcs,
3302 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming); 3715 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
3303 if (err) { 3716 if (err) {
3304 dprintk("vino_queue_get_incoming() failed\n"); 3717 dprintk("vino_queue_get_incoming() failed\n");
3305 return -EIO; 3718 return -EINVAL;
3306 } 3719 }
3307 err = vino_queue_get_outgoing(&vcs->fb_queue, &outgoing); 3720 err = vino_queue_get_outgoing(&vcs->fb_queue, &outgoing);
3308 if (err) { 3721 if (err) {
3309 dprintk("vino_queue_get_outgoing() failed\n"); 3722 dprintk("vino_queue_get_outgoing() failed\n");
3310 return -EIO; 3723 return -EINVAL;
3311 } 3724 }
3312 3725
3313 dprintk("incoming = %d, outgoing = %d\n", incoming, outgoing); 3726 dprintk("incoming = %d, outgoing = %d\n", incoming, outgoing);
@@ -3327,8 +3740,10 @@ static int vino_v4l2_dqbuf(struct vino_channel_settings *vcs,
3327 if (err) { 3740 if (err) {
3328 err = vino_wait_for_frame(vcs); 3741 err = vino_wait_for_frame(vcs);
3329 if (err) { 3742 if (err) {
3330 /* interrupted */ 3743 /* interrupted or
3331 vino_capture_failed(vcs); 3744 * no frames captured because
3745 * of frame skipping */
3746 // vino_capture_failed(vcs);
3332 return -EIO; 3747 return -EIO;
3333 } 3748 }
3334 } 3749 }
@@ -3341,10 +3756,12 @@ static int vino_v4l2_dqbuf(struct vino_channel_settings *vcs,
3341 } 3756 }
3342 3757
3343 err = vino_check_buffer(vcs, fb); 3758 err = vino_check_buffer(vcs, fb);
3759
3760 vino_v4l2_get_buffer_status(vcs, fb, b);
3761
3344 if (err) 3762 if (err)
3345 return -EIO; 3763 return -EIO;
3346 3764
3347 vino_v4l2_get_buffer_status(vcs, fb, b);
3348 break; 3765 break;
3349 } 3766 }
3350 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 3767 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
@@ -3401,8 +3818,8 @@ static int vino_v4l2_streamoff(struct vino_channel_settings *vcs)
3401 if (!vcs->streaming) 3818 if (!vcs->streaming)
3402 return 0; 3819 return 0;
3403 3820
3404 vino_capture_stop(vcs);
3405 vcs->streaming = 0; 3821 vcs->streaming = 0;
3822 vino_capture_stop(vcs);
3406 3823
3407 return 0; 3824 return 0;
3408} 3825}
@@ -3410,10 +3827,11 @@ static int vino_v4l2_streamoff(struct vino_channel_settings *vcs)
3410static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs, 3827static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs,
3411 struct v4l2_queryctrl *queryctrl) 3828 struct v4l2_queryctrl *queryctrl)
3412{ 3829{
3830 unsigned long flags;
3413 int i; 3831 int i;
3414 int err = 0; 3832 int err = 0;
3415 3833
3416 spin_lock(&vino_drvdata->input_lock); 3834 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3417 3835
3418 switch (vcs->input) { 3836 switch (vcs->input) {
3419 case VINO_INPUT_D1: 3837 case VINO_INPUT_D1:
@@ -3423,6 +3841,7 @@ static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs,
3423 memcpy(queryctrl, 3841 memcpy(queryctrl,
3424 &vino_indycam_v4l2_controls[i], 3842 &vino_indycam_v4l2_controls[i],
3425 sizeof(struct v4l2_queryctrl)); 3843 sizeof(struct v4l2_queryctrl));
3844 queryctrl->reserved[0] = 0;
3426 goto found; 3845 goto found;
3427 } 3846 }
3428 } 3847 }
@@ -3437,6 +3856,7 @@ static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs,
3437 memcpy(queryctrl, 3856 memcpy(queryctrl,
3438 &vino_saa7191_v4l2_controls[i], 3857 &vino_saa7191_v4l2_controls[i],
3439 sizeof(struct v4l2_queryctrl)); 3858 sizeof(struct v4l2_queryctrl));
3859 queryctrl->reserved[0] = 0;
3440 goto found; 3860 goto found;
3441 } 3861 }
3442 } 3862 }
@@ -3448,7 +3868,7 @@ static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs,
3448 } 3868 }
3449 3869
3450 found: 3870 found:
3451 spin_unlock(&vino_drvdata->input_lock); 3871 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3452 3872
3453 return err; 3873 return err;
3454} 3874}
@@ -3456,70 +3876,72 @@ static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs,
3456static int vino_v4l2_g_ctrl(struct vino_channel_settings *vcs, 3876static int vino_v4l2_g_ctrl(struct vino_channel_settings *vcs,
3457 struct v4l2_control *control) 3877 struct v4l2_control *control)
3458{ 3878{
3459 struct indycam_control indycam_ctrl; 3879 unsigned long flags;
3460 struct saa7191_control saa7191_ctrl; 3880 int i;
3461 int err = 0; 3881 int err = 0;
3462 3882
3463 spin_lock(&vino_drvdata->input_lock); 3883 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3464 3884
3465 switch (vcs->input) { 3885 switch (vcs->input) {
3466 case VINO_INPUT_D1: 3886 case VINO_INPUT_D1: {
3467 i2c_camera_command(DECODER_INDYCAM_GET_CONTROLS, 3887 struct indycam_control indycam_ctrl;
3468 &indycam_ctrl);
3469 3888
3470 switch(control->id) { 3889 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3471 case V4L2_CID_AUTOGAIN: 3890 if (vino_indycam_v4l2_controls[i].id ==
3472 control->value = indycam_ctrl.agc; 3891 control->id) {
3473 break; 3892 goto found1;
3474 case V4L2_CID_AUTO_WHITE_BALANCE: 3893 }
3475 control->value = indycam_ctrl.awb; 3894 }
3476 break; 3895
3477 case V4L2_CID_GAIN: 3896 err = -EINVAL;
3478 control->value = indycam_ctrl.gain; 3897 goto out;
3479 break; 3898
3480 case V4L2_CID_PRIVATE_BASE: 3899found1:
3481 control->value = indycam_ctrl.red_saturation; 3900 indycam_ctrl.type = vino_indycam_v4l2_controls[i].reserved[0];
3482 break; 3901
3483 case V4L2_CID_PRIVATE_BASE + 1: 3902 err = i2c_camera_command(DECODER_INDYCAM_GET_CONTROL,
3484 control->value = indycam_ctrl.blue_saturation; 3903 &indycam_ctrl);
3485 break; 3904 if (err) {
3486 case V4L2_CID_RED_BALANCE:
3487 control->value = indycam_ctrl.red_balance;
3488 break;
3489 case V4L2_CID_BLUE_BALANCE:
3490 control->value = indycam_ctrl.blue_balance;
3491 break;
3492 case V4L2_CID_EXPOSURE:
3493 control->value = indycam_ctrl.shutter;
3494 break;
3495 case V4L2_CID_GAMMA:
3496 control->value = indycam_ctrl.gamma;
3497 break;
3498 default:
3499 err = -EINVAL; 3905 err = -EINVAL;
3906 goto out;
3500 } 3907 }
3908
3909 control->value = indycam_ctrl.value;
3501 break; 3910 break;
3911 }
3502 case VINO_INPUT_COMPOSITE: 3912 case VINO_INPUT_COMPOSITE:
3503 case VINO_INPUT_SVIDEO: 3913 case VINO_INPUT_SVIDEO: {
3504 i2c_decoder_command(DECODER_SAA7191_GET_CONTROLS, 3914 struct saa7191_control saa7191_ctrl;
3505 &saa7191_ctrl);
3506 3915
3507 switch(control->id) { 3916 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3508 case V4L2_CID_HUE: 3917 if (vino_saa7191_v4l2_controls[i].id ==
3509 control->value = saa7191_ctrl.hue; 3918 control->id) {
3510 break; 3919 goto found2;
3511 case V4L2_CID_PRIVATE_BASE: 3920 }
3512 control->value = saa7191_ctrl.vtrc; 3921 }
3513 break; 3922
3514 default: 3923 err = -EINVAL;
3924 goto out;
3925
3926found2:
3927 saa7191_ctrl.type = vino_saa7191_v4l2_controls[i].reserved[0];
3928
3929 err = i2c_decoder_command(DECODER_SAA7191_GET_CONTROL,
3930 &saa7191_ctrl);
3931 if (err) {
3515 err = -EINVAL; 3932 err = -EINVAL;
3933 goto out;
3516 } 3934 }
3935
3936 control->value = saa7191_ctrl.value;
3517 break; 3937 break;
3938 }
3518 default: 3939 default:
3519 err = -EINVAL; 3940 err = -EINVAL;
3520 } 3941 }
3521 3942
3522 spin_unlock(&vino_drvdata->input_lock); 3943out:
3944 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3523 3945
3524 return err; 3946 return err;
3525} 3947}
@@ -3527,15 +3949,21 @@ static int vino_v4l2_g_ctrl(struct vino_channel_settings *vcs,
3527static int vino_v4l2_s_ctrl(struct vino_channel_settings *vcs, 3949static int vino_v4l2_s_ctrl(struct vino_channel_settings *vcs,
3528 struct v4l2_control *control) 3950 struct v4l2_control *control)
3529{ 3951{
3530 struct indycam_control indycam_ctrl; 3952 unsigned long flags;
3531 struct saa7191_control saa7191_ctrl;
3532 int i; 3953 int i;
3533 int err = 0; 3954 int err = 0;
3534 3955
3535 spin_lock(&vino_drvdata->input_lock); 3956 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3957
3958 if (!vino_is_input_owner(vcs)) {
3959 err = -EBUSY;
3960 goto out;
3961 }
3536 3962
3537 switch (vcs->input) { 3963 switch (vcs->input) {
3538 case VINO_INPUT_D1: 3964 case VINO_INPUT_D1: {
3965 struct indycam_control indycam_ctrl;
3966
3539 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) { 3967 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3540 if (vino_indycam_v4l2_controls[i].id == 3968 if (vino_indycam_v4l2_controls[i].id ==
3541 control->id) { 3969 control->id) {
@@ -3544,65 +3972,31 @@ static int vino_v4l2_s_ctrl(struct vino_channel_settings *vcs,
3544 && (control->value <= 3972 && (control->value <=
3545 vino_indycam_v4l2_controls[i]. 3973 vino_indycam_v4l2_controls[i].
3546 maximum)) { 3974 maximum)) {
3547 goto ok1; 3975 goto found1;
3548 } else { 3976 } else {
3549 err = -ERANGE; 3977 err = -ERANGE;
3550 goto error; 3978 goto out;
3551 } 3979 }
3552 } 3980 }
3553 } 3981 }
3982
3554 err = -EINVAL; 3983 err = -EINVAL;
3555 goto error; 3984 goto out;
3556 3985
3557ok1: 3986found1:
3558 indycam_ctrl.agc = INDYCAM_VALUE_UNCHANGED; 3987 indycam_ctrl.type = vino_indycam_v4l2_controls[i].reserved[0];
3559 indycam_ctrl.awb = INDYCAM_VALUE_UNCHANGED; 3988 indycam_ctrl.value = control->value;
3560 indycam_ctrl.shutter = INDYCAM_VALUE_UNCHANGED;
3561 indycam_ctrl.gain = INDYCAM_VALUE_UNCHANGED;
3562 indycam_ctrl.red_balance = INDYCAM_VALUE_UNCHANGED;
3563 indycam_ctrl.blue_balance = INDYCAM_VALUE_UNCHANGED;
3564 indycam_ctrl.red_saturation = INDYCAM_VALUE_UNCHANGED;
3565 indycam_ctrl.blue_saturation = INDYCAM_VALUE_UNCHANGED;
3566 indycam_ctrl.gamma = INDYCAM_VALUE_UNCHANGED;
3567
3568 switch(control->id) {
3569 case V4L2_CID_AUTOGAIN:
3570 indycam_ctrl.agc = control->value;
3571 break;
3572 case V4L2_CID_AUTO_WHITE_BALANCE:
3573 indycam_ctrl.awb = control->value;
3574 break;
3575 case V4L2_CID_GAIN:
3576 indycam_ctrl.gain = control->value;
3577 break;
3578 case V4L2_CID_PRIVATE_BASE:
3579 indycam_ctrl.red_saturation = control->value;
3580 break;
3581 case V4L2_CID_PRIVATE_BASE + 1:
3582 indycam_ctrl.blue_saturation = control->value;
3583 break;
3584 case V4L2_CID_RED_BALANCE:
3585 indycam_ctrl.red_balance = control->value;
3586 break;
3587 case V4L2_CID_BLUE_BALANCE:
3588 indycam_ctrl.blue_balance = control->value;
3589 break;
3590 case V4L2_CID_EXPOSURE:
3591 indycam_ctrl.shutter = control->value;
3592 break;
3593 case V4L2_CID_GAMMA:
3594 indycam_ctrl.gamma = control->value;
3595 break;
3596 default:
3597 err = -EINVAL;
3598 }
3599 3989
3600 if (!err) 3990 err = i2c_camera_command(DECODER_INDYCAM_SET_CONTROL,
3601 i2c_camera_command(DECODER_INDYCAM_SET_CONTROLS, 3991 &indycam_ctrl);
3602 &indycam_ctrl); 3992 if (err)
3993 err = -EINVAL;
3603 break; 3994 break;
3995 }
3604 case VINO_INPUT_COMPOSITE: 3996 case VINO_INPUT_COMPOSITE:
3605 case VINO_INPUT_SVIDEO: 3997 case VINO_INPUT_SVIDEO: {
3998 struct saa7191_control saa7191_ctrl;
3999
3606 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) { 4000 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3607 if (vino_saa7191_v4l2_controls[i].id == 4001 if (vino_saa7191_v4l2_controls[i].id ==
3608 control->id) { 4002 control->id) {
@@ -3611,41 +4005,32 @@ ok1:
3611 && (control->value <= 4005 && (control->value <=
3612 vino_saa7191_v4l2_controls[i]. 4006 vino_saa7191_v4l2_controls[i].
3613 maximum)) { 4007 maximum)) {
3614 goto ok2; 4008 goto found2;
3615 } else { 4009 } else {
3616 err = -ERANGE; 4010 err = -ERANGE;
3617 goto error; 4011 goto out;
3618 } 4012 }
3619 } 4013 }
3620 } 4014 }
3621 err = -EINVAL; 4015 err = -EINVAL;
3622 goto error; 4016 goto out;
3623
3624ok2:
3625 saa7191_ctrl.hue = SAA7191_VALUE_UNCHANGED;
3626 saa7191_ctrl.vtrc = SAA7191_VALUE_UNCHANGED;
3627 4017
3628 switch(control->id) { 4018found2:
3629 case V4L2_CID_HUE: 4019 saa7191_ctrl.type = vino_saa7191_v4l2_controls[i].reserved[0];
3630 saa7191_ctrl.hue = control->value; 4020 saa7191_ctrl.value = control->value;
3631 break;
3632 case V4L2_CID_PRIVATE_BASE:
3633 saa7191_ctrl.vtrc = control->value;
3634 break;
3635 default:
3636 err = -EINVAL;
3637 }
3638 4021
3639 if (!err) 4022 err = i2c_decoder_command(DECODER_SAA7191_SET_CONTROL,
3640 i2c_decoder_command(DECODER_SAA7191_SET_CONTROLS, 4023 &saa7191_ctrl);
3641 &saa7191_ctrl); 4024 if (err)
4025 err = -EINVAL;
3642 break; 4026 break;
4027 }
3643 default: 4028 default:
3644 err = -EINVAL; 4029 err = -EINVAL;
3645 } 4030 }
3646 4031
3647error: 4032out:
3648 spin_unlock(&vino_drvdata->input_lock); 4033 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3649 4034
3650 return err; 4035 return err;
3651} 4036}
@@ -3865,9 +4250,9 @@ static unsigned int vino_poll(struct file *file, poll_table *pt)
3865over: 4250over:
3866 dprintk("poll(): data %savailable\n", 4251 dprintk("poll(): data %savailable\n",
3867 (outgoing > 0) ? "" : "not "); 4252 (outgoing > 0) ? "" : "not ");
3868 if (outgoing > 0) { 4253
4254 if (outgoing > 0)
3869 ret = POLLIN | POLLRDNORM; 4255 ret = POLLIN | POLLRDNORM;
3870 }
3871 4256
3872error: 4257error:
3873 4258
@@ -3880,6 +4265,7 @@ static int vino_do_ioctl(struct inode *inode, struct file *file,
3880 struct video_device *dev = video_devdata(file); 4265 struct video_device *dev = video_devdata(file);
3881 struct vino_channel_settings *vcs = video_get_drvdata(dev); 4266 struct vino_channel_settings *vcs = video_get_drvdata(dev);
3882 4267
4268#ifdef VINO_DEBUG
3883 switch (_IOC_TYPE(cmd)) { 4269 switch (_IOC_TYPE(cmd)) {
3884 case 'v': 4270 case 'v':
3885 dprintk("ioctl(): V4L1 unsupported (0x%08x)\n", cmd); 4271 dprintk("ioctl(): V4L1 unsupported (0x%08x)\n", cmd);
@@ -3891,9 +4277,9 @@ static int vino_do_ioctl(struct inode *inode, struct file *file,
3891 default: 4277 default:
3892 dprintk("ioctl(): unsupported command 0x%08x\n", cmd); 4278 dprintk("ioctl(): unsupported command 0x%08x\n", cmd);
3893 } 4279 }
4280#endif
3894 4281
3895 switch (cmd) { 4282 switch (cmd) {
3896 /* TODO: V4L1 interface (use compatibility layer?) */
3897 /* V4L2 interface */ 4283 /* V4L2 interface */
3898 case VIDIOC_QUERYCAP: { 4284 case VIDIOC_QUERYCAP: {
3899 vino_v4l2_querycap(arg); 4285 vino_v4l2_querycap(arg);
@@ -3911,6 +4297,9 @@ static int vino_do_ioctl(struct inode *inode, struct file *file,
3911 case VIDIOC_ENUMSTD: { 4297 case VIDIOC_ENUMSTD: {
3912 return vino_v4l2_enumstd(vcs, arg); 4298 return vino_v4l2_enumstd(vcs, arg);
3913 } 4299 }
4300 case VIDIOC_QUERYSTD: {
4301 return vino_v4l2_querystd(vcs, arg);
4302 }
3914 case VIDIOC_G_STD: { 4303 case VIDIOC_G_STD: {
3915 return vino_v4l2_g_std(vcs, arg); 4304 return vino_v4l2_g_std(vcs, arg);
3916 } 4305 }
@@ -4100,8 +4489,7 @@ static int vino_probe(void)
4100 return -ENODEV; 4489 return -ENODEV;
4101 } 4490 }
4102 4491
4103 printk(KERN_INFO "VINO with chip ID %ld, revision %ld found\n", 4492 printk(KERN_INFO "VINO revision %ld found\n", VINO_REV_NUM(rev_id));
4104 VINO_ID_VALUE(rev_id), VINO_REV_NUM(rev_id));
4105 4493
4106 return 0; 4494 return 0;
4107} 4495}
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
index eed2acea1779..39a0d238900e 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran_card.c
@@ -1057,10 +1057,8 @@ zr36057_init (struct zoran *zr)
1057 KERN_ERR 1057 KERN_ERR
1058 "%s: zr36057_init() - kmalloc (STAT_COM) failed\n", 1058 "%s: zr36057_init() - kmalloc (STAT_COM) failed\n",
1059 ZR_DEVNAME(zr)); 1059 ZR_DEVNAME(zr));
1060 if (vdev) 1060 kfree(vdev);
1061 kfree(vdev); 1061 kfree((void *)mem);
1062 if (mem)
1063 kfree((void *)mem);
1064 return -ENOMEM; 1062 return -ENOMEM;
1065 } 1063 }
1066 memset((void *) mem, 0, mem_needed); 1064 memset((void *) mem, 0, mem_needed);
@@ -1105,15 +1103,15 @@ zoran_release (struct zoran *zr)
1105 /* unregister videocodec bus */ 1103 /* unregister videocodec bus */
1106 if (zr->codec) { 1104 if (zr->codec) {
1107 struct videocodec_master *master = zr->codec->master_data; 1105 struct videocodec_master *master = zr->codec->master_data;
1106
1108 videocodec_detach(zr->codec); 1107 videocodec_detach(zr->codec);
1109 if (master) 1108 kfree(master);
1110 kfree(master);
1111 } 1109 }
1112 if (zr->vfe) { 1110 if (zr->vfe) {
1113 struct videocodec_master *master = zr->vfe->master_data; 1111 struct videocodec_master *master = zr->vfe->master_data;
1112
1114 videocodec_detach(zr->vfe); 1113 videocodec_detach(zr->vfe);
1115 if (master) 1114 kfree(master);
1116 kfree(master);
1117 } 1115 }
1118 1116
1119 /* unregister i2c bus */ 1117 /* unregister i2c bus */
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index 53adeb70f2ca..07bde9acd672 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -996,8 +996,6 @@ zoran_jpg_queue_frame (struct file *file,
996 return -EINVAL; 996 return -EINVAL;
997 } 997 }
998 998
999 spin_lock_irqsave(&zr->spinlock, flags);
1000
1001 if (fh->jpg_buffers.active == ZORAN_FREE) { 999 if (fh->jpg_buffers.active == ZORAN_FREE) {
1002 if (zr->jpg_buffers.active == ZORAN_FREE) { 1000 if (zr->jpg_buffers.active == ZORAN_FREE) {
1003 zr->jpg_buffers = fh->jpg_buffers; 1001 zr->jpg_buffers = fh->jpg_buffers;
@@ -1016,6 +1014,8 @@ zoran_jpg_queue_frame (struct file *file,
1016 zr36057_enable_jpg(zr, mode); 1014 zr36057_enable_jpg(zr, mode);
1017 } 1015 }
1018 1016
1017 spin_lock_irqsave(&zr->spinlock, flags);
1018
1019 if (!res) { 1019 if (!res) {
1020 switch (zr->jpg_buffers.buffer[num].state) { 1020 switch (zr->jpg_buffers.buffer[num].state) {
1021 case BUZ_STATE_DONE: 1021 case BUZ_STATE_DONE:
diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c
index ed3c891e388f..014085d8ec85 100644
--- a/drivers/message/fusion/mptlan.c
+++ b/drivers/message/fusion/mptlan.c
@@ -511,7 +511,7 @@ mpt_lan_close(struct net_device *dev)
511{ 511{
512 struct mpt_lan_priv *priv = netdev_priv(dev); 512 struct mpt_lan_priv *priv = netdev_priv(dev);
513 MPT_ADAPTER *mpt_dev = priv->mpt_dev; 513 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
514 unsigned int timeout; 514 unsigned long timeout;
515 int i; 515 int i;
516 516
517 dlprintk((KERN_INFO MYNAM ": mpt_lan_close called\n")); 517 dlprintk((KERN_INFO MYNAM ": mpt_lan_close called\n"));
@@ -526,11 +526,9 @@ mpt_lan_close(struct net_device *dev)
526 526
527 mpt_lan_reset(dev); 527 mpt_lan_reset(dev);
528 528
529 timeout = 2 * HZ; 529 timeout = jiffies + 2 * HZ;
530 while (atomic_read(&priv->buckets_out) && --timeout) { 530 while (atomic_read(&priv->buckets_out) && time_before(jiffies, timeout))
531 set_current_state(TASK_INTERRUPTIBLE); 531 schedule_timeout_interruptible(1);
532 schedule_timeout(1);
533 }
534 532
535 for (i = 0; i < priv->max_buckets_out; i++) { 533 for (i = 0; i < priv->max_buckets_out; i++) {
536 if (priv->RcvCtl[i].skb != NULL) { 534 if (priv->RcvCtl[i].skb != NULL) {
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index 5cb07eb224d7..4330ed0cedaa 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -1013,10 +1013,8 @@ mptscsih_remove(struct pci_dev *pdev)
1013 spin_lock_irqsave(&dvtaskQ_lock, flags); 1013 spin_lock_irqsave(&dvtaskQ_lock, flags);
1014 if (dvtaskQ_active) { 1014 if (dvtaskQ_active) {
1015 spin_unlock_irqrestore(&dvtaskQ_lock, flags); 1015 spin_unlock_irqrestore(&dvtaskQ_lock, flags);
1016 while(dvtaskQ_active && --count) { 1016 while(dvtaskQ_active && --count)
1017 set_current_state(TASK_INTERRUPTIBLE); 1017 schedule_timeout_interruptible(1);
1018 schedule_timeout(1);
1019 }
1020 } else { 1018 } else {
1021 spin_unlock_irqrestore(&dvtaskQ_lock, flags); 1019 spin_unlock_irqrestore(&dvtaskQ_lock, flags);
1022 } 1020 }
diff --git a/drivers/message/i2o/exec-osm.c b/drivers/message/i2o/exec-osm.c
index b675b4ebbebd..9c339a2505b0 100644
--- a/drivers/message/i2o/exec-osm.c
+++ b/drivers/message/i2o/exec-osm.c
@@ -33,6 +33,7 @@
33#include <linux/workqueue.h> 33#include <linux/workqueue.h>
34#include <linux/string.h> 34#include <linux/string.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/sched.h> /* wait_event_interruptible_timeout() needs this */
36#include <asm/param.h> /* HZ */ 37#include <asm/param.h> /* HZ */
37#include "core.h" 38#include "core.h"
38 39
diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
index 61b837de4b6a..4eb53258842e 100644
--- a/drivers/message/i2o/iop.c
+++ b/drivers/message/i2o/iop.c
@@ -93,8 +93,7 @@ u32 i2o_msg_get_wait(struct i2o_controller *c,
93 c->name); 93 c->name);
94 return I2O_QUEUE_EMPTY; 94 return I2O_QUEUE_EMPTY;
95 } 95 }
96 set_current_state(TASK_UNINTERRUPTIBLE); 96 schedule_timeout_uninterruptible(1);
97 schedule_timeout(1);
98 } 97 }
99 98
100 return m; 99 return m;
@@ -485,8 +484,7 @@ static int i2o_iop_init_outbound_queue(struct i2o_controller *c)
485 osm_warn("%s: Timeout Initializing\n", c->name); 484 osm_warn("%s: Timeout Initializing\n", c->name);
486 return -ETIMEDOUT; 485 return -ETIMEDOUT;
487 } 486 }
488 set_current_state(TASK_UNINTERRUPTIBLE); 487 schedule_timeout_uninterruptible(1);
489 schedule_timeout(1);
490 } 488 }
491 489
492 m = c->out_queue.phys; 490 m = c->out_queue.phys;
@@ -548,8 +546,7 @@ static int i2o_iop_reset(struct i2o_controller *c)
548 if (time_after(jiffies, timeout)) 546 if (time_after(jiffies, timeout))
549 break; 547 break;
550 548
551 set_current_state(TASK_UNINTERRUPTIBLE); 549 schedule_timeout_uninterruptible(1);
552 schedule_timeout(1);
553 } 550 }
554 551
555 switch (*status) { 552 switch (*status) {
@@ -577,8 +574,7 @@ static int i2o_iop_reset(struct i2o_controller *c)
577 rc = -ETIMEDOUT; 574 rc = -ETIMEDOUT;
578 goto exit; 575 goto exit;
579 } 576 }
580 set_current_state(TASK_UNINTERRUPTIBLE); 577 schedule_timeout_uninterruptible(1);
581 schedule_timeout(1);
582 578
583 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_RESET); 579 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_RESET);
584 } 580 }
@@ -989,8 +985,7 @@ int i2o_status_get(struct i2o_controller *c)
989 return -ETIMEDOUT; 985 return -ETIMEDOUT;
990 } 986 }
991 987
992 set_current_state(TASK_UNINTERRUPTIBLE); 988 schedule_timeout_uninterruptible(1);
993 schedule_timeout(1);
994 } 989 }
995 990
996#ifdef DEBUG 991#ifdef DEBUG
diff --git a/drivers/mfd/mcp-core.c b/drivers/mfd/mcp-core.c
index c75d713c01e4..55ba23075c90 100644
--- a/drivers/mfd/mcp-core.c
+++ b/drivers/mfd/mcp-core.c
@@ -15,6 +15,8 @@
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/smp.h> 16#include <linux/smp.h>
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/slab.h>
19#include <linux/string.h>
18 20
19#include <asm/dma.h> 21#include <asm/dma.h>
20#include <asm/system.h> 22#include <asm/system.h>
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index ceae379a4d4c..da528390acf8 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -1263,7 +1263,7 @@ EXPORT_SYMBOL(mmc_suspend_host);
1263 */ 1263 */
1264int mmc_resume_host(struct mmc_host *host) 1264int mmc_resume_host(struct mmc_host *host)
1265{ 1265{
1266 mmc_detect_change(host, 0); 1266 mmc_rescan(host);
1267 1267
1268 return 0; 1268 return 0;
1269} 1269}
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c
index 4ff67e7363d9..e954b8354fef 100644
--- a/drivers/mmc/wbsd.c
+++ b/drivers/mmc/wbsd.c
@@ -1602,8 +1602,7 @@ static void __devexit wbsd_release_dma(struct wbsd_host* host)
1602 if (host->dma_addr) 1602 if (host->dma_addr)
1603 dma_unmap_single(host->mmc->dev, host->dma_addr, WBSD_DMA_SIZE, 1603 dma_unmap_single(host->mmc->dev, host->dma_addr, WBSD_DMA_SIZE,
1604 DMA_BIDIRECTIONAL); 1604 DMA_BIDIRECTIONAL);
1605 if (host->dma_buffer) 1605 kfree(host->dma_buffer);
1606 kfree(host->dma_buffer);
1607 if (host->dma >= 0) 1606 if (host->dma >= 0)
1608 free_dma(host->dma); 1607 free_dma(host->dma);
1609 1608
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 027054dea032..f6b775e63ac8 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -1,4 +1,4 @@
1# $Id: Kconfig,v 1.7 2004/11/22 11:33:56 ijc Exp $ 1# $Id: Kconfig,v 1.11 2005/11/07 11:14:19 gleixner Exp $
2 2
3menu "Memory Technology Devices (MTD)" 3menu "Memory Technology Devices (MTD)"
4 4
@@ -10,7 +10,7 @@ config MTD
10 will provide the generic support for MTD drivers to register 10 will provide the generic support for MTD drivers to register
11 themselves with the kernel and for potential users of MTD devices 11 themselves with the kernel and for potential users of MTD devices
12 to enumerate the devices which are present and obtain a handle on 12 to enumerate the devices which are present and obtain a handle on
13 them. It will also allow you to select individual drivers for 13 them. It will also allow you to select individual drivers for
14 particular hardware and users of MTD devices. If unsure, say N. 14 particular hardware and users of MTD devices. If unsure, say N.
15 15
16config MTD_DEBUG 16config MTD_DEBUG
@@ -61,11 +61,11 @@ config MTD_REDBOOT_PARTS
61 61
62 If you need code which can detect and parse this table, and register 62 If you need code which can detect and parse this table, and register
63 MTD 'partitions' corresponding to each image in the table, enable 63 MTD 'partitions' corresponding to each image in the table, enable
64 this option. 64 this option.
65 65
66 You will still need the parsing functions to be called by the driver 66 You will still need the parsing functions to be called by the driver
67 for your particular device. It won't happen automatically. The 67 for your particular device. It won't happen automatically. The
68 SA1100 map driver (CONFIG_MTD_SA1100) has an option for this, for 68 SA1100 map driver (CONFIG_MTD_SA1100) has an option for this, for
69 example. 69 example.
70 70
71config MTD_REDBOOT_DIRECTORY_BLOCK 71config MTD_REDBOOT_DIRECTORY_BLOCK
@@ -81,10 +81,10 @@ config MTD_REDBOOT_DIRECTORY_BLOCK
81 partition table. A zero or positive value gives an absolete 81 partition table. A zero or positive value gives an absolete
82 erase block number. A negative value specifies a number of 82 erase block number. A negative value specifies a number of
83 sectors before the end of the device. 83 sectors before the end of the device.
84 84
85 For example "2" means block number 2, "-1" means the last 85 For example "2" means block number 2, "-1" means the last
86 block and "-2" means the penultimate block. 86 block and "-2" means the penultimate block.
87 87
88config MTD_REDBOOT_PARTS_UNALLOCATED 88config MTD_REDBOOT_PARTS_UNALLOCATED
89 bool " Include unallocated flash regions" 89 bool " Include unallocated flash regions"
90 depends on MTD_REDBOOT_PARTS 90 depends on MTD_REDBOOT_PARTS
@@ -105,11 +105,11 @@ config MTD_CMDLINE_PARTS
105 ---help--- 105 ---help---
106 Allow generic configuration of the MTD paritition tables via the kernel 106 Allow generic configuration of the MTD paritition tables via the kernel
107 command line. Multiple flash resources are supported for hardware where 107 command line. Multiple flash resources are supported for hardware where
108 different kinds of flash memory are available. 108 different kinds of flash memory are available.
109 109
110 You will still need the parsing functions to be called by the driver 110 You will still need the parsing functions to be called by the driver
111 for your particular device. It won't happen automatically. The 111 for your particular device. It won't happen automatically. The
112 SA1100 map driver (CONFIG_MTD_SA1100) has an option for this, for 112 SA1100 map driver (CONFIG_MTD_SA1100) has an option for this, for
113 example. 113 example.
114 114
115 The format for the command line is as follows: 115 The format for the command line is as follows:
@@ -118,12 +118,12 @@ config MTD_CMDLINE_PARTS
118 <mtddef> := <mtd-id>:<partdef>[,<partdef>] 118 <mtddef> := <mtd-id>:<partdef>[,<partdef>]
119 <partdef> := <size>[@offset][<name>][ro] 119 <partdef> := <size>[@offset][<name>][ro]
120 <mtd-id> := unique id used in mapping driver/device 120 <mtd-id> := unique id used in mapping driver/device
121 <size> := standard linux memsize OR "-" to denote all 121 <size> := standard linux memsize OR "-" to denote all
122 remaining space 122 remaining space
123 <name> := (NAME) 123 <name> := (NAME)
124 124
125 Due to the way Linux handles the command line, no spaces are 125 Due to the way Linux handles the command line, no spaces are
126 allowed in the partition definition, including mtd id's and partition 126 allowed in the partition definition, including mtd id's and partition
127 names. 127 names.
128 128
129 Examples: 129 Examples:
@@ -240,7 +240,7 @@ config INFTL
240 tristate "INFTL (Inverse NAND Flash Translation Layer) support" 240 tristate "INFTL (Inverse NAND Flash Translation Layer) support"
241 depends on MTD 241 depends on MTD
242 ---help--- 242 ---help---
243 This provides support for the Inverse NAND Flash Translation 243 This provides support for the Inverse NAND Flash Translation
244 Layer which is used on M-Systems' newer DiskOnChip devices. It 244 Layer which is used on M-Systems' newer DiskOnChip devices. It
245 uses a kind of pseudo-file system on a flash device to emulate 245 uses a kind of pseudo-file system on a flash device to emulate
246 a block device with 512-byte sectors, on top of which you put 246 a block device with 512-byte sectors, on top of which you put
@@ -253,6 +253,16 @@ config INFTL
253 permitted to copy, modify and distribute the code as you wish. Just 253 permitted to copy, modify and distribute the code as you wish. Just
254 not use it. 254 not use it.
255 255
256config RFD_FTL
257 tristate "Resident Flash Disk (Flash Translation Layer) support"
258 depends on MTD
259 ---help---
260 This provides support for the flash translation layer known
261 as the Resident Flash Disk (RFD), as used by the Embedded BIOS
262 of General Software. There is a blurb at:
263
264 http://www.gensw.com/pages/prod/bios/rfd.htm
265
256source "drivers/mtd/chips/Kconfig" 266source "drivers/mtd/chips/Kconfig"
257 267
258source "drivers/mtd/maps/Kconfig" 268source "drivers/mtd/maps/Kconfig"
@@ -261,5 +271,7 @@ source "drivers/mtd/devices/Kconfig"
261 271
262source "drivers/mtd/nand/Kconfig" 272source "drivers/mtd/nand/Kconfig"
263 273
274source "drivers/mtd/onenand/Kconfig"
275
264endmenu 276endmenu
265 277
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index e4ad588327f7..fc9374407c2b 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -1,7 +1,7 @@
1# 1#
2# Makefile for the memory technology device drivers. 2# Makefile for the memory technology device drivers.
3# 3#
4# $Id: Makefile.common,v 1.5 2004/08/10 20:51:49 dwmw2 Exp $ 4# $Id: Makefile.common,v 1.7 2005/07/11 10:39:27 gleixner Exp $
5 5
6# Core functionality. 6# Core functionality.
7mtd-y := mtdcore.o 7mtd-y := mtdcore.o
@@ -20,8 +20,9 @@ obj-$(CONFIG_MTD_BLOCK_RO) += mtdblock_ro.o mtd_blkdevs.o
20obj-$(CONFIG_FTL) += ftl.o mtd_blkdevs.o 20obj-$(CONFIG_FTL) += ftl.o mtd_blkdevs.o
21obj-$(CONFIG_NFTL) += nftl.o mtd_blkdevs.o 21obj-$(CONFIG_NFTL) += nftl.o mtd_blkdevs.o
22obj-$(CONFIG_INFTL) += inftl.o mtd_blkdevs.o 22obj-$(CONFIG_INFTL) += inftl.o mtd_blkdevs.o
23obj-$(CONFIG_RFD_FTL) += rfd_ftl.o mtd_blkdevs.o
23 24
24nftl-objs := nftlcore.o nftlmount.o 25nftl-objs := nftlcore.o nftlmount.o
25inftl-objs := inftlcore.o inftlmount.o 26inftl-objs := inftlcore.o inftlmount.o
26 27
27obj-y += chips/ maps/ devices/ nand/ 28obj-y += chips/ maps/ devices/ nand/ onenand/
diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c
index 7363e101eb0f..6a45be04564b 100644
--- a/drivers/mtd/afs.c
+++ b/drivers/mtd/afs.c
@@ -1,27 +1,27 @@
1/*====================================================================== 1/*======================================================================
2 2
3 drivers/mtd/afs.c: ARM Flash Layout/Partitioning 3 drivers/mtd/afs.c: ARM Flash Layout/Partitioning
4 4
5 Copyright (C) 2000 ARM Limited 5 Copyright (C) 2000 ARM Limited
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 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 18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 20
21 This is access code for flashes using ARM's flash partitioning 21 This is access code for flashes using ARM's flash partitioning
22 standards. 22 standards.
23 23
24 $Id: afs.c,v 1.13 2004/02/27 22:09:59 rmk Exp $ 24 $Id: afs.c,v 1.15 2005/11/07 11:14:19 gleixner Exp $
25 25
26======================================================================*/ 26======================================================================*/
27 27
@@ -163,7 +163,7 @@ afs_read_iis(struct mtd_info *mtd, struct image_info_struct *iis, u_int ptr)
163 return ret; 163 return ret;
164} 164}
165 165
166static int parse_afs_partitions(struct mtd_info *mtd, 166static int parse_afs_partitions(struct mtd_info *mtd,
167 struct mtd_partition **pparts, 167 struct mtd_partition **pparts,
168 unsigned long origin) 168 unsigned long origin)
169{ 169{
diff --git a/drivers/mtd/chips/Kconfig b/drivers/mtd/chips/Kconfig
index df95d2158b16..eafa23f5cbd6 100644
--- a/drivers/mtd/chips/Kconfig
+++ b/drivers/mtd/chips/Kconfig
@@ -1,5 +1,5 @@
1# drivers/mtd/chips/Kconfig 1# drivers/mtd/chips/Kconfig
2# $Id: Kconfig,v 1.15 2005/06/06 23:04:35 tpoynor Exp $ 2# $Id: Kconfig,v 1.18 2005/11/07 11:14:22 gleixner Exp $
3 3
4menu "RAM/ROM/Flash chip drivers" 4menu "RAM/ROM/Flash chip drivers"
5 depends on MTD!=n 5 depends on MTD!=n
@@ -39,7 +39,7 @@ config MTD_CFI_ADV_OPTIONS
39 If you need to specify a specific endianness for access to flash 39 If you need to specify a specific endianness for access to flash
40 chips, or if you wish to reduce the size of the kernel by including 40 chips, or if you wish to reduce the size of the kernel by including
41 support for only specific arrangements of flash chips, say 'Y'. This 41 support for only specific arrangements of flash chips, say 'Y'. This
42 option does not directly affect the code, but will enable other 42 option does not directly affect the code, but will enable other
43 configuration options which allow you to do so. 43 configuration options which allow you to do so.
44 44
45 If unsure, say 'N'. 45 If unsure, say 'N'.
@@ -56,7 +56,7 @@ config MTD_CFI_NOSWAP
56 data bits when writing the 'magic' commands to the chips. Saying 56 data bits when writing the 'magic' commands to the chips. Saying
57 'NO', which is the default when CONFIG_MTD_CFI_ADV_OPTIONS isn't 57 'NO', which is the default when CONFIG_MTD_CFI_ADV_OPTIONS isn't
58 enabled, means that the CPU will not do any swapping; the chips 58 enabled, means that the CPU will not do any swapping; the chips
59 are expected to be wired to the CPU in 'host-endian' form. 59 are expected to be wired to the CPU in 'host-endian' form.
60 Specific arrangements are possible with the BIG_ENDIAN_BYTE and 60 Specific arrangements are possible with the BIG_ENDIAN_BYTE and
61 LITTLE_ENDIAN_BYTE, if the bytes are reversed. 61 LITTLE_ENDIAN_BYTE, if the bytes are reversed.
62 62
@@ -79,10 +79,10 @@ config MTD_CFI_GEOMETRY
79 bool "Specific CFI Flash geometry selection" 79 bool "Specific CFI Flash geometry selection"
80 depends on MTD_CFI_ADV_OPTIONS 80 depends on MTD_CFI_ADV_OPTIONS
81 help 81 help
82 This option does not affect the code directly, but will enable 82 This option does not affect the code directly, but will enable
83 some other configuration options which would allow you to reduce 83 some other configuration options which would allow you to reduce
84 the size of the kernel by including support for only certain 84 the size of the kernel by including support for only certain
85 arrangements of CFI chips. If unsure, say 'N' and all options 85 arrangements of CFI chips. If unsure, say 'N' and all options
86 which are supported by the current code will be enabled. 86 which are supported by the current code will be enabled.
87 87
88config MTD_MAP_BANK_WIDTH_1 88config MTD_MAP_BANK_WIDTH_1
@@ -197,7 +197,7 @@ config MTD_CFI_AMDSTD
197 help 197 help
198 The Common Flash Interface defines a number of different command 198 The Common Flash Interface defines a number of different command
199 sets which a CFI-compliant chip may claim to implement. This code 199 sets which a CFI-compliant chip may claim to implement. This code
200 provides support for one of those command sets, used on chips 200 provides support for one of those command sets, used on chips
201 including the AMD Am29LV320. 201 including the AMD Am29LV320.
202 202
203config MTD_CFI_AMDSTD_RETRY 203config MTD_CFI_AMDSTD_RETRY
@@ -237,14 +237,14 @@ config MTD_RAM
237 tristate "Support for RAM chips in bus mapping" 237 tristate "Support for RAM chips in bus mapping"
238 depends on MTD 238 depends on MTD
239 help 239 help
240 This option enables basic support for RAM chips accessed through 240 This option enables basic support for RAM chips accessed through
241 a bus mapping driver. 241 a bus mapping driver.
242 242
243config MTD_ROM 243config MTD_ROM
244 tristate "Support for ROM chips in bus mapping" 244 tristate "Support for ROM chips in bus mapping"
245 depends on MTD 245 depends on MTD
246 help 246 help
247 This option enables basic support for ROM chips accessed through 247 This option enables basic support for ROM chips accessed through
248 a bus mapping driver. 248 a bus mapping driver.
249 249
250config MTD_ABSENT 250config MTD_ABSENT
@@ -275,7 +275,7 @@ config MTD_AMDSTD
275 depends on MTD && MTD_OBSOLETE_CHIPS 275 depends on MTD && MTD_OBSOLETE_CHIPS
276 help 276 help
277 This option enables support for flash chips using AMD-compatible 277 This option enables support for flash chips using AMD-compatible
278 commands, including some which are not CFI-compatible and hence 278 commands, including some which are not CFI-compatible and hence
279 cannot be used with the CONFIG_MTD_CFI_AMDSTD option. 279 cannot be used with the CONFIG_MTD_CFI_AMDSTD option.
280 280
281 It also works on AMD compatible chips that do conform to CFI. 281 It also works on AMD compatible chips that do conform to CFI.
@@ -285,7 +285,7 @@ config MTD_SHARP
285 depends on MTD && MTD_OBSOLETE_CHIPS 285 depends on MTD && MTD_OBSOLETE_CHIPS
286 help 286 help
287 This option enables support for flash chips using Sharp-compatible 287 This option enables support for flash chips using Sharp-compatible
288 commands, including some which are not CFI-compatible and hence 288 commands, including some which are not CFI-compatible and hence
289 cannot be used with the CONFIG_MTD_CFI_INTELxxx options. 289 cannot be used with the CONFIG_MTD_CFI_INTELxxx options.
290 290
291config MTD_JEDEC 291config MTD_JEDEC
diff --git a/drivers/mtd/chips/Makefile b/drivers/mtd/chips/Makefile
index 6830489828c6..8afe3092c4e3 100644
--- a/drivers/mtd/chips/Makefile
+++ b/drivers/mtd/chips/Makefile
@@ -1,7 +1,7 @@
1# 1#
2# linux/drivers/chips/Makefile 2# linux/drivers/chips/Makefile
3# 3#
4# $Id: Makefile.common,v 1.4 2004/07/12 16:07:30 dwmw2 Exp $ 4# $Id: Makefile.common,v 1.5 2005/11/07 11:14:22 gleixner Exp $
5 5
6# *** BIG UGLY NOTE *** 6# *** BIG UGLY NOTE ***
7# 7#
@@ -11,7 +11,7 @@
11# the CFI command set drivers are linked before gen_probe.o 11# the CFI command set drivers are linked before gen_probe.o
12 12
13obj-$(CONFIG_MTD) += chipreg.o 13obj-$(CONFIG_MTD) += chipreg.o
14obj-$(CONFIG_MTD_AMDSTD) += amd_flash.o 14obj-$(CONFIG_MTD_AMDSTD) += amd_flash.o
15obj-$(CONFIG_MTD_CFI) += cfi_probe.o 15obj-$(CONFIG_MTD_CFI) += cfi_probe.o
16obj-$(CONFIG_MTD_CFI_UTIL) += cfi_util.o 16obj-$(CONFIG_MTD_CFI_UTIL) += cfi_util.o
17obj-$(CONFIG_MTD_CFI_STAA) += cfi_cmdset_0020.o 17obj-$(CONFIG_MTD_CFI_STAA) += cfi_cmdset_0020.o
diff --git a/drivers/mtd/chips/amd_flash.c b/drivers/mtd/chips/amd_flash.c
index 2dafeba3f3d5..fdb91b6f1d97 100644
--- a/drivers/mtd/chips/amd_flash.c
+++ b/drivers/mtd/chips/amd_flash.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Author: Jonas Holmberg <jonas.holmberg@axis.com> 4 * Author: Jonas Holmberg <jonas.holmberg@axis.com>
5 * 5 *
6 * $Id: amd_flash.c,v 1.27 2005/02/04 07:43:09 jonashg Exp $ 6 * $Id: amd_flash.c,v 1.28 2005/11/07 11:14:22 gleixner Exp $
7 * 7 *
8 * Copyright (c) 2001 Axis Communications AB 8 * Copyright (c) 2001 Axis Communications AB
9 * 9 *
@@ -93,9 +93,9 @@
93#define D6_MASK 0x40 93#define D6_MASK 0x40
94 94
95struct amd_flash_private { 95struct amd_flash_private {
96 int device_type; 96 int device_type;
97 int interleave; 97 int interleave;
98 int numchips; 98 int numchips;
99 unsigned long chipshift; 99 unsigned long chipshift;
100// const char *im_name; 100// const char *im_name;
101 struct flchip chips[0]; 101 struct flchip chips[0];
@@ -253,7 +253,7 @@ static int amd_flash_do_unlock(struct mtd_info *mtd, loff_t ofs, size_t len,
253 int i; 253 int i;
254 int retval = 0; 254 int retval = 0;
255 int lock_status; 255 int lock_status;
256 256
257 map = mtd->priv; 257 map = mtd->priv;
258 258
259 /* Pass the whole chip through sector by sector and check for each 259 /* Pass the whole chip through sector by sector and check for each
@@ -273,7 +273,7 @@ static int amd_flash_do_unlock(struct mtd_info *mtd, loff_t ofs, size_t len,
273 unlock_sector(map, eraseoffset, is_unlock); 273 unlock_sector(map, eraseoffset, is_unlock);
274 274
275 lock_status = is_sector_locked(map, eraseoffset); 275 lock_status = is_sector_locked(map, eraseoffset);
276 276
277 if (is_unlock && lock_status) { 277 if (is_unlock && lock_status) {
278 printk("Cannot unlock sector at address %x length %xx\n", 278 printk("Cannot unlock sector at address %x length %xx\n",
279 eraseoffset, merip->erasesize); 279 eraseoffset, merip->erasesize);
@@ -305,7 +305,7 @@ static int amd_flash_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
305/* 305/*
306 * Reads JEDEC manufacturer ID and device ID and returns the index of the first 306 * Reads JEDEC manufacturer ID and device ID and returns the index of the first
307 * matching table entry (-1 if not found or alias for already found chip). 307 * matching table entry (-1 if not found or alias for already found chip).
308 */ 308 */
309static int probe_new_chip(struct mtd_info *mtd, __u32 base, 309static int probe_new_chip(struct mtd_info *mtd, __u32 base,
310 struct flchip *chips, 310 struct flchip *chips,
311 struct amd_flash_private *private, 311 struct amd_flash_private *private,
@@ -636,7 +636,7 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
636 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 }, 636 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 },
637 { .offset = 0x1F0000, .erasesize = 0x02000, .numblocks = 8 } 637 { .offset = 0x1F0000, .erasesize = 0x02000, .numblocks = 8 }
638 } 638 }
639 } 639 }
640 }; 640 };
641 641
642 struct mtd_info *mtd; 642 struct mtd_info *mtd;
@@ -701,7 +701,7 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
701 701
702 mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) * 702 mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) *
703 mtd->numeraseregions, GFP_KERNEL); 703 mtd->numeraseregions, GFP_KERNEL);
704 if (!mtd->eraseregions) { 704 if (!mtd->eraseregions) {
705 printk(KERN_WARNING "%s: Failed to allocate " 705 printk(KERN_WARNING "%s: Failed to allocate "
706 "memory for MTD erase region info\n", map->name); 706 "memory for MTD erase region info\n", map->name);
707 kfree(mtd); 707 kfree(mtd);
@@ -739,12 +739,12 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
739 mtd->type = MTD_NORFLASH; 739 mtd->type = MTD_NORFLASH;
740 mtd->flags = MTD_CAP_NORFLASH; 740 mtd->flags = MTD_CAP_NORFLASH;
741 mtd->name = map->name; 741 mtd->name = map->name;
742 mtd->erase = amd_flash_erase; 742 mtd->erase = amd_flash_erase;
743 mtd->read = amd_flash_read; 743 mtd->read = amd_flash_read;
744 mtd->write = amd_flash_write; 744 mtd->write = amd_flash_write;
745 mtd->sync = amd_flash_sync; 745 mtd->sync = amd_flash_sync;
746 mtd->suspend = amd_flash_suspend; 746 mtd->suspend = amd_flash_suspend;
747 mtd->resume = amd_flash_resume; 747 mtd->resume = amd_flash_resume;
748 mtd->lock = amd_flash_lock; 748 mtd->lock = amd_flash_lock;
749 mtd->unlock = amd_flash_unlock; 749 mtd->unlock = amd_flash_unlock;
750 750
@@ -789,7 +789,7 @@ retry:
789 map->name, chip->state); 789 map->name, chip->state);
790 set_current_state(TASK_UNINTERRUPTIBLE); 790 set_current_state(TASK_UNINTERRUPTIBLE);
791 add_wait_queue(&chip->wq, &wait); 791 add_wait_queue(&chip->wq, &wait);
792 792
793 spin_unlock_bh(chip->mutex); 793 spin_unlock_bh(chip->mutex);
794 794
795 schedule(); 795 schedule();
@@ -802,7 +802,7 @@ retry:
802 timeo = jiffies + HZ; 802 timeo = jiffies + HZ;
803 803
804 goto retry; 804 goto retry;
805 } 805 }
806 806
807 adr += chip->start; 807 adr += chip->start;
808 808
@@ -889,7 +889,7 @@ retry:
889 map->name, chip->state); 889 map->name, chip->state);
890 set_current_state(TASK_UNINTERRUPTIBLE); 890 set_current_state(TASK_UNINTERRUPTIBLE);
891 add_wait_queue(&chip->wq, &wait); 891 add_wait_queue(&chip->wq, &wait);
892 892
893 spin_unlock_bh(chip->mutex); 893 spin_unlock_bh(chip->mutex);
894 894
895 schedule(); 895 schedule();
@@ -901,7 +901,7 @@ retry:
901 timeo = jiffies + HZ; 901 timeo = jiffies + HZ;
902 902
903 goto retry; 903 goto retry;
904 } 904 }
905 905
906 chip->state = FL_WRITING; 906 chip->state = FL_WRITING;
907 907
@@ -911,7 +911,7 @@ retry:
911 wide_write(map, datum, adr); 911 wide_write(map, datum, adr);
912 912
913 times_left = 500000; 913 times_left = 500000;
914 while (times_left-- && flash_is_busy(map, adr, private->interleave)) { 914 while (times_left-- && flash_is_busy(map, adr, private->interleave)) {
915 if (need_resched()) { 915 if (need_resched()) {
916 spin_unlock_bh(chip->mutex); 916 spin_unlock_bh(chip->mutex);
917 schedule(); 917 schedule();
@@ -989,7 +989,7 @@ static int amd_flash_write(struct mtd_info *mtd, loff_t to , size_t len,
989 if (ret) { 989 if (ret) {
990 return ret; 990 return ret;
991 } 991 }
992 992
993 ofs += n; 993 ofs += n;
994 buf += n; 994 buf += n;
995 (*retlen) += n; 995 (*retlen) += n;
@@ -1002,7 +1002,7 @@ static int amd_flash_write(struct mtd_info *mtd, loff_t to , size_t len,
1002 } 1002 }
1003 } 1003 }
1004 } 1004 }
1005 1005
1006 /* We are now aligned, write as much as possible. */ 1006 /* We are now aligned, write as much as possible. */
1007 while(len >= map->buswidth) { 1007 while(len >= map->buswidth) {
1008 __u32 datum; 1008 __u32 datum;
@@ -1063,7 +1063,7 @@ static int amd_flash_write(struct mtd_info *mtd, loff_t to , size_t len,
1063 if (ret) { 1063 if (ret) {
1064 return ret; 1064 return ret;
1065 } 1065 }
1066 1066
1067 (*retlen) += n; 1067 (*retlen) += n;
1068 } 1068 }
1069 1069
@@ -1085,7 +1085,7 @@ retry:
1085 if (chip->state != FL_READY){ 1085 if (chip->state != FL_READY){
1086 set_current_state(TASK_UNINTERRUPTIBLE); 1086 set_current_state(TASK_UNINTERRUPTIBLE);
1087 add_wait_queue(&chip->wq, &wait); 1087 add_wait_queue(&chip->wq, &wait);
1088 1088
1089 spin_unlock_bh(chip->mutex); 1089 spin_unlock_bh(chip->mutex);
1090 1090
1091 schedule(); 1091 schedule();
@@ -1098,7 +1098,7 @@ retry:
1098 timeo = jiffies + HZ; 1098 timeo = jiffies + HZ;
1099 1099
1100 goto retry; 1100 goto retry;
1101 } 1101 }
1102 1102
1103 chip->state = FL_ERASING; 1103 chip->state = FL_ERASING;
1104 1104
@@ -1106,30 +1106,30 @@ retry:
1106 ENABLE_VPP(map); 1106 ENABLE_VPP(map);
1107 send_cmd(map, chip->start, CMD_SECTOR_ERASE_UNLOCK_DATA); 1107 send_cmd(map, chip->start, CMD_SECTOR_ERASE_UNLOCK_DATA);
1108 send_cmd_to_addr(map, chip->start, CMD_SECTOR_ERASE_UNLOCK_DATA_2, adr); 1108 send_cmd_to_addr(map, chip->start, CMD_SECTOR_ERASE_UNLOCK_DATA_2, adr);
1109 1109
1110 timeo = jiffies + (HZ * 20); 1110 timeo = jiffies + (HZ * 20);
1111 1111
1112 spin_unlock_bh(chip->mutex); 1112 spin_unlock_bh(chip->mutex);
1113 msleep(1000); 1113 msleep(1000);
1114 spin_lock_bh(chip->mutex); 1114 spin_lock_bh(chip->mutex);
1115 1115
1116 while (flash_is_busy(map, adr, private->interleave)) { 1116 while (flash_is_busy(map, adr, private->interleave)) {
1117 1117
1118 if (chip->state != FL_ERASING) { 1118 if (chip->state != FL_ERASING) {
1119 /* Someone's suspended the erase. Sleep */ 1119 /* Someone's suspended the erase. Sleep */
1120 set_current_state(TASK_UNINTERRUPTIBLE); 1120 set_current_state(TASK_UNINTERRUPTIBLE);
1121 add_wait_queue(&chip->wq, &wait); 1121 add_wait_queue(&chip->wq, &wait);
1122 1122
1123 spin_unlock_bh(chip->mutex); 1123 spin_unlock_bh(chip->mutex);
1124 printk(KERN_INFO "%s: erase suspended. Sleeping\n", 1124 printk(KERN_INFO "%s: erase suspended. Sleeping\n",
1125 map->name); 1125 map->name);
1126 schedule(); 1126 schedule();
1127 remove_wait_queue(&chip->wq, &wait); 1127 remove_wait_queue(&chip->wq, &wait);
1128 1128
1129 if (signal_pending(current)) { 1129 if (signal_pending(current)) {
1130 return -EINTR; 1130 return -EINTR;
1131 } 1131 }
1132 1132
1133 timeo = jiffies + (HZ*2); /* FIXME */ 1133 timeo = jiffies + (HZ*2); /* FIXME */
1134 spin_lock_bh(chip->mutex); 1134 spin_lock_bh(chip->mutex);
1135 continue; 1135 continue;
@@ -1145,7 +1145,7 @@ retry:
1145 1145
1146 return -EIO; 1146 return -EIO;
1147 } 1147 }
1148 1148
1149 /* Latency issues. Drop the lock, wait a while and retry */ 1149 /* Latency issues. Drop the lock, wait a while and retry */
1150 spin_unlock_bh(chip->mutex); 1150 spin_unlock_bh(chip->mutex);
1151 1151
@@ -1153,7 +1153,7 @@ retry:
1153 schedule(); 1153 schedule();
1154 else 1154 else
1155 udelay(1); 1155 udelay(1);
1156 1156
1157 spin_lock_bh(chip->mutex); 1157 spin_lock_bh(chip->mutex);
1158 } 1158 }
1159 1159
@@ -1180,7 +1180,7 @@ retry:
1180 return -EIO; 1180 return -EIO;
1181 } 1181 }
1182 } 1182 }
1183 1183
1184 DISABLE_VPP(map); 1184 DISABLE_VPP(map);
1185 chip->state = FL_READY; 1185 chip->state = FL_READY;
1186 wake_up(&chip->wq); 1186 wake_up(&chip->wq);
@@ -1246,7 +1246,7 @@ static int amd_flash_erase(struct mtd_info *mtd, struct erase_info *instr)
1246 * with the erase region at that address. 1246 * with the erase region at that address.
1247 */ 1247 */
1248 1248
1249 while ((i < mtd->numeraseregions) && 1249 while ((i < mtd->numeraseregions) &&
1250 ((instr->addr + instr->len) >= regions[i].offset)) { 1250 ((instr->addr + instr->len) >= regions[i].offset)) {
1251 i++; 1251 i++;
1252 } 1252 }
@@ -1293,10 +1293,10 @@ static int amd_flash_erase(struct mtd_info *mtd, struct erase_info *instr)
1293 } 1293 }
1294 } 1294 }
1295 } 1295 }
1296 1296
1297 instr->state = MTD_ERASE_DONE; 1297 instr->state = MTD_ERASE_DONE;
1298 mtd_erase_callback(instr); 1298 mtd_erase_callback(instr);
1299 1299
1300 return 0; 1300 return 0;
1301} 1301}
1302 1302
@@ -1324,7 +1324,7 @@ static void amd_flash_sync(struct mtd_info *mtd)
1324 case FL_JEDEC_QUERY: 1324 case FL_JEDEC_QUERY:
1325 chip->oldstate = chip->state; 1325 chip->oldstate = chip->state;
1326 chip->state = FL_SYNCING; 1326 chip->state = FL_SYNCING;
1327 /* No need to wake_up() on this state change - 1327 /* No need to wake_up() on this state change -
1328 * as the whole point is that nobody can do anything 1328 * as the whole point is that nobody can do anything
1329 * with the chip now anyway. 1329 * with the chip now anyway.
1330 */ 1330 */
@@ -1335,13 +1335,13 @@ static void amd_flash_sync(struct mtd_info *mtd)
1335 default: 1335 default:
1336 /* Not an idle state */ 1336 /* Not an idle state */
1337 add_wait_queue(&chip->wq, &wait); 1337 add_wait_queue(&chip->wq, &wait);
1338 1338
1339 spin_unlock_bh(chip->mutex); 1339 spin_unlock_bh(chip->mutex);
1340 1340
1341 schedule(); 1341 schedule();
1342 1342
1343 remove_wait_queue(&chip->wq, &wait); 1343 remove_wait_queue(&chip->wq, &wait);
1344 1344
1345 goto retry; 1345 goto retry;
1346 } 1346 }
1347 } 1347 }
@@ -1351,7 +1351,7 @@ static void amd_flash_sync(struct mtd_info *mtd)
1351 chip = &private->chips[i]; 1351 chip = &private->chips[i];
1352 1352
1353 spin_lock_bh(chip->mutex); 1353 spin_lock_bh(chip->mutex);
1354 1354
1355 if (chip->state == FL_SYNCING) { 1355 if (chip->state == FL_SYNCING) {
1356 chip->state = chip->oldstate; 1356 chip->state = chip->oldstate;
1357 wake_up(&chip->wq); 1357 wake_up(&chip->wq);
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 0cfcd88468e0..143f01a4c170 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -4,9 +4,9 @@
4 * 4 *
5 * (C) 2000 Red Hat. GPL'd 5 * (C) 2000 Red Hat. GPL'd
6 * 6 *
7 * $Id: cfi_cmdset_0001.c,v 1.178 2005/05/19 17:05:43 nico Exp $ 7 * $Id: cfi_cmdset_0001.c,v 1.185 2005/11/07 11:14:22 gleixner Exp $
8 *
8 * 9 *
9 *
10 * 10/10/2000 Nicolas Pitre <nico@cam.org> 10 * 10/10/2000 Nicolas Pitre <nico@cam.org>
11 * - completely revamped method functions so they are aware and 11 * - completely revamped method functions so they are aware and
12 * independent of the flash geometry (buswidth, interleave, etc.) 12 * independent of the flash geometry (buswidth, interleave, etc.)
@@ -51,6 +51,7 @@
51static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 51static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
52static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 52static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
53static int cfi_intelext_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 53static int cfi_intelext_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
54static int cfi_intelext_writev(struct mtd_info *, const struct kvec *, unsigned long, loff_t, size_t *);
54static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *); 55static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *);
55static void cfi_intelext_sync (struct mtd_info *); 56static void cfi_intelext_sync (struct mtd_info *);
56static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len); 57static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len);
@@ -105,6 +106,7 @@ static struct mtd_chip_driver cfi_intelext_chipdrv = {
105static void cfi_tell_features(struct cfi_pri_intelext *extp) 106static void cfi_tell_features(struct cfi_pri_intelext *extp)
106{ 107{
107 int i; 108 int i;
109 printk(" Extended Query version %c.%c\n", extp->MajorVersion, extp->MinorVersion);
108 printk(" Feature/Command Support: %4.4X\n", extp->FeatureSupport); 110 printk(" Feature/Command Support: %4.4X\n", extp->FeatureSupport);
109 printk(" - Chip Erase: %s\n", extp->FeatureSupport&1?"supported":"unsupported"); 111 printk(" - Chip Erase: %s\n", extp->FeatureSupport&1?"supported":"unsupported");
110 printk(" - Suspend Erase: %s\n", extp->FeatureSupport&2?"supported":"unsupported"); 112 printk(" - Suspend Erase: %s\n", extp->FeatureSupport&2?"supported":"unsupported");
@@ -116,36 +118,43 @@ static void cfi_tell_features(struct cfi_pri_intelext *extp)
116 printk(" - Page-mode read: %s\n", extp->FeatureSupport&128?"supported":"unsupported"); 118 printk(" - Page-mode read: %s\n", extp->FeatureSupport&128?"supported":"unsupported");
117 printk(" - Synchronous read: %s\n", extp->FeatureSupport&256?"supported":"unsupported"); 119 printk(" - Synchronous read: %s\n", extp->FeatureSupport&256?"supported":"unsupported");
118 printk(" - Simultaneous operations: %s\n", extp->FeatureSupport&512?"supported":"unsupported"); 120 printk(" - Simultaneous operations: %s\n", extp->FeatureSupport&512?"supported":"unsupported");
119 for (i=10; i<32; i++) { 121 printk(" - Extended Flash Array: %s\n", extp->FeatureSupport&1024?"supported":"unsupported");
120 if (extp->FeatureSupport & (1<<i)) 122 for (i=11; i<32; i++) {
123 if (extp->FeatureSupport & (1<<i))
121 printk(" - Unknown Bit %X: supported\n", i); 124 printk(" - Unknown Bit %X: supported\n", i);
122 } 125 }
123 126
124 printk(" Supported functions after Suspend: %2.2X\n", extp->SuspendCmdSupport); 127 printk(" Supported functions after Suspend: %2.2X\n", extp->SuspendCmdSupport);
125 printk(" - Program after Erase Suspend: %s\n", extp->SuspendCmdSupport&1?"supported":"unsupported"); 128 printk(" - Program after Erase Suspend: %s\n", extp->SuspendCmdSupport&1?"supported":"unsupported");
126 for (i=1; i<8; i++) { 129 for (i=1; i<8; i++) {
127 if (extp->SuspendCmdSupport & (1<<i)) 130 if (extp->SuspendCmdSupport & (1<<i))
128 printk(" - Unknown Bit %X: supported\n", i); 131 printk(" - Unknown Bit %X: supported\n", i);
129 } 132 }
130 133
131 printk(" Block Status Register Mask: %4.4X\n", extp->BlkStatusRegMask); 134 printk(" Block Status Register Mask: %4.4X\n", extp->BlkStatusRegMask);
132 printk(" - Lock Bit Active: %s\n", extp->BlkStatusRegMask&1?"yes":"no"); 135 printk(" - Lock Bit Active: %s\n", extp->BlkStatusRegMask&1?"yes":"no");
133 printk(" - Valid Bit Active: %s\n", extp->BlkStatusRegMask&2?"yes":"no"); 136 printk(" - Lock-Down Bit Active: %s\n", extp->BlkStatusRegMask&2?"yes":"no");
134 for (i=2; i<16; i++) { 137 for (i=2; i<3; i++) {
135 if (extp->BlkStatusRegMask & (1<<i)) 138 if (extp->BlkStatusRegMask & (1<<i))
136 printk(" - Unknown Bit %X Active: yes\n",i); 139 printk(" - Unknown Bit %X Active: yes\n",i);
137 } 140 }
138 141 printk(" - EFA Lock Bit: %s\n", extp->BlkStatusRegMask&16?"yes":"no");
139 printk(" Vcc Logic Supply Optimum Program/Erase Voltage: %d.%d V\n", 142 printk(" - EFA Lock-Down Bit: %s\n", extp->BlkStatusRegMask&32?"yes":"no");
143 for (i=6; i<16; i++) {
144 if (extp->BlkStatusRegMask & (1<<i))
145 printk(" - Unknown Bit %X Active: yes\n",i);
146 }
147
148 printk(" Vcc Logic Supply Optimum Program/Erase Voltage: %d.%d V\n",
140 extp->VccOptimal >> 4, extp->VccOptimal & 0xf); 149 extp->VccOptimal >> 4, extp->VccOptimal & 0xf);
141 if (extp->VppOptimal) 150 if (extp->VppOptimal)
142 printk(" Vpp Programming Supply Optimum Program/Erase Voltage: %d.%d V\n", 151 printk(" Vpp Programming Supply Optimum Program/Erase Voltage: %d.%d V\n",
143 extp->VppOptimal >> 4, extp->VppOptimal & 0xf); 152 extp->VppOptimal >> 4, extp->VppOptimal & 0xf);
144} 153}
145#endif 154#endif
146 155
147#ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE 156#ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
148/* Some Intel Strata Flash prior to FPO revision C has bugs in this area */ 157/* Some Intel Strata Flash prior to FPO revision C has bugs in this area */
149static void fixup_intel_strataflash(struct mtd_info *mtd, void* param) 158static void fixup_intel_strataflash(struct mtd_info *mtd, void* param)
150{ 159{
151 struct map_info *map = mtd->priv; 160 struct map_info *map = mtd->priv;
@@ -176,7 +185,7 @@ static void fixup_st_m28w320ct(struct mtd_info *mtd, void* param)
176{ 185{
177 struct map_info *map = mtd->priv; 186 struct map_info *map = mtd->priv;
178 struct cfi_private *cfi = map->fldrv_priv; 187 struct cfi_private *cfi = map->fldrv_priv;
179 188
180 cfi->cfiq->BufWriteTimeoutTyp = 0; /* Not supported */ 189 cfi->cfiq->BufWriteTimeoutTyp = 0; /* Not supported */
181 cfi->cfiq->BufWriteTimeoutMax = 0; /* Not supported */ 190 cfi->cfiq->BufWriteTimeoutMax = 0; /* Not supported */
182} 191}
@@ -185,7 +194,7 @@ static void fixup_st_m28w320cb(struct mtd_info *mtd, void* param)
185{ 194{
186 struct map_info *map = mtd->priv; 195 struct map_info *map = mtd->priv;
187 struct cfi_private *cfi = map->fldrv_priv; 196 struct cfi_private *cfi = map->fldrv_priv;
188 197
189 /* Note this is done after the region info is endian swapped */ 198 /* Note this is done after the region info is endian swapped */
190 cfi->cfiq->EraseRegionInfo[1] = 199 cfi->cfiq->EraseRegionInfo[1] =
191 (cfi->cfiq->EraseRegionInfo[1] & 0xffff0000) | 0x3e; 200 (cfi->cfiq->EraseRegionInfo[1] & 0xffff0000) | 0x3e;
@@ -207,12 +216,13 @@ static void fixup_use_write_buffers(struct mtd_info *mtd, void *param)
207 if (cfi->cfiq->BufWriteTimeoutTyp) { 216 if (cfi->cfiq->BufWriteTimeoutTyp) {
208 printk(KERN_INFO "Using buffer write method\n" ); 217 printk(KERN_INFO "Using buffer write method\n" );
209 mtd->write = cfi_intelext_write_buffers; 218 mtd->write = cfi_intelext_write_buffers;
219 mtd->writev = cfi_intelext_writev;
210 } 220 }
211} 221}
212 222
213static struct cfi_fixup cfi_fixup_table[] = { 223static struct cfi_fixup cfi_fixup_table[] = {
214#ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE 224#ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
215 { CFI_MFR_ANY, CFI_ID_ANY, fixup_intel_strataflash, NULL }, 225 { CFI_MFR_ANY, CFI_ID_ANY, fixup_intel_strataflash, NULL },
216#endif 226#endif
217#ifdef CMDSET0001_DISABLE_WRITE_SUSPEND 227#ifdef CMDSET0001_DISABLE_WRITE_SUSPEND
218 { CFI_MFR_ANY, CFI_ID_ANY, fixup_no_write_suspend, NULL }, 228 { CFI_MFR_ANY, CFI_ID_ANY, fixup_no_write_suspend, NULL },
@@ -252,12 +262,21 @@ read_pri_intelext(struct map_info *map, __u16 adr)
252 if (!extp) 262 if (!extp)
253 return NULL; 263 return NULL;
254 264
265 if (extp->MajorVersion != '1' ||
266 (extp->MinorVersion < '0' || extp->MinorVersion > '4')) {
267 printk(KERN_ERR " Unknown Intel/Sharp Extended Query "
268 "version %c.%c.\n", extp->MajorVersion,
269 extp->MinorVersion);
270 kfree(extp);
271 return NULL;
272 }
273
255 /* Do some byteswapping if necessary */ 274 /* Do some byteswapping if necessary */
256 extp->FeatureSupport = le32_to_cpu(extp->FeatureSupport); 275 extp->FeatureSupport = le32_to_cpu(extp->FeatureSupport);
257 extp->BlkStatusRegMask = le16_to_cpu(extp->BlkStatusRegMask); 276 extp->BlkStatusRegMask = le16_to_cpu(extp->BlkStatusRegMask);
258 extp->ProtRegAddr = le16_to_cpu(extp->ProtRegAddr); 277 extp->ProtRegAddr = le16_to_cpu(extp->ProtRegAddr);
259 278
260 if (extp->MajorVersion == '1' && extp->MinorVersion == '3') { 279 if (extp->MajorVersion == '1' && extp->MinorVersion >= '3') {
261 unsigned int extra_size = 0; 280 unsigned int extra_size = 0;
262 int nb_parts, i; 281 int nb_parts, i;
263 282
@@ -266,7 +285,10 @@ read_pri_intelext(struct map_info *map, __u16 adr)
266 sizeof(struct cfi_intelext_otpinfo); 285 sizeof(struct cfi_intelext_otpinfo);
267 286
268 /* Burst Read info */ 287 /* Burst Read info */
269 extra_size += 6; 288 extra_size += 2;
289 if (extp_size < sizeof(*extp) + extra_size)
290 goto need_more;
291 extra_size += extp->extra[extra_size-1];
270 292
271 /* Number of hardware-partitions */ 293 /* Number of hardware-partitions */
272 extra_size += 1; 294 extra_size += 1;
@@ -274,6 +296,10 @@ read_pri_intelext(struct map_info *map, __u16 adr)
274 goto need_more; 296 goto need_more;
275 nb_parts = extp->extra[extra_size - 1]; 297 nb_parts = extp->extra[extra_size - 1];
276 298
299 /* skip the sizeof(partregion) field in CFI 1.4 */
300 if (extp->MinorVersion >= '4')
301 extra_size += 2;
302
277 for (i = 0; i < nb_parts; i++) { 303 for (i = 0; i < nb_parts; i++) {
278 struct cfi_intelext_regioninfo *rinfo; 304 struct cfi_intelext_regioninfo *rinfo;
279 rinfo = (struct cfi_intelext_regioninfo *)&extp->extra[extra_size]; 305 rinfo = (struct cfi_intelext_regioninfo *)&extp->extra[extra_size];
@@ -285,6 +311,9 @@ read_pri_intelext(struct map_info *map, __u16 adr)
285 * sizeof(struct cfi_intelext_blockinfo); 311 * sizeof(struct cfi_intelext_blockinfo);
286 } 312 }
287 313
314 if (extp->MinorVersion >= '4')
315 extra_size += sizeof(struct cfi_intelext_programming_regioninfo);
316
288 if (extp_size < sizeof(*extp) + extra_size) { 317 if (extp_size < sizeof(*extp) + extra_size) {
289 need_more: 318 need_more:
290 extp_size = sizeof(*extp) + extra_size; 319 extp_size = sizeof(*extp) + extra_size;
@@ -298,7 +327,7 @@ read_pri_intelext(struct map_info *map, __u16 adr)
298 goto again; 327 goto again;
299 } 328 }
300 } 329 }
301 330
302 return extp; 331 return extp;
303} 332}
304 333
@@ -339,7 +368,7 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
339 mtd->reboot_notifier.notifier_call = cfi_intelext_reboot; 368 mtd->reboot_notifier.notifier_call = cfi_intelext_reboot;
340 369
341 if (cfi->cfi_mode == CFI_MODE_CFI) { 370 if (cfi->cfi_mode == CFI_MODE_CFI) {
342 /* 371 /*
343 * It's a real CFI chip, not one for which the probe 372 * It's a real CFI chip, not one for which the probe
344 * routine faked a CFI structure. So we read the feature 373 * routine faked a CFI structure. So we read the feature
345 * table from it. 374 * table from it.
@@ -354,14 +383,14 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
354 } 383 }
355 384
356 /* Install our own private info structure */ 385 /* Install our own private info structure */
357 cfi->cmdset_priv = extp; 386 cfi->cmdset_priv = extp;
358 387
359 cfi_fixup(mtd, cfi_fixup_table); 388 cfi_fixup(mtd, cfi_fixup_table);
360 389
361#ifdef DEBUG_CFI_FEATURES 390#ifdef DEBUG_CFI_FEATURES
362 /* Tell the user about it in lots of lovely detail */ 391 /* Tell the user about it in lots of lovely detail */
363 cfi_tell_features(extp); 392 cfi_tell_features(extp);
364#endif 393#endif
365 394
366 if(extp->SuspendCmdSupport & 1) { 395 if(extp->SuspendCmdSupport & 1) {
367 printk(KERN_NOTICE "cfi_cmdset_0001: Erase suspend on write enabled\n"); 396 printk(KERN_NOTICE "cfi_cmdset_0001: Erase suspend on write enabled\n");
@@ -379,10 +408,10 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
379 cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp; 408 cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp;
380 cfi->chips[i].erase_time = 1<<cfi->cfiq->BlockEraseTimeoutTyp; 409 cfi->chips[i].erase_time = 1<<cfi->cfiq->BlockEraseTimeoutTyp;
381 cfi->chips[i].ref_point_counter = 0; 410 cfi->chips[i].ref_point_counter = 0;
382 } 411 }
383 412
384 map->fldrv = &cfi_intelext_chipdrv; 413 map->fldrv = &cfi_intelext_chipdrv;
385 414
386 return cfi_intelext_setup(mtd); 415 return cfi_intelext_setup(mtd);
387} 416}
388 417
@@ -399,13 +428,13 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
399 mtd->size = devsize * cfi->numchips; 428 mtd->size = devsize * cfi->numchips;
400 429
401 mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips; 430 mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips;
402 mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) 431 mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info)
403 * mtd->numeraseregions, GFP_KERNEL); 432 * mtd->numeraseregions, GFP_KERNEL);
404 if (!mtd->eraseregions) { 433 if (!mtd->eraseregions) {
405 printk(KERN_ERR "Failed to allocate memory for MTD erase region info\n"); 434 printk(KERN_ERR "Failed to allocate memory for MTD erase region info\n");
406 goto setup_err; 435 goto setup_err;
407 } 436 }
408 437
409 for (i=0; i<cfi->cfiq->NumEraseRegions; i++) { 438 for (i=0; i<cfi->cfiq->NumEraseRegions; i++) {
410 unsigned long ernum, ersize; 439 unsigned long ernum, ersize;
411 ersize = ((cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff) * cfi->interleave; 440 ersize = ((cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff) * cfi->interleave;
@@ -429,7 +458,7 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
429 } 458 }
430 459
431 for (i=0; i<mtd->numeraseregions;i++){ 460 for (i=0; i<mtd->numeraseregions;i++){
432 printk(KERN_DEBUG "%d: offset=0x%x,size=0x%x,blocks=%d\n", 461 printk(KERN_DEBUG "erase region %d: offset=0x%x,size=0x%x,blocks=%d\n",
433 i,mtd->eraseregions[i].offset, 462 i,mtd->eraseregions[i].offset,
434 mtd->eraseregions[i].erasesize, 463 mtd->eraseregions[i].erasesize,
435 mtd->eraseregions[i].numblocks); 464 mtd->eraseregions[i].numblocks);
@@ -455,8 +484,7 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
455 484
456 setup_err: 485 setup_err:
457 if(mtd) { 486 if(mtd) {
458 if(mtd->eraseregions) 487 kfree(mtd->eraseregions);
459 kfree(mtd->eraseregions);
460 kfree(mtd); 488 kfree(mtd);
461 } 489 }
462 kfree(cfi->cmdset_priv); 490 kfree(cfi->cmdset_priv);
@@ -481,7 +509,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
481 * arrangement at this point. This can be rearranged in the future 509 * arrangement at this point. This can be rearranged in the future
482 * if someone feels motivated enough. --nico 510 * if someone feels motivated enough. --nico
483 */ 511 */
484 if (extp && extp->MajorVersion == '1' && extp->MinorVersion == '3' 512 if (extp && extp->MajorVersion == '1' && extp->MinorVersion >= '3'
485 && extp->FeatureSupport & (1 << 9)) { 513 && extp->FeatureSupport & (1 << 9)) {
486 struct cfi_private *newcfi; 514 struct cfi_private *newcfi;
487 struct flchip *chip; 515 struct flchip *chip;
@@ -493,12 +521,16 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
493 sizeof(struct cfi_intelext_otpinfo); 521 sizeof(struct cfi_intelext_otpinfo);
494 522
495 /* Burst Read info */ 523 /* Burst Read info */
496 offs += 6; 524 offs += extp->extra[offs+1]+2;
497 525
498 /* Number of partition regions */ 526 /* Number of partition regions */
499 numregions = extp->extra[offs]; 527 numregions = extp->extra[offs];
500 offs += 1; 528 offs += 1;
501 529
530 /* skip the sizeof(partregion) field in CFI 1.4 */
531 if (extp->MinorVersion >= '4')
532 offs += 2;
533
502 /* Number of hardware partitions */ 534 /* Number of hardware partitions */
503 numparts = 0; 535 numparts = 0;
504 for (i = 0; i < numregions; i++) { 536 for (i = 0; i < numregions; i++) {
@@ -510,6 +542,20 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
510 sizeof(struct cfi_intelext_blockinfo); 542 sizeof(struct cfi_intelext_blockinfo);
511 } 543 }
512 544
545 /* Programming Region info */
546 if (extp->MinorVersion >= '4') {
547 struct cfi_intelext_programming_regioninfo *prinfo;
548 prinfo = (struct cfi_intelext_programming_regioninfo *)&extp->extra[offs];
549 MTD_PROGREGION_SIZE(mtd) = cfi->interleave << prinfo->ProgRegShift;
550 MTD_PROGREGION_CTRLMODE_VALID(mtd) = cfi->interleave * prinfo->ControlValid;
551 MTD_PROGREGION_CTRLMODE_INVALID(mtd) = cfi->interleave * prinfo->ControlInvalid;
552 mtd->flags |= MTD_PROGRAM_REGIONS;
553 printk(KERN_DEBUG "%s: program region size/ctrl_valid/ctrl_inval = %d/%d/%d\n",
554 map->name, MTD_PROGREGION_SIZE(mtd),
555 MTD_PROGREGION_CTRLMODE_VALID(mtd),
556 MTD_PROGREGION_CTRLMODE_INVALID(mtd));
557 }
558
513 /* 559 /*
514 * All functions below currently rely on all chips having 560 * All functions below currently rely on all chips having
515 * the same geometry so we'll just assume that all hardware 561 * the same geometry so we'll just assume that all hardware
@@ -654,8 +700,8 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
654 break; 700 break;
655 701
656 if (time_after(jiffies, timeo)) { 702 if (time_after(jiffies, timeo)) {
657 printk(KERN_ERR "Waiting for chip to be ready timed out. Status %lx\n", 703 printk(KERN_ERR "%s: Waiting for chip to be ready timed out. Status %lx\n",
658 status.x[0]); 704 map->name, status.x[0]);
659 return -EIO; 705 return -EIO;
660 } 706 }
661 spin_unlock(chip->mutex); 707 spin_unlock(chip->mutex);
@@ -664,7 +710,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
664 /* Someone else might have been playing with it. */ 710 /* Someone else might have been playing with it. */
665 goto retry; 711 goto retry;
666 } 712 }
667 713
668 case FL_READY: 714 case FL_READY:
669 case FL_CFI_QUERY: 715 case FL_CFI_QUERY:
670 case FL_JEDEC_QUERY: 716 case FL_JEDEC_QUERY:
@@ -702,8 +748,8 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
702 map_write(map, CMD(0x70), adr); 748 map_write(map, CMD(0x70), adr);
703 chip->state = FL_ERASING; 749 chip->state = FL_ERASING;
704 chip->oldstate = FL_READY; 750 chip->oldstate = FL_READY;
705 printk(KERN_ERR "Chip not ready after erase " 751 printk(KERN_ERR "%s: Chip not ready after erase "
706 "suspended: status = 0x%lx\n", status.x[0]); 752 "suspended: status = 0x%lx\n", map->name, status.x[0]);
707 return -EIO; 753 return -EIO;
708 } 754 }
709 755
@@ -783,14 +829,14 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
783 switch(chip->oldstate) { 829 switch(chip->oldstate) {
784 case FL_ERASING: 830 case FL_ERASING:
785 chip->state = chip->oldstate; 831 chip->state = chip->oldstate;
786 /* What if one interleaved chip has finished and the 832 /* What if one interleaved chip has finished and the
787 other hasn't? The old code would leave the finished 833 other hasn't? The old code would leave the finished
788 one in READY mode. That's bad, and caused -EROFS 834 one in READY mode. That's bad, and caused -EROFS
789 errors to be returned from do_erase_oneblock because 835 errors to be returned from do_erase_oneblock because
790 that's the only bit it checked for at the time. 836 that's the only bit it checked for at the time.
791 As the state machine appears to explicitly allow 837 As the state machine appears to explicitly allow
792 sending the 0x70 (Read Status) command to an erasing 838 sending the 0x70 (Read Status) command to an erasing
793 chip and expecting it to be ignored, that's what we 839 chip and expecting it to be ignored, that's what we
794 do. */ 840 do. */
795 map_write(map, CMD(0xd0), adr); 841 map_write(map, CMD(0xd0), adr);
796 map_write(map, CMD(0x70), adr); 842 map_write(map, CMD(0x70), adr);
@@ -810,7 +856,7 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
810 DISABLE_VPP(map); 856 DISABLE_VPP(map);
811 break; 857 break;
812 default: 858 default:
813 printk(KERN_ERR "put_chip() called with oldstate %d!!\n", chip->oldstate); 859 printk(KERN_ERR "%s: put_chip() called with oldstate %d!!\n", map->name, chip->oldstate);
814 } 860 }
815 wake_up(&chip->wq); 861 wake_up(&chip->wq);
816} 862}
@@ -1026,8 +1072,8 @@ static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t a
1026 1072
1027 adr += chip->start; 1073 adr += chip->start;
1028 1074
1029 /* Ensure cmd read/writes are aligned. */ 1075 /* Ensure cmd read/writes are aligned. */
1030 cmd_addr = adr & ~(map_bankwidth(map)-1); 1076 cmd_addr = adr & ~(map_bankwidth(map)-1);
1031 1077
1032 spin_lock(chip->mutex); 1078 spin_lock(chip->mutex);
1033 1079
@@ -1055,7 +1101,7 @@ static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len, si
1055 1101
1056 if (!map->virt || (from + len > mtd->size)) 1102 if (!map->virt || (from + len > mtd->size))
1057 return -EINVAL; 1103 return -EINVAL;
1058 1104
1059 *mtdbuf = (void *)map->virt + from; 1105 *mtdbuf = (void *)map->virt + from;
1060 *retlen = 0; 1106 *retlen = 0;
1061 1107
@@ -1082,7 +1128,7 @@ static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len, si
1082 1128
1083 *retlen += thislen; 1129 *retlen += thislen;
1084 len -= thislen; 1130 len -= thislen;
1085 1131
1086 ofs = 0; 1132 ofs = 0;
1087 chipnum++; 1133 chipnum++;
1088 } 1134 }
@@ -1121,7 +1167,7 @@ static void cfi_intelext_unpoint (struct mtd_info *mtd, u_char *addr, loff_t fro
1121 if(chip->ref_point_counter == 0) 1167 if(chip->ref_point_counter == 0)
1122 chip->state = FL_READY; 1168 chip->state = FL_READY;
1123 } else 1169 } else
1124 printk(KERN_ERR "Warning: unpoint called on non pointed region\n"); /* Should this give an error? */ 1170 printk(KERN_ERR "%s: Warning: unpoint called on non pointed region\n", map->name); /* Should this give an error? */
1125 1171
1126 put_chip(map, chip, chip->start); 1172 put_chip(map, chip, chip->start);
1127 spin_unlock(chip->mutex); 1173 spin_unlock(chip->mutex);
@@ -1140,8 +1186,8 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
1140 1186
1141 adr += chip->start; 1187 adr += chip->start;
1142 1188
1143 /* Ensure cmd read/writes are aligned. */ 1189 /* Ensure cmd read/writes are aligned. */
1144 cmd_addr = adr & ~(map_bankwidth(map)-1); 1190 cmd_addr = adr & ~(map_bankwidth(map)-1);
1145 1191
1146 spin_lock(chip->mutex); 1192 spin_lock(chip->mutex);
1147 ret = get_chip(map, chip, cmd_addr, FL_READY); 1193 ret = get_chip(map, chip, cmd_addr, FL_READY);
@@ -1196,7 +1242,7 @@ static int cfi_intelext_read (struct mtd_info *mtd, loff_t from, size_t len, siz
1196 *retlen += thislen; 1242 *retlen += thislen;
1197 len -= thislen; 1243 len -= thislen;
1198 buf += thislen; 1244 buf += thislen;
1199 1245
1200 ofs = 0; 1246 ofs = 0;
1201 chipnum++; 1247 chipnum++;
1202 } 1248 }
@@ -1213,12 +1259,17 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1213 1259
1214 adr += chip->start; 1260 adr += chip->start;
1215 1261
1216 /* Let's determine this according to the interleave only once */ 1262 /* Let's determine those according to the interleave only once */
1217 status_OK = CMD(0x80); 1263 status_OK = CMD(0x80);
1218 switch (mode) { 1264 switch (mode) {
1219 case FL_WRITING: write_cmd = CMD(0x40); break; 1265 case FL_WRITING:
1220 case FL_OTP_WRITE: write_cmd = CMD(0xc0); break; 1266 write_cmd = (cfi->cfiq->P_ID != 0x0200) ? CMD(0x40) : CMD(0x41);
1221 default: return -EINVAL; 1267 break;
1268 case FL_OTP_WRITE:
1269 write_cmd = CMD(0xc0);
1270 break;
1271 default:
1272 return -EINVAL;
1222 } 1273 }
1223 1274
1224 spin_lock(chip->mutex); 1275 spin_lock(chip->mutex);
@@ -1259,12 +1310,13 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1259 status = map_read(map, adr); 1310 status = map_read(map, adr);
1260 if (map_word_andequal(map, status, status_OK, status_OK)) 1311 if (map_word_andequal(map, status, status_OK, status_OK))
1261 break; 1312 break;
1262 1313
1263 /* OK Still waiting */ 1314 /* OK Still waiting */
1264 if (time_after(jiffies, timeo)) { 1315 if (time_after(jiffies, timeo)) {
1316 map_write(map, CMD(0x70), adr);
1265 chip->state = FL_STATUS; 1317 chip->state = FL_STATUS;
1266 xip_enable(map, chip, adr); 1318 xip_enable(map, chip, adr);
1267 printk(KERN_ERR "waiting for chip to be ready timed out in word write\n"); 1319 printk(KERN_ERR "%s: word write error (status timeout)\n", map->name);
1268 ret = -EIO; 1320 ret = -EIO;
1269 goto out; 1321 goto out;
1270 } 1322 }
@@ -1276,27 +1328,39 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1276 if (!z) { 1328 if (!z) {
1277 chip->word_write_time--; 1329 chip->word_write_time--;
1278 if (!chip->word_write_time) 1330 if (!chip->word_write_time)
1279 chip->word_write_time++; 1331 chip->word_write_time = 1;
1280 } 1332 }
1281 if (z > 1) 1333 if (z > 1)
1282 chip->word_write_time++; 1334 chip->word_write_time++;
1283 1335
1284 /* Done and happy. */ 1336 /* Done and happy. */
1285 chip->state = FL_STATUS; 1337 chip->state = FL_STATUS;
1286 1338
1287 /* check for lock bit */ 1339 /* check for errors */
1288 if (map_word_bitsset(map, status, CMD(0x02))) { 1340 if (map_word_bitsset(map, status, CMD(0x1a))) {
1289 /* clear status */ 1341 unsigned long chipstatus = MERGESTATUS(status);
1342
1343 /* reset status */
1290 map_write(map, CMD(0x50), adr); 1344 map_write(map, CMD(0x50), adr);
1291 /* put back into read status register mode */
1292 map_write(map, CMD(0x70), adr); 1345 map_write(map, CMD(0x70), adr);
1293 ret = -EROFS; 1346 xip_enable(map, chip, adr);
1347
1348 if (chipstatus & 0x02) {
1349 ret = -EROFS;
1350 } else if (chipstatus & 0x08) {
1351 printk(KERN_ERR "%s: word write error (bad VPP)\n", map->name);
1352 ret = -EIO;
1353 } else {
1354 printk(KERN_ERR "%s: word write error (status 0x%lx)\n", map->name, chipstatus);
1355 ret = -EINVAL;
1356 }
1357
1358 goto out;
1294 } 1359 }
1295 1360
1296 xip_enable(map, chip, adr); 1361 xip_enable(map, chip, adr);
1297 out: put_chip(map, chip, adr); 1362 out: put_chip(map, chip, adr);
1298 spin_unlock(chip->mutex); 1363 spin_unlock(chip->mutex);
1299
1300 return ret; 1364 return ret;
1301} 1365}
1302 1366
@@ -1329,7 +1393,7 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
1329 1393
1330 ret = do_write_oneword(map, &cfi->chips[chipnum], 1394 ret = do_write_oneword(map, &cfi->chips[chipnum],
1331 bus_ofs, datum, FL_WRITING); 1395 bus_ofs, datum, FL_WRITING);
1332 if (ret) 1396 if (ret)
1333 return ret; 1397 return ret;
1334 1398
1335 len -= n; 1399 len -= n;
@@ -1338,13 +1402,13 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
1338 (*retlen) += n; 1402 (*retlen) += n;
1339 1403
1340 if (ofs >> cfi->chipshift) { 1404 if (ofs >> cfi->chipshift) {
1341 chipnum ++; 1405 chipnum ++;
1342 ofs = 0; 1406 ofs = 0;
1343 if (chipnum == cfi->numchips) 1407 if (chipnum == cfi->numchips)
1344 return 0; 1408 return 0;
1345 } 1409 }
1346 } 1410 }
1347 1411
1348 while(len >= map_bankwidth(map)) { 1412 while(len >= map_bankwidth(map)) {
1349 map_word datum = map_word_load(map, buf); 1413 map_word datum = map_word_load(map, buf);
1350 1414
@@ -1359,7 +1423,7 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
1359 len -= map_bankwidth(map); 1423 len -= map_bankwidth(map);
1360 1424
1361 if (ofs >> cfi->chipshift) { 1425 if (ofs >> cfi->chipshift) {
1362 chipnum ++; 1426 chipnum ++;
1363 ofs = 0; 1427 ofs = 0;
1364 if (chipnum == cfi->numchips) 1428 if (chipnum == cfi->numchips)
1365 return 0; 1429 return 0;
@@ -1374,9 +1438,9 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
1374 1438
1375 ret = do_write_oneword(map, &cfi->chips[chipnum], 1439 ret = do_write_oneword(map, &cfi->chips[chipnum],
1376 ofs, datum, FL_WRITING); 1440 ofs, datum, FL_WRITING);
1377 if (ret) 1441 if (ret)
1378 return ret; 1442 return ret;
1379 1443
1380 (*retlen) += len; 1444 (*retlen) += len;
1381 } 1445 }
1382 1446
@@ -1384,20 +1448,24 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
1384} 1448}
1385 1449
1386 1450
1387static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, 1451static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1388 unsigned long adr, const u_char *buf, int len) 1452 unsigned long adr, const struct kvec **pvec,
1453 unsigned long *pvec_seek, int len)
1389{ 1454{
1390 struct cfi_private *cfi = map->fldrv_priv; 1455 struct cfi_private *cfi = map->fldrv_priv;
1391 map_word status, status_OK; 1456 map_word status, status_OK, write_cmd, datum;
1392 unsigned long cmd_adr, timeo; 1457 unsigned long cmd_adr, timeo;
1393 int wbufsize, z, ret=0, bytes, words; 1458 int wbufsize, z, ret=0, word_gap, words;
1459 const struct kvec *vec;
1460 unsigned long vec_seek;
1394 1461
1395 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize; 1462 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
1396 adr += chip->start; 1463 adr += chip->start;
1397 cmd_adr = adr & ~(wbufsize-1); 1464 cmd_adr = adr & ~(wbufsize-1);
1398 1465
1399 /* Let's determine this according to the interleave only once */ 1466 /* Let's determine this according to the interleave only once */
1400 status_OK = CMD(0x80); 1467 status_OK = CMD(0x80);
1468 write_cmd = (cfi->cfiq->P_ID != 0x0200) ? CMD(0xe8) : CMD(0xe9);
1401 1469
1402 spin_lock(chip->mutex); 1470 spin_lock(chip->mutex);
1403 ret = get_chip(map, chip, cmd_adr, FL_WRITING); 1471 ret = get_chip(map, chip, cmd_adr, FL_WRITING);
@@ -1411,7 +1479,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1411 xip_disable(map, chip, cmd_adr); 1479 xip_disable(map, chip, cmd_adr);
1412 1480
1413 /* §4.8 of the 28FxxxJ3A datasheet says "Any time SR.4 and/or SR.5 is set 1481 /* §4.8 of the 28FxxxJ3A datasheet says "Any time SR.4 and/or SR.5 is set
1414 [...], the device will not accept any more Write to Buffer commands". 1482 [...], the device will not accept any more Write to Buffer commands".
1415 So we must check here and reset those bits if they're set. Otherwise 1483 So we must check here and reset those bits if they're set. Otherwise
1416 we're just pissing in the wind */ 1484 we're just pissing in the wind */
1417 if (chip->state != FL_STATUS) 1485 if (chip->state != FL_STATUS)
@@ -1429,7 +1497,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1429 1497
1430 z = 0; 1498 z = 0;
1431 for (;;) { 1499 for (;;) {
1432 map_write(map, CMD(0xe8), cmd_adr); 1500 map_write(map, write_cmd, cmd_adr);
1433 1501
1434 status = map_read(map, cmd_adr); 1502 status = map_read(map, cmd_adr);
1435 if (map_word_andequal(map, status, status_OK, status_OK)) 1503 if (map_word_andequal(map, status, status_OK, status_OK))
@@ -1447,41 +1515,66 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1447 map_write(map, CMD(0x50), cmd_adr); 1515 map_write(map, CMD(0x50), cmd_adr);
1448 map_write(map, CMD(0x70), cmd_adr); 1516 map_write(map, CMD(0x70), cmd_adr);
1449 xip_enable(map, chip, cmd_adr); 1517 xip_enable(map, chip, cmd_adr);
1450 printk(KERN_ERR "Chip not ready for buffer write. status = %lx, Xstatus = %lx\n", 1518 printk(KERN_ERR "%s: Chip not ready for buffer write. status = %lx, Xstatus = %lx\n",
1451 status.x[0], Xstatus.x[0]); 1519 map->name, status.x[0], Xstatus.x[0]);
1452 ret = -EIO; 1520 ret = -EIO;
1453 goto out; 1521 goto out;
1454 } 1522 }
1455 } 1523 }
1456 1524
1525 /* Figure out the number of words to write */
1526 word_gap = (-adr & (map_bankwidth(map)-1));
1527 words = (len - word_gap + map_bankwidth(map) - 1) / map_bankwidth(map);
1528 if (!word_gap) {
1529 words--;
1530 } else {
1531 word_gap = map_bankwidth(map) - word_gap;
1532 adr -= word_gap;
1533 datum = map_word_ff(map);
1534 }
1535
1457 /* Write length of data to come */ 1536 /* Write length of data to come */
1458 bytes = len & (map_bankwidth(map)-1); 1537 map_write(map, CMD(words), cmd_adr );
1459 words = len / map_bankwidth(map);
1460 map_write(map, CMD(words - !bytes), cmd_adr );
1461 1538
1462 /* Write data */ 1539 /* Write data */
1463 z = 0; 1540 vec = *pvec;
1464 while(z < words * map_bankwidth(map)) { 1541 vec_seek = *pvec_seek;
1465 map_word datum = map_word_load(map, buf); 1542 do {
1466 map_write(map, datum, adr+z); 1543 int n = map_bankwidth(map) - word_gap;
1544 if (n > vec->iov_len - vec_seek)
1545 n = vec->iov_len - vec_seek;
1546 if (n > len)
1547 n = len;
1467 1548
1468 z += map_bankwidth(map); 1549 if (!word_gap && len < map_bankwidth(map))
1469 buf += map_bankwidth(map); 1550 datum = map_word_ff(map);
1470 }
1471 1551
1472 if (bytes) { 1552 datum = map_word_load_partial(map, datum,
1473 map_word datum; 1553 vec->iov_base + vec_seek,
1554 word_gap, n);
1474 1555
1475 datum = map_word_ff(map); 1556 len -= n;
1476 datum = map_word_load_partial(map, datum, buf, 0, bytes); 1557 word_gap += n;
1477 map_write(map, datum, adr+z); 1558 if (!len || word_gap == map_bankwidth(map)) {
1478 } 1559 map_write(map, datum, adr);
1560 adr += map_bankwidth(map);
1561 word_gap = 0;
1562 }
1563
1564 vec_seek += n;
1565 if (vec_seek == vec->iov_len) {
1566 vec++;
1567 vec_seek = 0;
1568 }
1569 } while (len);
1570 *pvec = vec;
1571 *pvec_seek = vec_seek;
1479 1572
1480 /* GO GO GO */ 1573 /* GO GO GO */
1481 map_write(map, CMD(0xd0), cmd_adr); 1574 map_write(map, CMD(0xd0), cmd_adr);
1482 chip->state = FL_WRITING; 1575 chip->state = FL_WRITING;
1483 1576
1484 INVALIDATE_CACHE_UDELAY(map, chip, 1577 INVALIDATE_CACHE_UDELAY(map, chip,
1485 cmd_adr, len, 1578 cmd_adr, len,
1486 chip->buffer_write_time); 1579 chip->buffer_write_time);
1487 1580
@@ -1507,13 +1600,14 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1507 1600
1508 /* OK Still waiting */ 1601 /* OK Still waiting */
1509 if (time_after(jiffies, timeo)) { 1602 if (time_after(jiffies, timeo)) {
1603 map_write(map, CMD(0x70), cmd_adr);
1510 chip->state = FL_STATUS; 1604 chip->state = FL_STATUS;
1511 xip_enable(map, chip, cmd_adr); 1605 xip_enable(map, chip, cmd_adr);
1512 printk(KERN_ERR "waiting for chip to be ready timed out in bufwrite\n"); 1606 printk(KERN_ERR "%s: buffer write error (status timeout)\n", map->name);
1513 ret = -EIO; 1607 ret = -EIO;
1514 goto out; 1608 goto out;
1515 } 1609 }
1516 1610
1517 /* Latency issues. Drop the lock, wait a while and retry */ 1611 /* Latency issues. Drop the lock, wait a while and retry */
1518 z++; 1612 z++;
1519 UDELAY(map, chip, cmd_adr, 1); 1613 UDELAY(map, chip, cmd_adr, 1);
@@ -1521,21 +1615,34 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1521 if (!z) { 1615 if (!z) {
1522 chip->buffer_write_time--; 1616 chip->buffer_write_time--;
1523 if (!chip->buffer_write_time) 1617 if (!chip->buffer_write_time)
1524 chip->buffer_write_time++; 1618 chip->buffer_write_time = 1;
1525 } 1619 }
1526 if (z > 1) 1620 if (z > 1)
1527 chip->buffer_write_time++; 1621 chip->buffer_write_time++;
1528 1622
1529 /* Done and happy. */ 1623 /* Done and happy. */
1530 chip->state = FL_STATUS; 1624 chip->state = FL_STATUS;
1531 1625
1532 /* check for lock bit */ 1626 /* check for errors */
1533 if (map_word_bitsset(map, status, CMD(0x02))) { 1627 if (map_word_bitsset(map, status, CMD(0x1a))) {
1534 /* clear status */ 1628 unsigned long chipstatus = MERGESTATUS(status);
1629
1630 /* reset status */
1535 map_write(map, CMD(0x50), cmd_adr); 1631 map_write(map, CMD(0x50), cmd_adr);
1536 /* put back into read status register mode */ 1632 map_write(map, CMD(0x70), cmd_adr);
1537 map_write(map, CMD(0x70), adr); 1633 xip_enable(map, chip, cmd_adr);
1538 ret = -EROFS; 1634
1635 if (chipstatus & 0x02) {
1636 ret = -EROFS;
1637 } else if (chipstatus & 0x08) {
1638 printk(KERN_ERR "%s: buffer write error (bad VPP)\n", map->name);
1639 ret = -EIO;
1640 } else {
1641 printk(KERN_ERR "%s: buffer write error (status 0x%lx)\n", map->name, chipstatus);
1642 ret = -EINVAL;
1643 }
1644
1645 goto out;
1539 } 1646 }
1540 1647
1541 xip_enable(map, chip, cmd_adr); 1648 xip_enable(map, chip, cmd_adr);
@@ -1544,70 +1651,65 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1544 return ret; 1651 return ret;
1545} 1652}
1546 1653
1547static int cfi_intelext_write_buffers (struct mtd_info *mtd, loff_t to, 1654static int cfi_intelext_writev (struct mtd_info *mtd, const struct kvec *vecs,
1548 size_t len, size_t *retlen, const u_char *buf) 1655 unsigned long count, loff_t to, size_t *retlen)
1549{ 1656{
1550 struct map_info *map = mtd->priv; 1657 struct map_info *map = mtd->priv;
1551 struct cfi_private *cfi = map->fldrv_priv; 1658 struct cfi_private *cfi = map->fldrv_priv;
1552 int wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize; 1659 int wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
1553 int ret = 0; 1660 int ret = 0;
1554 int chipnum; 1661 int chipnum;
1555 unsigned long ofs; 1662 unsigned long ofs, vec_seek, i;
1663 size_t len = 0;
1664
1665 for (i = 0; i < count; i++)
1666 len += vecs[i].iov_len;
1556 1667
1557 *retlen = 0; 1668 *retlen = 0;
1558 if (!len) 1669 if (!len)
1559 return 0; 1670 return 0;
1560 1671
1561 chipnum = to >> cfi->chipshift; 1672 chipnum = to >> cfi->chipshift;
1562 ofs = to - (chipnum << cfi->chipshift); 1673 ofs = to - (chipnum << cfi->chipshift);
1563 1674 vec_seek = 0;
1564 /* If it's not bus-aligned, do the first word write */
1565 if (ofs & (map_bankwidth(map)-1)) {
1566 size_t local_len = (-ofs)&(map_bankwidth(map)-1);
1567 if (local_len > len)
1568 local_len = len;
1569 ret = cfi_intelext_write_words(mtd, to, local_len,
1570 retlen, buf);
1571 if (ret)
1572 return ret;
1573 ofs += local_len;
1574 buf += local_len;
1575 len -= local_len;
1576
1577 if (ofs >> cfi->chipshift) {
1578 chipnum ++;
1579 ofs = 0;
1580 if (chipnum == cfi->numchips)
1581 return 0;
1582 }
1583 }
1584 1675
1585 while(len) { 1676 do {
1586 /* We must not cross write block boundaries */ 1677 /* We must not cross write block boundaries */
1587 int size = wbufsize - (ofs & (wbufsize-1)); 1678 int size = wbufsize - (ofs & (wbufsize-1));
1588 1679
1589 if (size > len) 1680 if (size > len)
1590 size = len; 1681 size = len;
1591 ret = do_write_buffer(map, &cfi->chips[chipnum], 1682 ret = do_write_buffer(map, &cfi->chips[chipnum],
1592 ofs, buf, size); 1683 ofs, &vecs, &vec_seek, size);
1593 if (ret) 1684 if (ret)
1594 return ret; 1685 return ret;
1595 1686
1596 ofs += size; 1687 ofs += size;
1597 buf += size;
1598 (*retlen) += size; 1688 (*retlen) += size;
1599 len -= size; 1689 len -= size;
1600 1690
1601 if (ofs >> cfi->chipshift) { 1691 if (ofs >> cfi->chipshift) {
1602 chipnum ++; 1692 chipnum ++;
1603 ofs = 0; 1693 ofs = 0;
1604 if (chipnum == cfi->numchips) 1694 if (chipnum == cfi->numchips)
1605 return 0; 1695 return 0;
1606 } 1696 }
1607 } 1697 } while (len);
1698
1608 return 0; 1699 return 0;
1609} 1700}
1610 1701
1702static int cfi_intelext_write_buffers (struct mtd_info *mtd, loff_t to,
1703 size_t len, size_t *retlen, const u_char *buf)
1704{
1705 struct kvec vec;
1706
1707 vec.iov_base = (void *) buf;
1708 vec.iov_len = len;
1709
1710 return cfi_intelext_writev(mtd, &vec, 1, to, retlen);
1711}
1712
1611static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip, 1713static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
1612 unsigned long adr, int len, void *thunk) 1714 unsigned long adr, int len, void *thunk)
1613{ 1715{
@@ -1673,23 +1775,17 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
1673 status = map_read(map, adr); 1775 status = map_read(map, adr);
1674 if (map_word_andequal(map, status, status_OK, status_OK)) 1776 if (map_word_andequal(map, status, status_OK, status_OK))
1675 break; 1777 break;
1676 1778
1677 /* OK Still waiting */ 1779 /* OK Still waiting */
1678 if (time_after(jiffies, timeo)) { 1780 if (time_after(jiffies, timeo)) {
1679 map_word Xstatus;
1680 map_write(map, CMD(0x70), adr); 1781 map_write(map, CMD(0x70), adr);
1681 chip->state = FL_STATUS; 1782 chip->state = FL_STATUS;
1682 Xstatus = map_read(map, adr);
1683 /* Clear status bits */
1684 map_write(map, CMD(0x50), adr);
1685 map_write(map, CMD(0x70), adr);
1686 xip_enable(map, chip, adr); 1783 xip_enable(map, chip, adr);
1687 printk(KERN_ERR "waiting for erase at %08lx to complete timed out. status = %lx, Xstatus = %lx.\n", 1784 printk(KERN_ERR "%s: block erase error: (status timeout)\n", map->name);
1688 adr, status.x[0], Xstatus.x[0]);
1689 ret = -EIO; 1785 ret = -EIO;
1690 goto out; 1786 goto out;
1691 } 1787 }
1692 1788
1693 /* Latency issues. Drop the lock, wait a while and retry */ 1789 /* Latency issues. Drop the lock, wait a while and retry */
1694 UDELAY(map, chip, adr, 1000000/HZ); 1790 UDELAY(map, chip, adr, 1000000/HZ);
1695 } 1791 }
@@ -1699,43 +1795,40 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
1699 chip->state = FL_STATUS; 1795 chip->state = FL_STATUS;
1700 status = map_read(map, adr); 1796 status = map_read(map, adr);
1701 1797
1702 /* check for lock bit */ 1798 /* check for errors */
1703 if (map_word_bitsset(map, status, CMD(0x3a))) { 1799 if (map_word_bitsset(map, status, CMD(0x3a))) {
1704 unsigned long chipstatus; 1800 unsigned long chipstatus = MERGESTATUS(status);
1705 1801
1706 /* Reset the error bits */ 1802 /* Reset the error bits */
1707 map_write(map, CMD(0x50), adr); 1803 map_write(map, CMD(0x50), adr);
1708 map_write(map, CMD(0x70), adr); 1804 map_write(map, CMD(0x70), adr);
1709 xip_enable(map, chip, adr); 1805 xip_enable(map, chip, adr);
1710 1806
1711 chipstatus = MERGESTATUS(status);
1712
1713 if ((chipstatus & 0x30) == 0x30) { 1807 if ((chipstatus & 0x30) == 0x30) {
1714 printk(KERN_NOTICE "Chip reports improper command sequence: status 0x%lx\n", chipstatus); 1808 printk(KERN_ERR "%s: block erase error: (bad command sequence, status 0x%lx)\n", map->name, chipstatus);
1715 ret = -EIO; 1809 ret = -EINVAL;
1716 } else if (chipstatus & 0x02) { 1810 } else if (chipstatus & 0x02) {
1717 /* Protection bit set */ 1811 /* Protection bit set */
1718 ret = -EROFS; 1812 ret = -EROFS;
1719 } else if (chipstatus & 0x8) { 1813 } else if (chipstatus & 0x8) {
1720 /* Voltage */ 1814 /* Voltage */
1721 printk(KERN_WARNING "Chip reports voltage low on erase: status 0x%lx\n", chipstatus); 1815 printk(KERN_ERR "%s: block erase error: (bad VPP)\n", map->name);
1722 ret = -EIO; 1816 ret = -EIO;
1723 } else if (chipstatus & 0x20) { 1817 } else if (chipstatus & 0x20 && retries--) {
1724 if (retries--) { 1818 printk(KERN_DEBUG "block erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus);
1725 printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus); 1819 timeo = jiffies + HZ;
1726 timeo = jiffies + HZ; 1820 put_chip(map, chip, adr);
1727 put_chip(map, chip, adr); 1821 spin_unlock(chip->mutex);
1728 spin_unlock(chip->mutex); 1822 goto retry;
1729 goto retry; 1823 } else {
1730 } 1824 printk(KERN_ERR "%s: block erase failed at 0x%08lx (status 0x%lx)\n", map->name, adr, chipstatus);
1731 printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx\n", adr, chipstatus);
1732 ret = -EIO; 1825 ret = -EIO;
1733 } 1826 }
1734 } else { 1827
1735 xip_enable(map, chip, adr); 1828 goto out;
1736 ret = 0;
1737 } 1829 }
1738 1830
1831 xip_enable(map, chip, adr);
1739 out: put_chip(map, chip, adr); 1832 out: put_chip(map, chip, adr);
1740 spin_unlock(chip->mutex); 1833 spin_unlock(chip->mutex);
1741 return ret; 1834 return ret;
@@ -1755,7 +1848,7 @@ int cfi_intelext_erase_varsize(struct mtd_info *mtd, struct erase_info *instr)
1755 1848
1756 instr->state = MTD_ERASE_DONE; 1849 instr->state = MTD_ERASE_DONE;
1757 mtd_erase_callback(instr); 1850 mtd_erase_callback(instr);
1758 1851
1759 return 0; 1852 return 0;
1760} 1853}
1761 1854
@@ -1776,7 +1869,7 @@ static void cfi_intelext_sync (struct mtd_info *mtd)
1776 if (!ret) { 1869 if (!ret) {
1777 chip->oldstate = chip->state; 1870 chip->oldstate = chip->state;
1778 chip->state = FL_SYNCING; 1871 chip->state = FL_SYNCING;
1779 /* No need to wake_up() on this state change - 1872 /* No need to wake_up() on this state change -
1780 * as the whole point is that nobody can do anything 1873 * as the whole point is that nobody can do anything
1781 * with the chip now anyway. 1874 * with the chip now anyway.
1782 */ 1875 */
@@ -1790,7 +1883,7 @@ static void cfi_intelext_sync (struct mtd_info *mtd)
1790 chip = &cfi->chips[i]; 1883 chip = &cfi->chips[i];
1791 1884
1792 spin_lock(chip->mutex); 1885 spin_lock(chip->mutex);
1793 1886
1794 if (chip->state == FL_SYNCING) { 1887 if (chip->state == FL_SYNCING) {
1795 chip->state = chip->oldstate; 1888 chip->state = chip->oldstate;
1796 chip->oldstate = FL_READY; 1889 chip->oldstate = FL_READY;
@@ -1847,7 +1940,7 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
1847 1940
1848 ENABLE_VPP(map); 1941 ENABLE_VPP(map);
1849 xip_disable(map, chip, adr); 1942 xip_disable(map, chip, adr);
1850 1943
1851 map_write(map, CMD(0x60), adr); 1944 map_write(map, CMD(0x60), adr);
1852 if (thunk == DO_XXLOCK_ONEBLOCK_LOCK) { 1945 if (thunk == DO_XXLOCK_ONEBLOCK_LOCK) {
1853 map_write(map, CMD(0x01), adr); 1946 map_write(map, CMD(0x01), adr);
@@ -1875,25 +1968,22 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
1875 status = map_read(map, adr); 1968 status = map_read(map, adr);
1876 if (map_word_andequal(map, status, status_OK, status_OK)) 1969 if (map_word_andequal(map, status, status_OK, status_OK))
1877 break; 1970 break;
1878 1971
1879 /* OK Still waiting */ 1972 /* OK Still waiting */
1880 if (time_after(jiffies, timeo)) { 1973 if (time_after(jiffies, timeo)) {
1881 map_word Xstatus;
1882 map_write(map, CMD(0x70), adr); 1974 map_write(map, CMD(0x70), adr);
1883 chip->state = FL_STATUS; 1975 chip->state = FL_STATUS;
1884 Xstatus = map_read(map, adr);
1885 xip_enable(map, chip, adr); 1976 xip_enable(map, chip, adr);
1886 printk(KERN_ERR "waiting for unlock to complete timed out. status = %lx, Xstatus = %lx.\n", 1977 printk(KERN_ERR "%s: block unlock error: (status timeout)\n", map->name);
1887 status.x[0], Xstatus.x[0]);
1888 put_chip(map, chip, adr); 1978 put_chip(map, chip, adr);
1889 spin_unlock(chip->mutex); 1979 spin_unlock(chip->mutex);
1890 return -EIO; 1980 return -EIO;
1891 } 1981 }
1892 1982
1893 /* Latency issues. Drop the lock, wait a while and retry */ 1983 /* Latency issues. Drop the lock, wait a while and retry */
1894 UDELAY(map, chip, adr, 1); 1984 UDELAY(map, chip, adr, 1);
1895 } 1985 }
1896 1986
1897 /* Done and happy. */ 1987 /* Done and happy. */
1898 chip->state = FL_STATUS; 1988 chip->state = FL_STATUS;
1899 xip_enable(map, chip, adr); 1989 xip_enable(map, chip, adr);
@@ -1913,9 +2003,9 @@ static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
1913 ofs, len, 0); 2003 ofs, len, 0);
1914#endif 2004#endif
1915 2005
1916 ret = cfi_varsize_frob(mtd, do_xxlock_oneblock, 2006 ret = cfi_varsize_frob(mtd, do_xxlock_oneblock,
1917 ofs, len, DO_XXLOCK_ONEBLOCK_LOCK); 2007 ofs, len, DO_XXLOCK_ONEBLOCK_LOCK);
1918 2008
1919#ifdef DEBUG_LOCK_BITS 2009#ifdef DEBUG_LOCK_BITS
1920 printk(KERN_DEBUG "%s: lock status after, ret=%d\n", 2010 printk(KERN_DEBUG "%s: lock status after, ret=%d\n",
1921 __FUNCTION__, ret); 2011 __FUNCTION__, ret);
@@ -1939,20 +2029,20 @@ static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1939 2029
1940 ret = cfi_varsize_frob(mtd, do_xxlock_oneblock, 2030 ret = cfi_varsize_frob(mtd, do_xxlock_oneblock,
1941 ofs, len, DO_XXLOCK_ONEBLOCK_UNLOCK); 2031 ofs, len, DO_XXLOCK_ONEBLOCK_UNLOCK);
1942 2032
1943#ifdef DEBUG_LOCK_BITS 2033#ifdef DEBUG_LOCK_BITS
1944 printk(KERN_DEBUG "%s: lock status after, ret=%d\n", 2034 printk(KERN_DEBUG "%s: lock status after, ret=%d\n",
1945 __FUNCTION__, ret); 2035 __FUNCTION__, ret);
1946 cfi_varsize_frob(mtd, do_printlockstatus_oneblock, 2036 cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
1947 ofs, len, 0); 2037 ofs, len, 0);
1948#endif 2038#endif
1949 2039
1950 return ret; 2040 return ret;
1951} 2041}
1952 2042
1953#ifdef CONFIG_MTD_OTP 2043#ifdef CONFIG_MTD_OTP
1954 2044
1955typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip, 2045typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip,
1956 u_long data_offset, u_char *buf, u_int size, 2046 u_long data_offset, u_char *buf, u_int size,
1957 u_long prot_offset, u_int groupno, u_int groupsize); 2047 u_long prot_offset, u_int groupno, u_int groupsize);
1958 2048
@@ -2003,7 +2093,7 @@ do_otp_write(struct map_info *map, struct flchip *chip, u_long offset,
2003 2093
2004 datum = map_word_load_partial(map, datum, buf, gap, n); 2094 datum = map_word_load_partial(map, datum, buf, gap, n);
2005 ret = do_write_oneword(map, chip, bus_ofs, datum, FL_OTP_WRITE); 2095 ret = do_write_oneword(map, chip, bus_ofs, datum, FL_OTP_WRITE);
2006 if (ret) 2096 if (ret)
2007 return ret; 2097 return ret;
2008 2098
2009 offset += n; 2099 offset += n;
@@ -2196,7 +2286,7 @@ static int cfi_intelext_lock_user_prot_reg(struct mtd_info *mtd,
2196 NULL, do_otp_lock, 1); 2286 NULL, do_otp_lock, 1);
2197} 2287}
2198 2288
2199static int cfi_intelext_get_fact_prot_info(struct mtd_info *mtd, 2289static int cfi_intelext_get_fact_prot_info(struct mtd_info *mtd,
2200 struct otp_info *buf, size_t len) 2290 struct otp_info *buf, size_t len)
2201{ 2291{
2202 size_t retlen; 2292 size_t retlen;
@@ -2239,7 +2329,7 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
2239 if (chip->oldstate == FL_READY) { 2329 if (chip->oldstate == FL_READY) {
2240 chip->oldstate = chip->state; 2330 chip->oldstate = chip->state;
2241 chip->state = FL_PM_SUSPENDED; 2331 chip->state = FL_PM_SUSPENDED;
2242 /* No need to wake_up() on this state change - 2332 /* No need to wake_up() on this state change -
2243 * as the whole point is that nobody can do anything 2333 * as the whole point is that nobody can do anything
2244 * with the chip now anyway. 2334 * with the chip now anyway.
2245 */ 2335 */
@@ -2267,9 +2357,9 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
2267 if (ret) { 2357 if (ret) {
2268 for (i--; i >=0; i--) { 2358 for (i--; i >=0; i--) {
2269 chip = &cfi->chips[i]; 2359 chip = &cfi->chips[i];
2270 2360
2271 spin_lock(chip->mutex); 2361 spin_lock(chip->mutex);
2272 2362
2273 if (chip->state == FL_PM_SUSPENDED) { 2363 if (chip->state == FL_PM_SUSPENDED) {
2274 /* No need to force it into a known state here, 2364 /* No need to force it into a known state here,
2275 because we're returning failure, and it didn't 2365 because we're returning failure, and it didn't
@@ -2280,8 +2370,8 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
2280 } 2370 }
2281 spin_unlock(chip->mutex); 2371 spin_unlock(chip->mutex);
2282 } 2372 }
2283 } 2373 }
2284 2374
2285 return ret; 2375 return ret;
2286} 2376}
2287 2377
@@ -2293,11 +2383,11 @@ static void cfi_intelext_resume(struct mtd_info *mtd)
2293 struct flchip *chip; 2383 struct flchip *chip;
2294 2384
2295 for (i=0; i<cfi->numchips; i++) { 2385 for (i=0; i<cfi->numchips; i++) {
2296 2386
2297 chip = &cfi->chips[i]; 2387 chip = &cfi->chips[i];
2298 2388
2299 spin_lock(chip->mutex); 2389 spin_lock(chip->mutex);
2300 2390
2301 /* Go to known state. Chip may have been power cycled */ 2391 /* Go to known state. Chip may have been power cycled */
2302 if (chip->state == FL_PM_SUSPENDED) { 2392 if (chip->state == FL_PM_SUSPENDED) {
2303 map_write(map, CMD(0xFF), cfi->chips[i].start); 2393 map_write(map, CMD(0xFF), cfi->chips[i].start);
@@ -2319,7 +2409,7 @@ static int cfi_intelext_reset(struct mtd_info *mtd)
2319 struct flchip *chip = &cfi->chips[i]; 2409 struct flchip *chip = &cfi->chips[i];
2320 2410
2321 /* force the completion of any ongoing operation 2411 /* force the completion of any ongoing operation
2322 and switch to array mode so any bootloader in 2412 and switch to array mode so any bootloader in
2323 flash is accessible for soft reboot. */ 2413 flash is accessible for soft reboot. */
2324 spin_lock(chip->mutex); 2414 spin_lock(chip->mutex);
2325 ret = get_chip(map, chip, chip->start, FL_SYNCING); 2415 ret = get_chip(map, chip, chip->start, FL_SYNCING);
@@ -2356,20 +2446,23 @@ static void cfi_intelext_destroy(struct mtd_info *mtd)
2356 kfree(mtd->eraseregions); 2446 kfree(mtd->eraseregions);
2357} 2447}
2358 2448
2359static char im_name_1[]="cfi_cmdset_0001"; 2449static char im_name_0001[] = "cfi_cmdset_0001";
2360static char im_name_3[]="cfi_cmdset_0003"; 2450static char im_name_0003[] = "cfi_cmdset_0003";
2451static char im_name_0200[] = "cfi_cmdset_0200";
2361 2452
2362static int __init cfi_intelext_init(void) 2453static int __init cfi_intelext_init(void)
2363{ 2454{
2364 inter_module_register(im_name_1, THIS_MODULE, &cfi_cmdset_0001); 2455 inter_module_register(im_name_0001, THIS_MODULE, &cfi_cmdset_0001);
2365 inter_module_register(im_name_3, THIS_MODULE, &cfi_cmdset_0001); 2456 inter_module_register(im_name_0003, THIS_MODULE, &cfi_cmdset_0001);
2457 inter_module_register(im_name_0200, THIS_MODULE, &cfi_cmdset_0001);
2366 return 0; 2458 return 0;
2367} 2459}
2368 2460
2369static void __exit cfi_intelext_exit(void) 2461static void __exit cfi_intelext_exit(void)
2370{ 2462{
2371 inter_module_unregister(im_name_1); 2463 inter_module_unregister(im_name_0001);
2372 inter_module_unregister(im_name_3); 2464 inter_module_unregister(im_name_0003);
2465 inter_module_unregister(im_name_0200);
2373} 2466}
2374 2467
2375module_init(cfi_intelext_init); 2468module_init(cfi_intelext_init);
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 8505f118f2db..aed10bd5c3c3 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -10,14 +10,14 @@
10 * 10 *
11 * 4_by_16 work by Carolyn J. Smith 11 * 4_by_16 work by Carolyn J. Smith
12 * 12 *
13 * XIP support hooks by Vitaly Wool (based on code for Intel flash 13 * XIP support hooks by Vitaly Wool (based on code for Intel flash
14 * by Nicolas Pitre) 14 * by Nicolas Pitre)
15 * 15 *
16 * Occasionally maintained by Thayne Harbaugh tharbaugh at lnxi dot com 16 * Occasionally maintained by Thayne Harbaugh tharbaugh at lnxi dot com
17 * 17 *
18 * This code is GPL 18 * This code is GPL
19 * 19 *
20 * $Id: cfi_cmdset_0002.c,v 1.118 2005/07/04 22:34:29 gleixner Exp $ 20 * $Id: cfi_cmdset_0002.c,v 1.122 2005/11/07 11:14:22 gleixner Exp $
21 * 21 *
22 */ 22 */
23 23
@@ -93,7 +93,7 @@ static void cfi_tell_features(struct cfi_pri_amdstd *extp)
93 }; 93 };
94 94
95 printk(" Silicon revision: %d\n", extp->SiliconRevision >> 1); 95 printk(" Silicon revision: %d\n", extp->SiliconRevision >> 1);
96 printk(" Address sensitive unlock: %s\n", 96 printk(" Address sensitive unlock: %s\n",
97 (extp->SiliconRevision & 1) ? "Not required" : "Required"); 97 (extp->SiliconRevision & 1) ? "Not required" : "Required");
98 98
99 if (extp->EraseSuspend < ARRAY_SIZE(erase_suspend)) 99 if (extp->EraseSuspend < ARRAY_SIZE(erase_suspend))
@@ -118,9 +118,9 @@ static void cfi_tell_features(struct cfi_pri_amdstd *extp)
118 else 118 else
119 printk(" Page mode: %d word page\n", extp->PageMode << 2); 119 printk(" Page mode: %d word page\n", extp->PageMode << 2);
120 120
121 printk(" Vpp Supply Minimum Program/Erase Voltage: %d.%d V\n", 121 printk(" Vpp Supply Minimum Program/Erase Voltage: %d.%d V\n",
122 extp->VppMin >> 4, extp->VppMin & 0xf); 122 extp->VppMin >> 4, extp->VppMin & 0xf);
123 printk(" Vpp Supply Maximum Program/Erase Voltage: %d.%d V\n", 123 printk(" Vpp Supply Maximum Program/Erase Voltage: %d.%d V\n",
124 extp->VppMax >> 4, extp->VppMax & 0xf); 124 extp->VppMax >> 4, extp->VppMax & 0xf);
125 125
126 if (extp->TopBottom < ARRAY_SIZE(top_bottom)) 126 if (extp->TopBottom < ARRAY_SIZE(top_bottom))
@@ -177,7 +177,7 @@ static void fixup_use_erase_chip(struct mtd_info *mtd, void *param)
177 ((cfi->cfiq->EraseRegionInfo[0] & 0xffff) == 0)) { 177 ((cfi->cfiq->EraseRegionInfo[0] & 0xffff) == 0)) {
178 mtd->erase = cfi_amdstd_erase_chip; 178 mtd->erase = cfi_amdstd_erase_chip;
179 } 179 }
180 180
181} 181}
182 182
183static struct cfi_fixup cfi_fixup_table[] = { 183static struct cfi_fixup cfi_fixup_table[] = {
@@ -239,7 +239,7 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
239 239
240 if (cfi->cfi_mode==CFI_MODE_CFI){ 240 if (cfi->cfi_mode==CFI_MODE_CFI){
241 unsigned char bootloc; 241 unsigned char bootloc;
242 /* 242 /*
243 * It's a real CFI chip, not one for which the probe 243 * It's a real CFI chip, not one for which the probe
244 * routine faked a CFI structure. So we read the feature 244 * routine faked a CFI structure. So we read the feature
245 * table from it. 245 * table from it.
@@ -253,8 +253,18 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
253 return NULL; 253 return NULL;
254 } 254 }
255 255
256 if (extp->MajorVersion != '1' ||
257 (extp->MinorVersion < '0' || extp->MinorVersion > '4')) {
258 printk(KERN_ERR " Unknown Amd/Fujitsu Extended Query "
259 "version %c.%c.\n", extp->MajorVersion,
260 extp->MinorVersion);
261 kfree(extp);
262 kfree(mtd);
263 return NULL;
264 }
265
256 /* Install our own private info structure */ 266 /* Install our own private info structure */
257 cfi->cmdset_priv = extp; 267 cfi->cmdset_priv = extp;
258 268
259 /* Apply cfi device specific fixups */ 269 /* Apply cfi device specific fixups */
260 cfi_fixup(mtd, cfi_fixup_table); 270 cfi_fixup(mtd, cfi_fixup_table);
@@ -262,7 +272,7 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
262#ifdef DEBUG_CFI_FEATURES 272#ifdef DEBUG_CFI_FEATURES
263 /* Tell the user about it in lots of lovely detail */ 273 /* Tell the user about it in lots of lovely detail */
264 cfi_tell_features(extp); 274 cfi_tell_features(extp);
265#endif 275#endif
266 276
267 bootloc = extp->TopBottom; 277 bootloc = extp->TopBottom;
268 if ((bootloc != 2) && (bootloc != 3)) { 278 if ((bootloc != 2) && (bootloc != 3)) {
@@ -273,11 +283,11 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
273 283
274 if (bootloc == 3 && cfi->cfiq->NumEraseRegions > 1) { 284 if (bootloc == 3 && cfi->cfiq->NumEraseRegions > 1) {
275 printk(KERN_WARNING "%s: Swapping erase regions for broken CFI table.\n", map->name); 285 printk(KERN_WARNING "%s: Swapping erase regions for broken CFI table.\n", map->name);
276 286
277 for (i=0; i<cfi->cfiq->NumEraseRegions / 2; i++) { 287 for (i=0; i<cfi->cfiq->NumEraseRegions / 2; i++) {
278 int j = (cfi->cfiq->NumEraseRegions-1)-i; 288 int j = (cfi->cfiq->NumEraseRegions-1)-i;
279 __u32 swap; 289 __u32 swap;
280 290
281 swap = cfi->cfiq->EraseRegionInfo[i]; 291 swap = cfi->cfiq->EraseRegionInfo[i];
282 cfi->cfiq->EraseRegionInfo[i] = cfi->cfiq->EraseRegionInfo[j]; 292 cfi->cfiq->EraseRegionInfo[i] = cfi->cfiq->EraseRegionInfo[j];
283 cfi->cfiq->EraseRegionInfo[j] = swap; 293 cfi->cfiq->EraseRegionInfo[j] = swap;
@@ -288,11 +298,11 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
288 cfi->addr_unlock2 = 0x2aa; 298 cfi->addr_unlock2 = 0x2aa;
289 /* Modify the unlock address if we are in compatibility mode */ 299 /* Modify the unlock address if we are in compatibility mode */
290 if ( /* x16 in x8 mode */ 300 if ( /* x16 in x8 mode */
291 ((cfi->device_type == CFI_DEVICETYPE_X8) && 301 ((cfi->device_type == CFI_DEVICETYPE_X8) &&
292 (cfi->cfiq->InterfaceDesc == 2)) || 302 (cfi->cfiq->InterfaceDesc == 2)) ||
293 /* x32 in x16 mode */ 303 /* x32 in x16 mode */
294 ((cfi->device_type == CFI_DEVICETYPE_X16) && 304 ((cfi->device_type == CFI_DEVICETYPE_X16) &&
295 (cfi->cfiq->InterfaceDesc == 4))) 305 (cfi->cfiq->InterfaceDesc == 4)))
296 { 306 {
297 cfi->addr_unlock1 = 0xaaa; 307 cfi->addr_unlock1 = 0xaaa;
298 cfi->addr_unlock2 = 0x555; 308 cfi->addr_unlock2 = 0x555;
@@ -310,10 +320,10 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
310 cfi->chips[i].word_write_time = 1<<cfi->cfiq->WordWriteTimeoutTyp; 320 cfi->chips[i].word_write_time = 1<<cfi->cfiq->WordWriteTimeoutTyp;
311 cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp; 321 cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp;
312 cfi->chips[i].erase_time = 1<<cfi->cfiq->BlockEraseTimeoutTyp; 322 cfi->chips[i].erase_time = 1<<cfi->cfiq->BlockEraseTimeoutTyp;
313 } 323 }
314 324
315 map->fldrv = &cfi_amdstd_chipdrv; 325 map->fldrv = &cfi_amdstd_chipdrv;
316 326
317 return cfi_amdstd_setup(mtd); 327 return cfi_amdstd_setup(mtd);
318} 328}
319 329
@@ -326,24 +336,24 @@ static struct mtd_info *cfi_amdstd_setup(struct mtd_info *mtd)
326 unsigned long offset = 0; 336 unsigned long offset = 0;
327 int i,j; 337 int i,j;
328 338
329 printk(KERN_NOTICE "number of %s chips: %d\n", 339 printk(KERN_NOTICE "number of %s chips: %d\n",
330 (cfi->cfi_mode == CFI_MODE_CFI)?"CFI":"JEDEC",cfi->numchips); 340 (cfi->cfi_mode == CFI_MODE_CFI)?"CFI":"JEDEC",cfi->numchips);
331 /* Select the correct geometry setup */ 341 /* Select the correct geometry setup */
332 mtd->size = devsize * cfi->numchips; 342 mtd->size = devsize * cfi->numchips;
333 343
334 mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips; 344 mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips;
335 mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) 345 mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info)
336 * mtd->numeraseregions, GFP_KERNEL); 346 * mtd->numeraseregions, GFP_KERNEL);
337 if (!mtd->eraseregions) { 347 if (!mtd->eraseregions) {
338 printk(KERN_WARNING "Failed to allocate memory for MTD erase region info\n"); 348 printk(KERN_WARNING "Failed to allocate memory for MTD erase region info\n");
339 goto setup_err; 349 goto setup_err;
340 } 350 }
341 351
342 for (i=0; i<cfi->cfiq->NumEraseRegions; i++) { 352 for (i=0; i<cfi->cfiq->NumEraseRegions; i++) {
343 unsigned long ernum, ersize; 353 unsigned long ernum, ersize;
344 ersize = ((cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff) * cfi->interleave; 354 ersize = ((cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff) * cfi->interleave;
345 ernum = (cfi->cfiq->EraseRegionInfo[i] & 0xffff) + 1; 355 ernum = (cfi->cfiq->EraseRegionInfo[i] & 0xffff) + 1;
346 356
347 if (mtd->erasesize < ersize) { 357 if (mtd->erasesize < ersize) {
348 mtd->erasesize = ersize; 358 mtd->erasesize = ersize;
349 } 359 }
@@ -378,8 +388,7 @@ static struct mtd_info *cfi_amdstd_setup(struct mtd_info *mtd)
378 388
379 setup_err: 389 setup_err:
380 if(mtd) { 390 if(mtd) {
381 if(mtd->eraseregions) 391 kfree(mtd->eraseregions);
382 kfree(mtd->eraseregions);
383 kfree(mtd); 392 kfree(mtd);
384 } 393 }
385 kfree(cfi->cmdset_priv); 394 kfree(cfi->cmdset_priv);
@@ -430,7 +439,7 @@ static int __xipram chip_good(struct map_info *map, unsigned long addr, map_word
430 oldd = map_read(map, addr); 439 oldd = map_read(map, addr);
431 curd = map_read(map, addr); 440 curd = map_read(map, addr);
432 441
433 return map_word_equal(map, oldd, curd) && 442 return map_word_equal(map, oldd, curd) &&
434 map_word_equal(map, curd, expected); 443 map_word_equal(map, curd, expected);
435} 444}
436 445
@@ -462,7 +471,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
462 /* Someone else might have been playing with it. */ 471 /* Someone else might have been playing with it. */
463 goto retry; 472 goto retry;
464 } 473 }
465 474
466 case FL_READY: 475 case FL_READY:
467 case FL_CFI_QUERY: 476 case FL_CFI_QUERY:
468 case FL_JEDEC_QUERY: 477 case FL_JEDEC_QUERY:
@@ -505,7 +514,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
505 printk(KERN_ERR "MTD %s(): chip not ready after erase suspend\n", __func__); 514 printk(KERN_ERR "MTD %s(): chip not ready after erase suspend\n", __func__);
506 return -EIO; 515 return -EIO;
507 } 516 }
508 517
509 spin_unlock(chip->mutex); 518 spin_unlock(chip->mutex);
510 cfi_udelay(1); 519 cfi_udelay(1);
511 spin_lock(chip->mutex); 520 spin_lock(chip->mutex);
@@ -608,7 +617,7 @@ static void __xipram xip_enable(struct map_info *map, struct flchip *chip,
608 * When a delay is required for the flash operation to complete, the 617 * When a delay is required for the flash operation to complete, the
609 * xip_udelay() function is polling for both the given timeout and pending 618 * xip_udelay() function is polling for both the given timeout and pending
610 * (but still masked) hardware interrupts. Whenever there is an interrupt 619 * (but still masked) hardware interrupts. Whenever there is an interrupt
611 * pending then the flash erase operation is suspended, array mode restored 620 * pending then the flash erase operation is suspended, array mode restored
612 * and interrupts unmasked. Task scheduling might also happen at that 621 * and interrupts unmasked. Task scheduling might also happen at that
613 * point. The CPU eventually returns from the interrupt or the call to 622 * point. The CPU eventually returns from the interrupt or the call to
614 * schedule() and the suspended flash operation is resumed for the remaining 623 * schedule() and the suspended flash operation is resumed for the remaining
@@ -632,9 +641,9 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
632 ((chip->state == FL_ERASING && (extp->EraseSuspend & 2))) && 641 ((chip->state == FL_ERASING && (extp->EraseSuspend & 2))) &&
633 (cfi_interleave_is_1(cfi) || chip->oldstate == FL_READY)) { 642 (cfi_interleave_is_1(cfi) || chip->oldstate == FL_READY)) {
634 /* 643 /*
635 * Let's suspend the erase operation when supported. 644 * Let's suspend the erase operation when supported.
636 * Note that we currently don't try to suspend 645 * Note that we currently don't try to suspend
637 * interleaved chips if there is already another 646 * interleaved chips if there is already another
638 * operation suspended (imagine what happens 647 * operation suspended (imagine what happens
639 * when one chip was already done with the current 648 * when one chip was already done with the current
640 * operation while another chip suspended it, then 649 * operation while another chip suspended it, then
@@ -770,8 +779,8 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
770 779
771 adr += chip->start; 780 adr += chip->start;
772 781
773 /* Ensure cmd read/writes are aligned. */ 782 /* Ensure cmd read/writes are aligned. */
774 cmd_addr = adr & ~(map_bankwidth(map)-1); 783 cmd_addr = adr & ~(map_bankwidth(map)-1);
775 784
776 spin_lock(chip->mutex); 785 spin_lock(chip->mutex);
777 ret = get_chip(map, chip, cmd_addr, FL_READY); 786 ret = get_chip(map, chip, cmd_addr, FL_READY);
@@ -851,7 +860,7 @@ static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chi
851#endif 860#endif
852 set_current_state(TASK_UNINTERRUPTIBLE); 861 set_current_state(TASK_UNINTERRUPTIBLE);
853 add_wait_queue(&chip->wq, &wait); 862 add_wait_queue(&chip->wq, &wait);
854 863
855 spin_unlock(chip->mutex); 864 spin_unlock(chip->mutex);
856 865
857 schedule(); 866 schedule();
@@ -863,7 +872,7 @@ static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chi
863 timeo = jiffies + HZ; 872 timeo = jiffies + HZ;
864 873
865 goto retry; 874 goto retry;
866 } 875 }
867 876
868 adr += chip->start; 877 adr += chip->start;
869 878
@@ -872,14 +881,14 @@ static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chi
872 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 881 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
873 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); 882 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
874 cfi_send_gen_cmd(0x88, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 883 cfi_send_gen_cmd(0x88, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
875 884
876 map_copy_from(map, buf, adr, len); 885 map_copy_from(map, buf, adr, len);
877 886
878 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 887 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
879 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); 888 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
880 cfi_send_gen_cmd(0x90, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 889 cfi_send_gen_cmd(0x90, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
881 cfi_send_gen_cmd(0x00, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 890 cfi_send_gen_cmd(0x00, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
882 891
883 wake_up(&chip->wq); 892 wake_up(&chip->wq);
884 spin_unlock(chip->mutex); 893 spin_unlock(chip->mutex);
885 894
@@ -988,7 +997,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
988 chip->word_write_time); 997 chip->word_write_time);
989 998
990 /* See comment above for timeout value. */ 999 /* See comment above for timeout value. */
991 timeo = jiffies + uWriteTimeout; 1000 timeo = jiffies + uWriteTimeout;
992 for (;;) { 1001 for (;;) {
993 if (chip->state != FL_WRITING) { 1002 if (chip->state != FL_WRITING) {
994 /* Someone's suspended the write. Sleep */ 1003 /* Someone's suspended the write. Sleep */
@@ -1004,16 +1013,16 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1004 continue; 1013 continue;
1005 } 1014 }
1006 1015
1007 if (chip_ready(map, adr)) 1016 if (time_after(jiffies, timeo) && !chip_ready(map, adr)){
1008 break;
1009
1010 if (time_after(jiffies, timeo)) {
1011 xip_enable(map, chip, adr); 1017 xip_enable(map, chip, adr);
1012 printk(KERN_WARNING "MTD %s(): software timeout\n", __func__); 1018 printk(KERN_WARNING "MTD %s(): software timeout\n", __func__);
1013 xip_disable(map, chip, adr); 1019 xip_disable(map, chip, adr);
1014 break; 1020 break;
1015 } 1021 }
1016 1022
1023 if (chip_ready(map, adr))
1024 break;
1025
1017 /* Latency issues. Drop the lock, wait a while and retry */ 1026 /* Latency issues. Drop the lock, wait a while and retry */
1018 UDELAY(map, chip, adr, 1); 1027 UDELAY(map, chip, adr, 1);
1019 } 1028 }
@@ -1023,7 +1032,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1023 map_write( map, CMD(0xF0), chip->start ); 1032 map_write( map, CMD(0xF0), chip->start );
1024 /* FIXME - should have reset delay before continuing */ 1033 /* FIXME - should have reset delay before continuing */
1025 1034
1026 if (++retry_cnt <= MAX_WORD_RETRIES) 1035 if (++retry_cnt <= MAX_WORD_RETRIES)
1027 goto retry; 1036 goto retry;
1028 1037
1029 ret = -EIO; 1038 ret = -EIO;
@@ -1091,27 +1100,27 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
1091 1100
1092 /* Number of bytes to copy from buffer */ 1101 /* Number of bytes to copy from buffer */
1093 n = min_t(int, len, map_bankwidth(map)-i); 1102 n = min_t(int, len, map_bankwidth(map)-i);
1094 1103
1095 tmp_buf = map_word_load_partial(map, tmp_buf, buf, i, n); 1104 tmp_buf = map_word_load_partial(map, tmp_buf, buf, i, n);
1096 1105
1097 ret = do_write_oneword(map, &cfi->chips[chipnum], 1106 ret = do_write_oneword(map, &cfi->chips[chipnum],
1098 bus_ofs, tmp_buf); 1107 bus_ofs, tmp_buf);
1099 if (ret) 1108 if (ret)
1100 return ret; 1109 return ret;
1101 1110
1102 ofs += n; 1111 ofs += n;
1103 buf += n; 1112 buf += n;
1104 (*retlen) += n; 1113 (*retlen) += n;
1105 len -= n; 1114 len -= n;
1106 1115
1107 if (ofs >> cfi->chipshift) { 1116 if (ofs >> cfi->chipshift) {
1108 chipnum ++; 1117 chipnum ++;
1109 ofs = 0; 1118 ofs = 0;
1110 if (chipnum == cfi->numchips) 1119 if (chipnum == cfi->numchips)
1111 return 0; 1120 return 0;
1112 } 1121 }
1113 } 1122 }
1114 1123
1115 /* We are now aligned, write as much as possible */ 1124 /* We are now aligned, write as much as possible */
1116 while(len >= map_bankwidth(map)) { 1125 while(len >= map_bankwidth(map)) {
1117 map_word datum; 1126 map_word datum;
@@ -1129,7 +1138,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
1129 len -= map_bankwidth(map); 1138 len -= map_bankwidth(map);
1130 1139
1131 if (ofs >> cfi->chipshift) { 1140 if (ofs >> cfi->chipshift) {
1132 chipnum ++; 1141 chipnum ++;
1133 ofs = 0; 1142 ofs = 0;
1134 if (chipnum == cfi->numchips) 1143 if (chipnum == cfi->numchips)
1135 return 0; 1144 return 0;
@@ -1167,12 +1176,12 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
1167 spin_unlock(cfi->chips[chipnum].mutex); 1176 spin_unlock(cfi->chips[chipnum].mutex);
1168 1177
1169 tmp_buf = map_word_load_partial(map, tmp_buf, buf, 0, len); 1178 tmp_buf = map_word_load_partial(map, tmp_buf, buf, 0, len);
1170 1179
1171 ret = do_write_oneword(map, &cfi->chips[chipnum], 1180 ret = do_write_oneword(map, &cfi->chips[chipnum],
1172 ofs, tmp_buf); 1181 ofs, tmp_buf);
1173 if (ret) 1182 if (ret)
1174 return ret; 1183 return ret;
1175 1184
1176 (*retlen) += len; 1185 (*retlen) += len;
1177 } 1186 }
1178 1187
@@ -1184,7 +1193,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
1184 * FIXME: interleaved mode not tested, and probably not supported! 1193 * FIXME: interleaved mode not tested, and probably not supported!
1185 */ 1194 */
1186static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, 1195static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1187 unsigned long adr, const u_char *buf, 1196 unsigned long adr, const u_char *buf,
1188 int len) 1197 int len)
1189{ 1198{
1190 struct cfi_private *cfi = map->fldrv_priv; 1199 struct cfi_private *cfi = map->fldrv_priv;
@@ -1214,7 +1223,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1214 XIP_INVAL_CACHED_RANGE(map, adr, len); 1223 XIP_INVAL_CACHED_RANGE(map, adr, len);
1215 ENABLE_VPP(map); 1224 ENABLE_VPP(map);
1216 xip_disable(map, chip, cmd_adr); 1225 xip_disable(map, chip, cmd_adr);
1217 1226
1218 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1227 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
1219 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); 1228 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
1220 //cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1229 //cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
@@ -1248,8 +1257,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1248 adr, map_bankwidth(map), 1257 adr, map_bankwidth(map),
1249 chip->word_write_time); 1258 chip->word_write_time);
1250 1259
1251 timeo = jiffies + uWriteTimeout; 1260 timeo = jiffies + uWriteTimeout;
1252 1261
1253 for (;;) { 1262 for (;;) {
1254 if (chip->state != FL_WRITING) { 1263 if (chip->state != FL_WRITING) {
1255 /* Someone's suspended the write. Sleep */ 1264 /* Someone's suspended the write. Sleep */
@@ -1265,13 +1274,13 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1265 continue; 1274 continue;
1266 } 1275 }
1267 1276
1277 if (time_after(jiffies, timeo) && !chip_ready(map, adr))
1278 break;
1279
1268 if (chip_ready(map, adr)) { 1280 if (chip_ready(map, adr)) {
1269 xip_enable(map, chip, adr); 1281 xip_enable(map, chip, adr);
1270 goto op_done; 1282 goto op_done;
1271 } 1283 }
1272
1273 if( time_after(jiffies, timeo))
1274 break;
1275 1284
1276 /* Latency issues. Drop the lock, wait a while and retry */ 1285 /* Latency issues. Drop the lock, wait a while and retry */
1277 UDELAY(map, chip, adr, 1); 1286 UDELAY(map, chip, adr, 1);
@@ -1343,7 +1352,7 @@ static int cfi_amdstd_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
1343 if (size % map_bankwidth(map)) 1352 if (size % map_bankwidth(map))
1344 size -= size % map_bankwidth(map); 1353 size -= size % map_bankwidth(map);
1345 1354
1346 ret = do_write_buffer(map, &cfi->chips[chipnum], 1355 ret = do_write_buffer(map, &cfi->chips[chipnum],
1347 ofs, buf, size); 1356 ofs, buf, size);
1348 if (ret) 1357 if (ret)
1349 return ret; 1358 return ret;
@@ -1354,7 +1363,7 @@ static int cfi_amdstd_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
1354 len -= size; 1363 len -= size;
1355 1364
1356 if (ofs >> cfi->chipshift) { 1365 if (ofs >> cfi->chipshift) {
1357 chipnum ++; 1366 chipnum ++;
1358 ofs = 0; 1367 ofs = 0;
1359 if (chipnum == cfi->numchips) 1368 if (chipnum == cfi->numchips)
1360 return 0; 1369 return 0;
@@ -1571,7 +1580,7 @@ int cfi_amdstd_erase_varsize(struct mtd_info *mtd, struct erase_info *instr)
1571 1580
1572 instr->state = MTD_ERASE_DONE; 1581 instr->state = MTD_ERASE_DONE;
1573 mtd_erase_callback(instr); 1582 mtd_erase_callback(instr);
1574 1583
1575 return 0; 1584 return 0;
1576} 1585}
1577 1586
@@ -1594,7 +1603,7 @@ static int cfi_amdstd_erase_chip(struct mtd_info *mtd, struct erase_info *instr)
1594 1603
1595 instr->state = MTD_ERASE_DONE; 1604 instr->state = MTD_ERASE_DONE;
1596 mtd_erase_callback(instr); 1605 mtd_erase_callback(instr);
1597 1606
1598 return 0; 1607 return 0;
1599} 1608}
1600 1609
@@ -1621,7 +1630,7 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
1621 case FL_JEDEC_QUERY: 1630 case FL_JEDEC_QUERY:
1622 chip->oldstate = chip->state; 1631 chip->oldstate = chip->state;
1623 chip->state = FL_SYNCING; 1632 chip->state = FL_SYNCING;
1624 /* No need to wake_up() on this state change - 1633 /* No need to wake_up() on this state change -
1625 * as the whole point is that nobody can do anything 1634 * as the whole point is that nobody can do anything
1626 * with the chip now anyway. 1635 * with the chip now anyway.
1627 */ 1636 */
@@ -1632,13 +1641,13 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
1632 default: 1641 default:
1633 /* Not an idle state */ 1642 /* Not an idle state */
1634 add_wait_queue(&chip->wq, &wait); 1643 add_wait_queue(&chip->wq, &wait);
1635 1644
1636 spin_unlock(chip->mutex); 1645 spin_unlock(chip->mutex);
1637 1646
1638 schedule(); 1647 schedule();
1639 1648
1640 remove_wait_queue(&chip->wq, &wait); 1649 remove_wait_queue(&chip->wq, &wait);
1641 1650
1642 goto retry; 1651 goto retry;
1643 } 1652 }
1644 } 1653 }
@@ -1649,7 +1658,7 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
1649 chip = &cfi->chips[i]; 1658 chip = &cfi->chips[i];
1650 1659
1651 spin_lock(chip->mutex); 1660 spin_lock(chip->mutex);
1652 1661
1653 if (chip->state == FL_SYNCING) { 1662 if (chip->state == FL_SYNCING) {
1654 chip->state = chip->oldstate; 1663 chip->state = chip->oldstate;
1655 wake_up(&chip->wq); 1664 wake_up(&chip->wq);
@@ -1679,7 +1688,7 @@ static int cfi_amdstd_suspend(struct mtd_info *mtd)
1679 case FL_JEDEC_QUERY: 1688 case FL_JEDEC_QUERY:
1680 chip->oldstate = chip->state; 1689 chip->oldstate = chip->state;
1681 chip->state = FL_PM_SUSPENDED; 1690 chip->state = FL_PM_SUSPENDED;
1682 /* No need to wake_up() on this state change - 1691 /* No need to wake_up() on this state change -
1683 * as the whole point is that nobody can do anything 1692 * as the whole point is that nobody can do anything
1684 * with the chip now anyway. 1693 * with the chip now anyway.
1685 */ 1694 */
@@ -1700,7 +1709,7 @@ static int cfi_amdstd_suspend(struct mtd_info *mtd)
1700 chip = &cfi->chips[i]; 1709 chip = &cfi->chips[i];
1701 1710
1702 spin_lock(chip->mutex); 1711 spin_lock(chip->mutex);
1703 1712
1704 if (chip->state == FL_PM_SUSPENDED) { 1713 if (chip->state == FL_PM_SUSPENDED) {
1705 chip->state = chip->oldstate; 1714 chip->state = chip->oldstate;
1706 wake_up(&chip->wq); 1715 wake_up(&chip->wq);
@@ -1708,7 +1717,7 @@ static int cfi_amdstd_suspend(struct mtd_info *mtd)
1708 spin_unlock(chip->mutex); 1717 spin_unlock(chip->mutex);
1709 } 1718 }
1710 } 1719 }
1711 1720
1712 return ret; 1721 return ret;
1713} 1722}
1714 1723
@@ -1721,11 +1730,11 @@ static void cfi_amdstd_resume(struct mtd_info *mtd)
1721 struct flchip *chip; 1730 struct flchip *chip;
1722 1731
1723 for (i=0; i<cfi->numchips; i++) { 1732 for (i=0; i<cfi->numchips; i++) {
1724 1733
1725 chip = &cfi->chips[i]; 1734 chip = &cfi->chips[i];
1726 1735
1727 spin_lock(chip->mutex); 1736 spin_lock(chip->mutex);
1728 1737
1729 if (chip->state == FL_PM_SUSPENDED) { 1738 if (chip->state == FL_PM_SUSPENDED) {
1730 chip->state = FL_READY; 1739 chip->state = FL_READY;
1731 map_write(map, CMD(0xF0), chip->start); 1740 map_write(map, CMD(0xF0), chip->start);
@@ -1742,6 +1751,7 @@ static void cfi_amdstd_destroy(struct mtd_info *mtd)
1742{ 1751{
1743 struct map_info *map = mtd->priv; 1752 struct map_info *map = mtd->priv;
1744 struct cfi_private *cfi = map->fldrv_priv; 1753 struct cfi_private *cfi = map->fldrv_priv;
1754
1745 kfree(cfi->cmdset_priv); 1755 kfree(cfi->cmdset_priv);
1746 kfree(cfi->cfiq); 1756 kfree(cfi->cfiq);
1747 kfree(cfi); 1757 kfree(cfi);
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index c894f8801578..c4a19d2dc67f 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -4,8 +4,8 @@
4 * 4 *
5 * (C) 2000 Red Hat. GPL'd 5 * (C) 2000 Red Hat. GPL'd
6 * 6 *
7 * $Id: cfi_cmdset_0020.c,v 1.19 2005/07/13 15:52:45 dwmw2 Exp $ 7 * $Id: cfi_cmdset_0020.c,v 1.22 2005/11/07 11:14:22 gleixner Exp $
8 * 8 *
9 * 10/10/2000 Nicolas Pitre <nico@cam.org> 9 * 10/10/2000 Nicolas Pitre <nico@cam.org>
10 * - completely revamped method functions so they are aware and 10 * - completely revamped method functions so they are aware and
11 * independent of the flash geometry (buswidth, interleave, etc.) 11 * independent of the flash geometry (buswidth, interleave, etc.)
@@ -81,17 +81,17 @@ static void cfi_tell_features(struct cfi_pri_intelext *extp)
81 printk(" - Page-mode read: %s\n", extp->FeatureSupport&128?"supported":"unsupported"); 81 printk(" - Page-mode read: %s\n", extp->FeatureSupport&128?"supported":"unsupported");
82 printk(" - Synchronous read: %s\n", extp->FeatureSupport&256?"supported":"unsupported"); 82 printk(" - Synchronous read: %s\n", extp->FeatureSupport&256?"supported":"unsupported");
83 for (i=9; i<32; i++) { 83 for (i=9; i<32; i++) {
84 if (extp->FeatureSupport & (1<<i)) 84 if (extp->FeatureSupport & (1<<i))
85 printk(" - Unknown Bit %X: supported\n", i); 85 printk(" - Unknown Bit %X: supported\n", i);
86 } 86 }
87 87
88 printk(" Supported functions after Suspend: %2.2X\n", extp->SuspendCmdSupport); 88 printk(" Supported functions after Suspend: %2.2X\n", extp->SuspendCmdSupport);
89 printk(" - Program after Erase Suspend: %s\n", extp->SuspendCmdSupport&1?"supported":"unsupported"); 89 printk(" - Program after Erase Suspend: %s\n", extp->SuspendCmdSupport&1?"supported":"unsupported");
90 for (i=1; i<8; i++) { 90 for (i=1; i<8; i++) {
91 if (extp->SuspendCmdSupport & (1<<i)) 91 if (extp->SuspendCmdSupport & (1<<i))
92 printk(" - Unknown Bit %X: supported\n", i); 92 printk(" - Unknown Bit %X: supported\n", i);
93 } 93 }
94 94
95 printk(" Block Status Register Mask: %4.4X\n", extp->BlkStatusRegMask); 95 printk(" Block Status Register Mask: %4.4X\n", extp->BlkStatusRegMask);
96 printk(" - Lock Bit Active: %s\n", extp->BlkStatusRegMask&1?"yes":"no"); 96 printk(" - Lock Bit Active: %s\n", extp->BlkStatusRegMask&1?"yes":"no");
97 printk(" - Valid Bit Active: %s\n", extp->BlkStatusRegMask&2?"yes":"no"); 97 printk(" - Valid Bit Active: %s\n", extp->BlkStatusRegMask&2?"yes":"no");
@@ -99,11 +99,11 @@ static void cfi_tell_features(struct cfi_pri_intelext *extp)
99 if (extp->BlkStatusRegMask & (1<<i)) 99 if (extp->BlkStatusRegMask & (1<<i))
100 printk(" - Unknown Bit %X Active: yes\n",i); 100 printk(" - Unknown Bit %X Active: yes\n",i);
101 } 101 }
102 102
103 printk(" Vcc Logic Supply Optimum Program/Erase Voltage: %d.%d V\n", 103 printk(" Vcc Logic Supply Optimum Program/Erase Voltage: %d.%d V\n",
104 extp->VccOptimal >> 8, extp->VccOptimal & 0xf); 104 extp->VccOptimal >> 8, extp->VccOptimal & 0xf);
105 if (extp->VppOptimal) 105 if (extp->VppOptimal)
106 printk(" Vpp Programming Supply Optimum Program/Erase Voltage: %d.%d V\n", 106 printk(" Vpp Programming Supply Optimum Program/Erase Voltage: %d.%d V\n",
107 extp->VppOptimal >> 8, extp->VppOptimal & 0xf); 107 extp->VppOptimal >> 8, extp->VppOptimal & 0xf);
108} 108}
109#endif 109#endif
@@ -121,7 +121,7 @@ struct mtd_info *cfi_cmdset_0020(struct map_info *map, int primary)
121 int i; 121 int i;
122 122
123 if (cfi->cfi_mode) { 123 if (cfi->cfi_mode) {
124 /* 124 /*
125 * It's a real CFI chip, not one for which the probe 125 * It's a real CFI chip, not one for which the probe
126 * routine faked a CFI structure. So we read the feature 126 * routine faked a CFI structure. So we read the feature
127 * table from it. 127 * table from it.
@@ -133,24 +133,33 @@ struct mtd_info *cfi_cmdset_0020(struct map_info *map, int primary)
133 if (!extp) 133 if (!extp)
134 return NULL; 134 return NULL;
135 135
136 if (extp->MajorVersion != '1' ||
137 (extp->MinorVersion < '0' || extp->MinorVersion > '3')) {
138 printk(KERN_ERR " Unknown ST Microelectronics"
139 " Extended Query version %c.%c.\n",
140 extp->MajorVersion, extp->MinorVersion);
141 kfree(extp);
142 return NULL;
143 }
144
136 /* Do some byteswapping if necessary */ 145 /* Do some byteswapping if necessary */
137 extp->FeatureSupport = cfi32_to_cpu(extp->FeatureSupport); 146 extp->FeatureSupport = cfi32_to_cpu(extp->FeatureSupport);
138 extp->BlkStatusRegMask = cfi32_to_cpu(extp->BlkStatusRegMask); 147 extp->BlkStatusRegMask = cfi32_to_cpu(extp->BlkStatusRegMask);
139 148
140#ifdef DEBUG_CFI_FEATURES 149#ifdef DEBUG_CFI_FEATURES
141 /* Tell the user about it in lots of lovely detail */ 150 /* Tell the user about it in lots of lovely detail */
142 cfi_tell_features(extp); 151 cfi_tell_features(extp);
143#endif 152#endif
144 153
145 /* Install our own private info structure */ 154 /* Install our own private info structure */
146 cfi->cmdset_priv = extp; 155 cfi->cmdset_priv = extp;
147 } 156 }
148 157
149 for (i=0; i< cfi->numchips; i++) { 158 for (i=0; i< cfi->numchips; i++) {
150 cfi->chips[i].word_write_time = 128; 159 cfi->chips[i].word_write_time = 128;
151 cfi->chips[i].buffer_write_time = 128; 160 cfi->chips[i].buffer_write_time = 128;
152 cfi->chips[i].erase_time = 1024; 161 cfi->chips[i].erase_time = 1024;
153 } 162 }
154 163
155 return cfi_staa_setup(map); 164 return cfi_staa_setup(map);
156} 165}
@@ -178,15 +187,15 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
178 mtd->size = devsize * cfi->numchips; 187 mtd->size = devsize * cfi->numchips;
179 188
180 mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips; 189 mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips;
181 mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) 190 mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info)
182 * mtd->numeraseregions, GFP_KERNEL); 191 * mtd->numeraseregions, GFP_KERNEL);
183 if (!mtd->eraseregions) { 192 if (!mtd->eraseregions) {
184 printk(KERN_ERR "Failed to allocate memory for MTD erase region info\n"); 193 printk(KERN_ERR "Failed to allocate memory for MTD erase region info\n");
185 kfree(cfi->cmdset_priv); 194 kfree(cfi->cmdset_priv);
186 kfree(mtd); 195 kfree(mtd);
187 return NULL; 196 return NULL;
188 } 197 }
189 198
190 for (i=0; i<cfi->cfiq->NumEraseRegions; i++) { 199 for (i=0; i<cfi->cfiq->NumEraseRegions; i++) {
191 unsigned long ernum, ersize; 200 unsigned long ernum, ersize;
192 ersize = ((cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff) * cfi->interleave; 201 ersize = ((cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff) * cfi->interleave;
@@ -219,7 +228,7 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
219 mtd->eraseregions[i].numblocks); 228 mtd->eraseregions[i].numblocks);
220 } 229 }
221 230
222 /* Also select the correct geometry setup too */ 231 /* Also select the correct geometry setup too */
223 mtd->erase = cfi_staa_erase_varsize; 232 mtd->erase = cfi_staa_erase_varsize;
224 mtd->read = cfi_staa_read; 233 mtd->read = cfi_staa_read;
225 mtd->write = cfi_staa_write_buffers; 234 mtd->write = cfi_staa_write_buffers;
@@ -250,8 +259,8 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
250 259
251 adr += chip->start; 260 adr += chip->start;
252 261
253 /* Ensure cmd read/writes are aligned. */ 262 /* Ensure cmd read/writes are aligned. */
254 cmd_addr = adr & ~(map_bankwidth(map)-1); 263 cmd_addr = adr & ~(map_bankwidth(map)-1);
255 264
256 /* Let's determine this according to the interleave only once */ 265 /* Let's determine this according to the interleave only once */
257 status_OK = CMD(0x80); 266 status_OK = CMD(0x80);
@@ -267,7 +276,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
267 case FL_ERASING: 276 case FL_ERASING:
268 if (!(((struct cfi_pri_intelext *)cfi->cmdset_priv)->FeatureSupport & 2)) 277 if (!(((struct cfi_pri_intelext *)cfi->cmdset_priv)->FeatureSupport & 2))
269 goto sleep; /* We don't support erase suspend */ 278 goto sleep; /* We don't support erase suspend */
270 279
271 map_write (map, CMD(0xb0), cmd_addr); 280 map_write (map, CMD(0xb0), cmd_addr);
272 /* If the flash has finished erasing, then 'erase suspend' 281 /* If the flash has finished erasing, then 'erase suspend'
273 * appears to make some (28F320) flash devices switch to 282 * appears to make some (28F320) flash devices switch to
@@ -282,7 +291,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
282 status = map_read(map, cmd_addr); 291 status = map_read(map, cmd_addr);
283 if (map_word_andequal(map, status, status_OK, status_OK)) 292 if (map_word_andequal(map, status, status_OK, status_OK))
284 break; 293 break;
285 294
286 if (time_after(jiffies, timeo)) { 295 if (time_after(jiffies, timeo)) {
287 /* Urgh */ 296 /* Urgh */
288 map_write(map, CMD(0xd0), cmd_addr); 297 map_write(map, CMD(0xd0), cmd_addr);
@@ -294,17 +303,17 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
294 "suspended: status = 0x%lx\n", status.x[0]); 303 "suspended: status = 0x%lx\n", status.x[0]);
295 return -EIO; 304 return -EIO;
296 } 305 }
297 306
298 spin_unlock_bh(chip->mutex); 307 spin_unlock_bh(chip->mutex);
299 cfi_udelay(1); 308 cfi_udelay(1);
300 spin_lock_bh(chip->mutex); 309 spin_lock_bh(chip->mutex);
301 } 310 }
302 311
303 suspended = 1; 312 suspended = 1;
304 map_write(map, CMD(0xff), cmd_addr); 313 map_write(map, CMD(0xff), cmd_addr);
305 chip->state = FL_READY; 314 chip->state = FL_READY;
306 break; 315 break;
307 316
308#if 0 317#if 0
309 case FL_WRITING: 318 case FL_WRITING:
310 /* Not quite yet */ 319 /* Not quite yet */
@@ -325,7 +334,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
325 chip->state = FL_READY; 334 chip->state = FL_READY;
326 break; 335 break;
327 } 336 }
328 337
329 /* Urgh. Chip not yet ready to talk to us. */ 338 /* Urgh. Chip not yet ready to talk to us. */
330 if (time_after(jiffies, timeo)) { 339 if (time_after(jiffies, timeo)) {
331 spin_unlock_bh(chip->mutex); 340 spin_unlock_bh(chip->mutex);
@@ -355,17 +364,17 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
355 364
356 if (suspended) { 365 if (suspended) {
357 chip->state = chip->oldstate; 366 chip->state = chip->oldstate;
358 /* What if one interleaved chip has finished and the 367 /* What if one interleaved chip has finished and the
359 other hasn't? The old code would leave the finished 368 other hasn't? The old code would leave the finished
360 one in READY mode. That's bad, and caused -EROFS 369 one in READY mode. That's bad, and caused -EROFS
361 errors to be returned from do_erase_oneblock because 370 errors to be returned from do_erase_oneblock because
362 that's the only bit it checked for at the time. 371 that's the only bit it checked for at the time.
363 As the state machine appears to explicitly allow 372 As the state machine appears to explicitly allow
364 sending the 0x70 (Read Status) command to an erasing 373 sending the 0x70 (Read Status) command to an erasing
365 chip and expecting it to be ignored, that's what we 374 chip and expecting it to be ignored, that's what we
366 do. */ 375 do. */
367 map_write(map, CMD(0xd0), cmd_addr); 376 map_write(map, CMD(0xd0), cmd_addr);
368 map_write(map, CMD(0x70), cmd_addr); 377 map_write(map, CMD(0x70), cmd_addr);
369 } 378 }
370 379
371 wake_up(&chip->wq); 380 wake_up(&chip->wq);
@@ -405,14 +414,14 @@ static int cfi_staa_read (struct mtd_info *mtd, loff_t from, size_t len, size_t
405 *retlen += thislen; 414 *retlen += thislen;
406 len -= thislen; 415 len -= thislen;
407 buf += thislen; 416 buf += thislen;
408 417
409 ofs = 0; 418 ofs = 0;
410 chipnum++; 419 chipnum++;
411 } 420 }
412 return ret; 421 return ret;
413} 422}
414 423
415static inline int do_write_buffer(struct map_info *map, struct flchip *chip, 424static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
416 unsigned long adr, const u_char *buf, int len) 425 unsigned long adr, const u_char *buf, int len)
417{ 426{
418 struct cfi_private *cfi = map->fldrv_priv; 427 struct cfi_private *cfi = map->fldrv_priv;
@@ -420,7 +429,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
420 unsigned long cmd_adr, timeo; 429 unsigned long cmd_adr, timeo;
421 DECLARE_WAITQUEUE(wait, current); 430 DECLARE_WAITQUEUE(wait, current);
422 int wbufsize, z; 431 int wbufsize, z;
423 432
424 /* M58LW064A requires bus alignment for buffer wriets -- saw */ 433 /* M58LW064A requires bus alignment for buffer wriets -- saw */
425 if (adr & (map_bankwidth(map)-1)) 434 if (adr & (map_bankwidth(map)-1))
426 return -EINVAL; 435 return -EINVAL;
@@ -428,10 +437,10 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
428 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize; 437 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
429 adr += chip->start; 438 adr += chip->start;
430 cmd_adr = adr & ~(wbufsize-1); 439 cmd_adr = adr & ~(wbufsize-1);
431 440
432 /* Let's determine this according to the interleave only once */ 441 /* Let's determine this according to the interleave only once */
433 status_OK = CMD(0x80); 442 status_OK = CMD(0x80);
434 443
435 timeo = jiffies + HZ; 444 timeo = jiffies + HZ;
436 retry: 445 retry:
437 446
@@ -439,7 +448,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
439 printk("%s: chip->state[%d]\n", __FUNCTION__, chip->state); 448 printk("%s: chip->state[%d]\n", __FUNCTION__, chip->state);
440#endif 449#endif
441 spin_lock_bh(chip->mutex); 450 spin_lock_bh(chip->mutex);
442 451
443 /* Check that the chip's ready to talk to us. 452 /* Check that the chip's ready to talk to us.
444 * Later, we can actually think about interrupting it 453 * Later, we can actually think about interrupting it
445 * if it's in FL_ERASING state. 454 * if it's in FL_ERASING state.
@@ -448,7 +457,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
448 switch (chip->state) { 457 switch (chip->state) {
449 case FL_READY: 458 case FL_READY:
450 break; 459 break;
451 460
452 case FL_CFI_QUERY: 461 case FL_CFI_QUERY:
453 case FL_JEDEC_QUERY: 462 case FL_JEDEC_QUERY:
454 map_write(map, CMD(0x70), cmd_adr); 463 map_write(map, CMD(0x70), cmd_adr);
@@ -513,7 +522,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
513 522
514 /* Write length of data to come */ 523 /* Write length of data to come */
515 map_write(map, CMD(len/map_bankwidth(map)-1), cmd_adr ); 524 map_write(map, CMD(len/map_bankwidth(map)-1), cmd_adr );
516 525
517 /* Write data */ 526 /* Write data */
518 for (z = 0; z < len; 527 for (z = 0; z < len;
519 z += map_bankwidth(map), buf += map_bankwidth(map)) { 528 z += map_bankwidth(map), buf += map_bankwidth(map)) {
@@ -560,7 +569,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
560 printk(KERN_ERR "waiting for chip to be ready timed out in bufwrite\n"); 569 printk(KERN_ERR "waiting for chip to be ready timed out in bufwrite\n");
561 return -EIO; 570 return -EIO;
562 } 571 }
563 572
564 /* Latency issues. Drop the lock, wait a while and retry */ 573 /* Latency issues. Drop the lock, wait a while and retry */
565 spin_unlock_bh(chip->mutex); 574 spin_unlock_bh(chip->mutex);
566 cfi_udelay(1); 575 cfi_udelay(1);
@@ -572,9 +581,9 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
572 if (!chip->buffer_write_time) 581 if (!chip->buffer_write_time)
573 chip->buffer_write_time++; 582 chip->buffer_write_time++;
574 } 583 }
575 if (z > 1) 584 if (z > 1)
576 chip->buffer_write_time++; 585 chip->buffer_write_time++;
577 586
578 /* Done and happy. */ 587 /* Done and happy. */
579 DISABLE_VPP(map); 588 DISABLE_VPP(map);
580 chip->state = FL_STATUS; 589 chip->state = FL_STATUS;
@@ -598,7 +607,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
598 return 0; 607 return 0;
599} 608}
600 609
601static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to, 610static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
602 size_t len, size_t *retlen, const u_char *buf) 611 size_t len, size_t *retlen, const u_char *buf)
603{ 612{
604 struct map_info *map = mtd->priv; 613 struct map_info *map = mtd->priv;
@@ -620,7 +629,7 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
620 printk("%s: chipnum[%x] wbufsize[%x]\n", __FUNCTION__, chipnum, wbufsize); 629 printk("%s: chipnum[%x] wbufsize[%x]\n", __FUNCTION__, chipnum, wbufsize);
621 printk("%s: ofs[%x] len[%x]\n", __FUNCTION__, ofs, len); 630 printk("%s: ofs[%x] len[%x]\n", __FUNCTION__, ofs, len);
622#endif 631#endif
623 632
624 /* Write buffer is worth it only if more than one word to write... */ 633 /* Write buffer is worth it only if more than one word to write... */
625 while (len > 0) { 634 while (len > 0) {
626 /* We must not cross write block boundaries */ 635 /* We must not cross write block boundaries */
@@ -629,7 +638,7 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
629 if (size > len) 638 if (size > len)
630 size = len; 639 size = len;
631 640
632 ret = do_write_buffer(map, &cfi->chips[chipnum], 641 ret = do_write_buffer(map, &cfi->chips[chipnum],
633 ofs, buf, size); 642 ofs, buf, size);
634 if (ret) 643 if (ret)
635 return ret; 644 return ret;
@@ -640,13 +649,13 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
640 len -= size; 649 len -= size;
641 650
642 if (ofs >> cfi->chipshift) { 651 if (ofs >> cfi->chipshift) {
643 chipnum ++; 652 chipnum ++;
644 ofs = 0; 653 ofs = 0;
645 if (chipnum == cfi->numchips) 654 if (chipnum == cfi->numchips)
646 return 0; 655 return 0;
647 } 656 }
648 } 657 }
649 658
650 return 0; 659 return 0;
651} 660}
652 661
@@ -756,7 +765,7 @@ retry:
756 status = map_read(map, adr); 765 status = map_read(map, adr);
757 if (map_word_andequal(map, status, status_OK, status_OK)) 766 if (map_word_andequal(map, status, status_OK, status_OK))
758 break; 767 break;
759 768
760 /* Urgh. Chip not yet ready to talk to us. */ 769 /* Urgh. Chip not yet ready to talk to us. */
761 if (time_after(jiffies, timeo)) { 770 if (time_after(jiffies, timeo)) {
762 spin_unlock_bh(chip->mutex); 771 spin_unlock_bh(chip->mutex);
@@ -789,7 +798,7 @@ retry:
789 map_write(map, CMD(0x20), adr); 798 map_write(map, CMD(0x20), adr);
790 map_write(map, CMD(0xD0), adr); 799 map_write(map, CMD(0xD0), adr);
791 chip->state = FL_ERASING; 800 chip->state = FL_ERASING;
792 801
793 spin_unlock_bh(chip->mutex); 802 spin_unlock_bh(chip->mutex);
794 msleep(1000); 803 msleep(1000);
795 spin_lock_bh(chip->mutex); 804 spin_lock_bh(chip->mutex);
@@ -814,7 +823,7 @@ retry:
814 status = map_read(map, adr); 823 status = map_read(map, adr);
815 if (map_word_andequal(map, status, status_OK, status_OK)) 824 if (map_word_andequal(map, status, status_OK, status_OK))
816 break; 825 break;
817 826
818 /* OK Still waiting */ 827 /* OK Still waiting */
819 if (time_after(jiffies, timeo)) { 828 if (time_after(jiffies, timeo)) {
820 map_write(map, CMD(0x70), adr); 829 map_write(map, CMD(0x70), adr);
@@ -824,13 +833,13 @@ retry:
824 spin_unlock_bh(chip->mutex); 833 spin_unlock_bh(chip->mutex);
825 return -EIO; 834 return -EIO;
826 } 835 }
827 836
828 /* Latency issues. Drop the lock, wait a while and retry */ 837 /* Latency issues. Drop the lock, wait a while and retry */
829 spin_unlock_bh(chip->mutex); 838 spin_unlock_bh(chip->mutex);
830 cfi_udelay(1); 839 cfi_udelay(1);
831 spin_lock_bh(chip->mutex); 840 spin_lock_bh(chip->mutex);
832 } 841 }
833 842
834 DISABLE_VPP(map); 843 DISABLE_VPP(map);
835 ret = 0; 844 ret = 0;
836 845
@@ -855,7 +864,7 @@ retry:
855 /* Reset the error bits */ 864 /* Reset the error bits */
856 map_write(map, CMD(0x50), adr); 865 map_write(map, CMD(0x50), adr);
857 map_write(map, CMD(0x70), adr); 866 map_write(map, CMD(0x70), adr);
858 867
859 if ((chipstatus & 0x30) == 0x30) { 868 if ((chipstatus & 0x30) == 0x30) {
860 printk(KERN_NOTICE "Chip reports improper command sequence: status 0x%x\n", chipstatus); 869 printk(KERN_NOTICE "Chip reports improper command sequence: status 0x%x\n", chipstatus);
861 ret = -EIO; 870 ret = -EIO;
@@ -904,17 +913,17 @@ int cfi_staa_erase_varsize(struct mtd_info *mtd, struct erase_info *instr)
904 913
905 i = 0; 914 i = 0;
906 915
907 /* Skip all erase regions which are ended before the start of 916 /* Skip all erase regions which are ended before the start of
908 the requested erase. Actually, to save on the calculations, 917 the requested erase. Actually, to save on the calculations,
909 we skip to the first erase region which starts after the 918 we skip to the first erase region which starts after the
910 start of the requested erase, and then go back one. 919 start of the requested erase, and then go back one.
911 */ 920 */
912 921
913 while (i < mtd->numeraseregions && instr->addr >= regions[i].offset) 922 while (i < mtd->numeraseregions && instr->addr >= regions[i].offset)
914 i++; 923 i++;
915 i--; 924 i--;
916 925
917 /* OK, now i is pointing at the erase region in which this 926 /* OK, now i is pointing at the erase region in which this
918 erase request starts. Check the start of the requested 927 erase request starts. Check the start of the requested
919 erase range is aligned with the erase size which is in 928 erase range is aligned with the erase size which is in
920 effect here. 929 effect here.
@@ -937,7 +946,7 @@ int cfi_staa_erase_varsize(struct mtd_info *mtd, struct erase_info *instr)
937 the address actually falls 946 the address actually falls
938 */ 947 */
939 i--; 948 i--;
940 949
941 if ((instr->addr + instr->len) & (regions[i].erasesize-1)) 950 if ((instr->addr + instr->len) & (regions[i].erasesize-1))
942 return -EINVAL; 951 return -EINVAL;
943 952
@@ -949,7 +958,7 @@ int cfi_staa_erase_varsize(struct mtd_info *mtd, struct erase_info *instr)
949 958
950 while(len) { 959 while(len) {
951 ret = do_erase_oneblock(map, &cfi->chips[chipnum], adr); 960 ret = do_erase_oneblock(map, &cfi->chips[chipnum], adr);
952 961
953 if (ret) 962 if (ret)
954 return ret; 963 return ret;
955 964
@@ -962,15 +971,15 @@ int cfi_staa_erase_varsize(struct mtd_info *mtd, struct erase_info *instr)
962 if (adr >> cfi->chipshift) { 971 if (adr >> cfi->chipshift) {
963 adr = 0; 972 adr = 0;
964 chipnum++; 973 chipnum++;
965 974
966 if (chipnum >= cfi->numchips) 975 if (chipnum >= cfi->numchips)
967 break; 976 break;
968 } 977 }
969 } 978 }
970 979
971 instr->state = MTD_ERASE_DONE; 980 instr->state = MTD_ERASE_DONE;
972 mtd_erase_callback(instr); 981 mtd_erase_callback(instr);
973 982
974 return 0; 983 return 0;
975} 984}
976 985
@@ -996,7 +1005,7 @@ static void cfi_staa_sync (struct mtd_info *mtd)
996 case FL_JEDEC_QUERY: 1005 case FL_JEDEC_QUERY:
997 chip->oldstate = chip->state; 1006 chip->oldstate = chip->state;
998 chip->state = FL_SYNCING; 1007 chip->state = FL_SYNCING;
999 /* No need to wake_up() on this state change - 1008 /* No need to wake_up() on this state change -
1000 * as the whole point is that nobody can do anything 1009 * as the whole point is that nobody can do anything
1001 * with the chip now anyway. 1010 * with the chip now anyway.
1002 */ 1011 */
@@ -1007,11 +1016,11 @@ static void cfi_staa_sync (struct mtd_info *mtd)
1007 default: 1016 default:
1008 /* Not an idle state */ 1017 /* Not an idle state */
1009 add_wait_queue(&chip->wq, &wait); 1018 add_wait_queue(&chip->wq, &wait);
1010 1019
1011 spin_unlock_bh(chip->mutex); 1020 spin_unlock_bh(chip->mutex);
1012 schedule(); 1021 schedule();
1013 remove_wait_queue(&chip->wq, &wait); 1022 remove_wait_queue(&chip->wq, &wait);
1014 1023
1015 goto retry; 1024 goto retry;
1016 } 1025 }
1017 } 1026 }
@@ -1022,7 +1031,7 @@ static void cfi_staa_sync (struct mtd_info *mtd)
1022 chip = &cfi->chips[i]; 1031 chip = &cfi->chips[i];
1023 1032
1024 spin_lock_bh(chip->mutex); 1033 spin_lock_bh(chip->mutex);
1025 1034
1026 if (chip->state == FL_SYNCING) { 1035 if (chip->state == FL_SYNCING) {
1027 chip->state = chip->oldstate; 1036 chip->state = chip->oldstate;
1028 wake_up(&chip->wq); 1037 wake_up(&chip->wq);
@@ -1057,9 +1066,9 @@ retry:
1057 1066
1058 case FL_STATUS: 1067 case FL_STATUS:
1059 status = map_read(map, adr); 1068 status = map_read(map, adr);
1060 if (map_word_andequal(map, status, status_OK, status_OK)) 1069 if (map_word_andequal(map, status, status_OK, status_OK))
1061 break; 1070 break;
1062 1071
1063 /* Urgh. Chip not yet ready to talk to us. */ 1072 /* Urgh. Chip not yet ready to talk to us. */
1064 if (time_after(jiffies, timeo)) { 1073 if (time_after(jiffies, timeo)) {
1065 spin_unlock_bh(chip->mutex); 1074 spin_unlock_bh(chip->mutex);
@@ -1088,7 +1097,7 @@ retry:
1088 map_write(map, CMD(0x60), adr); 1097 map_write(map, CMD(0x60), adr);
1089 map_write(map, CMD(0x01), adr); 1098 map_write(map, CMD(0x01), adr);
1090 chip->state = FL_LOCKING; 1099 chip->state = FL_LOCKING;
1091 1100
1092 spin_unlock_bh(chip->mutex); 1101 spin_unlock_bh(chip->mutex);
1093 msleep(1000); 1102 msleep(1000);
1094 spin_lock_bh(chip->mutex); 1103 spin_lock_bh(chip->mutex);
@@ -1102,7 +1111,7 @@ retry:
1102 status = map_read(map, adr); 1111 status = map_read(map, adr);
1103 if (map_word_andequal(map, status, status_OK, status_OK)) 1112 if (map_word_andequal(map, status, status_OK, status_OK))
1104 break; 1113 break;
1105 1114
1106 /* OK Still waiting */ 1115 /* OK Still waiting */
1107 if (time_after(jiffies, timeo)) { 1116 if (time_after(jiffies, timeo)) {
1108 map_write(map, CMD(0x70), adr); 1117 map_write(map, CMD(0x70), adr);
@@ -1112,13 +1121,13 @@ retry:
1112 spin_unlock_bh(chip->mutex); 1121 spin_unlock_bh(chip->mutex);
1113 return -EIO; 1122 return -EIO;
1114 } 1123 }
1115 1124
1116 /* Latency issues. Drop the lock, wait a while and retry */ 1125 /* Latency issues. Drop the lock, wait a while and retry */
1117 spin_unlock_bh(chip->mutex); 1126 spin_unlock_bh(chip->mutex);
1118 cfi_udelay(1); 1127 cfi_udelay(1);
1119 spin_lock_bh(chip->mutex); 1128 spin_lock_bh(chip->mutex);
1120 } 1129 }
1121 1130
1122 /* Done and happy. */ 1131 /* Done and happy. */
1123 chip->state = FL_STATUS; 1132 chip->state = FL_STATUS;
1124 DISABLE_VPP(map); 1133 DISABLE_VPP(map);
@@ -1162,8 +1171,8 @@ static int cfi_staa_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
1162 cfi_send_gen_cmd(0x90, 0x55, 0, map, cfi, cfi->device_type, NULL); 1171 cfi_send_gen_cmd(0x90, 0x55, 0, map, cfi, cfi->device_type, NULL);
1163 printk("after lock: block status register is %x\n",cfi_read_query(map, adr+(2*ofs_factor))); 1172 printk("after lock: block status register is %x\n",cfi_read_query(map, adr+(2*ofs_factor)));
1164 cfi_send_gen_cmd(0xff, 0x55, 0, map, cfi, cfi->device_type, NULL); 1173 cfi_send_gen_cmd(0xff, 0x55, 0, map, cfi, cfi->device_type, NULL);
1165#endif 1174#endif
1166 1175
1167 if (ret) 1176 if (ret)
1168 return ret; 1177 return ret;
1169 1178
@@ -1173,7 +1182,7 @@ static int cfi_staa_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
1173 if (adr >> cfi->chipshift) { 1182 if (adr >> cfi->chipshift) {
1174 adr = 0; 1183 adr = 0;
1175 chipnum++; 1184 chipnum++;
1176 1185
1177 if (chipnum >= cfi->numchips) 1186 if (chipnum >= cfi->numchips)
1178 break; 1187 break;
1179 } 1188 }
@@ -1208,7 +1217,7 @@ retry:
1208 status = map_read(map, adr); 1217 status = map_read(map, adr);
1209 if (map_word_andequal(map, status, status_OK, status_OK)) 1218 if (map_word_andequal(map, status, status_OK, status_OK))
1210 break; 1219 break;
1211 1220
1212 /* Urgh. Chip not yet ready to talk to us. */ 1221 /* Urgh. Chip not yet ready to talk to us. */
1213 if (time_after(jiffies, timeo)) { 1222 if (time_after(jiffies, timeo)) {
1214 spin_unlock_bh(chip->mutex); 1223 spin_unlock_bh(chip->mutex);
@@ -1237,7 +1246,7 @@ retry:
1237 map_write(map, CMD(0x60), adr); 1246 map_write(map, CMD(0x60), adr);
1238 map_write(map, CMD(0xD0), adr); 1247 map_write(map, CMD(0xD0), adr);
1239 chip->state = FL_UNLOCKING; 1248 chip->state = FL_UNLOCKING;
1240 1249
1241 spin_unlock_bh(chip->mutex); 1250 spin_unlock_bh(chip->mutex);
1242 msleep(1000); 1251 msleep(1000);
1243 spin_lock_bh(chip->mutex); 1252 spin_lock_bh(chip->mutex);
@@ -1251,7 +1260,7 @@ retry:
1251 status = map_read(map, adr); 1260 status = map_read(map, adr);
1252 if (map_word_andequal(map, status, status_OK, status_OK)) 1261 if (map_word_andequal(map, status, status_OK, status_OK))
1253 break; 1262 break;
1254 1263
1255 /* OK Still waiting */ 1264 /* OK Still waiting */
1256 if (time_after(jiffies, timeo)) { 1265 if (time_after(jiffies, timeo)) {
1257 map_write(map, CMD(0x70), adr); 1266 map_write(map, CMD(0x70), adr);
@@ -1261,13 +1270,13 @@ retry:
1261 spin_unlock_bh(chip->mutex); 1270 spin_unlock_bh(chip->mutex);
1262 return -EIO; 1271 return -EIO;
1263 } 1272 }
1264 1273
1265 /* Latency issues. Drop the unlock, wait a while and retry */ 1274 /* Latency issues. Drop the unlock, wait a while and retry */
1266 spin_unlock_bh(chip->mutex); 1275 spin_unlock_bh(chip->mutex);
1267 cfi_udelay(1); 1276 cfi_udelay(1);
1268 spin_lock_bh(chip->mutex); 1277 spin_lock_bh(chip->mutex);
1269 } 1278 }
1270 1279
1271 /* Done and happy. */ 1280 /* Done and happy. */
1272 chip->state = FL_STATUS; 1281 chip->state = FL_STATUS;
1273 DISABLE_VPP(map); 1282 DISABLE_VPP(map);
@@ -1292,7 +1301,7 @@ static int cfi_staa_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1292 { 1301 {
1293 unsigned long temp_adr = adr; 1302 unsigned long temp_adr = adr;
1294 unsigned long temp_len = len; 1303 unsigned long temp_len = len;
1295 1304
1296 cfi_send_gen_cmd(0x90, 0x55, 0, map, cfi, cfi->device_type, NULL); 1305 cfi_send_gen_cmd(0x90, 0x55, 0, map, cfi, cfi->device_type, NULL);
1297 while (temp_len) { 1306 while (temp_len) {
1298 printk("before unlock %x: block status register is %x\n",temp_adr,cfi_read_query(map, temp_adr+(2*ofs_factor))); 1307 printk("before unlock %x: block status register is %x\n",temp_adr,cfi_read_query(map, temp_adr+(2*ofs_factor)));
@@ -1310,7 +1319,7 @@ static int cfi_staa_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1310 printk("after unlock: block status register is %x\n",cfi_read_query(map, adr+(2*ofs_factor))); 1319 printk("after unlock: block status register is %x\n",cfi_read_query(map, adr+(2*ofs_factor)));
1311 cfi_send_gen_cmd(0xff, 0x55, 0, map, cfi, cfi->device_type, NULL); 1320 cfi_send_gen_cmd(0xff, 0x55, 0, map, cfi, cfi->device_type, NULL);
1312#endif 1321#endif
1313 1322
1314 return ret; 1323 return ret;
1315} 1324}
1316 1325
@@ -1334,7 +1343,7 @@ static int cfi_staa_suspend(struct mtd_info *mtd)
1334 case FL_JEDEC_QUERY: 1343 case FL_JEDEC_QUERY:
1335 chip->oldstate = chip->state; 1344 chip->oldstate = chip->state;
1336 chip->state = FL_PM_SUSPENDED; 1345 chip->state = FL_PM_SUSPENDED;
1337 /* No need to wake_up() on this state change - 1346 /* No need to wake_up() on this state change -
1338 * as the whole point is that nobody can do anything 1347 * as the whole point is that nobody can do anything
1339 * with the chip now anyway. 1348 * with the chip now anyway.
1340 */ 1349 */
@@ -1353,9 +1362,9 @@ static int cfi_staa_suspend(struct mtd_info *mtd)
1353 if (ret) { 1362 if (ret) {
1354 for (i--; i >=0; i--) { 1363 for (i--; i >=0; i--) {
1355 chip = &cfi->chips[i]; 1364 chip = &cfi->chips[i];
1356 1365
1357 spin_lock_bh(chip->mutex); 1366 spin_lock_bh(chip->mutex);
1358 1367
1359 if (chip->state == FL_PM_SUSPENDED) { 1368 if (chip->state == FL_PM_SUSPENDED) {
1360 /* No need to force it into a known state here, 1369 /* No need to force it into a known state here,
1361 because we're returning failure, and it didn't 1370 because we're returning failure, and it didn't
@@ -1365,8 +1374,8 @@ static int cfi_staa_suspend(struct mtd_info *mtd)
1365 } 1374 }
1366 spin_unlock_bh(chip->mutex); 1375 spin_unlock_bh(chip->mutex);
1367 } 1376 }
1368 } 1377 }
1369 1378
1370 return ret; 1379 return ret;
1371} 1380}
1372 1381
@@ -1378,11 +1387,11 @@ static void cfi_staa_resume(struct mtd_info *mtd)
1378 struct flchip *chip; 1387 struct flchip *chip;
1379 1388
1380 for (i=0; i<cfi->numchips; i++) { 1389 for (i=0; i<cfi->numchips; i++) {
1381 1390
1382 chip = &cfi->chips[i]; 1391 chip = &cfi->chips[i];
1383 1392
1384 spin_lock_bh(chip->mutex); 1393 spin_lock_bh(chip->mutex);
1385 1394
1386 /* Go to known state. Chip may have been power cycled */ 1395 /* Go to known state. Chip may have been power cycled */
1387 if (chip->state == FL_PM_SUSPENDED) { 1396 if (chip->state == FL_PM_SUSPENDED) {
1388 map_write(map, CMD(0xFF), 0); 1397 map_write(map, CMD(0xFF), 0);
diff --git a/drivers/mtd/chips/cfi_probe.c b/drivers/mtd/chips/cfi_probe.c
index cf750038ce6a..90eb30e06b7c 100644
--- a/drivers/mtd/chips/cfi_probe.c
+++ b/drivers/mtd/chips/cfi_probe.c
@@ -1,7 +1,7 @@
1/* 1/*
2 Common Flash Interface probe code. 2 Common Flash Interface probe code.
3 (C) 2000 Red Hat. GPL'd. 3 (C) 2000 Red Hat. GPL'd.
4 $Id: cfi_probe.c,v 1.83 2004/11/16 18:19:02 nico Exp $ 4 $Id: cfi_probe.c,v 1.84 2005/11/07 11:14:23 gleixner Exp $
5*/ 5*/
6 6
7#include <linux/config.h> 7#include <linux/config.h>
@@ -20,7 +20,7 @@
20#include <linux/mtd/cfi.h> 20#include <linux/mtd/cfi.h>
21#include <linux/mtd/gen_probe.h> 21#include <linux/mtd/gen_probe.h>
22 22
23//#define DEBUG_CFI 23//#define DEBUG_CFI
24 24
25#ifdef DEBUG_CFI 25#ifdef DEBUG_CFI
26static void print_cfi_ident(struct cfi_ident *); 26static void print_cfi_ident(struct cfi_ident *);
@@ -103,7 +103,7 @@ static int __xipram cfi_probe_chip(struct map_info *map, __u32 base,
103 unsigned long *chip_map, struct cfi_private *cfi) 103 unsigned long *chip_map, struct cfi_private *cfi)
104{ 104{
105 int i; 105 int i;
106 106
107 if ((base + 0) >= map->size) { 107 if ((base + 0) >= map->size) {
108 printk(KERN_NOTICE 108 printk(KERN_NOTICE
109 "Probe at base[0x00](0x%08lx) past the end of the map(0x%08lx)\n", 109 "Probe at base[0x00](0x%08lx) past the end of the map(0x%08lx)\n",
@@ -128,7 +128,7 @@ static int __xipram cfi_probe_chip(struct map_info *map, __u32 base,
128 } 128 }
129 129
130 if (!cfi->numchips) { 130 if (!cfi->numchips) {
131 /* This is the first time we're called. Set up the CFI 131 /* This is the first time we're called. Set up the CFI
132 stuff accordingly and return */ 132 stuff accordingly and return */
133 return cfi_chip_setup(map, cfi); 133 return cfi_chip_setup(map, cfi);
134 } 134 }
@@ -138,13 +138,13 @@ static int __xipram cfi_probe_chip(struct map_info *map, __u32 base,
138 unsigned long start; 138 unsigned long start;
139 if(!test_bit(i, chip_map)) { 139 if(!test_bit(i, chip_map)) {
140 /* Skip location; no valid chip at this address */ 140 /* Skip location; no valid chip at this address */
141 continue; 141 continue;
142 } 142 }
143 start = i << cfi->chipshift; 143 start = i << cfi->chipshift;
144 /* This chip should be in read mode if it's one 144 /* This chip should be in read mode if it's one
145 we've already touched. */ 145 we've already touched. */
146 if (qry_present(map, start, cfi)) { 146 if (qry_present(map, start, cfi)) {
147 /* Eep. This chip also had the QRY marker. 147 /* Eep. This chip also had the QRY marker.
148 * Is it an alias for the new one? */ 148 * Is it an alias for the new one? */
149 cfi_send_gen_cmd(0xF0, 0, start, map, cfi, cfi->device_type, NULL); 149 cfi_send_gen_cmd(0xF0, 0, start, map, cfi, cfi->device_type, NULL);
150 cfi_send_gen_cmd(0xFF, 0, start, map, cfi, cfi->device_type, NULL); 150 cfi_send_gen_cmd(0xFF, 0, start, map, cfi, cfi->device_type, NULL);
@@ -156,13 +156,13 @@ static int __xipram cfi_probe_chip(struct map_info *map, __u32 base,
156 map->name, base, start); 156 map->name, base, start);
157 return 0; 157 return 0;
158 } 158 }
159 /* Yes, it's actually got QRY for data. Most 159 /* Yes, it's actually got QRY for data. Most
160 * unfortunate. Stick the new chip in read mode 160 * unfortunate. Stick the new chip in read mode
161 * too and if it's the same, assume it's an alias. */ 161 * too and if it's the same, assume it's an alias. */
162 /* FIXME: Use other modes to do a proper check */ 162 /* FIXME: Use other modes to do a proper check */
163 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); 163 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
164 cfi_send_gen_cmd(0xFF, 0, start, map, cfi, cfi->device_type, NULL); 164 cfi_send_gen_cmd(0xFF, 0, start, map, cfi, cfi->device_type, NULL);
165 165
166 if (qry_present(map, base, cfi)) { 166 if (qry_present(map, base, cfi)) {
167 xip_allowed(base, map); 167 xip_allowed(base, map);
168 printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n", 168 printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n",
@@ -171,12 +171,12 @@ static int __xipram cfi_probe_chip(struct map_info *map, __u32 base,
171 } 171 }
172 } 172 }
173 } 173 }
174 174
175 /* OK, if we got to here, then none of the previous chips appear to 175 /* OK, if we got to here, then none of the previous chips appear to
176 be aliases for the current one. */ 176 be aliases for the current one. */
177 set_bit((base >> cfi->chipshift), chip_map); /* Update chip map */ 177 set_bit((base >> cfi->chipshift), chip_map); /* Update chip map */
178 cfi->numchips++; 178 cfi->numchips++;
179 179
180 /* Put it back into Read Mode */ 180 /* Put it back into Read Mode */
181 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); 181 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
182 cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL); 182 cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL);
@@ -185,11 +185,11 @@ static int __xipram cfi_probe_chip(struct map_info *map, __u32 base,
185 printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank\n", 185 printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank\n",
186 map->name, cfi->interleave, cfi->device_type*8, base, 186 map->name, cfi->interleave, cfi->device_type*8, base,
187 map->bankwidth*8); 187 map->bankwidth*8);
188 188
189 return 1; 189 return 1;
190} 190}
191 191
192static int __xipram cfi_chip_setup(struct map_info *map, 192static int __xipram cfi_chip_setup(struct map_info *map,
193 struct cfi_private *cfi) 193 struct cfi_private *cfi)
194{ 194{
195 int ofs_factor = cfi->interleave*cfi->device_type; 195 int ofs_factor = cfi->interleave*cfi->device_type;
@@ -209,11 +209,11 @@ static int __xipram cfi_chip_setup(struct map_info *map,
209 printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name); 209 printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name);
210 return 0; 210 return 0;
211 } 211 }
212 212
213 memset(cfi->cfiq,0,sizeof(struct cfi_ident)); 213 memset(cfi->cfiq,0,sizeof(struct cfi_ident));
214 214
215 cfi->cfi_mode = CFI_MODE_CFI; 215 cfi->cfi_mode = CFI_MODE_CFI;
216 216
217 /* Read the CFI info structure */ 217 /* Read the CFI info structure */
218 xip_disable_qry(base, map, cfi); 218 xip_disable_qry(base, map, cfi);
219 for (i=0; i<(sizeof(struct cfi_ident) + num_erase_regions * 4); i++) 219 for (i=0; i<(sizeof(struct cfi_ident) + num_erase_regions * 4); i++)
@@ -231,7 +231,7 @@ static int __xipram cfi_chip_setup(struct map_info *map,
231 cfi_send_gen_cmd(0x55, 0x2aa, base, map, cfi, cfi->device_type, NULL); 231 cfi_send_gen_cmd(0x55, 0x2aa, base, map, cfi, cfi->device_type, NULL);
232 cfi_send_gen_cmd(0x90, 0x555, base, map, cfi, cfi->device_type, NULL); 232 cfi_send_gen_cmd(0x90, 0x555, base, map, cfi, cfi->device_type, NULL);
233 cfi->mfr = cfi_read_query(map, base); 233 cfi->mfr = cfi_read_query(map, base);
234 cfi->id = cfi_read_query(map, base + ofs_factor); 234 cfi->id = cfi_read_query(map, base + ofs_factor);
235 235
236 /* Put it back into Read Mode */ 236 /* Put it back into Read Mode */
237 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); 237 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
@@ -255,10 +255,10 @@ static int __xipram cfi_chip_setup(struct map_info *map,
255 255
256 for (i=0; i<cfi->cfiq->NumEraseRegions; i++) { 256 for (i=0; i<cfi->cfiq->NumEraseRegions; i++) {
257 cfi->cfiq->EraseRegionInfo[i] = le32_to_cpu(cfi->cfiq->EraseRegionInfo[i]); 257 cfi->cfiq->EraseRegionInfo[i] = le32_to_cpu(cfi->cfiq->EraseRegionInfo[i]);
258 258
259#ifdef DEBUG_CFI 259#ifdef DEBUG_CFI
260 printk(" Erase Region #%d: BlockSize 0x%4.4X bytes, %d blocks\n", 260 printk(" Erase Region #%d: BlockSize 0x%4.4X bytes, %d blocks\n",
261 i, (cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff, 261 i, (cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff,
262 (cfi->cfiq->EraseRegionInfo[i] & 0xffff) + 1); 262 (cfi->cfiq->EraseRegionInfo[i] & 0xffff) + 1);
263#endif 263#endif
264 } 264 }
@@ -271,33 +271,33 @@ static int __xipram cfi_chip_setup(struct map_info *map,
271} 271}
272 272
273#ifdef DEBUG_CFI 273#ifdef DEBUG_CFI
274static char *vendorname(__u16 vendor) 274static char *vendorname(__u16 vendor)
275{ 275{
276 switch (vendor) { 276 switch (vendor) {
277 case P_ID_NONE: 277 case P_ID_NONE:
278 return "None"; 278 return "None";
279 279
280 case P_ID_INTEL_EXT: 280 case P_ID_INTEL_EXT:
281 return "Intel/Sharp Extended"; 281 return "Intel/Sharp Extended";
282 282
283 case P_ID_AMD_STD: 283 case P_ID_AMD_STD:
284 return "AMD/Fujitsu Standard"; 284 return "AMD/Fujitsu Standard";
285 285
286 case P_ID_INTEL_STD: 286 case P_ID_INTEL_STD:
287 return "Intel/Sharp Standard"; 287 return "Intel/Sharp Standard";
288 288
289 case P_ID_AMD_EXT: 289 case P_ID_AMD_EXT:
290 return "AMD/Fujitsu Extended"; 290 return "AMD/Fujitsu Extended";
291 291
292 case P_ID_WINBOND: 292 case P_ID_WINBOND:
293 return "Winbond Standard"; 293 return "Winbond Standard";
294 294
295 case P_ID_ST_ADV: 295 case P_ID_ST_ADV:
296 return "ST Advanced"; 296 return "ST Advanced";
297 297
298 case P_ID_MITSUBISHI_STD: 298 case P_ID_MITSUBISHI_STD:
299 return "Mitsubishi Standard"; 299 return "Mitsubishi Standard";
300 300
301 case P_ID_MITSUBISHI_EXT: 301 case P_ID_MITSUBISHI_EXT:
302 return "Mitsubishi Extended"; 302 return "Mitsubishi Extended";
303 303
@@ -306,13 +306,13 @@ static char *vendorname(__u16 vendor)
306 306
307 case P_ID_INTEL_PERFORMANCE: 307 case P_ID_INTEL_PERFORMANCE:
308 return "Intel Performance Code"; 308 return "Intel Performance Code";
309 309
310 case P_ID_INTEL_DATA: 310 case P_ID_INTEL_DATA:
311 return "Intel Data"; 311 return "Intel Data";
312 312
313 case P_ID_RESERVED: 313 case P_ID_RESERVED:
314 return "Not Allowed / Reserved for Future Use"; 314 return "Not Allowed / Reserved for Future Use";
315 315
316 default: 316 default:
317 return "Unknown"; 317 return "Unknown";
318 } 318 }
@@ -325,21 +325,21 @@ static void print_cfi_ident(struct cfi_ident *cfip)
325 if (cfip->qry[0] != 'Q' || cfip->qry[1] != 'R' || cfip->qry[2] != 'Y') { 325 if (cfip->qry[0] != 'Q' || cfip->qry[1] != 'R' || cfip->qry[2] != 'Y') {
326 printk("Invalid CFI ident structure.\n"); 326 printk("Invalid CFI ident structure.\n");
327 return; 327 return;
328 } 328 }
329#endif 329#endif
330 printk("Primary Vendor Command Set: %4.4X (%s)\n", cfip->P_ID, vendorname(cfip->P_ID)); 330 printk("Primary Vendor Command Set: %4.4X (%s)\n", cfip->P_ID, vendorname(cfip->P_ID));
331 if (cfip->P_ADR) 331 if (cfip->P_ADR)
332 printk("Primary Algorithm Table at %4.4X\n", cfip->P_ADR); 332 printk("Primary Algorithm Table at %4.4X\n", cfip->P_ADR);
333 else 333 else
334 printk("No Primary Algorithm Table\n"); 334 printk("No Primary Algorithm Table\n");
335 335
336 printk("Alternative Vendor Command Set: %4.4X (%s)\n", cfip->A_ID, vendorname(cfip->A_ID)); 336 printk("Alternative Vendor Command Set: %4.4X (%s)\n", cfip->A_ID, vendorname(cfip->A_ID));
337 if (cfip->A_ADR) 337 if (cfip->A_ADR)
338 printk("Alternate Algorithm Table at %4.4X\n", cfip->A_ADR); 338 printk("Alternate Algorithm Table at %4.4X\n", cfip->A_ADR);
339 else 339 else
340 printk("No Alternate Algorithm Table\n"); 340 printk("No Alternate Algorithm Table\n");
341 341
342 342
343 printk("Vcc Minimum: %2d.%d V\n", cfip->VccMin >> 4, cfip->VccMin & 0xf); 343 printk("Vcc Minimum: %2d.%d V\n", cfip->VccMin >> 4, cfip->VccMin & 0xf);
344 printk("Vcc Maximum: %2d.%d V\n", cfip->VccMax >> 4, cfip->VccMax & 0xf); 344 printk("Vcc Maximum: %2d.%d V\n", cfip->VccMax >> 4, cfip->VccMax & 0xf);
345 if (cfip->VppMin) { 345 if (cfip->VppMin) {
@@ -348,61 +348,61 @@ static void print_cfi_ident(struct cfi_ident *cfip)
348 } 348 }
349 else 349 else
350 printk("No Vpp line\n"); 350 printk("No Vpp line\n");
351 351
352 printk("Typical byte/word write timeout: %d µs\n", 1<<cfip->WordWriteTimeoutTyp); 352 printk("Typical byte/word write timeout: %d µs\n", 1<<cfip->WordWriteTimeoutTyp);
353 printk("Maximum byte/word write timeout: %d µs\n", (1<<cfip->WordWriteTimeoutMax) * (1<<cfip->WordWriteTimeoutTyp)); 353 printk("Maximum byte/word write timeout: %d µs\n", (1<<cfip->WordWriteTimeoutMax) * (1<<cfip->WordWriteTimeoutTyp));
354 354
355 if (cfip->BufWriteTimeoutTyp || cfip->BufWriteTimeoutMax) { 355 if (cfip->BufWriteTimeoutTyp || cfip->BufWriteTimeoutMax) {
356 printk("Typical full buffer write timeout: %d µs\n", 1<<cfip->BufWriteTimeoutTyp); 356 printk("Typical full buffer write timeout: %d µs\n", 1<<cfip->BufWriteTimeoutTyp);
357 printk("Maximum full buffer write timeout: %d µs\n", (1<<cfip->BufWriteTimeoutMax) * (1<<cfip->BufWriteTimeoutTyp)); 357 printk("Maximum full buffer write timeout: %d µs\n", (1<<cfip->BufWriteTimeoutMax) * (1<<cfip->BufWriteTimeoutTyp));
358 } 358 }
359 else 359 else
360 printk("Full buffer write not supported\n"); 360 printk("Full buffer write not supported\n");
361 361
362 printk("Typical block erase timeout: %d ms\n", 1<<cfip->BlockEraseTimeoutTyp); 362 printk("Typical block erase timeout: %d ms\n", 1<<cfip->BlockEraseTimeoutTyp);
363 printk("Maximum block erase timeout: %d ms\n", (1<<cfip->BlockEraseTimeoutMax) * (1<<cfip->BlockEraseTimeoutTyp)); 363 printk("Maximum block erase timeout: %d ms\n", (1<<cfip->BlockEraseTimeoutMax) * (1<<cfip->BlockEraseTimeoutTyp));
364 if (cfip->ChipEraseTimeoutTyp || cfip->ChipEraseTimeoutMax) { 364 if (cfip->ChipEraseTimeoutTyp || cfip->ChipEraseTimeoutMax) {
365 printk("Typical chip erase timeout: %d ms\n", 1<<cfip->ChipEraseTimeoutTyp); 365 printk("Typical chip erase timeout: %d ms\n", 1<<cfip->ChipEraseTimeoutTyp);
366 printk("Maximum chip erase timeout: %d ms\n", (1<<cfip->ChipEraseTimeoutMax) * (1<<cfip->ChipEraseTimeoutTyp)); 366 printk("Maximum chip erase timeout: %d ms\n", (1<<cfip->ChipEraseTimeoutMax) * (1<<cfip->ChipEraseTimeoutTyp));
367 } 367 }
368 else 368 else
369 printk("Chip erase not supported\n"); 369 printk("Chip erase not supported\n");
370 370
371 printk("Device size: 0x%X bytes (%d MiB)\n", 1 << cfip->DevSize, 1<< (cfip->DevSize - 20)); 371 printk("Device size: 0x%X bytes (%d MiB)\n", 1 << cfip->DevSize, 1<< (cfip->DevSize - 20));
372 printk("Flash Device Interface description: 0x%4.4X\n", cfip->InterfaceDesc); 372 printk("Flash Device Interface description: 0x%4.4X\n", cfip->InterfaceDesc);
373 switch(cfip->InterfaceDesc) { 373 switch(cfip->InterfaceDesc) {
374 case 0: 374 case 0:
375 printk(" - x8-only asynchronous interface\n"); 375 printk(" - x8-only asynchronous interface\n");
376 break; 376 break;
377 377
378 case 1: 378 case 1:
379 printk(" - x16-only asynchronous interface\n"); 379 printk(" - x16-only asynchronous interface\n");
380 break; 380 break;
381 381
382 case 2: 382 case 2:
383 printk(" - supports x8 and x16 via BYTE# with asynchronous interface\n"); 383 printk(" - supports x8 and x16 via BYTE# with asynchronous interface\n");
384 break; 384 break;
385 385
386 case 3: 386 case 3:
387 printk(" - x32-only asynchronous interface\n"); 387 printk(" - x32-only asynchronous interface\n");
388 break; 388 break;
389 389
390 case 4: 390 case 4:
391 printk(" - supports x16 and x32 via Word# with asynchronous interface\n"); 391 printk(" - supports x16 and x32 via Word# with asynchronous interface\n");
392 break; 392 break;
393 393
394 case 65535: 394 case 65535:
395 printk(" - Not Allowed / Reserved\n"); 395 printk(" - Not Allowed / Reserved\n");
396 break; 396 break;
397 397
398 default: 398 default:
399 printk(" - Unknown\n"); 399 printk(" - Unknown\n");
400 break; 400 break;
401 } 401 }
402 402
403 printk("Max. bytes in buffer write: 0x%x\n", 1<< cfip->MaxBufWriteSize); 403 printk("Max. bytes in buffer write: 0x%x\n", 1<< cfip->MaxBufWriteSize);
404 printk("Number of Erase Block Regions: %d\n", cfip->NumEraseRegions); 404 printk("Number of Erase Block Regions: %d\n", cfip->NumEraseRegions);
405 405
406} 406}
407#endif /* DEBUG_CFI */ 407#endif /* DEBUG_CFI */
408 408
diff --git a/drivers/mtd/chips/cfi_util.c b/drivers/mtd/chips/cfi_util.c
index 2b2ede2bfcca..d8e7a026ba5a 100644
--- a/drivers/mtd/chips/cfi_util.c
+++ b/drivers/mtd/chips/cfi_util.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * This code is covered by the GPL. 8 * This code is covered by the GPL.
9 * 9 *
10 * $Id: cfi_util.c,v 1.8 2004/12/14 19:55:56 nico Exp $ 10 * $Id: cfi_util.c,v 1.10 2005/11/07 11:14:23 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -56,7 +56,7 @@ __xipram cfi_read_pri(struct map_info *map, __u16 adr, __u16 size, const char* n
56 56
57 /* Read in the Extended Query Table */ 57 /* Read in the Extended Query Table */
58 for (i=0; i<size; i++) { 58 for (i=0; i<size; i++) {
59 ((unsigned char *)extp)[i] = 59 ((unsigned char *)extp)[i] =
60 cfi_read_query(map, base+((adr+i)*ofs_factor)); 60 cfi_read_query(map, base+((adr+i)*ofs_factor));
61 } 61 }
62 62
@@ -70,15 +70,6 @@ __xipram cfi_read_pri(struct map_info *map, __u16 adr, __u16 size, const char* n
70 local_irq_enable(); 70 local_irq_enable();
71#endif 71#endif
72 72
73 if (extp->MajorVersion != '1' ||
74 (extp->MinorVersion < '0' || extp->MinorVersion > '3')) {
75 printk(KERN_WARNING " Unknown %s Extended Query "
76 "version %c.%c.\n", name, extp->MajorVersion,
77 extp->MinorVersion);
78 kfree(extp);
79 extp = NULL;
80 }
81
82 out: return extp; 73 out: return extp;
83} 74}
84 75
@@ -122,17 +113,17 @@ int cfi_varsize_frob(struct mtd_info *mtd, varsize_frob_t frob,
122 113
123 i = 0; 114 i = 0;
124 115
125 /* Skip all erase regions which are ended before the start of 116 /* Skip all erase regions which are ended before the start of
126 the requested erase. Actually, to save on the calculations, 117 the requested erase. Actually, to save on the calculations,
127 we skip to the first erase region which starts after the 118 we skip to the first erase region which starts after the
128 start of the requested erase, and then go back one. 119 start of the requested erase, and then go back one.
129 */ 120 */
130 121
131 while (i < mtd->numeraseregions && ofs >= regions[i].offset) 122 while (i < mtd->numeraseregions && ofs >= regions[i].offset)
132 i++; 123 i++;
133 i--; 124 i--;
134 125
135 /* OK, now i is pointing at the erase region in which this 126 /* OK, now i is pointing at the erase region in which this
136 erase request starts. Check the start of the requested 127 erase request starts. Check the start of the requested
137 erase range is aligned with the erase size which is in 128 erase range is aligned with the erase size which is in
138 effect here. 129 effect here.
@@ -155,7 +146,7 @@ int cfi_varsize_frob(struct mtd_info *mtd, varsize_frob_t frob,
155 the address actually falls 146 the address actually falls
156 */ 147 */
157 i--; 148 i--;
158 149
159 if ((ofs + len) & (regions[i].erasesize-1)) 150 if ((ofs + len) & (regions[i].erasesize-1))
160 return -EINVAL; 151 return -EINVAL;
161 152
@@ -168,7 +159,7 @@ int cfi_varsize_frob(struct mtd_info *mtd, varsize_frob_t frob,
168 int size = regions[i].erasesize; 159 int size = regions[i].erasesize;
169 160
170 ret = (*frob)(map, &cfi->chips[chipnum], adr, size, thunk); 161 ret = (*frob)(map, &cfi->chips[chipnum], adr, size, thunk);
171 162
172 if (ret) 163 if (ret)
173 return ret; 164 return ret;
174 165
@@ -182,7 +173,7 @@ int cfi_varsize_frob(struct mtd_info *mtd, varsize_frob_t frob,
182 if (adr >> cfi->chipshift) { 173 if (adr >> cfi->chipshift) {
183 adr = 0; 174 adr = 0;
184 chipnum++; 175 chipnum++;
185 176
186 if (chipnum >= cfi->numchips) 177 if (chipnum >= cfi->numchips)
187 break; 178 break;
188 } 179 }
diff --git a/drivers/mtd/chips/chipreg.c b/drivers/mtd/chips/chipreg.c
index d7d739a108ae..c2127840a183 100644
--- a/drivers/mtd/chips/chipreg.c
+++ b/drivers/mtd/chips/chipreg.c
@@ -41,7 +41,7 @@ static struct mtd_chip_driver *get_mtd_chip_driver (const char *name)
41 41
42 list_for_each(pos, &chip_drvs_list) { 42 list_for_each(pos, &chip_drvs_list) {
43 this = list_entry(pos, typeof(*this), list); 43 this = list_entry(pos, typeof(*this), list);
44 44
45 if (!strcmp(this->name, name)) { 45 if (!strcmp(this->name, name)) {
46 ret = this; 46 ret = this;
47 break; 47 break;
@@ -73,7 +73,7 @@ struct mtd_info *do_map_probe(const char *name, struct map_info *map)
73 73
74 ret = drv->probe(map); 74 ret = drv->probe(map);
75 75
76 /* We decrease the use count here. It may have been a 76 /* We decrease the use count here. It may have been a
77 probe-only module, which is no longer required from this 77 probe-only module, which is no longer required from this
78 point, having given us a handle on (and increased the use 78 point, having given us a handle on (and increased the use
79 count of) the actual driver code. 79 count of) the actual driver code.
@@ -82,7 +82,7 @@ struct mtd_info *do_map_probe(const char *name, struct map_info *map)
82 82
83 if (ret) 83 if (ret)
84 return ret; 84 return ret;
85 85
86 return NULL; 86 return NULL;
87} 87}
88/* 88/*
diff --git a/drivers/mtd/chips/fwh_lock.h b/drivers/mtd/chips/fwh_lock.h
index e1a5b76596c5..77303ce5dcf1 100644
--- a/drivers/mtd/chips/fwh_lock.h
+++ b/drivers/mtd/chips/fwh_lock.h
@@ -25,7 +25,7 @@ struct fwh_xxlock_thunk {
25 * so this code has not been tested with interleaved chips, 25 * so this code has not been tested with interleaved chips,
26 * and will likely fail in that context. 26 * and will likely fail in that context.
27 */ 27 */
28static int fwh_xxlock_oneblock(struct map_info *map, struct flchip *chip, 28static int fwh_xxlock_oneblock(struct map_info *map, struct flchip *chip,
29 unsigned long adr, int len, void *thunk) 29 unsigned long adr, int len, void *thunk)
30{ 30{
31 struct cfi_private *cfi = map->fldrv_priv; 31 struct cfi_private *cfi = map->fldrv_priv;
@@ -44,7 +44,7 @@ static int fwh_xxlock_oneblock(struct map_info *map, struct flchip *chip,
44 * - on 64k boundariesand 44 * - on 64k boundariesand
45 * - bit 1 set high 45 * - bit 1 set high
46 * - block lock registers are 4MiB lower - overflow subtract (danger) 46 * - block lock registers are 4MiB lower - overflow subtract (danger)
47 * 47 *
48 * The address manipulation is first done on the logical address 48 * The address manipulation is first done on the logical address
49 * which is 0 at the start of the chip, and then the offset of 49 * which is 0 at the start of the chip, and then the offset of
50 * the individual chip is addted to it. Any other order a weird 50 * the individual chip is addted to it. Any other order a weird
@@ -93,7 +93,7 @@ static int fwh_unlock_varsize(struct mtd_info *mtd, loff_t ofs, size_t len)
93 93
94 ret = cfi_varsize_frob(mtd, fwh_xxlock_oneblock, ofs, len, 94 ret = cfi_varsize_frob(mtd, fwh_xxlock_oneblock, ofs, len,
95 (void *)&FWH_XXLOCK_ONEBLOCK_UNLOCK); 95 (void *)&FWH_XXLOCK_ONEBLOCK_UNLOCK);
96 96
97 return ret; 97 return ret;
98} 98}
99 99
diff --git a/drivers/mtd/chips/gen_probe.c b/drivers/mtd/chips/gen_probe.c
index dc065b22f79e..41bd59d20d85 100644
--- a/drivers/mtd/chips/gen_probe.c
+++ b/drivers/mtd/chips/gen_probe.c
@@ -2,7 +2,7 @@
2 * Routines common to all CFI-type probes. 2 * Routines common to all CFI-type probes.
3 * (C) 2001-2003 Red Hat, Inc. 3 * (C) 2001-2003 Red Hat, Inc.
4 * GPL'd 4 * GPL'd
5 * $Id: gen_probe.c,v 1.22 2005/01/24 23:49:50 rmk Exp $ 5 * $Id: gen_probe.c,v 1.24 2005/11/07 11:14:23 gleixner Exp $
6 */ 6 */
7 7
8#include <linux/kernel.h> 8#include <linux/kernel.h>
@@ -26,7 +26,7 @@ struct mtd_info *mtd_do_chip_probe(struct map_info *map, struct chip_probe *cp)
26 26
27 /* First probe the map to see if we have CFI stuff there. */ 27 /* First probe the map to see if we have CFI stuff there. */
28 cfi = genprobe_ident_chips(map, cp); 28 cfi = genprobe_ident_chips(map, cp);
29 29
30 if (!cfi) 30 if (!cfi)
31 return NULL; 31 return NULL;
32 32
@@ -36,12 +36,12 @@ struct mtd_info *mtd_do_chip_probe(struct map_info *map, struct chip_probe *cp)
36 mtd = check_cmd_set(map, 1); /* First the primary cmdset */ 36 mtd = check_cmd_set(map, 1); /* First the primary cmdset */
37 if (!mtd) 37 if (!mtd)
38 mtd = check_cmd_set(map, 0); /* Then the secondary */ 38 mtd = check_cmd_set(map, 0); /* Then the secondary */
39 39
40 if (mtd) 40 if (mtd)
41 return mtd; 41 return mtd;
42 42
43 printk(KERN_WARNING"gen_probe: No supported Vendor Command Set found\n"); 43 printk(KERN_WARNING"gen_probe: No supported Vendor Command Set found\n");
44 44
45 kfree(cfi->cfiq); 45 kfree(cfi->cfiq);
46 kfree(cfi); 46 kfree(cfi);
47 map->fldrv_priv = NULL; 47 map->fldrv_priv = NULL;
@@ -60,14 +60,14 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi
60 60
61 memset(&cfi, 0, sizeof(cfi)); 61 memset(&cfi, 0, sizeof(cfi));
62 62
63 /* Call the probetype-specific code with all permutations of 63 /* Call the probetype-specific code with all permutations of
64 interleave and device type, etc. */ 64 interleave and device type, etc. */
65 if (!genprobe_new_chip(map, cp, &cfi)) { 65 if (!genprobe_new_chip(map, cp, &cfi)) {
66 /* The probe didn't like it */ 66 /* The probe didn't like it */
67 printk(KERN_DEBUG "%s: Found no %s device at location zero\n", 67 printk(KERN_DEBUG "%s: Found no %s device at location zero\n",
68 cp->name, map->name); 68 cp->name, map->name);
69 return NULL; 69 return NULL;
70 } 70 }
71 71
72#if 0 /* Let the CFI probe routine do this sanity check. The Intel and AMD 72#if 0 /* Let the CFI probe routine do this sanity check. The Intel and AMD
73 probe routines won't ever return a broken CFI structure anyway, 73 probe routines won't ever return a broken CFI structure anyway,
@@ -92,13 +92,13 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi
92 } else { 92 } else {
93 BUG(); 93 BUG();
94 } 94 }
95 95
96 cfi.numchips = 1; 96 cfi.numchips = 1;
97 97
98 /* 98 /*
99 * Allocate memory for bitmap of valid chips. 99 * Allocate memory for bitmap of valid chips.
100 * Align bitmap storage size to full byte. 100 * Align bitmap storage size to full byte.
101 */ 101 */
102 max_chips = map->size >> cfi.chipshift; 102 max_chips = map->size >> cfi.chipshift;
103 mapsize = (max_chips / 8) + ((max_chips % 8) ? 1 : 0); 103 mapsize = (max_chips / 8) + ((max_chips % 8) ? 1 : 0);
104 chip_map = kmalloc(mapsize, GFP_KERNEL); 104 chip_map = kmalloc(mapsize, GFP_KERNEL);
@@ -122,7 +122,7 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi
122 } 122 }
123 123
124 /* 124 /*
125 * Now allocate the space for the structures we need to return to 125 * Now allocate the space for the structures we need to return to
126 * our caller, and copy the appropriate data into them. 126 * our caller, and copy the appropriate data into them.
127 */ 127 */
128 128
@@ -154,7 +154,7 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi
154 return retcfi; 154 return retcfi;
155} 155}
156 156
157 157
158static int genprobe_new_chip(struct map_info *map, struct chip_probe *cp, 158static int genprobe_new_chip(struct map_info *map, struct chip_probe *cp,
159 struct cfi_private *cfi) 159 struct cfi_private *cfi)
160{ 160{
@@ -189,7 +189,7 @@ extern cfi_cmdset_fn_t cfi_cmdset_0001;
189extern cfi_cmdset_fn_t cfi_cmdset_0002; 189extern cfi_cmdset_fn_t cfi_cmdset_0002;
190extern cfi_cmdset_fn_t cfi_cmdset_0020; 190extern cfi_cmdset_fn_t cfi_cmdset_0020;
191 191
192static inline struct mtd_info *cfi_cmdset_unknown(struct map_info *map, 192static inline struct mtd_info *cfi_cmdset_unknown(struct map_info *map,
193 int primary) 193 int primary)
194{ 194{
195 struct cfi_private *cfi = map->fldrv_priv; 195 struct cfi_private *cfi = map->fldrv_priv;
@@ -199,7 +199,7 @@ static inline struct mtd_info *cfi_cmdset_unknown(struct map_info *map,
199 cfi_cmdset_fn_t *probe_function; 199 cfi_cmdset_fn_t *probe_function;
200 200
201 sprintf(probename, "cfi_cmdset_%4.4X", type); 201 sprintf(probename, "cfi_cmdset_%4.4X", type);
202 202
203 probe_function = inter_module_get_request(probename, probename); 203 probe_function = inter_module_get_request(probename, probename);
204 204
205 if (probe_function) { 205 if (probe_function) {
@@ -221,7 +221,7 @@ static struct mtd_info *check_cmd_set(struct map_info *map, int primary)
221{ 221{
222 struct cfi_private *cfi = map->fldrv_priv; 222 struct cfi_private *cfi = map->fldrv_priv;
223 __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID; 223 __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID;
224 224
225 if (type == P_ID_NONE || type == P_ID_RESERVED) 225 if (type == P_ID_NONE || type == P_ID_RESERVED)
226 return NULL; 226 return NULL;
227 227
@@ -235,6 +235,7 @@ static struct mtd_info *check_cmd_set(struct map_info *map, int primary)
235#ifdef CONFIG_MTD_CFI_INTELEXT 235#ifdef CONFIG_MTD_CFI_INTELEXT
236 case 0x0001: 236 case 0x0001:
237 case 0x0003: 237 case 0x0003:
238 case 0x0200:
238 return cfi_cmdset_0001(map, primary); 239 return cfi_cmdset_0001(map, primary);
239#endif 240#endif
240#ifdef CONFIG_MTD_CFI_AMDSTD 241#ifdef CONFIG_MTD_CFI_AMDSTD
diff --git a/drivers/mtd/chips/jedec.c b/drivers/mtd/chips/jedec.c
index 4f6778f3ee3e..c40b48dabed3 100644
--- a/drivers/mtd/chips/jedec.c
+++ b/drivers/mtd/chips/jedec.c
@@ -1,6 +1,6 @@
1 1
2/* JEDEC Flash Interface. 2/* JEDEC Flash Interface.
3 * This is an older type of interface for self programming flash. It is 3 * This is an older type of interface for self programming flash. It is
4 * commonly use in older AMD chips and is obsolete compared with CFI. 4 * commonly use in older AMD chips and is obsolete compared with CFI.
5 * It is called JEDEC because the JEDEC association distributes the ID codes 5 * It is called JEDEC because the JEDEC association distributes the ID codes
6 * for the chips. 6 * for the chips.
@@ -88,9 +88,9 @@ static const struct JEDECTable JEDEC_table[] = {
88 88
89static const struct JEDECTable *jedec_idtoinf(__u8 mfr,__u8 id); 89static const struct JEDECTable *jedec_idtoinf(__u8 mfr,__u8 id);
90static void jedec_sync(struct mtd_info *mtd) {}; 90static void jedec_sync(struct mtd_info *mtd) {};
91static int jedec_read(struct mtd_info *mtd, loff_t from, size_t len, 91static int jedec_read(struct mtd_info *mtd, loff_t from, size_t len,
92 size_t *retlen, u_char *buf); 92 size_t *retlen, u_char *buf);
93static int jedec_read_banked(struct mtd_info *mtd, loff_t from, size_t len, 93static int jedec_read_banked(struct mtd_info *mtd, loff_t from, size_t len,
94 size_t *retlen, u_char *buf); 94 size_t *retlen, u_char *buf);
95 95
96static struct mtd_info *jedec_probe(struct map_info *map); 96static struct mtd_info *jedec_probe(struct map_info *map);
@@ -122,7 +122,7 @@ static struct mtd_info *jedec_probe(struct map_info *map)
122 122
123 memset(MTD, 0, sizeof(struct mtd_info) + sizeof(struct jedec_private)); 123 memset(MTD, 0, sizeof(struct mtd_info) + sizeof(struct jedec_private));
124 priv = (struct jedec_private *)&MTD[1]; 124 priv = (struct jedec_private *)&MTD[1];
125 125
126 my_bank_size = map->size; 126 my_bank_size = map->size;
127 127
128 if (map->size/my_bank_size > MAX_JEDEC_CHIPS) 128 if (map->size/my_bank_size > MAX_JEDEC_CHIPS)
@@ -131,13 +131,13 @@ static struct mtd_info *jedec_probe(struct map_info *map)
131 kfree(MTD); 131 kfree(MTD);
132 return NULL; 132 return NULL;
133 } 133 }
134 134
135 for (Base = 0; Base < map->size; Base += my_bank_size) 135 for (Base = 0; Base < map->size; Base += my_bank_size)
136 { 136 {
137 // Perhaps zero could designate all tests? 137 // Perhaps zero could designate all tests?
138 if (map->buswidth == 0) 138 if (map->buswidth == 0)
139 map->buswidth = 1; 139 map->buswidth = 1;
140 140
141 if (map->buswidth == 1){ 141 if (map->buswidth == 1){
142 if (jedec_probe8(map,Base,priv) == 0) { 142 if (jedec_probe8(map,Base,priv) == 0) {
143 printk("did recognize jedec chip\n"); 143 printk("did recognize jedec chip\n");
@@ -150,7 +150,7 @@ static struct mtd_info *jedec_probe(struct map_info *map)
150 if (map->buswidth == 4) 150 if (map->buswidth == 4)
151 jedec_probe32(map,Base,priv); 151 jedec_probe32(map,Base,priv);
152 } 152 }
153 153
154 // Get the biggest sector size 154 // Get the biggest sector size
155 SectorSize = 0; 155 SectorSize = 0;
156 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++) 156 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
@@ -160,7 +160,7 @@ static struct mtd_info *jedec_probe(struct map_info *map)
160 if (priv->chips[I].sectorsize > SectorSize) 160 if (priv->chips[I].sectorsize > SectorSize)
161 SectorSize = priv->chips[I].sectorsize; 161 SectorSize = priv->chips[I].sectorsize;
162 } 162 }
163 163
164 // Quickly ensure that the other sector sizes are factors of the largest 164 // Quickly ensure that the other sector sizes are factors of the largest
165 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++) 165 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
166 { 166 {
@@ -169,9 +169,9 @@ static struct mtd_info *jedec_probe(struct map_info *map)
169 printk("mtd: Failed. Device has incompatible mixed sector sizes\n"); 169 printk("mtd: Failed. Device has incompatible mixed sector sizes\n");
170 kfree(MTD); 170 kfree(MTD);
171 return NULL; 171 return NULL;
172 } 172 }
173 } 173 }
174 174
175 /* Generate a part name that includes the number of different chips and 175 /* Generate a part name that includes the number of different chips and
176 other configuration information */ 176 other configuration information */
177 count = 1; 177 count = 1;
@@ -181,13 +181,13 @@ static struct mtd_info *jedec_probe(struct map_info *map)
181 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++) 181 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
182 { 182 {
183 const struct JEDECTable *JEDEC; 183 const struct JEDECTable *JEDEC;
184 184
185 if (priv->chips[I+1].jedec == priv->chips[I].jedec) 185 if (priv->chips[I+1].jedec == priv->chips[I].jedec)
186 { 186 {
187 count++; 187 count++;
188 continue; 188 continue;
189 } 189 }
190 190
191 // Locate the chip in the jedec table 191 // Locate the chip in the jedec table
192 JEDEC = jedec_idtoinf(priv->chips[I].jedec >> 8,priv->chips[I].jedec); 192 JEDEC = jedec_idtoinf(priv->chips[I].jedec >> 8,priv->chips[I].jedec);
193 if (JEDEC == 0) 193 if (JEDEC == 0)
@@ -196,11 +196,11 @@ static struct mtd_info *jedec_probe(struct map_info *map)
196 kfree(MTD); 196 kfree(MTD);
197 return NULL; 197 return NULL;
198 } 198 }
199 199
200 if (Uniq != 0) 200 if (Uniq != 0)
201 strcat(Part,","); 201 strcat(Part,",");
202 Uniq++; 202 Uniq++;
203 203
204 if (count != 1) 204 if (count != 1)
205 sprintf(Part+strlen(Part),"%x*[%s]",count,JEDEC->name); 205 sprintf(Part+strlen(Part),"%x*[%s]",count,JEDEC->name);
206 else 206 else
@@ -208,7 +208,7 @@ static struct mtd_info *jedec_probe(struct map_info *map)
208 if (strlen(Part) > sizeof(Part)*2/3) 208 if (strlen(Part) > sizeof(Part)*2/3)
209 break; 209 break;
210 count = 1; 210 count = 1;
211 } 211 }
212 212
213 /* Determine if the chips are organized in a linear fashion, or if there 213 /* Determine if the chips are organized in a linear fashion, or if there
214 are empty banks. Note, the last bank does not count here, only the 214 are empty banks. Note, the last bank does not count here, only the
@@ -233,7 +233,7 @@ static struct mtd_info *jedec_probe(struct map_info *map)
233 { 233 {
234 if (priv->bank_fill[I] != my_bank_size) 234 if (priv->bank_fill[I] != my_bank_size)
235 priv->is_banked = 1; 235 priv->is_banked = 1;
236 236
237 /* This even could be eliminated, but new de-optimized read/write 237 /* This even could be eliminated, but new de-optimized read/write
238 functions have to be written */ 238 functions have to be written */
239 printk("priv->bank_fill[%d] is %lx, priv->bank_fill[0] is %lx\n",I,priv->bank_fill[I],priv->bank_fill[0]); 239 printk("priv->bank_fill[%d] is %lx, priv->bank_fill[0] is %lx\n",I,priv->bank_fill[I],priv->bank_fill[0]);
@@ -242,7 +242,7 @@ static struct mtd_info *jedec_probe(struct map_info *map)
242 printk("mtd: Failed. Cannot handle unsymmetric banking\n"); 242 printk("mtd: Failed. Cannot handle unsymmetric banking\n");
243 kfree(MTD); 243 kfree(MTD);
244 return NULL; 244 return NULL;
245 } 245 }
246 } 246 }
247 } 247 }
248 } 248 }
@@ -250,7 +250,7 @@ static struct mtd_info *jedec_probe(struct map_info *map)
250 strcat(Part,", banked"); 250 strcat(Part,", banked");
251 251
252 // printk("Part: '%s'\n",Part); 252 // printk("Part: '%s'\n",Part);
253 253
254 memset(MTD,0,sizeof(*MTD)); 254 memset(MTD,0,sizeof(*MTD));
255 // strlcpy(MTD->name,Part,sizeof(MTD->name)); 255 // strlcpy(MTD->name,Part,sizeof(MTD->name));
256 MTD->name = map->name; 256 MTD->name = map->name;
@@ -291,7 +291,7 @@ static int checkparity(u_char C)
291 291
292/* Take an array of JEDEC numbers that represent interleved flash chips 292/* Take an array of JEDEC numbers that represent interleved flash chips
293 and process them. Check to make sure they are good JEDEC numbers, look 293 and process them. Check to make sure they are good JEDEC numbers, look
294 them up and then add them to the chip list */ 294 them up and then add them to the chip list */
295static int handle_jedecs(struct map_info *map,__u8 *Mfg,__u8 *Id,unsigned Count, 295static int handle_jedecs(struct map_info *map,__u8 *Mfg,__u8 *Id,unsigned Count,
296 unsigned long base,struct jedec_private *priv) 296 unsigned long base,struct jedec_private *priv)
297{ 297{
@@ -306,16 +306,16 @@ static int handle_jedecs(struct map_info *map,__u8 *Mfg,__u8 *Id,unsigned Count,
306 if (checkparity(Mfg[I]) == 0 || checkparity(Id[I]) == 0) 306 if (checkparity(Mfg[I]) == 0 || checkparity(Id[I]) == 0)
307 return 0; 307 return 0;
308 } 308 }
309 309
310 // Finally, just make sure all the chip sizes are the same 310 // Finally, just make sure all the chip sizes are the same
311 JEDEC = jedec_idtoinf(Mfg[0],Id[0]); 311 JEDEC = jedec_idtoinf(Mfg[0],Id[0]);
312 312
313 if (JEDEC == 0) 313 if (JEDEC == 0)
314 { 314 {
315 printk("mtd: Found JEDEC flash chip, but do not have a table entry for %x:%x\n",Mfg[0],Mfg[1]); 315 printk("mtd: Found JEDEC flash chip, but do not have a table entry for %x:%x\n",Mfg[0],Mfg[1]);
316 return 0; 316 return 0;
317 } 317 }
318 318
319 Size = JEDEC->size; 319 Size = JEDEC->size;
320 SectorSize = JEDEC->sectorsize; 320 SectorSize = JEDEC->sectorsize;
321 for (I = 0; I != Count; I++) 321 for (I = 0; I != Count; I++)
@@ -331,7 +331,7 @@ static int handle_jedecs(struct map_info *map,__u8 *Mfg,__u8 *Id,unsigned Count,
331 { 331 {
332 printk("mtd: Failed. Interleved flash does not have matching characteristics\n"); 332 printk("mtd: Failed. Interleved flash does not have matching characteristics\n");
333 return 0; 333 return 0;
334 } 334 }
335 } 335 }
336 336
337 // Load the Chips 337 // Load the Chips
@@ -345,13 +345,13 @@ static int handle_jedecs(struct map_info *map,__u8 *Mfg,__u8 *Id,unsigned Count,
345 { 345 {
346 printk("mtd: Device has too many chips. Increase MAX_JEDEC_CHIPS\n"); 346 printk("mtd: Device has too many chips. Increase MAX_JEDEC_CHIPS\n");
347 return 0; 347 return 0;
348 } 348 }
349 349
350 // Add them to the table 350 // Add them to the table
351 for (J = 0; J != Count; J++) 351 for (J = 0; J != Count; J++)
352 { 352 {
353 unsigned long Bank; 353 unsigned long Bank;
354 354
355 JEDEC = jedec_idtoinf(Mfg[J],Id[J]); 355 JEDEC = jedec_idtoinf(Mfg[J],Id[J]);
356 priv->chips[I].jedec = (Mfg[J] << 8) | Id[J]; 356 priv->chips[I].jedec = (Mfg[J] << 8) | Id[J];
357 priv->chips[I].size = JEDEC->size; 357 priv->chips[I].size = JEDEC->size;
@@ -364,17 +364,17 @@ static int handle_jedecs(struct map_info *map,__u8 *Mfg,__u8 *Id,unsigned Count,
364 // log2 n :| 364 // log2 n :|
365 priv->chips[I].addrshift = 0; 365 priv->chips[I].addrshift = 0;
366 for (Bank = Count; Bank != 1; Bank >>= 1, priv->chips[I].addrshift++); 366 for (Bank = Count; Bank != 1; Bank >>= 1, priv->chips[I].addrshift++);
367 367
368 // Determine how filled this bank is. 368 // Determine how filled this bank is.
369 Bank = base & (~(my_bank_size-1)); 369 Bank = base & (~(my_bank_size-1));
370 if (priv->bank_fill[Bank/my_bank_size] < base + 370 if (priv->bank_fill[Bank/my_bank_size] < base +
371 (JEDEC->size << priv->chips[I].addrshift) - Bank) 371 (JEDEC->size << priv->chips[I].addrshift) - Bank)
372 priv->bank_fill[Bank/my_bank_size] = base + (JEDEC->size << priv->chips[I].addrshift) - Bank; 372 priv->bank_fill[Bank/my_bank_size] = base + (JEDEC->size << priv->chips[I].addrshift) - Bank;
373 I++; 373 I++;
374 } 374 }
375 375
376 priv->size += priv->chips[I-1].size*Count; 376 priv->size += priv->chips[I-1].size*Count;
377 377
378 return priv->chips[I-1].size; 378 return priv->chips[I-1].size;
379} 379}
380 380
@@ -392,7 +392,7 @@ static const struct JEDECTable *jedec_idtoinf(__u8 mfr,__u8 id)
392// Look for flash using an 8 bit bus interface 392// Look for flash using an 8 bit bus interface
393static int jedec_probe8(struct map_info *map,unsigned long base, 393static int jedec_probe8(struct map_info *map,unsigned long base,
394 struct jedec_private *priv) 394 struct jedec_private *priv)
395{ 395{
396 #define flread(x) map_read8(map,base+x) 396 #define flread(x) map_read8(map,base+x)
397 #define flwrite(v,x) map_write8(map,v,base+x) 397 #define flwrite(v,x) map_write8(map,v,base+x)
398 398
@@ -410,20 +410,20 @@ static int jedec_probe8(struct map_info *map,unsigned long base,
410 OldVal = flread(base); 410 OldVal = flread(base);
411 for (I = 0; OldVal != flread(base) && I < 10000; I++) 411 for (I = 0; OldVal != flread(base) && I < 10000; I++)
412 OldVal = flread(base); 412 OldVal = flread(base);
413 413
414 // Reset the chip 414 // Reset the chip
415 flwrite(Reset,0x555); 415 flwrite(Reset,0x555);
416 416
417 // Send the sequence 417 // Send the sequence
418 flwrite(AutoSel1,0x555); 418 flwrite(AutoSel1,0x555);
419 flwrite(AutoSel2,0x2AA); 419 flwrite(AutoSel2,0x2AA);
420 flwrite(AutoSel3,0x555); 420 flwrite(AutoSel3,0x555);
421 421
422 // Get the JEDEC numbers 422 // Get the JEDEC numbers
423 Mfg[0] = flread(0); 423 Mfg[0] = flread(0);
424 Id[0] = flread(1); 424 Id[0] = flread(1);
425 // printk("Mfg is %x, Id is %x\n",Mfg[0],Id[0]); 425 // printk("Mfg is %x, Id is %x\n",Mfg[0],Id[0]);
426 426
427 Size = handle_jedecs(map,Mfg,Id,1,base,priv); 427 Size = handle_jedecs(map,Mfg,Id,1,base,priv);
428 // printk("handle_jedecs Size is %x\n",(unsigned int)Size); 428 // printk("handle_jedecs Size is %x\n",(unsigned int)Size);
429 if (Size == 0) 429 if (Size == 0)
@@ -431,13 +431,13 @@ static int jedec_probe8(struct map_info *map,unsigned long base,
431 flwrite(Reset,0x555); 431 flwrite(Reset,0x555);
432 return 0; 432 return 0;
433 } 433 }
434 434
435 435
436 // Reset. 436 // Reset.
437 flwrite(Reset,0x555); 437 flwrite(Reset,0x555);
438 438
439 return 1; 439 return 1;
440 440
441 #undef flread 441 #undef flread
442 #undef flwrite 442 #undef flwrite
443} 443}
@@ -470,17 +470,17 @@ static int jedec_probe32(struct map_info *map,unsigned long base,
470 OldVal = flread(base); 470 OldVal = flread(base);
471 for (I = 0; OldVal != flread(base) && I < 10000; I++) 471 for (I = 0; OldVal != flread(base) && I < 10000; I++)
472 OldVal = flread(base); 472 OldVal = flread(base);
473 473
474 // Reset the chip 474 // Reset the chip
475 flwrite(Reset,0x555); 475 flwrite(Reset,0x555);
476 476
477 // Send the sequence 477 // Send the sequence
478 flwrite(AutoSel1,0x555); 478 flwrite(AutoSel1,0x555);
479 flwrite(AutoSel2,0x2AA); 479 flwrite(AutoSel2,0x2AA);
480 flwrite(AutoSel3,0x555); 480 flwrite(AutoSel3,0x555);
481 481
482 // Test #1, JEDEC numbers are readable from 0x??00/0x??01 482 // Test #1, JEDEC numbers are readable from 0x??00/0x??01
483 if (flread(0) != flread(0x100) || 483 if (flread(0) != flread(0x100) ||
484 flread(1) != flread(0x101)) 484 flread(1) != flread(0x101))
485 { 485 {
486 flwrite(Reset,0x555); 486 flwrite(Reset,0x555);
@@ -494,14 +494,14 @@ static int jedec_probe32(struct map_info *map,unsigned long base,
494 OldVal = flread(1); 494 OldVal = flread(1);
495 for (I = 0; I != 4; I++) 495 for (I = 0; I != 4; I++)
496 Id[I] = (OldVal >> (I*8)); 496 Id[I] = (OldVal >> (I*8));
497 497
498 Size = handle_jedecs(map,Mfg,Id,4,base,priv); 498 Size = handle_jedecs(map,Mfg,Id,4,base,priv);
499 if (Size == 0) 499 if (Size == 0)
500 { 500 {
501 flwrite(Reset,0x555); 501 flwrite(Reset,0x555);
502 return 0; 502 return 0;
503 } 503 }
504 504
505 /* Check if there is address wrap around within a single bank, if this 505 /* Check if there is address wrap around within a single bank, if this
506 returns JEDEC numbers then we assume that it is wrap around. Notice 506 returns JEDEC numbers then we assume that it is wrap around. Notice
507 we call this routine with the JEDEC return still enabled, if two or 507 we call this routine with the JEDEC return still enabled, if two or
@@ -519,27 +519,27 @@ static int jedec_probe32(struct map_info *map,unsigned long base,
519 519
520 // Reset. 520 // Reset.
521 flwrite(0xF0F0F0F0,0x555); 521 flwrite(0xF0F0F0F0,0x555);
522 522
523 return 1; 523 return 1;
524 524
525 #undef flread 525 #undef flread
526 #undef flwrite 526 #undef flwrite
527} 527}
528 528
529/* Linear read. */ 529/* Linear read. */
530static int jedec_read(struct mtd_info *mtd, loff_t from, size_t len, 530static int jedec_read(struct mtd_info *mtd, loff_t from, size_t len,
531 size_t *retlen, u_char *buf) 531 size_t *retlen, u_char *buf)
532{ 532{
533 struct map_info *map = mtd->priv; 533 struct map_info *map = mtd->priv;
534 534
535 map_copy_from(map, buf, from, len); 535 map_copy_from(map, buf, from, len);
536 *retlen = len; 536 *retlen = len;
537 return 0; 537 return 0;
538} 538}
539 539
540/* Banked read. Take special care to jump past the holes in the bank 540/* Banked read. Take special care to jump past the holes in the bank
541 mapping. This version assumes symetry in the holes.. */ 541 mapping. This version assumes symetry in the holes.. */
542static int jedec_read_banked(struct mtd_info *mtd, loff_t from, size_t len, 542static int jedec_read_banked(struct mtd_info *mtd, loff_t from, size_t len,
543 size_t *retlen, u_char *buf) 543 size_t *retlen, u_char *buf)
544{ 544{
545 struct map_info *map = mtd->priv; 545 struct map_info *map = mtd->priv;
@@ -555,17 +555,17 @@ static int jedec_read_banked(struct mtd_info *mtd, loff_t from, size_t len,
555 if (priv->bank_fill[0] - offset < len) 555 if (priv->bank_fill[0] - offset < len)
556 get = priv->bank_fill[0] - offset; 556 get = priv->bank_fill[0] - offset;
557 557
558 bank /= priv->bank_fill[0]; 558 bank /= priv->bank_fill[0];
559 map_copy_from(map,buf + *retlen,bank*my_bank_size + offset,get); 559 map_copy_from(map,buf + *retlen,bank*my_bank_size + offset,get);
560 560
561 len -= get; 561 len -= get;
562 *retlen += get; 562 *retlen += get;
563 from += get; 563 from += get;
564 } 564 }
565 return 0; 565 return 0;
566} 566}
567 567
568/* Pass the flags value that the flash return before it re-entered read 568/* Pass the flags value that the flash return before it re-entered read
569 mode. */ 569 mode. */
570static void jedec_flash_failed(unsigned char code) 570static void jedec_flash_failed(unsigned char code)
571{ 571{
@@ -579,17 +579,17 @@ static void jedec_flash_failed(unsigned char code)
579 printk("mtd: Programming didn't take\n"); 579 printk("mtd: Programming didn't take\n");
580} 580}
581 581
582/* This uses the erasure function described in the AMD Flash Handbook, 582/* This uses the erasure function described in the AMD Flash Handbook,
583 it will work for flashes with a fixed sector size only. Flashes with 583 it will work for flashes with a fixed sector size only. Flashes with
584 a selection of sector sizes (ie the AMD Am29F800B) will need a different 584 a selection of sector sizes (ie the AMD Am29F800B) will need a different
585 routine. This routine tries to parallize erasing multiple chips/sectors 585 routine. This routine tries to parallize erasing multiple chips/sectors
586 where possible */ 586 where possible */
587static int flash_erase(struct mtd_info *mtd, struct erase_info *instr) 587static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
588{ 588{
589 // Does IO to the currently selected chip 589 // Does IO to the currently selected chip
590 #define flread(x) map_read8(map,chip->base+((x)<<chip->addrshift)) 590 #define flread(x) map_read8(map,chip->base+((x)<<chip->addrshift))
591 #define flwrite(v,x) map_write8(map,v,chip->base+((x)<<chip->addrshift)) 591 #define flwrite(v,x) map_write8(map,v,chip->base+((x)<<chip->addrshift))
592 592
593 unsigned long Time = 0; 593 unsigned long Time = 0;
594 unsigned long NoTime = 0; 594 unsigned long NoTime = 0;
595 unsigned long start = instr->addr, len = instr->len; 595 unsigned long start = instr->addr, len = instr->len;
@@ -603,7 +603,7 @@ static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
603 (len % mtd->erasesize) != 0 || 603 (len % mtd->erasesize) != 0 ||
604 (len/mtd->erasesize) == 0) 604 (len/mtd->erasesize) == 0)
605 return -EINVAL; 605 return -EINVAL;
606 606
607 jedec_flash_chip_scan(priv,start,len); 607 jedec_flash_chip_scan(priv,start,len);
608 608
609 // Start the erase sequence on each chip 609 // Start the erase sequence on each chip
@@ -611,16 +611,16 @@ static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
611 { 611 {
612 unsigned long off; 612 unsigned long off;
613 struct jedec_flash_chip *chip = priv->chips + I; 613 struct jedec_flash_chip *chip = priv->chips + I;
614 614
615 if (chip->length == 0) 615 if (chip->length == 0)
616 continue; 616 continue;
617 617
618 if (chip->start + chip->length > chip->size) 618 if (chip->start + chip->length > chip->size)
619 { 619 {
620 printk("DIE\n"); 620 printk("DIE\n");
621 return -EIO; 621 return -EIO;
622 } 622 }
623 623
624 flwrite(0xF0,chip->start + 0x555); 624 flwrite(0xF0,chip->start + 0x555);
625 flwrite(0xAA,chip->start + 0x555); 625 flwrite(0xAA,chip->start + 0x555);
626 flwrite(0x55,chip->start + 0x2AA); 626 flwrite(0x55,chip->start + 0x2AA);
@@ -628,8 +628,8 @@ static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
628 flwrite(0xAA,chip->start + 0x555); 628 flwrite(0xAA,chip->start + 0x555);
629 flwrite(0x55,chip->start + 0x2AA); 629 flwrite(0x55,chip->start + 0x2AA);
630 630
631 /* Once we start selecting the erase sectors the delay between each 631 /* Once we start selecting the erase sectors the delay between each
632 command must not exceed 50us or it will immediately start erasing 632 command must not exceed 50us or it will immediately start erasing
633 and ignore the other sectors */ 633 and ignore the other sectors */
634 for (off = 0; off < len; off += chip->sectorsize) 634 for (off = 0; off < len; off += chip->sectorsize)
635 { 635 {
@@ -641,19 +641,19 @@ static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
641 { 641 {
642 printk("mtd: Ack! We timed out the erase timer!\n"); 642 printk("mtd: Ack! We timed out the erase timer!\n");
643 return -EIO; 643 return -EIO;
644 } 644 }
645 } 645 }
646 } 646 }
647 647
648 /* We could split this into a timer routine and return early, performing 648 /* We could split this into a timer routine and return early, performing
649 background erasure.. Maybe later if the need warrents */ 649 background erasure.. Maybe later if the need warrents */
650 650
651 /* Poll the flash for erasure completion, specs say this can take as long 651 /* Poll the flash for erasure completion, specs say this can take as long
652 as 480 seconds to do all the sectors (for a 2 meg flash). 652 as 480 seconds to do all the sectors (for a 2 meg flash).
653 Erasure time is dependent on chip age, temp and wear.. */ 653 Erasure time is dependent on chip age, temp and wear.. */
654 654
655 /* This being a generic routine assumes a 32 bit bus. It does read32s 655 /* This being a generic routine assumes a 32 bit bus. It does read32s
656 and bundles interleved chips into the same grouping. This will work 656 and bundles interleved chips into the same grouping. This will work
657 for all bus widths */ 657 for all bus widths */
658 Time = 0; 658 Time = 0;
659 NoTime = 0; 659 NoTime = 0;
@@ -664,20 +664,20 @@ static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
664 unsigned todo[4] = {0,0,0,0}; 664 unsigned todo[4] = {0,0,0,0};
665 unsigned todo_left = 0; 665 unsigned todo_left = 0;
666 unsigned J; 666 unsigned J;
667 667
668 if (chip->length == 0) 668 if (chip->length == 0)
669 continue; 669 continue;
670 670
671 /* Find all chips in this data line, realistically this is all 671 /* Find all chips in this data line, realistically this is all
672 or nothing up to the interleve count */ 672 or nothing up to the interleve count */
673 for (J = 0; priv->chips[J].jedec != 0 && J < MAX_JEDEC_CHIPS; J++) 673 for (J = 0; priv->chips[J].jedec != 0 && J < MAX_JEDEC_CHIPS; J++)
674 { 674 {
675 if ((priv->chips[J].base & (~((1<<chip->addrshift)-1))) == 675 if ((priv->chips[J].base & (~((1<<chip->addrshift)-1))) ==
676 (chip->base & (~((1<<chip->addrshift)-1)))) 676 (chip->base & (~((1<<chip->addrshift)-1))))
677 { 677 {
678 todo_left++; 678 todo_left++;
679 todo[priv->chips[J].base & ((1<<chip->addrshift)-1)] = 1; 679 todo[priv->chips[J].base & ((1<<chip->addrshift)-1)] = 1;
680 } 680 }
681 } 681 }
682 682
683 /* printk("todo: %x %x %x %x\n",(short)todo[0],(short)todo[1], 683 /* printk("todo: %x %x %x %x\n",(short)todo[0],(short)todo[1],
@@ -687,7 +687,7 @@ static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
687 { 687 {
688 __u32 Last[4]; 688 __u32 Last[4];
689 unsigned long Count = 0; 689 unsigned long Count = 0;
690 690
691 /* During erase bit 7 is held low and bit 6 toggles, we watch this, 691 /* During erase bit 7 is held low and bit 6 toggles, we watch this,
692 should it stop toggling or go high then the erase is completed, 692 should it stop toggling or go high then the erase is completed,
693 or this is not really flash ;> */ 693 or this is not really flash ;> */
@@ -718,23 +718,23 @@ static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
718 __u8 Byte3 = (Last[(Count-3)%4] >> (J*8)) & 0xFF; 718 __u8 Byte3 = (Last[(Count-3)%4] >> (J*8)) & 0xFF;
719 if (todo[J] == 0) 719 if (todo[J] == 0)
720 continue; 720 continue;
721 721
722 if ((Byte1 & (1 << 7)) == 0 && Byte1 != Byte2) 722 if ((Byte1 & (1 << 7)) == 0 && Byte1 != Byte2)
723 { 723 {
724// printk("Check %x %x %x\n",(short)J,(short)Byte1,(short)Byte2); 724// printk("Check %x %x %x\n",(short)J,(short)Byte1,(short)Byte2);
725 continue; 725 continue;
726 } 726 }
727 727
728 if (Byte1 == Byte2) 728 if (Byte1 == Byte2)
729 { 729 {
730 jedec_flash_failed(Byte3); 730 jedec_flash_failed(Byte3);
731 return -EIO; 731 return -EIO;
732 } 732 }
733 733
734 todo[J] = 0; 734 todo[J] = 0;
735 todo_left--; 735 todo_left--;
736 } 736 }
737 737
738/* if (NoTime == 0) 738/* if (NoTime == 0)
739 Time += HZ/10 - schedule_timeout(HZ/10);*/ 739 Time += HZ/10 - schedule_timeout(HZ/10);*/
740 NoTime = 0; 740 NoTime = 0;
@@ -751,7 +751,7 @@ static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
751 break; 751 break;
752 } 752 }
753 Count++; 753 Count++;
754 754
755/* // Count time, max of 15s per sector (according to AMD) 755/* // Count time, max of 15s per sector (according to AMD)
756 if (Time > 15*len/mtd->erasesize*HZ) 756 if (Time > 15*len/mtd->erasesize*HZ)
757 { 757 {
@@ -759,38 +759,38 @@ static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
759 return -EIO; 759 return -EIO;
760 } */ 760 } */
761 } 761 }
762 762
763 // Skip to the next chip if we used chip erase 763 // Skip to the next chip if we used chip erase
764 if (chip->length == chip->size) 764 if (chip->length == chip->size)
765 off = chip->size; 765 off = chip->size;
766 else 766 else
767 off += chip->sectorsize; 767 off += chip->sectorsize;
768 768
769 if (off >= chip->length) 769 if (off >= chip->length)
770 break; 770 break;
771 NoTime = 1; 771 NoTime = 1;
772 } 772 }
773 773
774 for (J = 0; priv->chips[J].jedec != 0 && J < MAX_JEDEC_CHIPS; J++) 774 for (J = 0; priv->chips[J].jedec != 0 && J < MAX_JEDEC_CHIPS; J++)
775 { 775 {
776 if ((priv->chips[J].base & (~((1<<chip->addrshift)-1))) == 776 if ((priv->chips[J].base & (~((1<<chip->addrshift)-1))) ==
777 (chip->base & (~((1<<chip->addrshift)-1)))) 777 (chip->base & (~((1<<chip->addrshift)-1))))
778 priv->chips[J].length = 0; 778 priv->chips[J].length = 0;
779 } 779 }
780 } 780 }
781 781
782 //printk("done\n"); 782 //printk("done\n");
783 instr->state = MTD_ERASE_DONE; 783 instr->state = MTD_ERASE_DONE;
784 mtd_erase_callback(instr); 784 mtd_erase_callback(instr);
785 return 0; 785 return 0;
786 786
787 #undef flread 787 #undef flread
788 #undef flwrite 788 #undef flwrite
789} 789}
790 790
791/* This is the simple flash writing function. It writes to every byte, in 791/* This is the simple flash writing function. It writes to every byte, in
792 sequence. It takes care of how to properly address the flash if 792 sequence. It takes care of how to properly address the flash if
793 the flash is interleved. It can only be used if all the chips in the 793 the flash is interleved. It can only be used if all the chips in the
794 array are identical!*/ 794 array are identical!*/
795static int flash_write(struct mtd_info *mtd, loff_t start, size_t len, 795static int flash_write(struct mtd_info *mtd, loff_t start, size_t len,
796 size_t *retlen, const u_char *buf) 796 size_t *retlen, const u_char *buf)
@@ -800,25 +800,25 @@ static int flash_write(struct mtd_info *mtd, loff_t start, size_t len,
800 of addrshift (interleave index) and then adds the control register index. */ 800 of addrshift (interleave index) and then adds the control register index. */
801 #define flread(x) map_read8(map,base+(off&((1<<chip->addrshift)-1))+((x)<<chip->addrshift)) 801 #define flread(x) map_read8(map,base+(off&((1<<chip->addrshift)-1))+((x)<<chip->addrshift))
802 #define flwrite(v,x) map_write8(map,v,base+(off&((1<<chip->addrshift)-1))+((x)<<chip->addrshift)) 802 #define flwrite(v,x) map_write8(map,v,base+(off&((1<<chip->addrshift)-1))+((x)<<chip->addrshift))
803 803
804 struct map_info *map = mtd->priv; 804 struct map_info *map = mtd->priv;
805 struct jedec_private *priv = map->fldrv_priv; 805 struct jedec_private *priv = map->fldrv_priv;
806 unsigned long base; 806 unsigned long base;
807 unsigned long off; 807 unsigned long off;
808 size_t save_len = len; 808 size_t save_len = len;
809 809
810 if (start + len > mtd->size) 810 if (start + len > mtd->size)
811 return -EIO; 811 return -EIO;
812 812
813 //printk("Here"); 813 //printk("Here");
814 814
815 //printk("flash_write: start is %x, len is %x\n",start,(unsigned long)len); 815 //printk("flash_write: start is %x, len is %x\n",start,(unsigned long)len);
816 while (len != 0) 816 while (len != 0)
817 { 817 {
818 struct jedec_flash_chip *chip = priv->chips; 818 struct jedec_flash_chip *chip = priv->chips;
819 unsigned long bank; 819 unsigned long bank;
820 unsigned long boffset; 820 unsigned long boffset;
821 821
822 // Compute the base of the flash. 822 // Compute the base of the flash.
823 off = ((unsigned long)start) % (chip->size << chip->addrshift); 823 off = ((unsigned long)start) % (chip->size << chip->addrshift);
824 base = start - off; 824 base = start - off;
@@ -828,10 +828,10 @@ static int flash_write(struct mtd_info *mtd, loff_t start, size_t len,
828 boffset = base & (priv->bank_fill[0]-1); 828 boffset = base & (priv->bank_fill[0]-1);
829 bank = (bank/priv->bank_fill[0])*my_bank_size; 829 bank = (bank/priv->bank_fill[0])*my_bank_size;
830 base = bank + boffset; 830 base = bank + boffset;
831 831
832 // printk("Flasing %X %X %X\n",base,chip->size,len); 832 // printk("Flasing %X %X %X\n",base,chip->size,len);
833 // printk("off is %x, compare with %x\n",off,chip->size << chip->addrshift); 833 // printk("off is %x, compare with %x\n",off,chip->size << chip->addrshift);
834 834
835 // Loop over this page 835 // Loop over this page
836 for (; off != (chip->size << chip->addrshift) && len != 0; start++, len--, off++,buf++) 836 for (; off != (chip->size << chip->addrshift) && len != 0; start++, len--, off++,buf++)
837 { 837 {
@@ -845,7 +845,7 @@ static int flash_write(struct mtd_info *mtd, loff_t start, size_t len,
845 } 845 }
846 if (((~oldbyte) & *buf) != 0) 846 if (((~oldbyte) & *buf) != 0)
847 printk("mtd: warn: Trying to set a 0 to a 1\n"); 847 printk("mtd: warn: Trying to set a 0 to a 1\n");
848 848
849 // Write 849 // Write
850 flwrite(0xAA,0x555); 850 flwrite(0xAA,0x555);
851 flwrite(0x55,0x2AA); 851 flwrite(0x55,0x2AA);
@@ -854,10 +854,10 @@ static int flash_write(struct mtd_info *mtd, loff_t start, size_t len,
854 Last[0] = map_read8(map,base + off); 854 Last[0] = map_read8(map,base + off);
855 Last[1] = map_read8(map,base + off); 855 Last[1] = map_read8(map,base + off);
856 Last[2] = map_read8(map,base + off); 856 Last[2] = map_read8(map,base + off);
857 857
858 /* Wait for the flash to finish the operation. We store the last 4 858 /* Wait for the flash to finish the operation. We store the last 4
859 status bytes that have been retrieved so we can determine why 859 status bytes that have been retrieved so we can determine why
860 it failed. The toggle bits keep toggling when there is a 860 it failed. The toggle bits keep toggling when there is a
861 failure */ 861 failure */
862 for (Count = 3; Last[(Count - 1) % 4] != Last[(Count - 2) % 4] && 862 for (Count = 3; Last[(Count - 1) % 4] != Last[(Count - 2) % 4] &&
863 Count < 10000; Count++) 863 Count < 10000; Count++)
@@ -866,7 +866,7 @@ static int flash_write(struct mtd_info *mtd, loff_t start, size_t len,
866 { 866 {
867 jedec_flash_failed(Last[(Count - 3) % 4]); 867 jedec_flash_failed(Last[(Count - 3) % 4]);
868 return -EIO; 868 return -EIO;
869 } 869 }
870 } 870 }
871 } 871 }
872 *retlen = save_len; 872 *retlen = save_len;
@@ -885,24 +885,24 @@ static void jedec_flash_chip_scan(struct jedec_private *priv,unsigned long start
885 // Zero the records 885 // Zero the records
886 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++) 886 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
887 priv->chips[I].start = priv->chips[I].length = 0; 887 priv->chips[I].start = priv->chips[I].length = 0;
888 888
889 // Intersect the region with each chip 889 // Intersect the region with each chip
890 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++) 890 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
891 { 891 {
892 struct jedec_flash_chip *chip = priv->chips + I; 892 struct jedec_flash_chip *chip = priv->chips + I;
893 unsigned long ByteStart; 893 unsigned long ByteStart;
894 unsigned long ChipEndByte = chip->offset + (chip->size << chip->addrshift); 894 unsigned long ChipEndByte = chip->offset + (chip->size << chip->addrshift);
895 895
896 // End is before this chip or the start is after it 896 // End is before this chip or the start is after it
897 if (start+len < chip->offset || 897 if (start+len < chip->offset ||
898 ChipEndByte - (1 << chip->addrshift) < start) 898 ChipEndByte - (1 << chip->addrshift) < start)
899 continue; 899 continue;
900 900
901 if (start < chip->offset) 901 if (start < chip->offset)
902 { 902 {
903 ByteStart = chip->offset; 903 ByteStart = chip->offset;
904 chip->start = 0; 904 chip->start = 0;
905 } 905 }
906 else 906 else
907 { 907 {
908 chip->start = (start - chip->offset + (1 << chip->addrshift)-1) >> chip->addrshift; 908 chip->start = (start - chip->offset + (1 << chip->addrshift)-1) >> chip->addrshift;
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index 30da428eb7b9..edb306c03c0a 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -1,7 +1,7 @@
1/* 1/*
2 Common Flash Interface probe code. 2 Common Flash Interface probe code.
3 (C) 2000 Red Hat. GPL'd. 3 (C) 2000 Red Hat. GPL'd.
4 $Id: jedec_probe.c,v 1.63 2005/02/14 16:30:32 bjd Exp $ 4 $Id: jedec_probe.c,v 1.66 2005/11/07 11:14:23 gleixner Exp $
5 See JEDEC (http://www.jedec.org/) standard JESD21C (section 3.5) 5 See JEDEC (http://www.jedec.org/) standard JESD21C (section 3.5)
6 for the standard this probe goes back to. 6 for the standard this probe goes back to.
7 7
@@ -1719,7 +1719,7 @@ static int jedec_probe_chip(struct map_info *map, __u32 base,
1719 1719
1720static struct mtd_info *jedec_probe(struct map_info *map); 1720static struct mtd_info *jedec_probe(struct map_info *map);
1721 1721
1722static inline u32 jedec_read_mfr(struct map_info *map, __u32 base, 1722static inline u32 jedec_read_mfr(struct map_info *map, __u32 base,
1723 struct cfi_private *cfi) 1723 struct cfi_private *cfi)
1724{ 1724{
1725 map_word result; 1725 map_word result;
@@ -1730,7 +1730,7 @@ static inline u32 jedec_read_mfr(struct map_info *map, __u32 base,
1730 return result.x[0] & mask; 1730 return result.x[0] & mask;
1731} 1731}
1732 1732
1733static inline u32 jedec_read_id(struct map_info *map, __u32 base, 1733static inline u32 jedec_read_id(struct map_info *map, __u32 base,
1734 struct cfi_private *cfi) 1734 struct cfi_private *cfi)
1735{ 1735{
1736 map_word result; 1736 map_word result;
@@ -1741,7 +1741,7 @@ static inline u32 jedec_read_id(struct map_info *map, __u32 base,
1741 return result.x[0] & mask; 1741 return result.x[0] & mask;
1742} 1742}
1743 1743
1744static inline void jedec_reset(u32 base, struct map_info *map, 1744static inline void jedec_reset(u32 base, struct map_info *map,
1745 struct cfi_private *cfi) 1745 struct cfi_private *cfi)
1746{ 1746{
1747 /* Reset */ 1747 /* Reset */
@@ -1765,7 +1765,7 @@ static inline void jedec_reset(u32 base, struct map_info *map,
1765 * so ensure we're in read mode. Send both the Intel and the AMD command 1765 * so ensure we're in read mode. Send both the Intel and the AMD command
1766 * for this. Intel uses 0xff for this, AMD uses 0xff for NOP, so 1766 * for this. Intel uses 0xff for this, AMD uses 0xff for NOP, so
1767 * this should be safe. 1767 * this should be safe.
1768 */ 1768 */
1769 cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL); 1769 cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL);
1770 /* FIXME - should have reset delay before continuing */ 1770 /* FIXME - should have reset delay before continuing */
1771} 1771}
@@ -1807,14 +1807,14 @@ static int cfi_jedec_setup(struct cfi_private *p_cfi, int index)
1807 printk("Found: %s\n",jedec_table[index].name); 1807 printk("Found: %s\n",jedec_table[index].name);
1808 1808
1809 num_erase_regions = jedec_table[index].NumEraseRegions; 1809 num_erase_regions = jedec_table[index].NumEraseRegions;
1810 1810
1811 p_cfi->cfiq = kmalloc(sizeof(struct cfi_ident) + num_erase_regions * 4, GFP_KERNEL); 1811 p_cfi->cfiq = kmalloc(sizeof(struct cfi_ident) + num_erase_regions * 4, GFP_KERNEL);
1812 if (!p_cfi->cfiq) { 1812 if (!p_cfi->cfiq) {
1813 //xx printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name); 1813 //xx printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name);
1814 return 0; 1814 return 0;
1815 } 1815 }
1816 1816
1817 memset(p_cfi->cfiq,0,sizeof(struct cfi_ident)); 1817 memset(p_cfi->cfiq,0,sizeof(struct cfi_ident));
1818 1818
1819 p_cfi->cfiq->P_ID = jedec_table[index].CmdSet; 1819 p_cfi->cfiq->P_ID = jedec_table[index].CmdSet;
1820 p_cfi->cfiq->NumEraseRegions = jedec_table[index].NumEraseRegions; 1820 p_cfi->cfiq->NumEraseRegions = jedec_table[index].NumEraseRegions;
@@ -1969,7 +1969,7 @@ static inline int jedec_match( __u32 base,
1969 cfi_send_gen_cmd(0x90, cfi->addr_unlock1, base, map, cfi, cfi->device_type, NULL); 1969 cfi_send_gen_cmd(0x90, cfi->addr_unlock1, base, map, cfi, cfi->device_type, NULL);
1970 /* FIXME - should have a delay before continuing */ 1970 /* FIXME - should have a delay before continuing */
1971 1971
1972 match_done: 1972 match_done:
1973 return rc; 1973 return rc;
1974} 1974}
1975 1975
@@ -1998,23 +1998,23 @@ static int jedec_probe_chip(struct map_info *map, __u32 base,
1998 "Probe at base(0x%08x) past the end of the map(0x%08lx)\n", 1998 "Probe at base(0x%08x) past the end of the map(0x%08lx)\n",
1999 base, map->size -1); 1999 base, map->size -1);
2000 return 0; 2000 return 0;
2001 2001
2002 } 2002 }
2003 /* Ensure the unlock addresses we try stay inside the map */ 2003 /* Ensure the unlock addresses we try stay inside the map */
2004 probe_offset1 = cfi_build_cmd_addr( 2004 probe_offset1 = cfi_build_cmd_addr(
2005 cfi->addr_unlock1, 2005 cfi->addr_unlock1,
2006 cfi_interleave(cfi), 2006 cfi_interleave(cfi),
2007 cfi->device_type); 2007 cfi->device_type);
2008 probe_offset2 = cfi_build_cmd_addr( 2008 probe_offset2 = cfi_build_cmd_addr(
2009 cfi->addr_unlock1, 2009 cfi->addr_unlock1,
2010 cfi_interleave(cfi), 2010 cfi_interleave(cfi),
2011 cfi->device_type); 2011 cfi->device_type);
2012 if ( ((base + probe_offset1 + map_bankwidth(map)) >= map->size) || 2012 if ( ((base + probe_offset1 + map_bankwidth(map)) >= map->size) ||
2013 ((base + probe_offset2 + map_bankwidth(map)) >= map->size)) 2013 ((base + probe_offset2 + map_bankwidth(map)) >= map->size))
2014 { 2014 {
2015 goto retry; 2015 goto retry;
2016 } 2016 }
2017 2017
2018 /* Reset */ 2018 /* Reset */
2019 jedec_reset(base, map, cfi); 2019 jedec_reset(base, map, cfi);
2020 2020
@@ -2027,13 +2027,13 @@ static int jedec_probe_chip(struct map_info *map, __u32 base,
2027 /* FIXME - should have a delay before continuing */ 2027 /* FIXME - should have a delay before continuing */
2028 2028
2029 if (!cfi->numchips) { 2029 if (!cfi->numchips) {
2030 /* This is the first time we're called. Set up the CFI 2030 /* This is the first time we're called. Set up the CFI
2031 stuff accordingly and return */ 2031 stuff accordingly and return */
2032 2032
2033 cfi->mfr = jedec_read_mfr(map, base, cfi); 2033 cfi->mfr = jedec_read_mfr(map, base, cfi);
2034 cfi->id = jedec_read_id(map, base, cfi); 2034 cfi->id = jedec_read_id(map, base, cfi);
2035 DEBUG(MTD_DEBUG_LEVEL3, 2035 DEBUG(MTD_DEBUG_LEVEL3,
2036 "Search for id:(%02x %02x) interleave(%d) type(%d)\n", 2036 "Search for id:(%02x %02x) interleave(%d) type(%d)\n",
2037 cfi->mfr, cfi->id, cfi_interleave(cfi), cfi->device_type); 2037 cfi->mfr, cfi->id, cfi_interleave(cfi), cfi->device_type);
2038 for (i=0; i<sizeof(jedec_table)/sizeof(jedec_table[0]); i++) { 2038 for (i=0; i<sizeof(jedec_table)/sizeof(jedec_table[0]); i++) {
2039 if ( jedec_match( base, map, cfi, &jedec_table[i] ) ) { 2039 if ( jedec_match( base, map, cfi, &jedec_table[i] ) ) {
@@ -2062,7 +2062,7 @@ static int jedec_probe_chip(struct map_info *map, __u32 base,
2062 return 0; 2062 return 0;
2063 } 2063 }
2064 } 2064 }
2065 2065
2066 /* Check each previous chip locations to see if it's an alias */ 2066 /* Check each previous chip locations to see if it's an alias */
2067 for (i=0; i < (base >> cfi->chipshift); i++) { 2067 for (i=0; i < (base >> cfi->chipshift); i++) {
2068 unsigned long start; 2068 unsigned long start;
@@ -2083,7 +2083,7 @@ static int jedec_probe_chip(struct map_info *map, __u32 base,
2083 map->name, base, start); 2083 map->name, base, start);
2084 return 0; 2084 return 0;
2085 } 2085 }
2086 2086
2087 /* Yes, it's actually got the device IDs as data. Most 2087 /* Yes, it's actually got the device IDs as data. Most
2088 * unfortunate. Stick the new chip in read mode 2088 * unfortunate. Stick the new chip in read mode
2089 * too and if it's the same, assume it's an alias. */ 2089 * too and if it's the same, assume it's an alias. */
@@ -2097,20 +2097,20 @@ static int jedec_probe_chip(struct map_info *map, __u32 base,
2097 } 2097 }
2098 } 2098 }
2099 } 2099 }
2100 2100
2101 /* OK, if we got to here, then none of the previous chips appear to 2101 /* OK, if we got to here, then none of the previous chips appear to
2102 be aliases for the current one. */ 2102 be aliases for the current one. */
2103 set_bit((base >> cfi->chipshift), chip_map); /* Update chip map */ 2103 set_bit((base >> cfi->chipshift), chip_map); /* Update chip map */
2104 cfi->numchips++; 2104 cfi->numchips++;
2105 2105
2106ok_out: 2106ok_out:
2107 /* Put it back into Read Mode */ 2107 /* Put it back into Read Mode */
2108 jedec_reset(base, map, cfi); 2108 jedec_reset(base, map, cfi);
2109 2109
2110 printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank\n", 2110 printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank\n",
2111 map->name, cfi_interleave(cfi), cfi->device_type*8, base, 2111 map->name, cfi_interleave(cfi), cfi->device_type*8, base,
2112 map->bankwidth*8); 2112 map->bankwidth*8);
2113 2113
2114 return 1; 2114 return 1;
2115} 2115}
2116 2116
diff --git a/drivers/mtd/chips/map_absent.c b/drivers/mtd/chips/map_absent.c
index c6c83833cc32..a611de9b1515 100644
--- a/drivers/mtd/chips/map_absent.c
+++ b/drivers/mtd/chips/map_absent.c
@@ -1,11 +1,11 @@
1/* 1/*
2 * Common code to handle absent "placeholder" devices 2 * Common code to handle absent "placeholder" devices
3 * Copyright 2001 Resilience Corporation <ebrower@resilience.com> 3 * Copyright 2001 Resilience Corporation <ebrower@resilience.com>
4 * $Id: map_absent.c,v 1.5 2004/11/16 18:29:00 dwmw2 Exp $ 4 * $Id: map_absent.c,v 1.6 2005/11/07 11:14:23 gleixner Exp $
5 * 5 *
6 * This map driver is used to allocate "placeholder" MTD 6 * This map driver is used to allocate "placeholder" MTD
7 * devices on systems that have socketed/removable media. 7 * devices on systems that have socketed/removable media.
8 * Use of this driver as a fallback preserves the expected 8 * Use of this driver as a fallback preserves the expected
9 * registration of MTD device nodes regardless of probe outcome. 9 * registration of MTD device nodes regardless of probe outcome.
10 * A usage example is as follows: 10 * A usage example is as follows:
11 * 11 *
@@ -80,7 +80,7 @@ static int map_absent_read(struct mtd_info *mtd, loff_t from, size_t len, size_t
80static int map_absent_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) 80static int map_absent_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
81{ 81{
82 *retlen = 0; 82 *retlen = 0;
83 return -ENODEV; 83 return -ENODEV;
84} 84}
85 85
86static int map_absent_erase(struct mtd_info *mtd, struct erase_info *instr) 86static int map_absent_erase(struct mtd_info *mtd, struct erase_info *instr)
diff --git a/drivers/mtd/chips/sharp.c b/drivers/mtd/chips/sharp.c
index c3cf0f63bc93..2d26bdef82d5 100644
--- a/drivers/mtd/chips/sharp.c
+++ b/drivers/mtd/chips/sharp.c
@@ -4,7 +4,7 @@
4 * Copyright 2000,2001 David A. Schleef <ds@schleef.org> 4 * Copyright 2000,2001 David A. Schleef <ds@schleef.org>
5 * 2000,2001 Lineo, Inc. 5 * 2000,2001 Lineo, Inc.
6 * 6 *
7 * $Id: sharp.c,v 1.14 2004/08/09 13:19:43 dwmw2 Exp $ 7 * $Id: sharp.c,v 1.16 2005/11/07 11:14:23 gleixner Exp $
8 * 8 *
9 * Devices supported: 9 * Devices supported:
10 * LH28F016SCT Symmetrical block flash memory, 2Mx8 10 * LH28F016SCT Symmetrical block flash memory, 2Mx8
@@ -31,6 +31,7 @@
31#include <linux/mtd/cfi.h> 31#include <linux/mtd/cfi.h>
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/slab.h>
34 35
35#define CMD_RESET 0xffffffff 36#define CMD_RESET 0xffffffff
36#define CMD_READ_ID 0x90909090 37#define CMD_READ_ID 0x90909090
@@ -214,7 +215,7 @@ static int sharp_probe_map(struct map_info *map,struct mtd_info *mtd)
214/* This function returns with the chip->mutex lock held. */ 215/* This function returns with the chip->mutex lock held. */
215static int sharp_wait(struct map_info *map, struct flchip *chip) 216static int sharp_wait(struct map_info *map, struct flchip *chip)
216{ 217{
217 __u16 status; 218 int status, i;
218 unsigned long timeo = jiffies + HZ; 219 unsigned long timeo = jiffies + HZ;
219 DECLARE_WAITQUEUE(wait, current); 220 DECLARE_WAITQUEUE(wait, current);
220 int adr = 0; 221 int adr = 0;
@@ -227,13 +228,11 @@ retry:
227 map_write32(map,CMD_READ_STATUS,adr); 228 map_write32(map,CMD_READ_STATUS,adr);
228 chip->state = FL_STATUS; 229 chip->state = FL_STATUS;
229 case FL_STATUS: 230 case FL_STATUS:
230 status = map_read32(map,adr); 231 for(i=0;i<100;i++){
231//printk("status=%08x\n",status); 232 status = map_read32(map,adr);
232 233 if((status & SR_READY)==SR_READY)
233 udelay(100); 234 break;
234 if((status & SR_READY)!=SR_READY){ 235 udelay(1);
235//printk(".status=%08x\n",status);
236 udelay(100);
237 } 236 }
238 break; 237 break;
239 default: 238 default:
@@ -460,12 +459,12 @@ static int sharp_do_wait_for_ready(struct map_info *map, struct flchip *chip,
460 remove_wait_queue(&chip->wq, &wait); 459 remove_wait_queue(&chip->wq, &wait);
461 460
462 //spin_lock_bh(chip->mutex); 461 //spin_lock_bh(chip->mutex);
463 462
464 if (signal_pending(current)){ 463 if (signal_pending(current)){
465 ret = -EINTR; 464 ret = -EINTR;
466 goto out; 465 goto out;
467 } 466 }
468 467
469 } 468 }
470 ret = -ETIME; 469 ret = -ETIME;
471out: 470out:
@@ -564,7 +563,7 @@ static int sharp_suspend(struct mtd_info *mtd)
564static void sharp_resume(struct mtd_info *mtd) 563static void sharp_resume(struct mtd_info *mtd)
565{ 564{
566 printk("sharp_resume()\n"); 565 printk("sharp_resume()\n");
567 566
568} 567}
569 568
570static void sharp_destroy(struct mtd_info *mtd) 569static void sharp_destroy(struct mtd_info *mtd)
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index ef24837019d3..6b8bb2e4dcfd 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -1,24 +1,24 @@
1/* 1/*
2 * $Id: cmdlinepart.c,v 1.18 2005/06/07 15:04:26 joern Exp $ 2 * $Id: cmdlinepart.c,v 1.19 2005/11/07 11:14:19 gleixner Exp $
3 * 3 *
4 * Read flash partition table from command line 4 * Read flash partition table from command line
5 * 5 *
6 * Copyright 2002 SYSGO Real-Time Solutions GmbH 6 * Copyright 2002 SYSGO Real-Time Solutions GmbH
7 * 7 *
8 * The format for the command line is as follows: 8 * The format for the command line is as follows:
9 * 9 *
10 * mtdparts=<mtddef>[;<mtddef] 10 * mtdparts=<mtddef>[;<mtddef]
11 * <mtddef> := <mtd-id>:<partdef>[,<partdef>] 11 * <mtddef> := <mtd-id>:<partdef>[,<partdef>]
12 * <partdef> := <size>[@offset][<name>][ro] 12 * <partdef> := <size>[@offset][<name>][ro]
13 * <mtd-id> := unique name used in mapping driver/device (mtd->name) 13 * <mtd-id> := unique name used in mapping driver/device (mtd->name)
14 * <size> := standard linux memsize OR "-" to denote all remaining space 14 * <size> := standard linux memsize OR "-" to denote all remaining space
15 * <name> := '(' NAME ')' 15 * <name> := '(' NAME ')'
16 * 16 *
17 * Examples: 17 * Examples:
18 * 18 *
19 * 1 NOR Flash, with 1 single writable partition: 19 * 1 NOR Flash, with 1 single writable partition:
20 * edb7312-nor:- 20 * edb7312-nor:-
21 * 21 *
22 * 1 NOR Flash with 2 partitions, 1 NAND with one 22 * 1 NOR Flash with 2 partitions, 1 NAND with one
23 * edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home) 23 * edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
24 */ 24 */
@@ -60,17 +60,17 @@ static int cmdline_parsed = 0;
60 60
61/* 61/*
62 * Parse one partition definition for an MTD. Since there can be many 62 * Parse one partition definition for an MTD. Since there can be many
63 * comma separated partition definitions, this function calls itself 63 * comma separated partition definitions, this function calls itself
64 * recursively until no more partition definitions are found. Nice side 64 * recursively until no more partition definitions are found. Nice side
65 * effect: the memory to keep the mtd_partition structs and the names 65 * effect: the memory to keep the mtd_partition structs and the names
66 * is allocated upon the last definition being found. At that point the 66 * is allocated upon the last definition being found. At that point the
67 * syntax has been verified ok. 67 * syntax has been verified ok.
68 */ 68 */
69static struct mtd_partition * newpart(char *s, 69static struct mtd_partition * newpart(char *s,
70 char **retptr, 70 char **retptr,
71 int *num_parts, 71 int *num_parts,
72 int this_part, 72 int this_part,
73 unsigned char **extra_mem_ptr, 73 unsigned char **extra_mem_ptr,
74 int extra_mem_size) 74 int extra_mem_size)
75{ 75{
76 struct mtd_partition *parts; 76 struct mtd_partition *parts;
@@ -102,7 +102,7 @@ static struct mtd_partition * newpart(char *s,
102 mask_flags = 0; /* this is going to be a regular partition */ 102 mask_flags = 0; /* this is going to be a regular partition */
103 delim = 0; 103 delim = 0;
104 /* check for offset */ 104 /* check for offset */
105 if (*s == '@') 105 if (*s == '@')
106 { 106 {
107 s++; 107 s++;
108 offset = memparse(s, &s); 108 offset = memparse(s, &s);
@@ -112,7 +112,7 @@ static struct mtd_partition * newpart(char *s,
112 { 112 {
113 delim = ')'; 113 delim = ')';
114 } 114 }
115 115
116 if (delim) 116 if (delim)
117 { 117 {
118 char *p; 118 char *p;
@@ -131,12 +131,12 @@ static struct mtd_partition * newpart(char *s,
131 name = NULL; 131 name = NULL;
132 name_len = 13; /* Partition_000 */ 132 name_len = 13; /* Partition_000 */
133 } 133 }
134 134
135 /* record name length for memory allocation later */ 135 /* record name length for memory allocation later */
136 extra_mem_size += name_len + 1; 136 extra_mem_size += name_len + 1;
137 137
138 /* test for options */ 138 /* test for options */
139 if (strncmp(s, "ro", 2) == 0) 139 if (strncmp(s, "ro", 2) == 0)
140 { 140 {
141 mask_flags |= MTD_WRITEABLE; 141 mask_flags |= MTD_WRITEABLE;
142 s += 2; 142 s += 2;
@@ -151,7 +151,7 @@ static struct mtd_partition * newpart(char *s,
151 return NULL; 151 return NULL;
152 } 152 }
153 /* more partitions follow, parse them */ 153 /* more partitions follow, parse them */
154 if ((parts = newpart(s + 1, &s, num_parts, 154 if ((parts = newpart(s + 1, &s, num_parts,
155 this_part + 1, &extra_mem, extra_mem_size)) == 0) 155 this_part + 1, &extra_mem, extra_mem_size)) == 0)
156 return NULL; 156 return NULL;
157 } 157 }
@@ -187,7 +187,7 @@ static struct mtd_partition * newpart(char *s,
187 extra_mem += name_len + 1; 187 extra_mem += name_len + 1;
188 188
189 dbg(("partition %d: name <%s>, offset %x, size %x, mask flags %x\n", 189 dbg(("partition %d: name <%s>, offset %x, size %x, mask flags %x\n",
190 this_part, 190 this_part,
191 parts[this_part].name, 191 parts[this_part].name,
192 parts[this_part].offset, 192 parts[this_part].offset,
193 parts[this_part].size, 193 parts[this_part].size,
@@ -204,8 +204,8 @@ static struct mtd_partition * newpart(char *s,
204 return parts; 204 return parts;
205} 205}
206 206
207/* 207/*
208 * Parse the command line. 208 * Parse the command line.
209 */ 209 */
210static int mtdpart_setup_real(char *s) 210static int mtdpart_setup_real(char *s)
211{ 211{
@@ -230,7 +230,7 @@ static int mtdpart_setup_real(char *s)
230 230
231 dbg(("parsing <%s>\n", p+1)); 231 dbg(("parsing <%s>\n", p+1));
232 232
233 /* 233 /*
234 * parse one mtd. have it reserve memory for the 234 * parse one mtd. have it reserve memory for the
235 * struct cmdline_mtd_partition and the mtd-id string. 235 * struct cmdline_mtd_partition and the mtd-id string.
236 */ 236 */
@@ -239,7 +239,7 @@ static int mtdpart_setup_real(char *s)
239 &num_parts, /* out: number of parts */ 239 &num_parts, /* out: number of parts */
240 0, /* first partition */ 240 0, /* first partition */
241 (unsigned char**)&this_mtd, /* out: extra mem */ 241 (unsigned char**)&this_mtd, /* out: extra mem */
242 mtd_id_len + 1 + sizeof(*this_mtd) + 242 mtd_id_len + 1 + sizeof(*this_mtd) +
243 sizeof(void*)-1 /*alignment*/); 243 sizeof(void*)-1 /*alignment*/);
244 if(!parts) 244 if(!parts)
245 { 245 {
@@ -254,21 +254,21 @@ static int mtdpart_setup_real(char *s)
254 } 254 }
255 255
256 /* align this_mtd */ 256 /* align this_mtd */
257 this_mtd = (struct cmdline_mtd_partition *) 257 this_mtd = (struct cmdline_mtd_partition *)
258 ALIGN((unsigned long)this_mtd, sizeof(void*)); 258 ALIGN((unsigned long)this_mtd, sizeof(void*));
259 /* enter results */ 259 /* enter results */
260 this_mtd->parts = parts; 260 this_mtd->parts = parts;
261 this_mtd->num_parts = num_parts; 261 this_mtd->num_parts = num_parts;
262 this_mtd->mtd_id = (char*)(this_mtd + 1); 262 this_mtd->mtd_id = (char*)(this_mtd + 1);
263 strlcpy(this_mtd->mtd_id, mtd_id, mtd_id_len + 1); 263 strlcpy(this_mtd->mtd_id, mtd_id, mtd_id_len + 1);
264 264
265 /* link into chain */ 265 /* link into chain */
266 this_mtd->next = partitions; 266 this_mtd->next = partitions;
267 partitions = this_mtd; 267 partitions = this_mtd;
268 268
269 dbg(("mtdid=<%s> num_parts=<%d>\n", 269 dbg(("mtdid=<%s> num_parts=<%d>\n",
270 this_mtd->mtd_id, this_mtd->num_parts)); 270 this_mtd->mtd_id, this_mtd->num_parts));
271 271
272 272
273 /* EOS - we're done */ 273 /* EOS - we're done */
274 if (*s == 0) 274 if (*s == 0)
@@ -292,7 +292,7 @@ static int mtdpart_setup_real(char *s)
292 * information. It returns partitions for the requested mtd device, or 292 * information. It returns partitions for the requested mtd device, or
293 * the first one in the chain if a NULL mtd_id is passed in. 293 * the first one in the chain if a NULL mtd_id is passed in.
294 */ 294 */
295static int parse_cmdline_partitions(struct mtd_info *master, 295static int parse_cmdline_partitions(struct mtd_info *master,
296 struct mtd_partition **pparts, 296 struct mtd_partition **pparts,
297 unsigned long origin) 297 unsigned long origin)
298{ 298{
@@ -322,7 +322,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
322 part->parts[i].size = master->size - offset; 322 part->parts[i].size = master->size - offset;
323 if (offset + part->parts[i].size > master->size) 323 if (offset + part->parts[i].size > master->size)
324 { 324 {
325 printk(KERN_WARNING ERRP 325 printk(KERN_WARNING ERRP
326 "%s: partitioning exceeds flash size, truncating\n", 326 "%s: partitioning exceeds flash size, truncating\n",
327 part->mtd_id); 327 part->mtd_id);
328 part->parts[i].size = master->size - offset; 328 part->parts[i].size = master->size - offset;
@@ -338,8 +338,8 @@ static int parse_cmdline_partitions(struct mtd_info *master,
338} 338}
339 339
340 340
341/* 341/*
342 * This is the handler for our kernel parameter, called from 342 * This is the handler for our kernel parameter, called from
343 * main.c::checksetup(). Note that we can not yet kmalloc() anything, 343 * main.c::checksetup(). Note that we can not yet kmalloc() anything,
344 * so we only save the commandline for later processing. 344 * so we only save the commandline for later processing.
345 * 345 *
diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
index c4a56a4ac5e2..9a2aa4033c6a 100644
--- a/drivers/mtd/devices/Kconfig
+++ b/drivers/mtd/devices/Kconfig
@@ -1,5 +1,5 @@
1# drivers/mtd/maps/Kconfig 1# drivers/mtd/maps/Kconfig
2# $Id: Kconfig,v 1.15 2004/12/22 17:51:15 joern Exp $ 2# $Id: Kconfig,v 1.18 2005/11/07 11:14:24 gleixner Exp $
3 3
4menu "Self-contained MTD device drivers" 4menu "Self-contained MTD device drivers"
5 depends on MTD!=n 5 depends on MTD!=n
@@ -110,7 +110,7 @@ config MTDRAM_ABS_POS
110 If you have system RAM accessible by the CPU but not used by Linux 110 If you have system RAM accessible by the CPU but not used by Linux
111 in normal operation, you can give the physical address at which the 111 in normal operation, you can give the physical address at which the
112 available RAM starts, and the MTDRAM driver will use it instead of 112 available RAM starts, and the MTDRAM driver will use it instead of
113 allocating space from Linux's available memory. Otherwise, leave 113 allocating space from Linux's available memory. Otherwise, leave
114 this set to zero. Most people will want to leave this as zero. 114 this set to zero. Most people will want to leave this as zero.
115 115
116config MTD_BLKMTD 116config MTD_BLKMTD
@@ -165,7 +165,7 @@ config MTD_DOC2001
165 select MTD_DOCPROBE 165 select MTD_DOCPROBE
166 select MTD_NAND_IDS 166 select MTD_NAND_IDS
167 ---help--- 167 ---help---
168 This provides an alternative MTD device driver for the M-Systems 168 This provides an alternative MTD device driver for the M-Systems
169 DiskOnChip Millennium devices. Use this if you have problems with 169 DiskOnChip Millennium devices. Use this if you have problems with
170 the combined DiskOnChip 2000 and Millennium driver above. To get 170 the combined DiskOnChip 2000 and Millennium driver above. To get
171 the DiskOnChip probe code to load and use this driver instead of 171 the DiskOnChip probe code to load and use this driver instead of
@@ -192,7 +192,7 @@ config MTD_DOC2001PLUS
192 192
193 If you use this device, you probably also want to enable the INFTL 193 If you use this device, you probably also want to enable the INFTL
194 'Inverse NAND Flash Translation Layer' option below, which is used 194 'Inverse NAND Flash Translation Layer' option below, which is used
195 to emulate a block device by using a kind of file system on the 195 to emulate a block device by using a kind of file system on the
196 flash chips. 196 flash chips.
197 197
198 NOTE: This driver will soon be replaced by the new DiskOnChip driver 198 NOTE: This driver will soon be replaced by the new DiskOnChip driver
diff --git a/drivers/mtd/devices/blkmtd.c b/drivers/mtd/devices/blkmtd.c
index 662e807801ed..f9db52f6bf00 100644
--- a/drivers/mtd/devices/blkmtd.c
+++ b/drivers/mtd/devices/blkmtd.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: blkmtd.c,v 1.24 2004/11/16 18:29:01 dwmw2 Exp $ 2 * $Id: blkmtd.c,v 1.27 2005/11/07 11:14:24 gleixner Exp $
3 * 3 *
4 * blkmtd.c - use a block device as a fake MTD 4 * blkmtd.c - use a block device as a fake MTD
5 * 5 *
@@ -39,7 +39,7 @@
39 39
40/* Default erase size in K, always make it a multiple of PAGE_SIZE */ 40/* Default erase size in K, always make it a multiple of PAGE_SIZE */
41#define CONFIG_MTD_BLKDEV_ERASESIZE (128 << 10) /* 128KiB */ 41#define CONFIG_MTD_BLKDEV_ERASESIZE (128 << 10) /* 128KiB */
42#define VERSION "$Revision: 1.24 $" 42#define VERSION "$Revision: 1.27 $"
43 43
44/* Info for the block device */ 44/* Info for the block device */
45struct blkmtd_dev { 45struct blkmtd_dev {
@@ -117,7 +117,7 @@ static int bi_write_complete(struct bio *bio, unsigned int bytes_done, int error
117 unlock_page(page); 117 unlock_page(page);
118 page_cache_release(page); 118 page_cache_release(page);
119 } while (bvec >= bio->bi_io_vec); 119 } while (bvec >= bio->bi_io_vec);
120 120
121 complete((struct completion*)bio->bi_private); 121 complete((struct completion*)bio->bi_private);
122 return 0; 122 return 0;
123} 123}
@@ -135,7 +135,7 @@ static int blkmtd_readpage(struct blkmtd_dev *dev, struct page *page)
135 unlock_page(page); 135 unlock_page(page);
136 return 0; 136 return 0;
137 } 137 }
138 138
139 ClearPageUptodate(page); 139 ClearPageUptodate(page);
140 ClearPageError(page); 140 ClearPageError(page);
141 141
@@ -539,11 +539,8 @@ static void free_device(struct blkmtd_dev *dev)
539{ 539{
540 DEBUG(2, "blkmtd: free_device() dev = %p\n", dev); 540 DEBUG(2, "blkmtd: free_device() dev = %p\n", dev);
541 if(dev) { 541 if(dev) {
542 if(dev->mtd_info.eraseregions) 542 kfree(dev->mtd_info.eraseregions);
543 kfree(dev->mtd_info.eraseregions); 543 kfree(dev->mtd_info.name);
544 if(dev->mtd_info.name)
545 kfree(dev->mtd_info.name);
546
547 if(dev->blkdev) { 544 if(dev->blkdev) {
548 invalidate_inode_pages(dev->blkdev->bd_inode->i_mapping); 545 invalidate_inode_pages(dev->blkdev->bd_inode->i_mapping);
549 close_bdev_excl(dev->blkdev); 546 close_bdev_excl(dev->blkdev);
@@ -710,7 +707,7 @@ static struct blkmtd_dev *add_device(char *devname, int readonly, int erase_size
710 dev->mtd_info.erasesize >> 10, 707 dev->mtd_info.erasesize >> 10,
711 readonly ? "(read-only)" : ""); 708 readonly ? "(read-only)" : "");
712 } 709 }
713 710
714 return dev; 711 return dev;
715 712
716 devinit_err: 713 devinit_err:
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 4a7a805e7564..0aaa0ced9aba 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: block2mtd.c,v 1.28 2005/03/19 22:40:44 gleixner Exp $ 2 * $Id: block2mtd.c,v 1.29 2005/11/07 11:14:24 gleixner Exp $
3 * 3 *
4 * block2mtd.c - create an mtd from a block device 4 * block2mtd.c - create an mtd from a block device
5 * 5 *
@@ -19,7 +19,7 @@
19#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
20#include <linux/buffer_head.h> 20#include <linux/buffer_head.h>
21 21
22#define VERSION "$Revision: 1.28 $" 22#define VERSION "$Revision: 1.29 $"
23 23
24 24
25#define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args) 25#define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args)
@@ -111,7 +111,7 @@ static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len)
111 return PTR_ERR(page); 111 return PTR_ERR(page);
112 112
113 max = (u_long*)page_address(page) + PAGE_SIZE; 113 max = (u_long*)page_address(page) + PAGE_SIZE;
114 for (p=(u_long*)page_address(page); p<max; p++) 114 for (p=(u_long*)page_address(page); p<max; p++)
115 if (*p != -1UL) { 115 if (*p != -1UL) {
116 lock_page(page); 116 lock_page(page);
117 memset(page_address(page), 0xff, PAGE_SIZE); 117 memset(page_address(page), 0xff, PAGE_SIZE);
@@ -206,7 +206,7 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf,
206 if (retlen) 206 if (retlen)
207 *retlen = 0; 207 *retlen = 0;
208 while (len) { 208 while (len) {
209 if ((offset+len) > PAGE_SIZE) 209 if ((offset+len) > PAGE_SIZE)
210 cpylen = PAGE_SIZE - offset; // multiple pages 210 cpylen = PAGE_SIZE - offset; // multiple pages
211 else 211 else
212 cpylen = len; // this page 212 cpylen = len; // this page
diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
index 5fc532895a24..be5e88b3888d 100644
--- a/drivers/mtd/devices/doc2000.c
+++ b/drivers/mtd/devices/doc2000.c
@@ -4,7 +4,7 @@
4 * (c) 1999 Machine Vision Holdings, Inc. 4 * (c) 1999 Machine Vision Holdings, Inc.
5 * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org> 5 * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org>
6 * 6 *
7 * $Id: doc2000.c,v 1.66 2005/01/05 18:05:12 dwmw2 Exp $ 7 * $Id: doc2000.c,v 1.67 2005/11/07 11:14:24 gleixner Exp $
8 */ 8 */
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
@@ -58,7 +58,7 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
58 size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel); 58 size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
59static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len, 59static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
60 size_t *retlen, const u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel); 60 size_t *retlen, const u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
61static int doc_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs, 61static int doc_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
62 unsigned long count, loff_t to, size_t *retlen, 62 unsigned long count, loff_t to, size_t *retlen,
63 u_char *eccbuf, struct nand_oobinfo *oobsel); 63 u_char *eccbuf, struct nand_oobinfo *oobsel);
64static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len, 64static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
@@ -76,14 +76,14 @@ static void DoC_Delay(struct DiskOnChip *doc, unsigned short cycles)
76{ 76{
77 volatile char dummy; 77 volatile char dummy;
78 int i; 78 int i;
79 79
80 for (i = 0; i < cycles; i++) { 80 for (i = 0; i < cycles; i++) {
81 if (DoC_is_Millennium(doc)) 81 if (DoC_is_Millennium(doc))
82 dummy = ReadDOC(doc->virtadr, NOP); 82 dummy = ReadDOC(doc->virtadr, NOP);
83 else 83 else
84 dummy = ReadDOC(doc->virtadr, DOCStatus); 84 dummy = ReadDOC(doc->virtadr, DOCStatus);
85 } 85 }
86 86
87} 87}
88 88
89/* DOC_WaitReady: Wait for RDY line to be asserted by the flash chip */ 89/* DOC_WaitReady: Wait for RDY line to be asserted by the flash chip */
@@ -220,8 +220,8 @@ static int DoC_Address(struct DiskOnChip *doc, int numbytes, unsigned long ofs,
220 WriteDOC(ofs & 0xff, docptr, WritePipeTerm); 220 WriteDOC(ofs & 0xff, docptr, WritePipeTerm);
221 221
222 DoC_Delay(doc, 2); /* Needed for some slow flash chips. mf. */ 222 DoC_Delay(doc, 2); /* Needed for some slow flash chips. mf. */
223 223
224 /* FIXME: The SlowIO's for millennium could be replaced by 224 /* FIXME: The SlowIO's for millennium could be replaced by
225 a single WritePipeTerm here. mf. */ 225 a single WritePipeTerm here. mf. */
226 226
227 /* Lower the ALE line */ 227 /* Lower the ALE line */
@@ -377,9 +377,9 @@ static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip)
377 if (mfr == 0xff || mfr == 0) 377 if (mfr == 0xff || mfr == 0)
378 return 0; 378 return 0;
379 379
380 /* Check it's the same as the first chip we identified. 380 /* Check it's the same as the first chip we identified.
381 * M-Systems say that any given DiskOnChip device should only 381 * M-Systems say that any given DiskOnChip device should only
382 * contain _one_ type of flash part, although that's not a 382 * contain _one_ type of flash part, although that's not a
383 * hardware restriction. */ 383 * hardware restriction. */
384 if (doc->mfr) { 384 if (doc->mfr) {
385 if (doc->mfr == mfr && doc->id == id) 385 if (doc->mfr == mfr && doc->id == id)
@@ -397,7 +397,7 @@ static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip)
397 for (j = 0; nand_manuf_ids[j].id != 0x0; j++) { 397 for (j = 0; nand_manuf_ids[j].id != 0x0; j++) {
398 if (nand_manuf_ids[j].id == mfr) 398 if (nand_manuf_ids[j].id == mfr)
399 break; 399 break;
400 } 400 }
401 printk(KERN_INFO 401 printk(KERN_INFO
402 "Flash chip found: Manufacturer ID: %2.2X, " 402 "Flash chip found: Manufacturer ID: %2.2X, "
403 "Chip ID: %2.2X (%s:%s)\n", mfr, id, 403 "Chip ID: %2.2X (%s:%s)\n", mfr, id,
@@ -405,7 +405,7 @@ static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip)
405 if (!doc->mfr) { 405 if (!doc->mfr) {
406 doc->mfr = mfr; 406 doc->mfr = mfr;
407 doc->id = id; 407 doc->id = id;
408 doc->chipshift = 408 doc->chipshift =
409 ffs((nand_flash_ids[i].chipsize << 20)) - 1; 409 ffs((nand_flash_ids[i].chipsize << 20)) - 1;
410 doc->page256 = (nand_flash_ids[i].pagesize == 256) ? 1 : 0; 410 doc->page256 = (nand_flash_ids[i].pagesize == 256) ? 1 : 0;
411 doc->pageadrlen = doc->chipshift > 25 ? 3 : 2; 411 doc->pageadrlen = doc->chipshift > 25 ? 3 : 2;
@@ -467,7 +467,7 @@ static void DoC_ScanChips(struct DiskOnChip *this, int maxchips)
467 467
468 ret = 0; 468 ret = 0;
469 469
470 /* Fill out the chip array with {floor, chipno} for each 470 /* Fill out the chip array with {floor, chipno} for each
471 * detected chip in the device. */ 471 * detected chip in the device. */
472 for (floor = 0; floor < MAX_FLOORS; floor++) { 472 for (floor = 0; floor < MAX_FLOORS; floor++) {
473 for (chip = 0; chip < numchips[floor]; chip++) { 473 for (chip = 0; chip < numchips[floor]; chip++) {
@@ -757,12 +757,12 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
757 (long)from, eccbuf[0], eccbuf[1], eccbuf[2], 757 (long)from, eccbuf[0], eccbuf[1], eccbuf[2],
758 eccbuf[3], eccbuf[4], eccbuf[5]); 758 eccbuf[3], eccbuf[4], eccbuf[5]);
759#endif 759#endif
760 760
761 /* disable the ECC engine */ 761 /* disable the ECC engine */
762 WriteDOC(DOC_ECC_DIS, docptr , ECCConf); 762 WriteDOC(DOC_ECC_DIS, docptr , ECCConf);
763 } 763 }
764 764
765 /* according to 11.4.1, we need to wait for the busy line 765 /* according to 11.4.1, we need to wait for the busy line
766 * drop if we read to the end of the page. */ 766 * drop if we read to the end of the page. */
767 if(0 == ((from + len) & 0x1ff)) 767 if(0 == ((from + len) & 0x1ff))
768 { 768 {
@@ -941,7 +941,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
941 941
942 /* Let the caller know we completed it */ 942 /* Let the caller know we completed it */
943 *retlen += len; 943 *retlen += len;
944 944
945 if (eccbuf) { 945 if (eccbuf) {
946 unsigned char x[8]; 946 unsigned char x[8];
947 size_t dummy; 947 size_t dummy;
@@ -950,10 +950,10 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
950 /* Write the ECC data to flash */ 950 /* Write the ECC data to flash */
951 for (di=0; di<6; di++) 951 for (di=0; di<6; di++)
952 x[di] = eccbuf[di]; 952 x[di] = eccbuf[di];
953 953
954 x[6]=0x55; 954 x[6]=0x55;
955 x[7]=0x55; 955 x[7]=0x55;
956 956
957 ret = doc_write_oob_nolock(mtd, to, 8, &dummy, x); 957 ret = doc_write_oob_nolock(mtd, to, 8, &dummy, x);
958 if (ret) { 958 if (ret) {
959 up(&this->lock); 959 up(&this->lock);
@@ -970,7 +970,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
970 return 0; 970 return 0;
971} 971}
972 972
973static int doc_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs, 973static int doc_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
974 unsigned long count, loff_t to, size_t *retlen, 974 unsigned long count, loff_t to, size_t *retlen,
975 u_char *eccbuf, struct nand_oobinfo *oobsel) 975 u_char *eccbuf, struct nand_oobinfo *oobsel)
976{ 976{
@@ -1022,7 +1022,7 @@ static int doc_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
1022 break; 1022 break;
1023 1023
1024 to += thislen; 1024 to += thislen;
1025 } 1025 }
1026 1026
1027 up(&writev_buf_sem); 1027 up(&writev_buf_sem);
1028 *retlen = totretlen; 1028 *retlen = totretlen;
@@ -1080,7 +1080,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
1080 /* Reading the full OOB data drops us off of the end of the page, 1080 /* Reading the full OOB data drops us off of the end of the page,
1081 * causing the flash device to go into busy mode, so we need 1081 * causing the flash device to go into busy mode, so we need
1082 * to wait until ready 11.4.1 and Toshiba TC58256FT docs */ 1082 * to wait until ready 11.4.1 and Toshiba TC58256FT docs */
1083 1083
1084 ret = DoC_WaitReady(this); 1084 ret = DoC_WaitReady(this);
1085 1085
1086 up(&this->lock); 1086 up(&this->lock);
@@ -1190,7 +1190,7 @@ static int doc_write_oob_nolock(struct mtd_info *mtd, loff_t ofs, size_t len,
1190 return 0; 1190 return 0;
1191 1191
1192} 1192}
1193 1193
1194static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len, 1194static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
1195 size_t * retlen, const u_char * buf) 1195 size_t * retlen, const u_char * buf)
1196{ 1196{
@@ -1222,7 +1222,7 @@ static int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
1222 } 1222 }
1223 1223
1224 instr->state = MTD_ERASING; 1224 instr->state = MTD_ERASING;
1225 1225
1226 /* FIXME: Do this in the background. Use timers or schedule_task() */ 1226 /* FIXME: Do this in the background. Use timers or schedule_task() */
1227 while(len) { 1227 while(len) {
1228 mychip = &this->chips[ofs >> this->chipshift]; 1228 mychip = &this->chips[ofs >> this->chipshift];
diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
index 1e704915ef08..fcb28a6fd89f 100644
--- a/drivers/mtd/devices/doc2001.c
+++ b/drivers/mtd/devices/doc2001.c
@@ -4,7 +4,7 @@
4 * (c) 1999 Machine Vision Holdings, Inc. 4 * (c) 1999 Machine Vision Holdings, Inc.
5 * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org> 5 * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org>
6 * 6 *
7 * $Id: doc2001.c,v 1.48 2005/01/05 18:05:12 dwmw2 Exp $ 7 * $Id: doc2001.c,v 1.49 2005/11/07 11:14:24 gleixner Exp $
8 */ 8 */
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
@@ -196,10 +196,10 @@ static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip)
196 DoC_Command(doc->virtadr, NAND_CMD_RESET, CDSN_CTRL_WP); 196 DoC_Command(doc->virtadr, NAND_CMD_RESET, CDSN_CTRL_WP);
197 DoC_WaitReady(doc->virtadr); 197 DoC_WaitReady(doc->virtadr);
198 198
199 /* Read the NAND chip ID: 1. Send ReadID command */ 199 /* Read the NAND chip ID: 1. Send ReadID command */
200 DoC_Command(doc->virtadr, NAND_CMD_READID, CDSN_CTRL_WP); 200 DoC_Command(doc->virtadr, NAND_CMD_READID, CDSN_CTRL_WP);
201 201
202 /* Read the NAND chip ID: 2. Send address byte zero */ 202 /* Read the NAND chip ID: 2. Send address byte zero */
203 DoC_Address(doc->virtadr, 1, 0x00, CDSN_CTRL_WP, 0x00); 203 DoC_Address(doc->virtadr, 1, 0x00, CDSN_CTRL_WP, 0x00);
204 204
205 /* Read the manufacturer and device id codes of the flash device through 205 /* Read the manufacturer and device id codes of the flash device through
@@ -223,7 +223,7 @@ static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip)
223 for (j = 0; nand_manuf_ids[j].id != 0x0; j++) { 223 for (j = 0; nand_manuf_ids[j].id != 0x0; j++) {
224 if (nand_manuf_ids[j].id == mfr) 224 if (nand_manuf_ids[j].id == mfr)
225 break; 225 break;
226 } 226 }
227 printk(KERN_INFO "Flash chip found: Manufacturer ID: %2.2X, " 227 printk(KERN_INFO "Flash chip found: Manufacturer ID: %2.2X, "
228 "Chip ID: %2.2X (%s:%s)\n", 228 "Chip ID: %2.2X (%s:%s)\n",
229 mfr, id, nand_manuf_ids[j].name, nand_flash_ids[i].name); 229 mfr, id, nand_manuf_ids[j].name, nand_flash_ids[i].name);
@@ -275,7 +275,7 @@ static void DoC_ScanChips(struct DiskOnChip *this)
275 return; 275 return;
276 } 276 }
277 277
278 /* Fill out the chip array with {floor, chipno} for each 278 /* Fill out the chip array with {floor, chipno} for each
279 * detected chip in the device. */ 279 * detected chip in the device. */
280 for (floor = 0, ret = 0; floor < MAX_FLOORS_MIL; floor++) { 280 for (floor = 0, ret = 0; floor < MAX_FLOORS_MIL; floor++) {
281 for (chip = 0 ; chip < numchips[floor] ; chip++) { 281 for (chip = 0 ; chip < numchips[floor] ; chip++) {
@@ -309,7 +309,7 @@ static int DoCMil_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2)
309 tmp2 = ReadDOC(doc2->virtadr, AliasResolution); 309 tmp2 = ReadDOC(doc2->virtadr, AliasResolution);
310 if (tmp1 != tmp2) 310 if (tmp1 != tmp2)
311 return 0; 311 return 0;
312 312
313 WriteDOC((tmp1+1) % 0xff, doc1->virtadr, AliasResolution); 313 WriteDOC((tmp1+1) % 0xff, doc1->virtadr, AliasResolution);
314 tmp2 = ReadDOC(doc2->virtadr, AliasResolution); 314 tmp2 = ReadDOC(doc2->virtadr, AliasResolution);
315 if (tmp2 == (tmp1+1) % 0xff) 315 if (tmp2 == (tmp1+1) % 0xff)
@@ -425,7 +425,7 @@ static int doc_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
425 return -EINVAL; 425 return -EINVAL;
426 426
427 /* Don't allow a single read to cross a 512-byte block boundary */ 427 /* Don't allow a single read to cross a 512-byte block boundary */
428 if (from + len > ((from | 0x1ff) + 1)) 428 if (from + len > ((from | 0x1ff) + 1))
429 len = ((from | 0x1ff) + 1) - from; 429 len = ((from | 0x1ff) + 1) - from;
430 430
431 /* Find the chip which is to be used and select it */ 431 /* Find the chip which is to be used and select it */
@@ -552,7 +552,7 @@ static int doc_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
552 552
553#if 0 553#if 0
554 /* Don't allow a single write to cross a 512-byte block boundary */ 554 /* Don't allow a single write to cross a 512-byte block boundary */
555 if (to + len > ( (to | 0x1ff) + 1)) 555 if (to + len > ( (to | 0x1ff) + 1))
556 len = ((to | 0x1ff) + 1) - to; 556 len = ((to | 0x1ff) + 1) - to;
557#else 557#else
558 /* Don't allow writes which aren't exactly one block */ 558 /* Don't allow writes which aren't exactly one block */
@@ -632,7 +632,7 @@ static int doc_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
632 632
633 /* write the block status BLOCK_USED (0x5555) at the end of ECC data 633 /* write the block status BLOCK_USED (0x5555) at the end of ECC data
634 FIXME: this is only a hack for programming the IPL area for LinuxBIOS 634 FIXME: this is only a hack for programming the IPL area for LinuxBIOS
635 and should be replace with proper codes in user space utilities */ 635 and should be replace with proper codes in user space utilities */
636 WriteDOC(0x55, docptr, Mil_CDSN_IO); 636 WriteDOC(0x55, docptr, Mil_CDSN_IO);
637 WriteDOC(0x55, docptr, Mil_CDSN_IO + 1); 637 WriteDOC(0x55, docptr, Mil_CDSN_IO + 1);
638 638
@@ -802,7 +802,7 @@ int doc_erase (struct mtd_info *mtd, struct erase_info *instr)
802 void __iomem *docptr = this->virtadr; 802 void __iomem *docptr = this->virtadr;
803 struct Nand *mychip = &this->chips[ofs >> this->chipshift]; 803 struct Nand *mychip = &this->chips[ofs >> this->chipshift];
804 804
805 if (len != mtd->erasesize) 805 if (len != mtd->erasesize)
806 printk(KERN_WARNING "Erase not right size (%x != %x)n", 806 printk(KERN_WARNING "Erase not right size (%x != %x)n",
807 len, mtd->erasesize); 807 len, mtd->erasesize);
808 808
@@ -870,9 +870,9 @@ static void __exit cleanup_doc2001(void)
870 while ((mtd=docmillist)) { 870 while ((mtd=docmillist)) {
871 this = mtd->priv; 871 this = mtd->priv;
872 docmillist = this->nextdoc; 872 docmillist = this->nextdoc;
873 873
874 del_mtd_device(mtd); 874 del_mtd_device(mtd);
875 875
876 iounmap(this->virtadr); 876 iounmap(this->virtadr);
877 kfree(this->chips); 877 kfree(this->chips);
878 kfree(mtd); 878 kfree(mtd);
diff --git a/drivers/mtd/devices/doc2001plus.c b/drivers/mtd/devices/doc2001plus.c
index ed47bafb2ce2..0595cc7324b2 100644
--- a/drivers/mtd/devices/doc2001plus.c
+++ b/drivers/mtd/devices/doc2001plus.c
@@ -6,7 +6,7 @@
6 * (c) 1999 Machine Vision Holdings, Inc. 6 * (c) 1999 Machine Vision Holdings, Inc.
7 * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org> 7 * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org>
8 * 8 *
9 * $Id: doc2001plus.c,v 1.13 2005/01/05 18:05:12 dwmw2 Exp $ 9 * $Id: doc2001plus.c,v 1.14 2005/11/07 11:14:24 gleixner Exp $
10 * 10 *
11 * Released under GPL 11 * Released under GPL
12 */ 12 */
@@ -293,10 +293,10 @@ static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip)
293 DoC_Command(docptr, NAND_CMD_RESET, 0); 293 DoC_Command(docptr, NAND_CMD_RESET, 0);
294 DoC_WaitReady(docptr); 294 DoC_WaitReady(docptr);
295 295
296 /* Read the NAND chip ID: 1. Send ReadID command */ 296 /* Read the NAND chip ID: 1. Send ReadID command */
297 DoC_Command(docptr, NAND_CMD_READID, 0); 297 DoC_Command(docptr, NAND_CMD_READID, 0);
298 298
299 /* Read the NAND chip ID: 2. Send address byte zero */ 299 /* Read the NAND chip ID: 2. Send address byte zero */
300 DoC_Address(doc, 1, 0x00, 0, 0x00); 300 DoC_Address(doc, 1, 0x00, 0, 0x00);
301 301
302 WriteDOC(0, docptr, Mplus_FlashControl); 302 WriteDOC(0, docptr, Mplus_FlashControl);
@@ -365,7 +365,7 @@ static void DoC_ScanChips(struct DiskOnChip *this)
365 this->interleave = 1; 365 this->interleave = 1;
366 366
367 /* Check the ASIC agrees */ 367 /* Check the ASIC agrees */
368 if ( (this->interleave << 2) != 368 if ( (this->interleave << 2) !=
369 (ReadDOC(this->virtadr, Mplus_Configuration) & 4)) { 369 (ReadDOC(this->virtadr, Mplus_Configuration) & 4)) {
370 u_char conf = ReadDOC(this->virtadr, Mplus_Configuration); 370 u_char conf = ReadDOC(this->virtadr, Mplus_Configuration);
371 printk(KERN_NOTICE "Setting DiskOnChip Millennium Plus interleave to %s\n", 371 printk(KERN_NOTICE "Setting DiskOnChip Millennium Plus interleave to %s\n",
@@ -398,7 +398,7 @@ static void DoC_ScanChips(struct DiskOnChip *this)
398 return; 398 return;
399 } 399 }
400 400
401 /* Fill out the chip array with {floor, chipno} for each 401 /* Fill out the chip array with {floor, chipno} for each
402 * detected chip in the device. */ 402 * detected chip in the device. */
403 for (floor = 0, ret = 0; floor < MAX_FLOORS_MPLUS; floor++) { 403 for (floor = 0, ret = 0; floor < MAX_FLOORS_MPLUS; floor++) {
404 for (chip = 0 ; chip < numchips[floor] ; chip++) { 404 for (chip = 0 ; chip < numchips[floor] ; chip++) {
@@ -432,7 +432,7 @@ static int DoCMilPlus_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2)
432 tmp2 = ReadDOC(doc2->virtadr, Mplus_AliasResolution); 432 tmp2 = ReadDOC(doc2->virtadr, Mplus_AliasResolution);
433 if (tmp1 != tmp2) 433 if (tmp1 != tmp2)
434 return 0; 434 return 0;
435 435
436 WriteDOC((tmp1+1) % 0xff, doc1->virtadr, Mplus_AliasResolution); 436 WriteDOC((tmp1+1) % 0xff, doc1->virtadr, Mplus_AliasResolution);
437 tmp2 = ReadDOC(doc2->virtadr, Mplus_AliasResolution); 437 tmp2 = ReadDOC(doc2->virtadr, Mplus_AliasResolution);
438 if (tmp2 == (tmp1+1) % 0xff) 438 if (tmp2 == (tmp1+1) % 0xff)
@@ -624,7 +624,7 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
624 return -EINVAL; 624 return -EINVAL;
625 625
626 /* Don't allow a single read to cross a 512-byte block boundary */ 626 /* Don't allow a single read to cross a 512-byte block boundary */
627 if (from + len > ((from | 0x1ff) + 1)) 627 if (from + len > ((from | 0x1ff) + 1))
628 len = ((from | 0x1ff) + 1) - from; 628 len = ((from | 0x1ff) + 1) - from;
629 629
630 DoC_CheckASIC(docptr); 630 DoC_CheckASIC(docptr);
@@ -1066,7 +1066,7 @@ int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
1066 1066
1067 DoC_CheckASIC(docptr); 1067 DoC_CheckASIC(docptr);
1068 1068
1069 if (len != mtd->erasesize) 1069 if (len != mtd->erasesize)
1070 printk(KERN_WARNING "MTD: Erase not right size (%x != %x)n", 1070 printk(KERN_WARNING "MTD: Erase not right size (%x != %x)n",
1071 len, mtd->erasesize); 1071 len, mtd->erasesize);
1072 1072
@@ -1136,9 +1136,9 @@ static void __exit cleanup_doc2001plus(void)
1136 while ((mtd=docmilpluslist)) { 1136 while ((mtd=docmilpluslist)) {
1137 this = mtd->priv; 1137 this = mtd->priv;
1138 docmilpluslist = this->nextdoc; 1138 docmilpluslist = this->nextdoc;
1139 1139
1140 del_mtd_device(mtd); 1140 del_mtd_device(mtd);
1141 1141
1142 iounmap(this->virtadr); 1142 iounmap(this->virtadr);
1143 kfree(this->chips); 1143 kfree(this->chips);
1144 kfree(mtd); 1144 kfree(mtd);
diff --git a/drivers/mtd/devices/docecc.c b/drivers/mtd/devices/docecc.c
index 24f670b5a4f3..cd3db72bef96 100644
--- a/drivers/mtd/devices/docecc.c
+++ b/drivers/mtd/devices/docecc.c
@@ -4,10 +4,10 @@
4 * GNU GPL License. The rest is simply to convert the disk on chip 4 * GNU GPL License. The rest is simply to convert the disk on chip
5 * syndrom into a standard syndom. 5 * syndrom into a standard syndom.
6 * 6 *
7 * Author: Fabrice Bellard (fabrice.bellard@netgem.com) 7 * Author: Fabrice Bellard (fabrice.bellard@netgem.com)
8 * Copyright (C) 2000 Netgem S.A. 8 * Copyright (C) 2000 Netgem S.A.
9 * 9 *
10 * $Id: docecc.c,v 1.5 2003/05/21 15:15:06 dwmw2 Exp $ 10 * $Id: docecc.c,v 1.7 2005/11/07 11:14:25 gleixner Exp $
11 * 11 *
12 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
@@ -122,7 +122,7 @@ for(ci=(n)-1;ci >=0;ci--)\
122 a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1) 122 a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1)
123 we consider the integer "i" whose binary representation with a(0) being LSB 123 we consider the integer "i" whose binary representation with a(0) being LSB
124 and a(m-1) MSB is (a(0),a(1),...,a(m-1)) and locate the entry 124 and a(m-1) MSB is (a(0),a(1),...,a(m-1)) and locate the entry
125 "index_of[i]". Now, @^index_of[i] is that element whose polynomial 125 "index_of[i]". Now, @^index_of[i] is that element whose polynomial
126 representation is (a(0),a(1),a(2),...,a(m-1)). 126 representation is (a(0),a(1),a(2),...,a(m-1)).
127 NOTE: 127 NOTE:
128 The element alpha_to[2^m-1] = 0 always signifying that the 128 The element alpha_to[2^m-1] = 0 always signifying that the
@@ -130,7 +130,7 @@ for(ci=(n)-1;ci >=0;ci--)\
130 Similarily, the element index_of[0] = A0 always signifying 130 Similarily, the element index_of[0] = A0 always signifying
131 that the power of alpha which has the polynomial representation 131 that the power of alpha which has the polynomial representation
132 (0,0,...,0) is "infinity". 132 (0,0,...,0) is "infinity".
133 133
134*/ 134*/
135 135
136static void 136static void
@@ -176,7 +176,7 @@ generate_gf(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1])
176 * are written back. NOTE! This array must be at least NN-KK elements long. 176 * are written back. NOTE! This array must be at least NN-KK elements long.
177 * The corrected data are written in eras_val[]. They must be xor with the data 177 * The corrected data are written in eras_val[]. They must be xor with the data
178 * to retrieve the correct data : data[erase_pos[i]] ^= erase_val[i] . 178 * to retrieve the correct data : data[erase_pos[i]] ^= erase_val[i] .
179 * 179 *
180 * First "no_eras" erasures are declared by the calling program. Then, the 180 * First "no_eras" erasures are declared by the calling program. Then, the
181 * maximum # of errors correctable is t_after_eras = floor((NN-KK-no_eras)/2). 181 * maximum # of errors correctable is t_after_eras = floor((NN-KK-no_eras)/2).
182 * If the number of channel errors is not greater than "t_after_eras" the 182 * If the number of channel errors is not greater than "t_after_eras" the
@@ -189,7 +189,7 @@ generate_gf(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1])
189 * */ 189 * */
190static int 190static int
191eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1], 191eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1],
192 gf bb[NN - KK + 1], gf eras_val[NN-KK], int eras_pos[NN-KK], 192 gf bb[NN - KK + 1], gf eras_val[NN-KK], int eras_pos[NN-KK],
193 int no_eras) 193 int no_eras)
194{ 194{
195 int deg_lambda, el, deg_omega; 195 int deg_lambda, el, deg_omega;
@@ -212,7 +212,7 @@ eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1],
212 count = 0; 212 count = 0;
213 goto finish; 213 goto finish;
214 } 214 }
215 215
216 for(i=1;i<=NN-KK;i++){ 216 for(i=1;i<=NN-KK;i++){
217 s[i] = bb[0]; 217 s[i] = bb[0];
218 } 218 }
@@ -220,7 +220,7 @@ eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1],
220 if(bb[j] == 0) 220 if(bb[j] == 0)
221 continue; 221 continue;
222 tmp = Index_of[bb[j]]; 222 tmp = Index_of[bb[j]];
223 223
224 for(i=1;i<=NN-KK;i++) 224 for(i=1;i<=NN-KK;i++)
225 s[i] ^= Alpha_to[modnn(tmp + (B0+i-1)*PRIM*j)]; 225 s[i] ^= Alpha_to[modnn(tmp + (B0+i-1)*PRIM*j)];
226 } 226 }
@@ -234,7 +234,7 @@ eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1],
234 tmp = modnn(tmp + 2 * KK * (B0+i-1)*PRIM); 234 tmp = modnn(tmp + 2 * KK * (B0+i-1)*PRIM);
235 s[i] = tmp; 235 s[i] = tmp;
236 } 236 }
237 237
238 CLEAR(&lambda[1],NN-KK); 238 CLEAR(&lambda[1],NN-KK);
239 lambda[0] = 1; 239 lambda[0] = 1;
240 240
@@ -252,7 +252,7 @@ eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1],
252#if DEBUG_ECC >= 1 252#if DEBUG_ECC >= 1
253 /* Test code that verifies the erasure locator polynomial just constructed 253 /* Test code that verifies the erasure locator polynomial just constructed
254 Needed only for decoder debugging. */ 254 Needed only for decoder debugging. */
255 255
256 /* find roots of the erasure location polynomial */ 256 /* find roots of the erasure location polynomial */
257 for(i=1;i<=no_eras;i++) 257 for(i=1;i<=no_eras;i++)
258 reg[i] = Index_of[lambda[i]]; 258 reg[i] = Index_of[lambda[i]];
@@ -286,7 +286,7 @@ eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1],
286 } 286 }
287 for(i=0;i<NN-KK+1;i++) 287 for(i=0;i<NN-KK+1;i++)
288 b[i] = Index_of[lambda[i]]; 288 b[i] = Index_of[lambda[i]];
289 289
290 /* 290 /*
291 * Begin Berlekamp-Massey algorithm to determine error+erasure 291 * Begin Berlekamp-Massey algorithm to determine error+erasure
292 * locator polynomial 292 * locator polynomial
@@ -389,7 +389,7 @@ eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1],
389 omega[i] = Index_of[tmp]; 389 omega[i] = Index_of[tmp];
390 } 390 }
391 omega[NN-KK] = A0; 391 omega[NN-KK] = A0;
392 392
393 /* 393 /*
394 * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 = 394 * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 =
395 * inv(X(l))**(B0-1) and den = lambda_pr(inv(X(l))) all in poly-form 395 * inv(X(l))**(B0-1) and den = lambda_pr(inv(X(l))) all in poly-form
@@ -402,7 +402,7 @@ eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1],
402 } 402 }
403 num2 = Alpha_to[modnn(root[j] * (B0 - 1) + NN)]; 403 num2 = Alpha_to[modnn(root[j] * (B0 - 1) + NN)];
404 den = 0; 404 den = 0;
405 405
406 /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */ 406 /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */
407 for (i = min(deg_lambda,NN-KK-1) & ~1; i >= 0; i -=2) { 407 for (i = min(deg_lambda,NN-KK-1) & ~1; i >= 0; i -=2) {
408 if(lambda[i+1] != A0) 408 if(lambda[i+1] != A0)
@@ -436,11 +436,11 @@ eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1],
436/* The sector bytes are packed into NB_DATA MM bits words */ 436/* The sector bytes are packed into NB_DATA MM bits words */
437#define NB_DATA (((SECTOR_SIZE + 1) * 8 + 6) / MM) 437#define NB_DATA (((SECTOR_SIZE + 1) * 8 + 6) / MM)
438 438
439/* 439/*
440 * Correct the errors in 'sector[]' by using 'ecc1[]' which is the 440 * Correct the errors in 'sector[]' by using 'ecc1[]' which is the
441 * content of the feedback shift register applyied to the sector and 441 * content of the feedback shift register applyied to the sector and
442 * the ECC. Return the number of errors corrected (and correct them in 442 * the ECC. Return the number of errors corrected (and correct them in
443 * sector), or -1 if error 443 * sector), or -1 if error
444 */ 444 */
445int doc_decode_ecc(unsigned char sector[SECTOR_SIZE], unsigned char ecc1[6]) 445int doc_decode_ecc(unsigned char sector[SECTOR_SIZE], unsigned char ecc1[6])
446{ 446{
@@ -454,7 +454,7 @@ int doc_decode_ecc(unsigned char sector[SECTOR_SIZE], unsigned char ecc1[6])
454 Alpha_to = kmalloc((NN + 1) * sizeof(dtype), GFP_KERNEL); 454 Alpha_to = kmalloc((NN + 1) * sizeof(dtype), GFP_KERNEL);
455 if (!Alpha_to) 455 if (!Alpha_to)
456 return -1; 456 return -1;
457 457
458 Index_of = kmalloc((NN + 1) * sizeof(dtype), GFP_KERNEL); 458 Index_of = kmalloc((NN + 1) * sizeof(dtype), GFP_KERNEL);
459 if (!Index_of) { 459 if (!Index_of) {
460 kfree(Alpha_to); 460 kfree(Alpha_to);
@@ -470,7 +470,7 @@ int doc_decode_ecc(unsigned char sector[SECTOR_SIZE], unsigned char ecc1[6])
470 bb[2] = ((ecc1[2] & 0xf0) >> 4) | ((ecc1[3] & 0x3f) << 4); 470 bb[2] = ((ecc1[2] & 0xf0) >> 4) | ((ecc1[3] & 0x3f) << 4);
471 bb[3] = ((ecc1[3] & 0xc0) >> 6) | ((ecc1[0] & 0xff) << 2); 471 bb[3] = ((ecc1[3] & 0xc0) >> 6) | ((ecc1[0] & 0xff) << 2);
472 472
473 nb_errors = eras_dec_rs(Alpha_to, Index_of, bb, 473 nb_errors = eras_dec_rs(Alpha_to, Index_of, bb,
474 error_val, error_pos, 0); 474 error_val, error_pos, 0);
475 if (nb_errors <= 0) 475 if (nb_errors <= 0)
476 goto the_end; 476 goto the_end;
@@ -489,7 +489,7 @@ int doc_decode_ecc(unsigned char sector[SECTOR_SIZE], unsigned char ecc1[6])
489 can be modified since pos is even */ 489 can be modified since pos is even */
490 index = (pos >> 3) ^ 1; 490 index = (pos >> 3) ^ 1;
491 bitpos = pos & 7; 491 bitpos = pos & 7;
492 if ((index >= 0 && index < SECTOR_SIZE) || 492 if ((index >= 0 && index < SECTOR_SIZE) ||
493 index == (SECTOR_SIZE + 1)) { 493 index == (SECTOR_SIZE + 1)) {
494 val = error_val[i] >> (2 + bitpos); 494 val = error_val[i] >> (2 + bitpos);
495 parity ^= val; 495 parity ^= val;
@@ -500,7 +500,7 @@ int doc_decode_ecc(unsigned char sector[SECTOR_SIZE], unsigned char ecc1[6])
500 bitpos = (bitpos + 10) & 7; 500 bitpos = (bitpos + 10) & 7;
501 if (bitpos == 0) 501 if (bitpos == 0)
502 bitpos = 8; 502 bitpos = 8;
503 if ((index >= 0 && index < SECTOR_SIZE) || 503 if ((index >= 0 && index < SECTOR_SIZE) ||
504 index == (SECTOR_SIZE + 1)) { 504 index == (SECTOR_SIZE + 1)) {
505 val = error_val[i] << (8 - bitpos); 505 val = error_val[i] << (8 - bitpos);
506 parity ^= val; 506 parity ^= val;
@@ -509,7 +509,7 @@ int doc_decode_ecc(unsigned char sector[SECTOR_SIZE], unsigned char ecc1[6])
509 } 509 }
510 } 510 }
511 } 511 }
512 512
513 /* use parity to test extra errors */ 513 /* use parity to test extra errors */
514 if ((parity & 0xff) != 0) 514 if ((parity & 0xff) != 0)
515 nb_errors = -1; 515 nb_errors = -1;
diff --git a/drivers/mtd/devices/docprobe.c b/drivers/mtd/devices/docprobe.c
index 197d67045e1e..13178b9dd00a 100644
--- a/drivers/mtd/devices/docprobe.c
+++ b/drivers/mtd/devices/docprobe.c
@@ -4,22 +4,22 @@
4/* (C) 1999 Machine Vision Holdings, Inc. */ 4/* (C) 1999 Machine Vision Holdings, Inc. */
5/* (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> */ 5/* (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> */
6 6
7/* $Id: docprobe.c,v 1.44 2005/01/05 12:40:36 dwmw2 Exp $ */ 7/* $Id: docprobe.c,v 1.46 2005/11/07 11:14:25 gleixner Exp $ */
8 8
9 9
10 10
11/* DOC_PASSIVE_PROBE: 11/* DOC_PASSIVE_PROBE:
12 In order to ensure that the BIOS checksum is correct at boot time, and 12 In order to ensure that the BIOS checksum is correct at boot time, and
13 hence that the onboard BIOS extension gets executed, the DiskOnChip 13 hence that the onboard BIOS extension gets executed, the DiskOnChip
14 goes into reset mode when it is read sequentially: all registers 14 goes into reset mode when it is read sequentially: all registers
15 return 0xff until the chip is woken up again by writing to the 15 return 0xff until the chip is woken up again by writing to the
16 DOCControl register. 16 DOCControl register.
17 17
18 Unfortunately, this means that the probe for the DiskOnChip is unsafe, 18 Unfortunately, this means that the probe for the DiskOnChip is unsafe,
19 because one of the first things it does is write to where it thinks 19 because one of the first things it does is write to where it thinks
20 the DOCControl register should be - which may well be shared memory 20 the DOCControl register should be - which may well be shared memory
21 for another device. I've had machines which lock up when this is 21 for another device. I've had machines which lock up when this is
22 attempted. Hence the possibility to do a passive probe, which will fail 22 attempted. Hence the possibility to do a passive probe, which will fail
23 to detect a chip in reset mode, but is at least guaranteed not to lock 23 to detect a chip in reset mode, but is at least guaranteed not to lock
24 the machine. 24 the machine.
25 25
@@ -33,9 +33,9 @@
33 33
34 The old Millennium-only driver has been retained just in case there 34 The old Millennium-only driver has been retained just in case there
35 are problems with the new code. If the combined driver doesn't work 35 are problems with the new code. If the combined driver doesn't work
36 for you, you can try the old one by undefining DOC_SINGLE_DRIVER 36 for you, you can try the old one by undefining DOC_SINGLE_DRIVER
37 below and also enabling it in your configuration. If this fixes the 37 below and also enabling it in your configuration. If this fixes the
38 problems, please send a report to the MTD mailing list at 38 problems, please send a report to the MTD mailing list at
39 <linux-mtd@lists.infradead.org>. 39 <linux-mtd@lists.infradead.org>.
40*/ 40*/
41#define DOC_SINGLE_DRIVER 41#define DOC_SINGLE_DRIVER
@@ -68,16 +68,16 @@ MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe
68static unsigned long __initdata doc_locations[] = { 68static unsigned long __initdata doc_locations[] = {
69#if defined (__alpha__) || defined(__i386__) || defined(__x86_64__) 69#if defined (__alpha__) || defined(__i386__) || defined(__x86_64__)
70#ifdef CONFIG_MTD_DOCPROBE_HIGH 70#ifdef CONFIG_MTD_DOCPROBE_HIGH
71 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000, 71 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000,
72 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000, 72 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000,
73 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000, 73 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000,
74 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000, 74 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000,
75 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000, 75 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000,
76#else /* CONFIG_MTD_DOCPROBE_HIGH */ 76#else /* CONFIG_MTD_DOCPROBE_HIGH */
77 0xc8000, 0xca000, 0xcc000, 0xce000, 77 0xc8000, 0xca000, 0xcc000, 0xce000,
78 0xd0000, 0xd2000, 0xd4000, 0xd6000, 78 0xd0000, 0xd2000, 0xd4000, 0xd6000,
79 0xd8000, 0xda000, 0xdc000, 0xde000, 79 0xd8000, 0xda000, 0xdc000, 0xde000,
80 0xe0000, 0xe2000, 0xe4000, 0xe6000, 80 0xe0000, 0xe2000, 0xe4000, 0xe6000,
81 0xe8000, 0xea000, 0xec000, 0xee000, 81 0xe8000, 0xea000, 0xec000, 0xee000,
82#endif /* CONFIG_MTD_DOCPROBE_HIGH */ 82#endif /* CONFIG_MTD_DOCPROBE_HIGH */
83#elif defined(__PPC__) 83#elif defined(__PPC__)
@@ -111,35 +111,35 @@ static inline int __init doccheck(void __iomem *potential, unsigned long physadr
111 return 0; 111 return 0;
112#endif /* CONFIG_MTD_DOCPROBE_55AA */ 112#endif /* CONFIG_MTD_DOCPROBE_55AA */
113 113
114#ifndef DOC_PASSIVE_PROBE 114#ifndef DOC_PASSIVE_PROBE
115 /* It's not possible to cleanly detect the DiskOnChip - the 115 /* It's not possible to cleanly detect the DiskOnChip - the
116 * bootup procedure will put the device into reset mode, and 116 * bootup procedure will put the device into reset mode, and
117 * it's not possible to talk to it without actually writing 117 * it's not possible to talk to it without actually writing
118 * to the DOCControl register. So we store the current contents 118 * to the DOCControl register. So we store the current contents
119 * of the DOCControl register's location, in case we later decide 119 * of the DOCControl register's location, in case we later decide
120 * that it's not a DiskOnChip, and want to put it back how we 120 * that it's not a DiskOnChip, and want to put it back how we
121 * found it. 121 * found it.
122 */ 122 */
123 tmp2 = ReadDOC(window, DOCControl); 123 tmp2 = ReadDOC(window, DOCControl);
124 124
125 /* Reset the DiskOnChip ASIC */ 125 /* Reset the DiskOnChip ASIC */
126 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET, 126 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
127 window, DOCControl); 127 window, DOCControl);
128 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET, 128 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
129 window, DOCControl); 129 window, DOCControl);
130 130
131 /* Enable the DiskOnChip ASIC */ 131 /* Enable the DiskOnChip ASIC */
132 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL, 132 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
133 window, DOCControl); 133 window, DOCControl);
134 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL, 134 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
135 window, DOCControl); 135 window, DOCControl);
136#endif /* !DOC_PASSIVE_PROBE */ 136#endif /* !DOC_PASSIVE_PROBE */
137 137
138 /* We need to read the ChipID register four times. For some 138 /* We need to read the ChipID register four times. For some
139 newer DiskOnChip 2000 units, the first three reads will 139 newer DiskOnChip 2000 units, the first three reads will
140 return the DiskOnChip Millennium ident. Don't ask. */ 140 return the DiskOnChip Millennium ident. Don't ask. */
141 ChipID = ReadDOC(window, ChipID); 141 ChipID = ReadDOC(window, ChipID);
142 142
143 switch (ChipID) { 143 switch (ChipID) {
144 case DOC_ChipID_Doc2k: 144 case DOC_ChipID_Doc2k:
145 /* Check the TOGGLE bit in the ECC register */ 145 /* Check the TOGGLE bit in the ECC register */
@@ -149,7 +149,7 @@ static inline int __init doccheck(void __iomem *potential, unsigned long physadr
149 if (tmp != tmpb && tmp == tmpc) 149 if (tmp != tmpb && tmp == tmpc)
150 return ChipID; 150 return ChipID;
151 break; 151 break;
152 152
153 case DOC_ChipID_DocMil: 153 case DOC_ChipID_DocMil:
154 /* Check for the new 2000 with Millennium ASIC */ 154 /* Check for the new 2000 with Millennium ASIC */
155 ReadDOC(window, ChipID); 155 ReadDOC(window, ChipID);
@@ -164,7 +164,7 @@ static inline int __init doccheck(void __iomem *potential, unsigned long physadr
164 if (tmp != tmpb && tmp == tmpc) 164 if (tmp != tmpb && tmp == tmpc)
165 return ChipID; 165 return ChipID;
166 break; 166 break;
167 167
168 case DOC_ChipID_DocMilPlus16: 168 case DOC_ChipID_DocMilPlus16:
169 case DOC_ChipID_DocMilPlus32: 169 case DOC_ChipID_DocMilPlus32:
170 case 0: 170 case 0:
@@ -179,7 +179,7 @@ static inline int __init doccheck(void __iomem *potential, unsigned long physadr
179 DOC_MODE_BDECT; 179 DOC_MODE_BDECT;
180 WriteDOC(tmp, window, Mplus_DOCControl); 180 WriteDOC(tmp, window, Mplus_DOCControl);
181 WriteDOC(~tmp, window, Mplus_CtrlConfirm); 181 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
182 182
183 mdelay(1); 183 mdelay(1);
184 /* Enable the DiskOnChip ASIC */ 184 /* Enable the DiskOnChip ASIC */
185 tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT | 185 tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
@@ -187,7 +187,7 @@ static inline int __init doccheck(void __iomem *potential, unsigned long physadr
187 WriteDOC(tmp, window, Mplus_DOCControl); 187 WriteDOC(tmp, window, Mplus_DOCControl);
188 WriteDOC(~tmp, window, Mplus_CtrlConfirm); 188 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
189 mdelay(1); 189 mdelay(1);
190#endif /* !DOC_PASSIVE_PROBE */ 190#endif /* !DOC_PASSIVE_PROBE */
191 191
192 ChipID = ReadDOC(window, ChipID); 192 ChipID = ReadDOC(window, ChipID);
193 193
@@ -227,7 +227,7 @@ static inline int __init doccheck(void __iomem *potential, unsigned long physadr
227 WriteDOC(tmp2, window, DOCControl); 227 WriteDOC(tmp2, window, DOCControl);
228#endif 228#endif
229 return 0; 229 return 0;
230} 230}
231 231
232static int docfound; 232static int docfound;
233 233
@@ -244,10 +244,10 @@ static void __init DoC_Probe(unsigned long physadr)
244 void (*initroutine)(struct mtd_info *) = NULL; 244 void (*initroutine)(struct mtd_info *) = NULL;
245 245
246 docptr = ioremap(physadr, DOC_IOREMAP_LEN); 246 docptr = ioremap(physadr, DOC_IOREMAP_LEN);
247 247
248 if (!docptr) 248 if (!docptr)
249 return; 249 return;
250 250
251 if ((ChipID = doccheck(docptr, physadr))) { 251 if ((ChipID = doccheck(docptr, physadr))) {
252 if (ChipID == DOC_ChipID_Doc2kTSOP) { 252 if (ChipID == DOC_ChipID_Doc2kTSOP) {
253 /* Remove this at your own peril. The hardware driver works but nothing prevents you from erasing bad blocks */ 253 /* Remove this at your own peril. The hardware driver works but nothing prevents you from erasing bad blocks */
@@ -263,9 +263,9 @@ static void __init DoC_Probe(unsigned long physadr)
263 iounmap(docptr); 263 iounmap(docptr);
264 return; 264 return;
265 } 265 }
266 266
267 this = (struct DiskOnChip *)(&mtd[1]); 267 this = (struct DiskOnChip *)(&mtd[1]);
268 268
269 memset((char *)mtd,0, sizeof(struct mtd_info)); 269 memset((char *)mtd,0, sizeof(struct mtd_info));
270 memset((char *)this, 0, sizeof(struct DiskOnChip)); 270 memset((char *)this, 0, sizeof(struct DiskOnChip));
271 271
@@ -281,13 +281,13 @@ static void __init DoC_Probe(unsigned long physadr)
281 im_funcname = "DoC2k_init"; 281 im_funcname = "DoC2k_init";
282 im_modname = "doc2000"; 282 im_modname = "doc2000";
283 break; 283 break;
284 284
285 case DOC_ChipID_Doc2k: 285 case DOC_ChipID_Doc2k:
286 name="2000"; 286 name="2000";
287 im_funcname = "DoC2k_init"; 287 im_funcname = "DoC2k_init";
288 im_modname = "doc2000"; 288 im_modname = "doc2000";
289 break; 289 break;
290 290
291 case DOC_ChipID_DocMil: 291 case DOC_ChipID_DocMil:
292 name="Millennium"; 292 name="Millennium";
293#ifdef DOC_SINGLE_DRIVER 293#ifdef DOC_SINGLE_DRIVER
@@ -331,7 +331,7 @@ static void __init DoC_Probe(unsigned long physadr)
331static int __init init_doc(void) 331static int __init init_doc(void)
332{ 332{
333 int i; 333 int i;
334 334
335 if (doc_config_location) { 335 if (doc_config_location) {
336 printk(KERN_INFO "Using configured DiskOnChip probe address 0x%lx\n", doc_config_location); 336 printk(KERN_INFO "Using configured DiskOnChip probe address 0x%lx\n", doc_config_location);
337 DoC_Probe(doc_config_location); 337 DoC_Probe(doc_config_location);
diff --git a/drivers/mtd/devices/lart.c b/drivers/mtd/devices/lart.c
index df987a53ed9c..1e876fcb0408 100644
--- a/drivers/mtd/devices/lart.c
+++ b/drivers/mtd/devices/lart.c
@@ -2,7 +2,7 @@
2/* 2/*
3 * MTD driver for the 28F160F3 Flash Memory (non-CFI) on LART. 3 * MTD driver for the 28F160F3 Flash Memory (non-CFI) on LART.
4 * 4 *
5 * $Id: lart.c,v 1.7 2004/08/09 13:19:44 dwmw2 Exp $ 5 * $Id: lart.c,v 1.9 2005/11/07 11:14:25 gleixner Exp $
6 * 6 *
7 * Author: Abraham vd Merwe <abraham@2d3d.co.za> 7 * Author: Abraham vd Merwe <abraham@2d3d.co.za>
8 * 8 *
@@ -122,7 +122,7 @@ static char module_name[] = "lart";
122 122
123/* 123/*
124 * The data line mapping on LART is as follows: 124 * The data line mapping on LART is as follows:
125 * 125 *
126 * U2 CPU | U3 CPU 126 * U2 CPU | U3 CPU
127 * ------------------- 127 * -------------------
128 * 0 20 | 0 12 128 * 0 20 | 0 12
@@ -181,7 +181,7 @@ static char module_name[] = "lart";
181 (((x) & 0x00004000) >> 13) \ 181 (((x) & 0x00004000) >> 13) \
182 ) 182 )
183 183
184/* 184/*
185 * The address line mapping on LART is as follows: 185 * The address line mapping on LART is as follows:
186 * 186 *
187 * U3 CPU | U2 CPU 187 * U3 CPU | U2 CPU
@@ -204,7 +204,7 @@ static char module_name[] = "lart";
204 * 12 15 | 12 15 204 * 12 15 | 12 15
205 * 13 14 | 13 14 205 * 13 14 | 13 14
206 * 14 16 | 14 16 206 * 14 16 | 14 16
207 * 207 *
208 * MAIN BLOCK BOUNDARY 208 * MAIN BLOCK BOUNDARY
209 * 209 *
210 * 15 17 | 15 18 210 * 15 17 | 15 18
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 765c0179c8df..e8685ee6c1e4 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * $Id: phram.c,v 1.14 2005/03/07 21:43:38 joern Exp $ 2 * $Id: phram.c,v 1.16 2005/11/07 11:14:25 gleixner Exp $
3 * 3 *
4 * Copyright (c) ???? Jochen Schäuble <psionic@psionic.de> 4 * Copyright (c) ???? Jochen Schäuble <psionic@psionic.de>
5 * Copyright (c) 2003-2004 Jörn Engel <joern@wh.fh-wedel.de> 5 * Copyright (c) 2003-2004 Jörn Engel <joern@wh.fh-wedel.de>
@@ -41,10 +41,10 @@ static int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
41 41
42 if (instr->addr + instr->len > mtd->size) 42 if (instr->addr + instr->len > mtd->size)
43 return -EINVAL; 43 return -EINVAL;
44 44
45 memset(start + instr->addr, 0xff, instr->len); 45 memset(start + instr->addr, 0xff, instr->len);
46 46
47 /* This'll catch a few races. Free the thing before returning :) 47 /* This'll catch a few races. Free the thing before returning :)
48 * I don't feel at all ashamed. This kind of thing is possible anyway 48 * I don't feel at all ashamed. This kind of thing is possible anyway
49 * with flash, but unlikely. 49 * with flash, but unlikely.
50 */ 50 */
@@ -63,7 +63,7 @@ static int phram_point(struct mtd_info *mtd, loff_t from, size_t len,
63 63
64 if (from + len > mtd->size) 64 if (from + len > mtd->size)
65 return -EINVAL; 65 return -EINVAL;
66 66
67 *mtdbuf = start + from; 67 *mtdbuf = start + from;
68 *retlen = len; 68 *retlen = len;
69 return 0; 69 return 0;
@@ -84,7 +84,7 @@ static int phram_read(struct mtd_info *mtd, loff_t from, size_t len,
84 84
85 if (len > mtd->size - from) 85 if (len > mtd->size - from)
86 len = mtd->size - from; 86 len = mtd->size - from;
87 87
88 memcpy(buf, start + from, len); 88 memcpy(buf, start + from, len);
89 89
90 *retlen = len; 90 *retlen = len;
@@ -101,7 +101,7 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len,
101 101
102 if (len > mtd->size - to) 102 if (len > mtd->size - to)
103 len = mtd->size - to; 103 len = mtd->size - to;
104 104
105 memcpy(start + to, buf, len); 105 memcpy(start + to, buf, len);
106 106
107 *retlen = len; 107 *retlen = len;
@@ -159,7 +159,7 @@ static int register_device(char *name, unsigned long start, unsigned long len)
159 } 159 }
160 160
161 list_add_tail(&new->list, &phram_list); 161 list_add_tail(&new->list, &phram_list);
162 return 0; 162 return 0;
163 163
164out2: 164out2:
165 iounmap(new->mtd.priv); 165 iounmap(new->mtd.priv);
diff --git a/drivers/mtd/devices/pmc551.c b/drivers/mtd/devices/pmc551.c
index 5b3defadf884..de48b35f5609 100644
--- a/drivers/mtd/devices/pmc551.c
+++ b/drivers/mtd/devices/pmc551.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: pmc551.c,v 1.30 2005/01/05 18:05:13 dwmw2 Exp $ 2 * $Id: pmc551.c,v 1.32 2005/11/07 11:14:25 gleixner Exp $
3 * 3 *
4 * PMC551 PCI Mezzanine Ram Device 4 * PMC551 PCI Mezzanine Ram Device
5 * 5 *
@@ -27,7 +27,7 @@
27 * it as high speed swap or for a high speed disk device of some 27 * it as high speed swap or for a high speed disk device of some
28 * sort. Which becomes very useful on diskless systems in the 28 * sort. Which becomes very useful on diskless systems in the
29 * embedded market I might add. 29 * embedded market I might add.
30 * 30 *
31 * Notes: 31 * Notes:
32 * Due to what I assume is more buggy SROM, the 64M PMC551 I 32 * Due to what I assume is more buggy SROM, the 64M PMC551 I
33 * have available claims that all 4 of it's DRAM banks have 64M 33 * have available claims that all 4 of it's DRAM banks have 64M
@@ -63,10 +63,10 @@
63 * Minyard set up the card to utilize a 1M sliding apature. 63 * Minyard set up the card to utilize a 1M sliding apature.
64 * 64 *
65 * Corey Minyard <minyard@nortelnetworks.com> 65 * Corey Minyard <minyard@nortelnetworks.com>
66 * * Modified driver to utilize a sliding aperture instead of 66 * * Modified driver to utilize a sliding aperture instead of
67 * mapping all memory into kernel space which turned out to 67 * mapping all memory into kernel space which turned out to
68 * be very wasteful. 68 * be very wasteful.
69 * * Located a bug in the SROM's initialization sequence that 69 * * Located a bug in the SROM's initialization sequence that
70 * made the memory unusable, added a fix to code to touch up 70 * made the memory unusable, added a fix to code to touch up
71 * the DRAM some. 71 * the DRAM some.
72 * 72 *
@@ -390,7 +390,7 @@ static u32 fixup_pmc551 (struct pci_dev *dev)
390 bcmd |= (0x40|0x20); 390 bcmd |= (0x40|0x20);
391 pci_write_config_byte(dev, PMC551_SYS_CTRL_REG, bcmd); 391 pci_write_config_byte(dev, PMC551_SYS_CTRL_REG, bcmd);
392 392
393 /* 393 /*
394 * Take care and turn off the memory on the device while we 394 * Take care and turn off the memory on the device while we
395 * tweak the configurations 395 * tweak the configurations
396 */ 396 */
@@ -408,7 +408,7 @@ static u32 fixup_pmc551 (struct pci_dev *dev)
408 * Grab old BAR0 config so that we can figure out memory size 408 * Grab old BAR0 config so that we can figure out memory size
409 * This is another bit of kludge going on. The reason for the 409 * This is another bit of kludge going on. The reason for the
410 * redundancy is I am hoping to retain the original configuration 410 * redundancy is I am hoping to retain the original configuration
411 * previously assigned to the card by the BIOS or some previous 411 * previously assigned to the card by the BIOS or some previous
412 * fixup routine in the kernel. So we read the old config into cfg, 412 * fixup routine in the kernel. So we read the old config into cfg,
413 * then write all 1's to the memory space, read back the result into 413 * then write all 1's to the memory space, read back the result into
414 * "size", and then write back all the old config. 414 * "size", and then write back all the old config.
@@ -480,7 +480,7 @@ static u32 fixup_pmc551 (struct pci_dev *dev)
480 } while ( (PCI_COMMAND_IO) & cmd ); 480 } while ( (PCI_COMMAND_IO) & cmd );
481 481
482 /* 482 /*
483 * Turn on auto refresh 483 * Turn on auto refresh
484 * The loop is taken directly from Ramix's example code. I assume that 484 * The loop is taken directly from Ramix's example code. I assume that
485 * this must be held high for some duration of time, but I can find no 485 * this must be held high for some duration of time, but I can find no
486 * documentation refrencing the reasons why. 486 * documentation refrencing the reasons why.
@@ -615,7 +615,7 @@ static u32 fixup_pmc551 (struct pci_dev *dev)
615 pci_read_config_byte(dev, PMC551_SYS_CTRL_REG, &bcmd ); 615 pci_read_config_byte(dev, PMC551_SYS_CTRL_REG, &bcmd );
616 printk( KERN_DEBUG "pmc551: EEPROM is under %s control\n" 616 printk( KERN_DEBUG "pmc551: EEPROM is under %s control\n"
617 "pmc551: System Control Register is %slocked to PCI access\n" 617 "pmc551: System Control Register is %slocked to PCI access\n"
618 "pmc551: System Control Register is %slocked to EEPROM access\n", 618 "pmc551: System Control Register is %slocked to EEPROM access\n",
619 (bcmd&0x1)?"software":"hardware", 619 (bcmd&0x1)?"software":"hardware",
620 (bcmd&0x20)?"":"un", (bcmd&0x40)?"":"un"); 620 (bcmd&0x20)?"":"un", (bcmd&0x40)?"":"un");
621#endif 621#endif
@@ -744,7 +744,7 @@ static int __init init_pmc551(void)
744 priv->start = ioremap(((PCI_Device->resource[0].start) 744 priv->start = ioremap(((PCI_Device->resource[0].start)
745 & PCI_BASE_ADDRESS_MEM_MASK), 745 & PCI_BASE_ADDRESS_MEM_MASK),
746 priv->asize); 746 priv->asize);
747 747
748 if (!priv->start) { 748 if (!priv->start) {
749 printk(KERN_NOTICE "pmc551: Unable to map IO space\n"); 749 printk(KERN_NOTICE "pmc551: Unable to map IO space\n");
750 kfree(mtd->priv); 750 kfree(mtd->priv);
@@ -765,7 +765,7 @@ static int __init init_pmc551(void)
765 priv->curr_map0 ); 765 priv->curr_map0 );
766 766
767#ifdef CONFIG_MTD_PMC551_DEBUG 767#ifdef CONFIG_MTD_PMC551_DEBUG
768 printk( KERN_DEBUG "pmc551: aperture set to %d\n", 768 printk( KERN_DEBUG "pmc551: aperture set to %d\n",
769 (priv->base_map0 & 0xF0)>>4 ); 769 (priv->base_map0 & 0xF0)>>4 );
770#endif 770#endif
771 771
@@ -823,13 +823,13 @@ static void __exit cleanup_pmc551(void)
823 while((mtd=pmc551list)) { 823 while((mtd=pmc551list)) {
824 priv = mtd->priv; 824 priv = mtd->priv;
825 pmc551list = priv->nextpmc551; 825 pmc551list = priv->nextpmc551;
826 826
827 if(priv->start) { 827 if(priv->start) {
828 printk (KERN_DEBUG "pmc551: unmapping %dM starting at 0x%p\n", 828 printk (KERN_DEBUG "pmc551: unmapping %dM starting at 0x%p\n",
829 priv->asize>>20, priv->start); 829 priv->asize>>20, priv->start);
830 iounmap (priv->start); 830 iounmap (priv->start);
831 } 831 }
832 832
833 kfree (mtd->priv); 833 kfree (mtd->priv);
834 del_mtd_device (mtd); 834 del_mtd_device (mtd);
835 kfree (mtd); 835 kfree (mtd);
diff --git a/drivers/mtd/devices/slram.c b/drivers/mtd/devices/slram.c
index 84fa91392a8c..6faee6c6958c 100644
--- a/drivers/mtd/devices/slram.c
+++ b/drivers/mtd/devices/slram.c
@@ -1,6 +1,6 @@
1/*====================================================================== 1/*======================================================================
2 2
3 $Id: slram.c,v 1.34 2005/01/06 21:16:42 jwboyer Exp $ 3 $Id: slram.c,v 1.36 2005/11/07 11:14:25 gleixner Exp $
4 4
5 This driver provides a method to access memory not used by the kernel 5 This driver provides a method to access memory not used by the kernel
6 itself (i.e. if the kernel commandline mem=xxx is used). To actually 6 itself (i.e. if the kernel commandline mem=xxx is used). To actually
@@ -18,14 +18,14 @@
18 <start>: start of the memory region, decimal or hex (0xabcdef) 18 <start>: start of the memory region, decimal or hex (0xabcdef)
19 <end/offset>: end of the memory region. It's possible to use +0x1234 19 <end/offset>: end of the memory region. It's possible to use +0x1234
20 to specify the offset instead of the absolute address 20 to specify the offset instead of the absolute address
21 21
22 NOTE: 22 NOTE:
23 With slram it's only possible to map a contigous memory region. Therfore 23 With slram it's only possible to map a contigous memory region. Therfore
24 if there's a device mapped somewhere in the region specified slram will 24 if there's a device mapped somewhere in the region specified slram will
25 fail to load (see kernel log if modprobe fails). 25 fail to load (see kernel log if modprobe fails).
26 26
27 - 27 -
28 28
29 Jochen Schaeuble <psionic@psionic.de> 29 Jochen Schaeuble <psionic@psionic.de>
30 30
31======================================================================*/ 31======================================================================*/
@@ -89,10 +89,10 @@ static int slram_erase(struct mtd_info *mtd, struct erase_info *instr)
89 if (instr->addr + instr->len > mtd->size) { 89 if (instr->addr + instr->len > mtd->size) {
90 return(-EINVAL); 90 return(-EINVAL);
91 } 91 }
92 92
93 memset(priv->start + instr->addr, 0xff, instr->len); 93 memset(priv->start + instr->addr, 0xff, instr->len);
94 94
95 /* This'll catch a few races. Free the thing before returning :) 95 /* This'll catch a few races. Free the thing before returning :)
96 * I don't feel at all ashamed. This kind of thing is possible anyway 96 * I don't feel at all ashamed. This kind of thing is possible anyway
97 * with flash, but unlikely. 97 * with flash, but unlikely.
98 */ 98 */
@@ -170,12 +170,12 @@ static int register_device(char *name, unsigned long start, unsigned long length
170 } 170 }
171 (*curmtd)->mtdinfo = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); 171 (*curmtd)->mtdinfo = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
172 (*curmtd)->next = NULL; 172 (*curmtd)->next = NULL;
173 173
174 if ((*curmtd)->mtdinfo) { 174 if ((*curmtd)->mtdinfo) {
175 memset((char *)(*curmtd)->mtdinfo, 0, sizeof(struct mtd_info)); 175 memset((char *)(*curmtd)->mtdinfo, 0, sizeof(struct mtd_info));
176 (*curmtd)->mtdinfo->priv = 176 (*curmtd)->mtdinfo->priv =
177 kmalloc(sizeof(slram_priv_t), GFP_KERNEL); 177 kmalloc(sizeof(slram_priv_t), GFP_KERNEL);
178 178
179 if (!(*curmtd)->mtdinfo->priv) { 179 if (!(*curmtd)->mtdinfo->priv) {
180 kfree((*curmtd)->mtdinfo); 180 kfree((*curmtd)->mtdinfo);
181 (*curmtd)->mtdinfo = NULL; 181 (*curmtd)->mtdinfo = NULL;
@@ -188,7 +188,7 @@ static int register_device(char *name, unsigned long start, unsigned long length
188 E("slram: Cannot allocate new MTD device.\n"); 188 E("slram: Cannot allocate new MTD device.\n");
189 return(-ENOMEM); 189 return(-ENOMEM);
190 } 190 }
191 191
192 if (!(((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start = 192 if (!(((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start =
193 ioremap(start, length))) { 193 ioremap(start, length))) {
194 E("slram: ioremap failed\n"); 194 E("slram: ioremap failed\n");
@@ -223,7 +223,7 @@ static int register_device(char *name, unsigned long start, unsigned long length
223 T("slram: Mapped from 0x%p to 0x%p\n", 223 T("slram: Mapped from 0x%p to 0x%p\n",
224 ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start, 224 ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start,
225 ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->end); 225 ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->end);
226 return(0); 226 return(0);
227} 227}
228 228
229static void unregister_devices(void) 229static void unregister_devices(void)
@@ -256,7 +256,7 @@ static int parse_cmdline(char *devname, char *szstart, char *szlength)
256 char *buffer; 256 char *buffer;
257 unsigned long devstart; 257 unsigned long devstart;
258 unsigned long devlength; 258 unsigned long devlength;
259 259
260 if ((!devname) || (!szstart) || (!szlength)) { 260 if ((!devname) || (!szstart) || (!szlength)) {
261 unregister_devices(); 261 unregister_devices();
262 return(-EINVAL); 262 return(-EINVAL);
@@ -264,7 +264,7 @@ static int parse_cmdline(char *devname, char *szstart, char *szlength)
264 264
265 devstart = simple_strtoul(szstart, &buffer, 0); 265 devstart = simple_strtoul(szstart, &buffer, 0);
266 devstart = handle_unit(devstart, buffer); 266 devstart = handle_unit(devstart, buffer);
267 267
268 if (*(szlength) != '+') { 268 if (*(szlength) != '+') {
269 devlength = simple_strtoul(szlength, &buffer, 0); 269 devlength = simple_strtoul(szlength, &buffer, 0);
270 devlength = handle_unit(devlength, buffer) - devstart; 270 devlength = handle_unit(devlength, buffer) - devstart;
@@ -278,7 +278,7 @@ static int parse_cmdline(char *devname, char *szstart, char *szlength)
278 E("slram: Illegal start / length parameter.\n"); 278 E("slram: Illegal start / length parameter.\n");
279 return(-EINVAL); 279 return(-EINVAL);
280 } 280 }
281 281
282 if ((devstart = register_device(devname, devstart, devlength))){ 282 if ((devstart = register_device(devname, devstart, devlength))){
283 unregister_devices(); 283 unregister_devices();
284 return((int)devstart); 284 return((int)devstart);
@@ -335,7 +335,7 @@ static int init_slram(void)
335 } 335 }
336#else 336#else
337 int count; 337 int count;
338 338
339 for (count = 0; (map[count]) && (count < SLRAM_MAX_DEVICES_PARAMS); 339 for (count = 0; (map[count]) && (count < SLRAM_MAX_DEVICES_PARAMS);
340 count++) { 340 count++) {
341 } 341 }
@@ -350,10 +350,10 @@ static int init_slram(void)
350 if (parse_cmdline(devname, map[i * 3 + 1], map[i * 3 + 2])!=0) { 350 if (parse_cmdline(devname, map[i * 3 + 1], map[i * 3 + 2])!=0) {
351 return(-EINVAL); 351 return(-EINVAL);
352 } 352 }
353 353
354 } 354 }
355#endif /* !MODULE */ 355#endif /* !MODULE */
356 356
357 return(0); 357 return(0);
358} 358}
359 359
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index d32c1b3a8ce3..de7e231d6d18 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -1,5 +1,5 @@
1/* This version ported to the Linux-MTD system by dwmw2@infradead.org 1/* This version ported to the Linux-MTD system by dwmw2@infradead.org
2 * $Id: ftl.c,v 1.55 2005/01/17 13:47:21 hvr Exp $ 2 * $Id: ftl.c,v 1.58 2005/11/07 11:14:19 gleixner Exp $
3 * 3 *
4 * Fixes: Arnaldo Carvalho de Melo <acme@conectiva.com.br> 4 * Fixes: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
5 * - fixes some leaks on failure in build_maps and ftl_notify_add, cleanups 5 * - fixes some leaks on failure in build_maps and ftl_notify_add, cleanups
@@ -53,7 +53,7 @@
53 Use of the FTL format for non-PCMCIA applications may be an 53 Use of the FTL format for non-PCMCIA applications may be an
54 infringement of these patents. For additional information, 54 infringement of these patents. For additional information,
55 contact M-Systems (http://www.m-sys.com) directly. 55 contact M-Systems (http://www.m-sys.com) directly.
56 56
57======================================================================*/ 57======================================================================*/
58#include <linux/mtd/blktrans.h> 58#include <linux/mtd/blktrans.h>
59#include <linux/module.h> 59#include <linux/module.h>
@@ -160,7 +160,7 @@ static void ftl_erase_callback(struct erase_info *done);
160 Scan_header() checks to see if a memory region contains an FTL 160 Scan_header() checks to see if a memory region contains an FTL
161 partition. build_maps() reads all the erase unit headers, builds 161 partition. build_maps() reads all the erase unit headers, builds
162 the erase unit map, and then builds the virtual page map. 162 the erase unit map, and then builds the virtual page map.
163 163
164======================================================================*/ 164======================================================================*/
165 165
166static int scan_header(partition_t *part) 166static int scan_header(partition_t *part)
@@ -176,10 +176,10 @@ static int scan_header(partition_t *part)
176 (offset + sizeof(header)) < max_offset; 176 (offset + sizeof(header)) < max_offset;
177 offset += part->mbd.mtd->erasesize ? : 0x2000) { 177 offset += part->mbd.mtd->erasesize ? : 0x2000) {
178 178
179 err = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(header), &ret, 179 err = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(header), &ret,
180 (unsigned char *)&header); 180 (unsigned char *)&header);
181 181
182 if (err) 182 if (err)
183 return err; 183 return err;
184 184
185 if (strcmp(header.DataOrgTuple+3, "FTL100") == 0) break; 185 if (strcmp(header.DataOrgTuple+3, "FTL100") == 0) break;
@@ -232,10 +232,10 @@ static int build_maps(partition_t *part)
232 for (i = 0; i < le16_to_cpu(part->header.NumEraseUnits); i++) { 232 for (i = 0; i < le16_to_cpu(part->header.NumEraseUnits); i++) {
233 offset = ((i + le16_to_cpu(part->header.FirstPhysicalEUN)) 233 offset = ((i + le16_to_cpu(part->header.FirstPhysicalEUN))
234 << part->header.EraseUnitSize); 234 << part->header.EraseUnitSize);
235 ret = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(header), &retval, 235 ret = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(header), &retval,
236 (unsigned char *)&header); 236 (unsigned char *)&header);
237 237
238 if (ret) 238 if (ret)
239 goto out_XferInfo; 239 goto out_XferInfo;
240 240
241 ret = -1; 241 ret = -1;
@@ -274,7 +274,7 @@ static int build_maps(partition_t *part)
274 "don't add up!\n"); 274 "don't add up!\n");
275 goto out_XferInfo; 275 goto out_XferInfo;
276 } 276 }
277 277
278 /* Set up virtual page map */ 278 /* Set up virtual page map */
279 blocks = le32_to_cpu(header.FormattedSize) >> header.BlockSize; 279 blocks = le32_to_cpu(header.FormattedSize) >> header.BlockSize;
280 part->VirtualBlockMap = vmalloc(blocks * sizeof(u_int32_t)); 280 part->VirtualBlockMap = vmalloc(blocks * sizeof(u_int32_t));
@@ -296,12 +296,12 @@ static int build_maps(partition_t *part)
296 part->EUNInfo[i].Free = 0; 296 part->EUNInfo[i].Free = 0;
297 part->EUNInfo[i].Deleted = 0; 297 part->EUNInfo[i].Deleted = 0;
298 offset = part->EUNInfo[i].Offset + le32_to_cpu(header.BAMOffset); 298 offset = part->EUNInfo[i].Offset + le32_to_cpu(header.BAMOffset);
299 299
300 ret = part->mbd.mtd->read(part->mbd.mtd, offset, 300 ret = part->mbd.mtd->read(part->mbd.mtd, offset,
301 part->BlocksPerUnit * sizeof(u_int32_t), &retval, 301 part->BlocksPerUnit * sizeof(u_int32_t), &retval,
302 (unsigned char *)part->bam_cache); 302 (unsigned char *)part->bam_cache);
303 303
304 if (ret) 304 if (ret)
305 goto out_bam_cache; 305 goto out_bam_cache;
306 306
307 for (j = 0; j < part->BlocksPerUnit; j++) { 307 for (j = 0; j < part->BlocksPerUnit; j++) {
@@ -316,7 +316,7 @@ static int build_maps(partition_t *part)
316 part->EUNInfo[i].Deleted++; 316 part->EUNInfo[i].Deleted++;
317 } 317 }
318 } 318 }
319 319
320 ret = 0; 320 ret = 0;
321 goto out; 321 goto out;
322 322
@@ -336,7 +336,7 @@ out:
336 336
337 Erase_xfer() schedules an asynchronous erase operation for a 337 Erase_xfer() schedules an asynchronous erase operation for a
338 transfer unit. 338 transfer unit.
339 339
340======================================================================*/ 340======================================================================*/
341 341
342static int erase_xfer(partition_t *part, 342static int erase_xfer(partition_t *part,
@@ -351,10 +351,10 @@ static int erase_xfer(partition_t *part,
351 xfer->state = XFER_ERASING; 351 xfer->state = XFER_ERASING;
352 352
353 /* Is there a free erase slot? Always in MTD. */ 353 /* Is there a free erase slot? Always in MTD. */
354 354
355 355
356 erase=kmalloc(sizeof(struct erase_info), GFP_KERNEL); 356 erase=kmalloc(sizeof(struct erase_info), GFP_KERNEL);
357 if (!erase) 357 if (!erase)
358 return -ENOMEM; 358 return -ENOMEM;
359 359
360 erase->mtd = part->mbd.mtd; 360 erase->mtd = part->mbd.mtd;
@@ -362,7 +362,7 @@ static int erase_xfer(partition_t *part,
362 erase->addr = xfer->Offset; 362 erase->addr = xfer->Offset;
363 erase->len = 1 << part->header.EraseUnitSize; 363 erase->len = 1 << part->header.EraseUnitSize;
364 erase->priv = (u_long)part; 364 erase->priv = (u_long)part;
365 365
366 ret = part->mbd.mtd->erase(part->mbd.mtd, erase); 366 ret = part->mbd.mtd->erase(part->mbd.mtd, erase);
367 367
368 if (!ret) 368 if (!ret)
@@ -377,7 +377,7 @@ static int erase_xfer(partition_t *part,
377 377
378 Prepare_xfer() takes a freshly erased transfer unit and gives 378 Prepare_xfer() takes a freshly erased transfer unit and gives
379 it an appropriate header. 379 it an appropriate header.
380 380
381======================================================================*/ 381======================================================================*/
382 382
383static void ftl_erase_callback(struct erase_info *erase) 383static void ftl_erase_callback(struct erase_info *erase)
@@ -385,7 +385,7 @@ static void ftl_erase_callback(struct erase_info *erase)
385 partition_t *part; 385 partition_t *part;
386 struct xfer_info_t *xfer; 386 struct xfer_info_t *xfer;
387 int i; 387 int i;
388 388
389 /* Look up the transfer unit */ 389 /* Look up the transfer unit */
390 part = (partition_t *)(erase->priv); 390 part = (partition_t *)(erase->priv);
391 391
@@ -422,7 +422,7 @@ static int prepare_xfer(partition_t *part, int i)
422 422
423 xfer = &part->XferInfo[i]; 423 xfer = &part->XferInfo[i];
424 xfer->state = XFER_FAILED; 424 xfer->state = XFER_FAILED;
425 425
426 DEBUG(1, "ftl_cs: preparing xfer unit at 0x%x\n", xfer->Offset); 426 DEBUG(1, "ftl_cs: preparing xfer unit at 0x%x\n", xfer->Offset);
427 427
428 /* Write the transfer unit header */ 428 /* Write the transfer unit header */
@@ -446,7 +446,7 @@ static int prepare_xfer(partition_t *part, int i)
446 446
447 for (i = 0; i < nbam; i++, offset += sizeof(u_int32_t)) { 447 for (i = 0; i < nbam; i++, offset += sizeof(u_int32_t)) {
448 448
449 ret = part->mbd.mtd->write(part->mbd.mtd, offset, sizeof(u_int32_t), 449 ret = part->mbd.mtd->write(part->mbd.mtd, offset, sizeof(u_int32_t),
450 &retlen, (u_char *)&ctl); 450 &retlen, (u_char *)&ctl);
451 451
452 if (ret) 452 if (ret)
@@ -454,7 +454,7 @@ static int prepare_xfer(partition_t *part, int i)
454 } 454 }
455 xfer->state = XFER_PREPARED; 455 xfer->state = XFER_PREPARED;
456 return 0; 456 return 0;
457 457
458} /* prepare_xfer */ 458} /* prepare_xfer */
459 459
460/*====================================================================== 460/*======================================================================
@@ -466,7 +466,7 @@ static int prepare_xfer(partition_t *part, int i)
466 All data blocks are copied to the corresponding blocks in the 466 All data blocks are copied to the corresponding blocks in the
467 target unit, so the virtual block map does not need to be 467 target unit, so the virtual block map does not need to be
468 updated. 468 updated.
469 469
470======================================================================*/ 470======================================================================*/
471 471
472static int copy_erase_unit(partition_t *part, u_int16_t srcunit, 472static int copy_erase_unit(partition_t *part, u_int16_t srcunit,
@@ -486,14 +486,14 @@ static int copy_erase_unit(partition_t *part, u_int16_t srcunit,
486 xfer = &part->XferInfo[xferunit]; 486 xfer = &part->XferInfo[xferunit];
487 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n", 487 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
488 eun->Offset, xfer->Offset); 488 eun->Offset, xfer->Offset);
489 489
490 490
491 /* Read current BAM */ 491 /* Read current BAM */
492 if (part->bam_index != srcunit) { 492 if (part->bam_index != srcunit) {
493 493
494 offset = eun->Offset + le32_to_cpu(part->header.BAMOffset); 494 offset = eun->Offset + le32_to_cpu(part->header.BAMOffset);
495 495
496 ret = part->mbd.mtd->read(part->mbd.mtd, offset, 496 ret = part->mbd.mtd->read(part->mbd.mtd, offset,
497 part->BlocksPerUnit * sizeof(u_int32_t), 497 part->BlocksPerUnit * sizeof(u_int32_t),
498 &retlen, (u_char *) (part->bam_cache)); 498 &retlen, (u_char *) (part->bam_cache));
499 499
@@ -501,11 +501,11 @@ static int copy_erase_unit(partition_t *part, u_int16_t srcunit,
501 part->bam_index = 0xffff; 501 part->bam_index = 0xffff;
502 502
503 if (ret) { 503 if (ret) {
504 printk( KERN_WARNING "ftl: Failed to read BAM cache in copy_erase_unit()!\n"); 504 printk( KERN_WARNING "ftl: Failed to read BAM cache in copy_erase_unit()!\n");
505 return ret; 505 return ret;
506 } 506 }
507 } 507 }
508 508
509 /* Write the LogicalEUN for the transfer unit */ 509 /* Write the LogicalEUN for the transfer unit */
510 xfer->state = XFER_UNKNOWN; 510 xfer->state = XFER_UNKNOWN;
511 offset = xfer->Offset + 20; /* Bad! */ 511 offset = xfer->Offset + 20; /* Bad! */
@@ -513,12 +513,12 @@ static int copy_erase_unit(partition_t *part, u_int16_t srcunit,
513 513
514 ret = part->mbd.mtd->write(part->mbd.mtd, offset, sizeof(u_int16_t), 514 ret = part->mbd.mtd->write(part->mbd.mtd, offset, sizeof(u_int16_t),
515 &retlen, (u_char *) &unit); 515 &retlen, (u_char *) &unit);
516 516
517 if (ret) { 517 if (ret) {
518 printk( KERN_WARNING "ftl: Failed to write back to BAM cache in copy_erase_unit()!\n"); 518 printk( KERN_WARNING "ftl: Failed to write back to BAM cache in copy_erase_unit()!\n");
519 return ret; 519 return ret;
520 } 520 }
521 521
522 /* Copy all data blocks from source unit to transfer unit */ 522 /* Copy all data blocks from source unit to transfer unit */
523 src = eun->Offset; dest = xfer->Offset; 523 src = eun->Offset; dest = xfer->Offset;
524 524
@@ -558,15 +558,15 @@ static int copy_erase_unit(partition_t *part, u_int16_t srcunit,
558 } 558 }
559 559
560 /* Write the BAM to the transfer unit */ 560 /* Write the BAM to the transfer unit */
561 ret = part->mbd.mtd->write(part->mbd.mtd, xfer->Offset + le32_to_cpu(part->header.BAMOffset), 561 ret = part->mbd.mtd->write(part->mbd.mtd, xfer->Offset + le32_to_cpu(part->header.BAMOffset),
562 part->BlocksPerUnit * sizeof(int32_t), &retlen, 562 part->BlocksPerUnit * sizeof(int32_t), &retlen,
563 (u_char *)part->bam_cache); 563 (u_char *)part->bam_cache);
564 if (ret) { 564 if (ret) {
565 printk( KERN_WARNING "ftl: Error writing BAM in copy_erase_unit\n"); 565 printk( KERN_WARNING "ftl: Error writing BAM in copy_erase_unit\n");
566 return ret; 566 return ret;
567 } 567 }
568 568
569 569
570 /* All clear? Then update the LogicalEUN again */ 570 /* All clear? Then update the LogicalEUN again */
571 ret = part->mbd.mtd->write(part->mbd.mtd, xfer->Offset + 20, sizeof(u_int16_t), 571 ret = part->mbd.mtd->write(part->mbd.mtd, xfer->Offset + 20, sizeof(u_int16_t),
572 &retlen, (u_char *)&srcunitswap); 572 &retlen, (u_char *)&srcunitswap);
@@ -574,9 +574,9 @@ static int copy_erase_unit(partition_t *part, u_int16_t srcunit,
574 if (ret) { 574 if (ret) {
575 printk(KERN_WARNING "ftl: Error writing new LogicalEUN in copy_erase_unit\n"); 575 printk(KERN_WARNING "ftl: Error writing new LogicalEUN in copy_erase_unit\n");
576 return ret; 576 return ret;
577 } 577 }
578 578
579 579
580 /* Update the maps and usage stats*/ 580 /* Update the maps and usage stats*/
581 i = xfer->EraseCount; 581 i = xfer->EraseCount;
582 xfer->EraseCount = eun->EraseCount; 582 xfer->EraseCount = eun->EraseCount;
@@ -588,10 +588,10 @@ static int copy_erase_unit(partition_t *part, u_int16_t srcunit,
588 part->FreeTotal += free; 588 part->FreeTotal += free;
589 eun->Free = free; 589 eun->Free = free;
590 eun->Deleted = 0; 590 eun->Deleted = 0;
591 591
592 /* Now, the cache should be valid for the new block */ 592 /* Now, the cache should be valid for the new block */
593 part->bam_index = srcunit; 593 part->bam_index = srcunit;
594 594
595 return 0; 595 return 0;
596} /* copy_erase_unit */ 596} /* copy_erase_unit */
597 597
@@ -608,7 +608,7 @@ static int copy_erase_unit(partition_t *part, u_int16_t srcunit,
608 oldest data unit instead. This means that we generally postpone 608 oldest data unit instead. This means that we generally postpone
609 the next reclaimation as long as possible, but shuffle static 609 the next reclaimation as long as possible, but shuffle static
610 stuff around a bit for wear leveling. 610 stuff around a bit for wear leveling.
611 611
612======================================================================*/ 612======================================================================*/
613 613
614static int reclaim_block(partition_t *part) 614static int reclaim_block(partition_t *part)
@@ -666,7 +666,7 @@ static int reclaim_block(partition_t *part)
666 else 666 else
667 DEBUG(1, "ftl_cs: reclaim failed: no " 667 DEBUG(1, "ftl_cs: reclaim failed: no "
668 "suitable transfer units!\n"); 668 "suitable transfer units!\n");
669 669
670 return -EIO; 670 return -EIO;
671 } 671 }
672 } 672 }
@@ -715,7 +715,7 @@ static int reclaim_block(partition_t *part)
715 returns the block index -- the erase unit is just the currently 715 returns the block index -- the erase unit is just the currently
716 cached unit. If there are no free blocks, it returns 0 -- this 716 cached unit. If there are no free blocks, it returns 0 -- this
717 is never a valid data block because it contains the header. 717 is never a valid data block because it contains the header.
718 718
719======================================================================*/ 719======================================================================*/
720 720
721#ifdef PSYCHO_DEBUG 721#ifdef PSYCHO_DEBUG
@@ -737,7 +737,7 @@ static u_int32_t find_free(partition_t *part)
737 u_int32_t blk; 737 u_int32_t blk;
738 size_t retlen; 738 size_t retlen;
739 int ret; 739 int ret;
740 740
741 /* Find an erase unit with some free space */ 741 /* Find an erase unit with some free space */
742 stop = (part->bam_index == 0xffff) ? 0 : part->bam_index; 742 stop = (part->bam_index == 0xffff) ? 0 : part->bam_index;
743 eun = stop; 743 eun = stop;
@@ -749,17 +749,17 @@ static u_int32_t find_free(partition_t *part)
749 749
750 if (part->EUNInfo[eun].Free == 0) 750 if (part->EUNInfo[eun].Free == 0)
751 return 0; 751 return 0;
752 752
753 /* Is this unit's BAM cached? */ 753 /* Is this unit's BAM cached? */
754 if (eun != part->bam_index) { 754 if (eun != part->bam_index) {
755 /* Invalidate cache */ 755 /* Invalidate cache */
756 part->bam_index = 0xffff; 756 part->bam_index = 0xffff;
757 757
758 ret = part->mbd.mtd->read(part->mbd.mtd, 758 ret = part->mbd.mtd->read(part->mbd.mtd,
759 part->EUNInfo[eun].Offset + le32_to_cpu(part->header.BAMOffset), 759 part->EUNInfo[eun].Offset + le32_to_cpu(part->header.BAMOffset),
760 part->BlocksPerUnit * sizeof(u_int32_t), 760 part->BlocksPerUnit * sizeof(u_int32_t),
761 &retlen, (u_char *) (part->bam_cache)); 761 &retlen, (u_char *) (part->bam_cache));
762 762
763 if (ret) { 763 if (ret) {
764 printk(KERN_WARNING"ftl: Error reading BAM in find_free\n"); 764 printk(KERN_WARNING"ftl: Error reading BAM in find_free\n");
765 return 0; 765 return 0;
@@ -781,14 +781,14 @@ static u_int32_t find_free(partition_t *part)
781 } 781 }
782 DEBUG(2, "ftl_cs: found free block at %d in %d\n", blk, eun); 782 DEBUG(2, "ftl_cs: found free block at %d in %d\n", blk, eun);
783 return blk; 783 return blk;
784 784
785} /* find_free */ 785} /* find_free */
786 786
787 787
788/*====================================================================== 788/*======================================================================
789 789
790 Read a series of sectors from an FTL partition. 790 Read a series of sectors from an FTL partition.
791 791
792======================================================================*/ 792======================================================================*/
793 793
794static int ftl_read(partition_t *part, caddr_t buffer, 794static int ftl_read(partition_t *part, caddr_t buffer,
@@ -798,7 +798,7 @@ static int ftl_read(partition_t *part, caddr_t buffer,
798 u_long i; 798 u_long i;
799 int ret; 799 int ret;
800 size_t offset, retlen; 800 size_t offset, retlen;
801 801
802 DEBUG(2, "ftl_cs: ftl_read(0x%p, 0x%lx, %ld)\n", 802 DEBUG(2, "ftl_cs: ftl_read(0x%p, 0x%lx, %ld)\n",
803 part, sector, nblocks); 803 part, sector, nblocks);
804 if (!(part->state & FTL_FORMATTED)) { 804 if (!(part->state & FTL_FORMATTED)) {
@@ -834,7 +834,7 @@ static int ftl_read(partition_t *part, caddr_t buffer,
834/*====================================================================== 834/*======================================================================
835 835
836 Write a series of sectors to an FTL partition 836 Write a series of sectors to an FTL partition
837 837
838======================================================================*/ 838======================================================================*/
839 839
840static int set_bam_entry(partition_t *part, u_int32_t log_addr, 840static int set_bam_entry(partition_t *part, u_int32_t log_addr,
@@ -855,7 +855,7 @@ static int set_bam_entry(partition_t *part, u_int32_t log_addr,
855 blk = (log_addr % bsize) / SECTOR_SIZE; 855 blk = (log_addr % bsize) / SECTOR_SIZE;
856 offset = (part->EUNInfo[eun].Offset + blk * sizeof(u_int32_t) + 856 offset = (part->EUNInfo[eun].Offset + blk * sizeof(u_int32_t) +
857 le32_to_cpu(part->header.BAMOffset)); 857 le32_to_cpu(part->header.BAMOffset));
858 858
859#ifdef PSYCHO_DEBUG 859#ifdef PSYCHO_DEBUG
860 ret = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(u_int32_t), 860 ret = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(u_int32_t),
861 &retlen, (u_char *)&old_addr); 861 &retlen, (u_char *)&old_addr);
@@ -925,7 +925,7 @@ static int ftl_write(partition_t *part, caddr_t buffer,
925 if (ret) 925 if (ret)
926 return ret; 926 return ret;
927 } 927 }
928 928
929 bsize = 1 << part->header.EraseUnitSize; 929 bsize = 1 << part->header.EraseUnitSize;
930 930
931 virt_addr = sector * SECTOR_SIZE | BLOCK_DATA; 931 virt_addr = sector * SECTOR_SIZE | BLOCK_DATA;
@@ -949,12 +949,12 @@ static int ftl_write(partition_t *part, caddr_t buffer,
949 log_addr = part->bam_index * bsize + blk * SECTOR_SIZE; 949 log_addr = part->bam_index * bsize + blk * SECTOR_SIZE;
950 part->EUNInfo[part->bam_index].Free--; 950 part->EUNInfo[part->bam_index].Free--;
951 part->FreeTotal--; 951 part->FreeTotal--;
952 if (set_bam_entry(part, log_addr, 0xfffffffe)) 952 if (set_bam_entry(part, log_addr, 0xfffffffe))
953 return -EIO; 953 return -EIO;
954 part->EUNInfo[part->bam_index].Deleted++; 954 part->EUNInfo[part->bam_index].Deleted++;
955 offset = (part->EUNInfo[part->bam_index].Offset + 955 offset = (part->EUNInfo[part->bam_index].Offset +
956 blk * SECTOR_SIZE); 956 blk * SECTOR_SIZE);
957 ret = part->mbd.mtd->write(part->mbd.mtd, offset, SECTOR_SIZE, &retlen, 957 ret = part->mbd.mtd->write(part->mbd.mtd, offset, SECTOR_SIZE, &retlen,
958 buffer); 958 buffer);
959 959
960 if (ret) { 960 if (ret) {
@@ -964,7 +964,7 @@ static int ftl_write(partition_t *part, caddr_t buffer,
964 offset); 964 offset);
965 return -EIO; 965 return -EIO;
966 } 966 }
967 967
968 /* Only delete the old entry when the new entry is ready */ 968 /* Only delete the old entry when the new entry is ready */
969 old_addr = part->VirtualBlockMap[sector+i]; 969 old_addr = part->VirtualBlockMap[sector+i];
970 if (old_addr != 0xffffffff) { 970 if (old_addr != 0xffffffff) {
@@ -979,7 +979,7 @@ static int ftl_write(partition_t *part, caddr_t buffer,
979 return -EIO; 979 return -EIO;
980 part->VirtualBlockMap[sector+i] = log_addr; 980 part->VirtualBlockMap[sector+i] = log_addr;
981 part->EUNInfo[part->bam_index].Deleted--; 981 part->EUNInfo[part->bam_index].Deleted--;
982 982
983 buffer += SECTOR_SIZE; 983 buffer += SECTOR_SIZE;
984 virt_addr += SECTOR_SIZE; 984 virt_addr += SECTOR_SIZE;
985 } 985 }
@@ -1034,20 +1034,20 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
1034 partition_t *partition; 1034 partition_t *partition;
1035 1035
1036 partition = kmalloc(sizeof(partition_t), GFP_KERNEL); 1036 partition = kmalloc(sizeof(partition_t), GFP_KERNEL);
1037 1037
1038 if (!partition) { 1038 if (!partition) {
1039 printk(KERN_WARNING "No memory to scan for FTL on %s\n", 1039 printk(KERN_WARNING "No memory to scan for FTL on %s\n",
1040 mtd->name); 1040 mtd->name);
1041 return; 1041 return;
1042 } 1042 }
1043 1043
1044 memset(partition, 0, sizeof(partition_t)); 1044 memset(partition, 0, sizeof(partition_t));
1045 1045
1046 partition->mbd.mtd = mtd; 1046 partition->mbd.mtd = mtd;
1047 1047
1048 if ((scan_header(partition) == 0) && 1048 if ((scan_header(partition) == 0) &&
1049 (build_maps(partition) == 0)) { 1049 (build_maps(partition) == 0)) {
1050 1050
1051 partition->state = FTL_FORMATTED; 1051 partition->state = FTL_FORMATTED;
1052#ifdef PCMCIA_DEBUG 1052#ifdef PCMCIA_DEBUG
1053 printk(KERN_INFO "ftl_cs: opening %d KiB FTL partition\n", 1053 printk(KERN_INFO "ftl_cs: opening %d KiB FTL partition\n",
@@ -1086,7 +1086,7 @@ struct mtd_blktrans_ops ftl_tr = {
1086 1086
1087int init_ftl(void) 1087int init_ftl(void)
1088{ 1088{
1089 DEBUG(0, "$Id: ftl.c,v 1.55 2005/01/17 13:47:21 hvr Exp $\n"); 1089 DEBUG(0, "$Id: ftl.c,v 1.58 2005/11/07 11:14:19 gleixner Exp $\n");
1090 1090
1091 return register_mtd_blktrans(&ftl_tr); 1091 return register_mtd_blktrans(&ftl_tr);
1092} 1092}
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index 39eb53f6551f..8a544890173d 100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * inftlcore.c -- Linux driver for Inverse Flash Translation Layer (INFTL) 2 * inftlcore.c -- Linux driver for Inverse Flash Translation Layer (INFTL)
3 * 3 *
4 * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com) 4 * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
@@ -7,7 +7,7 @@
7 * (c) 1999 Machine Vision Holdings, Inc. 7 * (c) 1999 Machine Vision Holdings, Inc.
8 * Author: David Woodhouse <dwmw2@infradead.org> 8 * Author: David Woodhouse <dwmw2@infradead.org>
9 * 9 *
10 * $Id: inftlcore.c,v 1.18 2004/11/16 18:28:59 dwmw2 Exp $ 10 * $Id: inftlcore.c,v 1.19 2005/11/07 11:14:20 gleixner Exp $
11 * 11 *
12 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
@@ -113,23 +113,21 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
113 113
114 if (inftl->mbd.size != inftl->heads * inftl->cylinders * inftl->sectors) { 114 if (inftl->mbd.size != inftl->heads * inftl->cylinders * inftl->sectors) {
115 /* 115 /*
116 Oh no we don't have 116 Oh no we don't have
117 mbd.size == heads * cylinders * sectors 117 mbd.size == heads * cylinders * sectors
118 */ 118 */
119 printk(KERN_WARNING "INFTL: cannot calculate a geometry to " 119 printk(KERN_WARNING "INFTL: cannot calculate a geometry to "
120 "match size of 0x%lx.\n", inftl->mbd.size); 120 "match size of 0x%lx.\n", inftl->mbd.size);
121 printk(KERN_WARNING "INFTL: using C:%d H:%d S:%d " 121 printk(KERN_WARNING "INFTL: using C:%d H:%d S:%d "
122 "(== 0x%lx sects)\n", 122 "(== 0x%lx sects)\n",
123 inftl->cylinders, inftl->heads , inftl->sectors, 123 inftl->cylinders, inftl->heads , inftl->sectors,
124 (long)inftl->cylinders * (long)inftl->heads * 124 (long)inftl->cylinders * (long)inftl->heads *
125 (long)inftl->sectors ); 125 (long)inftl->sectors );
126 } 126 }
127 127
128 if (add_mtd_blktrans_dev(&inftl->mbd)) { 128 if (add_mtd_blktrans_dev(&inftl->mbd)) {
129 if (inftl->PUtable) 129 kfree(inftl->PUtable);
130 kfree(inftl->PUtable); 130 kfree(inftl->VUtable);
131 if (inftl->VUtable)
132 kfree(inftl->VUtable);
133 kfree(inftl); 131 kfree(inftl);
134 return; 132 return;
135 } 133 }
@@ -147,10 +145,8 @@ static void inftl_remove_dev(struct mtd_blktrans_dev *dev)
147 145
148 del_mtd_blktrans_dev(dev); 146 del_mtd_blktrans_dev(dev);
149 147
150 if (inftl->PUtable) 148 kfree(inftl->PUtable);
151 kfree(inftl->PUtable); 149 kfree(inftl->VUtable);
152 if (inftl->VUtable)
153 kfree(inftl->VUtable);
154 kfree(inftl); 150 kfree(inftl);
155} 151}
156 152
@@ -223,7 +219,7 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
223 "Virtual Unit Chain %d!\n", thisVUC); 219 "Virtual Unit Chain %d!\n", thisVUC);
224 return BLOCK_NIL; 220 return BLOCK_NIL;
225 } 221 }
226 222
227 /* 223 /*
228 * Scan to find the Erase Unit which holds the actual data for each 224 * Scan to find the Erase Unit which holds the actual data for each
229 * 512-byte block within the Chain. 225 * 512-byte block within the Chain.
@@ -264,7 +260,7 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
264 "Unit Chain 0x%x\n", thisVUC); 260 "Unit Chain 0x%x\n", thisVUC);
265 return BLOCK_NIL; 261 return BLOCK_NIL;
266 } 262 }
267 263
268 thisEUN = inftl->PUtable[thisEUN]; 264 thisEUN = inftl->PUtable[thisEUN];
269 } 265 }
270 266
@@ -295,15 +291,15 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
295 */ 291 */
296 if (BlockMap[block] == BLOCK_NIL) 292 if (BlockMap[block] == BLOCK_NIL)
297 continue; 293 continue;
298 294
299 ret = MTD_READ(inftl->mbd.mtd, (inftl->EraseSize * 295 ret = MTD_READ(inftl->mbd.mtd, (inftl->EraseSize *
300 BlockMap[block]) + (block * SECTORSIZE), SECTORSIZE, 296 BlockMap[block]) + (block * SECTORSIZE), SECTORSIZE,
301 &retlen, movebuf); 297 &retlen, movebuf);
302 if (ret < 0) { 298 if (ret < 0) {
303 ret = MTD_READ(inftl->mbd.mtd, (inftl->EraseSize * 299 ret = MTD_READ(inftl->mbd.mtd, (inftl->EraseSize *
304 BlockMap[block]) + (block * SECTORSIZE), 300 BlockMap[block]) + (block * SECTORSIZE),
305 SECTORSIZE, &retlen, movebuf); 301 SECTORSIZE, &retlen, movebuf);
306 if (ret != -EIO) 302 if (ret != -EIO)
307 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: error went " 303 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: error went "
308 "away on retry?\n"); 304 "away on retry?\n");
309 } 305 }
@@ -355,7 +351,7 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
355static u16 INFTL_makefreeblock(struct INFTLrecord *inftl, unsigned pendingblock) 351static u16 INFTL_makefreeblock(struct INFTLrecord *inftl, unsigned pendingblock)
356{ 352{
357 /* 353 /*
358 * This is the part that needs some cleverness applied. 354 * This is the part that needs some cleverness applied.
359 * For now, I'm doing the minimum applicable to actually 355 * For now, I'm doing the minimum applicable to actually
360 * get the thing to work. 356 * get the thing to work.
361 * Wear-levelling and other clever stuff needs to be implemented 357 * Wear-levelling and other clever stuff needs to be implemented
@@ -414,7 +410,7 @@ static int nrbits(unsigned int val, int bitcount)
414} 410}
415 411
416/* 412/*
417 * INFTL_findwriteunit: Return the unit number into which we can write 413 * INFTL_findwriteunit: Return the unit number into which we can write
418 * for this block. Make it available if it isn't already. 414 * for this block. Make it available if it isn't already.
419 */ 415 */
420static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block) 416static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
@@ -463,10 +459,10 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
463 * Invalid block. Don't use it any more. 459 * Invalid block. Don't use it any more.
464 * Must implement. 460 * Must implement.
465 */ 461 */
466 break; 462 break;
467 } 463 }
468 464
469 if (!silly--) { 465 if (!silly--) {
470 printk(KERN_WARNING "INFTL: infinite loop in " 466 printk(KERN_WARNING "INFTL: infinite loop in "
471 "Virtual Unit Chain 0x%x\n", thisVUC); 467 "Virtual Unit Chain 0x%x\n", thisVUC);
472 return 0xffff; 468 return 0xffff;
@@ -482,7 +478,7 @@ hitused:
482 478
483 479
484 /* 480 /*
485 * OK. We didn't find one in the existing chain, or there 481 * OK. We didn't find one in the existing chain, or there
486 * is no existing chain. Allocate a new one. 482 * is no existing chain. Allocate a new one.
487 */ 483 */
488 writeEUN = INFTL_findfreeblock(inftl, 0); 484 writeEUN = INFTL_findfreeblock(inftl, 0);
@@ -506,8 +502,8 @@ hitused:
506 if (writeEUN == BLOCK_NIL) { 502 if (writeEUN == BLOCK_NIL) {
507 /* 503 /*
508 * Ouch. This should never happen - we should 504 * Ouch. This should never happen - we should
509 * always be able to make some room somehow. 505 * always be able to make some room somehow.
510 * If we get here, we've allocated more storage 506 * If we get here, we've allocated more storage
511 * space than actual media, or our makefreeblock 507 * space than actual media, or our makefreeblock
512 * routine is missing something. 508 * routine is missing something.
513 */ 509 */
@@ -518,7 +514,7 @@ hitused:
518 INFTL_dumpVUchains(inftl); 514 INFTL_dumpVUchains(inftl);
519#endif 515#endif
520 return BLOCK_NIL; 516 return BLOCK_NIL;
521 } 517 }
522 } 518 }
523 519
524 /* 520 /*
@@ -543,7 +539,7 @@ hitused:
543 parity |= (nrbits(prev_block, 16) & 0x1) ? 0x2 : 0; 539 parity |= (nrbits(prev_block, 16) & 0x1) ? 0x2 : 0;
544 parity |= (nrbits(anac, 8) & 0x1) ? 0x4 : 0; 540 parity |= (nrbits(anac, 8) & 0x1) ? 0x4 : 0;
545 parity |= (nrbits(nacs, 8) & 0x1) ? 0x8 : 0; 541 parity |= (nrbits(nacs, 8) & 0x1) ? 0x8 : 0;
546 542
547 oob.u.a.virtualUnitNo = cpu_to_le16(thisVUC); 543 oob.u.a.virtualUnitNo = cpu_to_le16(thisVUC);
548 oob.u.a.prevUnitNo = cpu_to_le16(prev_block); 544 oob.u.a.prevUnitNo = cpu_to_le16(prev_block);
549 oob.u.a.ANAC = anac; 545 oob.u.a.ANAC = anac;
@@ -562,7 +558,7 @@ hitused:
562 oob.u.b.parityPerField = parity; 558 oob.u.b.parityPerField = parity;
563 oob.u.b.discarded = 0xaa; 559 oob.u.b.discarded = 0xaa;
564 560
565 MTD_WRITEOOB(inftl->mbd.mtd, writeEUN * inftl->EraseSize + 561 MTD_WRITEOOB(inftl->mbd.mtd, writeEUN * inftl->EraseSize +
566 SECTORSIZE * 4 + 8, 8, &retlen, (char *)&oob.u); 562 SECTORSIZE * 4 + 8, 8, &retlen, (char *)&oob.u);
567 563
568 inftl->PUtable[writeEUN] = inftl->VUtable[thisVUC]; 564 inftl->PUtable[writeEUN] = inftl->VUtable[thisVUC];
@@ -602,7 +598,7 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
602 "Virtual Unit Chain %d!\n", thisVUC); 598 "Virtual Unit Chain %d!\n", thisVUC);
603 return; 599 return;
604 } 600 }
605 601
606 /* 602 /*
607 * Scan through the Erase Units to determine whether any data is in 603 * Scan through the Erase Units to determine whether any data is in
608 * each of the 512-byte blocks within the Chain. 604 * each of the 512-byte blocks within the Chain.
@@ -642,7 +638,7 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
642 "Unit Chain 0x%x\n", thisVUC); 638 "Unit Chain 0x%x\n", thisVUC);
643 return; 639 return;
644 } 640 }
645 641
646 thisEUN = inftl->PUtable[thisEUN]; 642 thisEUN = inftl->PUtable[thisEUN];
647 } 643 }
648 644
@@ -758,7 +754,7 @@ foundit:
758 return 0; 754 return 0;
759} 755}
760 756
761static int inftl_writeblock(struct mtd_blktrans_dev *mbd, unsigned long block, 757static int inftl_writeblock(struct mtd_blktrans_dev *mbd, unsigned long block,
762 char *buffer) 758 char *buffer)
763{ 759{
764 struct INFTLrecord *inftl = (void *)mbd; 760 struct INFTLrecord *inftl = (void *)mbd;
@@ -893,7 +889,7 @@ extern char inftlmountrev[];
893 889
894static int __init init_inftl(void) 890static int __init init_inftl(void)
895{ 891{
896 printk(KERN_INFO "INFTL: inftlcore.c $Revision: 1.18 $, " 892 printk(KERN_INFO "INFTL: inftlcore.c $Revision: 1.19 $, "
897 "inftlmount.c %s\n", inftlmountrev); 893 "inftlmount.c %s\n", inftlmountrev);
898 894
899 return register_mtd_blktrans(&inftl_tr); 895 return register_mtd_blktrans(&inftl_tr);
diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
index b5dda47395a7..43fdc9433882 100644
--- a/drivers/mtd/inftlmount.c
+++ b/drivers/mtd/inftlmount.c
@@ -1,14 +1,14 @@
1/* 1/*
2 * inftlmount.c -- INFTL mount code with extensive checks. 2 * inftlmount.c -- INFTL mount code with extensive checks.
3 * 3 *
4 * Author: Greg Ungerer (gerg@snapgear.com) 4 * Author: Greg Ungerer (gerg@snapgear.com)
5 * (C) Copyright 2002-2003, Greg Ungerer (gerg@snapgear.com) 5 * (C) Copyright 2002-2003, Greg Ungerer (gerg@snapgear.com)
6 * 6 *
7 * Based heavily on the nftlmount.c code which is: 7 * Based heavily on the nftlmount.c code which is:
8 * Author: Fabrice Bellard (fabrice.bellard@netgem.com) 8 * Author: Fabrice Bellard (fabrice.bellard@netgem.com)
9 * Copyright (C) 2000 Netgem S.A. 9 * Copyright (C) 2000 Netgem S.A.
10 * 10 *
11 * $Id: inftlmount.c,v 1.16 2004/11/22 13:50:53 kalev Exp $ 11 * $Id: inftlmount.c,v 1.18 2005/11/07 11:14:20 gleixner Exp $
12 * 12 *
13 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by 14 * it under the terms of the GNU General Public License as published by
@@ -41,7 +41,7 @@
41#include <linux/mtd/inftl.h> 41#include <linux/mtd/inftl.h>
42#include <linux/mtd/compatmac.h> 42#include <linux/mtd/compatmac.h>
43 43
44char inftlmountrev[]="$Revision: 1.16 $"; 44char inftlmountrev[]="$Revision: 1.18 $";
45 45
46/* 46/*
47 * find_boot_record: Find the INFTL Media Header and its Spare copy which 47 * find_boot_record: Find the INFTL Media Header and its Spare copy which
@@ -273,7 +273,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
273 inftl->nb_boot_blocks); 273 inftl->nb_boot_blocks);
274 return -1; 274 return -1;
275 } 275 }
276 276
277 inftl->mbd.size = inftl->numvunits * 277 inftl->mbd.size = inftl->numvunits *
278 (inftl->EraseSize / SECTORSIZE); 278 (inftl->EraseSize / SECTORSIZE);
279 279
@@ -302,7 +302,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
302 inftl->nb_blocks * sizeof(u16)); 302 inftl->nb_blocks * sizeof(u16));
303 return -ENOMEM; 303 return -ENOMEM;
304 } 304 }
305 305
306 /* Mark the blocks before INFTL MediaHeader as reserved */ 306 /* Mark the blocks before INFTL MediaHeader as reserved */
307 for (i = 0; i < inftl->nb_boot_blocks; i++) 307 for (i = 0; i < inftl->nb_boot_blocks; i++)
308 inftl->PUtable[i] = BLOCK_RESERVED; 308 inftl->PUtable[i] = BLOCK_RESERVED;
@@ -380,7 +380,7 @@ static int check_free_sectors(struct INFTLrecord *inftl, unsigned int address,
380 * 380 *
381 * Return: 0 when succeed, -1 on error. 381 * Return: 0 when succeed, -1 on error.
382 * 382 *
383 * ToDo: 1. Is it neceressary to check_free_sector after erasing ?? 383 * ToDo: 1. Is it neceressary to check_free_sector after erasing ??
384 */ 384 */
385int INFTL_formatblock(struct INFTLrecord *inftl, int block) 385int INFTL_formatblock(struct INFTLrecord *inftl, int block)
386{ 386{
@@ -563,7 +563,7 @@ int INFTL_mount(struct INFTLrecord *s)
563 /* Search for INFTL MediaHeader and Spare INFTL Media Header */ 563 /* Search for INFTL MediaHeader and Spare INFTL Media Header */
564 if (find_boot_record(s) < 0) { 564 if (find_boot_record(s) < 0) {
565 printk(KERN_WARNING "INFTL: could not find valid boot record?\n"); 565 printk(KERN_WARNING "INFTL: could not find valid boot record?\n");
566 return -1; 566 return -ENXIO;
567 } 567 }
568 568
569 /* Init the logical to physical table */ 569 /* Init the logical to physical table */
@@ -574,6 +574,12 @@ int INFTL_mount(struct INFTLrecord *s)
574 574
575 /* Temporary buffer to store ANAC numbers. */ 575 /* Temporary buffer to store ANAC numbers. */
576 ANACtable = kmalloc(s->nb_blocks * sizeof(u8), GFP_KERNEL); 576 ANACtable = kmalloc(s->nb_blocks * sizeof(u8), GFP_KERNEL);
577 if (!ANACtable) {
578 printk(KERN_WARNING "INFTL: allocation of ANACtable "
579 "failed (%zd bytes)\n",
580 s->nb_blocks * sizeof(u8));
581 return -ENOMEM;
582 }
577 memset(ANACtable, 0, s->nb_blocks); 583 memset(ANACtable, 0, s->nb_blocks);
578 584
579 /* 585 /*
@@ -595,7 +601,7 @@ int INFTL_mount(struct INFTLrecord *s)
595 601
596 for (chain_length = 0; ; chain_length++) { 602 for (chain_length = 0; ; chain_length++) {
597 603
598 if ((chain_length == 0) && 604 if ((chain_length == 0) &&
599 (s->PUtable[block] != BLOCK_NOTEXPLORED)) { 605 (s->PUtable[block] != BLOCK_NOTEXPLORED)) {
600 /* Nothing to do here, onto next block */ 606 /* Nothing to do here, onto next block */
601 break; 607 break;
@@ -742,7 +748,7 @@ int INFTL_mount(struct INFTLrecord *s)
742 "in virtual chain %d\n", 748 "in virtual chain %d\n",
743 s->PUtable[block], logical_block); 749 s->PUtable[block], logical_block);
744 s->PUtable[block] = BLOCK_NIL; 750 s->PUtable[block] = BLOCK_NIL;
745 751
746 } 752 }
747 if (ANACtable[block] != ANAC) { 753 if (ANACtable[block] != ANAC) {
748 /* 754 /*
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 44781a83b2e7..48638c8097a5 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -1,5 +1,5 @@
1# drivers/mtd/maps/Kconfig 1# drivers/mtd/maps/Kconfig
2# $Id: Kconfig,v 1.55 2005/07/02 01:53:24 tpoynor Exp $ 2# $Id: Kconfig,v 1.61 2005/11/07 11:14:26 gleixner Exp $
3 3
4menu "Mapping drivers for chip access" 4menu "Mapping drivers for chip access"
5 depends on MTD!=n 5 depends on MTD!=n
@@ -64,9 +64,9 @@ config MTD_SUN_UFLASH
64 tristate "Sun Microsystems userflash support" 64 tristate "Sun Microsystems userflash support"
65 depends on (SPARC32 || SPARC64) && MTD_CFI 65 depends on (SPARC32 || SPARC64) && MTD_CFI
66 help 66 help
67 This provides a 'mapping' driver which supports the way in 67 This provides a 'mapping' driver which supports the way in
68 which user-programmable flash chips are connected on various 68 which user-programmable flash chips are connected on various
69 Sun Microsystems boardsets. This driver will require CFI support 69 Sun Microsystems boardsets. This driver will require CFI support
70 in the kernel, so if you did not enable CFI previously, do that now. 70 in the kernel, so if you did not enable CFI previously, do that now.
71 71
72config MTD_PNC2000 72config MTD_PNC2000
@@ -89,22 +89,22 @@ config MTD_NETSC520
89 depends on X86 && MTD_CFI && MTD_PARTITIONS 89 depends on X86 && MTD_CFI && MTD_PARTITIONS
90 help 90 help
91 This enables access routines for the flash chips on the AMD NetSc520 91 This enables access routines for the flash chips on the AMD NetSc520
92 demonstration board. If you have one of these boards and would like 92 demonstration board. If you have one of these boards and would like
93 to use the flash chips on it, say 'Y'. 93 to use the flash chips on it, say 'Y'.
94 94
95config MTD_TS5500 95config MTD_TS5500
96 tristate "JEDEC Flash device mapped on Technologic Systems TS-5500" 96 tristate "JEDEC Flash device mapped on Technologic Systems TS-5500"
97 depends on X86 && MTD_JEDECPROBE && MTD_PARTITIONS 97 depends on ELAN
98 select MTD_PARTITIONS
99 select MTD_JEDECPROBE
100 select MTD_CFI_AMDSTD
98 help 101 help
99 This provides a driver for the on-board flash of the Technologic 102 This provides a driver for the on-board flash of the Technologic
100 System's TS-5500 board. The flash is split into 3 partitions 103 System's TS-5500 board. The 2MB flash is split into 3 partitions
101 which are accessed as separate MTD devices. 104 which are accessed as separate MTD devices.
102 105
103 mtd0 and mtd2 are the two BIOS drives. Unfortunately the BIOS 106 mtd0 and mtd2 are the two BIOS drives, which use the resident
104 uses a proprietary flash translation layer from General Software, 107 flash disk (RFD) flash translation layer.
105 which is not supported (the drives cannot be mounted). You can
106 create your own file system (jffs for example), but the BIOS
107 won't be able to boot from it.
108 108
109 mtd1 allows you to reprogram your BIOS. BE VERY CAREFUL. 109 mtd1 allows you to reprogram your BIOS. BE VERY CAREFUL.
110 110
@@ -212,11 +212,18 @@ config MTD_NETtel
212 Support for flash chips on NETtel/SecureEdge/SnapGear boards. 212 Support for flash chips on NETtel/SecureEdge/SnapGear boards.
213 213
214config MTD_ALCHEMY 214config MTD_ALCHEMY
215 tristate ' AMD Alchemy Pb1xxx/Db1xxx/RDK MTD support' 215 tristate ' AMD Alchemy Pb1xxx/Db1xxx/RDK MTD support'
216 depends on MIPS && SOC_AU1X00 216 depends on SOC_AU1X00
217 help 217 help
218 Flash memory access on AMD Alchemy Pb/Db/RDK Reference Boards 218 Flash memory access on AMD Alchemy Pb/Db/RDK Reference Boards
219 219
220config MTD_MTX1
221 tristate "4G Systems MTX-1 Flash device"
222 depends on MIPS && MIPS_MTX1
223 help
224 Flash memory access on 4G Systems MTX-1 Board. If you have one of
225 these boards and would like to use the flash chips on it, say 'Y'.
226
220config MTD_DILNETPC 227config MTD_DILNETPC
221 tristate "CFI Flash device mapped on DIL/Net PC" 228 tristate "CFI Flash device mapped on DIL/Net PC"
222 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT 229 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT
@@ -244,14 +251,14 @@ config MTD_L440GX
244 251
245config MTD_SBC8240 252config MTD_SBC8240
246 tristate "Flash device on SBC8240" 253 tristate "Flash device on SBC8240"
247 depends on PPC32 && MTD_JEDECPROBE && 6xx && 8260 254 depends on MTD_JEDECPROBE && 8260
248 help 255 help
249 Flash access on the SBC8240 board from Wind River. See 256 Flash access on the SBC8240 board from Wind River. See
250 <http://www.windriver.com/products/sbc8240/> 257 <http://www.windriver.com/products/sbc8240/>
251 258
252config MTD_TQM8XXL 259config MTD_TQM8XXL
253 tristate "CFI Flash device mapped on TQM8XXL" 260 tristate "CFI Flash device mapped on TQM8XXL"
254 depends on MTD_CFI && PPC32 && 8xx && TQM8xxL 261 depends on MTD_CFI && TQM8xxL
255 help 262 help
256 The TQM8xxL PowerPC board has up to two banks of CFI-compliant 263 The TQM8xxL PowerPC board has up to two banks of CFI-compliant
257 chips, currently uses AMD one. This 'mapping' driver supports 264 chips, currently uses AMD one. This 'mapping' driver supports
@@ -261,7 +268,7 @@ config MTD_TQM8XXL
261 268
262config MTD_RPXLITE 269config MTD_RPXLITE
263 tristate "CFI Flash device mapped on RPX Lite or CLLF" 270 tristate "CFI Flash device mapped on RPX Lite or CLLF"
264 depends on MTD_CFI && PPC32 && 8xx && (RPXCLASSIC || RPXLITE) 271 depends on MTD_CFI && (RPXCLASSIC || RPXLITE)
265 help 272 help
266 The RPXLite PowerPC board has CFI-compliant chips mapped in 273 The RPXLite PowerPC board has CFI-compliant chips mapped in
267 a strange sparse mapping. This 'mapping' driver supports that 274 a strange sparse mapping. This 'mapping' driver supports that
@@ -271,7 +278,7 @@ config MTD_RPXLITE
271 278
272config MTD_MBX860 279config MTD_MBX860
273 tristate "System flash on MBX860 board" 280 tristate "System flash on MBX860 board"
274 depends on MTD_CFI && PPC32 && 8xx && MBX 281 depends on MTD_CFI && MBX
275 help 282 help
276 This enables access routines for the flash chips on the Motorola 283 This enables access routines for the flash chips on the Motorola
277 MBX860 board. If you have one of these boards and would like 284 MBX860 board. If you have one of these boards and would like
@@ -279,7 +286,7 @@ config MTD_MBX860
279 286
280config MTD_DBOX2 287config MTD_DBOX2
281 tristate "CFI Flash device mapped on D-Box2" 288 tristate "CFI Flash device mapped on D-Box2"
282 depends on PPC32 && 8xx && DBOX2 && MTD_CFI_INTELSTD && MTD_CFI_INTELEXT && MTD_CFI_AMDSTD 289 depends on DBOX2 && MTD_CFI_INTELSTD && MTD_CFI_INTELEXT && MTD_CFI_AMDSTD
283 help 290 help
284 This enables access routines for the flash chips on the Nokia/Sagem 291 This enables access routines for the flash chips on the Nokia/Sagem
285 D-Box 2 board. If you have one of these boards and would like to use 292 D-Box 2 board. If you have one of these boards and would like to use
@@ -287,14 +294,14 @@ config MTD_DBOX2
287 294
288config MTD_CFI_FLAGADM 295config MTD_CFI_FLAGADM
289 tristate "CFI Flash device mapping on FlagaDM" 296 tristate "CFI Flash device mapping on FlagaDM"
290 depends on PPC32 && 8xx && MTD_CFI 297 depends on 8xx && MTD_CFI
291 help 298 help
292 Mapping for the Flaga digital module. If you don't have one, ignore 299 Mapping for the Flaga digital module. If you don't have one, ignore
293 this setting. 300 this setting.
294 301
295config MTD_BEECH 302config MTD_BEECH
296 tristate "CFI Flash device mapped on IBM 405LP Beech" 303 tristate "CFI Flash device mapped on IBM 405LP Beech"
297 depends on MTD_CFI && PPC32 && 40x && BEECH 304 depends on MTD_CFI && BEECH
298 help 305 help
299 This enables access routines for the flash chips on the IBM 306 This enables access routines for the flash chips on the IBM
300 405LP Beech board. If you have one of these boards and would like 307 405LP Beech board. If you have one of these boards and would like
@@ -302,7 +309,7 @@ config MTD_BEECH
302 309
303config MTD_ARCTIC 310config MTD_ARCTIC
304 tristate "CFI Flash device mapped on IBM 405LP Arctic" 311 tristate "CFI Flash device mapped on IBM 405LP Arctic"
305 depends on MTD_CFI && PPC32 && 40x && ARCTIC2 312 depends on MTD_CFI && ARCTIC2
306 help 313 help
307 This enables access routines for the flash chips on the IBM 405LP 314 This enables access routines for the flash chips on the IBM 405LP
308 Arctic board. If you have one of these boards and would like to 315 Arctic board. If you have one of these boards and would like to
@@ -310,7 +317,7 @@ config MTD_ARCTIC
310 317
311config MTD_WALNUT 318config MTD_WALNUT
312 tristate "Flash device mapped on IBM 405GP Walnut" 319 tristate "Flash device mapped on IBM 405GP Walnut"
313 depends on MTD_JEDECPROBE && PPC32 && 40x && WALNUT 320 depends on MTD_JEDECPROBE && WALNUT
314 help 321 help
315 This enables access routines for the flash chips on the IBM 405GP 322 This enables access routines for the flash chips on the IBM 405GP
316 Walnut board. If you have one of these boards and would like to 323 Walnut board. If you have one of these boards and would like to
@@ -318,7 +325,7 @@ config MTD_WALNUT
318 325
319config MTD_EBONY 326config MTD_EBONY
320 tristate "Flash devices mapped on IBM 440GP Ebony" 327 tristate "Flash devices mapped on IBM 440GP Ebony"
321 depends on MTD_JEDECPROBE && PPC32 && 44x && EBONY 328 depends on MTD_JEDECPROBE && EBONY
322 help 329 help
323 This enables access routines for the flash chips on the IBM 440GP 330 This enables access routines for the flash chips on the IBM 440GP
324 Ebony board. If you have one of these boards and would like to 331 Ebony board. If you have one of these boards and would like to
@@ -326,7 +333,7 @@ config MTD_EBONY
326 333
327config MTD_OCOTEA 334config MTD_OCOTEA
328 tristate "Flash devices mapped on IBM 440GX Ocotea" 335 tristate "Flash devices mapped on IBM 440GX Ocotea"
329 depends on MTD_CFI && PPC32 && 44x && OCOTEA 336 depends on MTD_CFI && OCOTEA
330 help 337 help
331 This enables access routines for the flash chips on the IBM 440GX 338 This enables access routines for the flash chips on the IBM 440GX
332 Ocotea board. If you have one of these boards and would like to 339 Ocotea board. If you have one of these boards and would like to
@@ -334,12 +341,20 @@ config MTD_OCOTEA
334 341
335config MTD_REDWOOD 342config MTD_REDWOOD
336 tristate "CFI Flash devices mapped on IBM Redwood" 343 tristate "CFI Flash devices mapped on IBM Redwood"
337 depends on MTD_CFI && PPC32 && 4xx && 40x && ( REDWOOD_4 || REDWOOD_5 || REDWOOD_6 ) 344 depends on MTD_CFI && ( REDWOOD_4 || REDWOOD_5 || REDWOOD_6 )
338 help 345 help
339 This enables access routines for the flash chips on the IBM 346 This enables access routines for the flash chips on the IBM
340 Redwood board. If you have one of these boards and would like to 347 Redwood board. If you have one of these boards and would like to
341 use the flash chips on it, say 'Y'. 348 use the flash chips on it, say 'Y'.
342 349
350config MTD_TQM834x
351 tristate "Flash device mapped on TQ Components TQM834x Boards"
352 depends on MTD_CFI && TQM834x
353 help
354 This enables access routines for the flash chips on the
355 TQ Components TQM834x boards. If you have one of these boards
356 and would like to use the flash chips on it, say 'Y'.
357
343config MTD_CSTM_MIPS_IXX 358config MTD_CSTM_MIPS_IXX
344 tristate "Flash chip mapping on ITE QED-4N-S01B, Globespan IVR or custom board" 359 tristate "Flash chip mapping on ITE QED-4N-S01B, Globespan IVR or custom board"
345 depends on MIPS && MTD_CFI && MTD_JEDECPROBE && MTD_PARTITIONS 360 depends on MIPS && MTD_CFI && MTD_JEDECPROBE && MTD_PARTITIONS
@@ -362,8 +377,8 @@ config MTD_CSTM_MIPS_IXX_START
362 default "0x8000000" 377 default "0x8000000"
363 help 378 help
364 This is the physical memory location that the MTD driver will 379 This is the physical memory location that the MTD driver will
365 use for the flash chips on your particular target board. 380 use for the flash chips on your particular target board.
366 Refer to the memory map which should hopefully be in the 381 Refer to the memory map which should hopefully be in the
367 documentation for your board. 382 documentation for your board.
368 383
369config MTD_CSTM_MIPS_IXX_LEN 384config MTD_CSTM_MIPS_IXX_LEN
@@ -371,7 +386,7 @@ config MTD_CSTM_MIPS_IXX_LEN
371 depends on MTD_CSTM_MIPS_IXX 386 depends on MTD_CSTM_MIPS_IXX
372 default "0x4000000" 387 default "0x4000000"
373 help 388 help
374 This is the total length that the MTD driver will use for the 389 This is the total length that the MTD driver will use for the
375 flash chips on your particular board. Refer to the memory 390 flash chips on your particular board. Refer to the memory
376 map which should hopefully be in the documentation for your 391 map which should hopefully be in the documentation for your
377 board. 392 board.
@@ -405,14 +420,14 @@ config MTD_ARM_INTEGRATOR
405 420
406config MTD_CDB89712 421config MTD_CDB89712
407 tristate "Cirrus CDB89712 evaluation board mappings" 422 tristate "Cirrus CDB89712 evaluation board mappings"
408 depends on ARM && MTD_CFI && ARCH_CDB89712 423 depends on MTD_CFI && ARCH_CDB89712
409 help 424 help
410 This enables access to the flash or ROM chips on the CDB89712 board. 425 This enables access to the flash or ROM chips on the CDB89712 board.
411 If you have such a board, say 'Y'. 426 If you have such a board, say 'Y'.
412 427
413config MTD_SA1100 428config MTD_SA1100
414 tristate "CFI Flash device mapped on StrongARM SA11x0" 429 tristate "CFI Flash device mapped on StrongARM SA11x0"
415 depends on ARM && MTD_CFI && ARCH_SA1100 && MTD_PARTITIONS 430 depends on MTD_CFI && ARCH_SA1100 && MTD_PARTITIONS
416 help 431 help
417 This enables access to the flash chips on most platforms based on 432 This enables access to the flash chips on most platforms based on
418 the SA1100 and SA1110, including the Assabet and the Compaq iPAQ. 433 the SA1100 and SA1110, including the Assabet and the Compaq iPAQ.
@@ -420,13 +435,13 @@ config MTD_SA1100
420 435
421config MTD_IPAQ 436config MTD_IPAQ
422 tristate "CFI Flash device mapped on Compaq/HP iPAQ" 437 tristate "CFI Flash device mapped on Compaq/HP iPAQ"
423 depends on ARM && IPAQ_HANDHELD && MTD_CFI 438 depends on IPAQ_HANDHELD && MTD_CFI
424 help 439 help
425 This provides a driver for the on-board flash of the iPAQ. 440 This provides a driver for the on-board flash of the iPAQ.
426 441
427config MTD_DC21285 442config MTD_DC21285
428 tristate "CFI Flash device mapped on DC21285 Footbridge" 443 tristate "CFI Flash device mapped on DC21285 Footbridge"
429 depends on ARM && MTD_CFI && ARCH_FOOTBRIDGE && MTD_COMPLEX_MAPPINGS 444 depends on MTD_CFI && ARCH_FOOTBRIDGE && MTD_COMPLEX_MAPPINGS
430 help 445 help
431 This provides a driver for the flash accessed using Intel's 446 This provides a driver for the flash accessed using Intel's
432 21285 bridge used with Intel's StrongARM processors. More info at 447 21285 bridge used with Intel's StrongARM processors. More info at
@@ -434,33 +449,33 @@ config MTD_DC21285
434 449
435config MTD_IQ80310 450config MTD_IQ80310
436 tristate "CFI Flash device mapped on the XScale IQ80310 board" 451 tristate "CFI Flash device mapped on the XScale IQ80310 board"
437 depends on ARM && MTD_CFI && ARCH_IQ80310 452 depends on MTD_CFI && ARCH_IQ80310
438 help 453 help
439 This enables access routines for the flash chips on the Intel XScale 454 This enables access routines for the flash chips on the Intel XScale
440 IQ80310 evaluation board. If you have one of these boards and would 455 IQ80310 evaluation board. If you have one of these boards and would
441 like to use the flash chips on it, say 'Y'. 456 like to use the flash chips on it, say 'Y'.
442 457
443config MTD_IXP4XX 458config MTD_IXP4XX
444 tristate "CFI Flash device mapped on Intel IXP4xx based systems" 459 tristate "CFI Flash device mapped on Intel IXP4xx based systems"
445 depends on ARM && MTD_CFI && MTD_COMPLEX_MAPPINGS && ARCH_IXP4XX 460 depends on MTD_CFI && MTD_COMPLEX_MAPPINGS && ARCH_IXP4XX
446 help 461 help
447 This enables MTD access to flash devices on platforms based 462 This enables MTD access to flash devices on platforms based
448 on Intel's IXP4xx family of network processors such as the 463 on Intel's IXP4xx family of network processors such as the
449 IXDP425 and Coyote. If you have an IXP4xx based board and 464 IXDP425 and Coyote. If you have an IXP4xx based board and
450 would like to use the flash chips on it, say 'Y'. 465 would like to use the flash chips on it, say 'Y'.
451 466
452config MTD_IXP2000 467config MTD_IXP2000
453 tristate "CFI Flash device mapped on Intel IXP2000 based systems" 468 tristate "CFI Flash device mapped on Intel IXP2000 based systems"
454 depends on ARM && MTD_CFI && MTD_COMPLEX_MAPPINGS && ARCH_IXP2000 469 depends on MTD_CFI && MTD_COMPLEX_MAPPINGS && ARCH_IXP2000
455 help 470 help
456 This enables MTD access to flash devices on platforms based 471 This enables MTD access to flash devices on platforms based
457 on Intel's IXP2000 family of network processors such as the 472 on Intel's IXP2000 family of network processors such as the
458 IXDP425 and Coyote. If you have an IXP2000 based board and 473 IXDP425 and Coyote. If you have an IXP2000 based board and
459 would like to use the flash chips on it, say 'Y'. 474 would like to use the flash chips on it, say 'Y'.
460 475
461config MTD_EPXA10DB 476config MTD_EPXA10DB
462 tristate "CFI Flash device mapped on Epxa10db" 477 tristate "CFI Flash device mapped on Epxa10db"
463 depends on ARM && MTD_CFI && MTD_PARTITIONS && ARCH_CAMELOT 478 depends on MTD_CFI && MTD_PARTITIONS && ARCH_CAMELOT
464 help 479 help
465 This enables support for the flash devices on the Altera 480 This enables support for the flash devices on the Altera
466 Excalibur XA10 Development Board. If you are building a kernel 481 Excalibur XA10 Development Board. If you are building a kernel
@@ -468,21 +483,21 @@ config MTD_EPXA10DB
468 483
469config MTD_FORTUNET 484config MTD_FORTUNET
470 tristate "CFI Flash device mapped on the FortuNet board" 485 tristate "CFI Flash device mapped on the FortuNet board"
471 depends on ARM && MTD_CFI && MTD_PARTITIONS && SA1100_FORTUNET 486 depends on MTD_CFI && MTD_PARTITIONS && SA1100_FORTUNET
472 help 487 help
473 This enables access to the Flash on the FortuNet board. If you 488 This enables access to the Flash on the FortuNet board. If you
474 have such a board, say 'Y'. 489 have such a board, say 'Y'.
475 490
476config MTD_AUTCPU12 491config MTD_AUTCPU12
477 tristate "NV-RAM mapping AUTCPU12 board" 492 tristate "NV-RAM mapping AUTCPU12 board"
478 depends on ARM && ARCH_AUTCPU12 493 depends on ARCH_AUTCPU12
479 help 494 help
480 This enables access to the NV-RAM on autronix autcpu12 board. 495 This enables access to the NV-RAM on autronix autcpu12 board.
481 If you have such a board, say 'Y'. 496 If you have such a board, say 'Y'.
482 497
483config MTD_EDB7312 498config MTD_EDB7312
484 tristate "CFI Flash device mapped on EDB7312" 499 tristate "CFI Flash device mapped on EDB7312"
485 depends on ARM && MTD_CFI 500 depends on ARCH_EDB7312 && MTD_CFI
486 help 501 help
487 This enables access to the CFI Flash on the Cogent EDB7312 board. 502 This enables access to the CFI Flash on the Cogent EDB7312 board.
488 If you have such a board, say 'Y' here. 503 If you have such a board, say 'Y' here.
@@ -496,7 +511,7 @@ config MTD_IMPA7
496 511
497config MTD_CEIVA 512config MTD_CEIVA
498 tristate "JEDEC Flash device mapped on Ceiva/Polaroid PhotoMax Digital Picture Frame" 513 tristate "JEDEC Flash device mapped on Ceiva/Polaroid PhotoMax Digital Picture Frame"
499 depends on ARM && MTD_JEDECPROBE && ARCH_CEIVA 514 depends on MTD_JEDECPROBE && ARCH_CEIVA
500 help 515 help
501 This enables access to the flash chips on the Ceiva/Polaroid 516 This enables access to the flash chips on the Ceiva/Polaroid
502 PhotoMax Digital Picture Frame. 517 PhotoMax Digital Picture Frame.
@@ -504,25 +519,31 @@ config MTD_CEIVA
504 519
505config MTD_NOR_TOTO 520config MTD_NOR_TOTO
506 tristate "NOR Flash device on TOTO board" 521 tristate "NOR Flash device on TOTO board"
507 depends on ARM && ARCH_OMAP && OMAP_TOTO 522 depends on ARCH_OMAP && OMAP_TOTO
508 help 523 help
509 This enables access to the NOR flash on the Texas Instruments 524 This enables access to the NOR flash on the Texas Instruments
510 TOTO board. 525 TOTO board.
511 526
512config MTD_H720X 527config MTD_H720X
513 tristate "Hynix evaluation board mappings" 528 tristate "Hynix evaluation board mappings"
514 depends on ARM && MTD_CFI && ( ARCH_H7201 || ARCH_H7202 ) 529 depends on MTD_CFI && ( ARCH_H7201 || ARCH_H7202 )
515 help 530 help
516 This enables access to the flash chips on the Hynix evaluation boards. 531 This enables access to the flash chips on the Hynix evaluation boards.
517 If you have such a board, say 'Y'. 532 If you have such a board, say 'Y'.
518 533
519config MTD_MPC1211 534config MTD_MPC1211
520 tristate "CFI Flash device mapped on Interface MPC-1211" 535 tristate "CFI Flash device mapped on Interface MPC-1211"
521 depends on SUPERH && SH_MPC1211 && MTD_CFI 536 depends on SH_MPC1211 && MTD_CFI
522 help 537 help
523 This enables access to the flash chips on the Interface MPC-1211(CTP/PCI/MPC-SH02). 538 This enables access to the flash chips on the Interface MPC-1211(CTP/PCI/MPC-SH02).
524 If you have such a board, say 'Y'. 539 If you have such a board, say 'Y'.
525 540
541config MTD_PQ2FADS
542 tristate "JEDEC flash SIMM mapped on PQ2FADS and 8272ADS boards"
543 depends on (ADS8272 || PQ2FADS) && MTD_PARTITIONS && MTD_JEDECPROBE && MTD_PHYSMAP && MTD_CFI_GEOMETRY && MTD_CFI_INTELEXT
544 help
545 This enables access to flash SIMM on PQ2FADS-like boards
546
526config MTD_OMAP_NOR 547config MTD_OMAP_NOR
527 tristate "TI OMAP board mappings" 548 tristate "TI OMAP board mappings"
528 depends on MTD_CFI && ARCH_OMAP 549 depends on MTD_CFI && ARCH_OMAP
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index 7bcbc49e329f..7d9e940a1dcd 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -1,7 +1,7 @@
1# 1#
2# linux/drivers/maps/Makefile 2# linux/drivers/maps/Makefile
3# 3#
4# $Id: Makefile.common,v 1.30 2005/07/02 01:53:24 tpoynor Exp $ 4# $Id: Makefile.common,v 1.34 2005/11/07 11:14:26 gleixner Exp $
5 5
6ifeq ($(CONFIG_MTD_COMPLEX_MAPPINGS),y) 6ifeq ($(CONFIG_MTD_COMPLEX_MAPPINGS),y)
7obj-$(CONFIG_MTD) += map_funcs.o 7obj-$(CONFIG_MTD) += map_funcs.o
@@ -26,7 +26,7 @@ obj-$(CONFIG_MTD_MAINSTONE) += mainstone-flash.o
26obj-$(CONFIG_MTD_MBX860) += mbx860.o 26obj-$(CONFIG_MTD_MBX860) += mbx860.o
27obj-$(CONFIG_MTD_CEIVA) += ceiva.o 27obj-$(CONFIG_MTD_CEIVA) += ceiva.o
28obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o 28obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o
29obj-$(CONFIG_MTD_PHYSMAP) += physmap.o 29obj-$(CONFIG_MTD_PHYSMAP) += physmap.o
30obj-$(CONFIG_MTD_PNC2000) += pnc2000.o 30obj-$(CONFIG_MTD_PNC2000) += pnc2000.o
31obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o 31obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
32obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o 32obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
@@ -70,3 +70,6 @@ obj-$(CONFIG_MTD_DMV182) += dmv182.o
70obj-$(CONFIG_MTD_SHARP_SL) += sharpsl-flash.o 70obj-$(CONFIG_MTD_SHARP_SL) += sharpsl-flash.o
71obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o 71obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o
72obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o 72obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o
73obj-$(CONFIG_MTD_PQ2FADS) += pq2fads.o
74obj-$(CONFIG_MTD_MTX1) += mtx-1_flash.o
75obj-$(CONFIG_MTD_TQM834x) += tqm834x.o
diff --git a/drivers/mtd/maps/alchemy-flash.c b/drivers/mtd/maps/alchemy-flash.c
index 27fd2a3c3b60..a57791a6ce40 100644
--- a/drivers/mtd/maps/alchemy-flash.c
+++ b/drivers/mtd/maps/alchemy-flash.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * Flash memory access on AMD Alchemy evaluation boards 2 * Flash memory access on AMD Alchemy evaluation boards
3 * 3 *
4 * $Id: alchemy-flash.c,v 1.1 2005/02/27 21:50:21 ppopov Exp $ 4 * $Id: alchemy-flash.c,v 1.2 2005/11/07 11:14:26 gleixner Exp $
5 * 5 *
6 * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com> 6 * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com>
7 * 7 *
8 */ 8 */
9 9
10#include <linux/config.h> 10#include <linux/config.h>
@@ -22,7 +22,7 @@
22#ifdef DEBUG_RW 22#ifdef DEBUG_RW
23#define DBG(x...) printk(x) 23#define DBG(x...) printk(x)
24#else 24#else
25#define DBG(x...) 25#define DBG(x...)
26#endif 26#endif
27 27
28#ifdef CONFIG_MIPS_PB1000 28#ifdef CONFIG_MIPS_PB1000
@@ -136,7 +136,7 @@ int __init alchemy_mtd_init(void)
136 int nb_parts = 0; 136 int nb_parts = 0;
137 unsigned long window_addr; 137 unsigned long window_addr;
138 unsigned long window_size; 138 unsigned long window_size;
139 139
140 /* Default flash buswidth */ 140 /* Default flash buswidth */
141 alchemy_map.bankwidth = BOARD_FLASH_WIDTH; 141 alchemy_map.bankwidth = BOARD_FLASH_WIDTH;
142 142
@@ -161,7 +161,7 @@ int __init alchemy_mtd_init(void)
161 * Now let's probe for the actual flash. Do it here since 161 * Now let's probe for the actual flash. Do it here since
162 * specific machine settings might have been set above. 162 * specific machine settings might have been set above.
163 */ 163 */
164 printk(KERN_NOTICE BOARD_MAP_NAME ": probing %d-bit flash bus\n", 164 printk(KERN_NOTICE BOARD_MAP_NAME ": probing %d-bit flash bus\n",
165 alchemy_map.bankwidth*8); 165 alchemy_map.bankwidth*8);
166 alchemy_map.virt = ioremap(window_addr, window_size); 166 alchemy_map.virt = ioremap(window_addr, window_size);
167 mymtd = do_map_probe("cfi_probe", &alchemy_map); 167 mymtd = do_map_probe("cfi_probe", &alchemy_map);
diff --git a/drivers/mtd/maps/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c
index e8a900a77685..c350878d4592 100644
--- a/drivers/mtd/maps/amd76xrom.c
+++ b/drivers/mtd/maps/amd76xrom.c
@@ -2,7 +2,7 @@
2 * amd76xrom.c 2 * amd76xrom.c
3 * 3 *
4 * Normal mappings of chips in physical memory 4 * Normal mappings of chips in physical memory
5 * $Id: amd76xrom.c,v 1.20 2005/03/18 14:04:35 gleixner Exp $ 5 * $Id: amd76xrom.c,v 1.21 2005/11/07 11:14:26 gleixner Exp $
6 */ 6 */
7 7
8#include <linux/module.h> 8#include <linux/module.h>
@@ -70,7 +70,7 @@ static void amd76xrom_cleanup(struct amd76xrom_window *window)
70 list_del(&map->list); 70 list_del(&map->list);
71 kfree(map); 71 kfree(map);
72 } 72 }
73 if (window->rsrc.parent) 73 if (window->rsrc.parent)
74 release_resource(&window->rsrc); 74 release_resource(&window->rsrc);
75 75
76 if (window->virt) { 76 if (window->virt) {
@@ -107,7 +107,7 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
107 window->phys = 0xffff0000; /* 64KiB */ 107 window->phys = 0xffff0000; /* 64KiB */
108 } 108 }
109 window->size = 0xffffffffUL - window->phys + 1UL; 109 window->size = 0xffffffffUL - window->phys + 1UL;
110 110
111 /* 111 /*
112 * Try to reserve the window mem region. If this fails then 112 * Try to reserve the window mem region. If this fails then
113 * it is likely due to a fragment of the window being 113 * it is likely due to a fragment of the window being
@@ -138,7 +138,7 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
138 /* Enable writes through the rom window */ 138 /* Enable writes through the rom window */
139 pci_read_config_byte(pdev, 0x40, &byte); 139 pci_read_config_byte(pdev, 0x40, &byte);
140 pci_write_config_byte(pdev, 0x40, byte | 1); 140 pci_write_config_byte(pdev, 0x40, byte | 1);
141 141
142 /* FIXME handle registers 0x80 - 0x8C the bios region locks */ 142 /* FIXME handle registers 0x80 - 0x8C the bios region locks */
143 143
144 /* For write accesses caches are useless */ 144 /* For write accesses caches are useless */
@@ -186,7 +186,7 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
186 MOD_NAME, map->map.phys); 186 MOD_NAME, map->map.phys);
187 187
188 /* There is no generic VPP support */ 188 /* There is no generic VPP support */
189 for(map->map.bankwidth = 32; map->map.bankwidth; 189 for(map->map.bankwidth = 32; map->map.bankwidth;
190 map->map.bankwidth >>= 1) 190 map->map.bankwidth >>= 1)
191 { 191 {
192 char **probe_type; 192 char **probe_type;
@@ -239,7 +239,7 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
239 for(i = 0; i < cfi->numchips; i++) { 239 for(i = 0; i < cfi->numchips; i++) {
240 cfi->chips[i].start += offset; 240 cfi->chips[i].start += offset;
241 } 241 }
242 242
243 /* Now that the mtd devices is complete claim and export it */ 243 /* Now that the mtd devices is complete claim and export it */
244 map->mtd->owner = THIS_MODULE; 244 map->mtd->owner = THIS_MODULE;
245 if (add_mtd_device(map->mtd)) { 245 if (add_mtd_device(map->mtd)) {
@@ -259,9 +259,7 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
259 259
260 out: 260 out:
261 /* Free any left over map structures */ 261 /* Free any left over map structures */
262 if (map) { 262 kfree(map);
263 kfree(map);
264 }
265 /* See if I have any map structures */ 263 /* See if I have any map structures */
266 if (list_empty(&window->maps)) { 264 if (list_empty(&window->maps)) {
267 amd76xrom_cleanup(window); 265 amd76xrom_cleanup(window);
@@ -279,9 +277,9 @@ static void __devexit amd76xrom_remove_one (struct pci_dev *pdev)
279} 277}
280 278
281static struct pci_device_id amd76xrom_pci_tbl[] = { 279static struct pci_device_id amd76xrom_pci_tbl[] = {
282 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7410, 280 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7410,
283 PCI_ANY_ID, PCI_ANY_ID, }, 281 PCI_ANY_ID, PCI_ANY_ID, },
284 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7440, 282 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7440,
285 PCI_ANY_ID, PCI_ANY_ID, }, 283 PCI_ANY_ID, PCI_ANY_ID, },
286 { PCI_VENDOR_ID_AMD, 0x7468 }, /* amd8111 support */ 284 { PCI_VENDOR_ID_AMD, 0x7468 }, /* amd8111 support */
287 { 0, } 285 { 0, }
diff --git a/drivers/mtd/maps/arctic-mtd.c b/drivers/mtd/maps/arctic-mtd.c
index 777276fd0e15..d95ae582fbe9 100644
--- a/drivers/mtd/maps/arctic-mtd.c
+++ b/drivers/mtd/maps/arctic-mtd.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * $Id: arctic-mtd.c,v 1.13 2004/11/04 13:24:14 gleixner Exp $ 2 * $Id: arctic-mtd.c,v 1.14 2005/11/07 11:14:26 gleixner Exp $
3 * 3 *
4 * drivers/mtd/maps/arctic-mtd.c MTD mappings and partition tables for 4 * drivers/mtd/maps/arctic-mtd.c MTD mappings and partition tables for
5 * IBM 405LP Arctic boards. 5 * IBM 405LP Arctic boards.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
diff --git a/drivers/mtd/maps/autcpu12-nvram.c b/drivers/mtd/maps/autcpu12-nvram.c
index cf362ccc3c8e..7ed3424dd959 100644
--- a/drivers/mtd/maps/autcpu12-nvram.c
+++ b/drivers/mtd/maps/autcpu12-nvram.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * NV-RAM memory access on autcpu12 2 * NV-RAM memory access on autcpu12
3 * (C) 2002 Thomas Gleixner (gleixner@autronix.de) 3 * (C) 2002 Thomas Gleixner (gleixner@autronix.de)
4 * 4 *
5 * $Id: autcpu12-nvram.c,v 1.8 2004/11/04 13:24:14 gleixner Exp $ 5 * $Id: autcpu12-nvram.c,v 1.9 2005/11/07 11:14:26 gleixner Exp $
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -55,10 +55,10 @@ static int __init init_autcpu12_sram (void)
55 } 55 }
56 simple_map_init(&autcpu_sram_map); 56 simple_map_init(&autcpu_sram_map);
57 57
58 /* 58 /*
59 * Check for 32K/128K 59 * Check for 32K/128K
60 * read ofs 0 60 * read ofs 0
61 * read ofs 0x10000 61 * read ofs 0x10000
62 * Write complement to ofs 0x100000 62 * Write complement to ofs 0x100000
63 * Read and check result on ofs 0x0 63 * Read and check result on ofs 0x0
64 * Restore contents 64 * Restore contents
@@ -66,7 +66,7 @@ static int __init init_autcpu12_sram (void)
66 save0 = map_read32(&autcpu12_sram_map,0); 66 save0 = map_read32(&autcpu12_sram_map,0);
67 save1 = map_read32(&autcpu12_sram_map,0x10000); 67 save1 = map_read32(&autcpu12_sram_map,0x10000);
68 map_write32(&autcpu12_sram_map,~save0,0x10000); 68 map_write32(&autcpu12_sram_map,~save0,0x10000);
69 /* if we find this pattern on 0x0, we have 32K size 69 /* if we find this pattern on 0x0, we have 32K size
70 * restore contents and exit 70 * restore contents and exit
71 */ 71 */
72 if ( map_read32(&autcpu12_sram_map,0) != save0) { 72 if ( map_read32(&autcpu12_sram_map,0) != save0) {
@@ -89,7 +89,7 @@ map:
89 89
90 sram_mtd->owner = THIS_MODULE; 90 sram_mtd->owner = THIS_MODULE;
91 sram_mtd->erasesize = 16; 91 sram_mtd->erasesize = 16;
92 92
93 if (add_mtd_device(sram_mtd)) { 93 if (add_mtd_device(sram_mtd)) {
94 printk("NV-RAM device addition failed\n"); 94 printk("NV-RAM device addition failed\n");
95 err = -ENOMEM; 95 err = -ENOMEM;
@@ -97,7 +97,7 @@ map:
97 } 97 }
98 98
99 printk("NV-RAM device size %ldKiB registered on AUTCPU12\n",autcpu12_sram_map.size/SZ_1K); 99 printk("NV-RAM device size %ldKiB registered on AUTCPU12\n",autcpu12_sram_map.size/SZ_1K);
100 100
101 return 0; 101 return 0;
102 102
103out_probe: 103out_probe:
diff --git a/drivers/mtd/maps/bast-flash.c b/drivers/mtd/maps/bast-flash.c
index bfe994e59265..b7858eb93534 100644
--- a/drivers/mtd/maps/bast-flash.c
+++ b/drivers/mtd/maps/bast-flash.c
@@ -9,7 +9,7 @@
9 * 20-Sep-2004 BJD Initial version 9 * 20-Sep-2004 BJD Initial version
10 * 17-Jan-2005 BJD Add whole device if no partitions found 10 * 17-Jan-2005 BJD Add whole device if no partitions found
11 * 11 *
12 * $Id: bast-flash.c,v 1.2 2005/01/18 11:13:47 bjd Exp $ 12 * $Id: bast-flash.c,v 1.5 2005/11/07 11:14:26 gleixner Exp $
13 * 13 *
14 * This program is free software; you can redistribute it and/or modify 14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by 15 * it under the terms of the GNU General Public License as published by
@@ -75,7 +75,7 @@ static void bast_flash_setrw(int to)
75 75
76 local_irq_save(flags); 76 local_irq_save(flags);
77 val = __raw_readb(BAST_VA_CTRL3); 77 val = __raw_readb(BAST_VA_CTRL3);
78 78
79 if (to) 79 if (to)
80 val |= BAST_CPLD_CTRL3_ROMWEN; 80 val |= BAST_CPLD_CTRL3_ROMWEN;
81 else 81 else
@@ -93,7 +93,7 @@ static int bast_flash_remove(struct device *dev)
93 93
94 dev_set_drvdata(dev, NULL); 94 dev_set_drvdata(dev, NULL);
95 95
96 if (info == NULL) 96 if (info == NULL)
97 return 0; 97 return 0;
98 98
99 if (info->map.virt != NULL) 99 if (info->map.virt != NULL)
@@ -104,14 +104,13 @@ static int bast_flash_remove(struct device *dev)
104 map_destroy(info->mtd); 104 map_destroy(info->mtd);
105 } 105 }
106 106
107 if (info->partitions) 107 kfree(info->partitions);
108 kfree(info->partitions);
109 108
110 if (info->area) { 109 if (info->area) {
111 release_resource(info->area); 110 release_resource(info->area);
112 kfree(info->area); 111 kfree(info->area);
113 } 112 }
114 113
115 kfree(info); 114 kfree(info);
116 115
117 return 0; 116 return 0;
@@ -138,15 +137,15 @@ static int bast_flash_probe(struct device *dev)
138 137
139 info->map.phys = res->start; 138 info->map.phys = res->start;
140 info->map.size = res->end - res->start + 1; 139 info->map.size = res->end - res->start + 1;
141 info->map.name = dev->bus_id; 140 info->map.name = dev->bus_id;
142 info->map.bankwidth = 2; 141 info->map.bankwidth = 2;
143 142
144 if (info->map.size > AREA_MAXSIZE) 143 if (info->map.size > AREA_MAXSIZE)
145 info->map.size = AREA_MAXSIZE; 144 info->map.size = AREA_MAXSIZE;
146 145
147 pr_debug("%s: area %08lx, size %ld\n", __FUNCTION__, 146 pr_debug("%s: area %08lx, size %ld\n", __FUNCTION__,
148 info->map.phys, info->map.size); 147 info->map.phys, info->map.size);
149 148
150 info->area = request_mem_region(res->start, info->map.size, 149 info->area = request_mem_region(res->start, info->map.size,
151 pdev->name); 150 pdev->name);
152 if (info->area == NULL) { 151 if (info->area == NULL) {
@@ -163,7 +162,7 @@ static int bast_flash_probe(struct device *dev)
163 err = -EIO; 162 err = -EIO;
164 goto exit_error; 163 goto exit_error;
165 } 164 }
166 165
167 simple_map_init(&info->map); 166 simple_map_init(&info->map);
168 167
169 /* enable the write to the flash area */ 168 /* enable the write to the flash area */
@@ -188,7 +187,7 @@ static int bast_flash_probe(struct device *dev)
188 err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0); 187 err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0);
189 if (err > 0) { 188 if (err > 0) {
190 err = add_mtd_partitions(info->mtd, info->partitions, err); 189 err = add_mtd_partitions(info->mtd, info->partitions, err);
191 if (err) 190 if (err)
192 printk(KERN_ERR PFX "cannot add/parse partitions\n"); 191 printk(KERN_ERR PFX "cannot add/parse partitions\n");
193 } else { 192 } else {
194 err = add_mtd_device(info->mtd); 193 err = add_mtd_device(info->mtd);
@@ -206,6 +205,7 @@ static int bast_flash_probe(struct device *dev)
206 205
207static struct device_driver bast_flash_driver = { 206static struct device_driver bast_flash_driver = {
208 .name = "bast-nor", 207 .name = "bast-nor",
208 .owner = THIS_MODULE,
209 .bus = &platform_bus_type, 209 .bus = &platform_bus_type,
210 .probe = bast_flash_probe, 210 .probe = bast_flash_probe,
211 .remove = bast_flash_remove, 211 .remove = bast_flash_remove,
diff --git a/drivers/mtd/maps/beech-mtd.c b/drivers/mtd/maps/beech-mtd.c
index 5e79c9d5da2b..5df7361d1407 100644
--- a/drivers/mtd/maps/beech-mtd.c
+++ b/drivers/mtd/maps/beech-mtd.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * $Id: beech-mtd.c,v 1.10 2004/11/04 13:24:14 gleixner Exp $ 2 * $Id: beech-mtd.c,v 1.11 2005/11/07 11:14:26 gleixner Exp $
3 * 3 *
4 * drivers/mtd/maps/beech-mtd.c MTD mappings and partition tables for 4 * drivers/mtd/maps/beech-mtd.c MTD mappings and partition tables for
5 * IBM 405LP Beech boards. 5 * IBM 405LP Beech boards.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
diff --git a/drivers/mtd/maps/cdb89712.c b/drivers/mtd/maps/cdb89712.c
index ab15dac2f936..9f17bb6c5a9d 100644
--- a/drivers/mtd/maps/cdb89712.c
+++ b/drivers/mtd/maps/cdb89712.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Flash on Cirrus CDB89712 2 * Flash on Cirrus CDB89712
3 * 3 *
4 * $Id: cdb89712.c,v 1.10 2004/11/04 13:24:14 gleixner Exp $ 4 * $Id: cdb89712.c,v 1.11 2005/11/07 11:14:26 gleixner Exp $
5 */ 5 */
6 6
7#include <linux/module.h> 7#include <linux/module.h>
@@ -37,13 +37,13 @@ struct resource cdb89712_flash_resource = {
37static int __init init_cdb89712_flash (void) 37static int __init init_cdb89712_flash (void)
38{ 38{
39 int err; 39 int err;
40 40
41 if (request_resource (&ioport_resource, &cdb89712_flash_resource)) { 41 if (request_resource (&ioport_resource, &cdb89712_flash_resource)) {
42 printk(KERN_NOTICE "Failed to reserve Cdb89712 FLASH space\n"); 42 printk(KERN_NOTICE "Failed to reserve Cdb89712 FLASH space\n");
43 err = -EBUSY; 43 err = -EBUSY;
44 goto out; 44 goto out;
45 } 45 }
46 46
47 cdb89712_flash_map.virt = ioremap(FLASH_START, FLASH_SIZE); 47 cdb89712_flash_map.virt = ioremap(FLASH_START, FLASH_SIZE);
48 if (!cdb89712_flash_map.virt) { 48 if (!cdb89712_flash_map.virt) {
49 printk(KERN_NOTICE "Failed to ioremap Cdb89712 FLASH space\n"); 49 printk(KERN_NOTICE "Failed to ioremap Cdb89712 FLASH space\n");
@@ -64,13 +64,13 @@ static int __init init_cdb89712_flash (void)
64 } 64 }
65 65
66 flash_mtd->owner = THIS_MODULE; 66 flash_mtd->owner = THIS_MODULE;
67 67
68 if (add_mtd_device(flash_mtd)) { 68 if (add_mtd_device(flash_mtd)) {
69 printk("FLASH device addition failed\n"); 69 printk("FLASH device addition failed\n");
70 err = -ENOMEM; 70 err = -ENOMEM;
71 goto out_probe; 71 goto out_probe;
72 } 72 }
73 73
74 return 0; 74 return 0;
75 75
76out_probe: 76out_probe:
@@ -107,13 +107,13 @@ struct resource cdb89712_sram_resource = {
107static int __init init_cdb89712_sram (void) 107static int __init init_cdb89712_sram (void)
108{ 108{
109 int err; 109 int err;
110 110
111 if (request_resource (&ioport_resource, &cdb89712_sram_resource)) { 111 if (request_resource (&ioport_resource, &cdb89712_sram_resource)) {
112 printk(KERN_NOTICE "Failed to reserve Cdb89712 SRAM space\n"); 112 printk(KERN_NOTICE "Failed to reserve Cdb89712 SRAM space\n");
113 err = -EBUSY; 113 err = -EBUSY;
114 goto out; 114 goto out;
115 } 115 }
116 116
117 cdb89712_sram_map.virt = ioremap(SRAM_START, SRAM_SIZE); 117 cdb89712_sram_map.virt = ioremap(SRAM_START, SRAM_SIZE);
118 if (!cdb89712_sram_map.virt) { 118 if (!cdb89712_sram_map.virt) {
119 printk(KERN_NOTICE "Failed to ioremap Cdb89712 SRAM space\n"); 119 printk(KERN_NOTICE "Failed to ioremap Cdb89712 SRAM space\n");
@@ -130,13 +130,13 @@ static int __init init_cdb89712_sram (void)
130 130
131 sram_mtd->owner = THIS_MODULE; 131 sram_mtd->owner = THIS_MODULE;
132 sram_mtd->erasesize = 16; 132 sram_mtd->erasesize = 16;
133 133
134 if (add_mtd_device(sram_mtd)) { 134 if (add_mtd_device(sram_mtd)) {
135 printk("SRAM device addition failed\n"); 135 printk("SRAM device addition failed\n");
136 err = -ENOMEM; 136 err = -ENOMEM;
137 goto out_probe; 137 goto out_probe;
138 } 138 }
139 139
140 return 0; 140 return 0;
141 141
142out_probe: 142out_probe:
@@ -175,13 +175,13 @@ struct resource cdb89712_bootrom_resource = {
175static int __init init_cdb89712_bootrom (void) 175static int __init init_cdb89712_bootrom (void)
176{ 176{
177 int err; 177 int err;
178 178
179 if (request_resource (&ioport_resource, &cdb89712_bootrom_resource)) { 179 if (request_resource (&ioport_resource, &cdb89712_bootrom_resource)) {
180 printk(KERN_NOTICE "Failed to reserve Cdb89712 BOOTROM space\n"); 180 printk(KERN_NOTICE "Failed to reserve Cdb89712 BOOTROM space\n");
181 err = -EBUSY; 181 err = -EBUSY;
182 goto out; 182 goto out;
183 } 183 }
184 184
185 cdb89712_bootrom_map.virt = ioremap(BOOTROM_START, BOOTROM_SIZE); 185 cdb89712_bootrom_map.virt = ioremap(BOOTROM_START, BOOTROM_SIZE);
186 if (!cdb89712_bootrom_map.virt) { 186 if (!cdb89712_bootrom_map.virt) {
187 printk(KERN_NOTICE "Failed to ioremap Cdb89712 BootROM space\n"); 187 printk(KERN_NOTICE "Failed to ioremap Cdb89712 BootROM space\n");
@@ -198,13 +198,13 @@ static int __init init_cdb89712_bootrom (void)
198 198
199 bootrom_mtd->owner = THIS_MODULE; 199 bootrom_mtd->owner = THIS_MODULE;
200 bootrom_mtd->erasesize = 0x10000; 200 bootrom_mtd->erasesize = 0x10000;
201 201
202 if (add_mtd_device(bootrom_mtd)) { 202 if (add_mtd_device(bootrom_mtd)) {
203 printk("BootROM device addition failed\n"); 203 printk("BootROM device addition failed\n");
204 err = -ENOMEM; 204 err = -ENOMEM;
205 goto out_probe; 205 goto out_probe;
206 } 206 }
207 207
208 return 0; 208 return 0;
209 209
210out_probe: 210out_probe:
@@ -225,16 +225,16 @@ out:
225static int __init init_cdb89712_maps(void) 225static int __init init_cdb89712_maps(void)
226{ 226{
227 227
228 printk(KERN_INFO "Cirrus CDB89712 MTD mappings:\n Flash 0x%x at 0x%x\n SRAM 0x%x at 0x%x\n BootROM 0x%x at 0x%x\n", 228 printk(KERN_INFO "Cirrus CDB89712 MTD mappings:\n Flash 0x%x at 0x%x\n SRAM 0x%x at 0x%x\n BootROM 0x%x at 0x%x\n",
229 FLASH_SIZE, FLASH_START, SRAM_SIZE, SRAM_START, BOOTROM_SIZE, BOOTROM_START); 229 FLASH_SIZE, FLASH_START, SRAM_SIZE, SRAM_START, BOOTROM_SIZE, BOOTROM_START);
230 230
231 init_cdb89712_flash(); 231 init_cdb89712_flash();
232 init_cdb89712_sram(); 232 init_cdb89712_sram();
233 init_cdb89712_bootrom(); 233 init_cdb89712_bootrom();
234 234
235 return 0; 235 return 0;
236} 236}
237 237
238 238
239static void __exit cleanup_cdb89712_maps(void) 239static void __exit cleanup_cdb89712_maps(void)
240{ 240{
@@ -244,7 +244,7 @@ static void __exit cleanup_cdb89712_maps(void)
244 iounmap((void *)cdb89712_sram_map.virt); 244 iounmap((void *)cdb89712_sram_map.virt);
245 release_resource (&cdb89712_sram_resource); 245 release_resource (&cdb89712_sram_resource);
246 } 246 }
247 247
248 if (flash_mtd) { 248 if (flash_mtd) {
249 del_mtd_device(flash_mtd); 249 del_mtd_device(flash_mtd);
250 map_destroy(flash_mtd); 250 map_destroy(flash_mtd);
diff --git a/drivers/mtd/maps/ceiva.c b/drivers/mtd/maps/ceiva.c
index c68b31dc7e6d..5a95ab370a97 100644
--- a/drivers/mtd/maps/ceiva.c
+++ b/drivers/mtd/maps/ceiva.c
@@ -313,8 +313,7 @@ static void __init clps_locate_partitions(struct mtd_info *mtd)
313 313
314static void __exit clps_destroy_partitions(void) 314static void __exit clps_destroy_partitions(void)
315{ 315{
316 if (parsed_parts) 316 kfree(parsed_parts);
317 kfree(parsed_parts);
318} 317}
319 318
320static struct mtd_info *mymtd; 319static struct mtd_info *mymtd;
diff --git a/drivers/mtd/maps/cfi_flagadm.c b/drivers/mtd/maps/cfi_flagadm.c
index f72e4f894b32..6a8c0415bde8 100644
--- a/drivers/mtd/maps/cfi_flagadm.c
+++ b/drivers/mtd/maps/cfi_flagadm.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * Copyright © 2001 Flaga hf. Medical Devices, Kári Davíðsson <kd@flaga.is> 2 * Copyright © 2001 Flaga hf. Medical Devices, Kári Davíðsson <kd@flaga.is>
3 * 3 *
4 * $Id: cfi_flagadm.c,v 1.14 2004/11/04 13:24:14 gleixner Exp $ 4 * $Id: cfi_flagadm.c,v 1.15 2005/11/07 11:14:26 gleixner Exp $
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 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 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 8 * Free Software Foundation; either version 2 of the License, or (at your
@@ -42,7 +42,7 @@
42 */ 42 */
43 43
44#define FLASH_PHYS_ADDR 0x40000000 44#define FLASH_PHYS_ADDR 0x40000000
45#define FLASH_SIZE 0x400000 45#define FLASH_SIZE 0x400000
46 46
47#define FLASH_PARTITION0_ADDR 0x00000000 47#define FLASH_PARTITION0_ADDR 0x00000000
48#define FLASH_PARTITION0_SIZE 0x00020000 48#define FLASH_PARTITION0_SIZE 0x00020000
@@ -79,7 +79,7 @@ struct mtd_partition flagadm_parts[] = {
79 .offset = FLASH_PARTITION2_ADDR, 79 .offset = FLASH_PARTITION2_ADDR,
80 .size = FLASH_PARTITION2_SIZE 80 .size = FLASH_PARTITION2_SIZE
81 }, 81 },
82 { 82 {
83 .name = "Persistant storage", 83 .name = "Persistant storage",
84 .offset = FLASH_PARTITION3_ADDR, 84 .offset = FLASH_PARTITION3_ADDR,
85 .size = FLASH_PARTITION3_SIZE 85 .size = FLASH_PARTITION3_SIZE
@@ -91,10 +91,10 @@ struct mtd_partition flagadm_parts[] = {
91static struct mtd_info *mymtd; 91static struct mtd_info *mymtd;
92 92
93int __init init_flagadm(void) 93int __init init_flagadm(void)
94{ 94{
95 printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n", 95 printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n",
96 FLASH_SIZE, FLASH_PHYS_ADDR); 96 FLASH_SIZE, FLASH_PHYS_ADDR);
97 97
98 flagadm_map.phys = FLASH_PHYS_ADDR; 98 flagadm_map.phys = FLASH_PHYS_ADDR;
99 flagadm_map.virt = ioremap(FLASH_PHYS_ADDR, 99 flagadm_map.virt = ioremap(FLASH_PHYS_ADDR,
100 FLASH_SIZE); 100 FLASH_SIZE);
diff --git a/drivers/mtd/maps/cstm_mips_ixx.c b/drivers/mtd/maps/cstm_mips_ixx.c
index ae9252fbf176..a370953c1513 100644
--- a/drivers/mtd/maps/cstm_mips_ixx.c
+++ b/drivers/mtd/maps/cstm_mips_ixx.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * $Id: cstm_mips_ixx.c,v 1.12 2004/11/04 13:24:14 gleixner Exp $ 2 * $Id: cstm_mips_ixx.c,v 1.14 2005/11/07 11:14:26 gleixner Exp $
3 * 3 *
4 * Mapping of a custom board with both AMD CFI and JEDEC flash in partitions. 4 * Mapping of a custom board with both AMD CFI and JEDEC flash in partitions.
5 * Config with both CFI and JEDEC device support. 5 * Config with both CFI and JEDEC device support.
6 * 6 *
7 * Basically physmap.c with the addition of partitions and 7 * Basically physmap.c with the addition of partitions and
8 * an array of mapping info to accomodate more than one flash type per board. 8 * an array of mapping info to accomodate more than one flash type per board.
9 * 9 *
10 * Copyright 2000 MontaVista Software Inc. 10 * Copyright 2000 MontaVista Software Inc.
@@ -69,7 +69,7 @@ void cstm_mips_ixx_set_vpp(struct map_info *map,int vpp)
69 __u16 data; 69 __u16 data;
70 __u8 data1; 70 __u8 data1;
71 static u8 first = 1; 71 static u8 first = 1;
72 72
73 // Set GPIO port B pin3 to high 73 // Set GPIO port B pin3 to high
74 data = *(__u16 *)(CC_GPBCR); 74 data = *(__u16 *)(CC_GPBCR);
75 data = (data & 0xff0f) | 0x0040; 75 data = (data & 0xff0f) | 0x0040;
@@ -85,7 +85,7 @@ void cstm_mips_ixx_set_vpp(struct map_info *map,int vpp)
85 } else { 85 } else {
86 if (!--vpp_count) { 86 if (!--vpp_count) {
87 __u16 data; 87 __u16 data;
88 88
89 // Set GPIO port B pin3 to high 89 // Set GPIO port B pin3 to high
90 data = *(__u16 *)(CC_GPBCR); 90 data = *(__u16 *)(CC_GPBCR);
91 data = (data & 0xff3f) | 0x0040; 91 data = (data & 0xff3f) | 0x0040;
@@ -109,8 +109,8 @@ struct cstm_mips_ixx_info {
109}; 109};
110 110
111#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) 111#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
112#define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type 112#define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type
113const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] = 113const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] =
114{ 114{
115 { // 28F128J3A in 2x16 configuration 115 { // 28F128J3A in 2x16 configuration
116 "big flash", // name 116 "big flash", // name
@@ -131,10 +131,10 @@ static struct mtd_partition cstm_mips_ixx_partitions[PHYSMAP_NUMBER][MAX_PHYSMAP
131}, 131},
132}; 132};
133#else /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */ 133#else /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
134#define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type 134#define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type
135const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] = 135const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] =
136{ 136{
137 { 137 {
138 "MTD flash", // name 138 "MTD flash", // name
139 CONFIG_MTD_CSTM_MIPS_IXX_START, // window_addr 139 CONFIG_MTD_CSTM_MIPS_IXX_START, // window_addr
140 CONFIG_MTD_CSTM_MIPS_IXX_LEN, // window_size 140 CONFIG_MTD_CSTM_MIPS_IXX_LEN, // window_size
@@ -144,7 +144,7 @@ const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] =
144 144
145}; 145};
146static struct mtd_partition cstm_mips_ixx_partitions[PHYSMAP_NUMBER][MAX_PHYSMAP_PARTITIONS] = { 146static struct mtd_partition cstm_mips_ixx_partitions[PHYSMAP_NUMBER][MAX_PHYSMAP_PARTITIONS] = {
147{ 147{
148 { 148 {
149 .name = "main partition", 149 .name = "main partition",
150 .size = CONFIG_MTD_CSTM_MIPS_IXX_LEN, 150 .size = CONFIG_MTD_CSTM_MIPS_IXX_LEN,
@@ -165,7 +165,7 @@ int __init init_cstm_mips_ixx(void)
165 165
166 /* Initialize mapping */ 166 /* Initialize mapping */
167 for (i=0;i<PHYSMAP_NUMBER;i++) { 167 for (i=0;i<PHYSMAP_NUMBER;i++) {
168 printk(KERN_NOTICE "cstm_mips_ixx flash device: 0x%lx at 0x%lx\n", 168 printk(KERN_NOTICE "cstm_mips_ixx flash device: 0x%lx at 0x%lx\n",
169 cstm_mips_ixx_board_desc[i].window_size, cstm_mips_ixx_board_desc[i].window_addr); 169 cstm_mips_ixx_board_desc[i].window_size, cstm_mips_ixx_board_desc[i].window_addr);
170 170
171 171
@@ -235,7 +235,7 @@ void PCISetULongByOffset(__u32 DevNumber, __u32 FuncNumber, __u32 Offset, __u32
235 235
236 offset = ( unsigned long )( 0x80000000 | ( DevNumber << 11 ) + ( FuncNumber << 8 ) + Offset) ; 236 offset = ( unsigned long )( 0x80000000 | ( DevNumber << 11 ) + ( FuncNumber << 8 ) + Offset) ;
237 237
238 *(__u32 *)CC_CONFADDR = offset; 238 *(__u32 *)CC_CONFADDR = offset;
239 *(__u32 *)CC_CONFDATA = data; 239 *(__u32 *)CC_CONFDATA = data;
240} 240}
241void setup_ITE_IVR_flash() 241void setup_ITE_IVR_flash()
diff --git a/drivers/mtd/maps/dbox2-flash.c b/drivers/mtd/maps/dbox2-flash.c
index d850a27a4b59..49d90542fc75 100644
--- a/drivers/mtd/maps/dbox2-flash.c
+++ b/drivers/mtd/maps/dbox2-flash.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: dbox2-flash.c,v 1.13 2004/11/04 13:24:14 gleixner Exp $ 2 * $Id: dbox2-flash.c,v 1.14 2005/11/07 11:14:26 gleixner Exp $
3 * 3 *
4 * D-Box 2 flash driver 4 * D-Box 2 flash driver
5 */ 5 */
@@ -21,38 +21,38 @@
21static struct mtd_partition partition_info[]= { 21static struct mtd_partition partition_info[]= {
22 { 22 {
23 .name = "BR bootloader", 23 .name = "BR bootloader",
24 .size = 128 * 1024, 24 .size = 128 * 1024,
25 .offset = 0, 25 .offset = 0,
26 .mask_flags = MTD_WRITEABLE 26 .mask_flags = MTD_WRITEABLE
27 }, 27 },
28 { 28 {
29 .name = "FLFS (U-Boot)", 29 .name = "FLFS (U-Boot)",
30 .size = 128 * 1024, 30 .size = 128 * 1024,
31 .offset = MTDPART_OFS_APPEND, 31 .offset = MTDPART_OFS_APPEND,
32 .mask_flags = 0 32 .mask_flags = 0
33 }, 33 },
34 { 34 {
35 .name = "Root (SquashFS)", 35 .name = "Root (SquashFS)",
36 .size = 7040 * 1024, 36 .size = 7040 * 1024,
37 .offset = MTDPART_OFS_APPEND, 37 .offset = MTDPART_OFS_APPEND,
38 .mask_flags = 0 38 .mask_flags = 0
39 }, 39 },
40 { 40 {
41 .name = "var (JFFS2)", 41 .name = "var (JFFS2)",
42 .size = 896 * 1024, 42 .size = 896 * 1024,
43 .offset = MTDPART_OFS_APPEND, 43 .offset = MTDPART_OFS_APPEND,
44 .mask_flags = 0 44 .mask_flags = 0
45 }, 45 },
46 { 46 {
47 .name = "Flash without bootloader", 47 .name = "Flash without bootloader",
48 .size = MTDPART_SIZ_FULL, 48 .size = MTDPART_SIZ_FULL,
49 .offset = 128 * 1024, 49 .offset = 128 * 1024,
50 .mask_flags = 0 50 .mask_flags = 0
51 }, 51 },
52 { 52 {
53 .name = "Complete Flash", 53 .name = "Complete Flash",
54 .size = MTDPART_SIZ_FULL, 54 .size = MTDPART_SIZ_FULL,
55 .offset = 0, 55 .offset = 0,
56 .mask_flags = MTD_WRITEABLE 56 .mask_flags = MTD_WRITEABLE
57 } 57 }
58}; 58};
@@ -88,16 +88,16 @@ int __init init_dbox2_flash(void)
88 if (!mymtd) { 88 if (!mymtd) {
89 // Probe for single Intel 28F640 89 // Probe for single Intel 28F640
90 dbox2_flash_map.bankwidth = 2; 90 dbox2_flash_map.bankwidth = 2;
91 91
92 mymtd = do_map_probe("cfi_probe", &dbox2_flash_map); 92 mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
93 } 93 }
94 94
95 if (mymtd) { 95 if (mymtd) {
96 mymtd->owner = THIS_MODULE; 96 mymtd->owner = THIS_MODULE;
97 97
98 /* Create MTD devices for each partition. */ 98 /* Create MTD devices for each partition. */
99 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS); 99 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS);
100 100
101 return 0; 101 return 0;
102 } 102 }
103 103
diff --git a/drivers/mtd/maps/dc21285.c b/drivers/mtd/maps/dc21285.c
index e5b74169fde6..701620b6baed 100644
--- a/drivers/mtd/maps/dc21285.c
+++ b/drivers/mtd/maps/dc21285.c
@@ -4,8 +4,8 @@
4 * (C) 2000 Nicolas Pitre <nico@cam.org> 4 * (C) 2000 Nicolas Pitre <nico@cam.org>
5 * 5 *
6 * This code is GPL 6 * This code is GPL
7 * 7 *
8 * $Id: dc21285.c,v 1.22 2004/11/01 13:39:21 rmk Exp $ 8 * $Id: dc21285.c,v 1.24 2005/11/07 11:14:26 gleixner Exp $
9 */ 9 */
10#include <linux/config.h> 10#include <linux/config.h>
11#include <linux/module.h> 11#include <linux/module.h>
@@ -27,9 +27,9 @@
27static struct mtd_info *dc21285_mtd; 27static struct mtd_info *dc21285_mtd;
28 28
29#ifdef CONFIG_ARCH_NETWINDER 29#ifdef CONFIG_ARCH_NETWINDER
30/* 30/*
31 * This is really ugly, but it seams to be the only 31 * This is really ugly, but it seams to be the only
32 * realiable way to do it, as the cpld state machine 32 * realiable way to do it, as the cpld state machine
33 * is unpredictible. So we have a 25us penalty per 33 * is unpredictible. So we have a 25us penalty per
34 * write access. 34 * write access.
35 */ 35 */
@@ -150,7 +150,7 @@ static struct map_info dc21285_map = {
150static struct mtd_partition *dc21285_parts; 150static struct mtd_partition *dc21285_parts;
151static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; 151static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
152#endif 152#endif
153 153
154static int __init init_dc21285(void) 154static int __init init_dc21285(void)
155{ 155{
156 156
@@ -160,20 +160,20 @@ static int __init init_dc21285(void)
160 160
161 /* Determine bankwidth */ 161 /* Determine bankwidth */
162 switch (*CSR_SA110_CNTL & (3<<14)) { 162 switch (*CSR_SA110_CNTL & (3<<14)) {
163 case SA110_CNTL_ROMWIDTH_8: 163 case SA110_CNTL_ROMWIDTH_8:
164 dc21285_map.bankwidth = 1; 164 dc21285_map.bankwidth = 1;
165 dc21285_map.read = dc21285_read8; 165 dc21285_map.read = dc21285_read8;
166 dc21285_map.write = dc21285_write8; 166 dc21285_map.write = dc21285_write8;
167 dc21285_map.copy_to = dc21285_copy_to_8; 167 dc21285_map.copy_to = dc21285_copy_to_8;
168 break; 168 break;
169 case SA110_CNTL_ROMWIDTH_16: 169 case SA110_CNTL_ROMWIDTH_16:
170 dc21285_map.bankwidth = 2; 170 dc21285_map.bankwidth = 2;
171 dc21285_map.read = dc21285_read16; 171 dc21285_map.read = dc21285_read16;
172 dc21285_map.write = dc21285_write16; 172 dc21285_map.write = dc21285_write16;
173 dc21285_map.copy_to = dc21285_copy_to_16; 173 dc21285_map.copy_to = dc21285_copy_to_16;
174 break; 174 break;
175 case SA110_CNTL_ROMWIDTH_32: 175 case SA110_CNTL_ROMWIDTH_32:
176 dc21285_map.bankwidth = 4; 176 dc21285_map.bankwidth = 4;
177 dc21285_map.read = dc21285_read32; 177 dc21285_map.read = dc21285_read32;
178 dc21285_map.write = dc21285_write32; 178 dc21285_map.write = dc21285_write32;
179 dc21285_map.copy_to = dc21285_copy_to_32; 179 dc21285_map.copy_to = dc21285_copy_to_32;
@@ -201,20 +201,20 @@ static int __init init_dc21285(void)
201 if (!dc21285_mtd) { 201 if (!dc21285_mtd) {
202 iounmap(dc21285_map.virt); 202 iounmap(dc21285_map.virt);
203 return -ENXIO; 203 return -ENXIO;
204 } 204 }
205 205
206 dc21285_mtd->owner = THIS_MODULE; 206 dc21285_mtd->owner = THIS_MODULE;
207 207
208#ifdef CONFIG_MTD_PARTITIONS 208#ifdef CONFIG_MTD_PARTITIONS
209 nrparts = parse_mtd_partitions(dc21285_mtd, probes, &dc21285_parts, 0); 209 nrparts = parse_mtd_partitions(dc21285_mtd, probes, &dc21285_parts, 0);
210 if (nrparts > 0) 210 if (nrparts > 0)
211 add_mtd_partitions(dc21285_mtd, dc21285_parts, nrparts); 211 add_mtd_partitions(dc21285_mtd, dc21285_parts, nrparts);
212 else 212 else
213#endif 213#endif
214 add_mtd_device(dc21285_mtd); 214 add_mtd_device(dc21285_mtd);
215 215
216 if(machine_is_ebsa285()) { 216 if(machine_is_ebsa285()) {
217 /* 217 /*
218 * Flash timing is determined with bits 19-16 of the 218 * Flash timing is determined with bits 19-16 of the
219 * CSR_SA110_CNTL. The value is the number of wait cycles, or 219 * CSR_SA110_CNTL. The value is the number of wait cycles, or
220 * 0 for 16 cycles (the default). Cycles are 20 ns. 220 * 0 for 16 cycles (the default). Cycles are 20 ns.
@@ -227,7 +227,7 @@ static int __init init_dc21285(void)
227 /* tristate time */ 227 /* tristate time */
228 *CSR_SA110_CNTL = ((*CSR_SA110_CNTL & ~0x0f000000) | (7 << 24)); 228 *CSR_SA110_CNTL = ((*CSR_SA110_CNTL & ~0x0f000000) | (7 << 24));
229 } 229 }
230 230
231 return 0; 231 return 0;
232} 232}
233 233
diff --git a/drivers/mtd/maps/dilnetpc.c b/drivers/mtd/maps/dilnetpc.c
index f99519692cb7..b51c757817d8 100644
--- a/drivers/mtd/maps/dilnetpc.c
+++ b/drivers/mtd/maps/dilnetpc.c
@@ -14,7 +14,7 @@
14 * along with this program; if not, write to the Free Software 14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
16 * 16 *
17 * $Id: dilnetpc.c,v 1.17 2004/11/28 09:40:39 dwmw2 Exp $ 17 * $Id: dilnetpc.c,v 1.20 2005/11/07 11:14:26 gleixner Exp $
18 * 18 *
19 * The DIL/Net PC is a tiny embedded PC board made by SSV Embedded Systems 19 * The DIL/Net PC is a tiny embedded PC board made by SSV Embedded Systems
20 * featuring the AMD Elan SC410 processor. There are two variants of this 20 * featuring the AMD Elan SC410 processor. There are two variants of this
@@ -272,13 +272,13 @@ static struct map_info dnpc_map = {
272 272
273static struct mtd_partition partition_info[]= 273static struct mtd_partition partition_info[]=
274{ 274{
275 { 275 {
276 .name = "ADNP boot", 276 .name = "ADNP boot",
277 .offset = 0, 277 .offset = 0,
278 .size = 0xf0000, 278 .size = 0xf0000,
279 }, 279 },
280 { 280 {
281 .name = "ADNP system BIOS", 281 .name = "ADNP system BIOS",
282 .offset = MTDPART_OFS_NXTBLK, 282 .offset = MTDPART_OFS_NXTBLK,
283 .size = 0x10000, 283 .size = 0x10000,
284#ifdef DNPC_BIOS_BLOCKS_WRITEPROTECTED 284#ifdef DNPC_BIOS_BLOCKS_WRITEPROTECTED
@@ -291,7 +291,7 @@ static struct mtd_partition partition_info[]=
291 .size = 0x2f0000, 291 .size = 0x2f0000,
292 }, 292 },
293 { 293 {
294 .name = "ADNP system BIOS entry", 294 .name = "ADNP system BIOS entry",
295 .offset = MTDPART_OFS_NXTBLK, 295 .offset = MTDPART_OFS_NXTBLK,
296 .size = MTDPART_SIZ_FULL, 296 .size = MTDPART_SIZ_FULL,
297#ifdef DNPC_BIOS_BLOCKS_WRITEPROTECTED 297#ifdef DNPC_BIOS_BLOCKS_WRITEPROTECTED
@@ -325,9 +325,9 @@ static struct mtd_info *merged_mtd;
325 325
326static struct mtd_partition higlvl_partition_info[]= 326static struct mtd_partition higlvl_partition_info[]=
327{ 327{
328 { 328 {
329 .name = "ADNP boot block", 329 .name = "ADNP boot block",
330 .offset = 0, 330 .offset = 0,
331 .size = CONFIG_MTD_DILNETPC_BOOTSIZE, 331 .size = CONFIG_MTD_DILNETPC_BOOTSIZE,
332 }, 332 },
333 { 333 {
@@ -335,8 +335,8 @@ static struct mtd_partition higlvl_partition_info[]=
335 .offset = MTDPART_OFS_NXTBLK, 335 .offset = MTDPART_OFS_NXTBLK,
336 .size = ADNP_WINDOW_SIZE-CONFIG_MTD_DILNETPC_BOOTSIZE-0x20000, 336 .size = ADNP_WINDOW_SIZE-CONFIG_MTD_DILNETPC_BOOTSIZE-0x20000,
337 }, 337 },
338 { 338 {
339 .name = "ADNP system BIOS + BIOS Entry", 339 .name = "ADNP system BIOS + BIOS Entry",
340 .offset = MTDPART_OFS_NXTBLK, 340 .offset = MTDPART_OFS_NXTBLK,
341 .size = MTDPART_SIZ_FULL, 341 .size = MTDPART_SIZ_FULL,
342#ifdef DNPC_BIOS_BLOCKS_WRITEPROTECTED 342#ifdef DNPC_BIOS_BLOCKS_WRITEPROTECTED
@@ -371,7 +371,7 @@ static int __init init_dnpc(void)
371 371
372 /* 372 /*
373 ** determine hardware (DNP/ADNP/invalid) 373 ** determine hardware (DNP/ADNP/invalid)
374 */ 374 */
375 if((is_dnp = dnp_adnp_probe()) < 0) 375 if((is_dnp = dnp_adnp_probe()) < 0)
376 return -ENXIO; 376 return -ENXIO;
377 377
@@ -397,13 +397,13 @@ static int __init init_dnpc(void)
397 ++dnpc_map.name; 397 ++dnpc_map.name;
398 for(i = 0; i < NUM_PARTITIONS; i++) 398 for(i = 0; i < NUM_PARTITIONS; i++)
399 ++partition_info[i].name; 399 ++partition_info[i].name;
400 higlvl_partition_info[1].size = DNP_WINDOW_SIZE - 400 higlvl_partition_info[1].size = DNP_WINDOW_SIZE -
401 CONFIG_MTD_DILNETPC_BOOTSIZE - 0x20000; 401 CONFIG_MTD_DILNETPC_BOOTSIZE - 0x20000;
402 for(i = 0; i < NUM_HIGHLVL_PARTITIONS; i++) 402 for(i = 0; i < NUM_HIGHLVL_PARTITIONS; i++)
403 ++higlvl_partition_info[i].name; 403 ++higlvl_partition_info[i].name;
404 } 404 }
405 405
406 printk(KERN_NOTICE "DIL/Net %s flash: 0x%lx at 0x%lx\n", 406 printk(KERN_NOTICE "DIL/Net %s flash: 0x%lx at 0x%lx\n",
407 is_dnp ? "DNPC" : "ADNP", dnpc_map.size, dnpc_map.phys); 407 is_dnp ? "DNPC" : "ADNP", dnpc_map.size, dnpc_map.phys);
408 408
409 dnpc_map.virt = ioremap_nocache(dnpc_map.phys, dnpc_map.size); 409 dnpc_map.virt = ioremap_nocache(dnpc_map.phys, dnpc_map.size);
@@ -436,7 +436,7 @@ static int __init init_dnpc(void)
436 iounmap(dnpc_map.virt); 436 iounmap(dnpc_map.virt);
437 return -ENXIO; 437 return -ENXIO;
438 } 438 }
439 439
440 mymtd->owner = THIS_MODULE; 440 mymtd->owner = THIS_MODULE;
441 441
442 /* 442 /*
diff --git a/drivers/mtd/maps/dmv182.c b/drivers/mtd/maps/dmv182.c
index b9bc63503e26..b993ac01a9a5 100644
--- a/drivers/mtd/maps/dmv182.c
+++ b/drivers/mtd/maps/dmv182.c
@@ -1,10 +1,10 @@
1 1
2/* 2/*
3 * drivers/mtd/maps/svme182.c 3 * drivers/mtd/maps/svme182.c
4 * 4 *
5 * Flash map driver for the Dy4 SVME182 board 5 * Flash map driver for the Dy4 SVME182 board
6 * 6 *
7 * $Id: dmv182.c,v 1.5 2004/11/04 13:24:14 gleixner Exp $ 7 * $Id: dmv182.c,v 1.6 2005/11/07 11:14:26 gleixner Exp $
8 * 8 *
9 * Copyright 2003-2004, TimeSys Corporation 9 * Copyright 2003-2004, TimeSys Corporation
10 * 10 *
@@ -104,7 +104,7 @@ static int __init init_svme182(void)
104 partitions = svme182_partitions; 104 partitions = svme182_partitions;
105 105
106 svme182_map.virt = ioremap(FLASH_BASE_ADDR, svme182_map.size); 106 svme182_map.virt = ioremap(FLASH_BASE_ADDR, svme182_map.size);
107 107
108 if (svme182_map.virt == 0) { 108 if (svme182_map.virt == 0) {
109 printk("Failed to ioremap FLASH memory area.\n"); 109 printk("Failed to ioremap FLASH memory area.\n");
110 return -EIO; 110 return -EIO;
diff --git a/drivers/mtd/maps/ebony.c b/drivers/mtd/maps/ebony.c
index b9d9cf4854b6..c0daf58357ca 100644
--- a/drivers/mtd/maps/ebony.c
+++ b/drivers/mtd/maps/ebony.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * $Id: ebony.c,v 1.15 2004/12/09 18:39:54 holindho Exp $ 2 * $Id: ebony.c,v 1.16 2005/11/07 11:14:26 gleixner Exp $
3 * 3 *
4 * Mapping for Ebony user flash 4 * Mapping for Ebony user flash
5 * 5 *
6 * Matt Porter <mporter@kernel.crashing.org> 6 * Matt Porter <mporter@kernel.crashing.org>
@@ -85,7 +85,7 @@ int __init init_ebony(void)
85 small_flash_base = EBONY_SMALL_FLASH_LOW2; 85 small_flash_base = EBONY_SMALL_FLASH_LOW2;
86 else 86 else
87 small_flash_base = EBONY_SMALL_FLASH_LOW1; 87 small_flash_base = EBONY_SMALL_FLASH_LOW1;
88 88
89 if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) && 89 if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
90 !EBONY_ONBRD_FLASH_EN(fpga0_reg)) 90 !EBONY_ONBRD_FLASH_EN(fpga0_reg))
91 large_flash_base = EBONY_LARGE_FLASH_LOW; 91 large_flash_base = EBONY_LARGE_FLASH_LOW;
diff --git a/drivers/mtd/maps/edb7312.c b/drivers/mtd/maps/edb7312.c
index 8b0da394f3fa..b48a3473ffc1 100644
--- a/drivers/mtd/maps/edb7312.c
+++ b/drivers/mtd/maps/edb7312.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * $Id: edb7312.c,v 1.13 2004/11/04 13:24:14 gleixner Exp $ 2 * $Id: edb7312.c,v 1.14 2005/11/07 11:14:27 gleixner Exp $
3 * 3 *
4 * Handle mapping of the NOR flash on Cogent EDB7312 boards 4 * Handle mapping of the NOR flash on Cogent EDB7312 boards
5 * 5 *
6 * Copyright 2002 SYSGO Real-Time Solutions GmbH 6 * Copyright 2002 SYSGO Real-Time Solutions GmbH
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 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 9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
@@ -46,7 +46,7 @@ struct map_info edb7312nor_map = {
46#ifdef CONFIG_MTD_PARTITIONS 46#ifdef CONFIG_MTD_PARTITIONS
47 47
48/* 48/*
49 * MTD partitioning stuff 49 * MTD partitioning stuff
50 */ 50 */
51static struct mtd_partition static_partitions[3] = 51static struct mtd_partition static_partitions[3] =
52{ 52{
@@ -80,7 +80,7 @@ int __init init_edb7312nor(void)
80 const char **type; 80 const char **type;
81 const char *part_type = 0; 81 const char *part_type = 0;
82 82
83 printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n", 83 printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n",
84 WINDOW_SIZE, WINDOW_ADDR); 84 WINDOW_SIZE, WINDOW_ADDR);
85 edb7312nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE); 85 edb7312nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
86 86
@@ -88,7 +88,7 @@ int __init init_edb7312nor(void)
88 printk(MSG_PREFIX "failed to ioremap\n"); 88 printk(MSG_PREFIX "failed to ioremap\n");
89 return -EIO; 89 return -EIO;
90 } 90 }
91 91
92 simple_map_init(&edb7312nor_map); 92 simple_map_init(&edb7312nor_map);
93 93
94 mymtd = 0; 94 mymtd = 0;
diff --git a/drivers/mtd/maps/epxa10db-flash.c b/drivers/mtd/maps/epxa10db-flash.c
index 1df6188926b3..265b079fe934 100644
--- a/drivers/mtd/maps/epxa10db-flash.c
+++ b/drivers/mtd/maps/epxa10db-flash.c
@@ -5,7 +5,7 @@
5 * Copyright (C) 2001 Altera Corporation 5 * Copyright (C) 2001 Altera Corporation
6 * Copyright (C) 2001 Red Hat, Inc. 6 * Copyright (C) 2001 Red Hat, Inc.
7 * 7 *
8 * $Id: epxa10db-flash.c,v 1.13 2004/11/04 13:24:14 gleixner Exp $ 8 * $Id: epxa10db-flash.c,v 1.15 2005/11/07 11:14:27 gleixner Exp $
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 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 11 * it under the terms of the GNU General Public License as published by
@@ -62,7 +62,7 @@ static const char *probes[] = { "RedBoot", "afs", NULL };
62static int __init epxa_mtd_init(void) 62static int __init epxa_mtd_init(void)
63{ 63{
64 int i; 64 int i;
65 65
66 printk(KERN_NOTICE "%s flash device: 0x%x at 0x%x\n", BOARD_NAME, FLASH_SIZE, FLASH_START); 66 printk(KERN_NOTICE "%s flash device: 0x%x at 0x%x\n", BOARD_NAME, FLASH_SIZE, FLASH_START);
67 67
68 epxa_map.virt = ioremap(FLASH_START, FLASH_SIZE); 68 epxa_map.virt = ioremap(FLASH_START, FLASH_SIZE);
@@ -126,8 +126,8 @@ static void __exit epxa_mtd_cleanup(void)
126} 126}
127 127
128 128
129/* 129/*
130 * This will do for now, once we decide which bootldr we're finally 130 * This will do for now, once we decide which bootldr we're finally
131 * going to use then we'll remove this function and do it properly 131 * going to use then we'll remove this function and do it properly
132 * 132 *
133 * Partions are currently (as offsets from base of flash): 133 * Partions are currently (as offsets from base of flash):
@@ -140,7 +140,7 @@ static int __init epxa_default_partitions(struct mtd_info *master, struct mtd_pa
140 struct mtd_partition *parts; 140 struct mtd_partition *parts;
141 int ret, i; 141 int ret, i;
142 int npartitions = 0; 142 int npartitions = 0;
143 char *names; 143 char *names;
144 const char *name = "jffs"; 144 const char *name = "jffs";
145 145
146 printk("Using default partitions for %s\n",BOARD_NAME); 146 printk("Using default partitions for %s\n",BOARD_NAME);
@@ -152,7 +152,7 @@ static int __init epxa_default_partitions(struct mtd_info *master, struct mtd_pa
152 goto out; 152 goto out;
153 } 153 }
154 i=0; 154 i=0;
155 names = (char *)&parts[npartitions]; 155 names = (char *)&parts[npartitions];
156 parts[i].name = names; 156 parts[i].name = names;
157 names += strlen(name) + 1; 157 names += strlen(name) + 1;
158 strcpy(parts[i].name, name); 158 strcpy(parts[i].name, name);
diff --git a/drivers/mtd/maps/fortunet.c b/drivers/mtd/maps/fortunet.c
index 00f7bbe5479e..c6bf4e1219ef 100644
--- a/drivers/mtd/maps/fortunet.c
+++ b/drivers/mtd/maps/fortunet.c
@@ -1,6 +1,6 @@
1/* fortunet.c memory map 1/* fortunet.c memory map
2 * 2 *
3 * $Id: fortunet.c,v 1.9 2004/11/04 13:24:14 gleixner Exp $ 3 * $Id: fortunet.c,v 1.11 2005/11/07 11:14:27 gleixner Exp $
4 */ 4 */
5 5
6#include <linux/module.h> 6#include <linux/module.h>
@@ -212,7 +212,7 @@ int __init init_fortunet(void)
212 212
213 map_regions[ix].map_info.phys = map_regions[ix].window_addr_physical, 213 map_regions[ix].map_info.phys = map_regions[ix].window_addr_physical,
214 214
215 map_regions[ix].map_info.virt = 215 map_regions[ix].map_info.virt =
216 ioremap_nocache( 216 ioremap_nocache(
217 map_regions[ix].window_addr_physical, 217 map_regions[ix].window_addr_physical,
218 map_regions[ix].map_info.size); 218 map_regions[ix].map_info.size);
diff --git a/drivers/mtd/maps/h720x-flash.c b/drivers/mtd/maps/h720x-flash.c
index c73828171d9b..319094821101 100644
--- a/drivers/mtd/maps/h720x-flash.c
+++ b/drivers/mtd/maps/h720x-flash.c
@@ -1,11 +1,11 @@
1/* 1/*
2 * Flash memory access on Hynix GMS30C7201/HMS30C7202 based 2 * Flash memory access on Hynix GMS30C7201/HMS30C7202 based
3 * evaluation boards 3 * evaluation boards
4 * 4 *
5 * $Id: h720x-flash.c,v 1.11 2004/11/04 13:24:14 gleixner Exp $ 5 * $Id: h720x-flash.c,v 1.12 2005/11/07 11:14:27 gleixner Exp $
6 * 6 *
7 * (C) 2002 Jungjun Kim <jungjun.kim@hynix.com> 7 * (C) 2002 Jungjun Kim <jungjun.kim@hynix.com>
8 * 2003 Thomas Gleixner <tglx@linutronix.de> 8 * 2003 Thomas Gleixner <tglx@linutronix.de>
9 */ 9 */
10 10
11#include <linux/config.h> 11#include <linux/config.h>
@@ -72,7 +72,7 @@ int __init h720x_mtd_init(void)
72{ 72{
73 73
74 char *part_type = NULL; 74 char *part_type = NULL;
75 75
76 h720x_map.virt = ioremap(FLASH_PHYS, FLASH_SIZE); 76 h720x_map.virt = ioremap(FLASH_PHYS, FLASH_SIZE);
77 77
78 if (!h720x_map.virt) { 78 if (!h720x_map.virt) {
@@ -91,7 +91,7 @@ int __init h720x_mtd_init(void)
91 h720x_map.bankwidth = 2; 91 h720x_map.bankwidth = 2;
92 mymtd = do_map_probe("cfi_probe", &h720x_map); 92 mymtd = do_map_probe("cfi_probe", &h720x_map);
93 } 93 }
94 94
95 if (mymtd) { 95 if (mymtd) {
96 mymtd->owner = THIS_MODULE; 96 mymtd->owner = THIS_MODULE;
97 97
@@ -124,11 +124,11 @@ static void __exit h720x_mtd_cleanup(void)
124 del_mtd_partitions(mymtd); 124 del_mtd_partitions(mymtd);
125 map_destroy(mymtd); 125 map_destroy(mymtd);
126 } 126 }
127 127
128 /* Free partition info, if commandline partition was used */ 128 /* Free partition info, if commandline partition was used */
129 if (mtd_parts && (mtd_parts != h720x_partitions)) 129 if (mtd_parts && (mtd_parts != h720x_partitions))
130 kfree (mtd_parts); 130 kfree (mtd_parts);
131 131
132 if (h720x_map.virt) { 132 if (h720x_map.virt) {
133 iounmap((void *)h720x_map.virt); 133 iounmap((void *)h720x_map.virt);
134 h720x_map.virt = 0; 134 h720x_map.virt = 0;
diff --git a/drivers/mtd/maps/ichxrom.c b/drivers/mtd/maps/ichxrom.c
index e505207cd489..ea5073781b3a 100644
--- a/drivers/mtd/maps/ichxrom.c
+++ b/drivers/mtd/maps/ichxrom.c
@@ -2,7 +2,7 @@
2 * ichxrom.c 2 * ichxrom.c
3 * 3 *
4 * Normal mappings of chips in physical memory 4 * Normal mappings of chips in physical memory
5 * $Id: ichxrom.c,v 1.18 2005/07/07 10:26:20 dwmw2 Exp $ 5 * $Id: ichxrom.c,v 1.19 2005/11/07 11:14:27 gleixner Exp $
6 */ 6 */
7 7
8#include <linux/module.h> 8#include <linux/module.h>
@@ -101,7 +101,7 @@ static int __devinit ichxrom_init_one (struct pci_dev *pdev,
101 * you can only really attach a FWH to an ICHX there 101 * you can only really attach a FWH to an ICHX there
102 * a number of simplifications you can make. 102 * a number of simplifications you can make.
103 * 103 *
104 * Also you can page firmware hubs if an 8MB window isn't enough 104 * Also you can page firmware hubs if an 8MB window isn't enough
105 * but don't currently handle that case either. 105 * but don't currently handle that case either.
106 */ 106 */
107 window->pdev = pdev; 107 window->pdev = pdev;
@@ -144,7 +144,7 @@ static int __devinit ichxrom_init_one (struct pci_dev *pdev,
144 window->phys = 0xfff00000; 144 window->phys = 0xfff00000;
145 } 145 }
146 else if ((byte & 0x80) == 0x80) { 146 else if ((byte & 0x80) == 0x80) {
147 window->phys = 0xfff80000; 147 window->phys = 0xfff80000;
148 } 148 }
149 149
150 if (window->phys == 0) { 150 if (window->phys == 0) {
@@ -233,7 +233,7 @@ static int __devinit ichxrom_init_one (struct pci_dev *pdev,
233 * in a factory setting. So in-place programming 233 * in a factory setting. So in-place programming
234 * needs to use a different method. 234 * needs to use a different method.
235 */ 235 */
236 for(map->map.bankwidth = 32; map->map.bankwidth; 236 for(map->map.bankwidth = 32; map->map.bankwidth;
237 map->map.bankwidth >>= 1) 237 map->map.bankwidth >>= 1)
238 { 238 {
239 char **probe_type; 239 char **probe_type;
@@ -286,7 +286,7 @@ static int __devinit ichxrom_init_one (struct pci_dev *pdev,
286 for(i = 0; i < cfi->numchips; i++) { 286 for(i = 0; i < cfi->numchips; i++) {
287 cfi->chips[i].start += offset; 287 cfi->chips[i].start += offset;
288 } 288 }
289 289
290 /* Now that the mtd devices is complete claim and export it */ 290 /* Now that the mtd devices is complete claim and export it */
291 map->mtd->owner = THIS_MODULE; 291 map->mtd->owner = THIS_MODULE;
292 if (add_mtd_device(map->mtd)) { 292 if (add_mtd_device(map->mtd)) {
@@ -306,9 +306,8 @@ static int __devinit ichxrom_init_one (struct pci_dev *pdev,
306 306
307 out: 307 out:
308 /* Free any left over map structures */ 308 /* Free any left over map structures */
309 if (map) { 309 kfree(map);
310 kfree(map); 310
311 }
312 /* See if I have any map structures */ 311 /* See if I have any map structures */
313 if (list_empty(&window->maps)) { 312 if (list_empty(&window->maps)) {
314 ichxrom_cleanup(window); 313 ichxrom_cleanup(window);
@@ -325,11 +324,11 @@ static void __devexit ichxrom_remove_one (struct pci_dev *pdev)
325} 324}
326 325
327static struct pci_device_id ichxrom_pci_tbl[] __devinitdata = { 326static struct pci_device_id ichxrom_pci_tbl[] __devinitdata = {
328 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, 327 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0,
329 PCI_ANY_ID, PCI_ANY_ID, }, 328 PCI_ANY_ID, PCI_ANY_ID, },
330 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, 329 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0,
331 PCI_ANY_ID, PCI_ANY_ID, }, 330 PCI_ANY_ID, PCI_ANY_ID, },
332 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, 331 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0,
333 PCI_ANY_ID, PCI_ANY_ID, }, 332 PCI_ANY_ID, PCI_ANY_ID, },
334 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, 333 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,
335 PCI_ANY_ID, PCI_ANY_ID, }, 334 PCI_ANY_ID, PCI_ANY_ID, },
diff --git a/drivers/mtd/maps/impa7.c b/drivers/mtd/maps/impa7.c
index cb39172c81d2..ba7f40311a7e 100644
--- a/drivers/mtd/maps/impa7.c
+++ b/drivers/mtd/maps/impa7.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * $Id: impa7.c,v 1.13 2004/11/04 13:24:14 gleixner Exp $ 2 * $Id: impa7.c,v 1.14 2005/11/07 11:14:27 gleixner Exp $
3 * 3 *
4 * Handle mapping of the NOR flash on implementa A7 boards 4 * Handle mapping of the NOR flash on implementa A7 boards
5 * 5 *
6 * Copyright 2002 SYSGO Real-Time Solutions GmbH 6 * Copyright 2002 SYSGO Real-Time Solutions GmbH
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 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 9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
@@ -55,7 +55,7 @@ static struct map_info impa7_map[NUM_FLASHBANKS] = {
55#ifdef CONFIG_MTD_PARTITIONS 55#ifdef CONFIG_MTD_PARTITIONS
56 56
57/* 57/*
58 * MTD partitioning stuff 58 * MTD partitioning stuff
59 */ 59 */
60static struct mtd_partition static_partitions[] = 60static struct mtd_partition static_partitions[] =
61{ 61{
@@ -108,9 +108,9 @@ int __init init_impa7(void)
108 impa7_mtd[i]->owner = THIS_MODULE; 108 impa7_mtd[i]->owner = THIS_MODULE;
109 devicesfound++; 109 devicesfound++;
110#ifdef CONFIG_MTD_PARTITIONS 110#ifdef CONFIG_MTD_PARTITIONS
111 mtd_parts_nb[i] = parse_mtd_partitions(impa7_mtd[i], 111 mtd_parts_nb[i] = parse_mtd_partitions(impa7_mtd[i],
112 probes, 112 probes,
113 &mtd_parts[i], 113 &mtd_parts[i],
114 0); 114 0);
115 if (mtd_parts_nb[i] > 0) { 115 if (mtd_parts_nb[i] > 0) {
116 part_type = "command line"; 116 part_type = "command line";
@@ -121,16 +121,16 @@ int __init init_impa7(void)
121 } 121 }
122 122
123 printk(KERN_NOTICE MSG_PREFIX 123 printk(KERN_NOTICE MSG_PREFIX
124 "using %s partition definition\n", 124 "using %s partition definition\n",
125 part_type); 125 part_type);
126 add_mtd_partitions(impa7_mtd[i], 126 add_mtd_partitions(impa7_mtd[i],
127 mtd_parts[i], mtd_parts_nb[i]); 127 mtd_parts[i], mtd_parts_nb[i]);
128#else 128#else
129 add_mtd_device(impa7_mtd[i]); 129 add_mtd_device(impa7_mtd[i]);
130 130
131#endif 131#endif
132 } 132 }
133 else 133 else
134 iounmap((void *)impa7_map[i].virt); 134 iounmap((void *)impa7_map[i].virt);
135 } 135 }
136 return devicesfound == 0 ? -ENXIO : 0; 136 return devicesfound == 0 ? -ENXIO : 0;
diff --git a/drivers/mtd/maps/integrator-flash.c b/drivers/mtd/maps/integrator-flash.c
index d14a0185b8f4..fe738fd8d6f8 100644
--- a/drivers/mtd/maps/integrator-flash.c
+++ b/drivers/mtd/maps/integrator-flash.c
@@ -1,28 +1,28 @@
1/*====================================================================== 1/*======================================================================
2 2
3 drivers/mtd/maps/integrator-flash.c: ARM Integrator flash map driver 3 drivers/mtd/maps/integrator-flash.c: ARM Integrator flash map driver
4 4
5 Copyright (C) 2000 ARM Limited 5 Copyright (C) 2000 ARM Limited
6 Copyright (C) 2003 Deep Blue Solutions Ltd. 6 Copyright (C) 2003 Deep Blue Solutions Ltd.
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 (at your option) any later version.
12 12
13 This program is distributed in the hope that it will be useful, 13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 21
22 This is access code for flashes using ARM's flash partitioning 22 This is access code for flashes using ARM's flash partitioning
23 standards. 23 standards.
24 24
25 $Id: integrator-flash.c,v 1.18 2004/11/01 13:26:15 rmk Exp $ 25 $Id: integrator-flash.c,v 1.20 2005/11/07 11:14:27 gleixner Exp $
26 26
27======================================================================*/ 27======================================================================*/
28 28
@@ -148,8 +148,7 @@ static int armflash_probe(struct device *_dev)
148 del_mtd_partitions(info->mtd); 148 del_mtd_partitions(info->mtd);
149 map_destroy(info->mtd); 149 map_destroy(info->mtd);
150 } 150 }
151 if (info->parts) 151 kfree(info->parts);
152 kfree(info->parts);
153 152
154 no_device: 153 no_device:
155 iounmap(base); 154 iounmap(base);
@@ -176,8 +175,7 @@ static int armflash_remove(struct device *_dev)
176 del_mtd_partitions(info->mtd); 175 del_mtd_partitions(info->mtd);
177 map_destroy(info->mtd); 176 map_destroy(info->mtd);
178 } 177 }
179 if (info->parts) 178 kfree(info->parts);
180 kfree(info->parts);
181 179
182 iounmap(info->map.virt); 180 iounmap(info->map.virt);
183 release_resource(info->res); 181 release_resource(info->res);
diff --git a/drivers/mtd/maps/ipaq-flash.c b/drivers/mtd/maps/ipaq-flash.c
index 712401810841..35097c9bbf50 100644
--- a/drivers/mtd/maps/ipaq-flash.c
+++ b/drivers/mtd/maps/ipaq-flash.c
@@ -1,11 +1,11 @@
1/* 1/*
2 * Flash memory access on iPAQ Handhelds (either SA1100 or PXA250 based) 2 * Flash memory access on iPAQ Handhelds (either SA1100 or PXA250 based)
3 * 3 *
4 * (C) 2000 Nicolas Pitre <nico@cam.org> 4 * (C) 2000 Nicolas Pitre <nico@cam.org>
5 * (C) 2002 Hewlett-Packard Company <jamey.hicks@hp.com> 5 * (C) 2002 Hewlett-Packard Company <jamey.hicks@hp.com>
6 * (C) 2003 Christian Pellegrin <chri@ascensit.com>, <chri@infis.univ.ts.it>: concatenation of multiple flashes 6 * (C) 2003 Christian Pellegrin <chri@ascensit.com>, <chri@infis.univ.ts.it>: concatenation of multiple flashes
7 * 7 *
8 * $Id: ipaq-flash.c,v 1.3 2004/11/04 13:24:15 gleixner Exp $ 8 * $Id: ipaq-flash.c,v 1.5 2005/11/07 11:14:27 gleixner Exp $
9 */ 9 */
10 10
11#include <linux/config.h> 11#include <linux/config.h>
@@ -107,7 +107,7 @@ static struct mtd_partition h3xxx_partitions[] = {
107#ifndef CONFIG_LAB 107#ifndef CONFIG_LAB
108 mask_flags: MTD_WRITEABLE, /* force read-only */ 108 mask_flags: MTD_WRITEABLE, /* force read-only */
109#endif 109#endif
110 }, 110 },
111 { 111 {
112 name: "H3XXX root jffs2", 112 name: "H3XXX root jffs2",
113#ifndef CONFIG_LAB 113#ifndef CONFIG_LAB
@@ -148,7 +148,7 @@ static DEFINE_SPINLOCK(ipaq_vpp_lock);
148static void h3xxx_set_vpp(struct map_info *map, int vpp) 148static void h3xxx_set_vpp(struct map_info *map, int vpp)
149{ 149{
150 static int nest = 0; 150 static int nest = 0;
151 151
152 spin_lock(&ipaq_vpp_lock); 152 spin_lock(&ipaq_vpp_lock);
153 if (vpp) 153 if (vpp)
154 nest++; 154 nest++;
@@ -191,7 +191,7 @@ static unsigned long cs_phys[] = {
191 SA1100_CS3_PHYS, 191 SA1100_CS3_PHYS,
192 SA1100_CS4_PHYS, 192 SA1100_CS4_PHYS,
193 SA1100_CS5_PHYS, 193 SA1100_CS5_PHYS,
194#else 194#else
195 PXA_CS0_PHYS, 195 PXA_CS0_PHYS,
196 PXA_CS1_PHYS, 196 PXA_CS1_PHYS,
197 PXA_CS2_PHYS, 197 PXA_CS2_PHYS,
@@ -216,7 +216,7 @@ int __init ipaq_mtd_init(void)
216 216
217 /* Default flash bankwidth */ 217 /* Default flash bankwidth */
218 // ipaq_map.bankwidth = (MSC0 & MSC_RBW) ? 2 : 4; 218 // ipaq_map.bankwidth = (MSC0 & MSC_RBW) ? 2 : 4;
219 219
220 if (machine_is_h1900()) 220 if (machine_is_h1900())
221 { 221 {
222 /* For our intents, the h1900 is not a real iPAQ, so we special-case it. */ 222 /* For our intents, the h1900 is not a real iPAQ, so we special-case it. */
@@ -229,7 +229,7 @@ int __init ipaq_mtd_init(void)
229 else 229 else
230 for(i=0; i<MAX_IPAQ_CS; i++) 230 for(i=0; i<MAX_IPAQ_CS; i++)
231 ipaq_map[i].bankwidth = 4; 231 ipaq_map[i].bankwidth = 4;
232 232
233 /* 233 /*
234 * Static partition definition selection 234 * Static partition definition selection
235 */ 235 */
@@ -309,7 +309,7 @@ int __init ipaq_mtd_init(void)
309 return -ENXIO; 309 return -ENXIO;
310 } else 310 } else
311 printk(KERN_NOTICE "iPAQ flash: found %d bytes\n", my_sub_mtd[i]->size); 311 printk(KERN_NOTICE "iPAQ flash: found %d bytes\n", my_sub_mtd[i]->size);
312 312
313 /* do we really need this debugging? --joshua 20030703 */ 313 /* do we really need this debugging? --joshua 20030703 */
314 // printk("my_sub_mtd[%d]=%p\n", i, my_sub_mtd[i]); 314 // printk("my_sub_mtd[%d]=%p\n", i, my_sub_mtd[i]);
315 my_sub_mtd[i]->owner = THIS_MODULE; 315 my_sub_mtd[i]->owner = THIS_MODULE;
@@ -333,11 +333,11 @@ int __init ipaq_mtd_init(void)
333#else 333#else
334 mymtd = my_sub_mtd[0]; 334 mymtd = my_sub_mtd[0];
335 335
336 /* 336 /*
337 *In the very near future, command line partition parsing 337 *In the very near future, command line partition parsing
338 * will use the device name as 'mtd-id' instead of a value 338 * will use the device name as 'mtd-id' instead of a value
339 * passed to the parse_cmdline_partitions() routine. Since 339 * passed to the parse_cmdline_partitions() routine. Since
340 * the bootldr says 'ipaq', make sure it continues to work. 340 * the bootldr says 'ipaq', make sure it continues to work.
341 */ 341 */
342 mymtd->name = "ipaq"; 342 mymtd->name = "ipaq";
343 343
@@ -385,7 +385,7 @@ int __init ipaq_mtd_init(void)
385 */ 385 */
386 386
387 i = parse_mtd_partitions(mymtd, part_probes, &parsed_parts, 0); 387 i = parse_mtd_partitions(mymtd, part_probes, &parsed_parts, 0);
388 388
389 if (i > 0) { 389 if (i > 0) {
390 nb_parts = parsed_nr_parts = i; 390 nb_parts = parsed_nr_parts = i;
391 parts = parsed_parts; 391 parts = parsed_parts;
@@ -423,16 +423,15 @@ static void __exit ipaq_mtd_cleanup(void)
423#endif 423#endif
424 map_destroy(mymtd); 424 map_destroy(mymtd);
425#ifdef CONFIG_MTD_CONCAT 425#ifdef CONFIG_MTD_CONCAT
426 for(i=0; i<MAX_IPAQ_CS; i++) 426 for(i=0; i<MAX_IPAQ_CS; i++)
427#else 427#else
428 for(i=1; i<MAX_IPAQ_CS; i++) 428 for(i=1; i<MAX_IPAQ_CS; i++)
429#endif 429#endif
430 { 430 {
431 if (my_sub_mtd[i]) 431 if (my_sub_mtd[i])
432 map_destroy(my_sub_mtd[i]); 432 map_destroy(my_sub_mtd[i]);
433 } 433 }
434 if (parsed_parts) 434 kfree(parsed_parts);
435 kfree(parsed_parts);
436 } 435 }
437} 436}
438 437
@@ -445,14 +444,14 @@ static int __init h1900_special_case(void)
445 ipaq_map[0].phys = 0x0; 444 ipaq_map[0].phys = 0x0;
446 ipaq_map[0].virt = __ioremap(0x0, 0x04000000, 0, 1); 445 ipaq_map[0].virt = __ioremap(0x0, 0x04000000, 0, 1);
447 ipaq_map[0].bankwidth = 2; 446 ipaq_map[0].bankwidth = 2;
448 447
449 printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map[0].bankwidth*8, ipaq_map[0].virt); 448 printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map[0].bankwidth*8, ipaq_map[0].virt);
450 mymtd = do_map_probe("jedec_probe", &ipaq_map[0]); 449 mymtd = do_map_probe("jedec_probe", &ipaq_map[0]);
451 if (!mymtd) 450 if (!mymtd)
452 return -ENODEV; 451 return -ENODEV;
453 add_mtd_device(mymtd); 452 add_mtd_device(mymtd);
454 printk(KERN_NOTICE "iPAQ flash: registered h1910 flash\n"); 453 printk(KERN_NOTICE "iPAQ flash: registered h1910 flash\n");
455 454
456 return 0; 455 return 0;
457} 456}
458 457
diff --git a/drivers/mtd/maps/iq80310.c b/drivers/mtd/maps/iq80310.c
index 558d014e7acc..62d9e87d84e2 100644
--- a/drivers/mtd/maps/iq80310.c
+++ b/drivers/mtd/maps/iq80310.c
@@ -1,11 +1,11 @@
1/* 1/*
2 * $Id: iq80310.c,v 1.20 2004/11/04 13:24:15 gleixner Exp $ 2 * $Id: iq80310.c,v 1.21 2005/11/07 11:14:27 gleixner Exp $
3 * 3 *
4 * Mapping for the Intel XScale IQ80310 evaluation board 4 * Mapping for the Intel XScale IQ80310 evaluation board
5 * 5 *
6 * Author: Nicolas Pitre 6 * Author: Nicolas Pitre
7 * Copyright: (C) 2001 MontaVista Software Inc. 7 * Copyright: (C) 2001 MontaVista Software Inc.
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as 10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -103,8 +103,7 @@ static void __exit cleanup_iq80310(void)
103 if (mymtd) { 103 if (mymtd) {
104 del_mtd_partitions(mymtd); 104 del_mtd_partitions(mymtd);
105 map_destroy(mymtd); 105 map_destroy(mymtd);
106 if (parsed_parts) 106 kfree(parsed_parts);
107 kfree(parsed_parts);
108 } 107 }
109 if (iq80310_map.virt) 108 if (iq80310_map.virt)
110 iounmap((void *)iq80310_map.virt); 109 iounmap((void *)iq80310_map.virt);
diff --git a/drivers/mtd/maps/ixp2000.c b/drivers/mtd/maps/ixp2000.c
index 00b9f67580f1..641eb2b55e9f 100644
--- a/drivers/mtd/maps/ixp2000.c
+++ b/drivers/mtd/maps/ixp2000.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ixp2000.c,v 1.6 2005/03/18 14:07:46 gleixner Exp $ 2 * $Id: ixp2000.c,v 1.9 2005/11/07 11:14:27 gleixner Exp $
3 * 3 *
4 * drivers/mtd/maps/ixp2000.c 4 * drivers/mtd/maps/ixp2000.c
5 * 5 *
@@ -14,7 +14,7 @@
14 * This program is free software; you can redistribute it and/or modify 14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as 15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation. 16 * published by the Free Software Foundation.
17 * 17 *
18 */ 18 */
19 19
20#include <linux/module.h> 20#include <linux/module.h>
@@ -46,8 +46,8 @@ struct ixp2000_flash_info {
46}; 46};
47 47
48static inline unsigned long flash_bank_setup(struct map_info *map, unsigned long ofs) 48static inline unsigned long flash_bank_setup(struct map_info *map, unsigned long ofs)
49{ 49{
50 unsigned long (*set_bank)(unsigned long) = 50 unsigned long (*set_bank)(unsigned long) =
51 (unsigned long(*)(unsigned long))map->map_priv_2; 51 (unsigned long(*)(unsigned long))map->map_priv_2;
52 52
53 return (set_bank ? set_bank(ofs) : ofs); 53 return (set_bank ? set_bank(ofs) : ofs);
@@ -55,8 +55,8 @@ static inline unsigned long flash_bank_setup(struct map_info *map, unsigned long
55 55
56#ifdef __ARMEB__ 56#ifdef __ARMEB__
57/* 57/*
58 * Rev A0 and A1 of IXP2400 silicon have a broken addressing unit which 58 * Rev A0 and A1 of IXP2400 silicon have a broken addressing unit which
59 * causes the lower address bits to be XORed with 0x11 on 8 bit accesses 59 * causes the lower address bits to be XORed with 0x11 on 8 bit accesses
60 * and XORed with 0x10 on 16 bit accesses. See the spec update, erratum 44. 60 * and XORed with 0x10 on 16 bit accesses. See the spec update, erratum 44.
61 */ 61 */
62static int erratum44_workaround = 0; 62static int erratum44_workaround = 0;
@@ -90,7 +90,7 @@ static void ixp2000_flash_copy_from(struct map_info *map, void *to,
90 unsigned long from, ssize_t len) 90 unsigned long from, ssize_t len)
91{ 91{
92 from = flash_bank_setup(map, from); 92 from = flash_bank_setup(map, from);
93 while(len--) 93 while(len--)
94 *(__u8 *) to++ = *(__u8 *)(map->map_priv_1 + from++); 94 *(__u8 *) to++ = *(__u8 *)(map->map_priv_1 + from++);
95} 95}
96 96
@@ -129,8 +129,7 @@ static int ixp2000_flash_remove(struct device *_dev)
129 if (info->map.map_priv_1) 129 if (info->map.map_priv_1)
130 iounmap((void *) info->map.map_priv_1); 130 iounmap((void *) info->map.map_priv_1);
131 131
132 if (info->partitions) { 132 kfree(info->partitions);
133 kfree(info->partitions); }
134 133
135 if (info->res) { 134 if (info->res) {
136 release_resource(info->res); 135 release_resource(info->res);
@@ -149,11 +148,11 @@ static int ixp2000_flash_probe(struct device *_dev)
149 static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; 148 static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
150 struct platform_device *dev = to_platform_device(_dev); 149 struct platform_device *dev = to_platform_device(_dev);
151 struct ixp2000_flash_data *ixp_data = dev->dev.platform_data; 150 struct ixp2000_flash_data *ixp_data = dev->dev.platform_data;
152 struct flash_platform_data *plat; 151 struct flash_platform_data *plat;
153 struct ixp2000_flash_info *info; 152 struct ixp2000_flash_info *info;
154 unsigned long window_size; 153 unsigned long window_size;
155 int err = -1; 154 int err = -1;
156 155
157 if (!ixp_data) 156 if (!ixp_data)
158 return -ENODEV; 157 return -ENODEV;
159 158
@@ -162,7 +161,7 @@ static int ixp2000_flash_probe(struct device *_dev)
162 return -ENODEV; 161 return -ENODEV;
163 162
164 window_size = dev->resource->end - dev->resource->start + 1; 163 window_size = dev->resource->end - dev->resource->start + 1;
165 dev_info(_dev, "Probe of IXP2000 flash(%d banks x %dMiB)\n", 164 dev_info(_dev, "Probe of IXP2000 flash(%d banks x %dMiB)\n",
166 ixp_data->nr_banks, ((u32)window_size >> 20)); 165 ixp_data->nr_banks, ((u32)window_size >> 20));
167 166
168 if (plat->width != 1) { 167 if (plat->width != 1) {
@@ -175,7 +174,7 @@ static int ixp2000_flash_probe(struct device *_dev)
175 if(!info) { 174 if(!info) {
176 err = -ENOMEM; 175 err = -ENOMEM;
177 goto Error; 176 goto Error;
178 } 177 }
179 memzero(info, sizeof(struct ixp2000_flash_info)); 178 memzero(info, sizeof(struct ixp2000_flash_info));
180 179
181 dev_set_drvdata(&dev->dev, info); 180 dev_set_drvdata(&dev->dev, info);
@@ -185,7 +184,7 @@ static int ixp2000_flash_probe(struct device *_dev)
185 * not attempt to do a direct access on us. 184 * not attempt to do a direct access on us.
186 */ 185 */
187 info->map.phys = NO_XIP; 186 info->map.phys = NO_XIP;
188 187
189 info->nr_banks = ixp_data->nr_banks; 188 info->nr_banks = ixp_data->nr_banks;
190 info->map.size = ixp_data->nr_banks * window_size; 189 info->map.size = ixp_data->nr_banks * window_size;
191 info->map.bankwidth = 1; 190 info->map.bankwidth = 1;
@@ -193,7 +192,7 @@ static int ixp2000_flash_probe(struct device *_dev)
193 /* 192 /*
194 * map_priv_2 is used to store a ptr to to the bank_setup routine 193 * map_priv_2 is used to store a ptr to to the bank_setup routine
195 */ 194 */
196 info->map.map_priv_2 = (void __iomem *) ixp_data->bank_setup; 195 info->map.map_priv_2 = (unsigned long) ixp_data->bank_setup;
197 196
198 info->map.name = dev->dev.bus_id; 197 info->map.name = dev->dev.bus_id;
199 info->map.read = ixp2000_flash_read8; 198 info->map.read = ixp2000_flash_read8;
@@ -201,8 +200,8 @@ static int ixp2000_flash_probe(struct device *_dev)
201 info->map.copy_from = ixp2000_flash_copy_from; 200 info->map.copy_from = ixp2000_flash_copy_from;
202 info->map.copy_to = ixp2000_flash_copy_to; 201 info->map.copy_to = ixp2000_flash_copy_to;
203 202
204 info->res = request_mem_region(dev->resource->start, 203 info->res = request_mem_region(dev->resource->start,
205 dev->resource->end - dev->resource->start + 1, 204 dev->resource->end - dev->resource->start + 1,
206 dev->dev.bus_id); 205 dev->dev.bus_id);
207 if (!info->res) { 206 if (!info->res) {
208 dev_err(_dev, "Could not reserve memory region\n"); 207 dev_err(_dev, "Could not reserve memory region\n");
@@ -210,7 +209,7 @@ static int ixp2000_flash_probe(struct device *_dev)
210 goto Error; 209 goto Error;
211 } 210 }
212 211
213 info->map.map_priv_1 = ioremap(dev->resource->start, 212 info->map.map_priv_1 = (unsigned long) ioremap(dev->resource->start,
214 dev->resource->end - dev->resource->start + 1); 213 dev->resource->end - dev->resource->start + 1);
215 if (!info->map.map_priv_1) { 214 if (!info->map.map_priv_1) {
216 dev_err(_dev, "Failed to ioremap flash region\n"); 215 dev_err(_dev, "Failed to ioremap flash region\n");
diff --git a/drivers/mtd/maps/ixp4xx.c b/drivers/mtd/maps/ixp4xx.c
index 733a9297a562..56b3a355bf7b 100644
--- a/drivers/mtd/maps/ixp4xx.c
+++ b/drivers/mtd/maps/ixp4xx.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ixp4xx.c,v 1.7 2004/11/04 13:24:15 gleixner Exp $ 2 * $Id: ixp4xx.c,v 1.12 2005/11/07 11:14:27 gleixner Exp $
3 * 3 *
4 * drivers/mtd/maps/ixp4xx.c 4 * drivers/mtd/maps/ixp4xx.c
5 * 5 *
@@ -45,7 +45,7 @@
45static map_word ixp4xx_read16(struct map_info *map, unsigned long ofs) 45static map_word ixp4xx_read16(struct map_info *map, unsigned long ofs)
46{ 46{
47 map_word val; 47 map_word val;
48 val.x[0] = *(__u16 *) (map->map_priv_1 + ofs); 48 val.x[0] = le16_to_cpu(readw(map->virt + ofs));
49 return val; 49 return val;
50} 50}
51 51
@@ -59,35 +59,35 @@ static void ixp4xx_copy_from(struct map_info *map, void *to,
59{ 59{
60 int i; 60 int i;
61 u8 *dest = (u8 *) to; 61 u8 *dest = (u8 *) to;
62 u16 *src = (u16 *) (map->map_priv_1 + from); 62 void __iomem *src = map->virt + from;
63 u16 data; 63 u16 data;
64 64
65 for (i = 0; i < (len / 2); i++) { 65 for (i = 0; i < (len / 2); i++) {
66 data = src[i]; 66 data = le16_to_cpu(readw(src + 2*i));
67 dest[i * 2] = BYTE0(data); 67 dest[i * 2] = BYTE0(data);
68 dest[i * 2 + 1] = BYTE1(data); 68 dest[i * 2 + 1] = BYTE1(data);
69 } 69 }
70 70
71 if (len & 1) 71 if (len & 1)
72 dest[len - 1] = BYTE0(src[i]); 72 dest[len - 1] = BYTE0(le16_to_cpu(readw(src + 2*i)));
73} 73}
74 74
75/* 75/*
76 * Unaligned writes are ignored, causing the 8-bit 76 * Unaligned writes are ignored, causing the 8-bit
77 * probe to fail and proceed to the 16-bit probe (which succeeds). 77 * probe to fail and proceed to the 16-bit probe (which succeeds).
78 */ 78 */
79static void ixp4xx_probe_write16(struct map_info *map, map_word d, unsigned long adr) 79static void ixp4xx_probe_write16(struct map_info *map, map_word d, unsigned long adr)
80{ 80{
81 if (!(adr & 1)) 81 if (!(adr & 1))
82 *(__u16 *) (map->map_priv_1 + adr) = d.x[0]; 82 writew(cpu_to_le16(d.x[0]), map->virt + adr);
83} 83}
84 84
85/* 85/*
86 * Fast write16 function without the probing check above 86 * Fast write16 function without the probing check above
87 */ 87 */
88static void ixp4xx_write16(struct map_info *map, map_word d, unsigned long adr) 88static void ixp4xx_write16(struct map_info *map, map_word d, unsigned long adr)
89{ 89{
90 *(__u16 *) (map->map_priv_1 + adr) = d.x[0]; 90 writew(cpu_to_le16(d.x[0]), map->virt + adr);
91} 91}
92 92
93struct ixp4xx_flash_info { 93struct ixp4xx_flash_info {
@@ -104,28 +104,20 @@ static int ixp4xx_flash_remove(struct device *_dev)
104 struct platform_device *dev = to_platform_device(_dev); 104 struct platform_device *dev = to_platform_device(_dev);
105 struct flash_platform_data *plat = dev->dev.platform_data; 105 struct flash_platform_data *plat = dev->dev.platform_data;
106 struct ixp4xx_flash_info *info = dev_get_drvdata(&dev->dev); 106 struct ixp4xx_flash_info *info = dev_get_drvdata(&dev->dev);
107 map_word d;
108 107
109 dev_set_drvdata(&dev->dev, NULL); 108 dev_set_drvdata(&dev->dev, NULL);
110 109
111 if(!info) 110 if(!info)
112 return 0; 111 return 0;
113 112
114 /*
115 * This is required for a soft reboot to work.
116 */
117 d.x[0] = 0xff;
118 ixp4xx_write16(&info->map, d, 0x55 * 0x2);
119
120 if (info->mtd) { 113 if (info->mtd) {
121 del_mtd_partitions(info->mtd); 114 del_mtd_partitions(info->mtd);
122 map_destroy(info->mtd); 115 map_destroy(info->mtd);
123 } 116 }
124 if (info->map.map_priv_1) 117 if (info->map.virt)
125 iounmap((void *) info->map.map_priv_1); 118 iounmap(info->map.virt);
126 119
127 if (info->partitions) 120 kfree(info->partitions);
128 kfree(info->partitions);
129 121
130 if (info->res) { 122 if (info->res) {
131 release_resource(info->res); 123 release_resource(info->res);
@@ -135,9 +127,6 @@ static int ixp4xx_flash_remove(struct device *_dev)
135 if (plat->exit) 127 if (plat->exit)
136 plat->exit(); 128 plat->exit();
137 129
138 /* Disable flash write */
139 *IXP4XX_EXP_CS0 &= ~IXP4XX_FLASH_WRITABLE;
140
141 return 0; 130 return 0;
142} 131}
143 132
@@ -161,17 +150,11 @@ static int ixp4xx_flash_probe(struct device *_dev)
161 if(!info) { 150 if(!info) {
162 err = -ENOMEM; 151 err = -ENOMEM;
163 goto Error; 152 goto Error;
164 } 153 }
165 memzero(info, sizeof(struct ixp4xx_flash_info)); 154 memzero(info, sizeof(struct ixp4xx_flash_info));
166 155
167 dev_set_drvdata(&dev->dev, info); 156 dev_set_drvdata(&dev->dev, info);
168 157
169 /*
170 * Enable flash write
171 * TODO: Move this out to board specific code
172 */
173 *IXP4XX_EXP_CS0 |= IXP4XX_FLASH_WRITABLE;
174
175 /* 158 /*
176 * Tell the MTD layer we're not 1:1 mapped so that it does 159 * Tell the MTD layer we're not 1:1 mapped so that it does
177 * not attempt to do a direct access on us. 160 * not attempt to do a direct access on us.
@@ -190,8 +173,8 @@ static int ixp4xx_flash_probe(struct device *_dev)
190 info->map.write = ixp4xx_probe_write16, 173 info->map.write = ixp4xx_probe_write16,
191 info->map.copy_from = ixp4xx_copy_from, 174 info->map.copy_from = ixp4xx_copy_from,
192 175
193 info->res = request_mem_region(dev->resource->start, 176 info->res = request_mem_region(dev->resource->start,
194 dev->resource->end - dev->resource->start + 1, 177 dev->resource->end - dev->resource->start + 1,
195 "IXP4XXFlash"); 178 "IXP4XXFlash");
196 if (!info->res) { 179 if (!info->res) {
197 printk(KERN_ERR "IXP4XXFlash: Could not reserve memory region\n"); 180 printk(KERN_ERR "IXP4XXFlash: Could not reserve memory region\n");
@@ -199,9 +182,9 @@ static int ixp4xx_flash_probe(struct device *_dev)
199 goto Error; 182 goto Error;
200 } 183 }
201 184
202 info->map.map_priv_1 = ioremap(dev->resource->start, 185 info->map.virt = ioremap(dev->resource->start,
203 dev->resource->end - dev->resource->start + 1); 186 dev->resource->end - dev->resource->start + 1);
204 if (!info->map.map_priv_1) { 187 if (!info->map.virt) {
205 printk(KERN_ERR "IXP4XXFlash: Failed to ioremap region\n"); 188 printk(KERN_ERR "IXP4XXFlash: Failed to ioremap region\n");
206 err = -EIO; 189 err = -EIO;
207 goto Error; 190 goto Error;
@@ -214,7 +197,7 @@ static int ixp4xx_flash_probe(struct device *_dev)
214 goto Error; 197 goto Error;
215 } 198 }
216 info->mtd->owner = THIS_MODULE; 199 info->mtd->owner = THIS_MODULE;
217 200
218 /* Use the fast version */ 201 /* Use the fast version */
219 info->map.write = ixp4xx_write16, 202 info->map.write = ixp4xx_write16,
220 203
@@ -259,4 +242,3 @@ module_exit(ixp4xx_flash_exit);
259MODULE_LICENSE("GPL"); 242MODULE_LICENSE("GPL");
260MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems"); 243MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems");
261MODULE_AUTHOR("Deepak Saxena"); 244MODULE_AUTHOR("Deepak Saxena");
262
diff --git a/drivers/mtd/maps/l440gx.c b/drivers/mtd/maps/l440gx.c
index b08668212ab7..851bf9576052 100644
--- a/drivers/mtd/maps/l440gx.c
+++ b/drivers/mtd/maps/l440gx.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: l440gx.c,v 1.17 2004/11/28 09:40:39 dwmw2 Exp $ 2 * $Id: l440gx.c,v 1.18 2005/11/07 11:14:27 gleixner Exp $
3 * 3 *
4 * BIOS Flash chip on Intel 440GX board. 4 * BIOS Flash chip on Intel 440GX board.
5 * 5 *
@@ -49,7 +49,7 @@ static struct map_info l440gx_map = {
49 .bankwidth = BUSWIDTH, 49 .bankwidth = BUSWIDTH,
50 .phys = WINDOW_ADDR, 50 .phys = WINDOW_ADDR,
51#if 0 51#if 0
52 /* FIXME verify that this is the 52 /* FIXME verify that this is the
53 * appripriate code for vpp enable/disable 53 * appripriate code for vpp enable/disable
54 */ 54 */
55 .set_vpp = l440gx_set_vpp 55 .set_vpp = l440gx_set_vpp
@@ -62,10 +62,10 @@ static int __init init_l440gx(void)
62 struct resource *pm_iobase; 62 struct resource *pm_iobase;
63 __u16 word; 63 __u16 word;
64 64
65 dev = pci_find_device(PCI_VENDOR_ID_INTEL, 65 dev = pci_find_device(PCI_VENDOR_ID_INTEL,
66 PCI_DEVICE_ID_INTEL_82371AB_0, NULL); 66 PCI_DEVICE_ID_INTEL_82371AB_0, NULL);
67 67
68 pm_dev = pci_find_device(PCI_VENDOR_ID_INTEL, 68 pm_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
69 PCI_DEVICE_ID_INTEL_82371AB_3, NULL); 69 PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
70 70
71 if (!dev || !pm_dev) { 71 if (!dev || !pm_dev) {
@@ -82,10 +82,10 @@ static int __init init_l440gx(void)
82 simple_map_init(&l440gx_map); 82 simple_map_init(&l440gx_map);
83 printk(KERN_NOTICE "window_addr = 0x%08lx\n", (unsigned long)l440gx_map.virt); 83 printk(KERN_NOTICE "window_addr = 0x%08lx\n", (unsigned long)l440gx_map.virt);
84 84
85 /* Setup the pm iobase resource 85 /* Setup the pm iobase resource
86 * This code should move into some kind of generic bridge 86 * This code should move into some kind of generic bridge
87 * driver but for the moment I'm content with getting the 87 * driver but for the moment I'm content with getting the
88 * allocation correct. 88 * allocation correct.
89 */ 89 */
90 pm_iobase = &pm_dev->resource[PIIXE_IOBASE_RESOURCE]; 90 pm_iobase = &pm_dev->resource[PIIXE_IOBASE_RESOURCE];
91 if (!(pm_iobase->flags & IORESOURCE_IO)) { 91 if (!(pm_iobase->flags & IORESOURCE_IO)) {
@@ -110,7 +110,7 @@ static int __init init_l440gx(void)
110 /* Set the iobase */ 110 /* Set the iobase */
111 iobase = pm_iobase->start; 111 iobase = pm_iobase->start;
112 pci_write_config_dword(pm_dev, 0x40, iobase | 1); 112 pci_write_config_dword(pm_dev, 0x40, iobase | 1);
113 113
114 114
115 /* Set XBCS# */ 115 /* Set XBCS# */
116 pci_read_config_word(dev, 0x4e, &word); 116 pci_read_config_word(dev, 0x4e, &word);
@@ -122,7 +122,7 @@ static int __init init_l440gx(void)
122 122
123 /* Enable the gate on the WE line */ 123 /* Enable the gate on the WE line */
124 outb(inb(TRIBUF_PORT) & ~1, TRIBUF_PORT); 124 outb(inb(TRIBUF_PORT) & ~1, TRIBUF_PORT);
125 125
126 printk(KERN_NOTICE "Enabled WE line to L440GX BIOS flash chip.\n"); 126 printk(KERN_NOTICE "Enabled WE line to L440GX BIOS flash chip.\n");
127 127
128 mymtd = do_map_probe("jedec_probe", &l440gx_map); 128 mymtd = do_map_probe("jedec_probe", &l440gx_map);
@@ -145,7 +145,7 @@ static void __exit cleanup_l440gx(void)
145{ 145{
146 del_mtd_device(mymtd); 146 del_mtd_device(mymtd);
147 map_destroy(mymtd); 147 map_destroy(mymtd);
148 148
149 iounmap(l440gx_map.virt); 149 iounmap(l440gx_map.virt);
150} 150}
151 151
diff --git a/drivers/mtd/maps/lubbock-flash.c b/drivers/mtd/maps/lubbock-flash.c
index 2337e0c46750..1aa0447c5e66 100644
--- a/drivers/mtd/maps/lubbock-flash.c
+++ b/drivers/mtd/maps/lubbock-flash.c
@@ -1,11 +1,11 @@
1/* 1/*
2 * $Id: lubbock-flash.c,v 1.19 2004/11/04 13:24:15 gleixner Exp $ 2 * $Id: lubbock-flash.c,v 1.21 2005/11/07 11:14:27 gleixner Exp $
3 * 3 *
4 * Map driver for the Lubbock developer platform. 4 * Map driver for the Lubbock developer platform.
5 * 5 *
6 * Author: Nicolas Pitre 6 * Author: Nicolas Pitre
7 * Copyright: (C) 2001 MontaVista Software Inc. 7 * Copyright: (C) 2001 MontaVista Software Inc.
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as 10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -76,7 +76,7 @@ static int __init init_lubbock(void)
76 int flashboot = (LUB_CONF_SWITCHES & 1); 76 int flashboot = (LUB_CONF_SWITCHES & 1);
77 int ret = 0, i; 77 int ret = 0, i;
78 78
79 lubbock_maps[0].bankwidth = lubbock_maps[1].bankwidth = 79 lubbock_maps[0].bankwidth = lubbock_maps[1].bankwidth =
80 (BOOT_DEF & 1) ? 2 : 4; 80 (BOOT_DEF & 1) ? 2 : 4;
81 81
82 /* Compensate for the nROMBT switch which swaps the flash banks */ 82 /* Compensate for the nROMBT switch which swaps the flash banks */
@@ -100,11 +100,11 @@ static int __init init_lubbock(void)
100 simple_map_init(&lubbock_maps[i]); 100 simple_map_init(&lubbock_maps[i]);
101 101
102 printk(KERN_NOTICE "Probing %s at physical address 0x%08lx (%d-bit bankwidth)\n", 102 printk(KERN_NOTICE "Probing %s at physical address 0x%08lx (%d-bit bankwidth)\n",
103 lubbock_maps[i].name, lubbock_maps[i].phys, 103 lubbock_maps[i].name, lubbock_maps[i].phys,
104 lubbock_maps[i].bankwidth * 8); 104 lubbock_maps[i].bankwidth * 8);
105 105
106 mymtds[i] = do_map_probe("cfi_probe", &lubbock_maps[i]); 106 mymtds[i] = do_map_probe("cfi_probe", &lubbock_maps[i]);
107 107
108 if (!mymtds[i]) { 108 if (!mymtds[i]) {
109 iounmap((void *)lubbock_maps[i].virt); 109 iounmap((void *)lubbock_maps[i].virt);
110 if (lubbock_maps[i].cached) 110 if (lubbock_maps[i].cached)
@@ -124,7 +124,7 @@ static int __init init_lubbock(void)
124 124
125 if (!mymtds[0] && !mymtds[1]) 125 if (!mymtds[0] && !mymtds[1])
126 return ret; 126 return ret;
127 127
128 for (i = 0; i < 2; i++) { 128 for (i = 0; i < 2; i++) {
129 if (!mymtds[i]) { 129 if (!mymtds[i]) {
130 printk(KERN_WARNING "%s is absent. Skipping\n", lubbock_maps[i].name); 130 printk(KERN_WARNING "%s is absent. Skipping\n", lubbock_maps[i].name);
@@ -151,15 +151,14 @@ static void __exit cleanup_lubbock(void)
151 if (nr_parsed_parts[i] || !i) 151 if (nr_parsed_parts[i] || !i)
152 del_mtd_partitions(mymtds[i]); 152 del_mtd_partitions(mymtds[i]);
153 else 153 else
154 del_mtd_device(mymtds[i]); 154 del_mtd_device(mymtds[i]);
155 155
156 map_destroy(mymtds[i]); 156 map_destroy(mymtds[i]);
157 iounmap((void *)lubbock_maps[i].virt); 157 iounmap((void *)lubbock_maps[i].virt);
158 if (lubbock_maps[i].cached) 158 if (lubbock_maps[i].cached)
159 iounmap(lubbock_maps[i].cached); 159 iounmap(lubbock_maps[i].cached);
160 160
161 if (parsed_parts[i]) 161 kfree(parsed_parts[i]);
162 kfree(parsed_parts[i]);
163 } 162 }
164} 163}
165 164
diff --git a/drivers/mtd/maps/mainstone-flash.c b/drivers/mtd/maps/mainstone-flash.c
index da0f8a692628..eaa4bbb868a3 100644
--- a/drivers/mtd/maps/mainstone-flash.c
+++ b/drivers/mtd/maps/mainstone-flash.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * Author: Nicolas Pitre 6 * Author: Nicolas Pitre
7 * Copyright: (C) 2001 MontaVista Software Inc. 7 * Copyright: (C) 2001 MontaVista Software Inc.
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as 10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -91,27 +91,27 @@ static int __init init_mainstone(void)
91 mainstone_maps[i].virt = ioremap(mainstone_maps[i].phys, 91 mainstone_maps[i].virt = ioremap(mainstone_maps[i].phys,
92 WINDOW_SIZE); 92 WINDOW_SIZE);
93 if (!mainstone_maps[i].virt) { 93 if (!mainstone_maps[i].virt) {
94 printk(KERN_WARNING "Failed to ioremap %s\n", 94 printk(KERN_WARNING "Failed to ioremap %s\n",
95 mainstone_maps[i].name); 95 mainstone_maps[i].name);
96 if (!ret) 96 if (!ret)
97 ret = -ENOMEM; 97 ret = -ENOMEM;
98 continue; 98 continue;
99 } 99 }
100 mainstone_maps[i].cached = 100 mainstone_maps[i].cached =
101 ioremap_cached(mainstone_maps[i].phys, WINDOW_SIZE); 101 ioremap_cached(mainstone_maps[i].phys, WINDOW_SIZE);
102 if (!mainstone_maps[i].cached) 102 if (!mainstone_maps[i].cached)
103 printk(KERN_WARNING "Failed to ioremap cached %s\n", 103 printk(KERN_WARNING "Failed to ioremap cached %s\n",
104 mainstone_maps[i].name); 104 mainstone_maps[i].name);
105 simple_map_init(&mainstone_maps[i]); 105 simple_map_init(&mainstone_maps[i]);
106 106
107 printk(KERN_NOTICE 107 printk(KERN_NOTICE
108 "Probing %s at physical address 0x%08lx" 108 "Probing %s at physical address 0x%08lx"
109 " (%d-bit bankwidth)\n", 109 " (%d-bit bankwidth)\n",
110 mainstone_maps[i].name, mainstone_maps[i].phys, 110 mainstone_maps[i].name, mainstone_maps[i].phys,
111 mainstone_maps[i].bankwidth * 8); 111 mainstone_maps[i].bankwidth * 8);
112 112
113 mymtds[i] = do_map_probe("cfi_probe", &mainstone_maps[i]); 113 mymtds[i] = do_map_probe("cfi_probe", &mainstone_maps[i]);
114 114
115 if (!mymtds[i]) { 115 if (!mymtds[i]) {
116 iounmap((void *)mainstone_maps[i].virt); 116 iounmap((void *)mainstone_maps[i].virt);
117 if (mainstone_maps[i].cached) 117 if (mainstone_maps[i].cached)
@@ -131,21 +131,21 @@ static int __init init_mainstone(void)
131 131
132 if (!mymtds[0] && !mymtds[1]) 132 if (!mymtds[0] && !mymtds[1])
133 return ret; 133 return ret;
134 134
135 for (i = 0; i < 2; i++) { 135 for (i = 0; i < 2; i++) {
136 if (!mymtds[i]) { 136 if (!mymtds[i]) {
137 printk(KERN_WARNING "%s is absent. Skipping\n", 137 printk(KERN_WARNING "%s is absent. Skipping\n",
138 mainstone_maps[i].name); 138 mainstone_maps[i].name);
139 } else if (nr_parsed_parts[i]) { 139 } else if (nr_parsed_parts[i]) {
140 add_mtd_partitions(mymtds[i], parsed_parts[i], 140 add_mtd_partitions(mymtds[i], parsed_parts[i],
141 nr_parsed_parts[i]); 141 nr_parsed_parts[i]);
142 } else if (!i) { 142 } else if (!i) {
143 printk("Using static partitions on %s\n", 143 printk("Using static partitions on %s\n",
144 mainstone_maps[i].name); 144 mainstone_maps[i].name);
145 add_mtd_partitions(mymtds[i], mainstone_partitions, 145 add_mtd_partitions(mymtds[i], mainstone_partitions,
146 ARRAY_SIZE(mainstone_partitions)); 146 ARRAY_SIZE(mainstone_partitions));
147 } else { 147 } else {
148 printk("Registering %s as whole device\n", 148 printk("Registering %s as whole device\n",
149 mainstone_maps[i].name); 149 mainstone_maps[i].name);
150 add_mtd_device(mymtds[i]); 150 add_mtd_device(mymtds[i]);
151 } 151 }
diff --git a/drivers/mtd/maps/mbx860.c b/drivers/mtd/maps/mbx860.c
index c5c6901a4763..06b118727846 100644
--- a/drivers/mtd/maps/mbx860.c
+++ b/drivers/mtd/maps/mbx860.c
@@ -1,11 +1,11 @@
1/* 1/*
2 * $Id: mbx860.c,v 1.8 2004/11/04 13:24:15 gleixner Exp $ 2 * $Id: mbx860.c,v 1.9 2005/11/07 11:14:27 gleixner Exp $
3 * 3 *
4 * Handle mapping of the flash on MBX860 boards 4 * Handle mapping of the flash on MBX860 boards
5 * 5 *
6 * Author: Anton Todorov 6 * Author: Anton Todorov
7 * Copyright: (C) 2001 Emness Technology 7 * Copyright: (C) 2001 Emness Technology
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as 10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
@@ -46,7 +46,7 @@ static struct mtd_partition partition_info[]={
46 { .name = "MBX flash APPLICATION partition", 46 { .name = "MBX flash APPLICATION partition",
47 .offset = (BOOT_PARTITION_SIZE_KiB+KERNEL_PARTITION_SIZE_KiB)*1024 } 47 .offset = (BOOT_PARTITION_SIZE_KiB+KERNEL_PARTITION_SIZE_KiB)*1024 }
48}; 48};
49 49
50 50
51static struct mtd_info *mymtd; 51static struct mtd_info *mymtd;
52 52
diff --git a/drivers/mtd/maps/mtx-1_flash.c b/drivers/mtd/maps/mtx-1_flash.c
new file mode 100644
index 000000000000..d1e66e186746
--- /dev/null
+++ b/drivers/mtd/maps/mtx-1_flash.c
@@ -0,0 +1,96 @@
1/*
2 * Flash memory access on 4G Systems MTX-1 boards
3 *
4 * $Id: mtx-1_flash.c,v 1.2 2005/11/07 11:14:27 gleixner Exp $
5 *
6 * (C) 2005 Bruno Randolf <bruno.randolf@4g-systems.biz>
7 * (C) 2005 Jörn Engel <joern@wohnheim.fh-wedel.de>
8 *
9 */
10
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/types.h>
14#include <linux/init.h>
15#include <linux/kernel.h>
16
17#include <linux/mtd/mtd.h>
18#include <linux/mtd/map.h>
19#include <linux/mtd/partitions.h>
20
21#include <asm/io.h>
22
23static struct map_info mtx1_map = {
24 .name = "MTX-1 flash",
25 .bankwidth = 4,
26 .size = 0x2000000,
27 .phys = 0x1E000000,
28};
29
30static struct mtd_partition mtx1_partitions[] = {
31 {
32 .name = "filesystem",
33 .size = 0x01C00000,
34 .offset = 0,
35 },{
36 .name = "yamon",
37 .size = 0x00100000,
38 .offset = MTDPART_OFS_APPEND,
39 .mask_flags = MTD_WRITEABLE,
40 },{
41 .name = "kernel",
42 .size = 0x002c0000,
43 .offset = MTDPART_OFS_APPEND,
44 },{
45 .name = "yamon env",
46 .size = 0x00040000,
47 .offset = MTDPART_OFS_APPEND,
48 }
49};
50
51static struct mtd_info *mtx1_mtd;
52
53int __init mtx1_mtd_init(void)
54{
55 int ret = -ENXIO;
56
57 simple_map_init(&mtx1_map);
58
59 mtx1_map.virt = ioremap(mtx1_map.phys, mtx1_map.size);
60 if (!mtx1_map.virt)
61 return -EIO;
62
63 mtx1_mtd = do_map_probe("cfi_probe", &mtx1_map);
64 if (!mtx1_mtd)
65 goto err;
66
67 mtx1_mtd->owner = THIS_MODULE;
68
69 ret = add_mtd_partitions(mtx1_mtd, mtx1_partitions,
70 ARRAY_SIZE(mtx1_partitions));
71 if (ret)
72 goto err;
73
74 return 0;
75
76err:
77 iounmap(mtx1_map.virt);
78 return ret;
79}
80
81static void __exit mtx1_mtd_cleanup(void)
82{
83 if (mtx1_mtd) {
84 del_mtd_partitions(mtx1_mtd);
85 map_destroy(mtx1_mtd);
86 }
87 if (mtx1_map.virt)
88 iounmap(mtx1_map.virt);
89}
90
91module_init(mtx1_mtd_init);
92module_exit(mtx1_mtd_cleanup);
93
94MODULE_AUTHOR("Bruno Randolf <bruno.randolf@4g-systems.biz>");
95MODULE_DESCRIPTION("MTX-1 flash map");
96MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/maps/netsc520.c b/drivers/mtd/maps/netsc520.c
index ab7e6358d281..33060a315722 100644
--- a/drivers/mtd/maps/netsc520.c
+++ b/drivers/mtd/maps/netsc520.c
@@ -3,7 +3,7 @@
3 * Copyright (C) 2001 Mark Langsdorf (mark.langsdorf@amd.com) 3 * Copyright (C) 2001 Mark Langsdorf (mark.langsdorf@amd.com)
4 * based on sc520cdp.c by Sysgo Real-Time Solutions GmbH 4 * based on sc520cdp.c by Sysgo Real-Time Solutions GmbH
5 * 5 *
6 * $Id: netsc520.c,v 1.13 2004/11/28 09:40:40 dwmw2 Exp $ 6 * $Id: netsc520.c,v 1.14 2005/11/07 11:14:27 gleixner Exp $
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -38,7 +38,7 @@
38** The single, 16 megabyte flash bank is divided into four virtual 38** The single, 16 megabyte flash bank is divided into four virtual
39** partitions. The first partition is 768 KiB and is intended to 39** partitions. The first partition is 768 KiB and is intended to
40** store the kernel image loaded by the bootstrap loader. The second 40** store the kernel image loaded by the bootstrap loader. The second
41** partition is 256 KiB and holds the BIOS image. The third 41** partition is 256 KiB and holds the BIOS image. The third
42** partition is 14.5 MiB and is intended for the flash file system 42** partition is 14.5 MiB and is intended for the flash file system
43** image. The last partition is 512 KiB and contains another copy 43** image. The last partition is 512 KiB and contains another copy
44** of the BIOS image and the reset vector. 44** of the BIOS image and the reset vector.
@@ -51,28 +51,28 @@
51** recoverable afterwards. 51** recoverable afterwards.
52*/ 52*/
53 53
54/* partition_info gives details on the logical partitions that the split the 54/* partition_info gives details on the logical partitions that the split the
55 * single flash device into. If the size if zero we use up to the end of the 55 * single flash device into. If the size if zero we use up to the end of the
56 * device. */ 56 * device. */
57static struct mtd_partition partition_info[]={ 57static struct mtd_partition partition_info[]={
58 { 58 {
59 .name = "NetSc520 boot kernel", 59 .name = "NetSc520 boot kernel",
60 .offset = 0, 60 .offset = 0,
61 .size = 0xc0000 61 .size = 0xc0000
62 }, 62 },
63 { 63 {
64 .name = "NetSc520 Low BIOS", 64 .name = "NetSc520 Low BIOS",
65 .offset = 0xc0000, 65 .offset = 0xc0000,
66 .size = 0x40000 66 .size = 0x40000
67 }, 67 },
68 { 68 {
69 .name = "NetSc520 file system", 69 .name = "NetSc520 file system",
70 .offset = 0x100000, 70 .offset = 0x100000,
71 .size = 0xe80000 71 .size = 0xe80000
72 }, 72 },
73 { 73 {
74 .name = "NetSc520 High BIOS", 74 .name = "NetSc520 High BIOS",
75 .offset = 0xf80000, 75 .offset = 0xf80000,
76 .size = 0x80000 76 .size = 0x80000
77 }, 77 },
78}; 78};
@@ -114,7 +114,7 @@ static int __init init_netsc520(void)
114 iounmap(netsc520_map.virt); 114 iounmap(netsc520_map.virt);
115 return -ENXIO; 115 return -ENXIO;
116 } 116 }
117 117
118 mymtd->owner = THIS_MODULE; 118 mymtd->owner = THIS_MODULE;
119 add_mtd_partitions( mymtd, partition_info, NUM_PARTITIONS ); 119 add_mtd_partitions( mymtd, partition_info, NUM_PARTITIONS );
120 return 0; 120 return 0;
diff --git a/drivers/mtd/maps/nettel.c b/drivers/mtd/maps/nettel.c
index 61be5a4148c9..f00ee7e54dba 100644
--- a/drivers/mtd/maps/nettel.c
+++ b/drivers/mtd/maps/nettel.c
@@ -6,7 +6,7 @@
6 * (C) Copyright 2000-2001, Greg Ungerer (gerg@snapgear.com) 6 * (C) Copyright 2000-2001, Greg Ungerer (gerg@snapgear.com)
7 * (C) Copyright 2001-2002, SnapGear (www.snapgear.com) 7 * (C) Copyright 2001-2002, SnapGear (www.snapgear.com)
8 * 8 *
9 * $Id: nettel.c,v 1.10 2005/01/05 17:11:29 dwmw2 Exp $ 9 * $Id: nettel.c,v 1.11 2005/11/07 11:14:27 gleixner Exp $
10 */ 10 */
11 11
12/****************************************************************************/ 12/****************************************************************************/
@@ -143,7 +143,7 @@ static int nettel_reboot_notifier(struct notifier_block *nb, unsigned long val,
143{ 143{
144 struct cfi_private *cfi = nettel_intel_map.fldrv_priv; 144 struct cfi_private *cfi = nettel_intel_map.fldrv_priv;
145 unsigned long b; 145 unsigned long b;
146 146
147 /* Make sure all FLASH chips are put back into read mode */ 147 /* Make sure all FLASH chips are put back into read mode */
148 for (b = 0; (b < nettel_intel_partitions[3].size); b += 0x100000) { 148 for (b = 0; (b < nettel_intel_partitions[3].size); b += 0x100000) {
149 cfi_send_gen_cmd(0xff, 0x55, b, &nettel_intel_map, cfi, 149 cfi_send_gen_cmd(0xff, 0x55, b, &nettel_intel_map, cfi,
@@ -199,7 +199,7 @@ int nettel_eraseconfig(void)
199 199
200 schedule(); /* Wait for erase to finish. */ 200 schedule(); /* Wait for erase to finish. */
201 remove_wait_queue(&wait_q, &wait); 201 remove_wait_queue(&wait_q, &wait);
202 202
203 put_mtd_device(mtd); 203 put_mtd_device(mtd);
204 } 204 }
205 205
@@ -430,7 +430,7 @@ int __init nettel_init(void)
430 nettel_intel_partitions[1].size = (intel0size + intel1size) - 430 nettel_intel_partitions[1].size = (intel0size + intel1size) -
431 (1024*1024 + intel_mtd->erasesize); 431 (1024*1024 + intel_mtd->erasesize);
432 nettel_intel_partitions[3].size = intel0size + intel1size; 432 nettel_intel_partitions[3].size = intel0size + intel1size;
433 nettel_intel_partitions[4].offset = 433 nettel_intel_partitions[4].offset =
434 (intel0size + intel1size) - intel_mtd->erasesize; 434 (intel0size + intel1size) - intel_mtd->erasesize;
435 nettel_intel_partitions[4].size = intel_mtd->erasesize; 435 nettel_intel_partitions[4].size = intel_mtd->erasesize;
436 nettel_intel_partitions[5].offset = 436 nettel_intel_partitions[5].offset =
diff --git a/drivers/mtd/maps/ocelot.c b/drivers/mtd/maps/ocelot.c
index 82c3070678c5..6977963d7897 100644
--- a/drivers/mtd/maps/ocelot.c
+++ b/drivers/mtd/maps/ocelot.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ocelot.c,v 1.16 2005/01/05 18:05:13 dwmw2 Exp $ 2 * $Id: ocelot.c,v 1.17 2005/11/07 11:14:27 gleixner Exp $
3 * 3 *
4 * Flash on Momenco Ocelot 4 * Flash on Momenco Ocelot
5 */ 5 */
@@ -31,7 +31,7 @@ static void ocelot_ram_write(struct mtd_info *mtd, loff_t to, size_t len, size_t
31 struct map_info *map = mtd->priv; 31 struct map_info *map = mtd->priv;
32 size_t done = 0; 32 size_t done = 0;
33 33
34 /* If we use memcpy, it does word-wide writes. Even though we told the 34 /* If we use memcpy, it does word-wide writes. Even though we told the
35 GT64120A that it's an 8-bit wide region, word-wide writes don't work. 35 GT64120A that it's an 8-bit wide region, word-wide writes don't work.
36 We end up just writing the first byte of the four to all four bytes. 36 We end up just writing the first byte of the four to all four bytes.
37 So we have this loop instead */ 37 So we have this loop instead */
@@ -68,7 +68,7 @@ static int __init init_ocelot_maps(void)
68 int nr_parts; 68 int nr_parts;
69 unsigned char brd_status; 69 unsigned char brd_status;
70 70
71 printk(KERN_INFO "Momenco Ocelot MTD mappings: Flash 0x%x at 0x%x, NVRAM 0x%x at 0x%x\n", 71 printk(KERN_INFO "Momenco Ocelot MTD mappings: Flash 0x%x at 0x%x, NVRAM 0x%x at 0x%x\n",
72 FLASH_WINDOW_SIZE, FLASH_WINDOW_ADDR, NVRAM_WINDOW_SIZE, NVRAM_WINDOW_ADDR); 72 FLASH_WINDOW_SIZE, FLASH_WINDOW_ADDR, NVRAM_WINDOW_SIZE, NVRAM_WINDOW_ADDR);
73 73
74 /* First check whether the flash jumper is present */ 74 /* First check whether the flash jumper is present */
@@ -138,8 +138,8 @@ static int __init init_ocelot_maps(void)
138 add_mtd_device(flash_mtd); 138 add_mtd_device(flash_mtd);
139 139
140 return 0; 140 return 0;
141 141
142 fail3: 142 fail3:
143 iounmap((void *)ocelot_flash_map.virt); 143 iounmap((void *)ocelot_flash_map.virt);
144 if (ocelot_flash_map.cached) 144 if (ocelot_flash_map.cached)
145 iounmap((void *)ocelot_flash_map.cached); 145 iounmap((void *)ocelot_flash_map.cached);
diff --git a/drivers/mtd/maps/octagon-5066.c b/drivers/mtd/maps/octagon-5066.c
index e5ff83de420e..a6642db3d325 100644
--- a/drivers/mtd/maps/octagon-5066.c
+++ b/drivers/mtd/maps/octagon-5066.c
@@ -1,12 +1,12 @@
1// $Id: octagon-5066.c,v 1.26 2004/07/12 22:38:29 dwmw2 Exp $ 1// $Id: octagon-5066.c,v 1.28 2005/11/07 11:14:27 gleixner Exp $
2/* ###################################################################### 2/* ######################################################################
3 3
4 Octagon 5066 MTD Driver. 4 Octagon 5066 MTD Driver.
5 5
6 The Octagon 5066 is a SBC based on AMD's 586-WB running at 133 MHZ. It 6 The Octagon 5066 is a SBC based on AMD's 586-WB running at 133 MHZ. It
7 comes with a builtin AMD 29F016 flash chip and a socketed EEPROM that 7 comes with a builtin AMD 29F016 flash chip and a socketed EEPROM that
8 is replacable by flash. Both units are mapped through a multiplexer 8 is replacable by flash. Both units are mapped through a multiplexer
9 into a 32k memory window at 0xe8000. The control register for the 9 into a 32k memory window at 0xe8000. The control register for the
10 multiplexing unit is located at IO 0x208 with a bit map of 10 multiplexing unit is located at IO 0x208 with a bit map of
11 0-5 Page Selection in 32k increments 11 0-5 Page Selection in 32k increments
12 6-7 Device selection: 12 6-7 Device selection:
@@ -14,14 +14,14 @@
14 01 SSD 0 (Socket) 14 01 SSD 0 (Socket)
15 10 SSD 1 (Flash chip) 15 10 SSD 1 (Flash chip)
16 11 undefined 16 11 undefined
17 17
18 On each SSD, the first 128k is reserved for use by the bios 18 On each SSD, the first 128k is reserved for use by the bios
19 (actually it IS the bios..) This only matters if you are booting off the 19 (actually it IS the bios..) This only matters if you are booting off the
20 flash, you must not put a file system starting there. 20 flash, you must not put a file system starting there.
21 21
22 The driver tries to do a detection algorithm to guess what sort of devices 22 The driver tries to do a detection algorithm to guess what sort of devices
23 are plugged into the sockets. 23 are plugged into the sockets.
24 24
25 ##################################################################### */ 25 ##################################################################### */
26 26
27#include <linux/module.h> 27#include <linux/module.h>
@@ -56,7 +56,7 @@ static void __oct5066_page(struct map_info *map, __u8 byte)
56static inline void oct5066_page(struct map_info *map, unsigned long ofs) 56static inline void oct5066_page(struct map_info *map, unsigned long ofs)
57{ 57{
58 __u8 byte = map->map_priv_1 | (ofs >> WINDOW_SHIFT); 58 __u8 byte = map->map_priv_1 | (ofs >> WINDOW_SHIFT);
59 59
60 if (page_n_dev != byte) 60 if (page_n_dev != byte)
61 __oct5066_page(map, byte); 61 __oct5066_page(map, byte);
62} 62}
@@ -78,7 +78,7 @@ static void oct5066_copy_from(struct map_info *map, void *to, unsigned long from
78 unsigned long thislen = len; 78 unsigned long thislen = len;
79 if (len > (WINDOW_LENGTH - (from & WINDOW_MASK))) 79 if (len > (WINDOW_LENGTH - (from & WINDOW_MASK)))
80 thislen = WINDOW_LENGTH-(from & WINDOW_MASK); 80 thislen = WINDOW_LENGTH-(from & WINDOW_MASK);
81 81
82 spin_lock(&oct5066_spin); 82 spin_lock(&oct5066_spin);
83 oct5066_page(map, from); 83 oct5066_page(map, from);
84 memcpy_fromio(to, iomapadr + from, thislen); 84 memcpy_fromio(to, iomapadr + from, thislen);
@@ -103,7 +103,7 @@ static void oct5066_copy_to(struct map_info *map, unsigned long to, const void *
103 unsigned long thislen = len; 103 unsigned long thislen = len;
104 if (len > (WINDOW_LENGTH - (to & WINDOW_MASK))) 104 if (len > (WINDOW_LENGTH - (to & WINDOW_MASK)))
105 thislen = WINDOW_LENGTH-(to & WINDOW_MASK); 105 thislen = WINDOW_LENGTH-(to & WINDOW_MASK);
106 106
107 spin_lock(&oct5066_spin); 107 spin_lock(&oct5066_spin);
108 oct5066_page(map, to); 108 oct5066_page(map, to);
109 memcpy_toio(iomapadr + to, from, thislen); 109 memcpy_toio(iomapadr + to, from, thislen);
@@ -144,7 +144,7 @@ static struct mtd_info *oct5066_mtd[2] = {NULL, NULL};
144// OctProbe - Sense if this is an octagon card 144// OctProbe - Sense if this is an octagon card
145// --------------------------------------------------------------------- 145// ---------------------------------------------------------------------
146/* Perform a simple validity test, we map the window select SSD0 and 146/* Perform a simple validity test, we map the window select SSD0 and
147 change pages while monitoring the window. A change in the window, 147 change pages while monitoring the window. A change in the window,
148 controlled by the PAGE_IO port is a functioning 5066 board. This will 148 controlled by the PAGE_IO port is a functioning 5066 board. This will
149 fail if the thing in the socket is set to a uniform value. */ 149 fail if the thing in the socket is set to a uniform value. */
150static int __init OctProbe(void) 150static int __init OctProbe(void)
@@ -161,13 +161,13 @@ static int __init OctProbe(void)
161 Values[I%10] = readl(iomapadr); 161 Values[I%10] = readl(iomapadr);
162 if (I > 0 && Values[I%10] == Values[0]) 162 if (I > 0 && Values[I%10] == Values[0])
163 return -EAGAIN; 163 return -EAGAIN;
164 } 164 }
165 else 165 else
166 { 166 {
167 // Make sure we get the same values on the second pass 167 // Make sure we get the same values on the second pass
168 if (Values[I%10] != readl(iomapadr)) 168 if (Values[I%10] != readl(iomapadr))
169 return -EAGAIN; 169 return -EAGAIN;
170 } 170 }
171 } 171 }
172 return 0; 172 return 0;
173} 173}
@@ -207,11 +207,11 @@ int __init init_oct5066(void)
207 ret = -EAGAIN; 207 ret = -EAGAIN;
208 goto out_unmap; 208 goto out_unmap;
209 } 209 }
210 210
211 // Print out our little header.. 211 // Print out our little header..
212 printk("Octagon 5066 SSD IO:0x%x MEM:0x%x-0x%x\n",PAGE_IO,WINDOW_START, 212 printk("Octagon 5066 SSD IO:0x%x MEM:0x%x-0x%x\n",PAGE_IO,WINDOW_START,
213 WINDOW_START+WINDOW_LENGTH); 213 WINDOW_START+WINDOW_LENGTH);
214 214
215 for (i=0; i<2; i++) { 215 for (i=0; i<2; i++) {
216 oct5066_mtd[i] = do_map_probe("cfi_probe", &oct5066_map[i]); 216 oct5066_mtd[i] = do_map_probe("cfi_probe", &oct5066_map[i]);
217 if (!oct5066_mtd[i]) 217 if (!oct5066_mtd[i])
@@ -225,11 +225,11 @@ int __init init_oct5066(void)
225 add_mtd_device(oct5066_mtd[i]); 225 add_mtd_device(oct5066_mtd[i]);
226 } 226 }
227 } 227 }
228 228
229 if (!oct5066_mtd[0] && !oct5066_mtd[1]) { 229 if (!oct5066_mtd[0] && !oct5066_mtd[1]) {
230 cleanup_oct5066(); 230 cleanup_oct5066();
231 return -ENXIO; 231 return -ENXIO;
232 } 232 }
233 233
234 return 0; 234 return 0;
235 235
diff --git a/drivers/mtd/maps/omap-toto-flash.c b/drivers/mtd/maps/omap-toto-flash.c
index da36e8dddd17..dc3765270057 100644
--- a/drivers/mtd/maps/omap-toto-flash.c
+++ b/drivers/mtd/maps/omap-toto-flash.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * (C) 2002 MontVista Software, Inc. 6 * (C) 2002 MontVista Software, Inc.
7 * 7 *
8 * $Id: omap-toto-flash.c,v 1.3 2004/09/16 23:27:13 gleixner Exp $ 8 * $Id: omap-toto-flash.c,v 1.5 2005/11/07 11:14:27 gleixner Exp $
9 */ 9 */
10 10
11#include <linux/config.h> 11#include <linux/config.h>
@@ -38,7 +38,7 @@ static struct map_info omap_toto_map_flash = {
38 .virt = (void __iomem *)OMAP_TOTO_FLASH_BASE, 38 .virt = (void __iomem *)OMAP_TOTO_FLASH_BASE,
39}; 39};
40 40
41 41
42static struct mtd_partition toto_flash_partitions[] = { 42static struct mtd_partition toto_flash_partitions[] = {
43 { 43 {
44 .name = "BootLoader", 44 .name = "BootLoader",
@@ -54,21 +54,21 @@ static struct mtd_partition toto_flash_partitions[] = {
54 .name = "EnvArea", /* bottom 64KiB for env vars */ 54 .name = "EnvArea", /* bottom 64KiB for env vars */
55 .size = MTDPART_SIZ_FULL, 55 .size = MTDPART_SIZ_FULL,
56 .offset = MTDPART_OFS_APPEND, 56 .offset = MTDPART_OFS_APPEND,
57 } 57 }
58}; 58};
59 59
60static struct mtd_partition *parsed_parts; 60static struct mtd_partition *parsed_parts;
61 61
62static struct mtd_info *flash_mtd; 62static struct mtd_info *flash_mtd;
63 63
64static int __init init_flash (void) 64static int __init init_flash (void)
65{ 65{
66 66
67 struct mtd_partition *parts; 67 struct mtd_partition *parts;
68 int nb_parts = 0; 68 int nb_parts = 0;
69 int parsed_nr_parts = 0; 69 int parsed_nr_parts = 0;
70 const char *part_type; 70 const char *part_type;
71 71
72 /* 72 /*
73 * Static partition definition selection 73 * Static partition definition selection
74 */ 74 */
@@ -89,7 +89,7 @@ static int __init init_flash (void)
89 flash_mtd = do_map_probe("jedec_probe", &omap_toto_map_flash); 89 flash_mtd = do_map_probe("jedec_probe", &omap_toto_map_flash);
90 if (!flash_mtd) 90 if (!flash_mtd)
91 return -ENXIO; 91 return -ENXIO;
92 92
93 if (parsed_nr_parts > 0) { 93 if (parsed_nr_parts > 0) {
94 parts = parsed_parts; 94 parts = parsed_parts;
95 nb_parts = parsed_nr_parts; 95 nb_parts = parsed_nr_parts;
@@ -108,8 +108,8 @@ static int __init init_flash (void)
108 } 108 }
109 return 0; 109 return 0;
110} 110}
111 111
112int __init omap_toto_mtd_init(void) 112int __init omap_toto_mtd_init(void)
113{ 113{
114 int status; 114 int status;
115 115
@@ -119,13 +119,12 @@ int __init omap_toto_mtd_init(void)
119 return status; 119 return status;
120} 120}
121 121
122static void __exit omap_toto_mtd_cleanup(void) 122static void __exit omap_toto_mtd_cleanup(void)
123{ 123{
124 if (flash_mtd) { 124 if (flash_mtd) {
125 del_mtd_partitions(flash_mtd); 125 del_mtd_partitions(flash_mtd);
126 map_destroy(flash_mtd); 126 map_destroy(flash_mtd);
127 if (parsed_parts) 127 kfree(parsed_parts);
128 kfree(parsed_parts);
129 } 128 }
130} 129}
131 130
diff --git a/drivers/mtd/maps/omap_nor.c b/drivers/mtd/maps/omap_nor.c
index 7f370bb794fe..fd3b4a5fc207 100644
--- a/drivers/mtd/maps/omap_nor.c
+++ b/drivers/mtd/maps/omap_nor.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2001-2002 MontaVista Software Inc. 4 * Copyright (C) 2001-2002 MontaVista Software Inc.
5 * Copyright (C) 2003-2004 Texas Instruments 5 * Copyright (C) 2003-2004 Texas Instruments
6 * Copyright (C) 2004 Nokia Corporation 6 * Copyright (C) 2004 Nokia Corporation
7 * 7 *
8 * Assembled using driver code copyright the companies above 8 * Assembled using driver code copyright the companies above
9 * and written by David Brownell, Jian Zhang <jzhang@ti.com>, 9 * and written by David Brownell, Jian Zhang <jzhang@ti.com>,
diff --git a/drivers/mtd/maps/pci.c b/drivers/mtd/maps/pci.c
index d9c64e99ee32..8b3570b09095 100644
--- a/drivers/mtd/maps/pci.c
+++ b/drivers/mtd/maps/pci.c
@@ -7,8 +7,8 @@
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 * $Id: pci.c,v 1.10 2005/03/18 14:04:35 gleixner Exp $ 10 * $Id: pci.c,v 1.13 2005/11/07 11:14:27 gleixner Exp $
11 * 11 *
12 * Generic PCI memory map driver. We support the following boards: 12 * Generic PCI memory map driver. We support the following boards:
13 * - Intel IQ80310 ATU. 13 * - Intel IQ80310 ATU.
14 * - Intel EBSA285 (blank rom programming mode). Tested working 27/09/2001 14 * - Intel EBSA285 (blank rom programming mode). Tested working 27/09/2001
@@ -38,7 +38,7 @@ struct map_pci_info {
38 void (*exit)(struct pci_dev *dev, struct map_pci_info *map); 38 void (*exit)(struct pci_dev *dev, struct map_pci_info *map);
39 unsigned long (*translate)(struct map_pci_info *map, unsigned long ofs); 39 unsigned long (*translate)(struct map_pci_info *map, unsigned long ofs);
40 struct pci_dev *dev; 40 struct pci_dev *dev;
41}; 41};
42 42
43static map_word mtd_pci_read8(struct map_info *_map, unsigned long ofs) 43static map_word mtd_pci_read8(struct map_info *_map, unsigned long ofs)
44{ 44{
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index ff7c50d10180..af24216a0626 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: pcmciamtd.c,v 1.51 2004/07/12 22:38:29 dwmw2 Exp $ 2 * $Id: pcmciamtd.c,v 1.55 2005/11/07 11:14:28 gleixner Exp $
3 * 3 *
4 * pcmciamtd.c - MTD driver for PCMCIA flash memory cards 4 * pcmciamtd.c - MTD driver for PCMCIA flash memory cards
5 * 5 *
@@ -48,7 +48,7 @@ static const int debug = 0;
48 48
49 49
50#define DRIVER_DESC "PCMCIA Flash memory card driver" 50#define DRIVER_DESC "PCMCIA Flash memory card driver"
51#define DRIVER_VERSION "$Revision: 1.51 $" 51#define DRIVER_VERSION "$Revision: 1.55 $"
52 52
53/* Size of the PCMCIA address space: 26 bits = 64 MB */ 53/* Size of the PCMCIA address space: 26 bits = 64 MB */
54#define MAX_PCMCIA_ADDR 0x4000000 54#define MAX_PCMCIA_ADDR 0x4000000
@@ -176,7 +176,7 @@ static void pcmcia_copy_from_remap(struct map_info *map, void *to, unsigned long
176 176
177 if(toread > len) 177 if(toread > len)
178 toread = len; 178 toread = len;
179 179
180 addr = remap_window(map, from); 180 addr = remap_window(map, from);
181 if(!addr) 181 if(!addr)
182 return; 182 return;
@@ -386,7 +386,7 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
386 cs_error(link->handle, ParseTuple, rc); 386 cs_error(link->handle, ParseTuple, rc);
387 break; 387 break;
388 } 388 }
389 389
390 switch(tuple.TupleCode) { 390 switch(tuple.TupleCode) {
391 case CISTPL_FORMAT: { 391 case CISTPL_FORMAT: {
392 cistpl_format_t *t = &parse.format; 392 cistpl_format_t *t = &parse.format;
@@ -394,9 +394,9 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
394 DEBUG(2, "Format type: %u, Error Detection: %u, offset = %u, length =%u", 394 DEBUG(2, "Format type: %u, Error Detection: %u, offset = %u, length =%u",
395 t->type, t->edc, t->offset, t->length); 395 t->type, t->edc, t->offset, t->length);
396 break; 396 break;
397 397
398 } 398 }
399 399
400 case CISTPL_DEVICE: { 400 case CISTPL_DEVICE: {
401 cistpl_device_t *t = &parse.device; 401 cistpl_device_t *t = &parse.device;
402 int i; 402 int i;
@@ -410,7 +410,7 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
410 } 410 }
411 break; 411 break;
412 } 412 }
413 413
414 case CISTPL_VERS_1: { 414 case CISTPL_VERS_1: {
415 cistpl_vers_1_t *t = &parse.version_1; 415 cistpl_vers_1_t *t = &parse.version_1;
416 int i; 416 int i;
@@ -425,7 +425,7 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
425 DEBUG(2, "Found name: %s", dev->mtd_name); 425 DEBUG(2, "Found name: %s", dev->mtd_name);
426 break; 426 break;
427 } 427 }
428 428
429 case CISTPL_JEDEC_C: { 429 case CISTPL_JEDEC_C: {
430 cistpl_jedec_t *t = &parse.jedec; 430 cistpl_jedec_t *t = &parse.jedec;
431 int i; 431 int i;
@@ -434,7 +434,7 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
434 } 434 }
435 break; 435 break;
436 } 436 }
437 437
438 case CISTPL_DEVICE_GEO: { 438 case CISTPL_DEVICE_GEO: {
439 cistpl_device_geo_t *t = &parse.device_geo; 439 cistpl_device_geo_t *t = &parse.device_geo;
440 int i; 440 int i;
@@ -449,11 +449,11 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
449 } 449 }
450 break; 450 break;
451 } 451 }
452 452
453 default: 453 default:
454 DEBUG(2, "Unknown tuple code %d", tuple.TupleCode); 454 DEBUG(2, "Unknown tuple code %d", tuple.TupleCode);
455 } 455 }
456 456
457 rc = pcmcia_get_next_tuple(link->handle, &tuple); 457 rc = pcmcia_get_next_tuple(link->handle, &tuple);
458 } 458 }
459 if(!dev->pcmcia_map.size) 459 if(!dev->pcmcia_map.size)
@@ -470,7 +470,7 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
470 if(bankwidth) { 470 if(bankwidth) {
471 dev->pcmcia_map.bankwidth = bankwidth; 471 dev->pcmcia_map.bankwidth = bankwidth;
472 DEBUG(2, "bankwidth forced to %d", bankwidth); 472 DEBUG(2, "bankwidth forced to %d", bankwidth);
473 } 473 }
474 474
475 dev->pcmcia_map.name = dev->mtd_name; 475 dev->pcmcia_map.name = dev->mtd_name;
476 if(!dev->mtd_name[0]) { 476 if(!dev->mtd_name[0]) {
@@ -568,7 +568,7 @@ static void pcmciamtd_config(dev_link_t *link)
568 return; 568 return;
569 } 569 }
570 DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10); 570 DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10);
571 571
572 /* Get write protect status */ 572 /* Get write protect status */
573 CS_CHECK(GetStatus, pcmcia_get_status(link->handle, &status)); 573 CS_CHECK(GetStatus, pcmcia_get_status(link->handle, &status));
574 DEBUG(2, "status value: 0x%x window handle = 0x%8.8lx", 574 DEBUG(2, "status value: 0x%x window handle = 0x%8.8lx",
@@ -624,11 +624,11 @@ static void pcmciamtd_config(dev_link_t *link)
624 mtd = do_map_probe(probes[i], &dev->pcmcia_map); 624 mtd = do_map_probe(probes[i], &dev->pcmcia_map);
625 if(mtd) 625 if(mtd)
626 break; 626 break;
627 627
628 DEBUG(1, "FAILED: %s", probes[i]); 628 DEBUG(1, "FAILED: %s", probes[i]);
629 } 629 }
630 } 630 }
631 631
632 if(!mtd) { 632 if(!mtd) {
633 DEBUG(1, "Cant find an MTD"); 633 DEBUG(1, "Cant find an MTD");
634 pcmciamtd_release(link); 634 pcmciamtd_release(link);
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index b853670bfb81..9ee760f97bc6 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: physmap.c,v 1.37 2004/11/28 09:40:40 dwmw2 Exp $ 2 * $Id: physmap.c,v 1.38 2005/11/07 11:14:28 gleixner Exp $
3 * 3 *
4 * Normal mappings of chips in physical memory 4 * Normal mappings of chips in physical memory
5 * 5 *
@@ -69,7 +69,7 @@ static int __init init_physmap(void)
69 mymtd->owner = THIS_MODULE; 69 mymtd->owner = THIS_MODULE;
70 70
71#ifdef CONFIG_MTD_PARTITIONS 71#ifdef CONFIG_MTD_PARTITIONS
72 mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes, 72 mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes,
73 &mtd_parts, 0); 73 &mtd_parts, 0);
74 74
75 if (mtd_parts_nb > 0) 75 if (mtd_parts_nb > 0)
@@ -78,9 +78,9 @@ static int __init init_physmap(void)
78 return 0; 78 return 0;
79 } 79 }
80 80
81 if (num_physmap_partitions != 0) 81 if (num_physmap_partitions != 0)
82 { 82 {
83 printk(KERN_NOTICE 83 printk(KERN_NOTICE
84 "Using physmap partition definition\n"); 84 "Using physmap partition definition\n");
85 add_mtd_partitions (mymtd, physmap_partitions, num_physmap_partitions); 85 add_mtd_partitions (mymtd, physmap_partitions, num_physmap_partitions);
86 return 0; 86 return 0;
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 104576b5be34..a02eed94a231 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -6,7 +6,7 @@
6 * 6 *
7 * Generic platfrom device based RAM map 7 * Generic platfrom device based RAM map
8 * 8 *
9 * $Id: plat-ram.c,v 1.3 2005/03/19 22:41:27 gleixner Exp $ 9 * $Id: plat-ram.c,v 1.7 2005/11/07 11:14:28 gleixner Exp $
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 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 12 * it under the terms of the GNU General Public License as published by
@@ -91,7 +91,7 @@ static int platram_remove(struct device *dev)
91 91
92 dev_dbg(dev, "removing device\n"); 92 dev_dbg(dev, "removing device\n");
93 93
94 if (info == NULL) 94 if (info == NULL)
95 return 0; 95 return 0;
96 96
97 if (info->mtd) { 97 if (info->mtd) {
@@ -118,7 +118,7 @@ static int platram_remove(struct device *dev)
118 118
119 if (info->map.virt != NULL) 119 if (info->map.virt != NULL)
120 iounmap(info->map.virt); 120 iounmap(info->map.virt);
121 121
122 kfree(info); 122 kfree(info);
123 123
124 return 0; 124 return 0;
@@ -139,7 +139,7 @@ static int platram_probe(struct device *dev)
139 int err = 0; 139 int err = 0;
140 140
141 dev_dbg(dev, "probe entered\n"); 141 dev_dbg(dev, "probe entered\n");
142 142
143 if (dev->platform_data == NULL) { 143 if (dev->platform_data == NULL) {
144 dev_err(dev, "no platform data supplied\n"); 144 dev_err(dev, "no platform data supplied\n");
145 err = -ENOENT; 145 err = -ENOENT;
@@ -177,7 +177,7 @@ static int platram_probe(struct device *dev)
177 177
178 info->map.phys = res->start; 178 info->map.phys = res->start;
179 info->map.size = (res->end - res->start) + 1; 179 info->map.size = (res->end - res->start) + 1;
180 info->map.name = pdata->mapname != NULL ? pdata->mapname : pd->name; 180 info->map.name = pdata->mapname != NULL ? pdata->mapname : (char *)pd->name;
181 info->map.bankwidth = pdata->bankwidth; 181 info->map.bankwidth = pdata->bankwidth;
182 182
183 /* register our usage of the memory area */ 183 /* register our usage of the memory area */
@@ -240,7 +240,7 @@ static int platram_probe(struct device *dev)
240 dev_err(dev, "add_mtd_device() failed\n"); 240 dev_err(dev, "add_mtd_device() failed\n");
241 err = -ENOMEM; 241 err = -ENOMEM;
242 } 242 }
243 243
244 dev_info(dev, "registered mtd device\n"); 244 dev_info(dev, "registered mtd device\n");
245 return err; 245 return err;
246 246
@@ -254,6 +254,7 @@ static int platram_probe(struct device *dev)
254 254
255static struct device_driver platram_driver = { 255static struct device_driver platram_driver = {
256 .name = "mtd-ram", 256 .name = "mtd-ram",
257 .owner = THIS_MODULE,
257 .bus = &platform_bus_type, 258 .bus = &platform_bus_type,
258 .probe = platram_probe, 259 .probe = platram_probe,
259 .remove = platram_remove, 260 .remove = platram_remove,
diff --git a/drivers/mtd/maps/pnc2000.c b/drivers/mtd/maps/pnc2000.c
index a0f43dad8985..d7e16c2d5c44 100644
--- a/drivers/mtd/maps/pnc2000.c
+++ b/drivers/mtd/maps/pnc2000.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * This code is GPL 6 * This code is GPL
7 * 7 *
8 * $Id: pnc2000.c,v 1.17 2004/11/16 18:29:02 dwmw2 Exp $ 8 * $Id: pnc2000.c,v 1.18 2005/11/07 11:14:28 gleixner Exp $
9 */ 9 */
10 10
11#include <linux/module.h> 11#include <linux/module.h>
@@ -21,7 +21,7 @@
21#define WINDOW_ADDR 0xbf000000 21#define WINDOW_ADDR 0xbf000000
22#define WINDOW_SIZE 0x00400000 22#define WINDOW_SIZE 0x00400000
23 23
24/* 24/*
25 * MAP DRIVER STUFF 25 * MAP DRIVER STUFF
26 */ 26 */
27 27
@@ -36,7 +36,7 @@ static struct map_info pnc_map = {
36 36
37 37
38/* 38/*
39 * MTD 'PARTITIONING' STUFF 39 * MTD 'PARTITIONING' STUFF
40 */ 40 */
41static struct mtd_partition pnc_partitions[3] = { 41static struct mtd_partition pnc_partitions[3] = {
42 { 42 {
@@ -56,7 +56,7 @@ static struct mtd_partition pnc_partitions[3] = {
56 } 56 }
57}; 57};
58 58
59/* 59/*
60 * This is the master MTD device for which all the others are just 60 * This is the master MTD device for which all the others are just
61 * auto-relocating aliases. 61 * auto-relocating aliases.
62 */ 62 */
diff --git a/drivers/mtd/maps/pq2fads.c b/drivers/mtd/maps/pq2fads.c
new file mode 100644
index 000000000000..fb78d87cc130
--- /dev/null
+++ b/drivers/mtd/maps/pq2fads.c
@@ -0,0 +1,88 @@
1/*
2 * drivers/mtd/maps/pq2fads.c
3 *
4 * Mapping for the flash SIMM on 8272ADS and PQ2FADS board
5 *
6 * Author: Vitaly Bordug <vbordug@ru.mvista.com>
7 *
8 * 2005 (c) MontaVista Software, Inc. This file is licensed under
9 * the terms of the GNU General Public License version 2. This program
10 * is licensed "as is" without any warranty of any kind, whether express
11 * or implied.
12 */
13
14#include <linux/module.h>
15#include <linux/types.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <asm/io.h>
19#include <asm/ppcboot.h>
20#include <linux/mtd/mtd.h>
21#include <linux/mtd/map.h>
22#include <linux/mtd/partitions.h>
23#include <linux/mtd/physmap.h>
24
25/*
26 NOTE: bank width and interleave relative to the installed flash
27 should have been chosen within MTD_CFI_GEOMETRY options.
28 */
29#define PQ2FADS_BANK_WIDTH 4
30
31static struct mtd_partition pq2fads_partitions[] = {
32 {
33#ifdef CONFIG_ADS8272
34 .name = "HRCW",
35 .size = 0x40000,
36 .offset = 0,
37 .mask_flags = MTD_WRITEABLE, /* force read-only */
38 }, {
39 .name = "User FS",
40 .size = 0x5c0000,
41 .offset = 0x40000,
42#else
43 .name = "User FS",
44 .size = 0x600000,
45 .offset = 0,
46#endif
47 }, {
48 .name = "uImage",
49 .size = 0x100000,
50 .offset = 0x600000,
51 .mask_flags = MTD_WRITEABLE, /* force read-only */
52 }, {
53 .name = "bootloader",
54 .size = 0x40000,
55 .offset = 0x700000,
56 .mask_flags = MTD_WRITEABLE, /* force read-only */
57 }, {
58 .name = "bootloader env",
59 .size = 0x40000,
60 .offset = 0x740000,
61 .mask_flags = MTD_WRITEABLE, /* force read-only */
62 }
63};
64
65
66/* pointer to MPC885ADS board info data */
67extern unsigned char __res[];
68
69static int __init init_pq2fads_mtd(void)
70{
71 bd_t *bd = (bd_t *)__res;
72 physmap_configure(bd->bi_flashstart, bd->bi_flashsize, PQ2FADS_BANK_WIDTH, NULL);
73
74 physmap_set_partitions(pq2fads_partitions,
75 sizeof (pq2fads_partitions) /
76 sizeof (pq2fads_partitions[0]));
77 return 0;
78}
79
80static void __exit cleanup_pq2fads_mtd(void)
81{
82}
83
84module_init(init_pq2fads_mtd);
85module_exit(cleanup_pq2fads_mtd);
86
87MODULE_LICENSE("GPL");
88MODULE_DESCRIPTION("MTD map and partitions for MPC8272ADS boards");
diff --git a/drivers/mtd/maps/redwood.c b/drivers/mtd/maps/redwood.c
index edd01ee4f90b..5b76ed886185 100644
--- a/drivers/mtd/maps/redwood.c
+++ b/drivers/mtd/maps/redwood.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: redwood.c,v 1.10 2004/11/04 13:24:15 gleixner Exp $ 2 * $Id: redwood.c,v 1.11 2005/11/07 11:14:28 gleixner Exp $
3 * 3 *
4 * drivers/mtd/maps/redwood.c 4 * drivers/mtd/maps/redwood.c
5 * 5 *
@@ -79,7 +79,7 @@ static struct mtd_partition redwood_flash_partitions[] = {
79 79
80#define RW_PART0_OF 0 80#define RW_PART0_OF 0
81#define RW_PART0_SZ 0x400000 /* 4 MiB data */ 81#define RW_PART0_SZ 0x400000 /* 4 MiB data */
82#define RW_PART1_OF RW_PART0_OF + RW_PART0_SZ 82#define RW_PART1_OF RW_PART0_OF + RW_PART0_SZ
83#define RW_PART1_SZ 0x10000 /* 64K VPD */ 83#define RW_PART1_SZ 0x10000 /* 64K VPD */
84#define RW_PART2_OF RW_PART1_OF + RW_PART1_SZ 84#define RW_PART2_OF RW_PART1_OF + RW_PART1_SZ
85#define RW_PART2_SZ 0x400000 - (0x10000 + 0x20000) 85#define RW_PART2_SZ 0x400000 - (0x10000 + 0x20000)
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index c8d0da19d897..9e8bb1782be0 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * Flash memory access on SA11x0 based devices 2 * Flash memory access on SA11x0 based devices
3 * 3 *
4 * (C) 2000 Nicolas Pitre <nico@cam.org> 4 * (C) 2000 Nicolas Pitre <nico@cam.org>
5 * 5 *
6 * $Id: sa1100-flash.c,v 1.47 2004/11/01 13:44:36 rmk Exp $ 6 * $Id: sa1100-flash.c,v 1.51 2005/11/07 11:14:28 gleixner Exp $
7 */ 7 */
8#include <linux/config.h> 8#include <linux/config.h>
9#include <linux/module.h> 9#include <linux/module.h>
@@ -241,8 +241,7 @@ static void sa1100_destroy(struct sa_info *info, struct flash_platform_data *pla
241#endif 241#endif
242 } 242 }
243 243
244 if (info->parts) 244 kfree(info->parts);
245 kfree(info->parts);
246 245
247 for (i = info->num_subdev - 1; i >= 0; i--) 246 for (i = info->num_subdev - 1; i >= 0; i--)
248 sa1100_destroy_subdev(&info->subdev[i]); 247 sa1100_destroy_subdev(&info->subdev[i]);
diff --git a/drivers/mtd/maps/sbc8240.c b/drivers/mtd/maps/sbc8240.c
index da684d3384e9..225cdd9ba5b2 100644
--- a/drivers/mtd/maps/sbc8240.c
+++ b/drivers/mtd/maps/sbc8240.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * This code is GPLed 6 * This code is GPLed
7 * 7 *
8 * $Id: sbc8240.c,v 1.4 2004/07/12 22:38:29 dwmw2 Exp $ 8 * $Id: sbc8240.c,v 1.5 2005/11/07 11:14:28 gleixner Exp $
9 * 9 *
10 */ 10 */
11 11
@@ -205,7 +205,7 @@ int __init init_sbc8240_mtd (void)
205 } else { 205 } else {
206 printk (KERN_NOTICE MSG_PREFIX 206 printk (KERN_NOTICE MSG_PREFIX
207 "Using %s partition definition\n", sbc8240_part_banks[i].mtd_part->name); 207 "Using %s partition definition\n", sbc8240_part_banks[i].mtd_part->name);
208 add_mtd_partitions (sbc8240_mtd[i], 208 add_mtd_partitions (sbc8240_mtd[i],
209 sbc8240_part_banks[i].mtd_part, 209 sbc8240_part_banks[i].mtd_part,
210 sbc8240_part_banks[i].nums); 210 sbc8240_part_banks[i].nums);
211 } 211 }
diff --git a/drivers/mtd/maps/sbc_gxx.c b/drivers/mtd/maps/sbc_gxx.c
index 65add28bde14..7cc4041d096d 100644
--- a/drivers/mtd/maps/sbc_gxx.c
+++ b/drivers/mtd/maps/sbc_gxx.c
@@ -1,35 +1,35 @@
1/* sbc_gxx.c -- MTD map driver for Arcom Control Systems SBC-MediaGX, 1/* sbc_gxx.c -- MTD map driver for Arcom Control Systems SBC-MediaGX,
2 SBC-GXm and SBC-GX1 series boards. 2 SBC-GXm and SBC-GX1 series boards.
3 3
4 Copyright (C) 2001 Arcom Control System Ltd 4 Copyright (C) 2001 Arcom Control System Ltd
5 5
6 This program is free software; you can redistribute it and/or modify 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 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 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 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 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 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 19
20 $Id: sbc_gxx.c,v 1.33 2004/11/28 09:40:40 dwmw2 Exp $ 20 $Id: sbc_gxx.c,v 1.35 2005/11/07 11:14:28 gleixner Exp $
21 21
22The SBC-MediaGX / SBC-GXx has up to 16 MiB of 22The SBC-MediaGX / SBC-GXx has up to 16 MiB of
23Intel StrataFlash (28F320/28F640) in x8 mode. 23Intel StrataFlash (28F320/28F640) in x8 mode.
24 24
25This driver uses the CFI probe and Intel Extended Command Set drivers. 25This driver uses the CFI probe and Intel Extended Command Set drivers.
26 26
27The flash is accessed as follows: 27The flash is accessed as follows:
28 28
29 16 KiB memory window at 0xdc000-0xdffff 29 16 KiB memory window at 0xdc000-0xdffff
30 30
31 Two IO address locations for paging 31 Two IO address locations for paging
32 32
33 0x258 33 0x258
34 bit 0-7: address bit 14-21 34 bit 0-7: address bit 14-21
35 0x259 35 0x259
@@ -37,7 +37,7 @@ The flash is accessed as follows:
37 bit 7: 0 - reset/powered down 37 bit 7: 0 - reset/powered down
38 1 - device enabled 38 1 - device enabled
39 39
40The single flash device is divided into 3 partition which appear as 40The single flash device is divided into 3 partition which appear as
41separate MTD devices. 41separate MTD devices.
42 42
4325/04/2001 AJL (Arcom) Modified signon strings and partition sizes 4325/04/2001 AJL (Arcom) Modified signon strings and partition sizes
@@ -87,17 +87,17 @@ static volatile int page_in_window = -1; // Current page in window.
87static void __iomem *iomapadr; 87static void __iomem *iomapadr;
88static DEFINE_SPINLOCK(sbc_gxx_spin); 88static DEFINE_SPINLOCK(sbc_gxx_spin);
89 89
90/* partition_info gives details on the logical partitions that the split the 90/* partition_info gives details on the logical partitions that the split the
91 * single flash device into. If the size if zero we use up to the end of the 91 * single flash device into. If the size if zero we use up to the end of the
92 * device. */ 92 * device. */
93static struct mtd_partition partition_info[]={ 93static struct mtd_partition partition_info[]={
94 { .name = "SBC-GXx flash boot partition", 94 { .name = "SBC-GXx flash boot partition",
95 .offset = 0, 95 .offset = 0,
96 .size = BOOT_PARTITION_SIZE_KiB*1024 }, 96 .size = BOOT_PARTITION_SIZE_KiB*1024 },
97 { .name = "SBC-GXx flash data partition", 97 { .name = "SBC-GXx flash data partition",
98 .offset = BOOT_PARTITION_SIZE_KiB*1024, 98 .offset = BOOT_PARTITION_SIZE_KiB*1024,
99 .size = (DATA_PARTITION_SIZE_KiB)*1024 }, 99 .size = (DATA_PARTITION_SIZE_KiB)*1024 },
100 { .name = "SBC-GXx flash application partition", 100 { .name = "SBC-GXx flash application partition",
101 .offset = (BOOT_PARTITION_SIZE_KiB+DATA_PARTITION_SIZE_KiB)*1024 } 101 .offset = (BOOT_PARTITION_SIZE_KiB+DATA_PARTITION_SIZE_KiB)*1024 }
102}; 102};
103 103
@@ -130,7 +130,7 @@ static void sbc_gxx_copy_from(struct map_info *map, void *to, unsigned long from
130 unsigned long thislen = len; 130 unsigned long thislen = len;
131 if (len > (WINDOW_LENGTH - (from & WINDOW_MASK))) 131 if (len > (WINDOW_LENGTH - (from & WINDOW_MASK)))
132 thislen = WINDOW_LENGTH-(from & WINDOW_MASK); 132 thislen = WINDOW_LENGTH-(from & WINDOW_MASK);
133 133
134 spin_lock(&sbc_gxx_spin); 134 spin_lock(&sbc_gxx_spin);
135 sbc_gxx_page(map, from); 135 sbc_gxx_page(map, from);
136 memcpy_fromio(to, iomapadr + (from & WINDOW_MASK), thislen); 136 memcpy_fromio(to, iomapadr + (from & WINDOW_MASK), thislen);
@@ -150,12 +150,12 @@ static void sbc_gxx_write8(struct map_info *map, map_word d, unsigned long adr)
150} 150}
151 151
152static void sbc_gxx_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) 152static void sbc_gxx_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
153{ 153{
154 while(len) { 154 while(len) {
155 unsigned long thislen = len; 155 unsigned long thislen = len;
156 if (len > (WINDOW_LENGTH - (to & WINDOW_MASK))) 156 if (len > (WINDOW_LENGTH - (to & WINDOW_MASK)))
157 thislen = WINDOW_LENGTH-(to & WINDOW_MASK); 157 thislen = WINDOW_LENGTH-(to & WINDOW_MASK);
158 158
159 spin_lock(&sbc_gxx_spin); 159 spin_lock(&sbc_gxx_spin);
160 sbc_gxx_page(map, to); 160 sbc_gxx_page(map, to);
161 memcpy_toio(iomapadr + (to & WINDOW_MASK), from, thislen); 161 memcpy_toio(iomapadr + (to & WINDOW_MASK), from, thislen);
@@ -201,7 +201,7 @@ static int __init init_sbc_gxx(void)
201 sbc_gxx_map.name ); 201 sbc_gxx_map.name );
202 return -EIO; 202 return -EIO;
203 } 203 }
204 204
205 if (!request_region( PAGE_IO, PAGE_IO_SIZE, "SBC-GXx flash")) { 205 if (!request_region( PAGE_IO, PAGE_IO_SIZE, "SBC-GXx flash")) {
206 printk( KERN_ERR"%s: IO ports 0x%x-0x%x in use\n", 206 printk( KERN_ERR"%s: IO ports 0x%x-0x%x in use\n",
207 sbc_gxx_map.name, 207 sbc_gxx_map.name,
@@ -209,8 +209,8 @@ static int __init init_sbc_gxx(void)
209 iounmap(iomapadr); 209 iounmap(iomapadr);
210 return -EAGAIN; 210 return -EAGAIN;
211 } 211 }
212 212
213 213
214 printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n", 214 printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n",
215 sbc_gxx_map.name, 215 sbc_gxx_map.name,
216 PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1, 216 PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1,
@@ -222,7 +222,7 @@ static int __init init_sbc_gxx(void)
222 cleanup_sbc_gxx(); 222 cleanup_sbc_gxx();
223 return -ENXIO; 223 return -ENXIO;
224 } 224 }
225 225
226 all_mtd->owner = THIS_MODULE; 226 all_mtd->owner = THIS_MODULE;
227 227
228 /* Create MTD devices for each partition. */ 228 /* Create MTD devices for each partition. */
diff --git a/drivers/mtd/maps/sc520cdp.c b/drivers/mtd/maps/sc520cdp.c
index a06ed21e7ed1..6fb9f3c57aab 100644
--- a/drivers/mtd/maps/sc520cdp.c
+++ b/drivers/mtd/maps/sc520cdp.c
@@ -16,7 +16,7 @@
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 * 18 *
19 * $Id: sc520cdp.c,v 1.21 2004/12/13 10:27:08 dedekind Exp $ 19 * $Id: sc520cdp.c,v 1.22 2005/11/07 11:14:28 gleixner Exp $
20 * 20 *
21 * 21 *
22 * The SC520CDP is an evaluation board for the Elan SC520 processor available 22 * The SC520CDP is an evaluation board for the Elan SC520 processor available
@@ -231,7 +231,7 @@ static void sc520cdp_setup_par(void)
231static int __init init_sc520cdp(void) 231static int __init init_sc520cdp(void)
232{ 232{
233 int i, devices_found = 0; 233 int i, devices_found = 0;
234 234
235#ifdef REPROGRAM_PAR 235#ifdef REPROGRAM_PAR
236 /* reprogram PAR registers so flash appears at the desired addresses */ 236 /* reprogram PAR registers so flash appears at the desired addresses */
237 sc520cdp_setup_par(); 237 sc520cdp_setup_par();
@@ -278,7 +278,7 @@ static int __init init_sc520cdp(void)
278static void __exit cleanup_sc520cdp(void) 278static void __exit cleanup_sc520cdp(void)
279{ 279{
280 int i; 280 int i;
281 281
282 if (merged_mtd) { 282 if (merged_mtd) {
283 del_mtd_device(merged_mtd); 283 del_mtd_device(merged_mtd);
284 mtd_concat_destroy(merged_mtd); 284 mtd_concat_destroy(merged_mtd);
diff --git a/drivers/mtd/maps/scx200_docflash.c b/drivers/mtd/maps/scx200_docflash.c
index 0ece3786d6ea..2c91dff8bb60 100644
--- a/drivers/mtd/maps/scx200_docflash.c
+++ b/drivers/mtd/maps/scx200_docflash.c
@@ -1,8 +1,8 @@
1/* linux/drivers/mtd/maps/scx200_docflash.c 1/* linux/drivers/mtd/maps/scx200_docflash.c
2 2
3 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com> 3 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
4 4
5 $Id: scx200_docflash.c,v 1.10 2004/11/28 09:40:40 dwmw2 Exp $ 5 $Id: scx200_docflash.c,v 1.12 2005/11/07 11:14:28 gleixner Exp $
6 6
7 National Semiconductor SCx200 flash mapped with DOCCS 7 National Semiconductor SCx200 flash mapped with DOCCS
8*/ 8*/
@@ -49,23 +49,23 @@ static struct mtd_info *mymtd;
49 49
50#ifdef CONFIG_MTD_PARTITIONS 50#ifdef CONFIG_MTD_PARTITIONS
51static struct mtd_partition partition_info[] = { 51static struct mtd_partition partition_info[] = {
52 { 52 {
53 .name = "DOCCS Boot kernel", 53 .name = "DOCCS Boot kernel",
54 .offset = 0, 54 .offset = 0,
55 .size = 0xc0000 55 .size = 0xc0000
56 }, 56 },
57 { 57 {
58 .name = "DOCCS Low BIOS", 58 .name = "DOCCS Low BIOS",
59 .offset = 0xc0000, 59 .offset = 0xc0000,
60 .size = 0x40000 60 .size = 0x40000
61 }, 61 },
62 { 62 {
63 .name = "DOCCS File system", 63 .name = "DOCCS File system",
64 .offset = 0x100000, 64 .offset = 0x100000,
65 .size = ~0 /* calculate from flash size */ 65 .size = ~0 /* calculate from flash size */
66 }, 66 },
67 { 67 {
68 .name = "DOCCS High BIOS", 68 .name = "DOCCS High BIOS",
69 .offset = ~0, /* calculate from flash size */ 69 .offset = ~0, /* calculate from flash size */
70 .size = 0x80000 70 .size = 0x80000
71 }, 71 },
@@ -88,7 +88,7 @@ static int __init init_scx200_docflash(void)
88 88
89 printk(KERN_DEBUG NAME ": NatSemi SCx200 DOCCS Flash Driver\n"); 89 printk(KERN_DEBUG NAME ": NatSemi SCx200 DOCCS Flash Driver\n");
90 90
91 if ((bridge = pci_find_device(PCI_VENDOR_ID_NS, 91 if ((bridge = pci_find_device(PCI_VENDOR_ID_NS,
92 PCI_DEVICE_ID_NS_SCx200_BRIDGE, 92 PCI_DEVICE_ID_NS_SCx200_BRIDGE,
93 NULL)) == NULL) 93 NULL)) == NULL)
94 return -ENODEV; 94 return -ENODEV;
@@ -134,28 +134,28 @@ static int __init init_scx200_docflash(void)
134 printk(KERN_ERR NAME ": invalid size for flash mapping\n"); 134 printk(KERN_ERR NAME ": invalid size for flash mapping\n");
135 return -EINVAL; 135 return -EINVAL;
136 } 136 }
137 137
138 if (width != 8 && width != 16) { 138 if (width != 8 && width != 16) {
139 printk(KERN_ERR NAME ": invalid bus width for flash mapping\n"); 139 printk(KERN_ERR NAME ": invalid bus width for flash mapping\n");
140 return -EINVAL; 140 return -EINVAL;
141 } 141 }
142 142
143 if (allocate_resource(&iomem_resource, &docmem, 143 if (allocate_resource(&iomem_resource, &docmem,
144 size, 144 size,
145 0xc0000000, 0xffffffff, 145 0xc0000000, 0xffffffff,
146 size, NULL, NULL)) { 146 size, NULL, NULL)) {
147 printk(KERN_ERR NAME ": unable to allocate memory for flash mapping\n"); 147 printk(KERN_ERR NAME ": unable to allocate memory for flash mapping\n");
148 return -ENOMEM; 148 return -ENOMEM;
149 } 149 }
150 150
151 ctrl = 0x07000000 | ((size-1) >> 13); 151 ctrl = 0x07000000 | ((size-1) >> 13);
152 152
153 printk(KERN_INFO "DOCCS BASE=0x%08lx, CTRL=0x%08lx\n", (long)docmem.start, (long)ctrl); 153 printk(KERN_INFO "DOCCS BASE=0x%08lx, CTRL=0x%08lx\n", (long)docmem.start, (long)ctrl);
154 154
155 pci_write_config_dword(bridge, SCx200_DOCCS_BASE, docmem.start); 155 pci_write_config_dword(bridge, SCx200_DOCCS_BASE, docmem.start);
156 pci_write_config_dword(bridge, SCx200_DOCCS_CTRL, ctrl); 156 pci_write_config_dword(bridge, SCx200_DOCCS_CTRL, ctrl);
157 pmr = inl(scx200_cb_base + SCx200_PMR); 157 pmr = inl(scx200_cb_base + SCx200_PMR);
158 158
159 if (width == 8) { 159 if (width == 8) {
160 pmr &= ~(1<<6); 160 pmr &= ~(1<<6);
161 } else { 161 } else {
@@ -163,8 +163,8 @@ static int __init init_scx200_docflash(void)
163 } 163 }
164 outl(pmr, scx200_cb_base + SCx200_PMR); 164 outl(pmr, scx200_cb_base + SCx200_PMR);
165 } 165 }
166 166
167 printk(KERN_INFO NAME ": DOCCS mapped at 0x%lx-0x%lx, width %d\n", 167 printk(KERN_INFO NAME ": DOCCS mapped at 0x%lx-0x%lx, width %d\n",
168 docmem.start, docmem.end, width); 168 docmem.start, docmem.end, width);
169 169
170 scx200_docflash_map.size = size; 170 scx200_docflash_map.size = size;
diff --git a/drivers/mtd/maps/sharpsl-flash.c b/drivers/mtd/maps/sharpsl-flash.c
index b7f093fbf9b0..999f4bb3d845 100644
--- a/drivers/mtd/maps/sharpsl-flash.c
+++ b/drivers/mtd/maps/sharpsl-flash.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * sharpsl-flash.c 2 * sharpsl-flash.c
3 * 3 *
4 * Copyright (C) 2001 Lineo Japan, Inc. 4 * Copyright (C) 2001 Lineo Japan, Inc.
5 * Copyright (C) 2002 SHARP 5 * Copyright (C) 2002 SHARP
6 * 6 *
7 * $Id: sharpsl-flash.c,v 1.5 2005/03/21 08:42:11 rpurdie Exp $ 7 * $Id: sharpsl-flash.c,v 1.7 2005/11/07 11:14:28 gleixner Exp $
8 * 8 *
9 * based on rpxlite.c,v 1.15 2001/10/02 15:05:14 dwmw2 Exp 9 * based on rpxlite.c,v 1.15 2001/10/02 15:05:14 dwmw2 Exp
10 * Handle mapping of the flash on the RPX Lite and CLLF boards 10 * Handle mapping of the flash on the RPX Lite and CLLF boards
@@ -57,7 +57,7 @@ int __init init_sharpsl(void)
57 int nb_parts = 0; 57 int nb_parts = 0;
58 char *part_type = "static"; 58 char *part_type = "static";
59 59
60 printk(KERN_NOTICE "Sharp SL series flash device: %x at %x\n", 60 printk(KERN_NOTICE "Sharp SL series flash device: %x at %x\n",
61 WINDOW_SIZE, WINDOW_ADDR); 61 WINDOW_SIZE, WINDOW_ADDR);
62 sharpsl_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE); 62 sharpsl_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
63 if (!sharpsl_map.virt) { 63 if (!sharpsl_map.virt) {
@@ -75,7 +75,7 @@ int __init init_sharpsl(void)
75 75
76 mymtd->owner = THIS_MODULE; 76 mymtd->owner = THIS_MODULE;
77 77
78 if (machine_is_corgi() || machine_is_shepherd() || machine_is_husky() 78 if (machine_is_corgi() || machine_is_shepherd() || machine_is_husky()
79 || machine_is_poodle()) { 79 || machine_is_poodle()) {
80 sharpsl_partitions[0].size=0x006d0000; 80 sharpsl_partitions[0].size=0x006d0000;
81 sharpsl_partitions[0].offset=0x00120000; 81 sharpsl_partitions[0].offset=0x00120000;
@@ -87,10 +87,10 @@ int __init init_sharpsl(void)
87 sharpsl_partitions[0].offset=0x00140000; 87 sharpsl_partitions[0].offset=0x00140000;
88 } else { 88 } else {
89 map_destroy(mymtd); 89 map_destroy(mymtd);
90 iounmap(sharpsl_map.virt); 90 iounmap(sharpsl_map.virt);
91 return -ENODEV; 91 return -ENODEV;
92 } 92 }
93 93
94 parts = sharpsl_partitions; 94 parts = sharpsl_partitions;
95 nb_parts = NB_OF(sharpsl_partitions); 95 nb_parts = NB_OF(sharpsl_partitions);
96 96
diff --git a/drivers/mtd/maps/solutionengine.c b/drivers/mtd/maps/solutionengine.c
index 8ce5d897645c..c53c2c369c9d 100644
--- a/drivers/mtd/maps/solutionengine.c
+++ b/drivers/mtd/maps/solutionengine.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: solutionengine.c,v 1.14 2004/09/16 23:27:14 gleixner Exp $ 2 * $Id: solutionengine.c,v 1.15 2005/11/07 11:14:28 gleixner Exp $
3 * 3 *
4 * Flash and EPROM on Hitachi Solution Engine and similar boards. 4 * Flash and EPROM on Hitachi Solution Engine and similar boards.
5 * 5 *
@@ -67,7 +67,7 @@ static int __init init_soleng_maps(void)
67 soleng_eprom_map.virt = (void __iomem *)P1SEGADDR(0x01000000); 67 soleng_eprom_map.virt = (void __iomem *)P1SEGADDR(0x01000000);
68 simple_map_init(&soleng_eprom_map); 68 simple_map_init(&soleng_eprom_map);
69 simple_map_init(&soleng_flash_map); 69 simple_map_init(&soleng_flash_map);
70 70
71 printk(KERN_NOTICE "Probing for flash chips at 0x00000000:\n"); 71 printk(KERN_NOTICE "Probing for flash chips at 0x00000000:\n");
72 flash_mtd = do_map_probe("cfi_probe", &soleng_flash_map); 72 flash_mtd = do_map_probe("cfi_probe", &soleng_flash_map);
73 if (!flash_mtd) { 73 if (!flash_mtd) {
diff --git a/drivers/mtd/maps/sun_uflash.c b/drivers/mtd/maps/sun_uflash.c
index 29091d10030a..0758cb1d0105 100644
--- a/drivers/mtd/maps/sun_uflash.c
+++ b/drivers/mtd/maps/sun_uflash.c
@@ -1,4 +1,4 @@
1/* $Id: sun_uflash.c,v 1.11 2004/11/04 13:24:15 gleixner Exp $ 1/* $Id: sun_uflash.c,v 1.13 2005/11/07 11:14:28 gleixner Exp $
2 * 2 *
3 * sun_uflash - Driver implementation for user-programmable flash 3 * sun_uflash - Driver implementation for user-programmable flash
4 * present on many Sun Microsystems SME boardsets. 4 * present on many Sun Microsystems SME boardsets.
@@ -63,7 +63,7 @@ int uflash_devinit(struct linux_ebus_device* edev)
63 iTmp = prom_getproperty( 63 iTmp = prom_getproperty(
64 edev->prom_node, "reg", (void *)regs, sizeof(regs)); 64 edev->prom_node, "reg", (void *)regs, sizeof(regs));
65 if ((iTmp % sizeof(regs[0])) != 0) { 65 if ((iTmp % sizeof(regs[0])) != 0) {
66 printk("%s: Strange reg property size %d\n", 66 printk("%s: Strange reg property size %d\n",
67 UFLASH_DEVNAME, iTmp); 67 UFLASH_DEVNAME, iTmp);
68 return -ENODEV; 68 return -ENODEV;
69 } 69 }
@@ -75,7 +75,7 @@ int uflash_devinit(struct linux_ebus_device* edev)
75 * can work on supporting it. 75 * can work on supporting it.
76 */ 76 */
77 printk("%s: unsupported device at 0x%lx (%d regs): " \ 77 printk("%s: unsupported device at 0x%lx (%d regs): " \
78 "email ebrower@usa.net\n", 78 "email ebrower@usa.net\n",
79 UFLASH_DEVNAME, edev->resource[0].start, nregs); 79 UFLASH_DEVNAME, edev->resource[0].start, nregs);
80 return -ENODEV; 80 return -ENODEV;
81 } 81 }
@@ -84,7 +84,7 @@ int uflash_devinit(struct linux_ebus_device* edev)
84 printk("%s: unable to kmalloc new device\n", UFLASH_DEVNAME); 84 printk("%s: unable to kmalloc new device\n", UFLASH_DEVNAME);
85 return(-ENOMEM); 85 return(-ENOMEM);
86 } 86 }
87 87
88 /* copy defaults and tweak parameters */ 88 /* copy defaults and tweak parameters */
89 memcpy(&pdev->map, &uflash_map_templ, sizeof(uflash_map_templ)); 89 memcpy(&pdev->map, &uflash_map_templ, sizeof(uflash_map_templ));
90 pdev->map.size = regs[0].reg_size; 90 pdev->map.size = regs[0].reg_size;
@@ -155,7 +155,7 @@ static void __exit uflash_cleanup(void)
155 155
156 list_for_each(udevlist, &device_list) { 156 list_for_each(udevlist, &device_list) {
157 udev = list_entry(udevlist, struct uflash_dev, list); 157 udev = list_entry(udevlist, struct uflash_dev, list);
158 DEBUG(2, "%s: removing device %s\n", 158 DEBUG(2, "%s: removing device %s\n",
159 UFLASH_DEVNAME, udev->name); 159 UFLASH_DEVNAME, udev->name);
160 160
161 if(0 != udev->mtd) { 161 if(0 != udev->mtd) {
@@ -166,11 +166,9 @@ static void __exit uflash_cleanup(void)
166 iounmap(udev->map.virt); 166 iounmap(udev->map.virt);
167 udev->map.virt = NULL; 167 udev->map.virt = NULL;
168 } 168 }
169 if(0 != udev->name) { 169 kfree(udev->name);
170 kfree(udev->name);
171 }
172 kfree(udev); 170 kfree(udev);
173 } 171 }
174} 172}
175 173
176module_init(uflash_init); 174module_init(uflash_init);
diff --git a/drivers/mtd/maps/tqm834x.c b/drivers/mtd/maps/tqm834x.c
new file mode 100644
index 000000000000..c7ae9a515c1a
--- /dev/null
+++ b/drivers/mtd/maps/tqm834x.c
@@ -0,0 +1,291 @@
1/*
2 * drivers/mtd/maps/tqm834x.c
3 *
4 * MTD mapping driver for TQM834x boards
5 *
6 * Copyright 2005 Wolfgang Denk, DENX Software Engineering, <wd@denx.de>.
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
11 *
12 */
13
14#include <linux/config.h>
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/types.h>
18#include <linux/kernel.h>
19#include <linux/slab.h>
20#include <asm/io.h>
21#include <asm/ppcboot.h>
22
23#include <linux/mtd/mtd.h>
24#include <linux/mtd/map.h>
25#include <linux/mtd/partitions.h>
26
27#define FLASH_BANK_MAX 2
28
29extern unsigned char __res[];
30
31/* trivial struct to describe partition information */
32struct mtd_part_def
33{
34 int nums;
35 unsigned char *type;
36 struct mtd_partition* mtd_part;
37};
38
39static struct mtd_info* mtd_banks[FLASH_BANK_MAX];
40static struct map_info* map_banks[FLASH_BANK_MAX];
41static struct mtd_part_def part_banks[FLASH_BANK_MAX];
42
43static unsigned long num_banks;
44static unsigned long start_scan_addr;
45
46#ifdef CONFIG_MTD_PARTITIONS
47/*
48 * The following defines the partition layout of TQM834x boards.
49 *
50 * See include/linux/mtd/partitions.h for definition of the
51 * mtd_partition structure.
52 *
53 * Assume minimal initial size of 4 MiB per bank, will be updated
54 * later in init_tqm834x_mtd() routine.
55 */
56
57/* Partition definition for the first flash bank which is always present. */
58static struct mtd_partition tqm834x_partitions_bank1[] = {
59 {
60 .name = "u-boot", /* u-boot firmware */
61 .offset = 0x00000000,
62 .size = 0x00040000, /* 256 KiB */
63 /*mask_flags: MTD_WRITEABLE, * force read-only */
64 },
65 {
66 .name = "env", /* u-boot environment */
67 .offset = 0x00040000,
68 .size = 0x00020000, /* 128 KiB */
69 /*mask_flags: MTD_WRITEABLE, * force read-only */
70 },
71 {
72 .name = "kernel", /* linux kernel image */
73 .offset = 0x00060000,
74 .size = 0x00100000, /* 1 MiB */
75 /*mask_flags: MTD_WRITEABLE, * force read-only */
76 },
77 {
78 .name = "initrd", /* ramdisk image */
79 .offset = 0x00160000,
80 .size = 0x00200000, /* 2 MiB */
81 },
82 {
83 .name = "user", /* user data */
84 .offset = 0x00360000,
85 .size = 0x000a0000, /* remaining space */
86 /* NOTE: this parttion size is re-calcated in */
87 /* init_tqm834x_mtd() to cover actual remaining space. */
88 },
89};
90
91/* Partition definition for the second flash bank which may be present on some
92 * TQM834x boards.
93 */
94static struct mtd_partition tqm834x_partitions_bank2[] = {
95 {
96 .name = "jffs2", /* jffs2 filesystem */
97 .offset = 0x00000000,
98 .size = 0x00400000, /* whole device */
99 /* NOTE: this parttion size is re-calcated in */
100 /* init_tqm834x_mtd() to cover actual device size. */
101 },
102};
103
104#endif /* CONFIG_MTD_PARTITIONS */
105
106static int __init init_tqm834x_mtd(void)
107{
108 int idx = 0, ret = 0;
109 unsigned long flash_addr, flash_size, mtd_size = 0;
110
111 /* pointer to TQM834x board info data */
112 bd_t *bd = (bd_t *)__res;
113#ifdef CONFIG_MTD_CMDLINE_PARTS
114 int n;
115 char mtdid[4];
116 const char *part_probes[] = { "cmdlinepart", NULL };
117#endif
118
119 flash_addr = bd->bi_flashstart;
120 flash_size = bd->bi_flashsize;
121
122 /* request maximum flash size address space */
123 start_scan_addr = (unsigned long)ioremap(flash_addr, flash_size);
124 if (!start_scan_addr) {
125 printk("%s: Failed to ioremap address: 0x%lx\n",
126 __FUNCTION__, flash_addr);
127 return -EIO;
128 }
129
130 for(idx = 0 ; idx < FLASH_BANK_MAX ; idx++) {
131 if (mtd_size >= flash_size)
132 break;
133
134 pr_debug("%s: chip probing count %d\n", __FUNCTION__, idx);
135
136 map_banks[idx] =
137 (struct map_info *)kmalloc(sizeof(struct map_info),
138 GFP_KERNEL);
139 if (map_banks[idx] == NULL) {
140 ret = -ENOMEM;
141 goto error_mem;
142 }
143 memset((void *)map_banks[idx], 0, sizeof(struct map_info));
144 map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
145 if (map_banks[idx]->name == NULL) {
146 ret = -ENOMEM;
147 goto error_mem;
148 }
149 memset((void *)map_banks[idx]->name, 0, 16);
150
151 sprintf(map_banks[idx]->name, "TQM834x-%d", idx);
152 map_banks[idx]->size = flash_size;
153 map_banks[idx]->bankwidth = 4;
154
155 simple_map_init(map_banks[idx]);
156
157 map_banks[idx]->virt = (void __iomem *)
158 (start_scan_addr + ((idx > 0) ?
159 (mtd_banks[idx-1] ? mtd_banks[idx-1]->size : 0) : 0));
160 map_banks[idx]->phys =
161 flash_addr + ((idx > 0) ?
162 (mtd_banks[idx-1] ? mtd_banks[idx-1]->size : 0) : 0);
163
164 /* start to probe flash chips */
165 mtd_banks[idx] = do_map_probe("cfi_probe", map_banks[idx]);
166 if (mtd_banks[idx]) {
167 mtd_banks[idx]->owner = THIS_MODULE;
168 mtd_size += mtd_banks[idx]->size;
169 num_banks++;
170 pr_debug("%s: bank %ld, name: %s, size: %d bytes \n",
171 __FUNCTION__, num_banks,
172 mtd_banks[idx]->name, mtd_banks[idx]->size);
173 }
174 }
175
176 /* no supported flash chips found */
177 if (!num_banks) {
178 printk("TQM834x: No supported flash chips found!\n");
179 ret = -ENXIO;
180 goto error_mem;
181 }
182
183#ifdef CONFIG_MTD_PARTITIONS
184 /*
185 * Select static partition definitions
186 */
187 n = ARRAY_SIZE(tqm834x_partitions_bank1);
188 part_banks[0].mtd_part = tqm834x_partitions_bank1;
189 part_banks[0].type = "static image bank1";
190 part_banks[0].nums = n;
191
192 /* update last partition size to cover actual remaining space */
193 tqm834x_partitions_bank1[n - 1].size =
194 mtd_banks[0]->size -
195 tqm834x_partitions_bank1[n - 1].offset;
196
197 /* check if we have second bank? */
198 if (num_banks == 2) {
199 n = ARRAY_SIZE(tqm834x_partitions_bank2);
200 part_banks[1].mtd_part = tqm834x_partitions_bank2;
201 part_banks[1].type = "static image bank2";
202 part_banks[1].nums = n;
203
204 /* update last partition size to cover actual remaining space */
205 tqm834x_partitions_bank2[n - 1].size =
206 mtd_banks[1]->size -
207 tqm834x_partitions_bank2[n - 1].offset;
208 }
209
210 for(idx = 0; idx < num_banks ; idx++) {
211#ifdef CONFIG_MTD_CMDLINE_PARTS
212 sprintf(mtdid, "%d", idx);
213 n = parse_mtd_partitions(mtd_banks[idx],
214 part_probes,
215 &part_banks[idx].mtd_part,
216 0);
217 pr_debug("%s: %d command line partitions on bank %s\n",
218 __FUNCTION__, n, mtdid);
219 if (n > 0) {
220 part_banks[idx].type = "command line";
221 part_banks[idx].nums = n;
222 }
223#endif /* CONFIG_MTD_CMDLINE_PARTS */
224 if (part_banks[idx].nums == 0) {
225 printk(KERN_NOTICE
226 "TQM834x flash bank %d: no partition info "
227 "available, registering whole device\n", idx);
228 add_mtd_device(mtd_banks[idx]);
229 } else {
230 printk(KERN_NOTICE
231 "TQM834x flash bank %d: Using %s partition "
232 "definition\n", idx, part_banks[idx].type);
233 add_mtd_partitions(mtd_banks[idx],
234 part_banks[idx].mtd_part,
235 part_banks[idx].nums);
236 }
237 }
238#else /* ! CONFIG_MTD_PARTITIONS */
239 printk(KERN_NOTICE "TQM834x flash: registering %d flash banks "
240 "at once\n", num_banks);
241
242 for(idx = 0 ; idx < num_banks ; idx++)
243 add_mtd_device(mtd_banks[idx]);
244
245#endif /* CONFIG_MTD_PARTITIONS */
246
247 return 0;
248error_mem:
249 for (idx = 0 ; idx < FLASH_BANK_MAX ; idx++) {
250 if (map_banks[idx] != NULL) {
251 if (map_banks[idx]->name != NULL) {
252 kfree(map_banks[idx]->name);
253 map_banks[idx]->name = NULL;
254 }
255 kfree(map_banks[idx]);
256 map_banks[idx] = NULL;
257 }
258 }
259
260 iounmap((void *)start_scan_addr);
261
262 return ret;
263}
264
265static void __exit cleanup_tqm834x_mtd(void)
266{
267 unsigned int idx = 0;
268 for(idx = 0 ; idx < num_banks ; idx++) {
269 /* destroy mtd_info previously allocated */
270 if (mtd_banks[idx]) {
271 del_mtd_partitions(mtd_banks[idx]);
272 map_destroy(mtd_banks[idx]);
273 }
274
275 /* release map_info not used anymore */
276 kfree(map_banks[idx]->name);
277 kfree(map_banks[idx]);
278 }
279
280 if (start_scan_addr) {
281 iounmap((void *)start_scan_addr);
282 start_scan_addr = 0;
283 }
284}
285
286module_init(init_tqm834x_mtd);
287module_exit(cleanup_tqm834x_mtd);
288
289MODULE_LICENSE("GPL");
290MODULE_AUTHOR("Wolfgang Denk <wd@denx.de>");
291MODULE_DESCRIPTION("MTD map driver for TQM834x boards");
diff --git a/drivers/mtd/maps/tqm8xxl.c b/drivers/mtd/maps/tqm8xxl.c
index 4e28b977f224..a43517053e7c 100644
--- a/drivers/mtd/maps/tqm8xxl.c
+++ b/drivers/mtd/maps/tqm8xxl.c
@@ -1,15 +1,15 @@
1/* 1/*
2 * Handle mapping of the flash memory access routines 2 * Handle mapping of the flash memory access routines
3 * on TQM8xxL based devices. 3 * on TQM8xxL based devices.
4 * 4 *
5 * $Id: tqm8xxl.c,v 1.13 2004/10/20 22:21:53 dwmw2 Exp $ 5 * $Id: tqm8xxl.c,v 1.15 2005/11/07 11:14:28 gleixner Exp $
6 * 6 *
7 * based on rpxlite.c 7 * based on rpxlite.c
8 * 8 *
9 * Copyright(C) 2001 Kirk Lee <kirk@hpc.ee.ntu.edu.tw> 9 * Copyright(C) 2001 Kirk Lee <kirk@hpc.ee.ntu.edu.tw>
10 * 10 *
11 * This code is GPLed 11 * This code is GPLed
12 * 12 *
13 */ 13 */
14 14
15/* 15/*
@@ -19,7 +19,7 @@
19 * 2MiB 512Kx16 2MiB 0 19 * 2MiB 512Kx16 2MiB 0
20 * 4MiB 1Mx16 4MiB 0 20 * 4MiB 1Mx16 4MiB 0
21 * 8MiB 1Mx16 4MiB 4MiB 21 * 8MiB 1Mx16 4MiB 4MiB
22 * Thus, we choose CONFIG_MTD_CFI_I2 & CONFIG_MTD_CFI_B4 at 22 * Thus, we choose CONFIG_MTD_CFI_I2 & CONFIG_MTD_CFI_B4 at
23 * kernel configuration. 23 * kernel configuration.
24 */ 24 */
25#include <linux/config.h> 25#include <linux/config.h>
@@ -58,9 +58,9 @@ static void __iomem *start_scan_addr;
58 * Here are partition information for all known TQM8xxL series devices. 58 * Here are partition information for all known TQM8xxL series devices.
59 * See include/linux/mtd/partitions.h for definition of the mtd_partition 59 * See include/linux/mtd/partitions.h for definition of the mtd_partition
60 * structure. 60 * structure.
61 * 61 *
62 * The *_max_flash_size is the maximum possible mapped flash size which 62 * The *_max_flash_size is the maximum possible mapped flash size which
63 * is not necessarily the actual flash size. It must correspond to the 63 * is not necessarily the actual flash size. It must correspond to the
64 * value specified in the mapping definition defined by the 64 * value specified in the mapping definition defined by the
65 * "struct map_desc *_io_desc" for the corresponding machine. 65 * "struct map_desc *_io_desc" for the corresponding machine.
66 */ 66 */
@@ -132,9 +132,9 @@ int __init init_tqm_mtd(void)
132 for (idx = 0 ; idx < FLASH_BANK_MAX ; idx++) { 132 for (idx = 0 ; idx < FLASH_BANK_MAX ; idx++) {
133 if(mtd_size >= flash_size) 133 if(mtd_size >= flash_size)
134 break; 134 break;
135 135
136 printk(KERN_INFO "%s: chip probing count %d\n", __FUNCTION__, idx); 136 printk(KERN_INFO "%s: chip probing count %d\n", __FUNCTION__, idx);
137 137
138 map_banks[idx] = (struct map_info *)kmalloc(sizeof(struct map_info), GFP_KERNEL); 138 map_banks[idx] = (struct map_info *)kmalloc(sizeof(struct map_info), GFP_KERNEL);
139 if(map_banks[idx] == NULL) { 139 if(map_banks[idx] == NULL) {
140 ret = -ENOMEM; 140 ret = -ENOMEM;
@@ -180,7 +180,7 @@ int __init init_tqm_mtd(void)
180 mtd_size += mtd_banks[idx]->size; 180 mtd_size += mtd_banks[idx]->size;
181 num_banks++; 181 num_banks++;
182 182
183 printk(KERN_INFO "%s: bank%d, name:%s, size:%dbytes \n", __FUNCTION__, num_banks, 183 printk(KERN_INFO "%s: bank%d, name:%s, size:%dbytes \n", __FUNCTION__, num_banks,
184 mtd_banks[idx]->name, mtd_banks[idx]->size); 184 mtd_banks[idx]->name, mtd_banks[idx]->size);
185 } 185 }
186 } 186 }
@@ -211,7 +211,7 @@ int __init init_tqm_mtd(void)
211 } else { 211 } else {
212 printk(KERN_NOTICE "TQM flash%d: Using %s partition definition\n", 212 printk(KERN_NOTICE "TQM flash%d: Using %s partition definition\n",
213 idx, part_banks[idx].type); 213 idx, part_banks[idx].type);
214 add_mtd_partitions(mtd_banks[idx], part_banks[idx].mtd_part, 214 add_mtd_partitions(mtd_banks[idx], part_banks[idx].mtd_part,
215 part_banks[idx].nums); 215 part_banks[idx].nums);
216 } 216 }
217 } 217 }
@@ -224,10 +224,8 @@ int __init init_tqm_mtd(void)
224error_mem: 224error_mem:
225 for(idx = 0 ; idx < FLASH_BANK_MAX ; idx++) { 225 for(idx = 0 ; idx < FLASH_BANK_MAX ; idx++) {
226 if(map_banks[idx] != NULL) { 226 if(map_banks[idx] != NULL) {
227 if(map_banks[idx]->name != NULL) { 227 kfree(map_banks[idx]->name);
228 kfree(map_banks[idx]->name); 228 map_banks[idx]->name = NULL;
229 map_banks[idx]->name = NULL;
230 }
231 kfree(map_banks[idx]); 229 kfree(map_banks[idx]);
232 map_banks[idx] = NULL; 230 map_banks[idx] = NULL;
233 } 231 }
diff --git a/drivers/mtd/maps/ts5500_flash.c b/drivers/mtd/maps/ts5500_flash.c
index 3ebd90f56503..4b372bcb17f1 100644
--- a/drivers/mtd/maps/ts5500_flash.c
+++ b/drivers/mtd/maps/ts5500_flash.c
@@ -19,26 +19,22 @@
19 * 19 *
20 * Note: 20 * Note:
21 * - In order for detection to work, jumper 3 must be set. 21 * - In order for detection to work, jumper 3 must be set.
22 * - Drive A and B use a proprietary FTL from General Software which isn't 22 * - Drive A and B use the resident flash disk (RFD) flash translation layer.
23 * supported as of yet so standard drives can't be mounted; you can create 23 * - If you have created your own jffs file system and the bios overwrites
24 * your own (e.g. jffs) file system.
25 * - If you have created your own jffs file system and the bios overwrites
26 * it during boot, try disabling Drive A: and B: in the boot order. 24 * it during boot, try disabling Drive A: and B: in the boot order.
27 * 25 *
28 * $Id: ts5500_flash.c,v 1.2 2004/11/28 09:40:40 dwmw2 Exp $ 26 * $Id: ts5500_flash.c,v 1.5 2005/11/07 11:14:28 gleixner Exp $
29 */ 27 */
30 28
31#include <linux/config.h> 29#include <linux/config.h>
30#include <linux/init.h>
32#include <linux/module.h> 31#include <linux/module.h>
33#include <linux/types.h>
34#include <linux/kernel.h> 32#include <linux/kernel.h>
35#include <linux/init.h>
36#include <linux/mtd/mtd.h>
37#include <linux/mtd/map.h> 33#include <linux/mtd/map.h>
38 34#include <linux/mtd/mtd.h>
39#ifdef CONFIG_MTD_PARTITIONS
40#include <linux/mtd/partitions.h> 35#include <linux/mtd/partitions.h>
41#endif 36#include <linux/types.h>
37
42 38
43#define WINDOW_ADDR 0x09400000 39#define WINDOW_ADDR 0x09400000
44#define WINDOW_SIZE 0x00200000 40#define WINDOW_SIZE 0x00200000
@@ -50,7 +46,6 @@ static struct map_info ts5500_map = {
50 .phys = WINDOW_ADDR 46 .phys = WINDOW_ADDR
51}; 47};
52 48
53#ifdef CONFIG_MTD_PARTITIONS
54static struct mtd_partition ts5500_partitions[] = { 49static struct mtd_partition ts5500_partitions[] = {
55 { 50 {
56 .name = "Drive A", 51 .name = "Drive A",
@@ -71,8 +66,6 @@ static struct mtd_partition ts5500_partitions[] = {
71 66
72#define NUM_PARTITIONS (sizeof(ts5500_partitions)/sizeof(struct mtd_partition)) 67#define NUM_PARTITIONS (sizeof(ts5500_partitions)/sizeof(struct mtd_partition))
73 68
74#endif
75
76static struct mtd_info *mymtd; 69static struct mtd_info *mymtd;
77 70
78static int __init init_ts5500_map(void) 71static int __init init_ts5500_map(void)
@@ -81,48 +74,39 @@ static int __init init_ts5500_map(void)
81 74
82 ts5500_map.virt = ioremap_nocache(ts5500_map.phys, ts5500_map.size); 75 ts5500_map.virt = ioremap_nocache(ts5500_map.phys, ts5500_map.size);
83 76
84 if(!ts5500_map.virt) { 77 if (!ts5500_map.virt) {
85 printk(KERN_ERR "Failed to ioremap_nocache\n"); 78 printk(KERN_ERR "Failed to ioremap_nocache\n");
86 rc = -EIO; 79 rc = -EIO;
87 goto err_out_ioremap; 80 goto err2;
88 } 81 }
89 82
90 simple_map_init(&ts5500_map); 83 simple_map_init(&ts5500_map);
91 84
92 mymtd = do_map_probe("jedec_probe", &ts5500_map); 85 mymtd = do_map_probe("jedec_probe", &ts5500_map);
93 if(!mymtd) 86 if (!mymtd)
94 mymtd = do_map_probe("map_rom", &ts5500_map); 87 mymtd = do_map_probe("map_rom", &ts5500_map);
95 88
96 if(!mymtd) { 89 if (!mymtd) {
97 rc = -ENXIO; 90 rc = -ENXIO;
98 goto err_out_map; 91 goto err1;
99 } 92 }
100 93
101 mymtd->owner = THIS_MODULE; 94 mymtd->owner = THIS_MODULE;
102#ifdef CONFIG_MTD_PARTITIONS
103 add_mtd_partitions(mymtd, ts5500_partitions, NUM_PARTITIONS); 95 add_mtd_partitions(mymtd, ts5500_partitions, NUM_PARTITIONS);
104#else
105 add_mtd_device(mymtd);
106#endif
107 96
108 return 0; 97 return 0;
109 98
110err_out_map: 99err1:
111 map_destroy(mymtd); 100 map_destroy(mymtd);
112err_out_ioremap:
113 iounmap(ts5500_map.virt); 101 iounmap(ts5500_map.virt);
114 102err2:
115 return rc; 103 return rc;
116} 104}
117 105
118static void __exit cleanup_ts5500_map(void) 106static void __exit cleanup_ts5500_map(void)
119{ 107{
120 if (mymtd) { 108 if (mymtd) {
121#ifdef CONFIG_MTD_PARTITIONS
122 del_mtd_partitions(mymtd); 109 del_mtd_partitions(mymtd);
123#else
124 del_mtd_device(mymtd);
125#endif
126 map_destroy(mymtd); 110 map_destroy(mymtd);
127 } 111 }
128 112
diff --git a/drivers/mtd/maps/tsunami_flash.c b/drivers/mtd/maps/tsunami_flash.c
index 170d71239e5e..9e21e6c02f80 100644
--- a/drivers/mtd/maps/tsunami_flash.c
+++ b/drivers/mtd/maps/tsunami_flash.c
@@ -2,7 +2,7 @@
2 * tsunami_flash.c 2 * tsunami_flash.c
3 * 3 *
4 * flash chip on alpha ds10... 4 * flash chip on alpha ds10...
5 * $Id: tsunami_flash.c,v 1.9 2004/07/14 09:52:55 dwmw2 Exp $ 5 * $Id: tsunami_flash.c,v 1.10 2005/11/07 11:14:29 gleixner Exp $
6 */ 6 */
7#include <asm/io.h> 7#include <asm/io.h>
8#include <asm/core_tsunami.h> 8#include <asm/core_tsunami.h>
@@ -41,7 +41,7 @@ static void tsunami_flash_copy_from(
41} 41}
42 42
43static void tsunami_flash_copy_to( 43static void tsunami_flash_copy_to(
44 struct map_info *map, unsigned long offset, 44 struct map_info *map, unsigned long offset,
45 const void *addr, ssize_t len) 45 const void *addr, ssize_t len)
46{ 46{
47 const unsigned char *src; 47 const unsigned char *src;
@@ -90,7 +90,7 @@ static int __init init_tsunami_flash(void)
90 char **type; 90 char **type;
91 91
92 tsunami_tig_writeb(FLASH_ENABLE_BYTE, FLASH_ENABLE_PORT); 92 tsunami_tig_writeb(FLASH_ENABLE_BYTE, FLASH_ENABLE_PORT);
93 93
94 tsunami_flash_mtd = 0; 94 tsunami_flash_mtd = 0;
95 type = rom_probe_types; 95 type = rom_probe_types;
96 for(; !tsunami_flash_mtd && *type; type++) { 96 for(; !tsunami_flash_mtd && *type; type++) {
diff --git a/drivers/mtd/maps/uclinux.c b/drivers/mtd/maps/uclinux.c
index cc372136e852..79d92808b766 100644
--- a/drivers/mtd/maps/uclinux.c
+++ b/drivers/mtd/maps/uclinux.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com) 6 * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
7 * 7 *
8 * $Id: uclinux.c,v 1.10 2005/01/05 18:05:13 dwmw2 Exp $ 8 * $Id: uclinux.c,v 1.12 2005/11/07 11:14:29 gleixner Exp $
9 */ 9 */
10 10
11/****************************************************************************/ 11/****************************************************************************/
@@ -82,7 +82,7 @@ int __init uclinux_mtd_init(void)
82 iounmap(mapp->virt); 82 iounmap(mapp->virt);
83 return(-ENXIO); 83 return(-ENXIO);
84 } 84 }
85 85
86 mtd->owner = THIS_MODULE; 86 mtd->owner = THIS_MODULE;
87 mtd->point = uclinux_point; 87 mtd->point = uclinux_point;
88 mtd->priv = mapp; 88 mtd->priv = mapp;
diff --git a/drivers/mtd/maps/vmax301.c b/drivers/mtd/maps/vmax301.c
index c8c74110ed1b..e0063941c0df 100644
--- a/drivers/mtd/maps/vmax301.c
+++ b/drivers/mtd/maps/vmax301.c
@@ -1,19 +1,19 @@
1// $Id: vmax301.c,v 1.30 2004/07/12 22:38:29 dwmw2 Exp $ 1// $Id: vmax301.c,v 1.32 2005/11/07 11:14:29 gleixner Exp $
2/* ###################################################################### 2/* ######################################################################
3 3
4 Tempustech VMAX SBC301 MTD Driver. 4 Tempustech VMAX SBC301 MTD Driver.
5 5
6 The VMAx 301 is a SBC based on . It 6 The VMAx 301 is a SBC based on . It
7 comes with three builtin AMD 29F016B flash chips and a socket for SRAM or 7 comes with three builtin AMD 29F016B flash chips and a socket for SRAM or
8 more flash. Each unit has it's own 8k mapping into a settable region 8 more flash. Each unit has it's own 8k mapping into a settable region
9 (0xD8000). There are two 8k mappings for each MTD, the first is always set 9 (0xD8000). There are two 8k mappings for each MTD, the first is always set
10 to the lower 8k of the device the second is paged. Writing a 16 bit page 10 to the lower 8k of the device the second is paged. Writing a 16 bit page
11 value to anywhere in the first 8k will cause the second 8k to page around. 11 value to anywhere in the first 8k will cause the second 8k to page around.
12 12
13 To boot the device a bios extension must be installed into the first 8k 13 To boot the device a bios extension must be installed into the first 8k
14 of flash that is smart enough to copy itself down, page in the rest of 14 of flash that is smart enough to copy itself down, page in the rest of
15 itself and begin executing. 15 itself and begin executing.
16 16
17 ##################################################################### */ 17 ##################################################################### */
18 18
19#include <linux/module.h> 19#include <linux/module.h>
@@ -35,7 +35,7 @@
35/* Actually we could use two spinlocks, but we'd have to have 35/* Actually we could use two spinlocks, but we'd have to have
36 more private space in the struct map_info. We lose a little 36 more private space in the struct map_info. We lose a little
37 performance like this, but we'd probably lose more by having 37 performance like this, but we'd probably lose more by having
38 the extra indirection from having one of the map->map_priv 38 the extra indirection from having one of the map->map_priv
39 fields pointing to yet another private struct. 39 fields pointing to yet another private struct.
40*/ 40*/
41static DEFINE_SPINLOCK(vmax301_spin); 41static DEFINE_SPINLOCK(vmax301_spin);
@@ -98,7 +98,7 @@ static void vmax301_copy_to(struct map_info *map, unsigned long to, const void *
98 spin_lock(&vmax301_spin); 98 spin_lock(&vmax301_spin);
99 vmax301_page(map, to); 99 vmax301_page(map, to);
100 memcpy_toio(map->map_priv_2 + to, from, thislen); 100 memcpy_toio(map->map_priv_2 + to, from, thislen);
101 spin_unlock(&vmax301_spin); 101 spin_unlock(&vmax301_spin);
102 to += thislen; 102 to += thislen;
103 from += thislen; 103 from += thislen;
104 len -= thislen; 104 len -= thislen;
@@ -137,7 +137,7 @@ static struct mtd_info *vmax_mtd[2] = {NULL, NULL};
137static void __exit cleanup_vmax301(void) 137static void __exit cleanup_vmax301(void)
138{ 138{
139 int i; 139 int i;
140 140
141 for (i=0; i<2; i++) { 141 for (i=0; i<2; i++) {
142 if (vmax_mtd[i]) { 142 if (vmax_mtd[i]) {
143 del_mtd_device(vmax_mtd[i]); 143 del_mtd_device(vmax_mtd[i]);
@@ -161,13 +161,13 @@ int __init init_vmax301(void)
161 return -EIO; 161 return -EIO;
162 } 162 }
163 /* Put the address in the map's private data area. 163 /* Put the address in the map's private data area.
164 We store the actual MTD IO address rather than the 164 We store the actual MTD IO address rather than the
165 address of the first half, because it's used more 165 address of the first half, because it's used more
166 often. 166 often.
167 */ 167 */
168 vmax_map[0].map_priv_2 = iomapadr + WINDOW_START; 168 vmax_map[0].map_priv_2 = iomapadr + WINDOW_START;
169 vmax_map[1].map_priv_2 = iomapadr + (3*WINDOW_START); 169 vmax_map[1].map_priv_2 = iomapadr + (3*WINDOW_START);
170 170
171 for (i=0; i<2; i++) { 171 for (i=0; i<2; i++) {
172 vmax_mtd[i] = do_map_probe("cfi_probe", &vmax_map[i]); 172 vmax_mtd[i] = do_map_probe("cfi_probe", &vmax_map[i]);
173 if (!vmax_mtd[i]) 173 if (!vmax_mtd[i])
diff --git a/drivers/mtd/maps/walnut.c b/drivers/mtd/maps/walnut.c
index d6137b1b5670..5c17bca3a37e 100644
--- a/drivers/mtd/maps/walnut.c
+++ b/drivers/mtd/maps/walnut.c
@@ -1,12 +1,12 @@
1/* 1/*
2 * $Id: walnut.c,v 1.2 2004/12/10 12:07:42 holindho Exp $ 2 * $Id: walnut.c,v 1.3 2005/11/07 11:14:29 gleixner Exp $
3 * 3 *
4 * Mapping for Walnut flash 4 * Mapping for Walnut flash
5 * (used ebony.c as a "framework") 5 * (used ebony.c as a "framework")
6 * 6 *
7 * Heikki Lindholm <holindho@infradead.org> 7 * Heikki Lindholm <holindho@infradead.org>
8 * 8 *
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the 11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your 12 * Free Software Foundation; either version 2 of the License, or (at your
@@ -48,7 +48,7 @@ static struct mtd_partition walnut_partitions[] = {
48 .name = "OpenBIOS", 48 .name = "OpenBIOS",
49 .offset = 0x0, 49 .offset = 0x0,
50 .size = WALNUT_FLASH_SIZE, 50 .size = WALNUT_FLASH_SIZE,
51 /*.mask_flags = MTD_WRITEABLE, */ /* force read-only */ 51 /*.mask_flags = MTD_WRITEABLE, */ /* force read-only */
52 } 52 }
53}; 53};
54 54
@@ -72,11 +72,11 @@ int __init init_walnut(void)
72 printk("The on-board flash is disabled (U79 sw 5)!"); 72 printk("The on-board flash is disabled (U79 sw 5)!");
73 return -EIO; 73 return -EIO;
74 } 74 }
75 if (WALNUT_FLASH_SRAM_SEL(fpga_brds1)) 75 if (WALNUT_FLASH_SRAM_SEL(fpga_brds1))
76 flash_base = WALNUT_FLASH_LOW; 76 flash_base = WALNUT_FLASH_LOW;
77 else 77 else
78 flash_base = WALNUT_FLASH_HIGH; 78 flash_base = WALNUT_FLASH_HIGH;
79 79
80 walnut_map.phys = flash_base; 80 walnut_map.phys = flash_base;
81 walnut_map.virt = 81 walnut_map.virt =
82 (void __iomem *)ioremap(flash_base, walnut_map.size); 82 (void __iomem *)ioremap(flash_base, walnut_map.size);
diff --git a/drivers/mtd/maps/wr_sbc82xx_flash.c b/drivers/mtd/maps/wr_sbc82xx_flash.c
index 82b887b05707..60c197ec455b 100644
--- a/drivers/mtd/maps/wr_sbc82xx_flash.c
+++ b/drivers/mtd/maps/wr_sbc82xx_flash.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: wr_sbc82xx_flash.c,v 1.7 2004/11/04 13:24:15 gleixner Exp $ 2 * $Id: wr_sbc82xx_flash.c,v 1.8 2005/11/07 11:14:29 gleixner Exp $
3 * 3 *
4 * Map for flash chips on Wind River PowerQUICC II SBC82xx board. 4 * Map for flash chips on Wind River PowerQUICC II SBC82xx board.
5 * 5 *
@@ -163,10 +163,10 @@ static void __exit cleanup_sbc82xx_flash(void)
163 del_mtd_partitions(sbcmtd[i]); 163 del_mtd_partitions(sbcmtd[i]);
164 else 164 else
165 del_mtd_device(sbcmtd[i]); 165 del_mtd_device(sbcmtd[i]);
166 166
167 kfree(sbcmtd_parts[i]); 167 kfree(sbcmtd_parts[i]);
168 map_destroy(sbcmtd[i]); 168 map_destroy(sbcmtd[i]);
169 169
170 iounmap((void *)sbc82xx_flash_map[i].virt); 170 iounmap((void *)sbc82xx_flash_map[i].virt);
171 sbc82xx_flash_map[i].virt = 0; 171 sbc82xx_flash_map[i].virt = 0;
172 } 172 }
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index f8d2185819e7..339cb1218eaa 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: mtd_blkdevs.c,v 1.24 2004/11/16 18:28:59 dwmw2 Exp $ 2 * $Id: mtd_blkdevs.c,v 1.27 2005/11/07 11:14:20 gleixner Exp $
3 * 3 *
4 * (C) 2003 David Woodhouse <dwmw2@infradead.org> 4 * (C) 2003 David Woodhouse <dwmw2@infradead.org>
5 * 5 *
@@ -21,7 +21,6 @@
21#include <linux/init.h> 21#include <linux/init.h>
22#include <asm/semaphore.h> 22#include <asm/semaphore.h>
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <linux/devfs_fs_kernel.h>
25 24
26static LIST_HEAD(blktrans_majors); 25static LIST_HEAD(blktrans_majors);
27 26
@@ -86,7 +85,7 @@ static int mtd_blktrans_thread(void *arg)
86 daemonize("%sd", tr->name); 85 daemonize("%sd", tr->name);
87 86
88 /* daemonize() doesn't do this for us since some kernel threads 87 /* daemonize() doesn't do this for us since some kernel threads
89 actually want to deal with signals. We can't just call 88 actually want to deal with signals. We can't just call
90 exit_sighand() since that'll cause an oops when we finally 89 exit_sighand() since that'll cause an oops when we finally
91 do exit. */ 90 do exit. */
92 spin_lock_irq(&current->sighand->siglock); 91 spin_lock_irq(&current->sighand->siglock);
@@ -95,7 +94,7 @@ static int mtd_blktrans_thread(void *arg)
95 spin_unlock_irq(&current->sighand->siglock); 94 spin_unlock_irq(&current->sighand->siglock);
96 95
97 spin_lock_irq(rq->queue_lock); 96 spin_lock_irq(rq->queue_lock);
98 97
99 while (!tr->blkcore_priv->exiting) { 98 while (!tr->blkcore_priv->exiting) {
100 struct request *req; 99 struct request *req;
101 struct mtd_blktrans_dev *dev; 100 struct mtd_blktrans_dev *dev;
@@ -158,7 +157,7 @@ static int blktrans_open(struct inode *i, struct file *f)
158 if (!try_module_get(tr->owner)) 157 if (!try_module_get(tr->owner))
159 goto out_tr; 158 goto out_tr;
160 159
161 /* FIXME: Locking. A hot pluggable device can go away 160 /* FIXME: Locking. A hot pluggable device can go away
162 (del_mtd_device can be called for it) without its module 161 (del_mtd_device can be called for it) without its module
163 being unloaded. */ 162 being unloaded. */
164 dev->mtd->usecount++; 163 dev->mtd->usecount++;
@@ -196,7 +195,7 @@ static int blktrans_release(struct inode *i, struct file *f)
196} 195}
197 196
198 197
199static int blktrans_ioctl(struct inode *inode, struct file *file, 198static int blktrans_ioctl(struct inode *inode, struct file *file,
200 unsigned int cmd, unsigned long arg) 199 unsigned int cmd, unsigned long arg)
201{ 200{
202 struct mtd_blktrans_dev *dev = inode->i_bdev->bd_disk->private_data; 201 struct mtd_blktrans_dev *dev = inode->i_bdev->bd_disk->private_data;
@@ -265,7 +264,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
265 /* Required number was free */ 264 /* Required number was free */
266 list_add_tail(&new->list, &d->list); 265 list_add_tail(&new->list, &d->list);
267 goto added; 266 goto added;
268 } 267 }
269 last_devnum = d->devnum; 268 last_devnum = d->devnum;
270 } 269 }
271 if (new->devnum == -1) 270 if (new->devnum == -1)
@@ -289,11 +288,19 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
289 gd->major = tr->major; 288 gd->major = tr->major;
290 gd->first_minor = (new->devnum) << tr->part_bits; 289 gd->first_minor = (new->devnum) << tr->part_bits;
291 gd->fops = &mtd_blktrans_ops; 290 gd->fops = &mtd_blktrans_ops;
292 291
293 snprintf(gd->disk_name, sizeof(gd->disk_name), 292 if (tr->part_bits)
294 "%s%c", tr->name, (tr->part_bits?'a':'0') + new->devnum); 293 if (new->devnum < 26)
295 snprintf(gd->devfs_name, sizeof(gd->devfs_name), 294 snprintf(gd->disk_name, sizeof(gd->disk_name),
296 "%s/%c", tr->name, (tr->part_bits?'a':'0') + new->devnum); 295 "%s%c", tr->name, 'a' + new->devnum);
296 else
297 snprintf(gd->disk_name, sizeof(gd->disk_name),
298 "%s%c%c", tr->name,
299 'a' - 1 + new->devnum / 26,
300 'a' + new->devnum % 26);
301 else
302 snprintf(gd->disk_name, sizeof(gd->disk_name),
303 "%s%d", tr->name, new->devnum);
297 304
298 /* 2.5 has capacity in units of 512 bytes while still 305 /* 2.5 has capacity in units of 512 bytes while still
299 having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */ 306 having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */
@@ -307,7 +314,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
307 set_disk_ro(gd, 1); 314 set_disk_ro(gd, 1);
308 315
309 add_disk(gd); 316 add_disk(gd);
310 317
311 return 0; 318 return 0;
312} 319}
313 320
@@ -322,7 +329,7 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
322 329
323 del_gendisk(old->blkcore_priv); 330 del_gendisk(old->blkcore_priv);
324 put_disk(old->blkcore_priv); 331 put_disk(old->blkcore_priv);
325 332
326 return 0; 333 return 0;
327} 334}
328 335
@@ -361,12 +368,12 @@ static struct mtd_notifier blktrans_notifier = {
361 .add = blktrans_notify_add, 368 .add = blktrans_notify_add,
362 .remove = blktrans_notify_remove, 369 .remove = blktrans_notify_remove,
363}; 370};
364 371
365int register_mtd_blktrans(struct mtd_blktrans_ops *tr) 372int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
366{ 373{
367 int ret, i; 374 int ret, i;
368 375
369 /* Register the notifier if/when the first device type is 376 /* Register the notifier if/when the first device type is
370 registered, to prevent the link/init ordering from fucking 377 registered, to prevent the link/init ordering from fucking
371 us over. */ 378 us over. */
372 if (!blktrans_notifier.list.next) 379 if (!blktrans_notifier.list.next)
@@ -409,9 +416,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
409 kfree(tr->blkcore_priv); 416 kfree(tr->blkcore_priv);
410 up(&mtd_table_mutex); 417 up(&mtd_table_mutex);
411 return ret; 418 return ret;
412 } 419 }
413
414 devfs_mk_dir(tr->name);
415 420
416 INIT_LIST_HEAD(&tr->devs); 421 INIT_LIST_HEAD(&tr->devs);
417 list_add(&tr->list, &blktrans_majors); 422 list_add(&tr->list, &blktrans_majors);
@@ -445,7 +450,6 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
445 tr->remove_dev(dev); 450 tr->remove_dev(dev);
446 } 451 }
447 452
448 devfs_remove(tr->name);
449 blk_cleanup_queue(tr->blkcore_priv->rq); 453 blk_cleanup_queue(tr->blkcore_priv->rq);
450 unregister_blkdev(tr->major, tr->name); 454 unregister_blkdev(tr->major, tr->name);
451 455
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 400dd9c89883..e84756644fd1 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -1,21 +1,22 @@
1/* 1/*
2 * Direct MTD block device access 2 * Direct MTD block device access
3 * 3 *
4 * $Id: mtdblock.c,v 1.66 2004/11/25 13:52:52 joern Exp $ 4 * $Id: mtdblock.c,v 1.68 2005/11/07 11:14:20 gleixner Exp $
5 * 5 *
6 * (C) 2000-2003 Nicolas Pitre <nico@cam.org> 6 * (C) 2000-2003 Nicolas Pitre <nico@cam.org>
7 * (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> 7 * (C) 1999-2003 David Woodhouse <dwmw2@infradead.org>
8 */ 8 */
9 9
10#include <linux/config.h> 10#include <linux/config.h>
11#include <linux/types.h>
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/fs.h> 11#include <linux/fs.h>
15#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/sched.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/types.h>
17#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
18#include <linux/sched.h> /* TASK_* */ 19
19#include <linux/mtd/mtd.h> 20#include <linux/mtd/mtd.h>
20#include <linux/mtd/blktrans.h> 21#include <linux/mtd/blktrans.h>
21 22
@@ -31,7 +32,7 @@ static struct mtdblk_dev {
31 32
32/* 33/*
33 * Cache stuff... 34 * Cache stuff...
34 * 35 *
35 * Since typical flash erasable sectors are much larger than what Linux's 36 * Since typical flash erasable sectors are much larger than what Linux's
36 * buffer cache can handle, we must implement read-modify-write on flash 37 * buffer cache can handle, we must implement read-modify-write on flash
37 * sectors for each block write requests. To avoid over-erasing flash sectors 38 * sectors for each block write requests. To avoid over-erasing flash sectors
@@ -45,7 +46,7 @@ static void erase_callback(struct erase_info *done)
45 wake_up(wait_q); 46 wake_up(wait_q);
46} 47}
47 48
48static int erase_write (struct mtd_info *mtd, unsigned long pos, 49static int erase_write (struct mtd_info *mtd, unsigned long pos,
49 int len, const char *buf) 50 int len, const char *buf)
50{ 51{
51 struct erase_info erase; 52 struct erase_info erase;
@@ -103,18 +104,18 @@ static int write_cached_data (struct mtdblk_dev *mtdblk)
103 return 0; 104 return 0;
104 105
105 DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: writing cached data for \"%s\" " 106 DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: writing cached data for \"%s\" "
106 "at 0x%lx, size 0x%x\n", mtd->name, 107 "at 0x%lx, size 0x%x\n", mtd->name,
107 mtdblk->cache_offset, mtdblk->cache_size); 108 mtdblk->cache_offset, mtdblk->cache_size);
108 109
109 ret = erase_write (mtd, mtdblk->cache_offset, 110 ret = erase_write (mtd, mtdblk->cache_offset,
110 mtdblk->cache_size, mtdblk->cache_data); 111 mtdblk->cache_size, mtdblk->cache_data);
111 if (ret) 112 if (ret)
112 return ret; 113 return ret;
113 114
114 /* 115 /*
115 * Here we could argubly set the cache state to STATE_CLEAN. 116 * Here we could argubly set the cache state to STATE_CLEAN.
116 * However this could lead to inconsistency since we will not 117 * However this could lead to inconsistency since we will not
117 * be notified if this content is altered on the flash by other 118 * be notified if this content is altered on the flash by other
118 * means. Let's declare it empty and leave buffering tasks to 119 * means. Let's declare it empty and leave buffering tasks to
119 * the buffer cache instead. 120 * the buffer cache instead.
120 */ 121 */
@@ -123,7 +124,7 @@ static int write_cached_data (struct mtdblk_dev *mtdblk)
123} 124}
124 125
125 126
126static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos, 127static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
127 int len, const char *buf) 128 int len, const char *buf)
128{ 129{
129 struct mtd_info *mtd = mtdblk->mtd; 130 struct mtd_info *mtd = mtdblk->mtd;
@@ -133,7 +134,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
133 134
134 DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: write on \"%s\" at 0x%lx, size 0x%x\n", 135 DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: write on \"%s\" at 0x%lx, size 0x%x\n",
135 mtd->name, pos, len); 136 mtd->name, pos, len);
136 137
137 if (!sect_size) 138 if (!sect_size)
138 return MTD_WRITE (mtd, pos, len, &retlen, buf); 139 return MTD_WRITE (mtd, pos, len, &retlen, buf);
139 140
@@ -141,11 +142,11 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
141 unsigned long sect_start = (pos/sect_size)*sect_size; 142 unsigned long sect_start = (pos/sect_size)*sect_size;
142 unsigned int offset = pos - sect_start; 143 unsigned int offset = pos - sect_start;
143 unsigned int size = sect_size - offset; 144 unsigned int size = sect_size - offset;
144 if( size > len ) 145 if( size > len )
145 size = len; 146 size = len;
146 147
147 if (size == sect_size) { 148 if (size == sect_size) {
148 /* 149 /*
149 * We are covering a whole sector. Thus there is no 150 * We are covering a whole sector. Thus there is no
150 * need to bother with the cache while it may still be 151 * need to bother with the cache while it may still be
151 * useful for other partial writes. 152 * useful for other partial writes.
@@ -159,7 +160,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
159 if (mtdblk->cache_state == STATE_DIRTY && 160 if (mtdblk->cache_state == STATE_DIRTY &&
160 mtdblk->cache_offset != sect_start) { 161 mtdblk->cache_offset != sect_start) {
161 ret = write_cached_data(mtdblk); 162 ret = write_cached_data(mtdblk);
162 if (ret) 163 if (ret)
163 return ret; 164 return ret;
164 } 165 }
165 166
@@ -192,7 +193,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
192} 193}
193 194
194 195
195static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos, 196static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
196 int len, char *buf) 197 int len, char *buf)
197{ 198{
198 struct mtd_info *mtd = mtdblk->mtd; 199 struct mtd_info *mtd = mtdblk->mtd;
@@ -200,9 +201,9 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
200 size_t retlen; 201 size_t retlen;
201 int ret; 202 int ret;
202 203
203 DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: read on \"%s\" at 0x%lx, size 0x%x\n", 204 DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: read on \"%s\" at 0x%lx, size 0x%x\n",
204 mtd->name, pos, len); 205 mtd->name, pos, len);
205 206
206 if (!sect_size) 207 if (!sect_size)
207 return MTD_READ (mtd, pos, len, &retlen, buf); 208 return MTD_READ (mtd, pos, len, &retlen, buf);
208 209
@@ -210,7 +211,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
210 unsigned long sect_start = (pos/sect_size)*sect_size; 211 unsigned long sect_start = (pos/sect_size)*sect_size;
211 unsigned int offset = pos - sect_start; 212 unsigned int offset = pos - sect_start;
212 unsigned int size = sect_size - offset; 213 unsigned int size = sect_size - offset;
213 if (size > len) 214 if (size > len)
214 size = len; 215 size = len;
215 216
216 /* 217 /*
@@ -268,12 +269,12 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
268 int dev = mbd->devnum; 269 int dev = mbd->devnum;
269 270
270 DEBUG(MTD_DEBUG_LEVEL1,"mtdblock_open\n"); 271 DEBUG(MTD_DEBUG_LEVEL1,"mtdblock_open\n");
271 272
272 if (mtdblks[dev]) { 273 if (mtdblks[dev]) {
273 mtdblks[dev]->count++; 274 mtdblks[dev]->count++;
274 return 0; 275 return 0;
275 } 276 }
276 277
277 /* OK, it's not open. Create cache info for it */ 278 /* OK, it's not open. Create cache info for it */
278 mtdblk = kmalloc(sizeof(struct mtdblk_dev), GFP_KERNEL); 279 mtdblk = kmalloc(sizeof(struct mtdblk_dev), GFP_KERNEL);
279 if (!mtdblk) 280 if (!mtdblk)
@@ -292,7 +293,7 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
292 } 293 }
293 294
294 mtdblks[dev] = mtdblk; 295 mtdblks[dev] = mtdblk;
295 296
296 DEBUG(MTD_DEBUG_LEVEL1, "ok\n"); 297 DEBUG(MTD_DEBUG_LEVEL1, "ok\n");
297 298
298 return 0; 299 return 0;
@@ -320,7 +321,7 @@ static int mtdblock_release(struct mtd_blktrans_dev *mbd)
320 DEBUG(MTD_DEBUG_LEVEL1, "ok\n"); 321 DEBUG(MTD_DEBUG_LEVEL1, "ok\n");
321 322
322 return 0; 323 return 0;
323} 324}
324 325
325static int mtdblock_flush(struct mtd_blktrans_dev *dev) 326static int mtdblock_flush(struct mtd_blktrans_dev *dev)
326{ 327{
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 16df1e4fb0e9..6f044584bdc6 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -1,22 +1,23 @@
1/* 1/*
2 * $Id: mtdchar.c,v 1.73 2005/07/04 17:36:41 gleixner Exp $ 2 * $Id: mtdchar.c,v 1.76 2005/11/07 11:14:20 gleixner Exp $
3 * 3 *
4 * Character-device access to raw MTD devices. 4 * Character-device access to raw MTD devices.
5 * 5 *
6 */ 6 */
7 7
8#include <linux/config.h> 8#include <linux/config.h>
9#include <linux/device.h>
10#include <linux/fs.h>
11#include <linux/init.h>
9#include <linux/kernel.h> 12#include <linux/kernel.h>
10#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/slab.h>
15#include <linux/sched.h>
16
11#include <linux/mtd/mtd.h> 17#include <linux/mtd/mtd.h>
12#include <linux/mtd/compatmac.h> 18#include <linux/mtd/compatmac.h>
13#include <linux/slab.h>
14#include <linux/init.h>
15#include <linux/fs.h>
16#include <linux/sched.h> /* TASK_* */
17#include <asm/uaccess.h>
18 19
19#include <linux/device.h> 20#include <asm/uaccess.h>
20 21
21static struct class *mtd_class; 22static struct class *mtd_class;
22 23
@@ -27,7 +28,7 @@ static void mtd_notify_add(struct mtd_info* mtd)
27 28
28 class_device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2), 29 class_device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
29 NULL, "mtd%d", mtd->index); 30 NULL, "mtd%d", mtd->index);
30 31
31 class_device_create(mtd_class, NULL, 32 class_device_create(mtd_class, NULL,
32 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), 33 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
33 NULL, "mtd%dro", mtd->index); 34 NULL, "mtd%dro", mtd->index);
@@ -70,26 +71,23 @@ static loff_t mtd_lseek (struct file *file, loff_t offset, int orig)
70 switch (orig) { 71 switch (orig) {
71 case 0: 72 case 0:
72 /* SEEK_SET */ 73 /* SEEK_SET */
73 file->f_pos = offset;
74 break; 74 break;
75 case 1: 75 case 1:
76 /* SEEK_CUR */ 76 /* SEEK_CUR */
77 file->f_pos += offset; 77 offset += file->f_pos;
78 break; 78 break;
79 case 2: 79 case 2:
80 /* SEEK_END */ 80 /* SEEK_END */
81 file->f_pos =mtd->size + offset; 81 offset += mtd->size;
82 break; 82 break;
83 default: 83 default:
84 return -EINVAL; 84 return -EINVAL;
85 } 85 }
86 86
87 if (file->f_pos < 0) 87 if (offset >= 0 && offset < mtd->size)
88 file->f_pos = 0; 88 return file->f_pos = offset;
89 else if (file->f_pos >= mtd->size)
90 file->f_pos = mtd->size - 1;
91 89
92 return file->f_pos; 90 return -EINVAL;
93} 91}
94 92
95 93
@@ -110,23 +108,23 @@ static int mtd_open(struct inode *inode, struct file *file)
110 return -EACCES; 108 return -EACCES;
111 109
112 mtd = get_mtd_device(NULL, devnum); 110 mtd = get_mtd_device(NULL, devnum);
113 111
114 if (!mtd) 112 if (!mtd)
115 return -ENODEV; 113 return -ENODEV;
116 114
117 if (MTD_ABSENT == mtd->type) { 115 if (MTD_ABSENT == mtd->type) {
118 put_mtd_device(mtd); 116 put_mtd_device(mtd);
119 return -ENODEV; 117 return -ENODEV;
120 } 118 }
121 119
122 file->private_data = mtd; 120 file->private_data = mtd;
123 121
124 /* You can't open it RW if it's not a writeable device */ 122 /* You can't open it RW if it's not a writeable device */
125 if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) { 123 if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) {
126 put_mtd_device(mtd); 124 put_mtd_device(mtd);
127 return -EACCES; 125 return -EACCES;
128 } 126 }
129 127
130 return 0; 128 return 0;
131} /* mtd_open */ 129} /* mtd_open */
132 130
@@ -139,10 +137,10 @@ static int mtd_close(struct inode *inode, struct file *file)
139 DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n"); 137 DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n");
140 138
141 mtd = TO_MTD(file); 139 mtd = TO_MTD(file);
142 140
143 if (mtd->sync) 141 if (mtd->sync)
144 mtd->sync(mtd); 142 mtd->sync(mtd);
145 143
146 put_mtd_device(mtd); 144 put_mtd_device(mtd);
147 145
148 return 0; 146 return 0;
@@ -161,7 +159,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
161 int ret=0; 159 int ret=0;
162 int len; 160 int len;
163 char *kbuf; 161 char *kbuf;
164 162
165 DEBUG(MTD_DEBUG_LEVEL0,"MTD_read\n"); 163 DEBUG(MTD_DEBUG_LEVEL0,"MTD_read\n");
166 164
167 if (*ppos + count > mtd->size) 165 if (*ppos + count > mtd->size)
@@ -169,11 +167,11 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
169 167
170 if (!count) 168 if (!count)
171 return 0; 169 return 0;
172 170
173 /* FIXME: Use kiovec in 2.5 to lock down the user's buffers 171 /* FIXME: Use kiovec in 2.5 to lock down the user's buffers
174 and pass them directly to the MTD functions */ 172 and pass them directly to the MTD functions */
175 while (count) { 173 while (count) {
176 if (count > MAX_KMALLOC_SIZE) 174 if (count > MAX_KMALLOC_SIZE)
177 len = MAX_KMALLOC_SIZE; 175 len = MAX_KMALLOC_SIZE;
178 else 176 else
179 len = count; 177 len = count;
@@ -181,7 +179,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
181 kbuf=kmalloc(len,GFP_KERNEL); 179 kbuf=kmalloc(len,GFP_KERNEL);
182 if (!kbuf) 180 if (!kbuf)
183 return -ENOMEM; 181 return -ENOMEM;
184 182
185 switch (MTD_MODE(file)) { 183 switch (MTD_MODE(file)) {
186 case MTD_MODE_OTP_FACT: 184 case MTD_MODE_OTP_FACT:
187 ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf); 185 ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf);
@@ -194,7 +192,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
194 } 192 }
195 /* Nand returns -EBADMSG on ecc errors, but it returns 193 /* Nand returns -EBADMSG on ecc errors, but it returns
196 * the data. For our userspace tools it is important 194 * the data. For our userspace tools it is important
197 * to dump areas with ecc errors ! 195 * to dump areas with ecc errors !
198 * Userspace software which accesses NAND this way 196 * Userspace software which accesses NAND this way
199 * must be aware of the fact that it deals with NAND 197 * must be aware of the fact that it deals with NAND
200 */ 198 */
@@ -216,7 +214,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
216 kfree(kbuf); 214 kfree(kbuf);
217 return ret; 215 return ret;
218 } 216 }
219 217
220 kfree(kbuf); 218 kfree(kbuf);
221 } 219 }
222 220
@@ -233,10 +231,10 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
233 int len; 231 int len;
234 232
235 DEBUG(MTD_DEBUG_LEVEL0,"MTD_write\n"); 233 DEBUG(MTD_DEBUG_LEVEL0,"MTD_write\n");
236 234
237 if (*ppos == mtd->size) 235 if (*ppos == mtd->size)
238 return -ENOSPC; 236 return -ENOSPC;
239 237
240 if (*ppos + count > mtd->size) 238 if (*ppos + count > mtd->size)
241 count = mtd->size - *ppos; 239 count = mtd->size - *ppos;
242 240
@@ -244,7 +242,7 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
244 return 0; 242 return 0;
245 243
246 while (count) { 244 while (count) {
247 if (count > MAX_KMALLOC_SIZE) 245 if (count > MAX_KMALLOC_SIZE)
248 len = MAX_KMALLOC_SIZE; 246 len = MAX_KMALLOC_SIZE;
249 else 247 else
250 len = count; 248 len = count;
@@ -259,7 +257,7 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
259 kfree(kbuf); 257 kfree(kbuf);
260 return -EFAULT; 258 return -EFAULT;
261 } 259 }
262 260
263 switch (MTD_MODE(file)) { 261 switch (MTD_MODE(file)) {
264 case MTD_MODE_OTP_FACT: 262 case MTD_MODE_OTP_FACT:
265 ret = -EROFS; 263 ret = -EROFS;
@@ -284,7 +282,7 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
284 kfree(kbuf); 282 kfree(kbuf);
285 return ret; 283 return ret;
286 } 284 }
287 285
288 kfree(kbuf); 286 kfree(kbuf);
289 } 287 }
290 288
@@ -308,7 +306,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
308 void __user *argp = (void __user *)arg; 306 void __user *argp = (void __user *)arg;
309 int ret = 0; 307 int ret = 0;
310 u_long size; 308 u_long size;
311 309
312 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n"); 310 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
313 311
314 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT; 312 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
@@ -320,7 +318,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
320 if (!access_ok(VERIFY_WRITE, argp, size)) 318 if (!access_ok(VERIFY_WRITE, argp, size))
321 return -EFAULT; 319 return -EFAULT;
322 } 320 }
323 321
324 switch (cmd) { 322 switch (cmd) {
325 case MEMGETREGIONCOUNT: 323 case MEMGETREGIONCOUNT:
326 if (copy_to_user(argp, &(mtd->numeraseregions), sizeof(int))) 324 if (copy_to_user(argp, &(mtd->numeraseregions), sizeof(int)))
@@ -372,11 +370,11 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
372 erase->mtd = mtd; 370 erase->mtd = mtd;
373 erase->callback = mtdchar_erase_callback; 371 erase->callback = mtdchar_erase_callback;
374 erase->priv = (unsigned long)&waitq; 372 erase->priv = (unsigned long)&waitq;
375 373
376 /* 374 /*
377 FIXME: Allow INTERRUPTIBLE. Which means 375 FIXME: Allow INTERRUPTIBLE. Which means
378 not having the wait_queue head on the stack. 376 not having the wait_queue head on the stack.
379 377
380 If the wq_head is on the stack, and we 378 If the wq_head is on the stack, and we
381 leave because we got interrupted, then the 379 leave because we got interrupted, then the
382 wq_head is no longer there when the 380 wq_head is no longer there when the
@@ -404,13 +402,13 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
404 struct mtd_oob_buf buf; 402 struct mtd_oob_buf buf;
405 void *databuf; 403 void *databuf;
406 ssize_t retlen; 404 ssize_t retlen;
407 405
408 if(!(file->f_mode & 2)) 406 if(!(file->f_mode & 2))
409 return -EPERM; 407 return -EPERM;
410 408
411 if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf))) 409 if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf)))
412 return -EFAULT; 410 return -EFAULT;
413 411
414 if (buf.length > 0x4096) 412 if (buf.length > 0x4096)
415 return -EINVAL; 413 return -EINVAL;
416 414
@@ -426,7 +424,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
426 databuf = kmalloc(buf.length, GFP_KERNEL); 424 databuf = kmalloc(buf.length, GFP_KERNEL);
427 if (!databuf) 425 if (!databuf)
428 return -ENOMEM; 426 return -ENOMEM;
429 427
430 if (copy_from_user(databuf, buf.ptr, buf.length)) { 428 if (copy_from_user(databuf, buf.ptr, buf.length)) {
431 kfree(databuf); 429 kfree(databuf);
432 return -EFAULT; 430 return -EFAULT;
@@ -450,7 +448,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
450 448
451 if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf))) 449 if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf)))
452 return -EFAULT; 450 return -EFAULT;
453 451
454 if (buf.length > 0x4096) 452 if (buf.length > 0x4096)
455 return -EINVAL; 453 return -EINVAL;
456 454
@@ -466,14 +464,14 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
466 databuf = kmalloc(buf.length, GFP_KERNEL); 464 databuf = kmalloc(buf.length, GFP_KERNEL);
467 if (!databuf) 465 if (!databuf)
468 return -ENOMEM; 466 return -ENOMEM;
469 467
470 ret = (mtd->read_oob)(mtd, buf.start, buf.length, &retlen, databuf); 468 ret = (mtd->read_oob)(mtd, buf.start, buf.length, &retlen, databuf);
471 469
472 if (put_user(retlen, (uint32_t __user *)argp)) 470 if (put_user(retlen, (uint32_t __user *)argp))
473 ret = -EFAULT; 471 ret = -EFAULT;
474 else if (retlen && copy_to_user(buf.ptr, databuf, retlen)) 472 else if (retlen && copy_to_user(buf.ptr, databuf, retlen))
475 ret = -EFAULT; 473 ret = -EFAULT;
476 474
477 kfree(databuf); 475 kfree(databuf);
478 break; 476 break;
479 } 477 }
@@ -523,7 +521,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
523 case MEMGETBADBLOCK: 521 case MEMGETBADBLOCK:
524 { 522 {
525 loff_t offs; 523 loff_t offs;
526 524
527 if (copy_from_user(&offs, argp, sizeof(loff_t))) 525 if (copy_from_user(&offs, argp, sizeof(loff_t)))
528 return -EFAULT; 526 return -EFAULT;
529 if (!mtd->block_isbad) 527 if (!mtd->block_isbad)
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index f3e65af33a9c..b1bf8c411de7 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -7,14 +7,15 @@
7 * 7 *
8 * This code is GPL 8 * This code is GPL
9 * 9 *
10 * $Id: mtdconcat.c,v 1.9 2004/06/30 15:17:41 dbrown Exp $ 10 * $Id: mtdconcat.c,v 1.11 2005/11/07 11:14:20 gleixner Exp $
11 */ 11 */
12 12
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/module.h>
16#include <linux/slab.h> 15#include <linux/slab.h>
17#include <linux/sched.h> /* TASK_* */ 16#include <linux/sched.h>
17#include <linux/types.h>
18
18#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
19#include <linux/mtd/concat.h> 20#include <linux/mtd/concat.h>
20 21
@@ -43,7 +44,7 @@ struct mtd_concat {
43 */ 44 */
44#define CONCAT(x) ((struct mtd_concat *)(x)) 45#define CONCAT(x) ((struct mtd_concat *)(x))
45 46
46/* 47/*
47 * MTD methods which look up the relevant subdevice, translate the 48 * MTD methods which look up the relevant subdevice, translate the
48 * effective address and pass through to the subdevice. 49 * effective address and pass through to the subdevice.
49 */ 50 */
@@ -877,7 +878,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
877 return &concat->mtd; 878 return &concat->mtd;
878} 879}
879 880
880/* 881/*
881 * This function destroys an MTD object obtained from concat_mtd_devs() 882 * This function destroys an MTD object obtained from concat_mtd_devs()
882 */ 883 */
883 884
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index dc86df18e94b..dade02ab0687 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: mtdcore.c,v 1.45 2005/02/18 14:34:50 dedekind Exp $ 2 * $Id: mtdcore.c,v 1.47 2005/11/07 11:14:20 gleixner Exp $
3 * 3 *
4 * Core registration and callback routines for MTD 4 * Core registration and callback routines for MTD
5 * drivers and users. 5 * drivers and users.
@@ -25,7 +25,7 @@
25 25
26#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
27 27
28/* These are exported solely for the purpose of mtd_blkdevs.c. You 28/* These are exported solely for the purpose of mtd_blkdevs.c. You
29 should not use them for _anything_ else */ 29 should not use them for _anything_ else */
30DECLARE_MUTEX(mtd_table_mutex); 30DECLARE_MUTEX(mtd_table_mutex);
31struct mtd_info *mtd_table[MAX_MTD_DEVICES]; 31struct mtd_info *mtd_table[MAX_MTD_DEVICES];
@@ -66,7 +66,7 @@ int add_mtd_device(struct mtd_info *mtd)
66 struct mtd_notifier *not = list_entry(this, struct mtd_notifier, list); 66 struct mtd_notifier *not = list_entry(this, struct mtd_notifier, list);
67 not->add(mtd); 67 not->add(mtd);
68 } 68 }
69 69
70 up(&mtd_table_mutex); 70 up(&mtd_table_mutex);
71 /* We _know_ we aren't being removed, because 71 /* We _know_ we aren't being removed, because
72 our caller is still holding us here. So none 72 our caller is still holding us here. So none
@@ -75,7 +75,7 @@ int add_mtd_device(struct mtd_info *mtd)
75 __module_get(THIS_MODULE); 75 __module_get(THIS_MODULE);
76 return 0; 76 return 0;
77 } 77 }
78 78
79 up(&mtd_table_mutex); 79 up(&mtd_table_mutex);
80 return 1; 80 return 1;
81} 81}
@@ -93,13 +93,13 @@ int add_mtd_device(struct mtd_info *mtd)
93int del_mtd_device (struct mtd_info *mtd) 93int del_mtd_device (struct mtd_info *mtd)
94{ 94{
95 int ret; 95 int ret;
96 96
97 down(&mtd_table_mutex); 97 down(&mtd_table_mutex);
98 98
99 if (mtd_table[mtd->index] != mtd) { 99 if (mtd_table[mtd->index] != mtd) {
100 ret = -ENODEV; 100 ret = -ENODEV;
101 } else if (mtd->usecount) { 101 } else if (mtd->usecount) {
102 printk(KERN_NOTICE "Removing MTD device #%d (%s) with use count %d\n", 102 printk(KERN_NOTICE "Removing MTD device #%d (%s) with use count %d\n",
103 mtd->index, mtd->name, mtd->usecount); 103 mtd->index, mtd->name, mtd->usecount);
104 ret = -EBUSY; 104 ret = -EBUSY;
105 } else { 105 } else {
@@ -140,7 +140,7 @@ void register_mtd_user (struct mtd_notifier *new)
140 list_add(&new->list, &mtd_notifiers); 140 list_add(&new->list, &mtd_notifiers);
141 141
142 __module_get(THIS_MODULE); 142 __module_get(THIS_MODULE);
143 143
144 for (i=0; i< MAX_MTD_DEVICES; i++) 144 for (i=0; i< MAX_MTD_DEVICES; i++)
145 if (mtd_table[i]) 145 if (mtd_table[i])
146 new->add(mtd_table[i]); 146 new->add(mtd_table[i]);
@@ -169,7 +169,7 @@ int unregister_mtd_user (struct mtd_notifier *old)
169 for (i=0; i< MAX_MTD_DEVICES; i++) 169 for (i=0; i< MAX_MTD_DEVICES; i++)
170 if (mtd_table[i]) 170 if (mtd_table[i])
171 old->remove(mtd_table[i]); 171 old->remove(mtd_table[i]);
172 172
173 list_del(&old->list); 173 list_del(&old->list);
174 up(&mtd_table_mutex); 174 up(&mtd_table_mutex);
175 return 0; 175 return 0;
@@ -187,7 +187,7 @@ int unregister_mtd_user (struct mtd_notifier *old)
187 * both, return the num'th driver only if its address matches. Return NULL 187 * both, return the num'th driver only if its address matches. Return NULL
188 * if not. 188 * if not.
189 */ 189 */
190 190
191struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) 191struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
192{ 192{
193 struct mtd_info *ret = NULL; 193 struct mtd_info *ret = NULL;
@@ -297,39 +297,6 @@ EXPORT_SYMBOL(default_mtd_writev);
297EXPORT_SYMBOL(default_mtd_readv); 297EXPORT_SYMBOL(default_mtd_readv);
298 298
299/*====================================================================*/ 299/*====================================================================*/
300/* Power management code */
301
302#ifdef CONFIG_PM
303
304#include <linux/pm.h>
305
306static struct pm_dev *mtd_pm_dev = NULL;
307
308static int mtd_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
309{
310 int ret = 0, i;
311
312 if (down_trylock(&mtd_table_mutex))
313 return -EAGAIN;
314 if (rqst == PM_SUSPEND) {
315 for (i = 0; ret == 0 && i < MAX_MTD_DEVICES; i++) {
316 if (mtd_table[i] && mtd_table[i]->suspend)
317 ret = mtd_table[i]->suspend(mtd_table[i]);
318 }
319 } else i = MAX_MTD_DEVICES-1;
320
321 if (rqst == PM_RESUME || ret) {
322 for ( ; i >= 0; i--) {
323 if (mtd_table[i] && mtd_table[i]->resume)
324 mtd_table[i]->resume(mtd_table[i]);
325 }
326 }
327 up(&mtd_table_mutex);
328 return ret;
329}
330#endif
331
332/*====================================================================*/
333/* Support for /proc/mtd */ 300/* Support for /proc/mtd */
334 301
335#ifdef CONFIG_PROC_FS 302#ifdef CONFIG_PROC_FS
@@ -388,22 +355,11 @@ static int __init init_mtd(void)
388 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL ))) 355 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL )))
389 proc_mtd->read_proc = mtd_read_proc; 356 proc_mtd->read_proc = mtd_read_proc;
390#endif 357#endif
391
392#ifdef CONFIG_PM
393 mtd_pm_dev = pm_register(PM_UNKNOWN_DEV, 0, mtd_pm_callback);
394#endif
395 return 0; 358 return 0;
396} 359}
397 360
398static void __exit cleanup_mtd(void) 361static void __exit cleanup_mtd(void)
399{ 362{
400#ifdef CONFIG_PM
401 if (mtd_pm_dev) {
402 pm_unregister(mtd_pm_dev);
403 mtd_pm_dev = NULL;
404 }
405#endif
406
407#ifdef CONFIG_PROC_FS 363#ifdef CONFIG_PROC_FS
408 if (proc_mtd) 364 if (proc_mtd)
409 remove_proc_entry( "mtd", NULL); 365 remove_proc_entry( "mtd", NULL);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index b92e6bfffaf2..99395911d26f 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -5,11 +5,11 @@
5 * 5 *
6 * This code is GPL 6 * This code is GPL
7 * 7 *
8 * $Id: mtdpart.c,v 1.53 2005/02/08 17:11:13 nico Exp $ 8 * $Id: mtdpart.c,v 1.55 2005/11/07 11:14:20 gleixner Exp $
9 * 9 *
10 * 02-21-2002 Thomas Gleixner <gleixner@autronix.de> 10 * 02-21-2002 Thomas Gleixner <gleixner@autronix.de>
11 * added support for read_oob, write_oob 11 * added support for read_oob, write_oob
12 */ 12 */
13 13
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/types.h> 15#include <linux/types.h>
@@ -41,13 +41,13 @@ struct mtd_part {
41 */ 41 */
42#define PART(x) ((struct mtd_part *)(x)) 42#define PART(x) ((struct mtd_part *)(x))
43 43
44 44
45/* 45/*
46 * MTD methods which simply translate the effective address and pass through 46 * MTD methods which simply translate the effective address and pass through
47 * to the _real_ device. 47 * to the _real_ device.
48 */ 48 */
49 49
50static int part_read (struct mtd_info *mtd, loff_t from, size_t len, 50static int part_read (struct mtd_info *mtd, loff_t from, size_t len,
51 size_t *retlen, u_char *buf) 51 size_t *retlen, u_char *buf)
52{ 52{
53 struct mtd_part *part = PART(mtd); 53 struct mtd_part *part = PART(mtd);
@@ -55,15 +55,15 @@ static int part_read (struct mtd_info *mtd, loff_t from, size_t len,
55 len = 0; 55 len = 0;
56 else if (from + len > mtd->size) 56 else if (from + len > mtd->size)
57 len = mtd->size - from; 57 len = mtd->size - from;
58 if (part->master->read_ecc == NULL) 58 if (part->master->read_ecc == NULL)
59 return part->master->read (part->master, from + part->offset, 59 return part->master->read (part->master, from + part->offset,
60 len, retlen, buf); 60 len, retlen, buf);
61 else 61 else
62 return part->master->read_ecc (part->master, from + part->offset, 62 return part->master->read_ecc (part->master, from + part->offset,
63 len, retlen, buf, NULL, &mtd->oobinfo); 63 len, retlen, buf, NULL, &mtd->oobinfo);
64} 64}
65 65
66static int part_point (struct mtd_info *mtd, loff_t from, size_t len, 66static int part_point (struct mtd_info *mtd, loff_t from, size_t len,
67 size_t *retlen, u_char **buf) 67 size_t *retlen, u_char **buf)
68{ 68{
69 struct mtd_part *part = PART(mtd); 69 struct mtd_part *part = PART(mtd);
@@ -71,7 +71,7 @@ static int part_point (struct mtd_info *mtd, loff_t from, size_t len,
71 len = 0; 71 len = 0;
72 else if (from + len > mtd->size) 72 else if (from + len > mtd->size)
73 len = mtd->size - from; 73 len = mtd->size - from;
74 return part->master->point (part->master, from + part->offset, 74 return part->master->point (part->master, from + part->offset,
75 len, retlen, buf); 75 len, retlen, buf);
76} 76}
77static void part_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, size_t len) 77static void part_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, size_t len)
@@ -82,7 +82,7 @@ static void part_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, size_
82} 82}
83 83
84 84
85static int part_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, 85static int part_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
86 size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel) 86 size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel)
87{ 87{
88 struct mtd_part *part = PART(mtd); 88 struct mtd_part *part = PART(mtd);
@@ -92,11 +92,11 @@ static int part_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
92 len = 0; 92 len = 0;
93 else if (from + len > mtd->size) 93 else if (from + len > mtd->size)
94 len = mtd->size - from; 94 len = mtd->size - from;
95 return part->master->read_ecc (part->master, from + part->offset, 95 return part->master->read_ecc (part->master, from + part->offset,
96 len, retlen, buf, eccbuf, oobsel); 96 len, retlen, buf, eccbuf, oobsel);
97} 97}
98 98
99static int part_read_oob (struct mtd_info *mtd, loff_t from, size_t len, 99static int part_read_oob (struct mtd_info *mtd, loff_t from, size_t len,
100 size_t *retlen, u_char *buf) 100 size_t *retlen, u_char *buf)
101{ 101{
102 struct mtd_part *part = PART(mtd); 102 struct mtd_part *part = PART(mtd);
@@ -104,15 +104,15 @@ static int part_read_oob (struct mtd_info *mtd, loff_t from, size_t len,
104 len = 0; 104 len = 0;
105 else if (from + len > mtd->size) 105 else if (from + len > mtd->size)
106 len = mtd->size - from; 106 len = mtd->size - from;
107 return part->master->read_oob (part->master, from + part->offset, 107 return part->master->read_oob (part->master, from + part->offset,
108 len, retlen, buf); 108 len, retlen, buf);
109} 109}
110 110
111static int part_read_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, 111static int part_read_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len,
112 size_t *retlen, u_char *buf) 112 size_t *retlen, u_char *buf)
113{ 113{
114 struct mtd_part *part = PART(mtd); 114 struct mtd_part *part = PART(mtd);
115 return part->master->read_user_prot_reg (part->master, from, 115 return part->master->read_user_prot_reg (part->master, from,
116 len, retlen, buf); 116 len, retlen, buf);
117} 117}
118 118
@@ -123,11 +123,11 @@ static int part_get_user_prot_info (struct mtd_info *mtd,
123 return part->master->get_user_prot_info (part->master, buf, len); 123 return part->master->get_user_prot_info (part->master, buf, len);
124} 124}
125 125
126static int part_read_fact_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, 126static int part_read_fact_prot_reg (struct mtd_info *mtd, loff_t from, size_t len,
127 size_t *retlen, u_char *buf) 127 size_t *retlen, u_char *buf)
128{ 128{
129 struct mtd_part *part = PART(mtd); 129 struct mtd_part *part = PART(mtd);
130 return part->master->read_fact_prot_reg (part->master, from, 130 return part->master->read_fact_prot_reg (part->master, from,
131 len, retlen, buf); 131 len, retlen, buf);
132} 132}
133 133
@@ -148,13 +148,13 @@ static int part_write (struct mtd_info *mtd, loff_t to, size_t len,
148 len = 0; 148 len = 0;
149 else if (to + len > mtd->size) 149 else if (to + len > mtd->size)
150 len = mtd->size - to; 150 len = mtd->size - to;
151 if (part->master->write_ecc == NULL) 151 if (part->master->write_ecc == NULL)
152 return part->master->write (part->master, to + part->offset, 152 return part->master->write (part->master, to + part->offset,
153 len, retlen, buf); 153 len, retlen, buf);
154 else 154 else
155 return part->master->write_ecc (part->master, to + part->offset, 155 return part->master->write_ecc (part->master, to + part->offset,
156 len, retlen, buf, NULL, &mtd->oobinfo); 156 len, retlen, buf, NULL, &mtd->oobinfo);
157 157
158} 158}
159 159
160static int part_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, 160static int part_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
@@ -170,7 +170,7 @@ static int part_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
170 len = 0; 170 len = 0;
171 else if (to + len > mtd->size) 171 else if (to + len > mtd->size)
172 len = mtd->size - to; 172 len = mtd->size - to;
173 return part->master->write_ecc (part->master, to + part->offset, 173 return part->master->write_ecc (part->master, to + part->offset,
174 len, retlen, buf, eccbuf, oobsel); 174 len, retlen, buf, eccbuf, oobsel);
175} 175}
176 176
@@ -184,19 +184,19 @@ static int part_write_oob (struct mtd_info *mtd, loff_t to, size_t len,
184 len = 0; 184 len = 0;
185 else if (to + len > mtd->size) 185 else if (to + len > mtd->size)
186 len = mtd->size - to; 186 len = mtd->size - to;
187 return part->master->write_oob (part->master, to + part->offset, 187 return part->master->write_oob (part->master, to + part->offset,
188 len, retlen, buf); 188 len, retlen, buf);
189} 189}
190 190
191static int part_write_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, 191static int part_write_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len,
192 size_t *retlen, u_char *buf) 192 size_t *retlen, u_char *buf)
193{ 193{
194 struct mtd_part *part = PART(mtd); 194 struct mtd_part *part = PART(mtd);
195 return part->master->write_user_prot_reg (part->master, from, 195 return part->master->write_user_prot_reg (part->master, from,
196 len, retlen, buf); 196 len, retlen, buf);
197} 197}
198 198
199static int part_lock_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len) 199static int part_lock_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len)
200{ 200{
201 struct mtd_part *part = PART(mtd); 201 struct mtd_part *part = PART(mtd);
202 return part->master->lock_user_prot_reg (part->master, from, len); 202 return part->master->lock_user_prot_reg (part->master, from, len);
@@ -208,7 +208,7 @@ static int part_writev (struct mtd_info *mtd, const struct kvec *vecs,
208 struct mtd_part *part = PART(mtd); 208 struct mtd_part *part = PART(mtd);
209 if (!(mtd->flags & MTD_WRITEABLE)) 209 if (!(mtd->flags & MTD_WRITEABLE))
210 return -EROFS; 210 return -EROFS;
211 if (part->master->writev_ecc == NULL) 211 if (part->master->writev_ecc == NULL)
212 return part->master->writev (part->master, vecs, count, 212 return part->master->writev (part->master, vecs, count,
213 to + part->offset, retlen); 213 to + part->offset, retlen);
214 else 214 else
@@ -221,12 +221,12 @@ static int part_readv (struct mtd_info *mtd, struct kvec *vecs,
221 unsigned long count, loff_t from, size_t *retlen) 221 unsigned long count, loff_t from, size_t *retlen)
222{ 222{
223 struct mtd_part *part = PART(mtd); 223 struct mtd_part *part = PART(mtd);
224 if (part->master->readv_ecc == NULL) 224 if (part->master->readv_ecc == NULL)
225 return part->master->readv (part->master, vecs, count, 225 return part->master->readv (part->master, vecs, count,
226 from + part->offset, retlen); 226 from + part->offset, retlen);
227 else 227 else
228 return part->master->readv_ecc (part->master, vecs, count, 228 return part->master->readv_ecc (part->master, vecs, count,
229 from + part->offset, retlen, 229 from + part->offset, retlen,
230 NULL, &mtd->oobinfo); 230 NULL, &mtd->oobinfo);
231} 231}
232 232
@@ -252,7 +252,7 @@ static int part_readv_ecc (struct mtd_info *mtd, struct kvec *vecs,
252 if (oobsel == NULL) 252 if (oobsel == NULL)
253 oobsel = &mtd->oobinfo; 253 oobsel = &mtd->oobinfo;
254 return part->master->readv_ecc (part->master, vecs, count, 254 return part->master->readv_ecc (part->master, vecs, count,
255 from + part->offset, retlen, 255 from + part->offset, retlen,
256 eccbuf, oobsel); 256 eccbuf, oobsel);
257} 257}
258 258
@@ -286,7 +286,7 @@ EXPORT_SYMBOL_GPL(mtd_erase_callback);
286static int part_lock (struct mtd_info *mtd, loff_t ofs, size_t len) 286static int part_lock (struct mtd_info *mtd, loff_t ofs, size_t len)
287{ 287{
288 struct mtd_part *part = PART(mtd); 288 struct mtd_part *part = PART(mtd);
289 if ((len + ofs) > mtd->size) 289 if ((len + ofs) > mtd->size)
290 return -EINVAL; 290 return -EINVAL;
291 return part->master->lock(part->master, ofs + part->offset, len); 291 return part->master->lock(part->master, ofs + part->offset, len);
292} 292}
@@ -294,7 +294,7 @@ static int part_lock (struct mtd_info *mtd, loff_t ofs, size_t len)
294static int part_unlock (struct mtd_info *mtd, loff_t ofs, size_t len) 294static int part_unlock (struct mtd_info *mtd, loff_t ofs, size_t len)
295{ 295{
296 struct mtd_part *part = PART(mtd); 296 struct mtd_part *part = PART(mtd);
297 if ((len + ofs) > mtd->size) 297 if ((len + ofs) > mtd->size)
298 return -EINVAL; 298 return -EINVAL;
299 return part->master->unlock(part->master, ofs + part->offset, len); 299 return part->master->unlock(part->master, ofs + part->offset, len);
300} 300}
@@ -337,8 +337,8 @@ static int part_block_markbad (struct mtd_info *mtd, loff_t ofs)
337 return part->master->block_markbad(part->master, ofs); 337 return part->master->block_markbad(part->master, ofs);
338} 338}
339 339
340/* 340/*
341 * This function unregisters and destroy all slave MTD objects which are 341 * This function unregisters and destroy all slave MTD objects which are
342 * attached to the given master MTD object. 342 * attached to the given master MTD object.
343 */ 343 */
344 344
@@ -371,7 +371,7 @@ int del_mtd_partitions(struct mtd_info *master)
371 * (Q: should we register the master MTD object as well?) 371 * (Q: should we register the master MTD object as well?)
372 */ 372 */
373 373
374int add_mtd_partitions(struct mtd_info *master, 374int add_mtd_partitions(struct mtd_info *master,
375 const struct mtd_partition *parts, 375 const struct mtd_partition *parts,
376 int nbparts) 376 int nbparts)
377{ 377{
@@ -414,7 +414,7 @@ int add_mtd_partitions(struct mtd_info *master,
414 slave->mtd.point = part_point; 414 slave->mtd.point = part_point;
415 slave->mtd.unpoint = part_unpoint; 415 slave->mtd.unpoint = part_unpoint;
416 } 416 }
417 417
418 if (master->read_ecc) 418 if (master->read_ecc)
419 slave->mtd.read_ecc = part_read_ecc; 419 slave->mtd.read_ecc = part_read_ecc;
420 if (master->write_ecc) 420 if (master->write_ecc)
@@ -465,9 +465,10 @@ int add_mtd_partitions(struct mtd_info *master,
465 if (slave->offset == MTDPART_OFS_APPEND) 465 if (slave->offset == MTDPART_OFS_APPEND)
466 slave->offset = cur_offset; 466 slave->offset = cur_offset;
467 if (slave->offset == MTDPART_OFS_NXTBLK) { 467 if (slave->offset == MTDPART_OFS_NXTBLK) {
468 u_int32_t emask = master->erasesize-1; 468 slave->offset = cur_offset;
469 slave->offset = (cur_offset + emask) & ~emask; 469 if ((cur_offset % master->erasesize) != 0) {
470 if (slave->offset != cur_offset) { 470 /* Round up to next erasesize */
471 slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
471 printk(KERN_NOTICE "Moving partition %d: " 472 printk(KERN_NOTICE "Moving partition %d: "
472 "0x%08x -> 0x%08x\n", i, 473 "0x%08x -> 0x%08x\n", i,
473 cur_offset, slave->offset); 474 cur_offset, slave->offset);
@@ -476,8 +477,8 @@ int add_mtd_partitions(struct mtd_info *master,
476 if (slave->mtd.size == MTDPART_SIZ_FULL) 477 if (slave->mtd.size == MTDPART_SIZ_FULL)
477 slave->mtd.size = master->size - slave->offset; 478 slave->mtd.size = master->size - slave->offset;
478 cur_offset = slave->offset + slave->mtd.size; 479 cur_offset = slave->offset + slave->mtd.size;
479 480
480 printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset, 481 printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
481 slave->offset + slave->mtd.size, slave->mtd.name); 482 slave->offset + slave->mtd.size, slave->mtd.name);
482 483
483 /* let's do some sanity checks */ 484 /* let's do some sanity checks */
@@ -497,7 +498,7 @@ int add_mtd_partitions(struct mtd_info *master,
497 /* Deal with variable erase size stuff */ 498 /* Deal with variable erase size stuff */
498 int i; 499 int i;
499 struct mtd_erase_region_info *regions = master->eraseregions; 500 struct mtd_erase_region_info *regions = master->eraseregions;
500 501
501 /* Find the first erase regions which is part of this partition. */ 502 /* Find the first erase regions which is part of this partition. */
502 for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++) 503 for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
503 ; 504 ;
@@ -512,7 +513,7 @@ int add_mtd_partitions(struct mtd_info *master,
512 slave->mtd.erasesize = master->erasesize; 513 slave->mtd.erasesize = master->erasesize;
513 } 514 }
514 515
515 if ((slave->mtd.flags & MTD_WRITEABLE) && 516 if ((slave->mtd.flags & MTD_WRITEABLE) &&
516 (slave->offset % slave->mtd.erasesize)) { 517 (slave->offset % slave->mtd.erasesize)) {
517 /* Doesn't start on a boundary of major erase size */ 518 /* Doesn't start on a boundary of major erase size */
518 /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */ 519 /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
@@ -520,14 +521,14 @@ int add_mtd_partitions(struct mtd_info *master,
520 printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n", 521 printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
521 parts[i].name); 522 parts[i].name);
522 } 523 }
523 if ((slave->mtd.flags & MTD_WRITEABLE) && 524 if ((slave->mtd.flags & MTD_WRITEABLE) &&
524 (slave->mtd.size % slave->mtd.erasesize)) { 525 (slave->mtd.size % slave->mtd.erasesize)) {
525 slave->mtd.flags &= ~MTD_WRITEABLE; 526 slave->mtd.flags &= ~MTD_WRITEABLE;
526 printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n", 527 printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
527 parts[i].name); 528 parts[i].name);
528 } 529 }
529 530
530 /* copy oobinfo from master */ 531 /* copy oobinfo from master */
531 memcpy(&slave->mtd.oobinfo, &master->oobinfo, sizeof(slave->mtd.oobinfo)); 532 memcpy(&slave->mtd.oobinfo, &master->oobinfo, sizeof(slave->mtd.oobinfo));
532 533
533 if(parts[i].mtdp) 534 if(parts[i].mtdp)
@@ -588,12 +589,12 @@ int deregister_mtd_parser(struct mtd_part_parser *p)
588 return 0; 589 return 0;
589} 590}
590 591
591int parse_mtd_partitions(struct mtd_info *master, const char **types, 592int parse_mtd_partitions(struct mtd_info *master, const char **types,
592 struct mtd_partition **pparts, unsigned long origin) 593 struct mtd_partition **pparts, unsigned long origin)
593{ 594{
594 struct mtd_part_parser *parser; 595 struct mtd_part_parser *parser;
595 int ret = 0; 596 int ret = 0;
596 597
597 for ( ; ret <= 0 && *types; types++) { 598 for ( ; ret <= 0 && *types; types++) {
598 parser = get_partition_parser(*types); 599 parser = get_partition_parser(*types);
599#ifdef CONFIG_KMOD 600#ifdef CONFIG_KMOD
@@ -607,7 +608,7 @@ int parse_mtd_partitions(struct mtd_info *master, const char **types,
607 } 608 }
608 ret = (*parser->parse_fn)(master, pparts, origin); 609 ret = (*parser->parse_fn)(master, pparts, origin);
609 if (ret > 0) { 610 if (ret > 0) {
610 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", 611 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n",
611 ret, parser->name, master->name); 612 ret, parser->name, master->name);
612 } 613 }
613 put_partition_parser(parser); 614 put_partition_parser(parser);
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 36d34e5e5a5a..1fc4c134d939 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -1,5 +1,5 @@
1# drivers/mtd/nand/Kconfig 1# drivers/mtd/nand/Kconfig
2# $Id: Kconfig,v 1.31 2005/06/20 12:03:21 bjd Exp $ 2# $Id: Kconfig,v 1.35 2005/11/07 11:14:30 gleixner Exp $
3 3
4menu "NAND Flash Device Drivers" 4menu "NAND Flash Device Drivers"
5 depends on MTD!=n 5 depends on MTD!=n
@@ -25,33 +25,33 @@ config MTD_NAND_VERIFY_WRITE
25 25
26config MTD_NAND_AUTCPU12 26config MTD_NAND_AUTCPU12
27 tristate "SmartMediaCard on autronix autcpu12 board" 27 tristate "SmartMediaCard on autronix autcpu12 board"
28 depends on ARM && MTD_NAND && ARCH_AUTCPU12 28 depends on MTD_NAND && ARCH_AUTCPU12
29 help 29 help
30 This enables the driver for the autronix autcpu12 board to 30 This enables the driver for the autronix autcpu12 board to
31 access the SmartMediaCard. 31 access the SmartMediaCard.
32 32
33config MTD_NAND_EDB7312 33config MTD_NAND_EDB7312
34 tristate "Support for Cirrus Logic EBD7312 evaluation board" 34 tristate "Support for Cirrus Logic EBD7312 evaluation board"
35 depends on ARM && MTD_NAND && ARCH_EDB7312 35 depends on MTD_NAND && ARCH_EDB7312
36 help 36 help
37 This enables the driver for the Cirrus Logic EBD7312 evaluation 37 This enables the driver for the Cirrus Logic EBD7312 evaluation
38 board to access the onboard NAND Flash. 38 board to access the onboard NAND Flash.
39 39
40config MTD_NAND_H1900 40config MTD_NAND_H1900
41 tristate "iPAQ H1900 flash" 41 tristate "iPAQ H1900 flash"
42 depends on ARM && MTD_NAND && ARCH_PXA && MTD_PARTITIONS 42 depends on MTD_NAND && ARCH_PXA && MTD_PARTITIONS
43 help 43 help
44 This enables the driver for the iPAQ h1900 flash. 44 This enables the driver for the iPAQ h1900 flash.
45 45
46config MTD_NAND_SPIA 46config MTD_NAND_SPIA
47 tristate "NAND Flash device on SPIA board" 47 tristate "NAND Flash device on SPIA board"
48 depends on ARM && ARCH_P720T && MTD_NAND 48 depends on ARCH_P720T && MTD_NAND
49 help 49 help
50 If you had to ask, you don't have one. Say 'N'. 50 If you had to ask, you don't have one. Say 'N'.
51 51
52config MTD_NAND_TOTO 52config MTD_NAND_TOTO
53 tristate "NAND Flash device on TOTO board" 53 tristate "NAND Flash device on TOTO board"
54 depends on ARM && ARCH_OMAP && MTD_NAND 54 depends on ARCH_OMAP && MTD_NAND
55 help 55 help
56 Support for NAND flash on Texas Instruments Toto platform. 56 Support for NAND flash on Texas Instruments Toto platform.
57 57
@@ -59,8 +59,8 @@ config MTD_NAND_IDS
59 tristate 59 tristate
60 60
61config MTD_NAND_AU1550 61config MTD_NAND_AU1550
62 tristate "Au1550 NAND support" 62 tristate "Au1550/1200 NAND support"
63 depends on SOC_AU1550 && MTD_NAND 63 depends on (SOC_AU1200 || SOC_AU1550) && MTD_NAND
64 help 64 help
65 This enables the driver for the NAND flash controller on the 65 This enables the driver for the NAND flash controller on the
66 AMD/Alchemy 1550 SOC. 66 AMD/Alchemy 1550 SOC.
@@ -71,7 +71,7 @@ config MTD_NAND_RTC_FROM4
71 select REED_SOLOMON 71 select REED_SOLOMON
72 select REED_SOLOMON_DEC8 72 select REED_SOLOMON_DEC8
73 help 73 help
74 This enables the driver for the Renesas Technology AG-AND 74 This enables the driver for the Renesas Technology AG-AND
75 flash interface board (FROM_BOARD4) 75 flash interface board (FROM_BOARD4)
76 76
77config MTD_NAND_PPCHAMELEONEVB 77config MTD_NAND_PPCHAMELEONEVB
@@ -88,7 +88,7 @@ config MTD_NAND_S3C2410
88 SoCs 88 SoCs
89 89
90 No board specfic support is done by this driver, each board 90 No board specfic support is done by this driver, each board
91 must advertise a platform_device for the driver to attach. 91 must advertise a platform_device for the driver to attach.
92 92
93config MTD_NAND_S3C2410_DEBUG 93config MTD_NAND_S3C2410_DEBUG
94 bool "S3C2410 NAND driver debug" 94 bool "S3C2410 NAND driver debug"
@@ -181,7 +181,7 @@ config MTD_NAND_DISKONCHIP_BBTWRITE
181 181
182 config MTD_NAND_SHARPSL 182 config MTD_NAND_SHARPSL
183 bool "Support for NAND Flash on Sharp SL Series (C7xx + others)" 183 bool "Support for NAND Flash on Sharp SL Series (C7xx + others)"
184 depends on MTD_NAND && ARCH_PXA 184 depends on MTD_NAND && ARCH_PXA
185 185
186 config MTD_NAND_NANDSIM 186 config MTD_NAND_NANDSIM
187 bool "Support for NAND Flash Simulator" 187 bool "Support for NAND Flash Simulator"
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 4c7719ce3f48..3cafcdf28aed 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2004 Embedded Edge, LLC 4 * Copyright (C) 2004 Embedded Edge, LLC
5 * 5 *
6 * $Id: au1550nd.c,v 1.11 2004/11/04 12:53:10 gleixner Exp $ 6 * $Id: au1550nd.c,v 1.13 2005/11/07 11:14:30 gleixner Exp $
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 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 9 * it under the terms of the GNU General Public License version 2 as
@@ -21,20 +21,14 @@
21 21
22/* fixme: this is ugly */ 22/* fixme: this is ugly */
23#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 0) 23#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 0)
24#include <asm/mach-au1x00/au1000.h> 24#include <asm/mach-au1x00/au1xxx.h>
25#ifdef CONFIG_MIPS_PB1550
26#include <asm/mach-pb1x00/pb1550.h>
27#endif
28#ifdef CONFIG_MIPS_DB1550
29#include <asm/mach-db1x00/db1x00.h>
30#endif
31#else 25#else
32#include <asm/au1000.h> 26#include <asm/au1000.h>
33#ifdef CONFIG_MIPS_PB1550 27#ifdef CONFIG_MIPS_PB1550
34#include <asm/pb1550.h> 28#include <asm/pb1550.h>
35#endif 29#endif
36#ifdef CONFIG_MIPS_DB1550 30#ifdef CONFIG_MIPS_DB1550
37#include <asm/db1x00.h> 31#include <asm/db1x00.h>
38#endif 32#endif
39#endif 33#endif
40 34
@@ -45,39 +39,22 @@ static struct mtd_info *au1550_mtd = NULL;
45static void __iomem *p_nand; 39static void __iomem *p_nand;
46static int nand_width = 1; /* default x8*/ 40static int nand_width = 1; /* default x8*/
47 41
48#define NAND_CS 1
49
50/* 42/*
51 * Define partitions for flash device 43 * Define partitions for flash device
52 */ 44 */
53const static struct mtd_partition partition_info[] = { 45const static struct mtd_partition partition_info[] = {
54#ifdef CONFIG_MIPS_PB1550 46 {
55#define NUM_PARTITIONS 2 47 .name = "NAND FS 0",
56 {
57 .name = "Pb1550 NAND FS 0",
58 .offset = 0, 48 .offset = 0,
59 .size = 8*1024*1024 49 .size = 8*1024*1024
60 }, 50 },
61 { 51 {
62 .name = "Pb1550 NAND FS 1", 52 .name = "NAND FS 1",
63 .offset = MTDPART_OFS_APPEND, 53 .offset = MTDPART_OFS_APPEND,
64 .size = MTDPART_SIZ_FULL 54 .size = MTDPART_SIZ_FULL
65 } 55 }
66#endif
67#ifdef CONFIG_MIPS_DB1550
68#define NUM_PARTITIONS 2
69 {
70 .name = "Db1550 NAND FS 0",
71 .offset = 0,
72 .size = 8*1024*1024
73 },
74 {
75 .name = "Db1550 NAND FS 1",
76 .offset = MTDPART_OFS_APPEND,
77 .size = MTDPART_SIZ_FULL
78 }
79#endif
80}; 56};
57#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
81 58
82 59
83/** 60/**
@@ -112,7 +89,7 @@ static void au_write_byte(struct mtd_info *mtd, u_char byte)
112 * au_read_byte16 - read one byte endianess aware from the chip 89 * au_read_byte16 - read one byte endianess aware from the chip
113 * @mtd: MTD device structure 90 * @mtd: MTD device structure
114 * 91 *
115 * read function for 16bit buswith with 92 * read function for 16bit buswith with
116 * endianess conversion 93 * endianess conversion
117 */ 94 */
118static u_char au_read_byte16(struct mtd_info *mtd) 95static u_char au_read_byte16(struct mtd_info *mtd)
@@ -142,7 +119,7 @@ static void au_write_byte16(struct mtd_info *mtd, u_char byte)
142 * au_read_word - read one word from the chip 119 * au_read_word - read one word from the chip
143 * @mtd: MTD device structure 120 * @mtd: MTD device structure
144 * 121 *
145 * read function for 16bit buswith without 122 * read function for 16bit buswith without
146 * endianess conversion 123 * endianess conversion
147 */ 124 */
148static u16 au_read_word(struct mtd_info *mtd) 125static u16 au_read_word(struct mtd_info *mtd)
@@ -158,7 +135,7 @@ static u16 au_read_word(struct mtd_info *mtd)
158 * @mtd: MTD device structure 135 * @mtd: MTD device structure
159 * @word: data word to write 136 * @word: data word to write
160 * 137 *
161 * write function for 16bit buswith without 138 * write function for 16bit buswith without
162 * endianess conversion 139 * endianess conversion
163 */ 140 */
164static void au_write_word(struct mtd_info *mtd, u16 word) 141static void au_write_word(struct mtd_info *mtd, u16 word)
@@ -188,7 +165,7 @@ static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
188} 165}
189 166
190/** 167/**
191 * au_read_buf - read chip data into buffer 168 * au_read_buf - read chip data into buffer
192 * @mtd: MTD device structure 169 * @mtd: MTD device structure
193 * @buf: buffer to store date 170 * @buf: buffer to store date
194 * @len: number of bytes to read 171 * @len: number of bytes to read
@@ -202,12 +179,12 @@ static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len)
202 179
203 for (i=0; i<len; i++) { 180 for (i=0; i<len; i++) {
204 buf[i] = readb(this->IO_ADDR_R); 181 buf[i] = readb(this->IO_ADDR_R);
205 au_sync(); 182 au_sync();
206 } 183 }
207} 184}
208 185
209/** 186/**
210 * au_verify_buf - Verify chip data against buffer 187 * au_verify_buf - Verify chip data against buffer
211 * @mtd: MTD device structure 188 * @mtd: MTD device structure
212 * @buf: buffer containing the data to compare 189 * @buf: buffer containing the data to compare
213 * @len: number of bytes to compare 190 * @len: number of bytes to compare
@@ -242,16 +219,16 @@ static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len)
242 struct nand_chip *this = mtd->priv; 219 struct nand_chip *this = mtd->priv;
243 u16 *p = (u16 *) buf; 220 u16 *p = (u16 *) buf;
244 len >>= 1; 221 len >>= 1;
245 222
246 for (i=0; i<len; i++) { 223 for (i=0; i<len; i++) {
247 writew(p[i], this->IO_ADDR_W); 224 writew(p[i], this->IO_ADDR_W);
248 au_sync(); 225 au_sync();
249 } 226 }
250 227
251} 228}
252 229
253/** 230/**
254 * au_read_buf16 - read chip data into buffer 231 * au_read_buf16 - read chip data into buffer
255 * @mtd: MTD device structure 232 * @mtd: MTD device structure
256 * @buf: buffer to store date 233 * @buf: buffer to store date
257 * @len: number of bytes to read 234 * @len: number of bytes to read
@@ -272,7 +249,7 @@ static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
272} 249}
273 250
274/** 251/**
275 * au_verify_buf16 - Verify chip data against buffer 252 * au_verify_buf16 - Verify chip data against buffer
276 * @mtd: MTD device structure 253 * @mtd: MTD device structure
277 * @buf: buffer containing the data to compare 254 * @buf: buffer containing the data to compare
278 * @len: number of bytes to compare 255 * @len: number of bytes to compare
@@ -305,26 +282,26 @@ static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
305 case NAND_CTL_CLRCLE: this->IO_ADDR_W = p_nand + MEM_STNAND_DATA; break; 282 case NAND_CTL_CLRCLE: this->IO_ADDR_W = p_nand + MEM_STNAND_DATA; break;
306 283
307 case NAND_CTL_SETALE: this->IO_ADDR_W = p_nand + MEM_STNAND_ADDR; break; 284 case NAND_CTL_SETALE: this->IO_ADDR_W = p_nand + MEM_STNAND_ADDR; break;
308 case NAND_CTL_CLRALE: 285 case NAND_CTL_CLRALE:
309 this->IO_ADDR_W = p_nand + MEM_STNAND_DATA; 286 this->IO_ADDR_W = p_nand + MEM_STNAND_DATA;
310 /* FIXME: Nobody knows why this is neccecary, 287 /* FIXME: Nobody knows why this is neccecary,
311 * but it works only that way */ 288 * but it works only that way */
312 udelay(1); 289 udelay(1);
313 break; 290 break;
314 291
315 case NAND_CTL_SETNCE: 292 case NAND_CTL_SETNCE:
316 /* assert (force assert) chip enable */ 293 /* assert (force assert) chip enable */
317 au_writel((1<<(4+NAND_CS)) , MEM_STNDCTL); break; 294 au_writel((1<<(4+NAND_CS)) , MEM_STNDCTL); break;
318 break; 295 break;
319 296
320 case NAND_CTL_CLRNCE: 297 case NAND_CTL_CLRNCE:
321 /* deassert chip enable */ 298 /* deassert chip enable */
322 au_writel(0, MEM_STNDCTL); break; 299 au_writel(0, MEM_STNDCTL); break;
323 break; 300 break;
324 } 301 }
325 302
326 this->IO_ADDR_R = this->IO_ADDR_W; 303 this->IO_ADDR_R = this->IO_ADDR_W;
327 304
328 /* Drain the writebuffer */ 305 /* Drain the writebuffer */
329 au_sync(); 306 au_sync();
330} 307}
@@ -339,14 +316,16 @@ int au1550_device_ready(struct mtd_info *mtd)
339/* 316/*
340 * Main initialization routine 317 * Main initialization routine
341 */ 318 */
342int __init au1550_init (void) 319int __init au1xxx_nand_init (void)
343{ 320{
344 struct nand_chip *this; 321 struct nand_chip *this;
345 u16 boot_swapboot = 0; /* default value */ 322 u16 boot_swapboot = 0; /* default value */
346 int retval; 323 int retval;
324 u32 mem_staddr;
325 u32 nand_phys;
347 326
348 /* Allocate memory for MTD device structure and private data */ 327 /* Allocate memory for MTD device structure and private data */
349 au1550_mtd = kmalloc (sizeof(struct mtd_info) + 328 au1550_mtd = kmalloc (sizeof(struct mtd_info) +
350 sizeof (struct nand_chip), GFP_KERNEL); 329 sizeof (struct nand_chip), GFP_KERNEL);
351 if (!au1550_mtd) { 330 if (!au1550_mtd) {
352 printk ("Unable to allocate NAND MTD dev structure.\n"); 331 printk ("Unable to allocate NAND MTD dev structure.\n");
@@ -364,14 +343,17 @@ int __init au1550_init (void)
364 au1550_mtd->priv = this; 343 au1550_mtd->priv = this;
365 344
366 345
367 /* MEM_STNDCTL: disable ints, disable nand boot */ 346 /* disable interrupts */
368 au_writel(0, MEM_STNDCTL); 347 au_writel(au_readl(MEM_STNDCTL) & ~(1<<8), MEM_STNDCTL);
348
349 /* disable NAND boot */
350 au_writel(au_readl(MEM_STNDCTL) & ~(1<<0), MEM_STNDCTL);
369 351
370#ifdef CONFIG_MIPS_PB1550 352#ifdef CONFIG_MIPS_PB1550
371 /* set gpio206 high */ 353 /* set gpio206 high */
372 au_writel(au_readl(GPIO2_DIR) & ~(1<<6), GPIO2_DIR); 354 au_writel(au_readl(GPIO2_DIR) & ~(1<<6), GPIO2_DIR);
373 355
374 boot_swapboot = (au_readl(MEM_STSTAT) & (0x7<<1)) | 356 boot_swapboot = (au_readl(MEM_STSTAT) & (0x7<<1)) |
375 ((bcsr->status >> 6) & 0x1); 357 ((bcsr->status >> 6) & 0x1);
376 switch (boot_swapboot) { 358 switch (boot_swapboot) {
377 case 0: 359 case 0:
@@ -397,25 +379,66 @@ int __init au1550_init (void)
397 } 379 }
398#endif 380#endif
399 381
400 /* Configure RCE1 - should be done by YAMON */ 382 /* Configure chip-select; normally done by boot code, e.g. YAMON */
401 au_writel(0x5 | (nand_width << 22), 0xB4001010); /* MEM_STCFG1 */ 383#ifdef NAND_STCFG
402 au_writel(NAND_TIMING, 0xB4001014); /* MEM_STTIME1 */ 384 if (NAND_CS == 0) {
403 au_sync(); 385 au_writel(NAND_STCFG, MEM_STCFG0);
386 au_writel(NAND_STTIME, MEM_STTIME0);
387 au_writel(NAND_STADDR, MEM_STADDR0);
388 }
389 if (NAND_CS == 1) {
390 au_writel(NAND_STCFG, MEM_STCFG1);
391 au_writel(NAND_STTIME, MEM_STTIME1);
392 au_writel(NAND_STADDR, MEM_STADDR1);
393 }
394 if (NAND_CS == 2) {
395 au_writel(NAND_STCFG, MEM_STCFG2);
396 au_writel(NAND_STTIME, MEM_STTIME2);
397 au_writel(NAND_STADDR, MEM_STADDR2);
398 }
399 if (NAND_CS == 3) {
400 au_writel(NAND_STCFG, MEM_STCFG3);
401 au_writel(NAND_STTIME, MEM_STTIME3);
402 au_writel(NAND_STADDR, MEM_STADDR3);
403 }
404#endif
404 405
405 /* setup and enable chip select, MEM_STADDR1 */ 406 /* Locate NAND chip-select in order to determine NAND phys address */
406 /* we really need to decode offsets only up till 0x20 */ 407 mem_staddr = 0x00000000;
407 au_writel((1<<28) | (NAND_PHYS_ADDR>>4) | 408 if (((au_readl(MEM_STCFG0) & 0x7) == 0x5) && (NAND_CS == 0))
408 (((NAND_PHYS_ADDR + 0x1000)-1) & (0x3fff<<18)>>18), 409 mem_staddr = au_readl(MEM_STADDR0);
409 MEM_STADDR1); 410 else if (((au_readl(MEM_STCFG1) & 0x7) == 0x5) && (NAND_CS == 1))
410 au_sync(); 411 mem_staddr = au_readl(MEM_STADDR1);
412 else if (((au_readl(MEM_STCFG2) & 0x7) == 0x5) && (NAND_CS == 2))
413 mem_staddr = au_readl(MEM_STADDR2);
414 else if (((au_readl(MEM_STCFG3) & 0x7) == 0x5) && (NAND_CS == 3))
415 mem_staddr = au_readl(MEM_STADDR3);
416
417 if (mem_staddr == 0x00000000) {
418 printk("Au1xxx NAND: ERROR WITH NAND CHIP-SELECT\n");
419 kfree(au1550_mtd);
420 return 1;
421 }
422 nand_phys = (mem_staddr << 4) & 0xFFFC0000;
423
424 p_nand = (void __iomem *)ioremap(nand_phys, 0x1000);
425
426 /* make controller and MTD agree */
427 if (NAND_CS == 0)
428 nand_width = au_readl(MEM_STCFG0) & (1<<22);
429 if (NAND_CS == 1)
430 nand_width = au_readl(MEM_STCFG1) & (1<<22);
431 if (NAND_CS == 2)
432 nand_width = au_readl(MEM_STCFG2) & (1<<22);
433 if (NAND_CS == 3)
434 nand_width = au_readl(MEM_STCFG3) & (1<<22);
411 435
412 p_nand = ioremap(NAND_PHYS_ADDR, 0x1000);
413 436
414 /* Set address of hardware control function */ 437 /* Set address of hardware control function */
415 this->hwcontrol = au1550_hwcontrol; 438 this->hwcontrol = au1550_hwcontrol;
416 this->dev_ready = au1550_device_ready; 439 this->dev_ready = au1550_device_ready;
417 /* 30 us command delay time */ 440 /* 30 us command delay time */
418 this->chip_delay = 30; 441 this->chip_delay = 30;
419 this->eccmode = NAND_ECC_SOFT; 442 this->eccmode = NAND_ECC_SOFT;
420 443
421 this->options = NAND_NO_AUTOINCR; 444 this->options = NAND_NO_AUTOINCR;
@@ -438,19 +461,19 @@ int __init au1550_init (void)
438 } 461 }
439 462
440 /* Register the partitions */ 463 /* Register the partitions */
441 add_mtd_partitions(au1550_mtd, partition_info, NUM_PARTITIONS); 464 add_mtd_partitions(au1550_mtd, partition_info, NB_OF(partition_info));
442 465
443 return 0; 466 return 0;
444 467
445 outio: 468 outio:
446 iounmap ((void *)p_nand); 469 iounmap ((void *)p_nand);
447 470
448 outmem: 471 outmem:
449 kfree (au1550_mtd); 472 kfree (au1550_mtd);
450 return retval; 473 return retval;
451} 474}
452 475
453module_init(au1550_init); 476module_init(au1xxx_nand_init);
454 477
455/* 478/*
456 * Clean up routine 479 * Clean up routine
diff --git a/drivers/mtd/nand/autcpu12.c b/drivers/mtd/nand/autcpu12.c
index 4afa8ced05ad..056dfc17a075 100644
--- a/drivers/mtd/nand/autcpu12.c
+++ b/drivers/mtd/nand/autcpu12.c
@@ -5,8 +5,8 @@
5 * 5 *
6 * Derived from drivers/mtd/spia.c 6 * Derived from drivers/mtd/spia.c
7 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com) 7 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
8 * 8 *
9 * $Id: autcpu12.c,v 1.22 2004/11/04 12:53:10 gleixner Exp $ 9 * $Id: autcpu12.c,v 1.23 2005/11/07 11:14:30 gleixner Exp $
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as 12 * it under the terms of the GNU General Public License version 2 as
@@ -14,7 +14,7 @@
14 * 14 *
15 * Overview: 15 * Overview:
16 * This is a device driver for the NAND flash device found on the 16 * This is a device driver for the NAND flash device found on the
17 * autronix autcpu12 board, which is a SmartMediaCard. It supports 17 * autronix autcpu12 board, which is a SmartMediaCard. It supports
18 * 16MiB, 32MiB and 64MiB cards. 18 * 16MiB, 32MiB and 64MiB cards.
19 * 19 *
20 * 20 *
@@ -93,7 +93,7 @@ static struct mtd_partition partition_info128k[] = {
93#define NUM_PARTITIONS32K 2 93#define NUM_PARTITIONS32K 2
94#define NUM_PARTITIONS64K 2 94#define NUM_PARTITIONS64K 2
95#define NUM_PARTITIONS128K 2 95#define NUM_PARTITIONS128K 2
96/* 96/*
97 * hardware specific access to control-lines 97 * hardware specific access to control-lines
98*/ 98*/
99static void autcpu12_hwcontrol(struct mtd_info *mtd, int cmd) 99static void autcpu12_hwcontrol(struct mtd_info *mtd, int cmd)
@@ -163,7 +163,7 @@ int __init autcpu12_init (void)
163 this->hwcontrol = autcpu12_hwcontrol; 163 this->hwcontrol = autcpu12_hwcontrol;
164 this->dev_ready = autcpu12_device_ready; 164 this->dev_ready = autcpu12_device_ready;
165 /* 20 us command delay time */ 165 /* 20 us command delay time */
166 this->chip_delay = 20; 166 this->chip_delay = 20;
167 this->eccmode = NAND_ECC_SOFT; 167 this->eccmode = NAND_ECC_SOFT;
168 168
169 /* Enable the following for a flash based bad block table */ 169 /* Enable the following for a flash based bad block table */
@@ -171,21 +171,21 @@ int __init autcpu12_init (void)
171 this->options = NAND_USE_FLASH_BBT; 171 this->options = NAND_USE_FLASH_BBT;
172 */ 172 */
173 this->options = NAND_USE_FLASH_BBT; 173 this->options = NAND_USE_FLASH_BBT;
174 174
175 /* Scan to find existance of the device */ 175 /* Scan to find existance of the device */
176 if (nand_scan (autcpu12_mtd, 1)) { 176 if (nand_scan (autcpu12_mtd, 1)) {
177 err = -ENXIO; 177 err = -ENXIO;
178 goto out_ior; 178 goto out_ior;
179 } 179 }
180 180
181 /* Register the partitions */ 181 /* Register the partitions */
182 switch(autcpu12_mtd->size){ 182 switch(autcpu12_mtd->size){
183 case SZ_16M: add_mtd_partitions(autcpu12_mtd, partition_info16k, NUM_PARTITIONS16K); break; 183 case SZ_16M: add_mtd_partitions(autcpu12_mtd, partition_info16k, NUM_PARTITIONS16K); break;
184 case SZ_32M: add_mtd_partitions(autcpu12_mtd, partition_info32k, NUM_PARTITIONS32K); break; 184 case SZ_32M: add_mtd_partitions(autcpu12_mtd, partition_info32k, NUM_PARTITIONS32K); break;
185 case SZ_64M: add_mtd_partitions(autcpu12_mtd, partition_info64k, NUM_PARTITIONS64K); break; 185 case SZ_64M: add_mtd_partitions(autcpu12_mtd, partition_info64k, NUM_PARTITIONS64K); break;
186 case SZ_128M: add_mtd_partitions(autcpu12_mtd, partition_info128k, NUM_PARTITIONS128K); break; 186 case SZ_128M: add_mtd_partitions(autcpu12_mtd, partition_info128k, NUM_PARTITIONS128K); break;
187 default: { 187 default: {
188 printk ("Unsupported SmartMedia device\n"); 188 printk ("Unsupported SmartMedia device\n");
189 err = -ENXIO; 189 err = -ENXIO;
190 goto out_ior; 190 goto out_ior;
191 } 191 }
@@ -213,7 +213,7 @@ static void __exit autcpu12_cleanup (void)
213 213
214 /* unmap physical adress */ 214 /* unmap physical adress */
215 iounmap((void *)autcpu12_fio_base); 215 iounmap((void *)autcpu12_fio_base);
216 216
217 /* Free the MTD device structure */ 217 /* Free the MTD device structure */
218 kfree (autcpu12_mtd); 218 kfree (autcpu12_mtd);
219} 219}
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index fdb5d4ad3d52..21d4e8f4b7af 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * drivers/mtd/nand/diskonchip.c 2 * drivers/mtd/nand/diskonchip.c
3 * 3 *
4 * (C) 2003 Red Hat, Inc. 4 * (C) 2003 Red Hat, Inc.
@@ -8,15 +8,15 @@
8 * Author: David Woodhouse <dwmw2@infradead.org> 8 * Author: David Woodhouse <dwmw2@infradead.org>
9 * Additional Diskonchip 2000 and Millennium support by Dan Brown <dan_brown@ieee.org> 9 * Additional Diskonchip 2000 and Millennium support by Dan Brown <dan_brown@ieee.org>
10 * Diskonchip Millennium Plus support by Kalev Lember <kalev@smartlink.ee> 10 * Diskonchip Millennium Plus support by Kalev Lember <kalev@smartlink.ee>
11 * 11 *
12 * Error correction code lifted from the old docecc code 12 * Error correction code lifted from the old docecc code
13 * Author: Fabrice Bellard (fabrice.bellard@netgem.com) 13 * Author: Fabrice Bellard (fabrice.bellard@netgem.com)
14 * Copyright (C) 2000 Netgem S.A. 14 * Copyright (C) 2000 Netgem S.A.
15 * converted to the generic Reed-Solomon library by Thomas Gleixner <tglx@linutronix.de> 15 * converted to the generic Reed-Solomon library by Thomas Gleixner <tglx@linutronix.de>
16 * 16 *
17 * Interface to generic NAND code for M-Systems DiskOnChip devices 17 * Interface to generic NAND code for M-Systems DiskOnChip devices
18 * 18 *
19 * $Id: diskonchip.c,v 1.54 2005/04/07 14:22:55 dbrown Exp $ 19 * $Id: diskonchip.c,v 1.55 2005/11/07 11:14:30 gleixner Exp $
20 */ 20 */
21 21
22#include <linux/kernel.h> 22#include <linux/kernel.h>
@@ -42,16 +42,16 @@
42static unsigned long __initdata doc_locations[] = { 42static unsigned long __initdata doc_locations[] = {
43#if defined (__alpha__) || defined(__i386__) || defined(__x86_64__) 43#if defined (__alpha__) || defined(__i386__) || defined(__x86_64__)
44#ifdef CONFIG_MTD_NAND_DISKONCHIP_PROBE_HIGH 44#ifdef CONFIG_MTD_NAND_DISKONCHIP_PROBE_HIGH
45 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000, 45 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000,
46 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000, 46 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000,
47 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000, 47 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000,
48 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000, 48 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000,
49 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000, 49 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000,
50#else /* CONFIG_MTD_DOCPROBE_HIGH */ 50#else /* CONFIG_MTD_DOCPROBE_HIGH */
51 0xc8000, 0xca000, 0xcc000, 0xce000, 51 0xc8000, 0xca000, 0xcc000, 0xce000,
52 0xd0000, 0xd2000, 0xd4000, 0xd6000, 52 0xd0000, 0xd2000, 0xd4000, 0xd6000,
53 0xd8000, 0xda000, 0xdc000, 0xde000, 53 0xd8000, 0xda000, 0xdc000, 0xde000,
54 0xe0000, 0xe2000, 0xe4000, 0xe6000, 54 0xe0000, 0xe2000, 0xe4000, 0xe6000,
55 0xe8000, 0xea000, 0xec000, 0xee000, 55 0xe8000, 0xea000, 0xec000, 0xee000,
56#endif /* CONFIG_MTD_DOCPROBE_HIGH */ 56#endif /* CONFIG_MTD_DOCPROBE_HIGH */
57#elif defined(__PPC__) 57#elif defined(__PPC__)
@@ -138,7 +138,7 @@ MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe
138/* the Reed Solomon control structure */ 138/* the Reed Solomon control structure */
139static struct rs_control *rs_decoder; 139static struct rs_control *rs_decoder;
140 140
141/* 141/*
142 * The HW decoder in the DoC ASIC's provides us a error syndrome, 142 * The HW decoder in the DoC ASIC's provides us a error syndrome,
143 * which we must convert to a standard syndrom usable by the generic 143 * which we must convert to a standard syndrom usable by the generic
144 * Reed-Solomon library code. 144 * Reed-Solomon library code.
@@ -163,8 +163,8 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
163 /* Initialize the syndrom buffer */ 163 /* Initialize the syndrom buffer */
164 for (i = 0; i < NROOTS; i++) 164 for (i = 0; i < NROOTS; i++)
165 s[i] = ds[0]; 165 s[i] = ds[0];
166 /* 166 /*
167 * Evaluate 167 * Evaluate
168 * s[i] = ds[3]x^3 + ds[2]x^2 + ds[1]x^1 + ds[0] 168 * s[i] = ds[3]x^3 + ds[2]x^2 + ds[1]x^1 + ds[0]
169 * where x = alpha^(FCR + i) 169 * where x = alpha^(FCR + i)
170 */ 170 */
@@ -188,7 +188,7 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
188 if (nerr < 0) 188 if (nerr < 0)
189 return nerr; 189 return nerr;
190 190
191 /* 191 /*
192 * Correct the errors. The bitpositions are a bit of magic, 192 * Correct the errors. The bitpositions are a bit of magic,
193 * but they are given by the design of the de/encoder circuit 193 * but they are given by the design of the de/encoder circuit
194 * in the DoC ASIC's. 194 * in the DoC ASIC's.
@@ -205,7 +205,7 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
205 can be modified since pos is even */ 205 can be modified since pos is even */
206 index = (pos >> 3) ^ 1; 206 index = (pos >> 3) ^ 1;
207 bitpos = pos & 7; 207 bitpos = pos & 7;
208 if ((index >= 0 && index < SECTOR_SIZE) || 208 if ((index >= 0 && index < SECTOR_SIZE) ||
209 index == (SECTOR_SIZE + 1)) { 209 index == (SECTOR_SIZE + 1)) {
210 val = (uint8_t) (errval[i] >> (2 + bitpos)); 210 val = (uint8_t) (errval[i] >> (2 + bitpos));
211 parity ^= val; 211 parity ^= val;
@@ -216,7 +216,7 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
216 bitpos = (bitpos + 10) & 7; 216 bitpos = (bitpos + 10) & 7;
217 if (bitpos == 0) 217 if (bitpos == 0)
218 bitpos = 8; 218 bitpos = 8;
219 if ((index >= 0 && index < SECTOR_SIZE) || 219 if ((index >= 0 && index < SECTOR_SIZE) ||
220 index == (SECTOR_SIZE + 1)) { 220 index == (SECTOR_SIZE + 1)) {
221 val = (uint8_t)(errval[i] << (8 - bitpos)); 221 val = (uint8_t)(errval[i] << (8 - bitpos));
222 parity ^= val; 222 parity ^= val;
@@ -233,7 +233,7 @@ static void DoC_Delay(struct doc_priv *doc, unsigned short cycles)
233{ 233{
234 volatile char dummy; 234 volatile char dummy;
235 int i; 235 int i;
236 236
237 for (i = 0; i < cycles; i++) { 237 for (i = 0; i < cycles; i++) {
238 if (DoC_is_Millennium(doc)) 238 if (DoC_is_Millennium(doc))
239 dummy = ReadDOC(doc->virtadr, NOP); 239 dummy = ReadDOC(doc->virtadr, NOP);
@@ -242,7 +242,7 @@ static void DoC_Delay(struct doc_priv *doc, unsigned short cycles)
242 else 242 else
243 dummy = ReadDOC(doc->virtadr, DOCStatus); 243 dummy = ReadDOC(doc->virtadr, DOCStatus);
244 } 244 }
245 245
246} 246}
247 247
248#define CDSN_CTRL_FR_B_MASK (CDSN_CTRL_FR_B0 | CDSN_CTRL_FR_B1) 248#define CDSN_CTRL_FR_B_MASK (CDSN_CTRL_FR_B0 | CDSN_CTRL_FR_B1)
@@ -327,7 +327,7 @@ static u_char doc2000_read_byte(struct mtd_info *mtd)
327 return ret; 327 return ret;
328} 328}
329 329
330static void doc2000_writebuf(struct mtd_info *mtd, 330static void doc2000_writebuf(struct mtd_info *mtd,
331 const u_char *buf, int len) 331 const u_char *buf, int len)
332{ 332{
333 struct nand_chip *this = mtd->priv; 333 struct nand_chip *this = mtd->priv;
@@ -343,7 +343,7 @@ static void doc2000_writebuf(struct mtd_info *mtd,
343 if (debug) printk("\n"); 343 if (debug) printk("\n");
344} 344}
345 345
346static void doc2000_readbuf(struct mtd_info *mtd, 346static void doc2000_readbuf(struct mtd_info *mtd,
347 u_char *buf, int len) 347 u_char *buf, int len)
348{ 348{
349 struct nand_chip *this = mtd->priv; 349 struct nand_chip *this = mtd->priv;
@@ -358,7 +358,7 @@ static void doc2000_readbuf(struct mtd_info *mtd,
358 } 358 }
359} 359}
360 360
361static void doc2000_readbuf_dword(struct mtd_info *mtd, 361static void doc2000_readbuf_dword(struct mtd_info *mtd,
362 u_char *buf, int len) 362 u_char *buf, int len)
363{ 363{
364 struct nand_chip *this = mtd->priv; 364 struct nand_chip *this = mtd->priv;
@@ -379,7 +379,7 @@ static void doc2000_readbuf_dword(struct mtd_info *mtd,
379 } 379 }
380} 380}
381 381
382static int doc2000_verifybuf(struct mtd_info *mtd, 382static int doc2000_verifybuf(struct mtd_info *mtd,
383 const u_char *buf, int len) 383 const u_char *buf, int len)
384{ 384{
385 struct nand_chip *this = mtd->priv; 385 struct nand_chip *this = mtd->priv;
@@ -406,12 +406,12 @@ static uint16_t __init doc200x_ident_chip(struct mtd_info *mtd, int nr)
406 doc200x_hwcontrol(mtd, NAND_CTL_SETALE); 406 doc200x_hwcontrol(mtd, NAND_CTL_SETALE);
407 this->write_byte(mtd, 0); 407 this->write_byte(mtd, 0);
408 doc200x_hwcontrol(mtd, NAND_CTL_CLRALE); 408 doc200x_hwcontrol(mtd, NAND_CTL_CLRALE);
409 409
410 /* We cant' use dev_ready here, but at least we wait for the 410 /* We cant' use dev_ready here, but at least we wait for the
411 * command to complete 411 * command to complete
412 */ 412 */
413 udelay(50); 413 udelay(50);
414 414
415 ret = this->read_byte(mtd) << 8; 415 ret = this->read_byte(mtd) << 8;
416 ret |= this->read_byte(mtd); 416 ret |= this->read_byte(mtd);
417 417
@@ -438,7 +438,7 @@ static uint16_t __init doc200x_ident_chip(struct mtd_info *mtd, int nr)
438 this->read_buf = &doc2000_readbuf_dword; 438 this->read_buf = &doc2000_readbuf_dword;
439 } 439 }
440 } 440 }
441 441
442 return ret; 442 return ret;
443} 443}
444 444
@@ -469,7 +469,7 @@ static int doc200x_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
469 struct doc_priv *doc = this->priv; 469 struct doc_priv *doc = this->priv;
470 470
471 int status; 471 int status;
472 472
473 DoC_WaitReady(doc); 473 DoC_WaitReady(doc);
474 this->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); 474 this->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
475 DoC_WaitReady(doc); 475 DoC_WaitReady(doc);
@@ -503,7 +503,7 @@ static u_char doc2001_read_byte(struct mtd_info *mtd)
503 return ReadDOC(docptr, LastDataRead); 503 return ReadDOC(docptr, LastDataRead);
504} 504}
505 505
506static void doc2001_writebuf(struct mtd_info *mtd, 506static void doc2001_writebuf(struct mtd_info *mtd,
507 const u_char *buf, int len) 507 const u_char *buf, int len)
508{ 508{
509 struct nand_chip *this = mtd->priv; 509 struct nand_chip *this = mtd->priv;
@@ -517,7 +517,7 @@ static void doc2001_writebuf(struct mtd_info *mtd,
517 WriteDOC(0x00, docptr, WritePipeTerm); 517 WriteDOC(0x00, docptr, WritePipeTerm);
518} 518}
519 519
520static void doc2001_readbuf(struct mtd_info *mtd, 520static void doc2001_readbuf(struct mtd_info *mtd,
521 u_char *buf, int len) 521 u_char *buf, int len)
522{ 522{
523 struct nand_chip *this = mtd->priv; 523 struct nand_chip *this = mtd->priv;
@@ -535,7 +535,7 @@ static void doc2001_readbuf(struct mtd_info *mtd,
535 buf[i] = ReadDOC(docptr, LastDataRead); 535 buf[i] = ReadDOC(docptr, LastDataRead);
536} 536}
537 537
538static int doc2001_verifybuf(struct mtd_info *mtd, 538static int doc2001_verifybuf(struct mtd_info *mtd,
539 const u_char *buf, int len) 539 const u_char *buf, int len)
540{ 540{
541 struct nand_chip *this = mtd->priv; 541 struct nand_chip *this = mtd->priv;
@@ -570,7 +570,7 @@ static u_char doc2001plus_read_byte(struct mtd_info *mtd)
570 return ret; 570 return ret;
571} 571}
572 572
573static void doc2001plus_writebuf(struct mtd_info *mtd, 573static void doc2001plus_writebuf(struct mtd_info *mtd,
574 const u_char *buf, int len) 574 const u_char *buf, int len)
575{ 575{
576 struct nand_chip *this = mtd->priv; 576 struct nand_chip *this = mtd->priv;
@@ -587,7 +587,7 @@ static void doc2001plus_writebuf(struct mtd_info *mtd,
587 if (debug) printk("\n"); 587 if (debug) printk("\n");
588} 588}
589 589
590static void doc2001plus_readbuf(struct mtd_info *mtd, 590static void doc2001plus_readbuf(struct mtd_info *mtd,
591 u_char *buf, int len) 591 u_char *buf, int len)
592{ 592{
593 struct nand_chip *this = mtd->priv; 593 struct nand_chip *this = mtd->priv;
@@ -617,7 +617,7 @@ static void doc2001plus_readbuf(struct mtd_info *mtd,
617 if (debug) printk("\n"); 617 if (debug) printk("\n");
618} 618}
619 619
620static int doc2001plus_verifybuf(struct mtd_info *mtd, 620static int doc2001plus_verifybuf(struct mtd_info *mtd,
621 const u_char *buf, int len) 621 const u_char *buf, int len)
622{ 622{
623 struct nand_chip *this = mtd->priv; 623 struct nand_chip *this = mtd->priv;
@@ -797,7 +797,7 @@ static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int col
797 WriteDOC(0, docptr, Mplus_FlashControl); 797 WriteDOC(0, docptr, Mplus_FlashControl);
798 } 798 }
799 799
800 /* 800 /*
801 * program and erase have their own busy handlers 801 * program and erase have their own busy handlers
802 * status and sequential in needs no delay 802 * status and sequential in needs no delay
803 */ 803 */
@@ -822,7 +822,7 @@ static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int col
822 822
823 /* This applies to read commands */ 823 /* This applies to read commands */
824 default: 824 default:
825 /* 825 /*
826 * If we don't have access to the busy pin, we apply the given 826 * If we don't have access to the busy pin, we apply the given
827 * command delay 827 * command delay
828 */ 828 */
@@ -945,7 +945,7 @@ static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
945 for (i = 0; i < 6; i++) { 945 for (i = 0; i < 6; i++) {
946 if (DoC_is_MillenniumPlus(doc)) 946 if (DoC_is_MillenniumPlus(doc))
947 ecc_code[i] = ReadDOC_(docptr, DoC_Mplus_ECCSyndrome0 + i); 947 ecc_code[i] = ReadDOC_(docptr, DoC_Mplus_ECCSyndrome0 + i);
948 else 948 else
949 ecc_code[i] = ReadDOC_(docptr, DoC_ECCSyndrome0 + i); 949 ecc_code[i] = ReadDOC_(docptr, DoC_ECCSyndrome0 + i);
950 if (ecc_code[i] != empty_write_ecc[i]) 950 if (ecc_code[i] != empty_write_ecc[i])
951 emptymatch = 0; 951 emptymatch = 0;
@@ -982,7 +982,7 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_
982 void __iomem *docptr = doc->virtadr; 982 void __iomem *docptr = doc->virtadr;
983 volatile u_char dummy; 983 volatile u_char dummy;
984 int emptymatch = 1; 984 int emptymatch = 1;
985 985
986 /* flush the pipeline */ 986 /* flush the pipeline */
987 if (DoC_is_2000(doc)) { 987 if (DoC_is_2000(doc)) {
988 dummy = ReadDOC(docptr, 2k_ECCStatus); 988 dummy = ReadDOC(docptr, 2k_ECCStatus);
@@ -997,7 +997,7 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_
997 dummy = ReadDOC(docptr, ECCConf); 997 dummy = ReadDOC(docptr, ECCConf);
998 dummy = ReadDOC(docptr, ECCConf); 998 dummy = ReadDOC(docptr, ECCConf);
999 } 999 }
1000 1000
1001 /* Error occured ? */ 1001 /* Error occured ? */
1002 if (dummy & 0x80) { 1002 if (dummy & 0x80) {
1003 for (i = 0; i < 6; i++) { 1003 for (i = 0; i < 6; i++) {
@@ -1035,7 +1035,7 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_
1035 if (!emptymatch) ret = doc_ecc_decode (rs_decoder, dat, calc_ecc); 1035 if (!emptymatch) ret = doc_ecc_decode (rs_decoder, dat, calc_ecc);
1036 if (ret > 0) 1036 if (ret > 0)
1037 printk(KERN_ERR "doc200x_correct_data corrected %d errors\n", ret); 1037 printk(KERN_ERR "doc200x_correct_data corrected %d errors\n", ret);
1038 } 1038 }
1039 if (DoC_is_MillenniumPlus(doc)) 1039 if (DoC_is_MillenniumPlus(doc))
1040 WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf); 1040 WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf);
1041 else 1041 else
@@ -1046,7 +1046,7 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_
1046 } 1046 }
1047 return ret; 1047 return ret;
1048} 1048}
1049 1049
1050//u_char mydatabuf[528]; 1050//u_char mydatabuf[528];
1051 1051
1052/* The strange out-of-order .oobfree list below is a (possibly unneeded) 1052/* The strange out-of-order .oobfree list below is a (possibly unneeded)
@@ -1065,7 +1065,7 @@ static struct nand_oobinfo doc200x_oobinfo = {
1065 .eccpos = {0, 1, 2, 3, 4, 5}, 1065 .eccpos = {0, 1, 2, 3, 4, 5},
1066 .oobfree = { {8, 8}, {6, 2} } 1066 .oobfree = { {8, 8}, {6, 2} }
1067}; 1067};
1068 1068
1069/* Find the (I)NFTL Media Header, and optionally also the mirror media header. 1069/* Find the (I)NFTL Media Header, and optionally also the mirror media header.
1070 On sucessful return, buf will contain a copy of the media header for 1070 On sucessful return, buf will contain a copy of the media header for
1071 further processing. id is the string to scan for, and will presumably be 1071 further processing. id is the string to scan for, and will presumably be
@@ -1251,7 +1251,7 @@ static inline int __init inftl_partscan(struct mtd_info *mtd,
1251 mh->BlockMultiplierBits = le32_to_cpu(mh->BlockMultiplierBits); 1251 mh->BlockMultiplierBits = le32_to_cpu(mh->BlockMultiplierBits);
1252 mh->FormatFlags = le32_to_cpu(mh->FormatFlags); 1252 mh->FormatFlags = le32_to_cpu(mh->FormatFlags);
1253 mh->PercentUsed = le32_to_cpu(mh->PercentUsed); 1253 mh->PercentUsed = le32_to_cpu(mh->PercentUsed);
1254 1254
1255 printk(KERN_INFO " bootRecordID = %s\n" 1255 printk(KERN_INFO " bootRecordID = %s\n"
1256 " NoOfBootImageBlocks = %d\n" 1256 " NoOfBootImageBlocks = %d\n"
1257 " NoOfBinaryPartitions = %d\n" 1257 " NoOfBinaryPartitions = %d\n"
@@ -1468,7 +1468,7 @@ static inline int __init doc2001_init(struct mtd_info *mtd)
1468 ReadDOC(doc->virtadr, ChipID); 1468 ReadDOC(doc->virtadr, ChipID);
1469 if (ReadDOC(doc->virtadr, ChipID) != DOC_ChipID_DocMil) { 1469 if (ReadDOC(doc->virtadr, ChipID) != DOC_ChipID_DocMil) {
1470 /* It's not a Millennium; it's one of the newer 1470 /* It's not a Millennium; it's one of the newer
1471 DiskOnChip 2000 units with a similar ASIC. 1471 DiskOnChip 2000 units with a similar ASIC.
1472 Treat it like a Millennium, except that it 1472 Treat it like a Millennium, except that it
1473 can have multiple chips. */ 1473 can have multiple chips. */
1474 doc2000_count_chips(mtd); 1474 doc2000_count_chips(mtd);
@@ -1530,20 +1530,20 @@ static inline int __init doc_probe(unsigned long physadr)
1530 * to the DOCControl register. So we store the current contents 1530 * to the DOCControl register. So we store the current contents
1531 * of the DOCControl register's location, in case we later decide 1531 * of the DOCControl register's location, in case we later decide
1532 * that it's not a DiskOnChip, and want to put it back how we 1532 * that it's not a DiskOnChip, and want to put it back how we
1533 * found it. 1533 * found it.
1534 */ 1534 */
1535 save_control = ReadDOC(virtadr, DOCControl); 1535 save_control = ReadDOC(virtadr, DOCControl);
1536 1536
1537 /* Reset the DiskOnChip ASIC */ 1537 /* Reset the DiskOnChip ASIC */
1538 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET, 1538 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
1539 virtadr, DOCControl); 1539 virtadr, DOCControl);
1540 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET, 1540 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
1541 virtadr, DOCControl); 1541 virtadr, DOCControl);
1542 1542
1543 /* Enable the DiskOnChip ASIC */ 1543 /* Enable the DiskOnChip ASIC */
1544 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL, 1544 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
1545 virtadr, DOCControl); 1545 virtadr, DOCControl);
1546 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL, 1546 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
1547 virtadr, DOCControl); 1547 virtadr, DOCControl);
1548 1548
1549 ChipID = ReadDOC(virtadr, ChipID); 1549 ChipID = ReadDOC(virtadr, ChipID);
@@ -1738,7 +1738,7 @@ static int __init init_nanddoc(void)
1738 int i, ret = 0; 1738 int i, ret = 0;
1739 1739
1740 /* We could create the decoder on demand, if memory is a concern. 1740 /* We could create the decoder on demand, if memory is a concern.
1741 * This way we have it handy, if an error happens 1741 * This way we have it handy, if an error happens
1742 * 1742 *
1743 * Symbolsize is 10 (bits) 1743 * Symbolsize is 10 (bits)
1744 * Primitve polynomial is x^10+x^3+1 1744 * Primitve polynomial is x^10+x^3+1
diff --git a/drivers/mtd/nand/edb7312.c b/drivers/mtd/nand/edb7312.c
index 5549681ccdce..9b1fd2f387fa 100644
--- a/drivers/mtd/nand/edb7312.c
+++ b/drivers/mtd/nand/edb7312.c
@@ -6,7 +6,7 @@
6 * Derived from drivers/mtd/nand/autcpu12.c 6 * Derived from drivers/mtd/nand/autcpu12.c
7 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de) 7 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
8 * 8 *
9 * $Id: edb7312.c,v 1.11 2004/11/04 12:53:10 gleixner Exp $ 9 * $Id: edb7312.c,v 1.12 2005/11/07 11:14:30 gleixner Exp $
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as 12 * it under the terms of the GNU General Public License version 2 as
@@ -71,27 +71,27 @@ static struct mtd_partition partition_info[] = {
71#endif 71#endif
72 72
73 73
74/* 74/*
75 * hardware specific access to control-lines 75 * hardware specific access to control-lines
76 */ 76 */
77static void ep7312_hwcontrol(struct mtd_info *mtd, int cmd) 77static void ep7312_hwcontrol(struct mtd_info *mtd, int cmd)
78{ 78{
79 switch(cmd) { 79 switch(cmd) {
80 80
81 case NAND_CTL_SETCLE: 81 case NAND_CTL_SETCLE:
82 clps_writeb(clps_readb(ep7312_pxdr) | 0x10, ep7312_pxdr); 82 clps_writeb(clps_readb(ep7312_pxdr) | 0x10, ep7312_pxdr);
83 break; 83 break;
84 case NAND_CTL_CLRCLE: 84 case NAND_CTL_CLRCLE:
85 clps_writeb(clps_readb(ep7312_pxdr) & ~0x10, ep7312_pxdr); 85 clps_writeb(clps_readb(ep7312_pxdr) & ~0x10, ep7312_pxdr);
86 break; 86 break;
87 87
88 case NAND_CTL_SETALE: 88 case NAND_CTL_SETALE:
89 clps_writeb(clps_readb(ep7312_pxdr) | 0x20, ep7312_pxdr); 89 clps_writeb(clps_readb(ep7312_pxdr) | 0x20, ep7312_pxdr);
90 break; 90 break;
91 case NAND_CTL_CLRALE: 91 case NAND_CTL_CLRALE:
92 clps_writeb(clps_readb(ep7312_pxdr) & ~0x20, ep7312_pxdr); 92 clps_writeb(clps_readb(ep7312_pxdr) & ~0x20, ep7312_pxdr);
93 break; 93 break;
94 94
95 case NAND_CTL_SETNCE: 95 case NAND_CTL_SETNCE:
96 clps_writeb((clps_readb(ep7312_pxdr) | 0x80) & ~0x40, ep7312_pxdr); 96 clps_writeb((clps_readb(ep7312_pxdr) | 0x80) & ~0x40, ep7312_pxdr);
97 break; 97 break;
@@ -122,16 +122,16 @@ static int __init ep7312_init (void)
122 int mtd_parts_nb = 0; 122 int mtd_parts_nb = 0;
123 struct mtd_partition *mtd_parts = 0; 123 struct mtd_partition *mtd_parts = 0;
124 void __iomem * ep7312_fio_base; 124 void __iomem * ep7312_fio_base;
125 125
126 /* Allocate memory for MTD device structure and private data */ 126 /* Allocate memory for MTD device structure and private data */
127 ep7312_mtd = kmalloc(sizeof(struct mtd_info) + 127 ep7312_mtd = kmalloc(sizeof(struct mtd_info) +
128 sizeof(struct nand_chip), 128 sizeof(struct nand_chip),
129 GFP_KERNEL); 129 GFP_KERNEL);
130 if (!ep7312_mtd) { 130 if (!ep7312_mtd) {
131 printk("Unable to allocate EDB7312 NAND MTD device structure.\n"); 131 printk("Unable to allocate EDB7312 NAND MTD device structure.\n");
132 return -ENOMEM; 132 return -ENOMEM;
133 } 133 }
134 134
135 /* map physical adress */ 135 /* map physical adress */
136 ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K); 136 ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K);
137 if(!ep7312_fio_base) { 137 if(!ep7312_fio_base) {
@@ -139,23 +139,23 @@ static int __init ep7312_init (void)
139 kfree(ep7312_mtd); 139 kfree(ep7312_mtd);
140 return -EIO; 140 return -EIO;
141 } 141 }
142 142
143 /* Get pointer to private data */ 143 /* Get pointer to private data */
144 this = (struct nand_chip *) (&ep7312_mtd[1]); 144 this = (struct nand_chip *) (&ep7312_mtd[1]);
145 145
146 /* Initialize structures */ 146 /* Initialize structures */
147 memset((char *) ep7312_mtd, 0, sizeof(struct mtd_info)); 147 memset((char *) ep7312_mtd, 0, sizeof(struct mtd_info));
148 memset((char *) this, 0, sizeof(struct nand_chip)); 148 memset((char *) this, 0, sizeof(struct nand_chip));
149 149
150 /* Link the private data with the MTD structure */ 150 /* Link the private data with the MTD structure */
151 ep7312_mtd->priv = this; 151 ep7312_mtd->priv = this;
152 152
153 /* 153 /*
154 * Set GPIO Port B control register so that the pins are configured 154 * Set GPIO Port B control register so that the pins are configured
155 * to be outputs for controlling the NAND flash. 155 * to be outputs for controlling the NAND flash.
156 */ 156 */
157 clps_writeb(0xf0, ep7312_pxddr); 157 clps_writeb(0xf0, ep7312_pxddr);
158 158
159 /* insert callbacks */ 159 /* insert callbacks */
160 this->IO_ADDR_R = ep7312_fio_base; 160 this->IO_ADDR_R = ep7312_fio_base;
161 this->IO_ADDR_W = ep7312_fio_base; 161 this->IO_ADDR_W = ep7312_fio_base;
@@ -163,14 +163,14 @@ static int __init ep7312_init (void)
163 this->dev_ready = ep7312_device_ready; 163 this->dev_ready = ep7312_device_ready;
164 /* 15 us command delay time */ 164 /* 15 us command delay time */
165 this->chip_delay = 15; 165 this->chip_delay = 15;
166 166
167 /* Scan to find existence of the device */ 167 /* Scan to find existence of the device */
168 if (nand_scan (ep7312_mtd, 1)) { 168 if (nand_scan (ep7312_mtd, 1)) {
169 iounmap((void *)ep7312_fio_base); 169 iounmap((void *)ep7312_fio_base);
170 kfree (ep7312_mtd); 170 kfree (ep7312_mtd);
171 return -ENXIO; 171 return -ENXIO;
172 } 172 }
173 173
174#ifdef CONFIG_MTD_PARTITIONS 174#ifdef CONFIG_MTD_PARTITIONS
175 ep7312_mtd->name = "edb7312-nand"; 175 ep7312_mtd->name = "edb7312-nand";
176 mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes, 176 mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes,
@@ -185,11 +185,11 @@ static int __init ep7312_init (void)
185 mtd_parts_nb = NUM_PARTITIONS; 185 mtd_parts_nb = NUM_PARTITIONS;
186 part_type = "static"; 186 part_type = "static";
187 } 187 }
188 188
189 /* Register the partitions */ 189 /* Register the partitions */
190 printk(KERN_NOTICE "Using %s partition definition\n", part_type); 190 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
191 add_mtd_partitions(ep7312_mtd, mtd_parts, mtd_parts_nb); 191 add_mtd_partitions(ep7312_mtd, mtd_parts, mtd_parts_nb);
192 192
193 /* Return happy */ 193 /* Return happy */
194 return 0; 194 return 0;
195} 195}
@@ -201,13 +201,13 @@ module_init(ep7312_init);
201static void __exit ep7312_cleanup (void) 201static void __exit ep7312_cleanup (void)
202{ 202{
203 struct nand_chip *this = (struct nand_chip *) &ep7312_mtd[1]; 203 struct nand_chip *this = (struct nand_chip *) &ep7312_mtd[1];
204 204
205 /* Release resources, unregister device */ 205 /* Release resources, unregister device */
206 nand_release (ap7312_mtd); 206 nand_release (ap7312_mtd);
207 207
208 /* Free internal data buffer */ 208 /* Free internal data buffer */
209 kfree (this->data_buf); 209 kfree (this->data_buf);
210 210
211 /* Free the MTD device structure */ 211 /* Free the MTD device structure */
212 kfree (ep7312_mtd); 212 kfree (ep7312_mtd);
213} 213}
diff --git a/drivers/mtd/nand/h1910.c b/drivers/mtd/nand/h1910.c
index 3825a7a0900c..041e4b3358fb 100644
--- a/drivers/mtd/nand/h1910.c
+++ b/drivers/mtd/nand/h1910.c
@@ -7,7 +7,7 @@
7 * Copyright (C) 2002 Marius Gröger (mag@sysgo.de) 7 * Copyright (C) 2002 Marius Gröger (mag@sysgo.de)
8 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de) 8 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
9 * 9 *
10 * $Id: h1910.c,v 1.5 2004/11/04 12:53:10 gleixner Exp $ 10 * $Id: h1910.c,v 1.6 2005/11/07 11:14:30 gleixner Exp $
11 * 11 *
12 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as 13 * it under the terms of the GNU General Public License version 2 as
@@ -54,24 +54,24 @@ static struct mtd_partition partition_info[] = {
54#endif 54#endif
55 55
56 56
57/* 57/*
58 * hardware specific access to control-lines 58 * hardware specific access to control-lines
59 */ 59 */
60static void h1910_hwcontrol(struct mtd_info *mtd, int cmd) 60static void h1910_hwcontrol(struct mtd_info *mtd, int cmd)
61{ 61{
62 struct nand_chip* this = (struct nand_chip *) (mtd->priv); 62 struct nand_chip* this = (struct nand_chip *) (mtd->priv);
63 63
64 switch(cmd) { 64 switch(cmd) {
65 65
66 case NAND_CTL_SETCLE: 66 case NAND_CTL_SETCLE:
67 this->IO_ADDR_R |= (1 << 2); 67 this->IO_ADDR_R |= (1 << 2);
68 this->IO_ADDR_W |= (1 << 2); 68 this->IO_ADDR_W |= (1 << 2);
69 break; 69 break;
70 case NAND_CTL_CLRCLE: 70 case NAND_CTL_CLRCLE:
71 this->IO_ADDR_R &= ~(1 << 2); 71 this->IO_ADDR_R &= ~(1 << 2);
72 this->IO_ADDR_W &= ~(1 << 2); 72 this->IO_ADDR_W &= ~(1 << 2);
73 break; 73 break;
74 74
75 case NAND_CTL_SETALE: 75 case NAND_CTL_SETALE:
76 this->IO_ADDR_R |= (1 << 3); 76 this->IO_ADDR_R |= (1 << 3);
77 this->IO_ADDR_W |= (1 << 3); 77 this->IO_ADDR_W |= (1 << 3);
@@ -80,7 +80,7 @@ static void h1910_hwcontrol(struct mtd_info *mtd, int cmd)
80 this->IO_ADDR_R &= ~(1 << 3); 80 this->IO_ADDR_R &= ~(1 << 3);
81 this->IO_ADDR_W &= ~(1 << 3); 81 this->IO_ADDR_W &= ~(1 << 3);
82 break; 82 break;
83 83
84 case NAND_CTL_SETNCE: 84 case NAND_CTL_SETNCE:
85 break; 85 break;
86 case NAND_CTL_CLRNCE: 86 case NAND_CTL_CLRNCE:
@@ -108,18 +108,18 @@ static int __init h1910_init (void)
108 int mtd_parts_nb = 0; 108 int mtd_parts_nb = 0;
109 struct mtd_partition *mtd_parts = 0; 109 struct mtd_partition *mtd_parts = 0;
110 void __iomem *nandaddr; 110 void __iomem *nandaddr;
111 111
112 if (!machine_is_h1900()) 112 if (!machine_is_h1900())
113 return -ENODEV; 113 return -ENODEV;
114 114
115 nandaddr = __ioremap(0x08000000, 0x1000, 0, 1); 115 nandaddr = __ioremap(0x08000000, 0x1000, 0, 1);
116 if (!nandaddr) { 116 if (!nandaddr) {
117 printk("Failed to ioremap nand flash.\n"); 117 printk("Failed to ioremap nand flash.\n");
118 return -ENOMEM; 118 return -ENOMEM;
119 } 119 }
120 120
121 /* Allocate memory for MTD device structure and private data */ 121 /* Allocate memory for MTD device structure and private data */
122 h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + 122 h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) +
123 sizeof(struct nand_chip), 123 sizeof(struct nand_chip),
124 GFP_KERNEL); 124 GFP_KERNEL);
125 if (!h1910_nand_mtd) { 125 if (!h1910_nand_mtd) {
@@ -127,22 +127,22 @@ static int __init h1910_init (void)
127 iounmap ((void *) nandaddr); 127 iounmap ((void *) nandaddr);
128 return -ENOMEM; 128 return -ENOMEM;
129 } 129 }
130 130
131 /* Get pointer to private data */ 131 /* Get pointer to private data */
132 this = (struct nand_chip *) (&h1910_nand_mtd[1]); 132 this = (struct nand_chip *) (&h1910_nand_mtd[1]);
133 133
134 /* Initialize structures */ 134 /* Initialize structures */
135 memset((char *) h1910_nand_mtd, 0, sizeof(struct mtd_info)); 135 memset((char *) h1910_nand_mtd, 0, sizeof(struct mtd_info));
136 memset((char *) this, 0, sizeof(struct nand_chip)); 136 memset((char *) this, 0, sizeof(struct nand_chip));
137 137
138 /* Link the private data with the MTD structure */ 138 /* Link the private data with the MTD structure */
139 h1910_nand_mtd->priv = this; 139 h1910_nand_mtd->priv = this;
140 140
141 /* 141 /*
142 * Enable VPEN 142 * Enable VPEN
143 */ 143 */
144 GPSR(37) = GPIO_bit(37); 144 GPSR(37) = GPIO_bit(37);
145 145
146 /* insert callbacks */ 146 /* insert callbacks */
147 this->IO_ADDR_R = nandaddr; 147 this->IO_ADDR_R = nandaddr;
148 this->IO_ADDR_W = nandaddr; 148 this->IO_ADDR_W = nandaddr;
@@ -152,7 +152,7 @@ static int __init h1910_init (void)
152 this->chip_delay = 50; 152 this->chip_delay = 50;
153 this->eccmode = NAND_ECC_SOFT; 153 this->eccmode = NAND_ECC_SOFT;
154 this->options = NAND_NO_AUTOINCR; 154 this->options = NAND_NO_AUTOINCR;
155 155
156 /* Scan to find existence of the device */ 156 /* Scan to find existence of the device */
157 if (nand_scan (h1910_nand_mtd, 1)) { 157 if (nand_scan (h1910_nand_mtd, 1)) {
158 printk(KERN_NOTICE "No NAND device - returning -ENXIO\n"); 158 printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
@@ -160,9 +160,9 @@ static int __init h1910_init (void)
160 iounmap ((void *) nandaddr); 160 iounmap ((void *) nandaddr);
161 return -ENXIO; 161 return -ENXIO;
162 } 162 }
163 163
164#ifdef CONFIG_MTD_CMDLINE_PARTS 164#ifdef CONFIG_MTD_CMDLINE_PARTS
165 mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts, 165 mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts,
166 "h1910-nand"); 166 "h1910-nand");
167 if (mtd_parts_nb > 0) 167 if (mtd_parts_nb > 0)
168 part_type = "command line"; 168 part_type = "command line";
@@ -175,11 +175,11 @@ static int __init h1910_init (void)
175 mtd_parts_nb = NUM_PARTITIONS; 175 mtd_parts_nb = NUM_PARTITIONS;
176 part_type = "static"; 176 part_type = "static";
177 } 177 }
178 178
179 /* Register the partitions */ 179 /* Register the partitions */
180 printk(KERN_NOTICE "Using %s partition definition\n", part_type); 180 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
181 add_mtd_partitions(h1910_nand_mtd, mtd_parts, mtd_parts_nb); 181 add_mtd_partitions(h1910_nand_mtd, mtd_parts, mtd_parts_nb);
182 182
183 /* Return happy */ 183 /* Return happy */
184 return 0; 184 return 0;
185} 185}
@@ -191,7 +191,7 @@ module_init(h1910_init);
191static void __exit h1910_cleanup (void) 191static void __exit h1910_cleanup (void)
192{ 192{
193 struct nand_chip *this = (struct nand_chip *) &h1910_nand_mtd[1]; 193 struct nand_chip *this = (struct nand_chip *) &h1910_nand_mtd[1];
194 194
195 /* Release resources, unregister device */ 195 /* Release resources, unregister device */
196 nand_release (h1910_nand_mtd); 196 nand_release (h1910_nand_mtd);
197 197
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 04e54318bc6a..5d222460b42a 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -5,14 +5,14 @@
5 * This is the generic MTD driver for NAND flash devices. It should be 5 * This is the generic MTD driver for NAND flash devices. It should be
6 * capable of working with almost all NAND chips currently available. 6 * capable of working with almost all NAND chips currently available.
7 * Basic support for AG-AND chips is provided. 7 * Basic support for AG-AND chips is provided.
8 * 8 *
9 * Additional technical information is available on 9 * Additional technical information is available on
10 * http://www.linux-mtd.infradead.org/tech/nand.html 10 * http://www.linux-mtd.infradead.org/tech/nand.html
11 * 11 *
12 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com) 12 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
13 * 2002 Thomas Gleixner (tglx@linutronix.de) 13 * 2002 Thomas Gleixner (tglx@linutronix.de)
14 * 14 *
15 * 02-08-2004 tglx: support for strange chips, which cannot auto increment 15 * 02-08-2004 tglx: support for strange chips, which cannot auto increment
16 * pages on read / read_oob 16 * pages on read / read_oob
17 * 17 *
18 * 03-17-2004 tglx: Check ready before auto increment check. Simon Bayes 18 * 03-17-2004 tglx: Check ready before auto increment check. Simon Bayes
@@ -21,7 +21,7 @@
21 * Make reads over block boundaries work too 21 * Make reads over block boundaries work too
22 * 22 *
23 * 04-14-2004 tglx: first working version for 2k page size chips 23 * 04-14-2004 tglx: first working version for 2k page size chips
24 * 24 *
25 * 05-19-2004 tglx: Basic support for Renesas AG-AND chips 25 * 05-19-2004 tglx: Basic support for Renesas AG-AND chips
26 * 26 *
27 * 09-24-2004 tglx: add support for hardware controllers (e.g. ECC) shared 27 * 09-24-2004 tglx: add support for hardware controllers (e.g. ECC) shared
@@ -30,25 +30,27 @@
30 * 30 *
31 * 12-05-2004 dmarlin: add workaround for Renesas AG-AND chips "disturb" issue. 31 * 12-05-2004 dmarlin: add workaround for Renesas AG-AND chips "disturb" issue.
32 * Basically, any block not rewritten may lose data when surrounding blocks 32 * Basically, any block not rewritten may lose data when surrounding blocks
33 * are rewritten many times. JFFS2 ensures this doesn't happen for blocks 33 * are rewritten many times. JFFS2 ensures this doesn't happen for blocks
34 * it uses, but the Bad Block Table(s) may not be rewritten. To ensure they 34 * it uses, but the Bad Block Table(s) may not be rewritten. To ensure they
35 * do not lose data, force them to be rewritten when some of the surrounding 35 * do not lose data, force them to be rewritten when some of the surrounding
36 * blocks are erased. Rather than tracking a specific nearby block (which 36 * blocks are erased. Rather than tracking a specific nearby block (which
37 * could itself go bad), use a page address 'mask' to select several blocks 37 * could itself go bad), use a page address 'mask' to select several blocks
38 * in the same area, and rewrite the BBT when any of them are erased. 38 * in the same area, and rewrite the BBT when any of them are erased.
39 * 39 *
40 * 01-03-2005 dmarlin: added support for the device recovery command sequence for Renesas 40 * 01-03-2005 dmarlin: added support for the device recovery command sequence for Renesas
41 * AG-AND chips. If there was a sudden loss of power during an erase operation, 41 * AG-AND chips. If there was a sudden loss of power during an erase operation,
42 * a "device recovery" operation must be performed when power is restored 42 * a "device recovery" operation must be performed when power is restored
43 * to ensure correct operation. 43 * to ensure correct operation.
44 * 44 *
45 * 01-20-2005 dmarlin: added support for optional hardware specific callback routine to 45 * 01-20-2005 dmarlin: added support for optional hardware specific callback routine to
46 * perform extra error status checks on erase and write failures. This required 46 * perform extra error status checks on erase and write failures. This required
47 * adding a wrapper function for nand_read_ecc. 47 * adding a wrapper function for nand_read_ecc.
48 * 48 *
49 * 08-20-2005 vwool: suspend/resume added
50 *
49 * Credits: 51 * Credits:
50 * David Woodhouse for adding multichip support 52 * David Woodhouse for adding multichip support
51 * 53 *
52 * Aleph One Ltd. and Toby Churchill Ltd. for supporting the 54 * Aleph One Ltd. and Toby Churchill Ltd. for supporting the
53 * rework for 2K page size chips 55 * rework for 2K page size chips
54 * 56 *
@@ -59,7 +61,7 @@
59 * The AG-AND chips have nice features for speed improvement, 61 * The AG-AND chips have nice features for speed improvement,
60 * which are not supported yet. Read / program 4 pages in one go. 62 * which are not supported yet. Read / program 4 pages in one go.
61 * 63 *
62 * $Id: nand_base.c,v 1.147 2005/07/15 07:18:06 gleixner Exp $ 64 * $Id: nand_base.c,v 1.150 2005/09/15 13:58:48 vwool Exp $
63 * 65 *
64 * This program is free software; you can redistribute it and/or modify 66 * This program is free software; you can redistribute it and/or modify
65 * it under the terms of the GNU General Public License version 2 as 67 * it under the terms of the GNU General Public License version 2 as
@@ -103,8 +105,8 @@ static struct nand_oobinfo nand_oob_64 = {
103 .useecc = MTD_NANDECC_AUTOPLACE, 105 .useecc = MTD_NANDECC_AUTOPLACE,
104 .eccbytes = 24, 106 .eccbytes = 24,
105 .eccpos = { 107 .eccpos = {
106 40, 41, 42, 43, 44, 45, 46, 47, 108 40, 41, 42, 43, 44, 45, 46, 47,
107 48, 49, 50, 51, 52, 53, 54, 55, 109 48, 49, 50, 51, 52, 53, 54, 55,
108 56, 57, 58, 59, 60, 61, 62, 63}, 110 56, 57, 58, 59, 60, 61, 62, 63},
109 .oobfree = { {2, 38} } 111 .oobfree = { {2, 38} }
110}; 112};
@@ -147,19 +149,19 @@ static void nand_sync (struct mtd_info *mtd);
147static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, u_char *oob_buf, 149static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, u_char *oob_buf,
148 struct nand_oobinfo *oobsel, int mode); 150 struct nand_oobinfo *oobsel, int mode);
149#ifdef CONFIG_MTD_NAND_VERIFY_WRITE 151#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
150static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, 152static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages,
151 u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode); 153 u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode);
152#else 154#else
153#define nand_verify_pages(...) (0) 155#define nand_verify_pages(...) (0)
154#endif 156#endif
155 157
156static void nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state); 158static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state);
157 159
158/** 160/**
159 * nand_release_device - [GENERIC] release chip 161 * nand_release_device - [GENERIC] release chip
160 * @mtd: MTD device structure 162 * @mtd: MTD device structure
161 * 163 *
162 * Deselect, release chip lock and wake up anyone waiting on the device 164 * Deselect, release chip lock and wake up anyone waiting on the device
163 */ 165 */
164static void nand_release_device (struct mtd_info *mtd) 166static void nand_release_device (struct mtd_info *mtd)
165{ 167{
@@ -213,7 +215,7 @@ static void nand_write_byte(struct mtd_info *mtd, u_char byte)
213 * nand_read_byte16 - [DEFAULT] read one byte endianess aware from the chip 215 * nand_read_byte16 - [DEFAULT] read one byte endianess aware from the chip
214 * @mtd: MTD device structure 216 * @mtd: MTD device structure
215 * 217 *
216 * Default read function for 16bit buswith with 218 * Default read function for 16bit buswith with
217 * endianess conversion 219 * endianess conversion
218 */ 220 */
219static u_char nand_read_byte16(struct mtd_info *mtd) 221static u_char nand_read_byte16(struct mtd_info *mtd)
@@ -240,7 +242,7 @@ static void nand_write_byte16(struct mtd_info *mtd, u_char byte)
240 * nand_read_word - [DEFAULT] read one word from the chip 242 * nand_read_word - [DEFAULT] read one word from the chip
241 * @mtd: MTD device structure 243 * @mtd: MTD device structure
242 * 244 *
243 * Default read function for 16bit buswith without 245 * Default read function for 16bit buswith without
244 * endianess conversion 246 * endianess conversion
245 */ 247 */
246static u16 nand_read_word(struct mtd_info *mtd) 248static u16 nand_read_word(struct mtd_info *mtd)
@@ -254,7 +256,7 @@ static u16 nand_read_word(struct mtd_info *mtd)
254 * @mtd: MTD device structure 256 * @mtd: MTD device structure
255 * @word: data word to write 257 * @word: data word to write
256 * 258 *
257 * Default write function for 16bit buswith without 259 * Default write function for 16bit buswith without
258 * endianess conversion 260 * endianess conversion
259 */ 261 */
260static void nand_write_word(struct mtd_info *mtd, u16 word) 262static void nand_write_word(struct mtd_info *mtd, u16 word)
@@ -275,7 +277,7 @@ static void nand_select_chip(struct mtd_info *mtd, int chip)
275 struct nand_chip *this = mtd->priv; 277 struct nand_chip *this = mtd->priv;
276 switch(chip) { 278 switch(chip) {
277 case -1: 279 case -1:
278 this->hwcontrol(mtd, NAND_CTL_CLRNCE); 280 this->hwcontrol(mtd, NAND_CTL_CLRNCE);
279 break; 281 break;
280 case 0: 282 case 0:
281 this->hwcontrol(mtd, NAND_CTL_SETNCE); 283 this->hwcontrol(mtd, NAND_CTL_SETNCE);
@@ -304,7 +306,7 @@ static void nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
304} 306}
305 307
306/** 308/**
307 * nand_read_buf - [DEFAULT] read chip data into buffer 309 * nand_read_buf - [DEFAULT] read chip data into buffer
308 * @mtd: MTD device structure 310 * @mtd: MTD device structure
309 * @buf: buffer to store date 311 * @buf: buffer to store date
310 * @len: number of bytes to read 312 * @len: number of bytes to read
@@ -321,7 +323,7 @@ static void nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
321} 323}
322 324
323/** 325/**
324 * nand_verify_buf - [DEFAULT] Verify chip data against buffer 326 * nand_verify_buf - [DEFAULT] Verify chip data against buffer
325 * @mtd: MTD device structure 327 * @mtd: MTD device structure
326 * @buf: buffer containing the data to compare 328 * @buf: buffer containing the data to compare
327 * @len: number of bytes to compare 329 * @len: number of bytes to compare
@@ -354,14 +356,14 @@ static void nand_write_buf16(struct mtd_info *mtd, const u_char *buf, int len)
354 struct nand_chip *this = mtd->priv; 356 struct nand_chip *this = mtd->priv;
355 u16 *p = (u16 *) buf; 357 u16 *p = (u16 *) buf;
356 len >>= 1; 358 len >>= 1;
357 359
358 for (i=0; i<len; i++) 360 for (i=0; i<len; i++)
359 writew(p[i], this->IO_ADDR_W); 361 writew(p[i], this->IO_ADDR_W);
360 362
361} 363}
362 364
363/** 365/**
364 * nand_read_buf16 - [DEFAULT] read chip data into buffer 366 * nand_read_buf16 - [DEFAULT] read chip data into buffer
365 * @mtd: MTD device structure 367 * @mtd: MTD device structure
366 * @buf: buffer to store date 368 * @buf: buffer to store date
367 * @len: number of bytes to read 369 * @len: number of bytes to read
@@ -380,7 +382,7 @@ static void nand_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
380} 382}
381 383
382/** 384/**
383 * nand_verify_buf16 - [DEFAULT] Verify chip data against buffer 385 * nand_verify_buf16 - [DEFAULT] Verify chip data against buffer
384 * @mtd: MTD device structure 386 * @mtd: MTD device structure
385 * @buf: buffer containing the data to compare 387 * @buf: buffer containing the data to compare
386 * @len: number of bytes to compare 388 * @len: number of bytes to compare
@@ -407,7 +409,7 @@ static int nand_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len)
407 * @ofs: offset from device start 409 * @ofs: offset from device start
408 * @getchip: 0, if the chip is already selected 410 * @getchip: 0, if the chip is already selected
409 * 411 *
410 * Check, if the block is bad. 412 * Check, if the block is bad.
411 */ 413 */
412static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) 414static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
413{ 415{
@@ -424,14 +426,14 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
424 426
425 /* Select the NAND device */ 427 /* Select the NAND device */
426 this->select_chip(mtd, chipnr); 428 this->select_chip(mtd, chipnr);
427 } else 429 } else
428 page = (int) ofs; 430 page = (int) ofs;
429 431
430 if (this->options & NAND_BUSWIDTH_16) { 432 if (this->options & NAND_BUSWIDTH_16) {
431 this->cmdfunc (mtd, NAND_CMD_READOOB, this->badblockpos & 0xFE, page & this->pagemask); 433 this->cmdfunc (mtd, NAND_CMD_READOOB, this->badblockpos & 0xFE, page & this->pagemask);
432 bad = cpu_to_le16(this->read_word(mtd)); 434 bad = cpu_to_le16(this->read_word(mtd));
433 if (this->badblockpos & 0x1) 435 if (this->badblockpos & 0x1)
434 bad >>= 1; 436 bad >>= 8;
435 if ((bad & 0xFF) != 0xff) 437 if ((bad & 0xFF) != 0xff)
436 res = 1; 438 res = 1;
437 } else { 439 } else {
@@ -439,12 +441,12 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
439 if (this->read_byte(mtd) != 0xff) 441 if (this->read_byte(mtd) != 0xff)
440 res = 1; 442 res = 1;
441 } 443 }
442 444
443 if (getchip) { 445 if (getchip) {
444 /* Deselect and wake up anyone waiting on the device */ 446 /* Deselect and wake up anyone waiting on the device */
445 nand_release_device(mtd); 447 nand_release_device(mtd);
446 } 448 }
447 449
448 return res; 450 return res;
449} 451}
450 452
@@ -462,7 +464,7 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
462 u_char buf[2] = {0, 0}; 464 u_char buf[2] = {0, 0};
463 size_t retlen; 465 size_t retlen;
464 int block; 466 int block;
465 467
466 /* Get block number */ 468 /* Get block number */
467 block = ((int) ofs) >> this->bbt_erase_shift; 469 block = ((int) ofs) >> this->bbt_erase_shift;
468 if (this->bbt) 470 if (this->bbt)
@@ -471,25 +473,25 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
471 /* Do we have a flash based bad block table ? */ 473 /* Do we have a flash based bad block table ? */
472 if (this->options & NAND_USE_FLASH_BBT) 474 if (this->options & NAND_USE_FLASH_BBT)
473 return nand_update_bbt (mtd, ofs); 475 return nand_update_bbt (mtd, ofs);
474 476
475 /* We write two bytes, so we dont have to mess with 16 bit access */ 477 /* We write two bytes, so we dont have to mess with 16 bit access */
476 ofs += mtd->oobsize + (this->badblockpos & ~0x01); 478 ofs += mtd->oobsize + (this->badblockpos & ~0x01);
477 return nand_write_oob (mtd, ofs , 2, &retlen, buf); 479 return nand_write_oob (mtd, ofs , 2, &retlen, buf);
478} 480}
479 481
480/** 482/**
481 * nand_check_wp - [GENERIC] check if the chip is write protected 483 * nand_check_wp - [GENERIC] check if the chip is write protected
482 * @mtd: MTD device structure 484 * @mtd: MTD device structure
483 * Check, if the device is write protected 485 * Check, if the device is write protected
484 * 486 *
485 * The function expects, that the device is already selected 487 * The function expects, that the device is already selected
486 */ 488 */
487static int nand_check_wp (struct mtd_info *mtd) 489static int nand_check_wp (struct mtd_info *mtd)
488{ 490{
489 struct nand_chip *this = mtd->priv; 491 struct nand_chip *this = mtd->priv;
490 /* Check the WP bit */ 492 /* Check the WP bit */
491 this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); 493 this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1);
492 return (this->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1; 494 return (this->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1;
493} 495}
494 496
495/** 497/**
@@ -505,15 +507,15 @@ static int nand_check_wp (struct mtd_info *mtd)
505static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt) 507static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt)
506{ 508{
507 struct nand_chip *this = mtd->priv; 509 struct nand_chip *this = mtd->priv;
508 510
509 if (!this->bbt) 511 if (!this->bbt)
510 return this->block_bad(mtd, ofs, getchip); 512 return this->block_bad(mtd, ofs, getchip);
511 513
512 /* Return info from the table */ 514 /* Return info from the table */
513 return nand_isbad_bbt (mtd, ofs, allowbbt); 515 return nand_isbad_bbt (mtd, ofs, allowbbt);
514} 516}
515 517
516/* 518/*
517 * Wait for the ready pin, after a command 519 * Wait for the ready pin, after a command
518 * The timeout is catched later. 520 * The timeout is catched later.
519 */ 521 */
@@ -527,7 +529,7 @@ static void nand_wait_ready(struct mtd_info *mtd)
527 if (this->dev_ready(mtd)) 529 if (this->dev_ready(mtd))
528 return; 530 return;
529 touch_softlockup_watchdog(); 531 touch_softlockup_watchdog();
530 } while (time_before(jiffies, timeo)); 532 } while (time_before(jiffies, timeo));
531} 533}
532 534
533/** 535/**
@@ -590,13 +592,13 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in
590 /* Latch in address */ 592 /* Latch in address */
591 this->hwcontrol(mtd, NAND_CTL_CLRALE); 593 this->hwcontrol(mtd, NAND_CTL_CLRALE);
592 } 594 }
593 595
594 /* 596 /*
595 * program and erase have their own busy handlers 597 * program and erase have their own busy handlers
596 * status and sequential in needs no delay 598 * status and sequential in needs no delay
597 */ 599 */
598 switch (command) { 600 switch (command) {
599 601
600 case NAND_CMD_PAGEPROG: 602 case NAND_CMD_PAGEPROG:
601 case NAND_CMD_ERASE1: 603 case NAND_CMD_ERASE1:
602 case NAND_CMD_ERASE2: 604 case NAND_CMD_ERASE2:
@@ -605,7 +607,7 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in
605 return; 607 return;
606 608
607 case NAND_CMD_RESET: 609 case NAND_CMD_RESET:
608 if (this->dev_ready) 610 if (this->dev_ready)
609 break; 611 break;
610 udelay(this->chip_delay); 612 udelay(this->chip_delay);
611 this->hwcontrol(mtd, NAND_CTL_SETCLE); 613 this->hwcontrol(mtd, NAND_CTL_SETCLE);
@@ -614,16 +616,16 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in
614 while ( !(this->read_byte(mtd) & NAND_STATUS_READY)); 616 while ( !(this->read_byte(mtd) & NAND_STATUS_READY));
615 return; 617 return;
616 618
617 /* This applies to read commands */ 619 /* This applies to read commands */
618 default: 620 default:
619 /* 621 /*
620 * If we don't have access to the busy pin, we apply the given 622 * If we don't have access to the busy pin, we apply the given
621 * command delay 623 * command delay
622 */ 624 */
623 if (!this->dev_ready) { 625 if (!this->dev_ready) {
624 udelay (this->chip_delay); 626 udelay (this->chip_delay);
625 return; 627 return;
626 } 628 }
627 } 629 }
628 /* Apply this short delay always to ensure that we do wait tWB in 630 /* Apply this short delay always to ensure that we do wait tWB in
629 * any case on any machine. */ 631 * any case on any machine. */
@@ -653,8 +655,8 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
653 column += mtd->oobblock; 655 column += mtd->oobblock;
654 command = NAND_CMD_READ0; 656 command = NAND_CMD_READ0;
655 } 657 }
656 658
657 659
658 /* Begin command latch cycle */ 660 /* Begin command latch cycle */
659 this->hwcontrol(mtd, NAND_CTL_SETCLE); 661 this->hwcontrol(mtd, NAND_CTL_SETCLE);
660 /* Write out the command to the device. */ 662 /* Write out the command to the device. */
@@ -672,7 +674,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
672 column >>= 1; 674 column >>= 1;
673 this->write_byte(mtd, column & 0xff); 675 this->write_byte(mtd, column & 0xff);
674 this->write_byte(mtd, column >> 8); 676 this->write_byte(mtd, column >> 8);
675 } 677 }
676 if (page_addr != -1) { 678 if (page_addr != -1) {
677 this->write_byte(mtd, (unsigned char) (page_addr & 0xff)); 679 this->write_byte(mtd, (unsigned char) (page_addr & 0xff));
678 this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff)); 680 this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff));
@@ -683,13 +685,13 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
683 /* Latch in address */ 685 /* Latch in address */
684 this->hwcontrol(mtd, NAND_CTL_CLRALE); 686 this->hwcontrol(mtd, NAND_CTL_CLRALE);
685 } 687 }
686 688
687 /* 689 /*
688 * program and erase have their own busy handlers 690 * program and erase have their own busy handlers
689 * status, sequential in, and deplete1 need no delay 691 * status, sequential in, and deplete1 need no delay
690 */ 692 */
691 switch (command) { 693 switch (command) {
692 694
693 case NAND_CMD_CACHEDPROG: 695 case NAND_CMD_CACHEDPROG:
694 case NAND_CMD_PAGEPROG: 696 case NAND_CMD_PAGEPROG:
695 case NAND_CMD_ERASE1: 697 case NAND_CMD_ERASE1:
@@ -699,7 +701,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
699 case NAND_CMD_DEPLETE1: 701 case NAND_CMD_DEPLETE1:
700 return; 702 return;
701 703
702 /* 704 /*
703 * read error status commands require only a short delay 705 * read error status commands require only a short delay
704 */ 706 */
705 case NAND_CMD_STATUS_ERROR: 707 case NAND_CMD_STATUS_ERROR:
@@ -711,7 +713,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
711 return; 713 return;
712 714
713 case NAND_CMD_RESET: 715 case NAND_CMD_RESET:
714 if (this->dev_ready) 716 if (this->dev_ready)
715 break; 717 break;
716 udelay(this->chip_delay); 718 udelay(this->chip_delay);
717 this->hwcontrol(mtd, NAND_CTL_SETCLE); 719 this->hwcontrol(mtd, NAND_CTL_SETCLE);
@@ -728,17 +730,17 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
728 /* End command latch cycle */ 730 /* End command latch cycle */
729 this->hwcontrol(mtd, NAND_CTL_CLRCLE); 731 this->hwcontrol(mtd, NAND_CTL_CLRCLE);
730 /* Fall through into ready check */ 732 /* Fall through into ready check */
731 733
732 /* This applies to read commands */ 734 /* This applies to read commands */
733 default: 735 default:
734 /* 736 /*
735 * If we don't have access to the busy pin, we apply the given 737 * If we don't have access to the busy pin, we apply the given
736 * command delay 738 * command delay
737 */ 739 */
738 if (!this->dev_ready) { 740 if (!this->dev_ready) {
739 udelay (this->chip_delay); 741 udelay (this->chip_delay);
740 return; 742 return;
741 } 743 }
742 } 744 }
743 745
744 /* Apply this short delay always to ensure that we do wait tWB in 746 /* Apply this short delay always to ensure that we do wait tWB in
@@ -752,11 +754,11 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
752 * nand_get_device - [GENERIC] Get chip for selected access 754 * nand_get_device - [GENERIC] Get chip for selected access
753 * @this: the nand chip descriptor 755 * @this: the nand chip descriptor
754 * @mtd: MTD device structure 756 * @mtd: MTD device structure
755 * @new_state: the state which is requested 757 * @new_state: the state which is requested
756 * 758 *
757 * Get the device and lock it for exclusive access 759 * Get the device and lock it for exclusive access
758 */ 760 */
759static void nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state) 761static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state)
760{ 762{
761 struct nand_chip *active; 763 struct nand_chip *active;
762 spinlock_t *lock; 764 spinlock_t *lock;
@@ -779,7 +781,11 @@ retry:
779 if (active == this && this->state == FL_READY) { 781 if (active == this && this->state == FL_READY) {
780 this->state = new_state; 782 this->state = new_state;
781 spin_unlock(lock); 783 spin_unlock(lock);
782 return; 784 return 0;
785 }
786 if (new_state == FL_PM_SUSPENDED) {
787 spin_unlock(lock);
788 return (this->state == FL_PM_SUSPENDED) ? 0 : -EAGAIN;
783 } 789 }
784 set_current_state(TASK_UNINTERRUPTIBLE); 790 set_current_state(TASK_UNINTERRUPTIBLE);
785 add_wait_queue(wq, &wait); 791 add_wait_queue(wq, &wait);
@@ -796,7 +802,7 @@ retry:
796 * @state: state to select the max. timeout value 802 * @state: state to select the max. timeout value
797 * 803 *
798 * Wait for command done. This applies to erase and program only 804 * Wait for command done. This applies to erase and program only
799 * Erase can take up to 400ms and program up to 20ms according to 805 * Erase can take up to 400ms and program up to 20ms according to
800 * general NAND and SmartMedia specs 806 * general NAND and SmartMedia specs
801 * 807 *
802*/ 808*/
@@ -805,7 +811,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
805 811
806 unsigned long timeo = jiffies; 812 unsigned long timeo = jiffies;
807 int status; 813 int status;
808 814
809 if (state == FL_ERASING) 815 if (state == FL_ERASING)
810 timeo += (HZ * 400) / 1000; 816 timeo += (HZ * 400) / 1000;
811 else 817 else
@@ -817,17 +823,17 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
817 823
818 if ((state == FL_ERASING) && (this->options & NAND_IS_AND)) 824 if ((state == FL_ERASING) && (this->options & NAND_IS_AND))
819 this->cmdfunc (mtd, NAND_CMD_STATUS_MULTI, -1, -1); 825 this->cmdfunc (mtd, NAND_CMD_STATUS_MULTI, -1, -1);
820 else 826 else
821 this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); 827 this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1);
822 828
823 while (time_before(jiffies, timeo)) { 829 while (time_before(jiffies, timeo)) {
824 /* Check, if we were interrupted */ 830 /* Check, if we were interrupted */
825 if (this->state != state) 831 if (this->state != state)
826 return 0; 832 return 0;
827 833
828 if (this->dev_ready) { 834 if (this->dev_ready) {
829 if (this->dev_ready(mtd)) 835 if (this->dev_ready(mtd))
830 break; 836 break;
831 } else { 837 } else {
832 if (this->read_byte(mtd) & NAND_STATUS_READY) 838 if (this->read_byte(mtd) & NAND_STATUS_READY)
833 break; 839 break;
@@ -853,7 +859,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
853 * 859 *
854 * Cached programming is not supported yet. 860 * Cached programming is not supported yet.
855 */ 861 */
856static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, 862static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page,
857 u_char *oob_buf, struct nand_oobinfo *oobsel, int cached) 863 u_char *oob_buf, struct nand_oobinfo *oobsel, int cached)
858{ 864{
859 int i, status; 865 int i, status;
@@ -862,10 +868,10 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa
862 int *oob_config = oobsel->eccpos; 868 int *oob_config = oobsel->eccpos;
863 int datidx = 0, eccidx = 0, eccsteps = this->eccsteps; 869 int datidx = 0, eccidx = 0, eccsteps = this->eccsteps;
864 int eccbytes = 0; 870 int eccbytes = 0;
865 871
866 /* FIXME: Enable cached programming */ 872 /* FIXME: Enable cached programming */
867 cached = 0; 873 cached = 0;
868 874
869 /* Send command to begin auto page programming */ 875 /* Send command to begin auto page programming */
870 this->cmdfunc (mtd, NAND_CMD_SEQIN, 0x00, page); 876 this->cmdfunc (mtd, NAND_CMD_SEQIN, 0x00, page);
871 877
@@ -876,7 +882,7 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa
876 printk (KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n"); 882 printk (KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n");
877 this->write_buf(mtd, this->data_poi, mtd->oobblock); 883 this->write_buf(mtd, this->data_poi, mtd->oobblock);
878 break; 884 break;
879 885
880 /* Software ecc 3/256, write all */ 886 /* Software ecc 3/256, write all */
881 case NAND_ECC_SOFT: 887 case NAND_ECC_SOFT:
882 for (; eccsteps; eccsteps--) { 888 for (; eccsteps; eccsteps--) {
@@ -905,11 +911,11 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa
905 } 911 }
906 break; 912 break;
907 } 913 }
908 914
909 /* Write out OOB data */ 915 /* Write out OOB data */
910 if (this->options & NAND_HWECC_SYNDROME) 916 if (this->options & NAND_HWECC_SYNDROME)
911 this->write_buf(mtd, &oob_buf[oobsel->eccbytes], mtd->oobsize - oobsel->eccbytes); 917 this->write_buf(mtd, &oob_buf[oobsel->eccbytes], mtd->oobsize - oobsel->eccbytes);
912 else 918 else
913 this->write_buf(mtd, oob_buf, mtd->oobsize); 919 this->write_buf(mtd, oob_buf, mtd->oobsize);
914 920
915 /* Send command to actually program the data */ 921 /* Send command to actually program the data */
@@ -934,7 +940,7 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa
934 /* wait until cache is ready*/ 940 /* wait until cache is ready*/
935 // status = this->waitfunc (mtd, this, FL_CACHEDRPG); 941 // status = this->waitfunc (mtd, this, FL_CACHEDRPG);
936 } 942 }
937 return 0; 943 return 0;
938} 944}
939 945
940#ifdef CONFIG_MTD_NAND_VERIFY_WRITE 946#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
@@ -950,19 +956,19 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa
950 * @oobmode: 1 = full buffer verify, 0 = ecc only 956 * @oobmode: 1 = full buffer verify, 0 = ecc only
951 * 957 *
952 * The NAND device assumes that it is always writing to a cleanly erased page. 958 * The NAND device assumes that it is always writing to a cleanly erased page.
953 * Hence, it performs its internal write verification only on bits that 959 * Hence, it performs its internal write verification only on bits that
954 * transitioned from 1 to 0. The device does NOT verify the whole page on a 960 * transitioned from 1 to 0. The device does NOT verify the whole page on a
955 * byte by byte basis. It is possible that the page was not completely erased 961 * byte by byte basis. It is possible that the page was not completely erased
956 * or the page is becoming unusable due to wear. The read with ECC would catch 962 * or the page is becoming unusable due to wear. The read with ECC would catch
957 * the error later when the ECC page check fails, but we would rather catch 963 * the error later when the ECC page check fails, but we would rather catch
958 * it early in the page write stage. Better to write no data than invalid data. 964 * it early in the page write stage. Better to write no data than invalid data.
959 */ 965 */
960static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, 966static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages,
961 u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode) 967 u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode)
962{ 968{
963 int i, j, datidx = 0, oobofs = 0, res = -EIO; 969 int i, j, datidx = 0, oobofs = 0, res = -EIO;
964 int eccsteps = this->eccsteps; 970 int eccsteps = this->eccsteps;
965 int hweccbytes; 971 int hweccbytes;
966 u_char oobdata[64]; 972 u_char oobdata[64];
967 973
968 hweccbytes = (this->options & NAND_HWECC_SYNDROME) ? (oobsel->eccbytes / eccsteps) : 0; 974 hweccbytes = (this->options & NAND_HWECC_SYNDROME) ? (oobsel->eccbytes / eccsteps) : 0;
@@ -1002,7 +1008,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
1002 1008
1003 if (oobsel->useecc != MTD_NANDECC_OFF && !hweccbytes) { 1009 if (oobsel->useecc != MTD_NANDECC_OFF && !hweccbytes) {
1004 int ecccnt = oobsel->eccbytes; 1010 int ecccnt = oobsel->eccbytes;
1005 1011
1006 for (i = 0; i < ecccnt; i++) { 1012 for (i = 0; i < ecccnt; i++) {
1007 int idx = oobsel->eccpos[i]; 1013 int idx = oobsel->eccpos[i];
1008 if (oobdata[idx] != oob_buf[oobofs + idx] ) { 1014 if (oobdata[idx] != oob_buf[oobofs + idx] ) {
@@ -1012,20 +1018,20 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
1012 goto out; 1018 goto out;
1013 } 1019 }
1014 } 1020 }
1015 } 1021 }
1016 } 1022 }
1017 oobofs += mtd->oobsize - hweccbytes * eccsteps; 1023 oobofs += mtd->oobsize - hweccbytes * eccsteps;
1018 page++; 1024 page++;
1019 numpages--; 1025 numpages--;
1020 1026
1021 /* Apply delay or wait for ready/busy pin 1027 /* Apply delay or wait for ready/busy pin
1022 * Do this before the AUTOINCR check, so no problems 1028 * Do this before the AUTOINCR check, so no problems
1023 * arise if a chip which does auto increment 1029 * arise if a chip which does auto increment
1024 * is marked as NOAUTOINCR by the board driver. 1030 * is marked as NOAUTOINCR by the board driver.
1025 * Do this also before returning, so the chip is 1031 * Do this also before returning, so the chip is
1026 * ready for the next command. 1032 * ready for the next command.
1027 */ 1033 */
1028 if (!this->dev_ready) 1034 if (!this->dev_ready)
1029 udelay (this->chip_delay); 1035 udelay (this->chip_delay);
1030 else 1036 else
1031 nand_wait_ready(mtd); 1037 nand_wait_ready(mtd);
@@ -1033,17 +1039,17 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
1033 /* All done, return happy */ 1039 /* All done, return happy */
1034 if (!numpages) 1040 if (!numpages)
1035 return 0; 1041 return 0;
1036 1042
1037 1043
1038 /* Check, if the chip supports auto page increment */ 1044 /* Check, if the chip supports auto page increment */
1039 if (!NAND_CANAUTOINCR(this)) 1045 if (!NAND_CANAUTOINCR(this))
1040 this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page); 1046 this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page);
1041 } 1047 }
1042 /* 1048 /*
1043 * Terminate the read command. We come here in case of an error 1049 * Terminate the read command. We come here in case of an error
1044 * So we must issue a reset command. 1050 * So we must issue a reset command.
1045 */ 1051 */
1046out: 1052out:
1047 this->cmdfunc (mtd, NAND_CMD_RESET, -1, -1); 1053 this->cmdfunc (mtd, NAND_CMD_RESET, -1, -1);
1048 return res; 1054 return res;
1049} 1055}
@@ -1105,7 +1111,7 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1105 * NAND read with ECC 1111 * NAND read with ECC
1106 */ 1112 */
1107int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, 1113int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1108 size_t * retlen, u_char * buf, u_char * oob_buf, 1114 size_t * retlen, u_char * buf, u_char * oob_buf,
1109 struct nand_oobinfo *oobsel, int flags) 1115 struct nand_oobinfo *oobsel, int flags)
1110{ 1116{
1111 1117
@@ -1139,7 +1145,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1139 /* Autoplace of oob data ? Use the default placement scheme */ 1145 /* Autoplace of oob data ? Use the default placement scheme */
1140 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) 1146 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE)
1141 oobsel = this->autooob; 1147 oobsel = this->autooob;
1142 1148
1143 eccmode = oobsel->useecc ? this->eccmode : NAND_ECC_NONE; 1149 eccmode = oobsel->useecc ? this->eccmode : NAND_ECC_NONE;
1144 oob_config = oobsel->eccpos; 1150 oob_config = oobsel->eccpos;
1145 1151
@@ -1157,28 +1163,28 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1157 end = mtd->oobblock; 1163 end = mtd->oobblock;
1158 ecc = this->eccsize; 1164 ecc = this->eccsize;
1159 eccbytes = this->eccbytes; 1165 eccbytes = this->eccbytes;
1160 1166
1161 if ((eccmode == NAND_ECC_NONE) || (this->options & NAND_HWECC_SYNDROME)) 1167 if ((eccmode == NAND_ECC_NONE) || (this->options & NAND_HWECC_SYNDROME))
1162 compareecc = 0; 1168 compareecc = 0;
1163 1169
1164 oobreadlen = mtd->oobsize; 1170 oobreadlen = mtd->oobsize;
1165 if (this->options & NAND_HWECC_SYNDROME) 1171 if (this->options & NAND_HWECC_SYNDROME)
1166 oobreadlen -= oobsel->eccbytes; 1172 oobreadlen -= oobsel->eccbytes;
1167 1173
1168 /* Loop until all data read */ 1174 /* Loop until all data read */
1169 while (read < len) { 1175 while (read < len) {
1170 1176
1171 int aligned = (!col && (len - read) >= end); 1177 int aligned = (!col && (len - read) >= end);
1172 /* 1178 /*
1173 * If the read is not page aligned, we have to read into data buffer 1179 * If the read is not page aligned, we have to read into data buffer
1174 * due to ecc, else we read into return buffer direct 1180 * due to ecc, else we read into return buffer direct
1175 */ 1181 */
1176 if (aligned) 1182 if (aligned)
1177 data_poi = &buf[read]; 1183 data_poi = &buf[read];
1178 else 1184 else
1179 data_poi = this->data_buf; 1185 data_poi = this->data_buf;
1180 1186
1181 /* Check, if we have this page in the buffer 1187 /* Check, if we have this page in the buffer
1182 * 1188 *
1183 * FIXME: Make it work when we must provide oob data too, 1189 * FIXME: Make it work when we must provide oob data too,
1184 * check the usage of data_buf oob field 1190 * check the usage of data_buf oob field
@@ -1194,7 +1200,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1194 if (sndcmd) { 1200 if (sndcmd) {
1195 this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page); 1201 this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page);
1196 sndcmd = 0; 1202 sndcmd = 0;
1197 } 1203 }
1198 1204
1199 /* get oob area, if we have no oob buffer from fs-driver */ 1205 /* get oob area, if we have no oob buffer from fs-driver */
1200 if (!oob_buf || oobsel->useecc == MTD_NANDECC_AUTOPLACE || 1206 if (!oob_buf || oobsel->useecc == MTD_NANDECC_AUTOPLACE ||
@@ -1202,7 +1208,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1202 oob_data = &this->data_buf[end]; 1208 oob_data = &this->data_buf[end];
1203 1209
1204 eccsteps = this->eccsteps; 1210 eccsteps = this->eccsteps;
1205 1211
1206 switch (eccmode) { 1212 switch (eccmode) {
1207 case NAND_ECC_NONE: { /* No ECC, Read in a page */ 1213 case NAND_ECC_NONE: { /* No ECC, Read in a page */
1208 static unsigned long lastwhinge = 0; 1214 static unsigned long lastwhinge = 0;
@@ -1213,12 +1219,12 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1213 this->read_buf(mtd, data_poi, end); 1219 this->read_buf(mtd, data_poi, end);
1214 break; 1220 break;
1215 } 1221 }
1216 1222
1217 case NAND_ECC_SOFT: /* Software ECC 3/256: Read in a page + oob data */ 1223 case NAND_ECC_SOFT: /* Software ECC 3/256: Read in a page + oob data */
1218 this->read_buf(mtd, data_poi, end); 1224 this->read_buf(mtd, data_poi, end);
1219 for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=3, datidx += ecc) 1225 for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=3, datidx += ecc)
1220 this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]); 1226 this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]);
1221 break; 1227 break;
1222 1228
1223 default: 1229 default:
1224 for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=eccbytes, datidx += ecc) { 1230 for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=eccbytes, datidx += ecc) {
@@ -1237,15 +1243,15 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1237 * does the error correction on the fly */ 1243 * does the error correction on the fly */
1238 ecc_status = this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]); 1244 ecc_status = this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]);
1239 if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { 1245 if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) {
1240 DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " 1246 DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: "
1241 "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr); 1247 "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr);
1242 ecc_failed++; 1248 ecc_failed++;
1243 } 1249 }
1244 } else { 1250 } else {
1245 this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]); 1251 this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]);
1246 } 1252 }
1247 } 1253 }
1248 break; 1254 break;
1249 } 1255 }
1250 1256
1251 /* read oobdata */ 1257 /* read oobdata */
@@ -1253,8 +1259,8 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1253 1259
1254 /* Skip ECC check, if not requested (ECC_NONE or HW_ECC with syndromes) */ 1260 /* Skip ECC check, if not requested (ECC_NONE or HW_ECC with syndromes) */
1255 if (!compareecc) 1261 if (!compareecc)
1256 goto readoob; 1262 goto readoob;
1257 1263
1258 /* Pick the ECC bytes out of the oob data */ 1264 /* Pick the ECC bytes out of the oob data */
1259 for (j = 0; j < oobsel->eccbytes; j++) 1265 for (j = 0; j < oobsel->eccbytes; j++)
1260 ecc_code[j] = oob_data[oob_config[j]]; 1266 ecc_code[j] = oob_data[oob_config[j]];
@@ -1262,24 +1268,24 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1262 /* correct data, if neccecary */ 1268 /* correct data, if neccecary */
1263 for (i = 0, j = 0, datidx = 0; i < this->eccsteps; i++, datidx += ecc) { 1269 for (i = 0, j = 0, datidx = 0; i < this->eccsteps; i++, datidx += ecc) {
1264 ecc_status = this->correct_data(mtd, &data_poi[datidx], &ecc_code[j], &ecc_calc[j]); 1270 ecc_status = this->correct_data(mtd, &data_poi[datidx], &ecc_code[j], &ecc_calc[j]);
1265 1271
1266 /* Get next chunk of ecc bytes */ 1272 /* Get next chunk of ecc bytes */
1267 j += eccbytes; 1273 j += eccbytes;
1268 1274
1269 /* Check, if we have a fs supplied oob-buffer, 1275 /* Check, if we have a fs supplied oob-buffer,
1270 * This is the legacy mode. Used by YAFFS1 1276 * This is the legacy mode. Used by YAFFS1
1271 * Should go away some day 1277 * Should go away some day
1272 */ 1278 */
1273 if (oob_buf && oobsel->useecc == MTD_NANDECC_PLACE) { 1279 if (oob_buf && oobsel->useecc == MTD_NANDECC_PLACE) {
1274 int *p = (int *)(&oob_data[mtd->oobsize]); 1280 int *p = (int *)(&oob_data[mtd->oobsize]);
1275 p[i] = ecc_status; 1281 p[i] = ecc_status;
1276 } 1282 }
1277 1283
1278 if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { 1284 if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) {
1279 DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " "Failed ECC read, page 0x%08x\n", page); 1285 DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " "Failed ECC read, page 0x%08x\n", page);
1280 ecc_failed++; 1286 ecc_failed++;
1281 } 1287 }
1282 } 1288 }
1283 1289
1284 readoob: 1290 readoob:
1285 /* check, if we have a fs supplied oob-buffer */ 1291 /* check, if we have a fs supplied oob-buffer */
@@ -1305,25 +1311,25 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1305 } 1311 }
1306 readdata: 1312 readdata:
1307 /* Partial page read, transfer data into fs buffer */ 1313 /* Partial page read, transfer data into fs buffer */
1308 if (!aligned) { 1314 if (!aligned) {
1309 for (j = col; j < end && read < len; j++) 1315 for (j = col; j < end && read < len; j++)
1310 buf[read++] = data_poi[j]; 1316 buf[read++] = data_poi[j];
1311 this->pagebuf = realpage; 1317 this->pagebuf = realpage;
1312 } else 1318 } else
1313 read += mtd->oobblock; 1319 read += mtd->oobblock;
1314 1320
1315 /* Apply delay or wait for ready/busy pin 1321 /* Apply delay or wait for ready/busy pin
1316 * Do this before the AUTOINCR check, so no problems 1322 * Do this before the AUTOINCR check, so no problems
1317 * arise if a chip which does auto increment 1323 * arise if a chip which does auto increment
1318 * is marked as NOAUTOINCR by the board driver. 1324 * is marked as NOAUTOINCR by the board driver.
1319 */ 1325 */
1320 if (!this->dev_ready) 1326 if (!this->dev_ready)
1321 udelay (this->chip_delay); 1327 udelay (this->chip_delay);
1322 else 1328 else
1323 nand_wait_ready(mtd); 1329 nand_wait_ready(mtd);
1324 1330
1325 if (read == len) 1331 if (read == len)
1326 break; 1332 break;
1327 1333
1328 /* For subsequent reads align to page boundary. */ 1334 /* For subsequent reads align to page boundary. */
1329 col = 0; 1335 col = 0;
@@ -1337,11 +1343,11 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1337 this->select_chip(mtd, -1); 1343 this->select_chip(mtd, -1);
1338 this->select_chip(mtd, chipnr); 1344 this->select_chip(mtd, chipnr);
1339 } 1345 }
1340 /* Check, if the chip supports auto page increment 1346 /* Check, if the chip supports auto page increment
1341 * or if we have hit a block boundary. 1347 * or if we have hit a block boundary.
1342 */ 1348 */
1343 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) 1349 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck))
1344 sndcmd = 1; 1350 sndcmd = 1;
1345 } 1351 }
1346 1352
1347 /* Deselect and wake up anyone waiting on the device */ 1353 /* Deselect and wake up anyone waiting on the device */
@@ -1378,7 +1384,7 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t
1378 /* Shift to get page */ 1384 /* Shift to get page */
1379 page = (int)(from >> this->page_shift); 1385 page = (int)(from >> this->page_shift);
1380 chipnr = (int)(from >> this->chip_shift); 1386 chipnr = (int)(from >> this->chip_shift);
1381 1387
1382 /* Mask to get column */ 1388 /* Mask to get column */
1383 col = from & (mtd->oobsize - 1); 1389 col = from & (mtd->oobsize - 1);
1384 1390
@@ -1400,7 +1406,7 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t
1400 1406
1401 /* Send the read command */ 1407 /* Send the read command */
1402 this->cmdfunc (mtd, NAND_CMD_READOOB, col, page & this->pagemask); 1408 this->cmdfunc (mtd, NAND_CMD_READOOB, col, page & this->pagemask);
1403 /* 1409 /*
1404 * Read the data, if we read more than one page 1410 * Read the data, if we read more than one page
1405 * oob data, let the device transfer the data ! 1411 * oob data, let the device transfer the data !
1406 */ 1412 */
@@ -1422,20 +1428,20 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t
1422 this->select_chip(mtd, -1); 1428 this->select_chip(mtd, -1);
1423 this->select_chip(mtd, chipnr); 1429 this->select_chip(mtd, chipnr);
1424 } 1430 }
1425 1431
1426 /* Apply delay or wait for ready/busy pin 1432 /* Apply delay or wait for ready/busy pin
1427 * Do this before the AUTOINCR check, so no problems 1433 * Do this before the AUTOINCR check, so no problems
1428 * arise if a chip which does auto increment 1434 * arise if a chip which does auto increment
1429 * is marked as NOAUTOINCR by the board driver. 1435 * is marked as NOAUTOINCR by the board driver.
1430 */ 1436 */
1431 if (!this->dev_ready) 1437 if (!this->dev_ready)
1432 udelay (this->chip_delay); 1438 udelay (this->chip_delay);
1433 else 1439 else
1434 nand_wait_ready(mtd); 1440 nand_wait_ready(mtd);
1435 1441
1436 /* Check, if the chip supports auto page increment 1442 /* Check, if the chip supports auto page increment
1437 * or if we have hit a block boundary. 1443 * or if we have hit a block boundary.
1438 */ 1444 */
1439 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) { 1445 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) {
1440 /* For subsequent page reads set offset to 0 */ 1446 /* For subsequent page reads set offset to 0 */
1441 this->cmdfunc (mtd, NAND_CMD_READOOB, 0x0, page & this->pagemask); 1447 this->cmdfunc (mtd, NAND_CMD_READOOB, 0x0, page & this->pagemask);
@@ -1481,27 +1487,27 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len,
1481 nand_get_device (this, mtd , FL_READING); 1487 nand_get_device (this, mtd , FL_READING);
1482 1488
1483 this->select_chip (mtd, chip); 1489 this->select_chip (mtd, chip);
1484 1490
1485 /* Add requested oob length */ 1491 /* Add requested oob length */
1486 len += ooblen; 1492 len += ooblen;
1487 1493
1488 while (len) { 1494 while (len) {
1489 if (sndcmd) 1495 if (sndcmd)
1490 this->cmdfunc (mtd, NAND_CMD_READ0, 0, page & this->pagemask); 1496 this->cmdfunc (mtd, NAND_CMD_READ0, 0, page & this->pagemask);
1491 sndcmd = 0; 1497 sndcmd = 0;
1492 1498
1493 this->read_buf (mtd, &buf[cnt], pagesize); 1499 this->read_buf (mtd, &buf[cnt], pagesize);
1494 1500
1495 len -= pagesize; 1501 len -= pagesize;
1496 cnt += pagesize; 1502 cnt += pagesize;
1497 page++; 1503 page++;
1498 1504
1499 if (!this->dev_ready) 1505 if (!this->dev_ready)
1500 udelay (this->chip_delay); 1506 udelay (this->chip_delay);
1501 else 1507 else
1502 nand_wait_ready(mtd); 1508 nand_wait_ready(mtd);
1503 1509
1504 /* Check, if the chip supports auto page increment */ 1510 /* Check, if the chip supports auto page increment */
1505 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) 1511 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck))
1506 sndcmd = 1; 1512 sndcmd = 1;
1507 } 1513 }
@@ -1512,8 +1518,8 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len,
1512} 1518}
1513 1519
1514 1520
1515/** 1521/**
1516 * nand_prepare_oobbuf - [GENERIC] Prepare the out of band buffer 1522 * nand_prepare_oobbuf - [GENERIC] Prepare the out of band buffer
1517 * @mtd: MTD device structure 1523 * @mtd: MTD device structure
1518 * @fsbuf: buffer given by fs driver 1524 * @fsbuf: buffer given by fs driver
1519 * @oobsel: out of band selection structre 1525 * @oobsel: out of band selection structre
@@ -1542,20 +1548,20 @@ static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct
1542 int i, len, ofs; 1548 int i, len, ofs;
1543 1549
1544 /* Zero copy fs supplied buffer */ 1550 /* Zero copy fs supplied buffer */
1545 if (fsbuf && !autoplace) 1551 if (fsbuf && !autoplace)
1546 return fsbuf; 1552 return fsbuf;
1547 1553
1548 /* Check, if the buffer must be filled with ff again */ 1554 /* Check, if the buffer must be filled with ff again */
1549 if (this->oobdirty) { 1555 if (this->oobdirty) {
1550 memset (this->oob_buf, 0xff, 1556 memset (this->oob_buf, 0xff,
1551 mtd->oobsize << (this->phys_erase_shift - this->page_shift)); 1557 mtd->oobsize << (this->phys_erase_shift - this->page_shift));
1552 this->oobdirty = 0; 1558 this->oobdirty = 0;
1553 } 1559 }
1554 1560
1555 /* If we have no autoplacement or no fs buffer use the internal one */ 1561 /* If we have no autoplacement or no fs buffer use the internal one */
1556 if (!autoplace || !fsbuf) 1562 if (!autoplace || !fsbuf)
1557 return this->oob_buf; 1563 return this->oob_buf;
1558 1564
1559 /* Walk through the pages and place the data */ 1565 /* Walk through the pages and place the data */
1560 this->oobdirty = 1; 1566 this->oobdirty = 1;
1561 ofs = 0; 1567 ofs = 0;
@@ -1589,7 +1595,7 @@ static int nand_write (struct mtd_info *mtd, loff_t to, size_t len, size_t * ret
1589{ 1595{
1590 return (nand_write_ecc (mtd, to, len, retlen, buf, NULL, NULL)); 1596 return (nand_write_ecc (mtd, to, len, retlen, buf, NULL, NULL));
1591} 1597}
1592 1598
1593/** 1599/**
1594 * nand_write_ecc - [MTD Interface] NAND write with ECC 1600 * nand_write_ecc - [MTD Interface] NAND write with ECC
1595 * @mtd: MTD device structure 1601 * @mtd: MTD device structure
@@ -1622,7 +1628,7 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
1622 return -EINVAL; 1628 return -EINVAL;
1623 } 1629 }
1624 1630
1625 /* reject writes, which are not page aligned */ 1631 /* reject writes, which are not page aligned */
1626 if (NOTALIGNED (to) || NOTALIGNED(len)) { 1632 if (NOTALIGNED (to) || NOTALIGNED(len)) {
1627 printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); 1633 printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n");
1628 return -EINVAL; 1634 return -EINVAL;
@@ -1641,14 +1647,14 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
1641 goto out; 1647 goto out;
1642 1648
1643 /* if oobsel is NULL, use chip defaults */ 1649 /* if oobsel is NULL, use chip defaults */
1644 if (oobsel == NULL) 1650 if (oobsel == NULL)
1645 oobsel = &mtd->oobinfo; 1651 oobsel = &mtd->oobinfo;
1646 1652
1647 /* Autoplace of oob data ? Use the default placement scheme */ 1653 /* Autoplace of oob data ? Use the default placement scheme */
1648 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) { 1654 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) {
1649 oobsel = this->autooob; 1655 oobsel = this->autooob;
1650 autoplace = 1; 1656 autoplace = 1;
1651 } 1657 }
1652 if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR) 1658 if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR)
1653 autoplace = 1; 1659 autoplace = 1;
1654 1660
@@ -1656,9 +1662,9 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
1656 totalpages = len >> this->page_shift; 1662 totalpages = len >> this->page_shift;
1657 page = (int) (to >> this->page_shift); 1663 page = (int) (to >> this->page_shift);
1658 /* Invalidate the page cache, if we write to the cached page */ 1664 /* Invalidate the page cache, if we write to the cached page */
1659 if (page <= this->pagebuf && this->pagebuf < (page + totalpages)) 1665 if (page <= this->pagebuf && this->pagebuf < (page + totalpages))
1660 this->pagebuf = -1; 1666 this->pagebuf = -1;
1661 1667
1662 /* Set it relative to chip */ 1668 /* Set it relative to chip */
1663 page &= this->pagemask; 1669 page &= this->pagemask;
1664 startpage = page; 1670 startpage = page;
@@ -1680,14 +1686,14 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
1680 if (ret) { 1686 if (ret) {
1681 DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: write_page failed %d\n", ret); 1687 DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: write_page failed %d\n", ret);
1682 goto out; 1688 goto out;
1683 } 1689 }
1684 /* Next oob page */ 1690 /* Next oob page */
1685 oob += mtd->oobsize; 1691 oob += mtd->oobsize;
1686 /* Update written bytes count */ 1692 /* Update written bytes count */
1687 written += mtd->oobblock; 1693 written += mtd->oobblock;
1688 if (written == len) 1694 if (written == len)
1689 goto cmp; 1695 goto cmp;
1690 1696
1691 /* Increment page address */ 1697 /* Increment page address */
1692 page++; 1698 page++;
1693 1699
@@ -1698,13 +1704,13 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
1698 if (!(page & (ppblock - 1))){ 1704 if (!(page & (ppblock - 1))){
1699 int ofs; 1705 int ofs;
1700 this->data_poi = bufstart; 1706 this->data_poi = bufstart;
1701 ret = nand_verify_pages (mtd, this, startpage, 1707 ret = nand_verify_pages (mtd, this, startpage,
1702 page - startpage, 1708 page - startpage,
1703 oobbuf, oobsel, chipnr, (eccbuf != NULL)); 1709 oobbuf, oobsel, chipnr, (eccbuf != NULL));
1704 if (ret) { 1710 if (ret) {
1705 DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); 1711 DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret);
1706 goto out; 1712 goto out;
1707 } 1713 }
1708 *retlen = written; 1714 *retlen = written;
1709 1715
1710 ofs = autoplace ? mtd->oobavail : mtd->oobsize; 1716 ofs = autoplace ? mtd->oobavail : mtd->oobsize;
@@ -1714,8 +1720,9 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
1714 numpages = min (totalpages, ppblock); 1720 numpages = min (totalpages, ppblock);
1715 page &= this->pagemask; 1721 page &= this->pagemask;
1716 startpage = page; 1722 startpage = page;
1717 oobbuf = nand_prepare_oobbuf (mtd, eccbuf, oobsel, 1723 oobbuf = nand_prepare_oobbuf (mtd, eccbuf, oobsel,
1718 autoplace, numpages); 1724 autoplace, numpages);
1725 oob = 0;
1719 /* Check, if we cross a chip boundary */ 1726 /* Check, if we cross a chip boundary */
1720 if (!page) { 1727 if (!page) {
1721 chipnr++; 1728 chipnr++;
@@ -1731,7 +1738,7 @@ cmp:
1731 oobbuf, oobsel, chipnr, (eccbuf != NULL)); 1738 oobbuf, oobsel, chipnr, (eccbuf != NULL));
1732 if (!ret) 1739 if (!ret)
1733 *retlen = written; 1740 *retlen = written;
1734 else 1741 else
1735 DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); 1742 DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret);
1736 1743
1737out: 1744out:
@@ -1791,7 +1798,7 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t *
1791 /* Check, if it is write protected */ 1798 /* Check, if it is write protected */
1792 if (nand_check_wp(mtd)) 1799 if (nand_check_wp(mtd))
1793 goto out; 1800 goto out;
1794 1801
1795 /* Invalidate the page cache, if we write to the cached page */ 1802 /* Invalidate the page cache, if we write to the cached page */
1796 if (page == this->pagebuf) 1803 if (page == this->pagebuf)
1797 this->pagebuf = -1; 1804 this->pagebuf = -1;
@@ -1854,10 +1861,10 @@ out:
1854 * 1861 *
1855 * NAND write with kvec. This just calls the ecc function 1862 * NAND write with kvec. This just calls the ecc function
1856 */ 1863 */
1857static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, 1864static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count,
1858 loff_t to, size_t * retlen) 1865 loff_t to, size_t * retlen)
1859{ 1866{
1860 return (nand_writev_ecc (mtd, vecs, count, to, retlen, NULL, NULL)); 1867 return (nand_writev_ecc (mtd, vecs, count, to, retlen, NULL, NULL));
1861} 1868}
1862 1869
1863/** 1870/**
@@ -1872,7 +1879,7 @@ static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned
1872 * 1879 *
1873 * NAND write with iovec with ecc 1880 * NAND write with iovec with ecc
1874 */ 1881 */
1875static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, 1882static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count,
1876 loff_t to, size_t * retlen, u_char *eccbuf, struct nand_oobinfo *oobsel) 1883 loff_t to, size_t * retlen, u_char *eccbuf, struct nand_oobinfo *oobsel)
1877{ 1884{
1878 int i, page, len, total_len, ret = -EIO, written = 0, chipnr; 1885 int i, page, len, total_len, ret = -EIO, written = 0, chipnr;
@@ -1898,7 +1905,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
1898 return -EINVAL; 1905 return -EINVAL;
1899 } 1906 }
1900 1907
1901 /* reject writes, which are not page aligned */ 1908 /* reject writes, which are not page aligned */
1902 if (NOTALIGNED (to) || NOTALIGNED(total_len)) { 1909 if (NOTALIGNED (to) || NOTALIGNED(total_len)) {
1903 printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); 1910 printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n");
1904 return -EINVAL; 1911 return -EINVAL;
@@ -1917,21 +1924,21 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
1917 goto out; 1924 goto out;
1918 1925
1919 /* if oobsel is NULL, use chip defaults */ 1926 /* if oobsel is NULL, use chip defaults */
1920 if (oobsel == NULL) 1927 if (oobsel == NULL)
1921 oobsel = &mtd->oobinfo; 1928 oobsel = &mtd->oobinfo;
1922 1929
1923 /* Autoplace of oob data ? Use the default placement scheme */ 1930 /* Autoplace of oob data ? Use the default placement scheme */
1924 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) { 1931 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) {
1925 oobsel = this->autooob; 1932 oobsel = this->autooob;
1926 autoplace = 1; 1933 autoplace = 1;
1927 } 1934 }
1928 if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR) 1935 if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR)
1929 autoplace = 1; 1936 autoplace = 1;
1930 1937
1931 /* Setup start page */ 1938 /* Setup start page */
1932 page = (int) (to >> this->page_shift); 1939 page = (int) (to >> this->page_shift);
1933 /* Invalidate the page cache, if we write to the cached page */ 1940 /* Invalidate the page cache, if we write to the cached page */
1934 if (page <= this->pagebuf && this->pagebuf < ((to + total_len) >> this->page_shift)) 1941 if (page <= this->pagebuf && this->pagebuf < ((to + total_len) >> this->page_shift))
1935 this->pagebuf = -1; 1942 this->pagebuf = -1;
1936 1943
1937 startpage = page & this->pagemask; 1944 startpage = page & this->pagemask;
@@ -1955,10 +1962,10 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
1955 oob = 0; 1962 oob = 0;
1956 for (i = 1; i <= numpages; i++) { 1963 for (i = 1; i <= numpages; i++) {
1957 /* Write one page. If this is the last page to write 1964 /* Write one page. If this is the last page to write
1958 * then use the real pageprogram command, else select 1965 * then use the real pageprogram command, else select
1959 * cached programming if supported by the chip. 1966 * cached programming if supported by the chip.
1960 */ 1967 */
1961 ret = nand_write_page (mtd, this, page & this->pagemask, 1968 ret = nand_write_page (mtd, this, page & this->pagemask,
1962 &oobbuf[oob], oobsel, i != numpages); 1969 &oobbuf[oob], oobsel, i != numpages);
1963 if (ret) 1970 if (ret)
1964 goto out; 1971 goto out;
@@ -1974,12 +1981,12 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
1974 count--; 1981 count--;
1975 } 1982 }
1976 } else { 1983 } else {
1977 /* We must use the internal buffer, read data out of each 1984 /* We must use the internal buffer, read data out of each
1978 * tuple until we have a full page to write 1985 * tuple until we have a full page to write
1979 */ 1986 */
1980 int cnt = 0; 1987 int cnt = 0;
1981 while (cnt < mtd->oobblock) { 1988 while (cnt < mtd->oobblock) {
1982 if (vecs->iov_base != NULL && vecs->iov_len) 1989 if (vecs->iov_base != NULL && vecs->iov_len)
1983 this->data_buf[cnt++] = ((u_char *) vecs->iov_base)[len++]; 1990 this->data_buf[cnt++] = ((u_char *) vecs->iov_base)[len++];
1984 /* Check, if we have to switch to the next tuple */ 1991 /* Check, if we have to switch to the next tuple */
1985 if (len >= (int) vecs->iov_len) { 1992 if (len >= (int) vecs->iov_len) {
@@ -1988,10 +1995,10 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
1988 count--; 1995 count--;
1989 } 1996 }
1990 } 1997 }
1991 this->pagebuf = page; 1998 this->pagebuf = page;
1992 this->data_poi = this->data_buf; 1999 this->data_poi = this->data_buf;
1993 bufstart = this->data_poi; 2000 bufstart = this->data_poi;
1994 numpages = 1; 2001 numpages = 1;
1995 oobbuf = nand_prepare_oobbuf (mtd, NULL, oobsel, autoplace, numpages); 2002 oobbuf = nand_prepare_oobbuf (mtd, NULL, oobsel, autoplace, numpages);
1996 ret = nand_write_page (mtd, this, page & this->pagemask, 2003 ret = nand_write_page (mtd, this, page & this->pagemask,
1997 oobbuf, oobsel, 0); 2004 oobbuf, oobsel, 0);
@@ -2004,7 +2011,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
2004 ret = nand_verify_pages (mtd, this, startpage, numpages, oobbuf, oobsel, chipnr, 0); 2011 ret = nand_verify_pages (mtd, this, startpage, numpages, oobbuf, oobsel, chipnr, 0);
2005 if (ret) 2012 if (ret)
2006 goto out; 2013 goto out;
2007 2014
2008 written += mtd->oobblock * numpages; 2015 written += mtd->oobblock * numpages;
2009 /* All done ? */ 2016 /* All done ? */
2010 if (!count) 2017 if (!count)
@@ -2072,7 +2079,7 @@ static int nand_erase (struct mtd_info *mtd, struct erase_info *instr)
2072{ 2079{
2073 return nand_erase_nand (mtd, instr, 0); 2080 return nand_erase_nand (mtd, instr, 0);
2074} 2081}
2075 2082
2076#define BBT_PAGE_MASK 0xffffff3f 2083#define BBT_PAGE_MASK 0xffffff3f
2077/** 2084/**
2078 * nand_erase_intern - [NAND Interface] erase block(s) 2085 * nand_erase_intern - [NAND Interface] erase block(s)
@@ -2154,14 +2161,14 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
2154 instr->state = MTD_ERASE_FAILED; 2161 instr->state = MTD_ERASE_FAILED;
2155 goto erase_exit; 2162 goto erase_exit;
2156 } 2163 }
2157 2164
2158 /* Invalidate the page cache, if we erase the block which contains 2165 /* Invalidate the page cache, if we erase the block which contains
2159 the current cached page */ 2166 the current cached page */
2160 if (page <= this->pagebuf && this->pagebuf < (page + pages_per_block)) 2167 if (page <= this->pagebuf && this->pagebuf < (page + pages_per_block))
2161 this->pagebuf = -1; 2168 this->pagebuf = -1;
2162 2169
2163 this->erase_cmd (mtd, page & this->pagemask); 2170 this->erase_cmd (mtd, page & this->pagemask);
2164 2171
2165 status = this->waitfunc (mtd, this, FL_ERASING); 2172 status = this->waitfunc (mtd, this, FL_ERASING);
2166 2173
2167 /* See if operation failed and additional status checks are available */ 2174 /* See if operation failed and additional status checks are available */
@@ -2179,12 +2186,12 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
2179 2186
2180 /* if BBT requires refresh, set the BBT rewrite flag to the page being erased */ 2187 /* if BBT requires refresh, set the BBT rewrite flag to the page being erased */
2181 if (this->options & BBT_AUTO_REFRESH) { 2188 if (this->options & BBT_AUTO_REFRESH) {
2182 if (((page & BBT_PAGE_MASK) == bbt_masked_page) && 2189 if (((page & BBT_PAGE_MASK) == bbt_masked_page) &&
2183 (page != this->bbt_td->pages[chipnr])) { 2190 (page != this->bbt_td->pages[chipnr])) {
2184 rewrite_bbt[chipnr] = (page << this->page_shift); 2191 rewrite_bbt[chipnr] = (page << this->page_shift);
2185 } 2192 }
2186 } 2193 }
2187 2194
2188 /* Increment page address and decrement length */ 2195 /* Increment page address and decrement length */
2189 len -= (1 << this->phys_erase_shift); 2196 len -= (1 << this->phys_erase_shift);
2190 page += pages_per_block; 2197 page += pages_per_block;
@@ -2195,7 +2202,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
2195 this->select_chip(mtd, -1); 2202 this->select_chip(mtd, -1);
2196 this->select_chip(mtd, chipnr); 2203 this->select_chip(mtd, chipnr);
2197 2204
2198 /* if BBT requires refresh and BBT-PERCHIP, 2205 /* if BBT requires refresh and BBT-PERCHIP,
2199 * set the BBT page mask to see if this BBT should be rewritten */ 2206 * set the BBT page mask to see if this BBT should be rewritten */
2200 if ((this->options & BBT_AUTO_REFRESH) && (this->bbt_td->options & NAND_BBT_PERCHIP)) { 2207 if ((this->options & BBT_AUTO_REFRESH) && (this->bbt_td->options & NAND_BBT_PERCHIP)) {
2201 bbt_masked_page = this->bbt_td->pages[chipnr] & BBT_PAGE_MASK; 2208 bbt_masked_page = this->bbt_td->pages[chipnr] & BBT_PAGE_MASK;
@@ -2220,7 +2227,7 @@ erase_exit:
2220 for (chipnr = 0; chipnr < this->numchips; chipnr++) { 2227 for (chipnr = 0; chipnr < this->numchips; chipnr++) {
2221 if (rewrite_bbt[chipnr]) { 2228 if (rewrite_bbt[chipnr]) {
2222 /* update the BBT for chip */ 2229 /* update the BBT for chip */
2223 DEBUG (MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt (%d:0x%0x 0x%0x)\n", 2230 DEBUG (MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt (%d:0x%0x 0x%0x)\n",
2224 chipnr, rewrite_bbt[chipnr], this->bbt_td->pages[chipnr]); 2231 chipnr, rewrite_bbt[chipnr], this->bbt_td->pages[chipnr]);
2225 nand_update_bbt (mtd, rewrite_bbt[chipnr]); 2232 nand_update_bbt (mtd, rewrite_bbt[chipnr]);
2226 } 2233 }
@@ -2258,9 +2265,9 @@ static void nand_sync (struct mtd_info *mtd)
2258static int nand_block_isbad (struct mtd_info *mtd, loff_t ofs) 2265static int nand_block_isbad (struct mtd_info *mtd, loff_t ofs)
2259{ 2266{
2260 /* Check for invalid offset */ 2267 /* Check for invalid offset */
2261 if (ofs > mtd->size) 2268 if (ofs > mtd->size)
2262 return -EINVAL; 2269 return -EINVAL;
2263 2270
2264 return nand_block_checkbad (mtd, ofs, 1, 0); 2271 return nand_block_checkbad (mtd, ofs, 1, 0);
2265} 2272}
2266 2273
@@ -2285,6 +2292,34 @@ static int nand_block_markbad (struct mtd_info *mtd, loff_t ofs)
2285} 2292}
2286 2293
2287/** 2294/**
2295 * nand_suspend - [MTD Interface] Suspend the NAND flash
2296 * @mtd: MTD device structure
2297 */
2298static int nand_suspend(struct mtd_info *mtd)
2299{
2300 struct nand_chip *this = mtd->priv;
2301
2302 return nand_get_device (this, mtd, FL_PM_SUSPENDED);
2303}
2304
2305/**
2306 * nand_resume - [MTD Interface] Resume the NAND flash
2307 * @mtd: MTD device structure
2308 */
2309static void nand_resume(struct mtd_info *mtd)
2310{
2311 struct nand_chip *this = mtd->priv;
2312
2313 if (this->state == FL_PM_SUSPENDED)
2314 nand_release_device(mtd);
2315 else
2316 printk(KERN_ERR "resume() called for the chip which is not "
2317 "in suspended state\n");
2318
2319}
2320
2321
2322/**
2288 * nand_scan - [NAND Interface] Scan for the NAND device 2323 * nand_scan - [NAND Interface] Scan for the NAND device
2289 * @mtd: MTD device structure 2324 * @mtd: MTD device structure
2290 * @maxchips: Number of chips to scan for 2325 * @maxchips: Number of chips to scan for
@@ -2351,13 +2386,13 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2351 2386
2352 /* Print and store flash device information */ 2387 /* Print and store flash device information */
2353 for (i = 0; nand_flash_ids[i].name != NULL; i++) { 2388 for (i = 0; nand_flash_ids[i].name != NULL; i++) {
2354 2389
2355 if (nand_dev_id != nand_flash_ids[i].id) 2390 if (nand_dev_id != nand_flash_ids[i].id)
2356 continue; 2391 continue;
2357 2392
2358 if (!mtd->name) mtd->name = nand_flash_ids[i].name; 2393 if (!mtd->name) mtd->name = nand_flash_ids[i].name;
2359 this->chipsize = nand_flash_ids[i].chipsize << 20; 2394 this->chipsize = nand_flash_ids[i].chipsize << 20;
2360 2395
2361 /* New devices have all the information in additional id bytes */ 2396 /* New devices have all the information in additional id bytes */
2362 if (!nand_flash_ids[i].pagesize) { 2397 if (!nand_flash_ids[i].pagesize) {
2363 int extid; 2398 int extid;
@@ -2369,14 +2404,14 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2369 mtd->oobblock = 1024 << (extid & 0x3); 2404 mtd->oobblock = 1024 << (extid & 0x3);
2370 extid >>= 2; 2405 extid >>= 2;
2371 /* Calc oobsize */ 2406 /* Calc oobsize */
2372 mtd->oobsize = (8 << (extid & 0x03)) * (mtd->oobblock / 512); 2407 mtd->oobsize = (8 << (extid & 0x01)) * (mtd->oobblock >> 9);
2373 extid >>= 2; 2408 extid >>= 2;
2374 /* Calc blocksize. Blocksize is multiples of 64KiB */ 2409 /* Calc blocksize. Blocksize is multiples of 64KiB */
2375 mtd->erasesize = (64 * 1024) << (extid & 0x03); 2410 mtd->erasesize = (64 * 1024) << (extid & 0x03);
2376 extid >>= 2; 2411 extid >>= 2;
2377 /* Get buswidth information */ 2412 /* Get buswidth information */
2378 busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; 2413 busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0;
2379 2414
2380 } else { 2415 } else {
2381 /* Old devices have this data hardcoded in the 2416 /* Old devices have this data hardcoded in the
2382 * device id table */ 2417 * device id table */
@@ -2396,23 +2431,23 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2396 * this correct ! */ 2431 * this correct ! */
2397 if (busw != (this->options & NAND_BUSWIDTH_16)) { 2432 if (busw != (this->options & NAND_BUSWIDTH_16)) {
2398 printk (KERN_INFO "NAND device: Manufacturer ID:" 2433 printk (KERN_INFO "NAND device: Manufacturer ID:"
2399 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, 2434 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id,
2400 nand_manuf_ids[maf_id].name , mtd->name); 2435 nand_manuf_ids[maf_id].name , mtd->name);
2401 printk (KERN_WARNING 2436 printk (KERN_WARNING
2402 "NAND bus width %d instead %d bit\n", 2437 "NAND bus width %d instead %d bit\n",
2403 (this->options & NAND_BUSWIDTH_16) ? 16 : 8, 2438 (this->options & NAND_BUSWIDTH_16) ? 16 : 8,
2404 busw ? 16 : 8); 2439 busw ? 16 : 8);
2405 this->select_chip(mtd, -1); 2440 this->select_chip(mtd, -1);
2406 return 1; 2441 return 1;
2407 } 2442 }
2408 2443
2409 /* Calculate the address shift from the page size */ 2444 /* Calculate the address shift from the page size */
2410 this->page_shift = ffs(mtd->oobblock) - 1; 2445 this->page_shift = ffs(mtd->oobblock) - 1;
2411 this->bbt_erase_shift = this->phys_erase_shift = ffs(mtd->erasesize) - 1; 2446 this->bbt_erase_shift = this->phys_erase_shift = ffs(mtd->erasesize) - 1;
2412 this->chip_shift = ffs(this->chipsize) - 1; 2447 this->chip_shift = ffs(this->chipsize) - 1;
2413 2448
2414 /* Set the bad block position */ 2449 /* Set the bad block position */
2415 this->badblockpos = mtd->oobblock > 512 ? 2450 this->badblockpos = mtd->oobblock > 512 ?
2416 NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS; 2451 NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS;
2417 2452
2418 /* Get chip options, preserve non chip based options */ 2453 /* Get chip options, preserve non chip based options */
@@ -2422,10 +2457,10 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2422 this->options |= NAND_NO_AUTOINCR; 2457 this->options |= NAND_NO_AUTOINCR;
2423 /* Check if this is a not a samsung device. Do not clear the options 2458 /* Check if this is a not a samsung device. Do not clear the options
2424 * for chips which are not having an extended id. 2459 * for chips which are not having an extended id.
2425 */ 2460 */
2426 if (nand_maf_id != NAND_MFR_SAMSUNG && !nand_flash_ids[i].pagesize) 2461 if (nand_maf_id != NAND_MFR_SAMSUNG && !nand_flash_ids[i].pagesize)
2427 this->options &= ~NAND_SAMSUNG_LP_OPTIONS; 2462 this->options &= ~NAND_SAMSUNG_LP_OPTIONS;
2428 2463
2429 /* Check for AND chips with 4 page planes */ 2464 /* Check for AND chips with 4 page planes */
2430 if (this->options & NAND_4PAGE_ARRAY) 2465 if (this->options & NAND_4PAGE_ARRAY)
2431 this->erase_cmd = multi_erase_cmd; 2466 this->erase_cmd = multi_erase_cmd;
@@ -2435,9 +2470,9 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2435 /* Do not replace user supplied command function ! */ 2470 /* Do not replace user supplied command function ! */
2436 if (mtd->oobblock > 512 && this->cmdfunc == nand_command) 2471 if (mtd->oobblock > 512 && this->cmdfunc == nand_command)
2437 this->cmdfunc = nand_command_lp; 2472 this->cmdfunc = nand_command_lp;
2438 2473
2439 printk (KERN_INFO "NAND device: Manufacturer ID:" 2474 printk (KERN_INFO "NAND device: Manufacturer ID:"
2440 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, 2475 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id,
2441 nand_manuf_ids[maf_id].name , nand_flash_ids[i].name); 2476 nand_manuf_ids[maf_id].name , nand_flash_ids[i].name);
2442 break; 2477 break;
2443 } 2478 }
@@ -2461,7 +2496,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2461 } 2496 }
2462 if (i > 1) 2497 if (i > 1)
2463 printk(KERN_INFO "%d NAND chips detected\n", i); 2498 printk(KERN_INFO "%d NAND chips detected\n", i);
2464 2499
2465 /* Allocate buffers, if neccecary */ 2500 /* Allocate buffers, if neccecary */
2466 if (!this->oob_buf) { 2501 if (!this->oob_buf) {
2467 size_t len; 2502 size_t len;
@@ -2473,7 +2508,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2473 } 2508 }
2474 this->options |= NAND_OOBBUF_ALLOC; 2509 this->options |= NAND_OOBBUF_ALLOC;
2475 } 2510 }
2476 2511
2477 if (!this->data_buf) { 2512 if (!this->data_buf) {
2478 size_t len; 2513 size_t len;
2479 len = mtd->oobblock + mtd->oobsize; 2514 len = mtd->oobblock + mtd->oobsize;
@@ -2500,7 +2535,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2500 if (!this->autooob) { 2535 if (!this->autooob) {
2501 /* Select the appropriate default oob placement scheme for 2536 /* Select the appropriate default oob placement scheme for
2502 * placement agnostic filesystems */ 2537 * placement agnostic filesystems */
2503 switch (mtd->oobsize) { 2538 switch (mtd->oobsize) {
2504 case 8: 2539 case 8:
2505 this->autooob = &nand_oob_8; 2540 this->autooob = &nand_oob_8;
2506 break; 2541 break;
@@ -2516,19 +2551,19 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2516 BUG(); 2551 BUG();
2517 } 2552 }
2518 } 2553 }
2519 2554
2520 /* The number of bytes available for the filesystem to place fs dependend 2555 /* The number of bytes available for the filesystem to place fs dependend
2521 * oob data */ 2556 * oob data */
2522 mtd->oobavail = 0; 2557 mtd->oobavail = 0;
2523 for (i = 0; this->autooob->oobfree[i][1]; i++) 2558 for (i = 0; this->autooob->oobfree[i][1]; i++)
2524 mtd->oobavail += this->autooob->oobfree[i][1]; 2559 mtd->oobavail += this->autooob->oobfree[i][1];
2525 2560
2526 /* 2561 /*
2527 * check ECC mode, default to software 2562 * check ECC mode, default to software
2528 * if 3byte/512byte hardware ECC is selected and we have 256 byte pagesize 2563 * if 3byte/512byte hardware ECC is selected and we have 256 byte pagesize
2529 * fallback to software ECC 2564 * fallback to software ECC
2530 */ 2565 */
2531 this->eccsize = 256; /* set default eccsize */ 2566 this->eccsize = 256; /* set default eccsize */
2532 this->eccbytes = 3; 2567 this->eccbytes = 3;
2533 2568
2534 switch (this->eccmode) { 2569 switch (this->eccmode) {
@@ -2543,56 +2578,56 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2543 this->eccsize = 2048; 2578 this->eccsize = 2048;
2544 break; 2579 break;
2545 2580
2546 case NAND_ECC_HW3_512: 2581 case NAND_ECC_HW3_512:
2547 case NAND_ECC_HW6_512: 2582 case NAND_ECC_HW6_512:
2548 case NAND_ECC_HW8_512: 2583 case NAND_ECC_HW8_512:
2549 if (mtd->oobblock == 256) { 2584 if (mtd->oobblock == 256) {
2550 printk (KERN_WARNING "512 byte HW ECC not possible on 256 Byte pagesize, fallback to SW ECC \n"); 2585 printk (KERN_WARNING "512 byte HW ECC not possible on 256 Byte pagesize, fallback to SW ECC \n");
2551 this->eccmode = NAND_ECC_SOFT; 2586 this->eccmode = NAND_ECC_SOFT;
2552 this->calculate_ecc = nand_calculate_ecc; 2587 this->calculate_ecc = nand_calculate_ecc;
2553 this->correct_data = nand_correct_data; 2588 this->correct_data = nand_correct_data;
2554 } else 2589 } else
2555 this->eccsize = 512; /* set eccsize to 512 */ 2590 this->eccsize = 512; /* set eccsize to 512 */
2556 break; 2591 break;
2557 2592
2558 case NAND_ECC_HW3_256: 2593 case NAND_ECC_HW3_256:
2559 break; 2594 break;
2560 2595
2561 case NAND_ECC_NONE: 2596 case NAND_ECC_NONE:
2562 printk (KERN_WARNING "NAND_ECC_NONE selected by board driver. This is not recommended !!\n"); 2597 printk (KERN_WARNING "NAND_ECC_NONE selected by board driver. This is not recommended !!\n");
2563 this->eccmode = NAND_ECC_NONE; 2598 this->eccmode = NAND_ECC_NONE;
2564 break; 2599 break;
2565 2600
2566 case NAND_ECC_SOFT: 2601 case NAND_ECC_SOFT:
2567 this->calculate_ecc = nand_calculate_ecc; 2602 this->calculate_ecc = nand_calculate_ecc;
2568 this->correct_data = nand_correct_data; 2603 this->correct_data = nand_correct_data;
2569 break; 2604 break;
2570 2605
2571 default: 2606 default:
2572 printk (KERN_WARNING "Invalid NAND_ECC_MODE %d\n", this->eccmode); 2607 printk (KERN_WARNING "Invalid NAND_ECC_MODE %d\n", this->eccmode);
2573 BUG(); 2608 BUG();
2574 } 2609 }
2575 2610
2576 /* Check hardware ecc function availability and adjust number of ecc bytes per 2611 /* Check hardware ecc function availability and adjust number of ecc bytes per
2577 * calculation step 2612 * calculation step
2578 */ 2613 */
2579 switch (this->eccmode) { 2614 switch (this->eccmode) {
2580 case NAND_ECC_HW12_2048: 2615 case NAND_ECC_HW12_2048:
2581 this->eccbytes += 4; 2616 this->eccbytes += 4;
2582 case NAND_ECC_HW8_512: 2617 case NAND_ECC_HW8_512:
2583 this->eccbytes += 2; 2618 this->eccbytes += 2;
2584 case NAND_ECC_HW6_512: 2619 case NAND_ECC_HW6_512:
2585 this->eccbytes += 3; 2620 this->eccbytes += 3;
2586 case NAND_ECC_HW3_512: 2621 case NAND_ECC_HW3_512:
2587 case NAND_ECC_HW3_256: 2622 case NAND_ECC_HW3_256:
2588 if (this->calculate_ecc && this->correct_data && this->enable_hwecc) 2623 if (this->calculate_ecc && this->correct_data && this->enable_hwecc)
2589 break; 2624 break;
2590 printk (KERN_WARNING "No ECC functions supplied, Hardware ECC not possible\n"); 2625 printk (KERN_WARNING "No ECC functions supplied, Hardware ECC not possible\n");
2591 BUG(); 2626 BUG();
2592 } 2627 }
2593 2628
2594 mtd->eccsize = this->eccsize; 2629 mtd->eccsize = this->eccsize;
2595 2630
2596 /* Set the number of read / write steps for one page to ensure ECC generation */ 2631 /* Set the number of read / write steps for one page to ensure ECC generation */
2597 switch (this->eccmode) { 2632 switch (this->eccmode) {
2598 case NAND_ECC_HW12_2048: 2633 case NAND_ECC_HW12_2048:
@@ -2604,15 +2639,15 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2604 this->eccsteps = mtd->oobblock / 512; 2639 this->eccsteps = mtd->oobblock / 512;
2605 break; 2640 break;
2606 case NAND_ECC_HW3_256: 2641 case NAND_ECC_HW3_256:
2607 case NAND_ECC_SOFT: 2642 case NAND_ECC_SOFT:
2608 this->eccsteps = mtd->oobblock / 256; 2643 this->eccsteps = mtd->oobblock / 256;
2609 break; 2644 break;
2610 2645
2611 case NAND_ECC_NONE: 2646 case NAND_ECC_NONE:
2612 this->eccsteps = 1; 2647 this->eccsteps = 1;
2613 break; 2648 break;
2614 } 2649 }
2615 2650
2616 /* Initialize state, waitqueue and spinlock */ 2651 /* Initialize state, waitqueue and spinlock */
2617 this->state = FL_READY; 2652 this->state = FL_READY;
2618 init_waitqueue_head (&this->wq); 2653 init_waitqueue_head (&this->wq);
@@ -2643,8 +2678,8 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2643 mtd->sync = nand_sync; 2678 mtd->sync = nand_sync;
2644 mtd->lock = NULL; 2679 mtd->lock = NULL;
2645 mtd->unlock = NULL; 2680 mtd->unlock = NULL;
2646 mtd->suspend = NULL; 2681 mtd->suspend = nand_suspend;
2647 mtd->resume = NULL; 2682 mtd->resume = nand_resume;
2648 mtd->block_isbad = nand_block_isbad; 2683 mtd->block_isbad = nand_block_isbad;
2649 mtd->block_markbad = nand_block_markbad; 2684 mtd->block_markbad = nand_block_markbad;
2650 2685
@@ -2652,7 +2687,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2652 memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo)); 2687 memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo));
2653 2688
2654 mtd->owner = THIS_MODULE; 2689 mtd->owner = THIS_MODULE;
2655 2690
2656 /* Check, if we should skip the bad block table scan */ 2691 /* Check, if we should skip the bad block table scan */
2657 if (this->options & NAND_SKIP_BBTSCAN) 2692 if (this->options & NAND_SKIP_BBTSCAN)
2658 return 0; 2693 return 0;
@@ -2662,7 +2697,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2662} 2697}
2663 2698
2664/** 2699/**
2665 * nand_release - [NAND Interface] Free resources held by the NAND device 2700 * nand_release - [NAND Interface] Free resources held by the NAND device
2666 * @mtd: MTD device structure 2701 * @mtd: MTD device structure
2667*/ 2702*/
2668void nand_release (struct mtd_info *mtd) 2703void nand_release (struct mtd_info *mtd)
@@ -2676,9 +2711,8 @@ void nand_release (struct mtd_info *mtd)
2676 /* Deregister the device */ 2711 /* Deregister the device */
2677 del_mtd_device (mtd); 2712 del_mtd_device (mtd);
2678 2713
2679 /* Free bad block table memory, if allocated */ 2714 /* Free bad block table memory */
2680 if (this->bbt) 2715 kfree (this->bbt);
2681 kfree (this->bbt);
2682 /* Buffer allocated by nand_scan ? */ 2716 /* Buffer allocated by nand_scan ? */
2683 if (this->options & NAND_OOBBUF_ALLOC) 2717 if (this->options & NAND_OOBBUF_ALLOC)
2684 kfree (this->oob_buf); 2718 kfree (this->oob_buf);
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index 7535ef53685e..ca286999fe08 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -3,10 +3,10 @@
3 * 3 *
4 * Overview: 4 * Overview:
5 * Bad block table support for the NAND driver 5 * Bad block table support for the NAND driver
6 * 6 *
7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de) 7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)
8 * 8 *
9 * $Id: nand_bbt.c,v 1.35 2005/07/15 13:53:47 gleixner Exp $ 9 * $Id: nand_bbt.c,v 1.36 2005/11/07 11:14:30 gleixner Exp $
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as 12 * it under the terms of the GNU General Public License version 2 as
@@ -14,23 +14,23 @@
14 * 14 *
15 * Description: 15 * Description:
16 * 16 *
17 * When nand_scan_bbt is called, then it tries to find the bad block table 17 * When nand_scan_bbt is called, then it tries to find the bad block table
18 * depending on the options in the bbt descriptor(s). If a bbt is found 18 * depending on the options in the bbt descriptor(s). If a bbt is found
19 * then the contents are read and the memory based bbt is created. If a 19 * then the contents are read and the memory based bbt is created. If a
20 * mirrored bbt is selected then the mirror is searched too and the 20 * mirrored bbt is selected then the mirror is searched too and the
21 * versions are compared. If the mirror has a greater version number 21 * versions are compared. If the mirror has a greater version number
22 * than the mirror bbt is used to build the memory based bbt. 22 * than the mirror bbt is used to build the memory based bbt.
23 * If the tables are not versioned, then we "or" the bad block information. 23 * If the tables are not versioned, then we "or" the bad block information.
24 * If one of the bbt's is out of date or does not exist it is (re)created. 24 * If one of the bbt's is out of date or does not exist it is (re)created.
25 * If no bbt exists at all then the device is scanned for factory marked 25 * If no bbt exists at all then the device is scanned for factory marked
26 * good / bad blocks and the bad block tables are created. 26 * good / bad blocks and the bad block tables are created.
27 * 27 *
28 * For manufacturer created bbts like the one found on M-SYS DOC devices 28 * For manufacturer created bbts like the one found on M-SYS DOC devices
29 * the bbt is searched and read but never created 29 * the bbt is searched and read but never created
30 * 30 *
31 * The autogenerated bad block table is located in the last good blocks 31 * The autogenerated bad block table is located in the last good blocks
32 * of the device. The table is mirrored, so it can be updated eventually. 32 * of the device. The table is mirrored, so it can be updated eventually.
33 * The table is marked in the oob area with an ident pattern and a version 33 * The table is marked in the oob area with an ident pattern and a version
34 * number which indicates which of both tables is more up to date. 34 * number which indicates which of both tables is more up to date.
35 * 35 *
36 * The table uses 2 bits per block 36 * The table uses 2 bits per block
@@ -43,13 +43,13 @@
43 * 01b: block is marked bad due to wear 43 * 01b: block is marked bad due to wear
44 * 10b: block is reserved (to protect the bbt area) 44 * 10b: block is reserved (to protect the bbt area)
45 * 11b: block is factory marked bad 45 * 11b: block is factory marked bad
46 * 46 *
47 * Multichip devices like DOC store the bad block info per floor. 47 * Multichip devices like DOC store the bad block info per floor.
48 * 48 *
49 * Following assumptions are made: 49 * Following assumptions are made:
50 * - bbts start at a page boundary, if autolocated on a block boundary 50 * - bbts start at a page boundary, if autolocated on a block boundary
51 * - the space neccecary for a bbt in FLASH does not exceed a block boundary 51 * - the space neccecary for a bbt in FLASH does not exceed a block boundary
52 * 52 *
53 */ 53 */
54 54
55#include <linux/slab.h> 55#include <linux/slab.h>
@@ -62,7 +62,7 @@
62#include <linux/delay.h> 62#include <linux/delay.h>
63 63
64 64
65/** 65/**
66 * check_pattern - [GENERIC] check if a pattern is in the buffer 66 * check_pattern - [GENERIC] check if a pattern is in the buffer
67 * @buf: the buffer to search 67 * @buf: the buffer to search
68 * @len: the length of buffer to search 68 * @len: the length of buffer to search
@@ -86,9 +86,9 @@ static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_des
86 if (p[i] != 0xff) 86 if (p[i] != 0xff)
87 return -1; 87 return -1;
88 } 88 }
89 } 89 }
90 p += end; 90 p += end;
91 91
92 /* Compare the pattern */ 92 /* Compare the pattern */
93 for (i = 0; i < td->len; i++) { 93 for (i = 0; i < td->len; i++) {
94 if (p[i] != td->pattern[i]) 94 if (p[i] != td->pattern[i])
@@ -106,13 +106,13 @@ static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_des
106 return 0; 106 return 0;
107} 107}
108 108
109/** 109/**
110 * check_short_pattern - [GENERIC] check if a pattern is in the buffer 110 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
111 * @buf: the buffer to search 111 * @buf: the buffer to search
112 * @td: search pattern descriptor 112 * @td: search pattern descriptor
113 * 113 *
114 * Check for a pattern at the given place. Used to search bad block 114 * Check for a pattern at the given place. Used to search bad block
115 * tables and good / bad block identifiers. Same as check_pattern, but 115 * tables and good / bad block identifiers. Same as check_pattern, but
116 * no optional empty check 116 * no optional empty check
117 * 117 *
118*/ 118*/
@@ -142,7 +142,7 @@ static int check_short_pattern (uint8_t *buf, struct nand_bbt_descr *td)
142 * Read the bad block table starting from page. 142 * Read the bad block table starting from page.
143 * 143 *
144 */ 144 */
145static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num, 145static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
146 int bits, int offs, int reserved_block_code) 146 int bits, int offs, int reserved_block_code)
147{ 147{
148 int res, i, j, act = 0; 148 int res, i, j, act = 0;
@@ -153,7 +153,7 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
153 153
154 totlen = (num * bits) >> 3; 154 totlen = (num * bits) >> 3;
155 from = ((loff_t)page) << this->page_shift; 155 from = ((loff_t)page) << this->page_shift;
156 156
157 while (totlen) { 157 while (totlen) {
158 len = min (totlen, (size_t) (1 << this->bbt_erase_shift)); 158 len = min (totlen, (size_t) (1 << this->bbt_erase_shift));
159 res = mtd->read_ecc (mtd, from, len, &retlen, buf, NULL, this->autooob); 159 res = mtd->read_ecc (mtd, from, len, &retlen, buf, NULL, this->autooob);
@@ -163,7 +163,7 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
163 return res; 163 return res;
164 } 164 }
165 printk (KERN_WARNING "nand_bbt: ECC error while reading bad block table\n"); 165 printk (KERN_WARNING "nand_bbt: ECC error while reading bad block table\n");
166 } 166 }
167 167
168 /* Analyse data */ 168 /* Analyse data */
169 for (i = 0; i < len; i++) { 169 for (i = 0; i < len; i++) {
@@ -183,12 +183,12 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
183 * message to MTD_DEBUG_LEVEL0 */ 183 * message to MTD_DEBUG_LEVEL0 */
184 printk (KERN_DEBUG "nand_read_bbt: Bad block at 0x%08x\n", 184 printk (KERN_DEBUG "nand_read_bbt: Bad block at 0x%08x\n",
185 ((offs << 2) + (act >> 1)) << this->bbt_erase_shift); 185 ((offs << 2) + (act >> 1)) << this->bbt_erase_shift);
186 /* Factory marked bad or worn out ? */ 186 /* Factory marked bad or worn out ? */
187 if (tmp == 0) 187 if (tmp == 0)
188 this->bbt[offs + (act >> 3)] |= 0x3 << (act & 0x06); 188 this->bbt[offs + (act >> 3)] |= 0x3 << (act & 0x06);
189 else 189 else
190 this->bbt[offs + (act >> 3)] |= 0x1 << (act & 0x06); 190 this->bbt[offs + (act >> 3)] |= 0x1 << (act & 0x06);
191 } 191 }
192 } 192 }
193 totlen -= len; 193 totlen -= len;
194 from += len; 194 from += len;
@@ -200,7 +200,7 @@ static int read_bbt (struct mtd_info *mtd, uint8_t *buf, int page, int num,
200 * read_abs_bbt - [GENERIC] Read the bad block table starting at a given page 200 * read_abs_bbt - [GENERIC] Read the bad block table starting at a given page
201 * @mtd: MTD device structure 201 * @mtd: MTD device structure
202 * @buf: temporary buffer 202 * @buf: temporary buffer
203 * @td: descriptor for the bad block table 203 * @td: descriptor for the bad block table
204 * @chip: read the table for a specific chip, -1 read all chips. 204 * @chip: read the table for a specific chip, -1 read all chips.
205 * Applies only if NAND_BBT_PERCHIP option is set 205 * Applies only if NAND_BBT_PERCHIP option is set
206 * 206 *
@@ -235,7 +235,7 @@ static int read_abs_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des
235 * read_abs_bbts - [GENERIC] Read the bad block table(s) for all chips starting at a given page 235 * read_abs_bbts - [GENERIC] Read the bad block table(s) for all chips starting at a given page
236 * @mtd: MTD device structure 236 * @mtd: MTD device structure
237 * @buf: temporary buffer 237 * @buf: temporary buffer
238 * @td: descriptor for the bad block table 238 * @td: descriptor for the bad block table
239 * @md: descriptor for the bad block table mirror 239 * @md: descriptor for the bad block table mirror
240 * 240 *
241 * Read the bad block table(s) for all chips starting at a given page 241 * Read the bad block table(s) for all chips starting at a given page
@@ -247,16 +247,16 @@ static int read_abs_bbts (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_de
247{ 247{
248 struct nand_chip *this = mtd->priv; 248 struct nand_chip *this = mtd->priv;
249 249
250 /* Read the primary version, if available */ 250 /* Read the primary version, if available */
251 if (td->options & NAND_BBT_VERSION) { 251 if (td->options & NAND_BBT_VERSION) {
252 nand_read_raw (mtd, buf, td->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize); 252 nand_read_raw (mtd, buf, td->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize);
253 td->version[0] = buf[mtd->oobblock + td->veroffs]; 253 td->version[0] = buf[mtd->oobblock + td->veroffs];
254 printk (KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", td->pages[0], td->version[0]); 254 printk (KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", td->pages[0], td->version[0]);
255 } 255 }
256 256
257 /* Read the mirror version, if available */ 257 /* Read the mirror version, if available */
258 if (md && (md->options & NAND_BBT_VERSION)) { 258 if (md && (md->options & NAND_BBT_VERSION)) {
259 nand_read_raw (mtd, buf, md->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize); 259 nand_read_raw (mtd, buf, md->pages[0] << this->page_shift, mtd->oobblock, mtd->oobsize);
260 md->version[0] = buf[mtd->oobblock + md->veroffs]; 260 md->version[0] = buf[mtd->oobblock + md->veroffs];
261 printk (KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", md->pages[0], md->version[0]); 261 printk (KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", md->pages[0], md->version[0]);
262 } 262 }
@@ -290,7 +290,7 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
290 else { 290 else {
291 if (bd->options & NAND_BBT_SCAN2NDPAGE) 291 if (bd->options & NAND_BBT_SCAN2NDPAGE)
292 len = 2; 292 len = 2;
293 else 293 else
294 len = 1; 294 len = 1;
295 } 295 }
296 296
@@ -322,10 +322,10 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
322 numblocks += startblock; 322 numblocks += startblock;
323 from = startblock << (this->bbt_erase_shift - 1); 323 from = startblock << (this->bbt_erase_shift - 1);
324 } 324 }
325 325
326 for (i = startblock; i < numblocks;) { 326 for (i = startblock; i < numblocks;) {
327 int ret; 327 int ret;
328 328
329 if (bd->options & NAND_BBT_SCANEMPTY) 329 if (bd->options & NAND_BBT_SCANEMPTY)
330 if ((ret = nand_read_raw (mtd, buf, from, readlen, ooblen))) 330 if ((ret = nand_read_raw (mtd, buf, from, readlen, ooblen)))
331 return ret; 331 return ret;
@@ -333,8 +333,8 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
333 for (j = 0; j < len; j++) { 333 for (j = 0; j < len; j++) {
334 if (!(bd->options & NAND_BBT_SCANEMPTY)) { 334 if (!(bd->options & NAND_BBT_SCANEMPTY)) {
335 size_t retlen; 335 size_t retlen;
336 336
337 /* Read the full oob until read_oob is fixed to 337 /* Read the full oob until read_oob is fixed to
338 * handle single byte reads for 16 bit buswidth */ 338 * handle single byte reads for 16 bit buswidth */
339 ret = mtd->read_oob(mtd, from + j * mtd->oobblock, 339 ret = mtd->read_oob(mtd, from + j * mtd->oobblock,
340 mtd->oobsize, &retlen, buf); 340 mtd->oobsize, &retlen, buf);
@@ -343,14 +343,14 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
343 343
344 if (check_short_pattern (buf, bd)) { 344 if (check_short_pattern (buf, bd)) {
345 this->bbt[i >> 3] |= 0x03 << (i & 0x6); 345 this->bbt[i >> 3] |= 0x03 << (i & 0x6);
346 printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n", 346 printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
347 i >> 1, (unsigned int) from); 347 i >> 1, (unsigned int) from);
348 break; 348 break;
349 } 349 }
350 } else { 350 } else {
351 if (check_pattern (&buf[j * scanlen], scanlen, mtd->oobblock, bd)) { 351 if (check_pattern (&buf[j * scanlen], scanlen, mtd->oobblock, bd)) {
352 this->bbt[i >> 3] |= 0x03 << (i & 0x6); 352 this->bbt[i >> 3] |= 0x03 << (i & 0x6);
353 printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n", 353 printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
354 i >> 1, (unsigned int) from); 354 i >> 1, (unsigned int) from);
355 break; 355 break;
356 } 356 }
@@ -369,15 +369,15 @@ static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
369 * @td: descriptor for the bad block table 369 * @td: descriptor for the bad block table
370 * 370 *
371 * Read the bad block table by searching for a given ident pattern. 371 * Read the bad block table by searching for a given ident pattern.
372 * Search is preformed either from the beginning up or from the end of 372 * Search is preformed either from the beginning up or from the end of
373 * the device downwards. The search starts always at the start of a 373 * the device downwards. The search starts always at the start of a
374 * block. 374 * block.
375 * If the option NAND_BBT_PERCHIP is given, each chip is searched 375 * If the option NAND_BBT_PERCHIP is given, each chip is searched
376 * for a bbt, which contains the bad block information of this chip. 376 * for a bbt, which contains the bad block information of this chip.
377 * This is neccecary to provide support for certain DOC devices. 377 * This is neccecary to provide support for certain DOC devices.
378 * 378 *
379 * The bbt ident pattern resides in the oob area of the first page 379 * The bbt ident pattern resides in the oob area of the first page
380 * in a block. 380 * in a block.
381 */ 381 */
382static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td) 382static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td)
383{ 383{
@@ -392,10 +392,10 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
392 startblock = (mtd->size >> this->bbt_erase_shift) -1; 392 startblock = (mtd->size >> this->bbt_erase_shift) -1;
393 dir = -1; 393 dir = -1;
394 } else { 394 } else {
395 startblock = 0; 395 startblock = 0;
396 dir = 1; 396 dir = 1;
397 } 397 }
398 398
399 /* Do we have a bbt per chip ? */ 399 /* Do we have a bbt per chip ? */
400 if (td->options & NAND_BBT_PERCHIP) { 400 if (td->options & NAND_BBT_PERCHIP) {
401 chips = this->numchips; 401 chips = this->numchips;
@@ -405,19 +405,19 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
405 chips = 1; 405 chips = 1;
406 bbtblocks = mtd->size >> this->bbt_erase_shift; 406 bbtblocks = mtd->size >> this->bbt_erase_shift;
407 } 407 }
408 408
409 /* Number of bits for each erase block in the bbt */ 409 /* Number of bits for each erase block in the bbt */
410 bits = td->options & NAND_BBT_NRBITS_MSK; 410 bits = td->options & NAND_BBT_NRBITS_MSK;
411 411
412 for (i = 0; i < chips; i++) { 412 for (i = 0; i < chips; i++) {
413 /* Reset version information */ 413 /* Reset version information */
414 td->version[i] = 0; 414 td->version[i] = 0;
415 td->pages[i] = -1; 415 td->pages[i] = -1;
416 /* Scan the maximum number of blocks */ 416 /* Scan the maximum number of blocks */
417 for (block = 0; block < td->maxblocks; block++) { 417 for (block = 0; block < td->maxblocks; block++) {
418 int actblock = startblock + dir * block; 418 int actblock = startblock + dir * block;
419 /* Read first page */ 419 /* Read first page */
420 nand_read_raw (mtd, buf, actblock << this->bbt_erase_shift, mtd->oobblock, mtd->oobsize); 420 nand_read_raw (mtd, buf, actblock << this->bbt_erase_shift, mtd->oobblock, mtd->oobsize);
421 if (!check_pattern(buf, scanlen, mtd->oobblock, td)) { 421 if (!check_pattern(buf, scanlen, mtd->oobblock, td)) {
422 td->pages[i] = actblock << (this->bbt_erase_shift - this->page_shift); 422 td->pages[i] = actblock << (this->bbt_erase_shift - this->page_shift);
423 if (td->options & NAND_BBT_VERSION) { 423 if (td->options & NAND_BBT_VERSION) {
@@ -435,46 +435,46 @@ static int search_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
435 else 435 else
436 printk (KERN_DEBUG "Bad block table found at page %d, version 0x%02X\n", td->pages[i], td->version[i]); 436 printk (KERN_DEBUG "Bad block table found at page %d, version 0x%02X\n", td->pages[i], td->version[i]);
437 } 437 }
438 return 0; 438 return 0;
439} 439}
440 440
441/** 441/**
442 * search_read_bbts - [GENERIC] scan the device for bad block table(s) 442 * search_read_bbts - [GENERIC] scan the device for bad block table(s)
443 * @mtd: MTD device structure 443 * @mtd: MTD device structure
444 * @buf: temporary buffer 444 * @buf: temporary buffer
445 * @td: descriptor for the bad block table 445 * @td: descriptor for the bad block table
446 * @md: descriptor for the bad block table mirror 446 * @md: descriptor for the bad block table mirror
447 * 447 *
448 * Search and read the bad block table(s) 448 * Search and read the bad block table(s)
449*/ 449*/
450static int search_read_bbts (struct mtd_info *mtd, uint8_t *buf, 450static int search_read_bbts (struct mtd_info *mtd, uint8_t *buf,
451 struct nand_bbt_descr *td, struct nand_bbt_descr *md) 451 struct nand_bbt_descr *td, struct nand_bbt_descr *md)
452{ 452{
453 /* Search the primary table */ 453 /* Search the primary table */
454 search_bbt (mtd, buf, td); 454 search_bbt (mtd, buf, td);
455 455
456 /* Search the mirror table */ 456 /* Search the mirror table */
457 if (md) 457 if (md)
458 search_bbt (mtd, buf, md); 458 search_bbt (mtd, buf, md);
459 459
460 /* Force result check */ 460 /* Force result check */
461 return 1; 461 return 1;
462} 462}
463
464 463
465/** 464
465/**
466 * write_bbt - [GENERIC] (Re)write the bad block table 466 * write_bbt - [GENERIC] (Re)write the bad block table
467 * 467 *
468 * @mtd: MTD device structure 468 * @mtd: MTD device structure
469 * @buf: temporary buffer 469 * @buf: temporary buffer
470 * @td: descriptor for the bad block table 470 * @td: descriptor for the bad block table
471 * @md: descriptor for the bad block table mirror 471 * @md: descriptor for the bad block table mirror
472 * @chipsel: selector for a specific chip, -1 for all 472 * @chipsel: selector for a specific chip, -1 for all
473 * 473 *
474 * (Re)write the bad block table 474 * (Re)write the bad block table
475 * 475 *
476*/ 476*/
477static int write_bbt (struct mtd_info *mtd, uint8_t *buf, 477static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
478 struct nand_bbt_descr *td, struct nand_bbt_descr *md, int chipsel) 478 struct nand_bbt_descr *td, struct nand_bbt_descr *md, int chipsel)
479{ 479{
480 struct nand_chip *this = mtd->priv; 480 struct nand_chip *this = mtd->priv;
@@ -493,7 +493,7 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
493 /* Write bad block table per chip rather than per device ? */ 493 /* Write bad block table per chip rather than per device ? */
494 if (td->options & NAND_BBT_PERCHIP) { 494 if (td->options & NAND_BBT_PERCHIP) {
495 numblocks = (int) (this->chipsize >> this->bbt_erase_shift); 495 numblocks = (int) (this->chipsize >> this->bbt_erase_shift);
496 /* Full device write or specific chip ? */ 496 /* Full device write or specific chip ? */
497 if (chipsel == -1) { 497 if (chipsel == -1) {
498 nrchips = this->numchips; 498 nrchips = this->numchips;
499 } else { 499 } else {
@@ -503,19 +503,19 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
503 } else { 503 } else {
504 numblocks = (int) (mtd->size >> this->bbt_erase_shift); 504 numblocks = (int) (mtd->size >> this->bbt_erase_shift);
505 nrchips = 1; 505 nrchips = 1;
506 } 506 }
507 507
508 /* Loop through the chips */ 508 /* Loop through the chips */
509 for (; chip < nrchips; chip++) { 509 for (; chip < nrchips; chip++) {
510 510
511 /* There was already a version of the table, reuse the page 511 /* There was already a version of the table, reuse the page
512 * This applies for absolute placement too, as we have the 512 * This applies for absolute placement too, as we have the
513 * page nr. in td->pages. 513 * page nr. in td->pages.
514 */ 514 */
515 if (td->pages[chip] != -1) { 515 if (td->pages[chip] != -1) {
516 page = td->pages[chip]; 516 page = td->pages[chip];
517 goto write; 517 goto write;
518 } 518 }
519 519
520 /* Automatic placement of the bad block table */ 520 /* Automatic placement of the bad block table */
521 /* Search direction top -> down ? */ 521 /* Search direction top -> down ? */
@@ -525,7 +525,7 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
525 } else { 525 } else {
526 startblock = chip * numblocks; 526 startblock = chip * numblocks;
527 dir = 1; 527 dir = 1;
528 } 528 }
529 529
530 for (i = 0; i < td->maxblocks; i++) { 530 for (i = 0; i < td->maxblocks; i++) {
531 int block = startblock + dir * i; 531 int block = startblock + dir * i;
@@ -542,7 +542,7 @@ static int write_bbt (struct mtd_info *mtd, uint8_t *buf,
542 } 542 }
543 printk (KERN_ERR "No space left to write bad block table\n"); 543 printk (KERN_ERR "No space left to write bad block table\n");
544 return -ENOSPC; 544 return -ENOSPC;
545write: 545write:
546 546
547 /* Set up shift count and masks for the flash table */ 547 /* Set up shift count and masks for the flash table */
548 bits = td->options & NAND_BBT_NRBITS_MSK; 548 bits = td->options & NAND_BBT_NRBITS_MSK;
@@ -553,14 +553,14 @@ write:
553 case 8: sft = 0; sftmsk = 0x00; msk[0] = 0x00; msk[1] = 0x0F; msk[2] = ~rcode; msk[3] = 0xff; break; 553 case 8: sft = 0; sftmsk = 0x00; msk[0] = 0x00; msk[1] = 0x0F; msk[2] = ~rcode; msk[3] = 0xff; break;
554 default: return -EINVAL; 554 default: return -EINVAL;
555 } 555 }
556 556
557 bbtoffs = chip * (numblocks >> 2); 557 bbtoffs = chip * (numblocks >> 2);
558 558
559 to = ((loff_t) page) << this->page_shift; 559 to = ((loff_t) page) << this->page_shift;
560 560
561 memcpy (&oobinfo, this->autooob, sizeof(oobinfo)); 561 memcpy (&oobinfo, this->autooob, sizeof(oobinfo));
562 oobinfo.useecc = MTD_NANDECC_PLACEONLY; 562 oobinfo.useecc = MTD_NANDECC_PLACEONLY;
563 563
564 /* Must we save the block contents ? */ 564 /* Must we save the block contents ? */
565 if (td->options & NAND_BBT_SAVECONTENT) { 565 if (td->options & NAND_BBT_SAVECONTENT) {
566 /* Make it block aligned */ 566 /* Make it block aligned */
@@ -599,7 +599,7 @@ write:
599 buf[len + td->veroffs] = td->version[chip]; 599 buf[len + td->veroffs] = td->version[chip];
600 } 600 }
601 } 601 }
602 602
603 /* walk through the memory table */ 603 /* walk through the memory table */
604 for (i = 0; i < numblocks; ) { 604 for (i = 0; i < numblocks; ) {
605 uint8_t dat; 605 uint8_t dat;
@@ -611,7 +611,7 @@ write:
611 dat >>= 2; 611 dat >>= 2;
612 } 612 }
613 } 613 }
614 614
615 memset (&einfo, 0, sizeof (einfo)); 615 memset (&einfo, 0, sizeof (einfo));
616 einfo.mtd = mtd; 616 einfo.mtd = mtd;
617 einfo.addr = (unsigned long) to; 617 einfo.addr = (unsigned long) to;
@@ -621,18 +621,18 @@ write:
621 printk (KERN_WARNING "nand_bbt: Error during block erase: %d\n", res); 621 printk (KERN_WARNING "nand_bbt: Error during block erase: %d\n", res);
622 return res; 622 return res;
623 } 623 }
624 624
625 res = mtd->write_ecc (mtd, to, len, &retlen, buf, &buf[len], &oobinfo); 625 res = mtd->write_ecc (mtd, to, len, &retlen, buf, &buf[len], &oobinfo);
626 if (res < 0) { 626 if (res < 0) {
627 printk (KERN_WARNING "nand_bbt: Error while writing bad block table %d\n", res); 627 printk (KERN_WARNING "nand_bbt: Error while writing bad block table %d\n", res);
628 return res; 628 return res;
629 } 629 }
630 printk (KERN_DEBUG "Bad block table written to 0x%08x, version 0x%02X\n", 630 printk (KERN_DEBUG "Bad block table written to 0x%08x, version 0x%02X\n",
631 (unsigned int) to, td->version[chip]); 631 (unsigned int) to, td->version[chip]);
632 632
633 /* Mark it as used */ 633 /* Mark it as used */
634 td->pages[chip] = page; 634 td->pages[chip] = page;
635 } 635 }
636 return 0; 636 return 0;
637} 637}
638 638
@@ -641,7 +641,7 @@ write:
641 * @mtd: MTD device structure 641 * @mtd: MTD device structure
642 * @bd: descriptor for the good/bad block search pattern 642 * @bd: descriptor for the good/bad block search pattern
643 * 643 *
644 * The function creates a memory based bbt by scanning the device 644 * The function creates a memory based bbt by scanning the device
645 * for manufacturer / software marked good / bad blocks 645 * for manufacturer / software marked good / bad blocks
646*/ 646*/
647static inline int nand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd) 647static inline int nand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
@@ -673,11 +673,11 @@ static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des
673 struct nand_bbt_descr *rd, *rd2; 673 struct nand_bbt_descr *rd, *rd2;
674 674
675 /* Do we have a bbt per chip ? */ 675 /* Do we have a bbt per chip ? */
676 if (td->options & NAND_BBT_PERCHIP) 676 if (td->options & NAND_BBT_PERCHIP)
677 chips = this->numchips; 677 chips = this->numchips;
678 else 678 else
679 chips = 1; 679 chips = 1;
680 680
681 for (i = 0; i < chips; i++) { 681 for (i = 0; i < chips; i++) {
682 writeops = 0; 682 writeops = 0;
683 rd = NULL; 683 rd = NULL;
@@ -692,7 +692,7 @@ static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des
692 } 692 }
693 693
694 if (td->pages[i] == -1) { 694 if (td->pages[i] == -1) {
695 rd = md; 695 rd = md;
696 td->version[i] = md->version[i]; 696 td->version[i] = md->version[i];
697 writeops = 1; 697 writeops = 1;
698 goto writecheck; 698 goto writecheck;
@@ -710,7 +710,7 @@ static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des
710 if (!(td->options & NAND_BBT_VERSION)) 710 if (!(td->options & NAND_BBT_VERSION))
711 rd2 = md; 711 rd2 = md;
712 goto writecheck; 712 goto writecheck;
713 } 713 }
714 714
715 if (((int8_t) (td->version[i] - md->version[i])) > 0) { 715 if (((int8_t) (td->version[i] - md->version[i])) > 0) {
716 rd = td; 716 rd = td;
@@ -735,15 +735,15 @@ static int check_create (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_des
735create: 735create:
736 /* Create the bad block table by scanning the device ? */ 736 /* Create the bad block table by scanning the device ? */
737 if (!(td->options & NAND_BBT_CREATE)) 737 if (!(td->options & NAND_BBT_CREATE))
738 continue; 738 continue;
739 739
740 /* Create the table in memory by scanning the chip(s) */ 740 /* Create the table in memory by scanning the chip(s) */
741 create_bbt (mtd, buf, bd, chipsel); 741 create_bbt (mtd, buf, bd, chipsel);
742 742
743 td->version[i] = 1; 743 td->version[i] = 1;
744 if (md) 744 if (md)
745 md->version[i] = 1; 745 md->version[i] = 1;
746writecheck: 746writecheck:
747 /* read back first ? */ 747 /* read back first ? */
748 if (rd) 748 if (rd)
749 read_abs_bbt (mtd, buf, rd, chipsel); 749 read_abs_bbt (mtd, buf, rd, chipsel);
@@ -757,7 +757,7 @@ writecheck:
757 if (res < 0) 757 if (res < 0)
758 return res; 758 return res;
759 } 759 }
760 760
761 /* Write the mirror bad block table to the device ? */ 761 /* Write the mirror bad block table to the device ? */
762 if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) { 762 if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) {
763 res = write_bbt (mtd, buf, md, td, chipsel); 763 res = write_bbt (mtd, buf, md, td, chipsel);
@@ -765,11 +765,11 @@ writecheck:
765 return res; 765 return res;
766 } 766 }
767 } 767 }
768 return 0; 768 return 0;
769} 769}
770 770
771/** 771/**
772 * mark_bbt_regions - [GENERIC] mark the bad block table regions 772 * mark_bbt_regions - [GENERIC] mark the bad block table regions
773 * @mtd: MTD device structure 773 * @mtd: MTD device structure
774 * @td: bad block table descriptor 774 * @td: bad block table descriptor
775 * 775 *
@@ -790,14 +790,14 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
790 } else { 790 } else {
791 chips = 1; 791 chips = 1;
792 nrblocks = (int)(mtd->size >> this->bbt_erase_shift); 792 nrblocks = (int)(mtd->size >> this->bbt_erase_shift);
793 } 793 }
794 794
795 for (i = 0; i < chips; i++) { 795 for (i = 0; i < chips; i++) {
796 if ((td->options & NAND_BBT_ABSPAGE) || 796 if ((td->options & NAND_BBT_ABSPAGE) ||
797 !(td->options & NAND_BBT_WRITE)) { 797 !(td->options & NAND_BBT_WRITE)) {
798 if (td->pages[i] == -1) continue; 798 if (td->pages[i] == -1) continue;
799 block = td->pages[i] >> (this->bbt_erase_shift - this->page_shift); 799 block = td->pages[i] >> (this->bbt_erase_shift - this->page_shift);
800 block <<= 1; 800 block <<= 1;
801 oldval = this->bbt[(block >> 3)]; 801 oldval = this->bbt[(block >> 3)];
802 newval = oldval | (0x2 << (block & 0x06)); 802 newval = oldval | (0x2 << (block & 0x06));
803 this->bbt[(block >> 3)] = newval; 803 this->bbt[(block >> 3)] = newval;
@@ -808,16 +808,16 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
808 update = 0; 808 update = 0;
809 if (td->options & NAND_BBT_LASTBLOCK) 809 if (td->options & NAND_BBT_LASTBLOCK)
810 block = ((i + 1) * nrblocks) - td->maxblocks; 810 block = ((i + 1) * nrblocks) - td->maxblocks;
811 else 811 else
812 block = i * nrblocks; 812 block = i * nrblocks;
813 block <<= 1; 813 block <<= 1;
814 for (j = 0; j < td->maxblocks; j++) { 814 for (j = 0; j < td->maxblocks; j++) {
815 oldval = this->bbt[(block >> 3)]; 815 oldval = this->bbt[(block >> 3)];
816 newval = oldval | (0x2 << (block & 0x06)); 816 newval = oldval | (0x2 << (block & 0x06));
817 this->bbt[(block >> 3)] = newval; 817 this->bbt[(block >> 3)] = newval;
818 if (oldval != newval) update = 1; 818 if (oldval != newval) update = 1;
819 block += 2; 819 block += 2;
820 } 820 }
821 /* If we want reserved blocks to be recorded to flash, and some 821 /* If we want reserved blocks to be recorded to flash, and some
822 new ones have been marked, then we need to update the stored 822 new ones have been marked, then we need to update the stored
823 bbts. This should only happen once. */ 823 bbts. This should only happen once. */
@@ -831,7 +831,7 @@ static void mark_bbt_region (struct mtd_info *mtd, struct nand_bbt_descr *td)
831 * @mtd: MTD device structure 831 * @mtd: MTD device structure
832 * @bd: descriptor for the good/bad block search pattern 832 * @bd: descriptor for the good/bad block search pattern
833 * 833 *
834 * The function checks, if a bad block table(s) is/are already 834 * The function checks, if a bad block table(s) is/are already
835 * available. If not it scans the device for manufacturer 835 * available. If not it scans the device for manufacturer
836 * marked good / bad blocks and writes the bad block table(s) to 836 * marked good / bad blocks and writes the bad block table(s) to
837 * the selected place. 837 * the selected place.
@@ -880,30 +880,30 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
880 this->bbt = NULL; 880 this->bbt = NULL;
881 return -ENOMEM; 881 return -ENOMEM;
882 } 882 }
883 883
884 /* Is the bbt at a given page ? */ 884 /* Is the bbt at a given page ? */
885 if (td->options & NAND_BBT_ABSPAGE) { 885 if (td->options & NAND_BBT_ABSPAGE) {
886 res = read_abs_bbts (mtd, buf, td, md); 886 res = read_abs_bbts (mtd, buf, td, md);
887 } else { 887 } else {
888 /* Search the bad block table using a pattern in oob */ 888 /* Search the bad block table using a pattern in oob */
889 res = search_read_bbts (mtd, buf, td, md); 889 res = search_read_bbts (mtd, buf, td, md);
890 } 890 }
891 891
892 if (res) 892 if (res)
893 res = check_create (mtd, buf, bd); 893 res = check_create (mtd, buf, bd);
894 894
895 /* Prevent the bbt regions from erasing / writing */ 895 /* Prevent the bbt regions from erasing / writing */
896 mark_bbt_region (mtd, td); 896 mark_bbt_region (mtd, td);
897 if (md) 897 if (md)
898 mark_bbt_region (mtd, md); 898 mark_bbt_region (mtd, md);
899 899
900 kfree (buf); 900 kfree (buf);
901 return res; 901 return res;
902} 902}
903 903
904 904
905/** 905/**
906 * nand_update_bbt - [NAND Interface] update bad block table(s) 906 * nand_update_bbt - [NAND Interface] update bad block table(s)
907 * @mtd: MTD device structure 907 * @mtd: MTD device structure
908 * @offs: the offset of the newly marked block 908 * @offs: the offset of the newly marked block
909 * 909 *
@@ -930,7 +930,7 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs)
930 printk (KERN_ERR "nand_update_bbt: Out of memory\n"); 930 printk (KERN_ERR "nand_update_bbt: Out of memory\n");
931 return -ENOMEM; 931 return -ENOMEM;
932 } 932 }
933 933
934 writeops = md != NULL ? 0x03 : 0x01; 934 writeops = md != NULL ? 0x03 : 0x01;
935 935
936 /* Do we have a bbt per chip ? */ 936 /* Do we have a bbt per chip ? */
@@ -944,7 +944,7 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs)
944 944
945 td->version[chip]++; 945 td->version[chip]++;
946 if (md) 946 if (md)
947 md->version[chip]++; 947 md->version[chip]++;
948 948
949 /* Write the bad block table to the device ? */ 949 /* Write the bad block table to the device ? */
950 if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) { 950 if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) {
@@ -957,12 +957,12 @@ int nand_update_bbt (struct mtd_info *mtd, loff_t offs)
957 res = write_bbt (mtd, buf, md, td, chipsel); 957 res = write_bbt (mtd, buf, md, td, chipsel);
958 } 958 }
959 959
960out: 960out:
961 kfree (buf); 961 kfree (buf);
962 return res; 962 return res;
963} 963}
964 964
965/* Define some generic bad / good block scan pattern which are used 965/* Define some generic bad / good block scan pattern which are used
966 * while scanning a device for factory marked good / bad blocks. */ 966 * while scanning a device for factory marked good / bad blocks. */
967static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; 967static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
968 968
@@ -1009,7 +1009,7 @@ static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' };
1009static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' }; 1009static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' };
1010 1010
1011static struct nand_bbt_descr bbt_main_descr = { 1011static struct nand_bbt_descr bbt_main_descr = {
1012 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE 1012 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
1013 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, 1013 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
1014 .offs = 8, 1014 .offs = 8,
1015 .len = 4, 1015 .len = 4,
@@ -1019,7 +1019,7 @@ static struct nand_bbt_descr bbt_main_descr = {
1019}; 1019};
1020 1020
1021static struct nand_bbt_descr bbt_mirror_descr = { 1021static struct nand_bbt_descr bbt_mirror_descr = {
1022 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE 1022 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
1023 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, 1023 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
1024 .offs = 8, 1024 .offs = 8,
1025 .len = 4, 1025 .len = 4,
@@ -1029,7 +1029,7 @@ static struct nand_bbt_descr bbt_mirror_descr = {
1029}; 1029};
1030 1030
1031/** 1031/**
1032 * nand_default_bbt - [NAND Interface] Select a default bad block table for the device 1032 * nand_default_bbt - [NAND Interface] Select a default bad block table for the device
1033 * @mtd: MTD device structure 1033 * @mtd: MTD device structure
1034 * 1034 *
1035 * This function selects the default bad block table 1035 * This function selects the default bad block table
@@ -1039,29 +1039,29 @@ static struct nand_bbt_descr bbt_mirror_descr = {
1039int nand_default_bbt (struct mtd_info *mtd) 1039int nand_default_bbt (struct mtd_info *mtd)
1040{ 1040{
1041 struct nand_chip *this = mtd->priv; 1041 struct nand_chip *this = mtd->priv;
1042 1042
1043 /* Default for AG-AND. We must use a flash based 1043 /* Default for AG-AND. We must use a flash based
1044 * bad block table as the devices have factory marked 1044 * bad block table as the devices have factory marked
1045 * _good_ blocks. Erasing those blocks leads to loss 1045 * _good_ blocks. Erasing those blocks leads to loss
1046 * of the good / bad information, so we _must_ store 1046 * of the good / bad information, so we _must_ store
1047 * this information in a good / bad table during 1047 * this information in a good / bad table during
1048 * startup 1048 * startup
1049 */ 1049 */
1050 if (this->options & NAND_IS_AND) { 1050 if (this->options & NAND_IS_AND) {
1051 /* Use the default pattern descriptors */ 1051 /* Use the default pattern descriptors */
1052 if (!this->bbt_td) { 1052 if (!this->bbt_td) {
1053 this->bbt_td = &bbt_main_descr; 1053 this->bbt_td = &bbt_main_descr;
1054 this->bbt_md = &bbt_mirror_descr; 1054 this->bbt_md = &bbt_mirror_descr;
1055 } 1055 }
1056 this->options |= NAND_USE_FLASH_BBT; 1056 this->options |= NAND_USE_FLASH_BBT;
1057 return nand_scan_bbt (mtd, &agand_flashbased); 1057 return nand_scan_bbt (mtd, &agand_flashbased);
1058 } 1058 }
1059 1059
1060 1060
1061 /* Is a flash based bad block table requested ? */ 1061 /* Is a flash based bad block table requested ? */
1062 if (this->options & NAND_USE_FLASH_BBT) { 1062 if (this->options & NAND_USE_FLASH_BBT) {
1063 /* Use the default pattern descriptors */ 1063 /* Use the default pattern descriptors */
1064 if (!this->bbt_td) { 1064 if (!this->bbt_td) {
1065 this->bbt_td = &bbt_main_descr; 1065 this->bbt_td = &bbt_main_descr;
1066 this->bbt_md = &bbt_mirror_descr; 1066 this->bbt_md = &bbt_mirror_descr;
1067 } 1067 }
@@ -1081,7 +1081,7 @@ int nand_default_bbt (struct mtd_info *mtd)
1081} 1081}
1082 1082
1083/** 1083/**
1084 * nand_isbad_bbt - [NAND Interface] Check if a block is bad 1084 * nand_isbad_bbt - [NAND Interface] Check if a block is bad
1085 * @mtd: MTD device structure 1085 * @mtd: MTD device structure
1086 * @offs: offset in the device 1086 * @offs: offset in the device
1087 * @allowbbt: allow access to bad block table region 1087 * @allowbbt: allow access to bad block table region
@@ -1092,12 +1092,12 @@ int nand_isbad_bbt (struct mtd_info *mtd, loff_t offs, int allowbbt)
1092 struct nand_chip *this = mtd->priv; 1092 struct nand_chip *this = mtd->priv;
1093 int block; 1093 int block;
1094 uint8_t res; 1094 uint8_t res;
1095 1095
1096 /* Get block number * 2 */ 1096 /* Get block number * 2 */
1097 block = (int) (offs >> (this->bbt_erase_shift - 1)); 1097 block = (int) (offs >> (this->bbt_erase_shift - 1));
1098 res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03; 1098 res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03;
1099 1099
1100 DEBUG (MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n", 1100 DEBUG (MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n",
1101 (unsigned int)offs, block >> 1, res); 1101 (unsigned int)offs, block >> 1, res);
1102 1102
1103 switch ((int)res) { 1103 switch ((int)res) {
diff --git a/drivers/mtd/nand/nand_ecc.c b/drivers/mtd/nand/nand_ecc.c
index 2e341b75437a..40ac909150a3 100644
--- a/drivers/mtd/nand/nand_ecc.c
+++ b/drivers/mtd/nand/nand_ecc.c
@@ -7,22 +7,22 @@
7 * Copyright (C) 2000-2004 Steven J. Hill (sjhill@realitydiluted.com) 7 * Copyright (C) 2000-2004 Steven J. Hill (sjhill@realitydiluted.com)
8 * Toshiba America Electronics Components, Inc. 8 * Toshiba America Electronics Components, Inc.
9 * 9 *
10 * $Id: nand_ecc.c,v 1.14 2004/06/16 15:34:37 gleixner Exp $ 10 * $Id: nand_ecc.c,v 1.15 2005/11/07 11:14:30 gleixner Exp $
11 * 11 *
12 * This file is free software; you can redistribute it and/or modify it 12 * This file is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the 13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 or (at your option) any 14 * Free Software Foundation; either version 2 or (at your option) any
15 * later version. 15 * later version.
16 * 16 *
17 * This file is distributed in the hope that it will be useful, but WITHOUT 17 * This file is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details. 20 * for more details.
21 * 21 *
22 * You should have received a copy of the GNU General Public License along 22 * You should have received a copy of the GNU General Public License along
23 * with this file; if not, write to the Free Software Foundation, Inc., 23 * with this file; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 * 25 *
26 * As a special exception, if other files instantiate templates or use 26 * As a special exception, if other files instantiate templates or use
27 * macros or inline functions from these files, or you compile these 27 * macros or inline functions from these files, or you compile these
28 * files and link them with other works to produce a work based on these 28 * files and link them with other works to produce a work based on these
@@ -30,7 +30,7 @@
30 * covered by the GNU General Public License. However the source code for 30 * covered by the GNU General Public License. However the source code for
31 * these files must still be made available in accordance with section (3) 31 * these files must still be made available in accordance with section (3)
32 * of the GNU General Public License. 32 * of the GNU General Public License.
33 * 33 *
34 * This exception does not invalidate any other reasons why a work based on 34 * This exception does not invalidate any other reasons why a work based on
35 * this file might be covered by the GNU General Public License. 35 * this file might be covered by the GNU General Public License.
36 */ 36 */
@@ -67,7 +67,7 @@ static const u_char nand_ecc_precalc_table[] = {
67 * nand_trans_result - [GENERIC] create non-inverted ECC 67 * nand_trans_result - [GENERIC] create non-inverted ECC
68 * @reg2: line parity reg 2 68 * @reg2: line parity reg 2
69 * @reg3: line parity reg 3 69 * @reg3: line parity reg 3
70 * @ecc_code: ecc 70 * @ecc_code: ecc
71 * 71 *
72 * Creates non-inverted ECC code from line parity 72 * Creates non-inverted ECC code from line parity
73 */ 73 */
@@ -75,11 +75,11 @@ static void nand_trans_result(u_char reg2, u_char reg3,
75 u_char *ecc_code) 75 u_char *ecc_code)
76{ 76{
77 u_char a, b, i, tmp1, tmp2; 77 u_char a, b, i, tmp1, tmp2;
78 78
79 /* Initialize variables */ 79 /* Initialize variables */
80 a = b = 0x80; 80 a = b = 0x80;
81 tmp1 = tmp2 = 0; 81 tmp1 = tmp2 = 0;
82 82
83 /* Calculate first ECC byte */ 83 /* Calculate first ECC byte */
84 for (i = 0; i < 4; i++) { 84 for (i = 0; i < 4; i++) {
85 if (reg3 & a) /* LP15,13,11,9 --> ecc_code[0] */ 85 if (reg3 & a) /* LP15,13,11,9 --> ecc_code[0] */
@@ -90,7 +90,7 @@ static void nand_trans_result(u_char reg2, u_char reg3,
90 b >>= 1; 90 b >>= 1;
91 a >>= 1; 91 a >>= 1;
92 } 92 }
93 93
94 /* Calculate second ECC byte */ 94 /* Calculate second ECC byte */
95 b = 0x80; 95 b = 0x80;
96 for (i = 0; i < 4; i++) { 96 for (i = 0; i < 4; i++) {
@@ -102,7 +102,7 @@ static void nand_trans_result(u_char reg2, u_char reg3,
102 b >>= 1; 102 b >>= 1;
103 a >>= 1; 103 a >>= 1;
104 } 104 }
105 105
106 /* Store two of the ECC bytes */ 106 /* Store two of the ECC bytes */
107 ecc_code[0] = tmp1; 107 ecc_code[0] = tmp1;
108 ecc_code[1] = tmp2; 108 ecc_code[1] = tmp2;
@@ -118,28 +118,28 @@ int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code
118{ 118{
119 u_char idx, reg1, reg2, reg3; 119 u_char idx, reg1, reg2, reg3;
120 int j; 120 int j;
121 121
122 /* Initialize variables */ 122 /* Initialize variables */
123 reg1 = reg2 = reg3 = 0; 123 reg1 = reg2 = reg3 = 0;
124 ecc_code[0] = ecc_code[1] = ecc_code[2] = 0; 124 ecc_code[0] = ecc_code[1] = ecc_code[2] = 0;
125 125
126 /* Build up column parity */ 126 /* Build up column parity */
127 for(j = 0; j < 256; j++) { 127 for(j = 0; j < 256; j++) {
128 128
129 /* Get CP0 - CP5 from table */ 129 /* Get CP0 - CP5 from table */
130 idx = nand_ecc_precalc_table[dat[j]]; 130 idx = nand_ecc_precalc_table[dat[j]];
131 reg1 ^= (idx & 0x3f); 131 reg1 ^= (idx & 0x3f);
132 132
133 /* All bit XOR = 1 ? */ 133 /* All bit XOR = 1 ? */
134 if (idx & 0x40) { 134 if (idx & 0x40) {
135 reg3 ^= (u_char) j; 135 reg3 ^= (u_char) j;
136 reg2 ^= ~((u_char) j); 136 reg2 ^= ~((u_char) j);
137 } 137 }
138 } 138 }
139 139
140 /* Create non-inverted ECC code from line parity */ 140 /* Create non-inverted ECC code from line parity */
141 nand_trans_result(reg2, reg3, ecc_code); 141 nand_trans_result(reg2, reg3, ecc_code);
142 142
143 /* Calculate final ECC code */ 143 /* Calculate final ECC code */
144 ecc_code[0] = ~ecc_code[0]; 144 ecc_code[0] = ~ecc_code[0];
145 ecc_code[1] = ~ecc_code[1]; 145 ecc_code[1] = ~ecc_code[1];
@@ -159,12 +159,12 @@ int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code
159int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc) 159int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc)
160{ 160{
161 u_char a, b, c, d1, d2, d3, add, bit, i; 161 u_char a, b, c, d1, d2, d3, add, bit, i;
162 162
163 /* Do error detection */ 163 /* Do error detection */
164 d1 = calc_ecc[0] ^ read_ecc[0]; 164 d1 = calc_ecc[0] ^ read_ecc[0];
165 d2 = calc_ecc[1] ^ read_ecc[1]; 165 d2 = calc_ecc[1] ^ read_ecc[1];
166 d3 = calc_ecc[2] ^ read_ecc[2]; 166 d3 = calc_ecc[2] ^ read_ecc[2];
167 167
168 if ((d1 | d2 | d3) == 0) { 168 if ((d1 | d2 | d3) == 0) {
169 /* No errors */ 169 /* No errors */
170 return 0; 170 return 0;
@@ -173,7 +173,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha
173 a = (d1 ^ (d1 >> 1)) & 0x55; 173 a = (d1 ^ (d1 >> 1)) & 0x55;
174 b = (d2 ^ (d2 >> 1)) & 0x55; 174 b = (d2 ^ (d2 >> 1)) & 0x55;
175 c = (d3 ^ (d3 >> 1)) & 0x54; 175 c = (d3 ^ (d3 >> 1)) & 0x54;
176 176
177 /* Found and will correct single bit error in the data */ 177 /* Found and will correct single bit error in the data */
178 if ((a == 0x55) && (b == 0x55) && (c == 0x54)) { 178 if ((a == 0x55) && (b == 0x55) && (c == 0x54)) {
179 c = 0x80; 179 c = 0x80;
@@ -237,7 +237,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_cha
237 } 237 }
238 } 238 }
239 } 239 }
240 240
241 /* Should never happen */ 241 /* Should never happen */
242 return -1; 242 return -1;
243} 243}
diff --git a/drivers/mtd/nand/nand_ids.c b/drivers/mtd/nand/nand_ids.c
index efe246961b69..dbc7e55a4247 100644
--- a/drivers/mtd/nand/nand_ids.c
+++ b/drivers/mtd/nand/nand_ids.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2002 Thomas Gleixner (tglx@linutronix.de) 4 * Copyright (C) 2002 Thomas Gleixner (tglx@linutronix.de)
5 * 5 *
6 * $Id: nand_ids.c,v 1.14 2005/06/23 09:38:50 gleixner Exp $ 6 * $Id: nand_ids.c,v 1.16 2005/11/07 11:14:31 gleixner Exp $
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 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 9 * it under the terms of the GNU General Public License version 2 as
@@ -14,14 +14,14 @@
14#include <linux/mtd/nand.h> 14#include <linux/mtd/nand.h>
15/* 15/*
16* Chip ID list 16* Chip ID list
17* 17*
18* Name. ID code, pagesize, chipsize in MegaByte, eraseblock size, 18* Name. ID code, pagesize, chipsize in MegaByte, eraseblock size,
19* options 19* options
20* 20*
21* Pagesize; 0, 256, 512 21* Pagesize; 0, 256, 512
22* 0 get this information from the extended chip ID 22* 0 get this information from the extended chip ID
23+ 256 256 Byte page size 23+ 256 256 Byte page size
24* 512 512 Byte page size 24* 512 512 Byte page size
25*/ 25*/
26struct nand_flash_dev nand_flash_ids[] = { 26struct nand_flash_dev nand_flash_ids[] = {
27 {"NAND 1MiB 5V 8-bit", 0x6e, 256, 1, 0x1000, 0}, 27 {"NAND 1MiB 5V 8-bit", 0x6e, 256, 1, 0x1000, 0},
@@ -34,27 +34,27 @@ struct nand_flash_dev nand_flash_ids[] = {
34 {"NAND 4MiB 3,3V 8-bit", 0xe3, 512, 4, 0x2000, 0}, 34 {"NAND 4MiB 3,3V 8-bit", 0xe3, 512, 4, 0x2000, 0},
35 {"NAND 4MiB 3,3V 8-bit", 0xe5, 512, 4, 0x2000, 0}, 35 {"NAND 4MiB 3,3V 8-bit", 0xe5, 512, 4, 0x2000, 0},
36 {"NAND 8MiB 3,3V 8-bit", 0xd6, 512, 8, 0x2000, 0}, 36 {"NAND 8MiB 3,3V 8-bit", 0xd6, 512, 8, 0x2000, 0},
37 37
38 {"NAND 8MiB 1,8V 8-bit", 0x39, 512, 8, 0x2000, 0}, 38 {"NAND 8MiB 1,8V 8-bit", 0x39, 512, 8, 0x2000, 0},
39 {"NAND 8MiB 3,3V 8-bit", 0xe6, 512, 8, 0x2000, 0}, 39 {"NAND 8MiB 3,3V 8-bit", 0xe6, 512, 8, 0x2000, 0},
40 {"NAND 8MiB 1,8V 16-bit", 0x49, 512, 8, 0x2000, NAND_BUSWIDTH_16}, 40 {"NAND 8MiB 1,8V 16-bit", 0x49, 512, 8, 0x2000, NAND_BUSWIDTH_16},
41 {"NAND 8MiB 3,3V 16-bit", 0x59, 512, 8, 0x2000, NAND_BUSWIDTH_16}, 41 {"NAND 8MiB 3,3V 16-bit", 0x59, 512, 8, 0x2000, NAND_BUSWIDTH_16},
42 42
43 {"NAND 16MiB 1,8V 8-bit", 0x33, 512, 16, 0x4000, 0}, 43 {"NAND 16MiB 1,8V 8-bit", 0x33, 512, 16, 0x4000, 0},
44 {"NAND 16MiB 3,3V 8-bit", 0x73, 512, 16, 0x4000, 0}, 44 {"NAND 16MiB 3,3V 8-bit", 0x73, 512, 16, 0x4000, 0},
45 {"NAND 16MiB 1,8V 16-bit", 0x43, 512, 16, 0x4000, NAND_BUSWIDTH_16}, 45 {"NAND 16MiB 1,8V 16-bit", 0x43, 512, 16, 0x4000, NAND_BUSWIDTH_16},
46 {"NAND 16MiB 3,3V 16-bit", 0x53, 512, 16, 0x4000, NAND_BUSWIDTH_16}, 46 {"NAND 16MiB 3,3V 16-bit", 0x53, 512, 16, 0x4000, NAND_BUSWIDTH_16},
47 47
48 {"NAND 32MiB 1,8V 8-bit", 0x35, 512, 32, 0x4000, 0}, 48 {"NAND 32MiB 1,8V 8-bit", 0x35, 512, 32, 0x4000, 0},
49 {"NAND 32MiB 3,3V 8-bit", 0x75, 512, 32, 0x4000, 0}, 49 {"NAND 32MiB 3,3V 8-bit", 0x75, 512, 32, 0x4000, 0},
50 {"NAND 32MiB 1,8V 16-bit", 0x45, 512, 32, 0x4000, NAND_BUSWIDTH_16}, 50 {"NAND 32MiB 1,8V 16-bit", 0x45, 512, 32, 0x4000, NAND_BUSWIDTH_16},
51 {"NAND 32MiB 3,3V 16-bit", 0x55, 512, 32, 0x4000, NAND_BUSWIDTH_16}, 51 {"NAND 32MiB 3,3V 16-bit", 0x55, 512, 32, 0x4000, NAND_BUSWIDTH_16},
52 52
53 {"NAND 64MiB 1,8V 8-bit", 0x36, 512, 64, 0x4000, 0}, 53 {"NAND 64MiB 1,8V 8-bit", 0x36, 512, 64, 0x4000, 0},
54 {"NAND 64MiB 3,3V 8-bit", 0x76, 512, 64, 0x4000, 0}, 54 {"NAND 64MiB 3,3V 8-bit", 0x76, 512, 64, 0x4000, 0},
55 {"NAND 64MiB 1,8V 16-bit", 0x46, 512, 64, 0x4000, NAND_BUSWIDTH_16}, 55 {"NAND 64MiB 1,8V 16-bit", 0x46, 512, 64, 0x4000, NAND_BUSWIDTH_16},
56 {"NAND 64MiB 3,3V 16-bit", 0x56, 512, 64, 0x4000, NAND_BUSWIDTH_16}, 56 {"NAND 64MiB 3,3V 16-bit", 0x56, 512, 64, 0x4000, NAND_BUSWIDTH_16},
57 57
58 {"NAND 128MiB 1,8V 8-bit", 0x78, 512, 128, 0x4000, 0}, 58 {"NAND 128MiB 1,8V 8-bit", 0x78, 512, 128, 0x4000, 0},
59 {"NAND 128MiB 1,8V 8-bit", 0x39, 512, 128, 0x4000, 0}, 59 {"NAND 128MiB 1,8V 8-bit", 0x39, 512, 128, 0x4000, 0},
60 {"NAND 128MiB 3,3V 8-bit", 0x79, 512, 128, 0x4000, 0}, 60 {"NAND 128MiB 3,3V 8-bit", 0x79, 512, 128, 0x4000, 0},
@@ -62,7 +62,7 @@ struct nand_flash_dev nand_flash_ids[] = {
62 {"NAND 128MiB 1,8V 16-bit", 0x49, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 62 {"NAND 128MiB 1,8V 16-bit", 0x49, 512, 128, 0x4000, NAND_BUSWIDTH_16},
63 {"NAND 128MiB 3,3V 16-bit", 0x74, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 63 {"NAND 128MiB 3,3V 16-bit", 0x74, 512, 128, 0x4000, NAND_BUSWIDTH_16},
64 {"NAND 128MiB 3,3V 16-bit", 0x59, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 64 {"NAND 128MiB 3,3V 16-bit", 0x59, 512, 128, 0x4000, NAND_BUSWIDTH_16},
65 65
66 {"NAND 256MiB 3,3V 8-bit", 0x71, 512, 256, 0x4000, 0}, 66 {"NAND 256MiB 3,3V 8-bit", 0x71, 512, 256, 0x4000, 0},
67 67
68 /* These are the new chips with large page size. The pagesize 68 /* These are the new chips with large page size. The pagesize
@@ -73,7 +73,7 @@ struct nand_flash_dev nand_flash_ids[] = {
73 {"NAND 64MiB 3,3V 8-bit", 0xF2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 73 {"NAND 64MiB 3,3V 8-bit", 0xF2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
74 {"NAND 64MiB 1,8V 16-bit", 0xB2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR}, 74 {"NAND 64MiB 1,8V 16-bit", 0xB2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
75 {"NAND 64MiB 3,3V 16-bit", 0xC2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR}, 75 {"NAND 64MiB 3,3V 16-bit", 0xC2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
76 76
77 /* 1 Gigabit */ 77 /* 1 Gigabit */
78 {"NAND 128MiB 1,8V 8-bit", 0xA1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 78 {"NAND 128MiB 1,8V 8-bit", 0xA1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
79 {"NAND 128MiB 3,3V 8-bit", 0xF1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 79 {"NAND 128MiB 3,3V 8-bit", 0xF1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
@@ -85,13 +85,13 @@ struct nand_flash_dev nand_flash_ids[] = {
85 {"NAND 256MiB 3,3V 8-bit", 0xDA, 0, 256, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 85 {"NAND 256MiB 3,3V 8-bit", 0xDA, 0, 256, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
86 {"NAND 256MiB 1,8V 16-bit", 0xBA, 0, 256, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR}, 86 {"NAND 256MiB 1,8V 16-bit", 0xBA, 0, 256, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
87 {"NAND 256MiB 3,3V 16-bit", 0xCA, 0, 256, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR}, 87 {"NAND 256MiB 3,3V 16-bit", 0xCA, 0, 256, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
88 88
89 /* 4 Gigabit */ 89 /* 4 Gigabit */
90 {"NAND 512MiB 1,8V 8-bit", 0xAC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 90 {"NAND 512MiB 1,8V 8-bit", 0xAC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
91 {"NAND 512MiB 3,3V 8-bit", 0xDC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 91 {"NAND 512MiB 3,3V 8-bit", 0xDC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
92 {"NAND 512MiB 1,8V 16-bit", 0xBC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR}, 92 {"NAND 512MiB 1,8V 16-bit", 0xBC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
93 {"NAND 512MiB 3,3V 16-bit", 0xCC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR}, 93 {"NAND 512MiB 3,3V 16-bit", 0xCC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
94 94
95 /* 8 Gigabit */ 95 /* 8 Gigabit */
96 {"NAND 1GiB 1,8V 8-bit", 0xA3, 0, 1024, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 96 {"NAND 1GiB 1,8V 8-bit", 0xA3, 0, 1024, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
97 {"NAND 1GiB 3,3V 8-bit", 0xD3, 0, 1024, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 97 {"NAND 1GiB 3,3V 8-bit", 0xD3, 0, 1024, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
@@ -104,11 +104,11 @@ struct nand_flash_dev nand_flash_ids[] = {
104 {"NAND 2GiB 1,8V 16-bit", 0xB5, 0, 2048, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR}, 104 {"NAND 2GiB 1,8V 16-bit", 0xB5, 0, 2048, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
105 {"NAND 2GiB 3,3V 16-bit", 0xC5, 0, 2048, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR}, 105 {"NAND 2GiB 3,3V 16-bit", 0xC5, 0, 2048, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
106 106
107 /* Renesas AND 1 Gigabit. Those chips do not support extended id and have a strange page/block layout ! 107 /* Renesas AND 1 Gigabit. Those chips do not support extended id and have a strange page/block layout !
108 * The chosen minimum erasesize is 4 * 2 * 2048 = 16384 Byte, as those chips have an array of 4 page planes 108 * The chosen minimum erasesize is 4 * 2 * 2048 = 16384 Byte, as those chips have an array of 4 page planes
109 * 1 block = 2 pages, but due to plane arrangement the blocks 0-3 consists of page 0 + 4,1 + 5, 2 + 6, 3 + 7 109 * 1 block = 2 pages, but due to plane arrangement the blocks 0-3 consists of page 0 + 4,1 + 5, 2 + 6, 3 + 7
110 * Anyway JFFS2 would increase the eraseblock size so we chose a combined one which can be erased in one go 110 * Anyway JFFS2 would increase the eraseblock size so we chose a combined one which can be erased in one go
111 * There are more speed improvements for reads and writes possible, but not implemented now 111 * There are more speed improvements for reads and writes possible, but not implemented now
112 */ 112 */
113 {"AND 128MiB 3,3V 8-bit", 0x01, 2048, 128, 0x4000, NAND_IS_AND | NAND_NO_AUTOINCR | NAND_4PAGE_ARRAY | BBT_AUTO_REFRESH}, 113 {"AND 128MiB 3,3V 8-bit", 0x01, 2048, 128, 0x4000, NAND_IS_AND | NAND_NO_AUTOINCR | NAND_4PAGE_ARRAY | BBT_AUTO_REFRESH},
114 114
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 754b6ed7ce14..de4500395300 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Author: Artem B. Bityuckiy <dedekind@oktetlabs.ru>, <dedekind@infradead.org> 4 * Author: Artem B. Bityuckiy <dedekind@oktetlabs.ru>, <dedekind@infradead.org>
5 * 5 *
6 * Copyright (C) 2004 Nokia Corporation 6 * Copyright (C) 2004 Nokia Corporation
7 * 7 *
8 * Note: NS means "NAND Simulator". 8 * Note: NS means "NAND Simulator".
9 * Note: Input means input TO flash chip, output means output FROM chip. 9 * Note: Input means input TO flash chip, output means output FROM chip.
@@ -126,7 +126,7 @@ MODULE_PARM_DESC(dbg, "Output debug information if not zero");
126 126
127/* The largest possible page size */ 127/* The largest possible page size */
128#define NS_LARGEST_PAGE_SIZE 2048 128#define NS_LARGEST_PAGE_SIZE 2048
129 129
130/* The prefix for simulator output */ 130/* The prefix for simulator output */
131#define NS_OUTPUT_PREFIX "[nandsim]" 131#define NS_OUTPUT_PREFIX "[nandsim]"
132 132
@@ -145,7 +145,7 @@ MODULE_PARM_DESC(dbg, "Output debug information if not zero");
145 do { if (do_delays) udelay(us); } while(0) 145 do { if (do_delays) udelay(us); } while(0)
146#define NS_MDELAY(us) \ 146#define NS_MDELAY(us) \
147 do { if (do_delays) mdelay(us); } while(0) 147 do { if (do_delays) mdelay(us); } while(0)
148 148
149/* Is the nandsim structure initialized ? */ 149/* Is the nandsim structure initialized ? */
150#define NS_IS_INITIALIZED(ns) ((ns)->geom.totsz != 0) 150#define NS_IS_INITIALIZED(ns) ((ns)->geom.totsz != 0)
151 151
@@ -153,12 +153,12 @@ MODULE_PARM_DESC(dbg, "Output debug information if not zero");
153#define NS_STATUS_OK(ns) (NAND_STATUS_READY | (NAND_STATUS_WP * ((ns)->lines.wp == 0))) 153#define NS_STATUS_OK(ns) (NAND_STATUS_READY | (NAND_STATUS_WP * ((ns)->lines.wp == 0)))
154 154
155/* Operation failed completion status */ 155/* Operation failed completion status */
156#define NS_STATUS_FAILED(ns) (NAND_STATUS_FAIL | NS_STATUS_OK(ns)) 156#define NS_STATUS_FAILED(ns) (NAND_STATUS_FAIL | NS_STATUS_OK(ns))
157 157
158/* Calculate the page offset in flash RAM image by (row, column) address */ 158/* Calculate the page offset in flash RAM image by (row, column) address */
159#define NS_RAW_OFFSET(ns) \ 159#define NS_RAW_OFFSET(ns) \
160 (((ns)->regs.row << (ns)->geom.pgshift) + ((ns)->regs.row * (ns)->geom.oobsz) + (ns)->regs.column) 160 (((ns)->regs.row << (ns)->geom.pgshift) + ((ns)->regs.row * (ns)->geom.oobsz) + (ns)->regs.column)
161 161
162/* Calculate the OOB offset in flash RAM image by (row, column) address */ 162/* Calculate the OOB offset in flash RAM image by (row, column) address */
163#define NS_RAW_OFFSET_OOB(ns) (NS_RAW_OFFSET(ns) + ns->geom.pgsz) 163#define NS_RAW_OFFSET_OOB(ns) (NS_RAW_OFFSET(ns) + ns->geom.pgsz)
164 164
@@ -223,15 +223,15 @@ MODULE_PARM_DESC(dbg, "Output debug information if not zero");
223 223
224/* Remove action bits ftom state */ 224/* Remove action bits ftom state */
225#define NS_STATE(x) ((x) & ~ACTION_MASK) 225#define NS_STATE(x) ((x) & ~ACTION_MASK)
226 226
227/* 227/*
228 * Maximum previous states which need to be saved. Currently saving is 228 * Maximum previous states which need to be saved. Currently saving is
229 * only needed for page programm operation with preceeded read command 229 * only needed for page programm operation with preceeded read command
230 * (which is only valid for 512-byte pages). 230 * (which is only valid for 512-byte pages).
231 */ 231 */
232#define NS_MAX_PREVSTATES 1 232#define NS_MAX_PREVSTATES 1
233 233
234/* 234/*
235 * The structure which describes all the internal simulator data. 235 * The structure which describes all the internal simulator data.
236 */ 236 */
237struct nandsim { 237struct nandsim {
@@ -242,7 +242,7 @@ struct nandsim {
242 uint32_t options; /* chip's characteristic bits */ 242 uint32_t options; /* chip's characteristic bits */
243 uint32_t state; /* current chip state */ 243 uint32_t state; /* current chip state */
244 uint32_t nxstate; /* next expected state */ 244 uint32_t nxstate; /* next expected state */
245 245
246 uint32_t *op; /* current operation, NULL operations isn't known yet */ 246 uint32_t *op; /* current operation, NULL operations isn't known yet */
247 uint32_t pstates[NS_MAX_PREVSTATES]; /* previous states */ 247 uint32_t pstates[NS_MAX_PREVSTATES]; /* previous states */
248 uint16_t npstates; /* number of previous states saved */ 248 uint16_t npstates; /* number of previous states saved */
@@ -413,7 +413,7 @@ init_nandsim(struct mtd_info *mtd)
413 ns->geom.secaddrbytes = 3; 413 ns->geom.secaddrbytes = 3;
414 } 414 }
415 } 415 }
416 416
417 /* Detect how many ID bytes the NAND chip outputs */ 417 /* Detect how many ID bytes the NAND chip outputs */
418 for (i = 0; nand_flash_ids[i].name != NULL; i++) { 418 for (i = 0; nand_flash_ids[i].name != NULL; i++) {
419 if (second_id_byte != nand_flash_ids[i].id) 419 if (second_id_byte != nand_flash_ids[i].id)
@@ -444,7 +444,7 @@ init_nandsim(struct mtd_info *mtd)
444#ifdef CONFIG_NS_ABS_POS 444#ifdef CONFIG_NS_ABS_POS
445 ns->mem.byte = ioremap(CONFIG_NS_ABS_POS, ns->geom.totszoob); 445 ns->mem.byte = ioremap(CONFIG_NS_ABS_POS, ns->geom.totszoob);
446 if (!ns->mem.byte) { 446 if (!ns->mem.byte) {
447 NS_ERR("init_nandsim: failed to map the NAND flash image at address %p\n", 447 NS_ERR("init_nandsim: failed to map the NAND flash image at address %p\n",
448 (void *)CONFIG_NS_ABS_POS); 448 (void *)CONFIG_NS_ABS_POS);
449 return -ENOMEM; 449 return -ENOMEM;
450 } 450 }
@@ -567,7 +567,7 @@ static int
567check_command(int cmd) 567check_command(int cmd)
568{ 568{
569 switch (cmd) { 569 switch (cmd) {
570 570
571 case NAND_CMD_READ0: 571 case NAND_CMD_READ0:
572 case NAND_CMD_READSTART: 572 case NAND_CMD_READSTART:
573 case NAND_CMD_PAGEPROG: 573 case NAND_CMD_PAGEPROG:
@@ -580,7 +580,7 @@ check_command(int cmd)
580 case NAND_CMD_RESET: 580 case NAND_CMD_RESET:
581 case NAND_CMD_READ1: 581 case NAND_CMD_READ1:
582 return 0; 582 return 0;
583 583
584 case NAND_CMD_STATUS_MULTI: 584 case NAND_CMD_STATUS_MULTI:
585 default: 585 default:
586 return 1; 586 return 1;
@@ -631,7 +631,7 @@ static inline void
631accept_addr_byte(struct nandsim *ns, u_char bt) 631accept_addr_byte(struct nandsim *ns, u_char bt)
632{ 632{
633 uint byte = (uint)bt; 633 uint byte = (uint)bt;
634 634
635 if (ns->regs.count < (ns->geom.pgaddrbytes - ns->geom.secaddrbytes)) 635 if (ns->regs.count < (ns->geom.pgaddrbytes - ns->geom.secaddrbytes))
636 ns->regs.column |= (byte << 8 * ns->regs.count); 636 ns->regs.column |= (byte << 8 * ns->regs.count);
637 else { 637 else {
@@ -642,11 +642,11 @@ accept_addr_byte(struct nandsim *ns, u_char bt)
642 642
643 return; 643 return;
644} 644}
645 645
646/* 646/*
647 * Switch to STATE_READY state. 647 * Switch to STATE_READY state.
648 */ 648 */
649static inline void 649static inline void
650switch_to_ready_state(struct nandsim *ns, u_char status) 650switch_to_ready_state(struct nandsim *ns, u_char status)
651{ 651{
652 NS_DBG("switch_to_ready_state: switch to %s state\n", get_state_name(STATE_READY)); 652 NS_DBG("switch_to_ready_state: switch to %s state\n", get_state_name(STATE_READY));
@@ -675,7 +675,7 @@ switch_to_ready_state(struct nandsim *ns, u_char status)
675 * (for example program from the second half and read from the 675 * (for example program from the second half and read from the
676 * second half operations both begin with the READ1 command). In this 676 * second half operations both begin with the READ1 command). In this
677 * case the ns->pstates[] array contains previous states. 677 * case the ns->pstates[] array contains previous states.
678 * 678 *
679 * Thus, the function tries to find operation containing the following 679 * Thus, the function tries to find operation containing the following
680 * states (if the 'flag' parameter is 0): 680 * states (if the 'flag' parameter is 0):
681 * ns->pstates[0], ... ns->pstates[ns->npstates], ns->state 681 * ns->pstates[0], ... ns->pstates[ns->npstates], ns->state
@@ -683,7 +683,7 @@ switch_to_ready_state(struct nandsim *ns, u_char status)
683 * If (one and only one) matching operation is found, it is accepted ( 683 * If (one and only one) matching operation is found, it is accepted (
684 * ns->ops, ns->state, ns->nxstate are initialized, ns->npstate is 684 * ns->ops, ns->state, ns->nxstate are initialized, ns->npstate is
685 * zeroed). 685 * zeroed).
686 * 686 *
687 * If there are several maches, the current state is pushed to the 687 * If there are several maches, the current state is pushed to the
688 * ns->pstates. 688 * ns->pstates.
689 * 689 *
@@ -692,7 +692,7 @@ switch_to_ready_state(struct nandsim *ns, u_char status)
692 * In such situation the function is called with 'flag' != 0, and the 692 * In such situation the function is called with 'flag' != 0, and the
693 * operation is searched using the following pattern: 693 * operation is searched using the following pattern:
694 * ns->pstates[0], ... ns->pstates[ns->npstates], <address input> 694 * ns->pstates[0], ... ns->pstates[ns->npstates], <address input>
695 * 695 *
696 * It is supposed that this pattern must either match one operation on 696 * It is supposed that this pattern must either match one operation on
697 * none. There can't be ambiguity in that case. 697 * none. There can't be ambiguity in that case.
698 * 698 *
@@ -711,15 +711,15 @@ find_operation(struct nandsim *ns, uint32_t flag)
711{ 711{
712 int opsfound = 0; 712 int opsfound = 0;
713 int i, j, idx = 0; 713 int i, j, idx = 0;
714 714
715 for (i = 0; i < NS_OPER_NUM; i++) { 715 for (i = 0; i < NS_OPER_NUM; i++) {
716 716
717 int found = 1; 717 int found = 1;
718 718
719 if (!(ns->options & ops[i].reqopts)) 719 if (!(ns->options & ops[i].reqopts))
720 /* Ignore operations we can't perform */ 720 /* Ignore operations we can't perform */
721 continue; 721 continue;
722 722
723 if (flag) { 723 if (flag) {
724 if (!(ops[i].states[ns->npstates] & STATE_ADDR_MASK)) 724 if (!(ops[i].states[ns->npstates] & STATE_ADDR_MASK))
725 continue; 725 continue;
@@ -728,7 +728,7 @@ find_operation(struct nandsim *ns, uint32_t flag)
728 continue; 728 continue;
729 } 729 }
730 730
731 for (j = 0; j < ns->npstates; j++) 731 for (j = 0; j < ns->npstates; j++)
732 if (NS_STATE(ops[i].states[j]) != NS_STATE(ns->pstates[j]) 732 if (NS_STATE(ops[i].states[j]) != NS_STATE(ns->pstates[j])
733 && (ns->options & ops[idx].reqopts)) { 733 && (ns->options & ops[idx].reqopts)) {
734 found = 0; 734 found = 0;
@@ -745,7 +745,7 @@ find_operation(struct nandsim *ns, uint32_t flag)
745 /* Exact match */ 745 /* Exact match */
746 ns->op = &ops[idx].states[0]; 746 ns->op = &ops[idx].states[0];
747 if (flag) { 747 if (flag) {
748 /* 748 /*
749 * In this case the find_operation function was 749 * In this case the find_operation function was
750 * called when address has just began input. But it isn't 750 * called when address has just began input. But it isn't
751 * yet fully input and the current state must 751 * yet fully input and the current state must
@@ -763,7 +763,7 @@ find_operation(struct nandsim *ns, uint32_t flag)
763 idx, get_state_name(ns->state), get_state_name(ns->nxstate)); 763 idx, get_state_name(ns->state), get_state_name(ns->nxstate));
764 return 0; 764 return 0;
765 } 765 }
766 766
767 if (opsfound == 0) { 767 if (opsfound == 0) {
768 /* Nothing was found. Try to ignore previous commands (if any) and search again */ 768 /* Nothing was found. Try to ignore previous commands (if any) and search again */
769 if (ns->npstates != 0) { 769 if (ns->npstates != 0) {
@@ -777,13 +777,13 @@ find_operation(struct nandsim *ns, uint32_t flag)
777 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); 777 switch_to_ready_state(ns, NS_STATUS_FAILED(ns));
778 return -2; 778 return -2;
779 } 779 }
780 780
781 if (flag) { 781 if (flag) {
782 /* This shouldn't happen */ 782 /* This shouldn't happen */
783 NS_DBG("find_operation: BUG, operation must be known if address is input\n"); 783 NS_DBG("find_operation: BUG, operation must be known if address is input\n");
784 return -2; 784 return -2;
785 } 785 }
786 786
787 NS_DBG("find_operation: there is still ambiguity\n"); 787 NS_DBG("find_operation: there is still ambiguity\n");
788 788
789 ns->pstates[ns->npstates++] = ns->state; 789 ns->pstates[ns->npstates++] = ns->state;
@@ -803,7 +803,7 @@ do_state_action(struct nandsim *ns, uint32_t action)
803 int busdiv = ns->busw == 8 ? 1 : 2; 803 int busdiv = ns->busw == 8 ? 1 : 2;
804 804
805 action &= ACTION_MASK; 805 action &= ACTION_MASK;
806 806
807 /* Check that page address input is correct */ 807 /* Check that page address input is correct */
808 if (action != ACTION_SECERASE && ns->regs.row >= ns->geom.pgnum) { 808 if (action != ACTION_SECERASE && ns->regs.row >= ns->geom.pgnum) {
809 NS_WARN("do_state_action: wrong page number (%#x)\n", ns->regs.row); 809 NS_WARN("do_state_action: wrong page number (%#x)\n", ns->regs.row);
@@ -827,14 +827,14 @@ do_state_action(struct nandsim *ns, uint32_t action)
827 827
828 NS_DBG("do_state_action: (ACTION_CPY:) copy %d bytes to int buf, raw offset %d\n", 828 NS_DBG("do_state_action: (ACTION_CPY:) copy %d bytes to int buf, raw offset %d\n",
829 num, NS_RAW_OFFSET(ns) + ns->regs.off); 829 num, NS_RAW_OFFSET(ns) + ns->regs.off);
830 830
831 if (ns->regs.off == 0) 831 if (ns->regs.off == 0)
832 NS_LOG("read page %d\n", ns->regs.row); 832 NS_LOG("read page %d\n", ns->regs.row);
833 else if (ns->regs.off < ns->geom.pgsz) 833 else if (ns->regs.off < ns->geom.pgsz)
834 NS_LOG("read page %d (second half)\n", ns->regs.row); 834 NS_LOG("read page %d (second half)\n", ns->regs.row);
835 else 835 else
836 NS_LOG("read OOB of page %d\n", ns->regs.row); 836 NS_LOG("read OOB of page %d\n", ns->regs.row);
837 837
838 NS_UDELAY(access_delay); 838 NS_UDELAY(access_delay);
839 NS_UDELAY(input_cycle * ns->geom.pgsz / 1000 / busdiv); 839 NS_UDELAY(input_cycle * ns->geom.pgsz / 1000 / busdiv);
840 840
@@ -844,30 +844,30 @@ do_state_action(struct nandsim *ns, uint32_t action)
844 /* 844 /*
845 * Erase sector. 845 * Erase sector.
846 */ 846 */
847 847
848 if (ns->lines.wp) { 848 if (ns->lines.wp) {
849 NS_ERR("do_state_action: device is write-protected, ignore sector erase\n"); 849 NS_ERR("do_state_action: device is write-protected, ignore sector erase\n");
850 return -1; 850 return -1;
851 } 851 }
852 852
853 if (ns->regs.row >= ns->geom.pgnum - ns->geom.pgsec 853 if (ns->regs.row >= ns->geom.pgnum - ns->geom.pgsec
854 || (ns->regs.row & ~(ns->geom.secsz - 1))) { 854 || (ns->regs.row & ~(ns->geom.secsz - 1))) {
855 NS_ERR("do_state_action: wrong sector address (%#x)\n", ns->regs.row); 855 NS_ERR("do_state_action: wrong sector address (%#x)\n", ns->regs.row);
856 return -1; 856 return -1;
857 } 857 }
858 858
859 ns->regs.row = (ns->regs.row << 859 ns->regs.row = (ns->regs.row <<
860 8 * (ns->geom.pgaddrbytes - ns->geom.secaddrbytes)) | ns->regs.column; 860 8 * (ns->geom.pgaddrbytes - ns->geom.secaddrbytes)) | ns->regs.column;
861 ns->regs.column = 0; 861 ns->regs.column = 0;
862 862
863 NS_DBG("do_state_action: erase sector at address %#x, off = %d\n", 863 NS_DBG("do_state_action: erase sector at address %#x, off = %d\n",
864 ns->regs.row, NS_RAW_OFFSET(ns)); 864 ns->regs.row, NS_RAW_OFFSET(ns));
865 NS_LOG("erase sector %d\n", ns->regs.row >> (ns->geom.secshift - ns->geom.pgshift)); 865 NS_LOG("erase sector %d\n", ns->regs.row >> (ns->geom.secshift - ns->geom.pgshift));
866 866
867 memset(ns->mem.byte + NS_RAW_OFFSET(ns), 0xFF, ns->geom.secszoob); 867 memset(ns->mem.byte + NS_RAW_OFFSET(ns), 0xFF, ns->geom.secszoob);
868 868
869 NS_MDELAY(erase_delay); 869 NS_MDELAY(erase_delay);
870 870
871 break; 871 break;
872 872
873 case ACTION_PRGPAGE: 873 case ACTION_PRGPAGE:
@@ -893,12 +893,12 @@ do_state_action(struct nandsim *ns, uint32_t action)
893 NS_DBG("do_state_action: copy %d bytes from int buf to (%#x, %#x), raw off = %d\n", 893 NS_DBG("do_state_action: copy %d bytes from int buf to (%#x, %#x), raw off = %d\n",
894 num, ns->regs.row, ns->regs.column, NS_RAW_OFFSET(ns) + ns->regs.off); 894 num, ns->regs.row, ns->regs.column, NS_RAW_OFFSET(ns) + ns->regs.off);
895 NS_LOG("programm page %d\n", ns->regs.row); 895 NS_LOG("programm page %d\n", ns->regs.row);
896 896
897 NS_UDELAY(programm_delay); 897 NS_UDELAY(programm_delay);
898 NS_UDELAY(output_cycle * ns->geom.pgsz / 1000 / busdiv); 898 NS_UDELAY(output_cycle * ns->geom.pgsz / 1000 / busdiv);
899 899
900 break; 900 break;
901 901
902 case ACTION_ZEROOFF: 902 case ACTION_ZEROOFF:
903 NS_DBG("do_state_action: set internal offset to 0\n"); 903 NS_DBG("do_state_action: set internal offset to 0\n");
904 ns->regs.off = 0; 904 ns->regs.off = 0;
@@ -918,7 +918,7 @@ do_state_action(struct nandsim *ns, uint32_t action)
918 NS_DBG("do_state_action: set internal offset to %d\n", ns->geom.pgsz); 918 NS_DBG("do_state_action: set internal offset to %d\n", ns->geom.pgsz);
919 ns->regs.off = ns->geom.pgsz; 919 ns->regs.off = ns->geom.pgsz;
920 break; 920 break;
921 921
922 default: 922 default:
923 NS_DBG("do_state_action: BUG! unknown action\n"); 923 NS_DBG("do_state_action: BUG! unknown action\n");
924 } 924 }
@@ -937,7 +937,7 @@ switch_state(struct nandsim *ns)
937 * The current operation have already been identified. 937 * The current operation have already been identified.
938 * Just follow the states chain. 938 * Just follow the states chain.
939 */ 939 */
940 940
941 ns->stateidx += 1; 941 ns->stateidx += 1;
942 ns->state = ns->nxstate; 942 ns->state = ns->nxstate;
943 ns->nxstate = ns->op[ns->stateidx + 1]; 943 ns->nxstate = ns->op[ns->stateidx + 1];
@@ -951,14 +951,14 @@ switch_state(struct nandsim *ns)
951 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); 951 switch_to_ready_state(ns, NS_STATUS_FAILED(ns));
952 return; 952 return;
953 } 953 }
954 954
955 } else { 955 } else {
956 /* 956 /*
957 * We don't yet know which operation we perform. 957 * We don't yet know which operation we perform.
958 * Try to identify it. 958 * Try to identify it.
959 */ 959 */
960 960
961 /* 961 /*
962 * The only event causing the switch_state function to 962 * The only event causing the switch_state function to
963 * be called with yet unknown operation is new command. 963 * be called with yet unknown operation is new command.
964 */ 964 */
@@ -987,7 +987,7 @@ switch_state(struct nandsim *ns)
987 */ 987 */
988 988
989 u_char status = NS_STATUS_OK(ns); 989 u_char status = NS_STATUS_OK(ns);
990 990
991 /* In case of data states, see if all bytes were input/output */ 991 /* In case of data states, see if all bytes were input/output */
992 if ((ns->state & (STATE_DATAIN_MASK | STATE_DATAOUT_MASK)) 992 if ((ns->state & (STATE_DATAIN_MASK | STATE_DATAOUT_MASK))
993 && ns->regs.count != ns->regs.num) { 993 && ns->regs.count != ns->regs.num) {
@@ -995,17 +995,17 @@ switch_state(struct nandsim *ns)
995 ns->regs.num - ns->regs.count); 995 ns->regs.num - ns->regs.count);
996 status = NS_STATUS_FAILED(ns); 996 status = NS_STATUS_FAILED(ns);
997 } 997 }
998 998
999 NS_DBG("switch_state: operation complete, switch to STATE_READY state\n"); 999 NS_DBG("switch_state: operation complete, switch to STATE_READY state\n");
1000 1000
1001 switch_to_ready_state(ns, status); 1001 switch_to_ready_state(ns, status);
1002 1002
1003 return; 1003 return;
1004 } else if (ns->nxstate & (STATE_DATAIN_MASK | STATE_DATAOUT_MASK)) { 1004 } else if (ns->nxstate & (STATE_DATAIN_MASK | STATE_DATAOUT_MASK)) {
1005 /* 1005 /*
1006 * If the next state is data input/output, switch to it now 1006 * If the next state is data input/output, switch to it now
1007 */ 1007 */
1008 1008
1009 ns->state = ns->nxstate; 1009 ns->state = ns->nxstate;
1010 ns->nxstate = ns->op[++ns->stateidx + 1]; 1010 ns->nxstate = ns->op[++ns->stateidx + 1];
1011 ns->regs.num = ns->regs.count = 0; 1011 ns->regs.num = ns->regs.count = 0;
@@ -1023,16 +1023,16 @@ switch_state(struct nandsim *ns)
1023 case STATE_DATAOUT: 1023 case STATE_DATAOUT:
1024 ns->regs.num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; 1024 ns->regs.num = ns->geom.pgszoob - ns->regs.off - ns->regs.column;
1025 break; 1025 break;
1026 1026
1027 case STATE_DATAOUT_ID: 1027 case STATE_DATAOUT_ID:
1028 ns->regs.num = ns->geom.idbytes; 1028 ns->regs.num = ns->geom.idbytes;
1029 break; 1029 break;
1030 1030
1031 case STATE_DATAOUT_STATUS: 1031 case STATE_DATAOUT_STATUS:
1032 case STATE_DATAOUT_STATUS_M: 1032 case STATE_DATAOUT_STATUS_M:
1033 ns->regs.count = ns->regs.num = 0; 1033 ns->regs.count = ns->regs.num = 0;
1034 break; 1034 break;
1035 1035
1036 default: 1036 default:
1037 NS_ERR("switch_state: BUG! unknown data state\n"); 1037 NS_ERR("switch_state: BUG! unknown data state\n");
1038 } 1038 }
@@ -1044,16 +1044,16 @@ switch_state(struct nandsim *ns)
1044 */ 1044 */
1045 1045
1046 ns->regs.count = 0; 1046 ns->regs.count = 0;
1047 1047
1048 switch (NS_STATE(ns->nxstate)) { 1048 switch (NS_STATE(ns->nxstate)) {
1049 case STATE_ADDR_PAGE: 1049 case STATE_ADDR_PAGE:
1050 ns->regs.num = ns->geom.pgaddrbytes; 1050 ns->regs.num = ns->geom.pgaddrbytes;
1051 1051
1052 break; 1052 break;
1053 case STATE_ADDR_SEC: 1053 case STATE_ADDR_SEC:
1054 ns->regs.num = ns->geom.secaddrbytes; 1054 ns->regs.num = ns->geom.secaddrbytes;
1055 break; 1055 break;
1056 1056
1057 case STATE_ADDR_ZERO: 1057 case STATE_ADDR_ZERO:
1058 ns->regs.num = 1; 1058 ns->regs.num = 1;
1059 break; 1059 break;
@@ -1062,7 +1062,7 @@ switch_state(struct nandsim *ns)
1062 NS_ERR("switch_state: BUG! unknown address state\n"); 1062 NS_ERR("switch_state: BUG! unknown address state\n");
1063 } 1063 }
1064 } else { 1064 } else {
1065 /* 1065 /*
1066 * Just reset internal counters. 1066 * Just reset internal counters.
1067 */ 1067 */
1068 1068
@@ -1184,7 +1184,7 @@ ns_nand_read_byte(struct mtd_info *mtd)
1184 default: 1184 default:
1185 BUG(); 1185 BUG();
1186 } 1186 }
1187 1187
1188 if (ns->regs.count == ns->regs.num) { 1188 if (ns->regs.count == ns->regs.num) {
1189 NS_DBG("read_byte: all bytes were read\n"); 1189 NS_DBG("read_byte: all bytes were read\n");
1190 1190
@@ -1201,9 +1201,9 @@ ns_nand_read_byte(struct mtd_info *mtd)
1201 } 1201 }
1202 else if (NS_STATE(ns->nxstate) == STATE_READY) 1202 else if (NS_STATE(ns->nxstate) == STATE_READY)
1203 switch_state(ns); 1203 switch_state(ns);
1204 1204
1205 } 1205 }
1206 1206
1207 return outb; 1207 return outb;
1208} 1208}
1209 1209
@@ -1211,7 +1211,7 @@ static void
1211ns_nand_write_byte(struct mtd_info *mtd, u_char byte) 1211ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1212{ 1212{
1213 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1213 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv;
1214 1214
1215 /* Sanity and correctness checks */ 1215 /* Sanity and correctness checks */
1216 if (!ns->lines.ce) { 1216 if (!ns->lines.ce) {
1217 NS_ERR("write_byte: chip is disabled, ignore write\n"); 1217 NS_ERR("write_byte: chip is disabled, ignore write\n");
@@ -1221,7 +1221,7 @@ ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1221 NS_ERR("write_byte: ALE and CLE pins are high simultaneously, ignore write\n"); 1221 NS_ERR("write_byte: ALE and CLE pins are high simultaneously, ignore write\n");
1222 return; 1222 return;
1223 } 1223 }
1224 1224
1225 if (ns->lines.cle == 1) { 1225 if (ns->lines.cle == 1) {
1226 /* 1226 /*
1227 * The byte written is a command. 1227 * The byte written is a command.
@@ -1233,7 +1233,7 @@ ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1233 return; 1233 return;
1234 } 1234 }
1235 1235
1236 /* 1236 /*
1237 * Chip might still be in STATE_DATAOUT 1237 * Chip might still be in STATE_DATAOUT
1238 * (if OPT_AUTOINCR feature is supported), STATE_DATAOUT_STATUS or 1238 * (if OPT_AUTOINCR feature is supported), STATE_DATAOUT_STATUS or
1239 * STATE_DATAOUT_STATUS_M state. If so, switch state. 1239 * STATE_DATAOUT_STATUS_M state. If so, switch state.
@@ -1254,13 +1254,13 @@ ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1254 "ignore previous states\n", (uint)byte, get_state_name(ns->nxstate)); 1254 "ignore previous states\n", (uint)byte, get_state_name(ns->nxstate));
1255 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); 1255 switch_to_ready_state(ns, NS_STATUS_FAILED(ns));
1256 } 1256 }
1257 1257
1258 /* Check that the command byte is correct */ 1258 /* Check that the command byte is correct */
1259 if (check_command(byte)) { 1259 if (check_command(byte)) {
1260 NS_ERR("write_byte: unknown command %#x\n", (uint)byte); 1260 NS_ERR("write_byte: unknown command %#x\n", (uint)byte);
1261 return; 1261 return;
1262 } 1262 }
1263 1263
1264 NS_DBG("command byte corresponding to %s state accepted\n", 1264 NS_DBG("command byte corresponding to %s state accepted\n",
1265 get_state_name(get_state_by_command(byte))); 1265 get_state_name(get_state_by_command(byte)));
1266 ns->regs.command = byte; 1266 ns->regs.command = byte;
@@ -1277,12 +1277,12 @@ ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1277 1277
1278 if (find_operation(ns, 1) < 0) 1278 if (find_operation(ns, 1) < 0)
1279 return; 1279 return;
1280 1280
1281 if ((ns->state & ACTION_MASK) && do_state_action(ns, ns->state) < 0) { 1281 if ((ns->state & ACTION_MASK) && do_state_action(ns, ns->state) < 0) {
1282 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); 1282 switch_to_ready_state(ns, NS_STATUS_FAILED(ns));
1283 return; 1283 return;
1284 } 1284 }
1285 1285
1286 ns->regs.count = 0; 1286 ns->regs.count = 0;
1287 switch (NS_STATE(ns->nxstate)) { 1287 switch (NS_STATE(ns->nxstate)) {
1288 case STATE_ADDR_PAGE: 1288 case STATE_ADDR_PAGE:
@@ -1306,7 +1306,7 @@ ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1306 switch_to_ready_state(ns, NS_STATUS_FAILED(ns)); 1306 switch_to_ready_state(ns, NS_STATUS_FAILED(ns));
1307 return; 1307 return;
1308 } 1308 }
1309 1309
1310 /* Check if this is expected byte */ 1310 /* Check if this is expected byte */
1311 if (ns->regs.count == ns->regs.num) { 1311 if (ns->regs.count == ns->regs.num) {
1312 NS_ERR("write_byte: no more address bytes expected\n"); 1312 NS_ERR("write_byte: no more address bytes expected\n");
@@ -1325,12 +1325,12 @@ ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1325 NS_DBG("address (%#x, %#x) is accepted\n", ns->regs.row, ns->regs.column); 1325 NS_DBG("address (%#x, %#x) is accepted\n", ns->regs.row, ns->regs.column);
1326 switch_state(ns); 1326 switch_state(ns);
1327 } 1327 }
1328 1328
1329 } else { 1329 } else {
1330 /* 1330 /*
1331 * The byte written is an input data. 1331 * The byte written is an input data.
1332 */ 1332 */
1333 1333
1334 /* Check that chip is expecting data input */ 1334 /* Check that chip is expecting data input */
1335 if (!(ns->state & STATE_DATAIN_MASK)) { 1335 if (!(ns->state & STATE_DATAIN_MASK)) {
1336 NS_ERR("write_byte: data input (%#x) isn't expected, state is %s, " 1336 NS_ERR("write_byte: data input (%#x) isn't expected, state is %s, "
@@ -1372,7 +1372,7 @@ ns_nand_read_word(struct mtd_info *mtd)
1372 struct nand_chip *chip = (struct nand_chip *)mtd->priv; 1372 struct nand_chip *chip = (struct nand_chip *)mtd->priv;
1373 1373
1374 NS_DBG("read_word\n"); 1374 NS_DBG("read_word\n");
1375 1375
1376 return chip->read_byte(mtd) | (chip->read_byte(mtd) << 8); 1376 return chip->read_byte(mtd) | (chip->read_byte(mtd) << 8);
1377} 1377}
1378 1378
@@ -1380,14 +1380,14 @@ static void
1380ns_nand_write_word(struct mtd_info *mtd, uint16_t word) 1380ns_nand_write_word(struct mtd_info *mtd, uint16_t word)
1381{ 1381{
1382 struct nand_chip *chip = (struct nand_chip *)mtd->priv; 1382 struct nand_chip *chip = (struct nand_chip *)mtd->priv;
1383 1383
1384 NS_DBG("write_word\n"); 1384 NS_DBG("write_word\n");
1385 1385
1386 chip->write_byte(mtd, word & 0xFF); 1386 chip->write_byte(mtd, word & 0xFF);
1387 chip->write_byte(mtd, word >> 8); 1387 chip->write_byte(mtd, word >> 8);
1388} 1388}
1389 1389
1390static void 1390static void
1391ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len) 1391ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
1392{ 1392{
1393 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1393 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv;
@@ -1409,13 +1409,13 @@ ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
1409 1409
1410 memcpy(ns->buf.byte + ns->regs.count, buf, len); 1410 memcpy(ns->buf.byte + ns->regs.count, buf, len);
1411 ns->regs.count += len; 1411 ns->regs.count += len;
1412 1412
1413 if (ns->regs.count == ns->regs.num) { 1413 if (ns->regs.count == ns->regs.num) {
1414 NS_DBG("write_buf: %d bytes were written\n", ns->regs.count); 1414 NS_DBG("write_buf: %d bytes were written\n", ns->regs.count);
1415 } 1415 }
1416} 1416}
1417 1417
1418static void 1418static void
1419ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) 1419ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
1420{ 1420{
1421 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1421 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv;
@@ -1453,7 +1453,7 @@ ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
1453 1453
1454 memcpy(buf, ns->buf.byte + ns->regs.count, len); 1454 memcpy(buf, ns->buf.byte + ns->regs.count, len);
1455 ns->regs.count += len; 1455 ns->regs.count += len;
1456 1456
1457 if (ns->regs.count == ns->regs.num) { 1457 if (ns->regs.count == ns->regs.num) {
1458 if ((ns->options & OPT_AUTOINCR) && NS_STATE(ns->state) == STATE_DATAOUT) { 1458 if ((ns->options & OPT_AUTOINCR) && NS_STATE(ns->state) == STATE_DATAOUT) {
1459 ns->regs.count = 0; 1459 ns->regs.count = 0;
@@ -1465,11 +1465,11 @@ ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
1465 else if (NS_STATE(ns->nxstate) == STATE_READY) 1465 else if (NS_STATE(ns->nxstate) == STATE_READY)
1466 switch_state(ns); 1466 switch_state(ns);
1467 } 1467 }
1468 1468
1469 return; 1469 return;
1470} 1470}
1471 1471
1472static int 1472static int
1473ns_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len) 1473ns_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
1474{ 1474{
1475 ns_nand_read_buf(mtd, (u_char *)&ns_verify_buf[0], len); 1475 ns_nand_read_buf(mtd, (u_char *)&ns_verify_buf[0], len);
@@ -1496,7 +1496,7 @@ int __init ns_init_module(void)
1496 NS_ERR("wrong bus width (%d), use only 8 or 16\n", bus_width); 1496 NS_ERR("wrong bus width (%d), use only 8 or 16\n", bus_width);
1497 return -EINVAL; 1497 return -EINVAL;
1498 } 1498 }
1499 1499
1500 /* Allocate and initialize mtd_info, nand_chip and nandsim structures */ 1500 /* Allocate and initialize mtd_info, nand_chip and nandsim structures */
1501 nsmtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip) 1501 nsmtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip)
1502 + sizeof(struct nandsim), GFP_KERNEL); 1502 + sizeof(struct nandsim), GFP_KERNEL);
@@ -1509,7 +1509,7 @@ int __init ns_init_module(void)
1509 chip = (struct nand_chip *)(nsmtd + 1); 1509 chip = (struct nand_chip *)(nsmtd + 1);
1510 nsmtd->priv = (void *)chip; 1510 nsmtd->priv = (void *)chip;
1511 nand = (struct nandsim *)(chip + 1); 1511 nand = (struct nandsim *)(chip + 1);
1512 chip->priv = (void *)nand; 1512 chip->priv = (void *)nand;
1513 1513
1514 /* 1514 /*
1515 * Register simulator's callbacks. 1515 * Register simulator's callbacks.
@@ -1526,9 +1526,9 @@ int __init ns_init_module(void)
1526 chip->eccmode = NAND_ECC_SOFT; 1526 chip->eccmode = NAND_ECC_SOFT;
1527 chip->options |= NAND_SKIP_BBTSCAN; 1527 chip->options |= NAND_SKIP_BBTSCAN;
1528 1528
1529 /* 1529 /*
1530 * Perform minimum nandsim structure initialization to handle 1530 * Perform minimum nandsim structure initialization to handle
1531 * the initial ID read command correctly 1531 * the initial ID read command correctly
1532 */ 1532 */
1533 if (third_id_byte != 0xFF || fourth_id_byte != 0xFF) 1533 if (third_id_byte != 0xFF || fourth_id_byte != 0xFF)
1534 nand->geom.idbytes = 4; 1534 nand->geom.idbytes = 4;
@@ -1557,7 +1557,7 @@ int __init ns_init_module(void)
1557 NS_ERR("scan_bbt: can't initialize the nandsim structure\n"); 1557 NS_ERR("scan_bbt: can't initialize the nandsim structure\n");
1558 goto error; 1558 goto error;
1559 } 1559 }
1560 1560
1561 if ((retval = nand_default_bbt(nsmtd)) != 0) { 1561 if ((retval = nand_default_bbt(nsmtd)) != 0) {
1562 free_nandsim(nand); 1562 free_nandsim(nand);
1563 goto error; 1563 goto error;
diff --git a/drivers/mtd/nand/ppchameleonevb.c b/drivers/mtd/nand/ppchameleonevb.c
index e510a83d7bdb..91a95f34a6ee 100644
--- a/drivers/mtd/nand/ppchameleonevb.c
+++ b/drivers/mtd/nand/ppchameleonevb.c
@@ -6,7 +6,7 @@
6 * Derived from drivers/mtd/nand/edb7312.c 6 * Derived from drivers/mtd/nand/edb7312.c
7 * 7 *
8 * 8 *
9 * $Id: ppchameleonevb.c,v 1.6 2004/11/05 16:07:16 kalev Exp $ 9 * $Id: ppchameleonevb.c,v 1.7 2005/11/07 11:14:31 gleixner Exp $
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as 12 * it under the terms of the GNU General Public License version 2 as
@@ -338,7 +338,7 @@ nand_evb_init:
338 out_be32((volatile unsigned*)GPIO0_TSRH, in_be32((volatile unsigned*)GPIO0_TSRH) & 0xFFFFFFF0); 338 out_be32((volatile unsigned*)GPIO0_TSRH, in_be32((volatile unsigned*)GPIO0_TSRH) & 0xFFFFFFF0);
339 out_be32((volatile unsigned*)GPIO0_TSRL, in_be32((volatile unsigned*)GPIO0_TSRL) & 0x3FFFFFFF); 339 out_be32((volatile unsigned*)GPIO0_TSRL, in_be32((volatile unsigned*)GPIO0_TSRL) & 0x3FFFFFFF);
340 /* enable output driver */ 340 /* enable output driver */
341 out_be32((volatile unsigned*)GPIO0_TCR, in_be32((volatile unsigned*)GPIO0_TCR) | NAND_EVB_nCE_GPIO_PIN | 341 out_be32((volatile unsigned*)GPIO0_TCR, in_be32((volatile unsigned*)GPIO0_TCR) | NAND_EVB_nCE_GPIO_PIN |
342 NAND_EVB_CLE_GPIO_PIN | NAND_EVB_ALE_GPIO_PIN); 342 NAND_EVB_CLE_GPIO_PIN | NAND_EVB_ALE_GPIO_PIN);
343#ifdef USE_READY_BUSY_PIN 343#ifdef USE_READY_BUSY_PIN
344 /* three-state select */ 344 /* three-state select */
@@ -402,7 +402,7 @@ static void __exit ppchameleonevb_cleanup (void)
402 /* Release resources, unregister device(s) */ 402 /* Release resources, unregister device(s) */
403 nand_release (ppchameleon_mtd); 403 nand_release (ppchameleon_mtd);
404 nand_release (ppchameleonevb_mtd); 404 nand_release (ppchameleonevb_mtd);
405 405
406 /* Release iomaps */ 406 /* Release iomaps */
407 this = (struct nand_chip *) &ppchameleon_mtd[1]; 407 this = (struct nand_chip *) &ppchameleon_mtd[1];
408 iounmap((void *) this->IO_ADDR_R; 408 iounmap((void *) this->IO_ADDR_R;
diff --git a/drivers/mtd/nand/rtc_from4.c b/drivers/mtd/nand/rtc_from4.c
index 031051cbde76..3a5841c9d950 100644
--- a/drivers/mtd/nand/rtc_from4.c
+++ b/drivers/mtd/nand/rtc_from4.c
@@ -2,11 +2,11 @@
2 * drivers/mtd/nand/rtc_from4.c 2 * drivers/mtd/nand/rtc_from4.c
3 * 3 *
4 * Copyright (C) 2004 Red Hat, Inc. 4 * Copyright (C) 2004 Red Hat, Inc.
5 * 5 *
6 * Derived from drivers/mtd/nand/spia.c 6 * Derived from drivers/mtd/nand/spia.c
7 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com) 7 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
8 * 8 *
9 * $Id: rtc_from4.c,v 1.9 2005/01/24 20:40:11 dmarlin Exp $ 9 * $Id: rtc_from4.c,v 1.10 2005/11/07 11:14:31 gleixner Exp $
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as 12 * it under the terms of the GNU General Public License version 2 as
@@ -14,8 +14,8 @@
14 * 14 *
15 * Overview: 15 * Overview:
16 * This is a device driver for the AG-AND flash device found on the 16 * This is a device driver for the AG-AND flash device found on the
17 * Renesas Technology Corp. Flash ROM 4-slot interface board (FROM_BOARD4), 17 * Renesas Technology Corp. Flash ROM 4-slot interface board (FROM_BOARD4),
18 * which utilizes the Renesas HN29V1G91T-30 part. 18 * which utilizes the Renesas HN29V1G91T-30 part.
19 * This chip is a 1 GBibit (128MiB x 8 bits) AG-AND flash device. 19 * This chip is a 1 GBibit (128MiB x 8 bits) AG-AND flash device.
20 */ 20 */
21 21
@@ -105,9 +105,9 @@ const static struct mtd_partition partition_info[] = {
105}; 105};
106#define NUM_PARTITIONS 1 106#define NUM_PARTITIONS 1
107 107
108/* 108/*
109 * hardware specific flash bbt decriptors 109 * hardware specific flash bbt decriptors
110 * Note: this is to allow debugging by disabling 110 * Note: this is to allow debugging by disabling
111 * NAND_BBT_CREATE and/or NAND_BBT_WRITE 111 * NAND_BBT_CREATE and/or NAND_BBT_WRITE
112 * 112 *
113 */ 113 */
@@ -141,7 +141,7 @@ static struct nand_bbt_descr rtc_from4_bbt_mirror_descr = {
141/* the Reed Solomon control structure */ 141/* the Reed Solomon control structure */
142static struct rs_control *rs_decoder; 142static struct rs_control *rs_decoder;
143 143
144/* 144/*
145 * hardware specific Out Of Band information 145 * hardware specific Out Of Band information
146 */ 146 */
147static struct nand_oobinfo rtc_from4_nand_oobinfo = { 147static struct nand_oobinfo rtc_from4_nand_oobinfo = {
@@ -200,38 +200,38 @@ static uint8_t revbits[256] = {
200 200
201 201
202 202
203/* 203/*
204 * rtc_from4_hwcontrol - hardware specific access to control-lines 204 * rtc_from4_hwcontrol - hardware specific access to control-lines
205 * @mtd: MTD device structure 205 * @mtd: MTD device structure
206 * @cmd: hardware control command 206 * @cmd: hardware control command
207 * 207 *
208 * Address lines (A5 and A4) are used to control Command and Address Latch 208 * Address lines (A5 and A4) are used to control Command and Address Latch
209 * Enable on this board, so set the read/write address appropriately. 209 * Enable on this board, so set the read/write address appropriately.
210 * 210 *
211 * Chip Enable is also controlled by the Chip Select (CS5) and 211 * Chip Enable is also controlled by the Chip Select (CS5) and
212 * Address lines (A24-A22), so no action is required here. 212 * Address lines (A24-A22), so no action is required here.
213 * 213 *
214 */ 214 */
215static void rtc_from4_hwcontrol(struct mtd_info *mtd, int cmd) 215static void rtc_from4_hwcontrol(struct mtd_info *mtd, int cmd)
216{ 216{
217 struct nand_chip* this = (struct nand_chip *) (mtd->priv); 217 struct nand_chip* this = (struct nand_chip *) (mtd->priv);
218 218
219 switch(cmd) { 219 switch(cmd) {
220 220
221 case NAND_CTL_SETCLE: 221 case NAND_CTL_SETCLE:
222 this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_CLE); 222 this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_CLE);
223 break; 223 break;
224 case NAND_CTL_CLRCLE: 224 case NAND_CTL_CLRCLE:
225 this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W & ~RTC_FROM4_CLE); 225 this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W & ~RTC_FROM4_CLE);
226 break; 226 break;
227 227
228 case NAND_CTL_SETALE: 228 case NAND_CTL_SETALE:
229 this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_ALE); 229 this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_ALE);
230 break; 230 break;
231 case NAND_CTL_CLRALE: 231 case NAND_CTL_CLRALE:
232 this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W & ~RTC_FROM4_ALE); 232 this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W & ~RTC_FROM4_ALE);
233 break; 233 break;
234 234
235 case NAND_CTL_SETNCE: 235 case NAND_CTL_SETNCE:
236 break; 236 break;
237 case NAND_CTL_CLRNCE: 237 case NAND_CTL_CLRNCE:
@@ -296,7 +296,7 @@ static int rtc_from4_nand_device_ready(struct mtd_info *mtd)
296 * @mtd: MTD device structure 296 * @mtd: MTD device structure
297 * @chip: Chip to select (0 == slot 3, 1 == slot 4) 297 * @chip: Chip to select (0 == slot 3, 1 == slot 4)
298 * 298 *
299 * If there was a sudden loss of power during an erase operation, a 299 * If there was a sudden loss of power during an erase operation, a
300 * "device recovery" operation must be performed when power is restored 300 * "device recovery" operation must be performed when power is restored
301 * to ensure correct operation. This routine performs the required steps 301 * to ensure correct operation. This routine performs the required steps
302 * for the requested chip. 302 * for the requested chip.
@@ -312,7 +312,7 @@ static void deplete(struct mtd_info *mtd, int chip)
312 while (!this->dev_ready(mtd)); 312 while (!this->dev_ready(mtd));
313 313
314 this->select_chip(mtd, chip); 314 this->select_chip(mtd, chip);
315 315
316 /* Send the commands for device recovery, phase 1 */ 316 /* Send the commands for device recovery, phase 1 */
317 this->cmdfunc (mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0000); 317 this->cmdfunc (mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0000);
318 this->cmdfunc (mtd, NAND_CMD_DEPLETE2, -1, -1); 318 this->cmdfunc (mtd, NAND_CMD_DEPLETE2, -1, -1);
@@ -330,7 +330,7 @@ static void deplete(struct mtd_info *mtd, int chip)
330 * @mtd: MTD device structure 330 * @mtd: MTD device structure
331 * @mode: I/O mode; read or write 331 * @mode: I/O mode; read or write
332 * 332 *
333 * enable hardware ECC for data read or write 333 * enable hardware ECC for data read or write
334 * 334 *
335 */ 335 */
336static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode) 336static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode)
@@ -340,7 +340,7 @@ static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode)
340 340
341 switch (mode) { 341 switch (mode) {
342 case NAND_ECC_READ : 342 case NAND_ECC_READ :
343 status = RTC_FROM4_RS_ECC_CTL_CLR 343 status = RTC_FROM4_RS_ECC_CTL_CLR
344 | RTC_FROM4_RS_ECC_CTL_FD_E; 344 | RTC_FROM4_RS_ECC_CTL_FD_E;
345 345
346 *rs_ecc_ctl = status; 346 *rs_ecc_ctl = status;
@@ -353,8 +353,8 @@ static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode)
353 break; 353 break;
354 354
355 case NAND_ECC_WRITE : 355 case NAND_ECC_WRITE :
356 status = RTC_FROM4_RS_ECC_CTL_CLR 356 status = RTC_FROM4_RS_ECC_CTL_CLR
357 | RTC_FROM4_RS_ECC_CTL_GEN 357 | RTC_FROM4_RS_ECC_CTL_GEN
358 | RTC_FROM4_RS_ECC_CTL_FD_E; 358 | RTC_FROM4_RS_ECC_CTL_FD_E;
359 359
360 *rs_ecc_ctl = status; 360 *rs_ecc_ctl = status;
@@ -411,7 +411,7 @@ static void rtc_from4_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_c
411static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_char *ecc1, u_char *ecc2) 411static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_char *ecc1, u_char *ecc2)
412{ 412{
413 int i, j, res; 413 int i, j, res;
414 unsigned short status; 414 unsigned short status;
415 uint16_t par[6], syn[6]; 415 uint16_t par[6], syn[6];
416 uint8_t ecc[8]; 416 uint8_t ecc[8];
417 volatile unsigned short *rs_ecc; 417 volatile unsigned short *rs_ecc;
@@ -430,7 +430,7 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha
430 } 430 }
431 431
432 /* convert into 6 10bit syndrome fields */ 432 /* convert into 6 10bit syndrome fields */
433 par[5] = rs_decoder->index_of[(((uint16_t)ecc[0] >> 0) & 0x0ff) | 433 par[5] = rs_decoder->index_of[(((uint16_t)ecc[0] >> 0) & 0x0ff) |
434 (((uint16_t)ecc[1] << 8) & 0x300)]; 434 (((uint16_t)ecc[1] << 8) & 0x300)];
435 par[4] = rs_decoder->index_of[(((uint16_t)ecc[1] >> 2) & 0x03f) | 435 par[4] = rs_decoder->index_of[(((uint16_t)ecc[1] >> 2) & 0x03f) |
436 (((uint16_t)ecc[2] << 6) & 0x3c0)]; 436 (((uint16_t)ecc[2] << 6) & 0x3c0)];
@@ -456,7 +456,7 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha
456 /* Let the library code do its magic.*/ 456 /* Let the library code do its magic.*/
457 res = decode_rs8(rs_decoder, (uint8_t *)buf, par, 512, syn, 0, NULL, 0xff, NULL); 457 res = decode_rs8(rs_decoder, (uint8_t *)buf, par, 512, syn, 0, NULL, 0xff, NULL);
458 if (res > 0) { 458 if (res > 0) {
459 DEBUG (MTD_DEBUG_LEVEL0, "rtc_from4_correct_data: " 459 DEBUG (MTD_DEBUG_LEVEL0, "rtc_from4_correct_data: "
460 "ECC corrected %d errors on read\n", res); 460 "ECC corrected %d errors on read\n", res);
461 } 461 }
462 return res; 462 return res;
@@ -470,9 +470,9 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha
470 * @state: state or the operation 470 * @state: state or the operation
471 * @status: status code returned from read status 471 * @status: status code returned from read status
472 * @page: startpage inside the chip, must be called with (page & this->pagemask) 472 * @page: startpage inside the chip, must be called with (page & this->pagemask)
473 * 473 *
474 * Perform additional error status checks on erase and write failures 474 * Perform additional error status checks on erase and write failures
475 * to determine if errors are correctable. For this device, correctable 475 * to determine if errors are correctable. For this device, correctable
476 * 1-bit errors on erase and write are considered acceptable. 476 * 1-bit errors on erase and write are considered acceptable.
477 * 477 *
478 * note: see pages 34..37 of data sheet for details. 478 * note: see pages 34..37 of data sheet for details.
@@ -633,7 +633,7 @@ int __init rtc_from4_init (void)
633 633
634#ifdef RTC_FROM4_HWECC 634#ifdef RTC_FROM4_HWECC
635 /* We could create the decoder on demand, if memory is a concern. 635 /* We could create the decoder on demand, if memory is a concern.
636 * This way we have it handy, if an error happens 636 * This way we have it handy, if an error happens
637 * 637 *
638 * Symbolsize is 10 (bits) 638 * Symbolsize is 10 (bits)
639 * Primitve polynomial is x^10+x^3+1 639 * Primitve polynomial is x^10+x^3+1
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 2df5e47d1f5c..97e9b7892d29 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -17,8 +17,9 @@
17 * 02-May-2005 BJD Reduced hwcontrol decode 17 * 02-May-2005 BJD Reduced hwcontrol decode
18 * 20-Jun-2005 BJD Updated s3c2440 support, fixed timing bug 18 * 20-Jun-2005 BJD Updated s3c2440 support, fixed timing bug
19 * 08-Jul-2005 BJD Fix OOPS when no platform data supplied 19 * 08-Jul-2005 BJD Fix OOPS when no platform data supplied
20 * 20-Oct-2005 BJD Fix timing calculation bug
20 * 21 *
21 * $Id: s3c2410.c,v 1.14 2005/07/06 20:05:06 bjd Exp $ 22 * $Id: s3c2410.c,v 1.20 2005/11/07 11:14:31 gleixner Exp $
22 * 23 *
23 * This program is free software; you can redistribute it and/or modify 24 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by 25 * it under the terms of the GNU General Public License as published by
@@ -136,13 +137,13 @@ static struct s3c2410_platform_nand *to_nand_plat(struct device *dev)
136 137
137/* timing calculations */ 138/* timing calculations */
138 139
139#define NS_IN_KHZ 10000000 140#define NS_IN_KHZ 1000000
140 141
141static int s3c2410_nand_calc_rate(int wanted, unsigned long clk, int max) 142static int s3c2410_nand_calc_rate(int wanted, unsigned long clk, int max)
142{ 143{
143 int result; 144 int result;
144 145
145 result = (wanted * NS_IN_KHZ) / clk; 146 result = (wanted * clk) / NS_IN_KHZ;
146 result++; 147 result++;
147 148
148 pr_debug("result %d from %ld, %d\n", result, clk, wanted); 149 pr_debug("result %d from %ld, %d\n", result, clk, wanted);
@@ -159,20 +160,22 @@ static int s3c2410_nand_calc_rate(int wanted, unsigned long clk, int max)
159 return result; 160 return result;
160} 161}
161 162
162#define to_ns(ticks,clk) (((clk) * (ticks)) / NS_IN_KHZ) 163#define to_ns(ticks,clk) (((ticks) * NS_IN_KHZ) / (unsigned int)(clk))
163 164
164/* controller setup */ 165/* controller setup */
165 166
166static int s3c2410_nand_inithw(struct s3c2410_nand_info *info, 167static int s3c2410_nand_inithw(struct s3c2410_nand_info *info,
167 struct device *dev) 168 struct device *dev)
168{ 169{
169 struct s3c2410_platform_nand *plat = to_nand_plat(dev); 170 struct s3c2410_platform_nand *plat = to_nand_plat(dev);
170 unsigned int tacls, twrph0, twrph1;
171 unsigned long clkrate = clk_get_rate(info->clk); 171 unsigned long clkrate = clk_get_rate(info->clk);
172 int tacls, twrph0, twrph1;
172 unsigned long cfg; 173 unsigned long cfg;
173 174
174 /* calculate the timing information for the controller */ 175 /* calculate the timing information for the controller */
175 176
177 clkrate /= 1000; /* turn clock into kHz for ease of use */
178
176 if (plat != NULL) { 179 if (plat != NULL) {
177 tacls = s3c2410_nand_calc_rate(plat->tacls, clkrate, 4); 180 tacls = s3c2410_nand_calc_rate(plat->tacls, clkrate, 4);
178 twrph0 = s3c2410_nand_calc_rate(plat->twrph0, clkrate, 8); 181 twrph0 = s3c2410_nand_calc_rate(plat->twrph0, clkrate, 8);
@@ -183,16 +186,16 @@ static int s3c2410_nand_inithw(struct s3c2410_nand_info *info,
183 twrph0 = 8; 186 twrph0 = 8;
184 twrph1 = 8; 187 twrph1 = 8;
185 } 188 }
186 189
187 if (tacls < 0 || twrph0 < 0 || twrph1 < 0) { 190 if (tacls < 0 || twrph0 < 0 || twrph1 < 0) {
188 printk(KERN_ERR PFX "cannot get timings suitable for board\n"); 191 printk(KERN_ERR PFX "cannot get timings suitable for board\n");
189 return -EINVAL; 192 return -EINVAL;
190 } 193 }
191 194
192 printk(KERN_INFO PFX "timing: Tacls %ldns, Twrph0 %ldns, Twrph1 %ldns\n", 195 printk(KERN_INFO PFX "Tacls=%d, %dns Twrph0=%d %dns, Twrph1=%d %dns\n",
193 to_ns(tacls, clkrate), 196 tacls, to_ns(tacls, clkrate),
194 to_ns(twrph0, clkrate), 197 twrph0, to_ns(twrph0, clkrate),
195 to_ns(twrph1, clkrate)); 198 twrph1, to_ns(twrph1, clkrate));
196 199
197 if (!info->is_s3c2440) { 200 if (!info->is_s3c2440) {
198 cfg = S3C2410_NFCONF_EN; 201 cfg = S3C2410_NFCONF_EN;
@@ -216,7 +219,7 @@ static int s3c2410_nand_inithw(struct s3c2410_nand_info *info,
216static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip) 219static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
217{ 220{
218 struct s3c2410_nand_info *info; 221 struct s3c2410_nand_info *info;
219 struct s3c2410_nand_mtd *nmtd; 222 struct s3c2410_nand_mtd *nmtd;
220 struct nand_chip *this = mtd->priv; 223 struct nand_chip *this = mtd->priv;
221 void __iomem *reg; 224 void __iomem *reg;
222 unsigned long cur; 225 unsigned long cur;
@@ -249,7 +252,7 @@ static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
249 writel(cur, reg); 252 writel(cur, reg);
250} 253}
251 254
252/* command and control functions 255/* command and control functions
253 * 256 *
254 * Note, these all use tglx's method of changing the IO_ADDR_W field 257 * Note, these all use tglx's method of changing the IO_ADDR_W field
255 * to make the code simpler, and use the nand layer's code to issue the 258 * to make the code simpler, and use the nand layer's code to issue the
@@ -321,7 +324,7 @@ static void s3c2440_nand_hwcontrol(struct mtd_info *mtd, int cmd)
321static int s3c2410_nand_devready(struct mtd_info *mtd) 324static int s3c2410_nand_devready(struct mtd_info *mtd)
322{ 325{
323 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 326 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
324 327
325 if (info->is_s3c2440) 328 if (info->is_s3c2440)
326 return readb(info->regs + S3C2440_NFSTAT) & S3C2440_NFSTAT_READY; 329 return readb(info->regs + S3C2440_NFSTAT) & S3C2440_NFSTAT_READY;
327 return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY; 330 return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY;
@@ -342,7 +345,7 @@ static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
342 345
343 if (read_ecc[0] == calc_ecc[0] && 346 if (read_ecc[0] == calc_ecc[0] &&
344 read_ecc[1] == calc_ecc[1] && 347 read_ecc[1] == calc_ecc[1] &&
345 read_ecc[2] == calc_ecc[2]) 348 read_ecc[2] == calc_ecc[2])
346 return 0; 349 return 0;
347 350
348 /* we curently have no method for correcting the error */ 351 /* we curently have no method for correcting the error */
@@ -433,14 +436,14 @@ static int s3c2410_nand_remove(struct device *dev)
433 436
434 dev_set_drvdata(dev, NULL); 437 dev_set_drvdata(dev, NULL);
435 438
436 if (info == NULL) 439 if (info == NULL)
437 return 0; 440 return 0;
438 441
439 /* first thing we need to do is release all our mtds 442 /* first thing we need to do is release all our mtds
440 * and their partitions, then go through freeing the 443 * and their partitions, then go through freeing the
441 * resources used 444 * resources used
442 */ 445 */
443 446
444 if (info->mtds != NULL) { 447 if (info->mtds != NULL) {
445 struct s3c2410_nand_mtd *ptr = info->mtds; 448 struct s3c2410_nand_mtd *ptr = info->mtds;
446 int mtdno; 449 int mtdno;
@@ -504,7 +507,7 @@ static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
504 507
505/* s3c2410_nand_init_chip 508/* s3c2410_nand_init_chip
506 * 509 *
507 * init a single instance of an chip 510 * init a single instance of an chip
508*/ 511*/
509 512
510static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info, 513static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
@@ -576,7 +579,7 @@ static int s3c24xx_nand_probe(struct device *dev, int is_s3c2440)
576 579
577 info = kmalloc(sizeof(*info), GFP_KERNEL); 580 info = kmalloc(sizeof(*info), GFP_KERNEL);
578 if (info == NULL) { 581 if (info == NULL) {
579 printk(KERN_ERR PFX "no memory for flash info\n"); 582 dev_err(dev, "no memory for flash info\n");
580 err = -ENOMEM; 583 err = -ENOMEM;
581 goto exit_error; 584 goto exit_error;
582 } 585 }
@@ -591,7 +594,7 @@ static int s3c24xx_nand_probe(struct device *dev, int is_s3c2440)
591 594
592 info->clk = clk_get(dev, "nand"); 595 info->clk = clk_get(dev, "nand");
593 if (IS_ERR(info->clk)) { 596 if (IS_ERR(info->clk)) {
594 printk(KERN_ERR PFX "failed to get clock"); 597 dev_err(dev, "failed to get clock");
595 err = -ENOENT; 598 err = -ENOENT;
596 goto exit_error; 599 goto exit_error;
597 } 600 }
@@ -608,7 +611,7 @@ static int s3c24xx_nand_probe(struct device *dev, int is_s3c2440)
608 info->area = request_mem_region(res->start, size, pdev->name); 611 info->area = request_mem_region(res->start, size, pdev->name);
609 612
610 if (info->area == NULL) { 613 if (info->area == NULL) {
611 printk(KERN_ERR PFX "cannot reserve register region\n"); 614 dev_err(dev, "cannot reserve register region\n");
612 err = -ENOENT; 615 err = -ENOENT;
613 goto exit_error; 616 goto exit_error;
614 } 617 }
@@ -619,12 +622,12 @@ static int s3c24xx_nand_probe(struct device *dev, int is_s3c2440)
619 info->is_s3c2440 = is_s3c2440; 622 info->is_s3c2440 = is_s3c2440;
620 623
621 if (info->regs == NULL) { 624 if (info->regs == NULL) {
622 printk(KERN_ERR PFX "cannot reserve register region\n"); 625 dev_err(dev, "cannot reserve register region\n");
623 err = -EIO; 626 err = -EIO;
624 goto exit_error; 627 goto exit_error;
625 } 628 }
626 629
627 printk(KERN_INFO PFX "mapped registers at %p\n", info->regs); 630 dev_dbg(dev, "mapped registers at %p\n", info->regs);
628 631
629 /* initialise the hardware */ 632 /* initialise the hardware */
630 633
@@ -642,7 +645,7 @@ static int s3c24xx_nand_probe(struct device *dev, int is_s3c2440)
642 size = nr_sets * sizeof(*info->mtds); 645 size = nr_sets * sizeof(*info->mtds);
643 info->mtds = kmalloc(size, GFP_KERNEL); 646 info->mtds = kmalloc(size, GFP_KERNEL);
644 if (info->mtds == NULL) { 647 if (info->mtds == NULL) {
645 printk(KERN_ERR PFX "failed to allocate mtd storage\n"); 648 dev_err(dev, "failed to allocate mtd storage\n");
646 err = -ENOMEM; 649 err = -ENOMEM;
647 goto exit_error; 650 goto exit_error;
648 } 651 }
@@ -656,7 +659,7 @@ static int s3c24xx_nand_probe(struct device *dev, int is_s3c2440)
656 for (setno = 0; setno < nr_sets; setno++, nmtd++) { 659 for (setno = 0; setno < nr_sets; setno++, nmtd++) {
657 pr_debug("initialising set %d (%p, info %p)\n", 660 pr_debug("initialising set %d (%p, info %p)\n",
658 setno, nmtd, info); 661 setno, nmtd, info);
659 662
660 s3c2410_nand_init_chip(info, nmtd, sets); 663 s3c2410_nand_init_chip(info, nmtd, sets);
661 664
662 nmtd->scan_res = nand_scan(&nmtd->mtd, 665 nmtd->scan_res = nand_scan(&nmtd->mtd,
@@ -669,7 +672,7 @@ static int s3c24xx_nand_probe(struct device *dev, int is_s3c2440)
669 if (sets != NULL) 672 if (sets != NULL)
670 sets++; 673 sets++;
671 } 674 }
672 675
673 pr_debug("initialised ok\n"); 676 pr_debug("initialised ok\n");
674 return 0; 677 return 0;
675 678
@@ -695,6 +698,7 @@ static int s3c2440_nand_probe(struct device *dev)
695 698
696static struct device_driver s3c2410_nand_driver = { 699static struct device_driver s3c2410_nand_driver = {
697 .name = "s3c2410-nand", 700 .name = "s3c2410-nand",
701 .owner = THIS_MODULE,
698 .bus = &platform_bus_type, 702 .bus = &platform_bus_type,
699 .probe = s3c2410_nand_probe, 703 .probe = s3c2410_nand_probe,
700 .remove = s3c2410_nand_remove, 704 .remove = s3c2410_nand_remove,
@@ -702,6 +706,7 @@ static struct device_driver s3c2410_nand_driver = {
702 706
703static struct device_driver s3c2440_nand_driver = { 707static struct device_driver s3c2440_nand_driver = {
704 .name = "s3c2440-nand", 708 .name = "s3c2440-nand",
709 .owner = THIS_MODULE,
705 .bus = &platform_bus_type, 710 .bus = &platform_bus_type,
706 .probe = s3c2440_nand_probe, 711 .probe = s3c2440_nand_probe,
707 .remove = s3c2410_nand_remove, 712 .remove = s3c2410_nand_remove,
diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c
index 88b5b5b40b43..1924a4f137c7 100644
--- a/drivers/mtd/nand/sharpsl.c
+++ b/drivers/mtd/nand/sharpsl.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2004 Richard Purdie 4 * Copyright (C) 2004 Richard Purdie
5 * 5 *
6 * $Id: sharpsl.c,v 1.4 2005/01/23 11:09:19 rpurdie Exp $ 6 * $Id: sharpsl.c,v 1.7 2005/11/07 11:14:31 gleixner Exp $
7 * 7 *
8 * Based on Sharp's NAND driver sharp_sl.c 8 * Based on Sharp's NAND driver sharp_sl.c
9 * 9 *
@@ -76,14 +76,14 @@ static struct mtd_partition sharpsl_nand_default_partition_info[] = {
76 }, 76 },
77}; 77};
78 78
79/* 79/*
80 * hardware specific access to control-lines 80 * hardware specific access to control-lines
81 */ 81 */
82static void 82static void
83sharpsl_nand_hwcontrol(struct mtd_info* mtd, int cmd) 83sharpsl_nand_hwcontrol(struct mtd_info* mtd, int cmd)
84{ 84{
85 switch (cmd) { 85 switch (cmd) {
86 case NAND_CTL_SETCLE: 86 case NAND_CTL_SETCLE:
87 writeb(readb(FLASHCTL) | FLCLE, FLASHCTL); 87 writeb(readb(FLASHCTL) | FLCLE, FLASHCTL);
88 break; 88 break;
89 case NAND_CTL_CLRCLE: 89 case NAND_CTL_CLRCLE:
@@ -97,10 +97,10 @@ sharpsl_nand_hwcontrol(struct mtd_info* mtd, int cmd)
97 writeb(readb(FLASHCTL) & ~FLALE, FLASHCTL); 97 writeb(readb(FLASHCTL) & ~FLALE, FLASHCTL);
98 break; 98 break;
99 99
100 case NAND_CTL_SETNCE: 100 case NAND_CTL_SETNCE:
101 writeb(readb(FLASHCTL) & ~(FLCE0|FLCE1), FLASHCTL); 101 writeb(readb(FLASHCTL) & ~(FLCE0|FLCE1), FLASHCTL);
102 break; 102 break;
103 case NAND_CTL_CLRNCE: 103 case NAND_CTL_CLRNCE:
104 writeb(readb(FLASHCTL) | (FLCE0|FLCE1), FLASHCTL); 104 writeb(readb(FLASHCTL) | (FLCE0|FLCE1), FLASHCTL);
105 break; 105 break;
106 } 106 }
@@ -115,6 +115,23 @@ static struct nand_bbt_descr sharpsl_bbt = {
115 .pattern = scan_ff_pattern 115 .pattern = scan_ff_pattern
116}; 116};
117 117
118static struct nand_bbt_descr sharpsl_akita_bbt = {
119 .options = 0,
120 .offs = 4,
121 .len = 1,
122 .pattern = scan_ff_pattern
123};
124
125static struct nand_oobinfo akita_oobinfo = {
126 .useecc = MTD_NANDECC_AUTOPLACE,
127 .eccbytes = 24,
128 .eccpos = {
129 0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11,
130 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23,
131 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37},
132 .oobfree = { {0x08, 0x09} }
133};
134
118static int 135static int
119sharpsl_nand_dev_ready(struct mtd_info* mtd) 136sharpsl_nand_dev_ready(struct mtd_info* mtd)
120{ 137{
@@ -160,7 +177,7 @@ sharpsl_nand_init(void)
160 printk ("Unable to allocate SharpSL NAND MTD device structure.\n"); 177 printk ("Unable to allocate SharpSL NAND MTD device structure.\n");
161 return -ENOMEM; 178 return -ENOMEM;
162 } 179 }
163 180
164 /* map physical adress */ 181 /* map physical adress */
165 sharpsl_io_base = ioremap(sharpsl_phys_base, 0x1000); 182 sharpsl_io_base = ioremap(sharpsl_phys_base, 0x1000);
166 if(!sharpsl_io_base){ 183 if(!sharpsl_io_base){
@@ -168,7 +185,7 @@ sharpsl_nand_init(void)
168 kfree(sharpsl_mtd); 185 kfree(sharpsl_mtd);
169 return -EIO; 186 return -EIO;
170 } 187 }
171 188
172 /* Get pointer to private data */ 189 /* Get pointer to private data */
173 this = (struct nand_chip *) (&sharpsl_mtd[1]); 190 this = (struct nand_chip *) (&sharpsl_mtd[1]);
174 191
@@ -194,10 +211,14 @@ sharpsl_nand_init(void)
194 this->chip_delay = 15; 211 this->chip_delay = 15;
195 /* set eccmode using hardware ECC */ 212 /* set eccmode using hardware ECC */
196 this->eccmode = NAND_ECC_HW3_256; 213 this->eccmode = NAND_ECC_HW3_256;
214 this->badblock_pattern = &sharpsl_bbt;
215 if (machine_is_akita() || machine_is_borzoi()) {
216 this->badblock_pattern = &sharpsl_akita_bbt;
217 this->autooob = &akita_oobinfo;
218 }
197 this->enable_hwecc = sharpsl_nand_enable_hwecc; 219 this->enable_hwecc = sharpsl_nand_enable_hwecc;
198 this->calculate_ecc = sharpsl_nand_calculate_ecc; 220 this->calculate_ecc = sharpsl_nand_calculate_ecc;
199 this->correct_data = nand_correct_data; 221 this->correct_data = nand_correct_data;
200 this->badblock_pattern = &sharpsl_bbt;
201 222
202 /* Scan to find existence of the device */ 223 /* Scan to find existence of the device */
203 err=nand_scan(sharpsl_mtd,1); 224 err=nand_scan(sharpsl_mtd,1);
@@ -211,7 +232,7 @@ sharpsl_nand_init(void)
211 sharpsl_mtd->name = "sharpsl-nand"; 232 sharpsl_mtd->name = "sharpsl-nand";
212 nr_partitions = parse_mtd_partitions(sharpsl_mtd, part_probes, 233 nr_partitions = parse_mtd_partitions(sharpsl_mtd, part_probes,
213 &sharpsl_partition_info, 0); 234 &sharpsl_partition_info, 0);
214 235
215 if (nr_partitions <= 0) { 236 if (nr_partitions <= 0) {
216 nr_partitions = DEFAULT_NUM_PARTITIONS; 237 nr_partitions = DEFAULT_NUM_PARTITIONS;
217 sharpsl_partition_info = sharpsl_nand_default_partition_info; 238 sharpsl_partition_info = sharpsl_nand_default_partition_info;
@@ -230,7 +251,7 @@ sharpsl_nand_init(void)
230 } 251 }
231 } 252 }
232 253
233 if (machine_is_husky() || machine_is_borzoi()) { 254 if (machine_is_husky() || machine_is_borzoi() || machine_is_akita()) {
234 /* Need to use small eraseblock size for backward compatibility */ 255 /* Need to use small eraseblock size for backward compatibility */
235 sharpsl_mtd->flags |= MTD_NO_VIRTBLOCKS; 256 sharpsl_mtd->flags |= MTD_NO_VIRTBLOCKS;
236 } 257 }
diff --git a/drivers/mtd/nand/spia.c b/drivers/mtd/nand/spia.c
index b777c412b758..32541cbb0103 100644
--- a/drivers/mtd/nand/spia.c
+++ b/drivers/mtd/nand/spia.c
@@ -8,7 +8,7 @@
8 * to controllines (due to change in nand.c) 8 * to controllines (due to change in nand.c)
9 * page_cache added 9 * page_cache added
10 * 10 *
11 * $Id: spia.c,v 1.24 2004/11/04 12:53:10 gleixner Exp $ 11 * $Id: spia.c,v 1.25 2005/11/07 11:14:31 gleixner Exp $
12 * 12 *
13 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as 14 * it under the terms of the GNU General Public License version 2 as
@@ -82,7 +82,7 @@ const static struct mtd_partition partition_info[] = {
82#define NUM_PARTITIONS 2 82#define NUM_PARTITIONS 2
83 83
84 84
85/* 85/*
86 * hardware specific access to control-lines 86 * hardware specific access to control-lines
87*/ 87*/
88static void spia_hwcontrol(struct mtd_info *mtd, int cmd){ 88static void spia_hwcontrol(struct mtd_info *mtd, int cmd){
@@ -137,7 +137,7 @@ int __init spia_init (void)
137 /* Set address of hardware control function */ 137 /* Set address of hardware control function */
138 this->hwcontrol = spia_hwcontrol; 138 this->hwcontrol = spia_hwcontrol;
139 /* 15 us command delay time */ 139 /* 15 us command delay time */
140 this->chip_delay = 15; 140 this->chip_delay = 15;
141 141
142 /* Scan to find existence of the device */ 142 /* Scan to find existence of the device */
143 if (nand_scan (spia_mtd, 1)) { 143 if (nand_scan (spia_mtd, 1)) {
diff --git a/drivers/mtd/nand/toto.c b/drivers/mtd/nand/toto.c
index 52c808fb5fa9..7609c43cb3ec 100644
--- a/drivers/mtd/nand/toto.c
+++ b/drivers/mtd/nand/toto.c
@@ -15,7 +15,7 @@
15 * This is a device driver for the NAND flash device found on the 15 * This is a device driver for the NAND flash device found on the
16 * TI fido board. It supports 32MiB and 64MiB cards 16 * TI fido board. It supports 32MiB and 64MiB cards
17 * 17 *
18 * $Id: toto.c,v 1.4 2004/10/05 13:50:20 gleixner Exp $ 18 * $Id: toto.c,v 1.5 2005/11/07 11:14:31 gleixner Exp $
19 */ 19 */
20 20
21#include <linux/slab.h> 21#include <linux/slab.h>
@@ -57,7 +57,7 @@ static unsigned long toto_io_base = OMAP_FLASH_1_BASE;
57#endif 57#endif
58#define T_NAND_CTL_SETNCE(iob) gpiosetout(NAND_NCE, 0) 58#define T_NAND_CTL_SETNCE(iob) gpiosetout(NAND_NCE, 0)
59#define T_NAND_CTL_CLRNCE(iob) gpiosetout(NAND_NCE, NAND_NCE) 59#define T_NAND_CTL_CLRNCE(iob) gpiosetout(NAND_NCE, NAND_NCE)
60 60
61/* 61/*
62 * Define partitions for flash devices 62 * Define partitions for flash devices
63 */ 63 */
@@ -91,7 +91,7 @@ static struct mtd_partition partition_info32M[] = {
91 91
92#define NUM_PARTITIONS32M 3 92#define NUM_PARTITIONS32M 3
93#define NUM_PARTITIONS64M 4 93#define NUM_PARTITIONS64M 4
94/* 94/*
95 * hardware specific access to control-lines 95 * hardware specific access to control-lines
96*/ 96*/
97 97
@@ -146,7 +146,7 @@ int __init toto_init (void)
146 this->hwcontrol = toto_hwcontrol; 146 this->hwcontrol = toto_hwcontrol;
147 this->dev_ready = NULL; 147 this->dev_ready = NULL;
148 /* 25 us command delay time */ 148 /* 25 us command delay time */
149 this->chip_delay = 30; 149 this->chip_delay = 30;
150 this->eccmode = NAND_ECC_SOFT; 150 this->eccmode = NAND_ECC_SOFT;
151 151
152 /* Scan to find existance of the device */ 152 /* Scan to find existance of the device */
@@ -157,10 +157,10 @@ int __init toto_init (void)
157 157
158 /* Register the partitions */ 158 /* Register the partitions */
159 switch(toto_mtd->size){ 159 switch(toto_mtd->size){
160 case SZ_64M: add_mtd_partitions(toto_mtd, partition_info64M, NUM_PARTITIONS64M); break; 160 case SZ_64M: add_mtd_partitions(toto_mtd, partition_info64M, NUM_PARTITIONS64M); break;
161 case SZ_32M: add_mtd_partitions(toto_mtd, partition_info32M, NUM_PARTITIONS32M); break; 161 case SZ_32M: add_mtd_partitions(toto_mtd, partition_info32M, NUM_PARTITIONS32M); break;
162 default: { 162 default: {
163 printk (KERN_WARNING "Unsupported Nand device\n"); 163 printk (KERN_WARNING "Unsupported Nand device\n");
164 err = -ENXIO; 164 err = -ENXIO;
165 goto out_buf; 165 goto out_buf;
166 } 166 }
@@ -170,9 +170,9 @@ int __init toto_init (void)
170 archflashwp(0,0); /* open up flash for writing */ 170 archflashwp(0,0); /* open up flash for writing */
171 171
172 goto out; 172 goto out;
173 173
174out_buf: 174out_buf:
175 kfree (this->data_buf); 175 kfree (this->data_buf);
176out_mtd: 176out_mtd:
177 kfree (toto_mtd); 177 kfree (toto_mtd);
178out: 178out:
@@ -194,7 +194,7 @@ static void __exit toto_cleanup (void)
194 194
195 /* stop flash writes */ 195 /* stop flash writes */
196 archflashwp(0,1); 196 archflashwp(0,1);
197 197
198 /* release gpios to system */ 198 /* release gpios to system */
199 gpiorelease(NAND_MASK); 199 gpiorelease(NAND_MASK);
200} 200}
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index b2014043634f..d7cd5fa16ba4 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -1,7 +1,7 @@
1/* Linux driver for NAND Flash Translation Layer */ 1/* Linux driver for NAND Flash Translation Layer */
2/* (c) 1999 Machine Vision Holdings, Inc. */ 2/* (c) 1999 Machine Vision Holdings, Inc. */
3/* Author: David Woodhouse <dwmw2@infradead.org> */ 3/* Author: David Woodhouse <dwmw2@infradead.org> */
4/* $Id: nftlcore.c,v 1.97 2004/11/16 18:28:59 dwmw2 Exp $ */ 4/* $Id: nftlcore.c,v 1.98 2005/11/07 11:14:21 gleixner Exp $ */
5 5
6/* 6/*
7 The contents of this file are distributed under the GNU General 7 The contents of this file are distributed under the GNU General
@@ -101,23 +101,21 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
101 101
102 if (nftl->mbd.size != nftl->heads * nftl->cylinders * nftl->sectors) { 102 if (nftl->mbd.size != nftl->heads * nftl->cylinders * nftl->sectors) {
103 /* 103 /*
104 Oh no we don't have 104 Oh no we don't have
105 mbd.size == heads * cylinders * sectors 105 mbd.size == heads * cylinders * sectors
106 */ 106 */
107 printk(KERN_WARNING "NFTL: cannot calculate a geometry to " 107 printk(KERN_WARNING "NFTL: cannot calculate a geometry to "
108 "match size of 0x%lx.\n", nftl->mbd.size); 108 "match size of 0x%lx.\n", nftl->mbd.size);
109 printk(KERN_WARNING "NFTL: using C:%d H:%d S:%d " 109 printk(KERN_WARNING "NFTL: using C:%d H:%d S:%d "
110 "(== 0x%lx sects)\n", 110 "(== 0x%lx sects)\n",
111 nftl->cylinders, nftl->heads , nftl->sectors, 111 nftl->cylinders, nftl->heads , nftl->sectors,
112 (long)nftl->cylinders * (long)nftl->heads * 112 (long)nftl->cylinders * (long)nftl->heads *
113 (long)nftl->sectors ); 113 (long)nftl->sectors );
114 } 114 }
115 115
116 if (add_mtd_blktrans_dev(&nftl->mbd)) { 116 if (add_mtd_blktrans_dev(&nftl->mbd)) {
117 if (nftl->ReplUnitTable) 117 kfree(nftl->ReplUnitTable);
118 kfree(nftl->ReplUnitTable); 118 kfree(nftl->EUNtable);
119 if (nftl->EUNtable)
120 kfree(nftl->EUNtable);
121 kfree(nftl); 119 kfree(nftl);
122 return; 120 return;
123 } 121 }
@@ -133,10 +131,8 @@ static void nftl_remove_dev(struct mtd_blktrans_dev *dev)
133 DEBUG(MTD_DEBUG_LEVEL1, "NFTL: remove_dev (i=%d)\n", dev->devnum); 131 DEBUG(MTD_DEBUG_LEVEL1, "NFTL: remove_dev (i=%d)\n", dev->devnum);
134 132
135 del_mtd_blktrans_dev(dev); 133 del_mtd_blktrans_dev(dev);
136 if (nftl->ReplUnitTable) 134 kfree(nftl->ReplUnitTable);
137 kfree(nftl->ReplUnitTable); 135 kfree(nftl->EUNtable);
138 if (nftl->EUNtable)
139 kfree(nftl->EUNtable);
140 kfree(nftl); 136 kfree(nftl);
141} 137}
142 138
@@ -178,7 +174,7 @@ static u16 NFTL_findfreeblock(struct NFTLrecord *nftl, int desperate )
178 174
179 if (!silly--) { 175 if (!silly--) {
180 printk("Argh! No free blocks found! LastFreeEUN = %d, " 176 printk("Argh! No free blocks found! LastFreeEUN = %d, "
181 "FirstEUN = %d\n", nftl->LastFreeEUN, 177 "FirstEUN = %d\n", nftl->LastFreeEUN,
182 le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN)); 178 le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN));
183 return 0xffff; 179 return 0xffff;
184 } 180 }
@@ -210,7 +206,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
210 "Virtual Unit Chain %d!\n", thisVUC); 206 "Virtual Unit Chain %d!\n", thisVUC);
211 return BLOCK_NIL; 207 return BLOCK_NIL;
212 } 208 }
213 209
214 /* Scan to find the Erase Unit which holds the actual data for each 210 /* Scan to find the Erase Unit which holds the actual data for each
215 512-byte block within the Chain. 211 512-byte block within the Chain.
216 */ 212 */
@@ -227,7 +223,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
227 if (block == 2) { 223 if (block == 2) {
228 foldmark = oob.u.c.FoldMark | oob.u.c.FoldMark1; 224 foldmark = oob.u.c.FoldMark | oob.u.c.FoldMark1;
229 if (foldmark == FOLD_MARK_IN_PROGRESS) { 225 if (foldmark == FOLD_MARK_IN_PROGRESS) {
230 DEBUG(MTD_DEBUG_LEVEL1, 226 DEBUG(MTD_DEBUG_LEVEL1,
231 "Write Inhibited on EUN %d\n", thisEUN); 227 "Write Inhibited on EUN %d\n", thisEUN);
232 inplace = 0; 228 inplace = 0;
233 } else { 229 } else {
@@ -249,7 +245,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
249 if (!BlockFreeFound[block]) 245 if (!BlockFreeFound[block])
250 BlockMap[block] = thisEUN; 246 BlockMap[block] = thisEUN;
251 else 247 else
252 printk(KERN_WARNING 248 printk(KERN_WARNING
253 "SECTOR_USED found after SECTOR_FREE " 249 "SECTOR_USED found after SECTOR_FREE "
254 "in Virtual Unit Chain %d for block %d\n", 250 "in Virtual Unit Chain %d for block %d\n",
255 thisVUC, block); 251 thisVUC, block);
@@ -258,7 +254,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
258 if (!BlockFreeFound[block]) 254 if (!BlockFreeFound[block])
259 BlockMap[block] = BLOCK_NIL; 255 BlockMap[block] = BLOCK_NIL;
260 else 256 else
261 printk(KERN_WARNING 257 printk(KERN_WARNING
262 "SECTOR_DELETED found after SECTOR_FREE " 258 "SECTOR_DELETED found after SECTOR_FREE "
263 "in Virtual Unit Chain %d for block %d\n", 259 "in Virtual Unit Chain %d for block %d\n",
264 thisVUC, block); 260 thisVUC, block);
@@ -277,14 +273,14 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
277 thisVUC); 273 thisVUC);
278 return BLOCK_NIL; 274 return BLOCK_NIL;
279 } 275 }
280 276
281 thisEUN = nftl->ReplUnitTable[thisEUN]; 277 thisEUN = nftl->ReplUnitTable[thisEUN];
282 } 278 }
283 279
284 if (inplace) { 280 if (inplace) {
285 /* We're being asked to be a fold-in-place. Check 281 /* We're being asked to be a fold-in-place. Check
286 that all blocks which actually have data associated 282 that all blocks which actually have data associated
287 with them (i.e. BlockMap[block] != BLOCK_NIL) are 283 with them (i.e. BlockMap[block] != BLOCK_NIL) are
288 either already present or SECTOR_FREE in the target 284 either already present or SECTOR_FREE in the target
289 block. If not, we're going to have to fold out-of-place 285 block. If not, we're going to have to fold out-of-place
290 anyway. 286 anyway.
@@ -297,7 +293,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
297 "block %d was %x lastEUN, " 293 "block %d was %x lastEUN, "
298 "and is in EUN %d (%s) %d\n", 294 "and is in EUN %d (%s) %d\n",
299 thisVUC, block, BlockLastState[block], 295 thisVUC, block, BlockLastState[block],
300 BlockMap[block], 296 BlockMap[block],
301 BlockMap[block]== targetEUN ? "==" : "!=", 297 BlockMap[block]== targetEUN ? "==" : "!=",
302 targetEUN); 298 targetEUN);
303 inplace = 0; 299 inplace = 0;
@@ -314,17 +310,17 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
314 inplace = 0; 310 inplace = 0;
315 } 311 }
316 } 312 }
317 313
318 if (!inplace) { 314 if (!inplace) {
319 DEBUG(MTD_DEBUG_LEVEL1, "Cannot fold Virtual Unit Chain %d in place. " 315 DEBUG(MTD_DEBUG_LEVEL1, "Cannot fold Virtual Unit Chain %d in place. "
320 "Trying out-of-place\n", thisVUC); 316 "Trying out-of-place\n", thisVUC);
321 /* We need to find a targetEUN to fold into. */ 317 /* We need to find a targetEUN to fold into. */
322 targetEUN = NFTL_findfreeblock(nftl, 1); 318 targetEUN = NFTL_findfreeblock(nftl, 1);
323 if (targetEUN == BLOCK_NIL) { 319 if (targetEUN == BLOCK_NIL) {
324 /* Ouch. Now we're screwed. We need to do a 320 /* Ouch. Now we're screwed. We need to do a
325 fold-in-place of another chain to make room 321 fold-in-place of another chain to make room
326 for this one. We need a better way of selecting 322 for this one. We need a better way of selecting
327 which chain to fold, because makefreeblock will 323 which chain to fold, because makefreeblock will
328 only ask us to fold the same one again. 324 only ask us to fold the same one again.
329 */ 325 */
330 printk(KERN_WARNING 326 printk(KERN_WARNING
@@ -338,7 +334,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
338 chain by selecting the longer one */ 334 chain by selecting the longer one */
339 oob.u.c.FoldMark = oob.u.c.FoldMark1 = cpu_to_le16(FOLD_MARK_IN_PROGRESS); 335 oob.u.c.FoldMark = oob.u.c.FoldMark1 = cpu_to_le16(FOLD_MARK_IN_PROGRESS);
340 oob.u.c.unused = 0xffffffff; 336 oob.u.c.unused = 0xffffffff;
341 MTD_WRITEOOB(nftl->mbd.mtd, (nftl->EraseSize * targetEUN) + 2 * 512 + 8, 337 MTD_WRITEOOB(nftl->mbd.mtd, (nftl->EraseSize * targetEUN) + 2 * 512 + 8,
342 8, &retlen, (char *)&oob.u); 338 8, &retlen, (char *)&oob.u);
343 } 339 }
344 340
@@ -361,14 +357,14 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
361 happen in case of media errors or deleted blocks) */ 357 happen in case of media errors or deleted blocks) */
362 if (BlockMap[block] == BLOCK_NIL) 358 if (BlockMap[block] == BLOCK_NIL)
363 continue; 359 continue;
364 360
365 ret = MTD_READ(nftl->mbd.mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512), 361 ret = MTD_READ(nftl->mbd.mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512),
366 512, &retlen, movebuf); 362 512, &retlen, movebuf);
367 if (ret < 0) { 363 if (ret < 0) {
368 ret = MTD_READ(nftl->mbd.mtd, (nftl->EraseSize * BlockMap[block]) 364 ret = MTD_READ(nftl->mbd.mtd, (nftl->EraseSize * BlockMap[block])
369 + (block * 512), 512, &retlen, 365 + (block * 512), 512, &retlen,
370 movebuf); 366 movebuf);
371 if (ret != -EIO) 367 if (ret != -EIO)
372 printk("Error went away on retry.\n"); 368 printk("Error went away on retry.\n");
373 } 369 }
374 memset(&oob, 0xff, sizeof(struct nftl_oob)); 370 memset(&oob, 0xff, sizeof(struct nftl_oob));
@@ -376,18 +372,18 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
376 MTD_WRITEECC(nftl->mbd.mtd, (nftl->EraseSize * targetEUN) + (block * 512), 372 MTD_WRITEECC(nftl->mbd.mtd, (nftl->EraseSize * targetEUN) + (block * 512),
377 512, &retlen, movebuf, (char *)&oob, &nftl->oobinfo); 373 512, &retlen, movebuf, (char *)&oob, &nftl->oobinfo);
378 } 374 }
379 375
380 /* add the header so that it is now a valid chain */ 376 /* add the header so that it is now a valid chain */
381 oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum 377 oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum
382 = cpu_to_le16(thisVUC); 378 = cpu_to_le16(thisVUC);
383 oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum = 0xffff; 379 oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum = 0xffff;
384 380
385 MTD_WRITEOOB(nftl->mbd.mtd, (nftl->EraseSize * targetEUN) + 8, 381 MTD_WRITEOOB(nftl->mbd.mtd, (nftl->EraseSize * targetEUN) + 8,
386 8, &retlen, (char *)&oob.u); 382 8, &retlen, (char *)&oob.u);
387 383
388 /* OK. We've moved the whole lot into the new block. Now we have to free the original blocks. */ 384 /* OK. We've moved the whole lot into the new block. Now we have to free the original blocks. */
389 385
390 /* At this point, we have two different chains for this Virtual Unit, and no way to tell 386 /* At this point, we have two different chains for this Virtual Unit, and no way to tell
391 them apart. If we crash now, we get confused. However, both contain the same data, so we 387 them apart. If we crash now, we get confused. However, both contain the same data, so we
392 shouldn't actually lose data in this case. It's just that when we load up on a medium which 388 shouldn't actually lose data in this case. It's just that when we load up on a medium which
393 has duplicate chains, we need to free one of the chains because it's not necessary any more. 389 has duplicate chains, we need to free one of the chains because it's not necessary any more.
@@ -395,7 +391,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
395 thisEUN = nftl->EUNtable[thisVUC]; 391 thisEUN = nftl->EUNtable[thisVUC];
396 DEBUG(MTD_DEBUG_LEVEL1,"Want to erase\n"); 392 DEBUG(MTD_DEBUG_LEVEL1,"Want to erase\n");
397 393
398 /* For each block in the old chain (except the targetEUN of course), 394 /* For each block in the old chain (except the targetEUN of course),
399 free it and make it available for future use */ 395 free it and make it available for future use */
400 while (thisEUN <= nftl->lastEUN && thisEUN != targetEUN) { 396 while (thisEUN <= nftl->lastEUN && thisEUN != targetEUN) {
401 unsigned int EUNtmp; 397 unsigned int EUNtmp;
@@ -413,7 +409,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
413 } 409 }
414 thisEUN = EUNtmp; 410 thisEUN = EUNtmp;
415 } 411 }
416 412
417 /* Make this the new start of chain for thisVUC */ 413 /* Make this the new start of chain for thisVUC */
418 nftl->ReplUnitTable[targetEUN] = BLOCK_NIL; 414 nftl->ReplUnitTable[targetEUN] = BLOCK_NIL;
419 nftl->EUNtable[thisVUC] = targetEUN; 415 nftl->EUNtable[thisVUC] = targetEUN;
@@ -423,7 +419,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
423 419
424static u16 NFTL_makefreeblock( struct NFTLrecord *nftl , unsigned pendingblock) 420static u16 NFTL_makefreeblock( struct NFTLrecord *nftl , unsigned pendingblock)
425{ 421{
426 /* This is the part that needs some cleverness applied. 422 /* This is the part that needs some cleverness applied.
427 For now, I'm doing the minimum applicable to actually 423 For now, I'm doing the minimum applicable to actually
428 get the thing to work. 424 get the thing to work.
429 Wear-levelling and other clever stuff needs to be implemented 425 Wear-levelling and other clever stuff needs to be implemented
@@ -470,7 +466,7 @@ static u16 NFTL_makefreeblock( struct NFTLrecord *nftl , unsigned pendingblock)
470 return NFTL_foldchain (nftl, LongestChain, pendingblock); 466 return NFTL_foldchain (nftl, LongestChain, pendingblock);
471} 467}
472 468
473/* NFTL_findwriteunit: Return the unit number into which we can write 469/* NFTL_findwriteunit: Return the unit number into which we can write
474 for this block. Make it available if it isn't already 470 for this block. Make it available if it isn't already
475*/ 471*/
476static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block) 472static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
@@ -488,7 +484,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
488 a free space for the block in question. 484 a free space for the block in question.
489 */ 485 */
490 486
491 /* This condition catches the 0x[7f]fff cases, as well as 487 /* This condition catches the 0x[7f]fff cases, as well as
492 being a sanity check for past-end-of-media access 488 being a sanity check for past-end-of-media access
493 */ 489 */
494 lastEUN = BLOCK_NIL; 490 lastEUN = BLOCK_NIL;
@@ -503,7 +499,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
503 499
504 MTD_READOOB(nftl->mbd.mtd, (writeEUN * nftl->EraseSize) + blockofs, 500 MTD_READOOB(nftl->mbd.mtd, (writeEUN * nftl->EraseSize) + blockofs,
505 8, &retlen, (char *)&bci); 501 8, &retlen, (char *)&bci);
506 502
507 DEBUG(MTD_DEBUG_LEVEL2, "Status of block %d in EUN %d is %x\n", 503 DEBUG(MTD_DEBUG_LEVEL2, "Status of block %d in EUN %d is %x\n",
508 block , writeEUN, le16_to_cpu(bci.Status)); 504 block , writeEUN, le16_to_cpu(bci.Status));
509 505
@@ -518,10 +514,10 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
518 break; 514 break;
519 default: 515 default:
520 // Invalid block. Don't use it any more. Must implement. 516 // Invalid block. Don't use it any more. Must implement.
521 break; 517 break;
522 } 518 }
523 519
524 if (!silly--) { 520 if (!silly--) {
525 printk(KERN_WARNING 521 printk(KERN_WARNING
526 "Infinite loop in Virtual Unit Chain 0x%x\n", 522 "Infinite loop in Virtual Unit Chain 0x%x\n",
527 thisVUC); 523 thisVUC);
@@ -532,7 +528,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
532 writeEUN = nftl->ReplUnitTable[writeEUN]; 528 writeEUN = nftl->ReplUnitTable[writeEUN];
533 } 529 }
534 530
535 /* OK. We didn't find one in the existing chain, or there 531 /* OK. We didn't find one in the existing chain, or there
536 is no existing chain. */ 532 is no existing chain. */
537 533
538 /* Try to find an already-free block */ 534 /* Try to find an already-free block */
@@ -546,12 +542,12 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
546 542
547 /* First remember the start of this chain */ 543 /* First remember the start of this chain */
548 //u16 startEUN = nftl->EUNtable[thisVUC]; 544 //u16 startEUN = nftl->EUNtable[thisVUC];
549 545
550 //printk("Write to VirtualUnitChain %d, calling makefreeblock()\n", thisVUC); 546 //printk("Write to VirtualUnitChain %d, calling makefreeblock()\n", thisVUC);
551 writeEUN = NFTL_makefreeblock(nftl, 0xffff); 547 writeEUN = NFTL_makefreeblock(nftl, 0xffff);
552 548
553 if (writeEUN == BLOCK_NIL) { 549 if (writeEUN == BLOCK_NIL) {
554 /* OK, we accept that the above comment is 550 /* OK, we accept that the above comment is
555 lying - there may have been free blocks 551 lying - there may have been free blocks
556 last time we called NFTL_findfreeblock(), 552 last time we called NFTL_findfreeblock(),
557 but they are reserved for when we're 553 but they are reserved for when we're
@@ -562,21 +558,21 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
562 } 558 }
563 if (writeEUN == BLOCK_NIL) { 559 if (writeEUN == BLOCK_NIL) {
564 /* Ouch. This should never happen - we should 560 /* Ouch. This should never happen - we should
565 always be able to make some room somehow. 561 always be able to make some room somehow.
566 If we get here, we've allocated more storage 562 If we get here, we've allocated more storage
567 space than actual media, or our makefreeblock 563 space than actual media, or our makefreeblock
568 routine is missing something. 564 routine is missing something.
569 */ 565 */
570 printk(KERN_WARNING "Cannot make free space.\n"); 566 printk(KERN_WARNING "Cannot make free space.\n");
571 return BLOCK_NIL; 567 return BLOCK_NIL;
572 } 568 }
573 //printk("Restarting scan\n"); 569 //printk("Restarting scan\n");
574 lastEUN = BLOCK_NIL; 570 lastEUN = BLOCK_NIL;
575 continue; 571 continue;
576 } 572 }
577 573
578 /* We've found a free block. Insert it into the chain. */ 574 /* We've found a free block. Insert it into the chain. */
579 575
580 if (lastEUN != BLOCK_NIL) { 576 if (lastEUN != BLOCK_NIL) {
581 thisVUC |= 0x8000; /* It's a replacement block */ 577 thisVUC |= 0x8000; /* It's a replacement block */
582 } else { 578 } else {
@@ -749,7 +745,7 @@ extern char nftlmountrev[];
749 745
750static int __init init_nftl(void) 746static int __init init_nftl(void)
751{ 747{
752 printk(KERN_INFO "NFTL driver: nftlcore.c $Revision: 1.97 $, nftlmount.c %s\n", nftlmountrev); 748 printk(KERN_INFO "NFTL driver: nftlcore.c $Revision: 1.98 $, nftlmount.c %s\n", nftlmountrev);
753 749
754 return register_mtd_blktrans(&nftl_tr); 750 return register_mtd_blktrans(&nftl_tr);
755} 751}
diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
index 84afd9029f53..3b104ebb219a 100644
--- a/drivers/mtd/nftlmount.c
+++ b/drivers/mtd/nftlmount.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * NFTL mount code with extensive checks 2 * NFTL mount code with extensive checks
3 * 3 *
4 * Author: Fabrice Bellard (fabrice.bellard@netgem.com) 4 * Author: Fabrice Bellard (fabrice.bellard@netgem.com)
5 * Copyright (C) 2000 Netgem S.A. 5 * Copyright (C) 2000 Netgem S.A.
6 * 6 *
7 * $Id: nftlmount.c,v 1.40 2004/11/22 14:38:29 kalev Exp $ 7 * $Id: nftlmount.c,v 1.41 2005/11/07 11:14:21 gleixner Exp $
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@
31 31
32#define SECTORSIZE 512 32#define SECTORSIZE 512
33 33
34char nftlmountrev[]="$Revision: 1.40 $"; 34char nftlmountrev[]="$Revision: 1.41 $";
35 35
36/* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the 36/* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the
37 * various device information of the NFTL partition and Bad Unit Table. Update 37 * various device information of the NFTL partition and Bad Unit Table. Update
@@ -47,7 +47,7 @@ static int find_boot_record(struct NFTLrecord *nftl)
47 struct NFTLMediaHeader *mh = &nftl->MediaHdr; 47 struct NFTLMediaHeader *mh = &nftl->MediaHdr;
48 unsigned int i; 48 unsigned int i;
49 49
50 /* Assume logical EraseSize == physical erasesize for starting the scan. 50 /* Assume logical EraseSize == physical erasesize for starting the scan.
51 We'll sort it out later if we find a MediaHeader which says otherwise */ 51 We'll sort it out later if we find a MediaHeader which says otherwise */
52 /* Actually, we won't. The new DiskOnChip driver has already scanned 52 /* Actually, we won't. The new DiskOnChip driver has already scanned
53 the MediaHeader and adjusted the virtual erasesize it presents in 53 the MediaHeader and adjusted the virtual erasesize it presents in
@@ -83,9 +83,9 @@ static int find_boot_record(struct NFTLrecord *nftl)
83 if (retlen < 6 || memcmp(buf, "ANAND", 6)) { 83 if (retlen < 6 || memcmp(buf, "ANAND", 6)) {
84 /* ANAND\0 not found. Continue */ 84 /* ANAND\0 not found. Continue */
85#if 0 85#if 0
86 printk(KERN_DEBUG "ANAND header not found at 0x%x in mtd%d\n", 86 printk(KERN_DEBUG "ANAND header not found at 0x%x in mtd%d\n",
87 block * nftl->EraseSize, nftl->mbd.mtd->index); 87 block * nftl->EraseSize, nftl->mbd.mtd->index);
88#endif 88#endif
89 continue; 89 continue;
90 } 90 }
91 91
@@ -103,7 +103,7 @@ static int find_boot_record(struct NFTLrecord *nftl)
103 */ 103 */
104 if (le16_to_cpu(h1.EraseMark | h1.EraseMark1) != ERASE_MARK) { 104 if (le16_to_cpu(h1.EraseMark | h1.EraseMark1) != ERASE_MARK) {
105 printk(KERN_NOTICE "ANAND header found at 0x%x in mtd%d, but erase mark not present (0x%04x,0x%04x instead)\n", 105 printk(KERN_NOTICE "ANAND header found at 0x%x in mtd%d, but erase mark not present (0x%04x,0x%04x instead)\n",
106 block * nftl->EraseSize, nftl->mbd.mtd->index, 106 block * nftl->EraseSize, nftl->mbd.mtd->index,
107 le16_to_cpu(h1.EraseMark), le16_to_cpu(h1.EraseMark1)); 107 le16_to_cpu(h1.EraseMark), le16_to_cpu(h1.EraseMark1));
108 continue; 108 continue;
109 } 109 }
@@ -175,7 +175,7 @@ device is already correct.
175 nftl->nb_boot_blocks = le16_to_cpu(mh->FirstPhysicalEUN); 175 nftl->nb_boot_blocks = le16_to_cpu(mh->FirstPhysicalEUN);
176 if ((nftl->nb_boot_blocks + 2) >= nftl->nb_blocks) { 176 if ((nftl->nb_boot_blocks + 2) >= nftl->nb_blocks) {
177 printk(KERN_NOTICE "NFTL Media Header sanity check failed:\n"); 177 printk(KERN_NOTICE "NFTL Media Header sanity check failed:\n");
178 printk(KERN_NOTICE "nb_boot_blocks (%d) + 2 > nb_blocks (%d)\n", 178 printk(KERN_NOTICE "nb_boot_blocks (%d) + 2 > nb_blocks (%d)\n",
179 nftl->nb_boot_blocks, nftl->nb_blocks); 179 nftl->nb_boot_blocks, nftl->nb_blocks);
180 return -1; 180 return -1;
181 } 181 }
@@ -187,7 +187,7 @@ device is already correct.
187 nftl->numvunits, nftl->nb_blocks, nftl->nb_boot_blocks); 187 nftl->numvunits, nftl->nb_blocks, nftl->nb_boot_blocks);
188 return -1; 188 return -1;
189 } 189 }
190 190
191 nftl->mbd.size = nftl->numvunits * (nftl->EraseSize / SECTORSIZE); 191 nftl->mbd.size = nftl->numvunits * (nftl->EraseSize / SECTORSIZE);
192 192
193 /* If we're not using the last sectors in the device for some reason, 193 /* If we're not using the last sectors in the device for some reason,
@@ -210,12 +210,12 @@ device is already correct.
210 printk(KERN_NOTICE "NFTL: allocation of ReplUnitTable failed\n"); 210 printk(KERN_NOTICE "NFTL: allocation of ReplUnitTable failed\n");
211 return -ENOMEM; 211 return -ENOMEM;
212 } 212 }
213 213
214 /* mark the bios blocks (blocks before NFTL MediaHeader) as reserved */ 214 /* mark the bios blocks (blocks before NFTL MediaHeader) as reserved */
215 for (i = 0; i < nftl->nb_boot_blocks; i++) 215 for (i = 0; i < nftl->nb_boot_blocks; i++)
216 nftl->ReplUnitTable[i] = BLOCK_RESERVED; 216 nftl->ReplUnitTable[i] = BLOCK_RESERVED;
217 /* mark all remaining blocks as potentially containing data */ 217 /* mark all remaining blocks as potentially containing data */
218 for (; i < nftl->nb_blocks; i++) { 218 for (; i < nftl->nb_blocks; i++) {
219 nftl->ReplUnitTable[i] = BLOCK_NOTEXPLORED; 219 nftl->ReplUnitTable[i] = BLOCK_NOTEXPLORED;
220 } 220 }
221 221
@@ -245,12 +245,12 @@ The new DiskOnChip driver already scanned the bad block table. Just query it.
245 if (nftl->mbd.mtd->block_isbad(nftl->mbd.mtd, i * nftl->EraseSize)) 245 if (nftl->mbd.mtd->block_isbad(nftl->mbd.mtd, i * nftl->EraseSize))
246 nftl->ReplUnitTable[i] = BLOCK_RESERVED; 246 nftl->ReplUnitTable[i] = BLOCK_RESERVED;
247 } 247 }
248 248
249 nftl->MediaUnit = block; 249 nftl->MediaUnit = block;
250 boot_record_count++; 250 boot_record_count++;
251 251
252 } /* foreach (block) */ 252 } /* foreach (block) */
253 253
254 return boot_record_count?0:-1; 254 return boot_record_count?0:-1;
255} 255}
256 256
@@ -265,7 +265,7 @@ static int memcmpb(void *a, int c, int n)
265} 265}
266 266
267/* check_free_sector: check if a free sector is actually FREE, i.e. All 0xff in data and oob area */ 267/* check_free_sector: check if a free sector is actually FREE, i.e. All 0xff in data and oob area */
268static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int len, 268static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int len,
269 int check_oob) 269 int check_oob)
270{ 270{
271 int i; 271 int i;
@@ -293,7 +293,7 @@ static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int
293 * 293 *
294 * Return: 0 when succeed, -1 on error. 294 * Return: 0 when succeed, -1 on error.
295 * 295 *
296 * ToDo: 1. Is it neceressary to check_free_sector after erasing ?? 296 * ToDo: 1. Is it neceressary to check_free_sector after erasing ??
297 */ 297 */
298int NFTL_formatblock(struct NFTLrecord *nftl, int block) 298int NFTL_formatblock(struct NFTLrecord *nftl, int block)
299{ 299{
@@ -385,7 +385,7 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b
385 /* verify that the sector is really free. If not, mark 385 /* verify that the sector is really free. If not, mark
386 as ignore */ 386 as ignore */
387 if (memcmpb(&bci, 0xff, 8) != 0 || 387 if (memcmpb(&bci, 0xff, 8) != 0 ||
388 check_free_sectors(nftl, block * nftl->EraseSize + i * SECTORSIZE, 388 check_free_sectors(nftl, block * nftl->EraseSize + i * SECTORSIZE,
389 SECTORSIZE, 0) != 0) { 389 SECTORSIZE, 0) != 0) {
390 printk("Incorrect free sector %d in block %d: " 390 printk("Incorrect free sector %d in block %d: "
391 "marking it as ignored\n", 391 "marking it as ignored\n",
@@ -486,7 +486,7 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
486 size_t retlen; 486 size_t retlen;
487 487
488 /* check erase mark. */ 488 /* check erase mark. */
489 if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, 489 if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8,
490 &retlen, (char *)&h1) < 0) 490 &retlen, (char *)&h1) < 0)
491 return -1; 491 return -1;
492 492
@@ -501,7 +501,7 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
501 h1.EraseMark = cpu_to_le16(ERASE_MARK); 501 h1.EraseMark = cpu_to_le16(ERASE_MARK);
502 h1.EraseMark1 = cpu_to_le16(ERASE_MARK); 502 h1.EraseMark1 = cpu_to_le16(ERASE_MARK);
503 h1.WearInfo = cpu_to_le32(0); 503 h1.WearInfo = cpu_to_le32(0);
504 if (MTD_WRITEOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, 504 if (MTD_WRITEOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8,
505 &retlen, (char *)&h1) < 0) 505 &retlen, (char *)&h1) < 0)
506 return -1; 506 return -1;
507 } else { 507 } else {
@@ -582,9 +582,9 @@ int NFTL_mount(struct NFTLrecord *s)
582 582
583 for (;;) { 583 for (;;) {
584 /* read the block header. If error, we format the chain */ 584 /* read the block header. If error, we format the chain */
585 if (MTD_READOOB(s->mbd.mtd, block * s->EraseSize + 8, 8, 585 if (MTD_READOOB(s->mbd.mtd, block * s->EraseSize + 8, 8,
586 &retlen, (char *)&h0) < 0 || 586 &retlen, (char *)&h0) < 0 ||
587 MTD_READOOB(s->mbd.mtd, block * s->EraseSize + SECTORSIZE + 8, 8, 587 MTD_READOOB(s->mbd.mtd, block * s->EraseSize + SECTORSIZE + 8, 8,
588 &retlen, (char *)&h1) < 0) { 588 &retlen, (char *)&h1) < 0) {
589 s->ReplUnitTable[block] = BLOCK_NIL; 589 s->ReplUnitTable[block] = BLOCK_NIL;
590 do_format_chain = 1; 590 do_format_chain = 1;
@@ -639,7 +639,7 @@ int NFTL_mount(struct NFTLrecord *s)
639 first_logical_block = logical_block; 639 first_logical_block = logical_block;
640 } else { 640 } else {
641 if (logical_block != first_logical_block) { 641 if (logical_block != first_logical_block) {
642 printk("Block %d: incorrect logical block: %d expected: %d\n", 642 printk("Block %d: incorrect logical block: %d expected: %d\n",
643 block, logical_block, first_logical_block); 643 block, logical_block, first_logical_block);
644 /* the chain is incorrect : we must format it, 644 /* the chain is incorrect : we must format it,
645 but we need to read it completly */ 645 but we need to read it completly */
@@ -668,7 +668,7 @@ int NFTL_mount(struct NFTLrecord *s)
668 s->ReplUnitTable[block] = BLOCK_NIL; 668 s->ReplUnitTable[block] = BLOCK_NIL;
669 break; 669 break;
670 } else if (rep_block >= s->nb_blocks) { 670 } else if (rep_block >= s->nb_blocks) {
671 printk("Block %d: referencing invalid block %d\n", 671 printk("Block %d: referencing invalid block %d\n",
672 block, rep_block); 672 block, rep_block);
673 do_format_chain = 1; 673 do_format_chain = 1;
674 s->ReplUnitTable[block] = BLOCK_NIL; 674 s->ReplUnitTable[block] = BLOCK_NIL;
@@ -688,7 +688,7 @@ int NFTL_mount(struct NFTLrecord *s)
688 s->ReplUnitTable[block] = rep_block; 688 s->ReplUnitTable[block] = rep_block;
689 s->EUNtable[first_logical_block] = BLOCK_NIL; 689 s->EUNtable[first_logical_block] = BLOCK_NIL;
690 } else { 690 } else {
691 printk("Block %d: referencing block %d already in another chain\n", 691 printk("Block %d: referencing block %d already in another chain\n",
692 block, rep_block); 692 block, rep_block);
693 /* XXX: should handle correctly fold in progress chains */ 693 /* XXX: should handle correctly fold in progress chains */
694 do_format_chain = 1; 694 do_format_chain = 1;
@@ -710,7 +710,7 @@ int NFTL_mount(struct NFTLrecord *s)
710 } else { 710 } else {
711 unsigned int first_block1, chain_to_format, chain_length1; 711 unsigned int first_block1, chain_to_format, chain_length1;
712 int fold_mark; 712 int fold_mark;
713 713
714 /* valid chain : get foldmark */ 714 /* valid chain : get foldmark */
715 fold_mark = get_fold_mark(s, first_block); 715 fold_mark = get_fold_mark(s, first_block);
716 if (fold_mark == 0) { 716 if (fold_mark == 0) {
@@ -729,9 +729,9 @@ int NFTL_mount(struct NFTLrecord *s)
729 if (first_block1 != BLOCK_NIL) { 729 if (first_block1 != BLOCK_NIL) {
730 /* XXX: what to do if same length ? */ 730 /* XXX: what to do if same length ? */
731 chain_length1 = calc_chain_length(s, first_block1); 731 chain_length1 = calc_chain_length(s, first_block1);
732 printk("Two chains at blocks %d (len=%d) and %d (len=%d)\n", 732 printk("Two chains at blocks %d (len=%d) and %d (len=%d)\n",
733 first_block1, chain_length1, first_block, chain_length); 733 first_block1, chain_length1, first_block, chain_length);
734 734
735 if (chain_length >= chain_length1) { 735 if (chain_length >= chain_length1) {
736 chain_to_format = first_block1; 736 chain_to_format = first_block1;
737 s->EUNtable[first_logical_block] = first_block; 737 s->EUNtable[first_logical_block] = first_block;
diff --git a/drivers/mtd/onenand/Kconfig b/drivers/mtd/onenand/Kconfig
new file mode 100644
index 000000000000..126ff6bf63d5
--- /dev/null
+++ b/drivers/mtd/onenand/Kconfig
@@ -0,0 +1,38 @@
1#
2# linux/drivers/mtd/onenand/Kconfig
3#
4
5menu "OneNAND Flash Device Drivers"
6 depends on MTD != n
7
8config MTD_ONENAND
9 tristate "OneNAND Device Support"
10 depends on MTD
11 help
12 This enables support for accessing all type of OneNAND flash
13 devices. For further information see
14 <http://www.samsung.com/Products/Semiconductor/Flash/OneNAND_TM/index.htm>.
15
16config MTD_ONENAND_VERIFY_WRITE
17 bool "Verify OneNAND page writes"
18 depends on MTD_ONENAND
19 help
20 This adds an extra check when data is written to the flash. The
21 OneNAND flash device internally checks only bits transitioning
22 from 1 to 0. There is a rare possibility that even though the
23 device thinks the write was successful, a bit could have been
24 flipped accidentaly due to device wear or something else.
25
26config MTD_ONENAND_GENERIC
27 tristate "OneNAND Flash device via platform device driver"
28 depends on MTD_ONENAND && ARM
29 help
30 Support for OneNAND flash via platform device driver.
31
32config MTD_ONENAND_SYNC_READ
33 bool "OneNAND Sync. Burst Read Support"
34 depends on ARCH_OMAP
35 help
36 This enables support for Sync. Burst Read.
37
38endmenu
diff --git a/drivers/mtd/onenand/Makefile b/drivers/mtd/onenand/Makefile
new file mode 100644
index 000000000000..269cfe467345
--- /dev/null
+++ b/drivers/mtd/onenand/Makefile
@@ -0,0 +1,11 @@
1#
2# Makefile for the OneNAND MTD
3#
4
5# Core functionality.
6obj-$(CONFIG_MTD_ONENAND) += onenand.o
7
8# Board specific.
9obj-$(CONFIG_MTD_ONENAND_GENERIC) += generic.o
10
11onenand-objs = onenand_base.o onenand_bbt.o
diff --git a/drivers/mtd/onenand/generic.c b/drivers/mtd/onenand/generic.c
new file mode 100644
index 000000000000..48cce431f89f
--- /dev/null
+++ b/drivers/mtd/onenand/generic.c
@@ -0,0 +1,147 @@
1/*
2 * linux/drivers/mtd/onenand/generic.c
3 *
4 * Copyright (c) 2005 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
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 * Overview:
12 * This is a device driver for the OneNAND flash for generic boards.
13 */
14
15#include <linux/device.h>
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/mtd/mtd.h>
19#include <linux/mtd/onenand.h>
20#include <linux/mtd/partitions.h>
21
22#include <asm/io.h>
23#include <asm/mach/flash.h>
24
25#define DRIVER_NAME "onenand"
26
27
28#ifdef CONFIG_MTD_PARTITIONS
29static const char *part_probes[] = { "cmdlinepart", NULL, };
30#endif
31
32struct onenand_info {
33 struct mtd_info mtd;
34 struct mtd_partition *parts;
35 struct onenand_chip onenand;
36};
37
38static int __devinit generic_onenand_probe(struct device *dev)
39{
40 struct onenand_info *info;
41 struct platform_device *pdev = to_platform_device(dev);
42 struct onenand_platform_data *pdata = pdev->dev.platform_data;
43 struct resource *res = pdev->resource;
44 unsigned long size = res->end - res->start + 1;
45 int err;
46
47 info = kmalloc(sizeof(struct onenand_info), GFP_KERNEL);
48 if (!info)
49 return -ENOMEM;
50
51 memset(info, 0, sizeof(struct onenand_info));
52
53 if (!request_mem_region(res->start, size, dev->driver->name)) {
54 err = -EBUSY;
55 goto out_free_info;
56 }
57
58 info->onenand.base = ioremap(res->start, size);
59 if (!info->onenand.base) {
60 err = -ENOMEM;
61 goto out_release_mem_region;
62 }
63
64 info->onenand.mmcontrol = pdata->mmcontrol;
65
66 info->mtd.name = pdev->dev.bus_id;
67 info->mtd.priv = &info->onenand;
68 info->mtd.owner = THIS_MODULE;
69
70 if (onenand_scan(&info->mtd, 1)) {
71 err = -ENXIO;
72 goto out_iounmap;
73 }
74
75#ifdef CONFIG_MTD_PARTITIONS
76 err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0);
77 if (err > 0)
78 add_mtd_partitions(&info->mtd, info->parts, err);
79 else if (err < 0 && pdata->parts)
80 add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts);
81 else
82#endif
83 err = add_mtd_device(&info->mtd);
84
85 dev_set_drvdata(&pdev->dev, info);
86
87 return 0;
88
89out_iounmap:
90 iounmap(info->onenand.base);
91out_release_mem_region:
92 release_mem_region(res->start, size);
93out_free_info:
94 kfree(info);
95
96 return err;
97}
98
99static int __devexit generic_onenand_remove(struct device *dev)
100{
101 struct platform_device *pdev = to_platform_device(dev);
102 struct onenand_info *info = dev_get_drvdata(&pdev->dev);
103 struct resource *res = pdev->resource;
104 unsigned long size = res->end - res->start + 1;
105
106 dev_set_drvdata(&pdev->dev, NULL);
107
108 if (info) {
109 if (info->parts)
110 del_mtd_partitions(&info->mtd);
111 else
112 del_mtd_device(&info->mtd);
113
114 onenand_release(&info->mtd);
115 release_mem_region(res->start, size);
116 iounmap(info->onenand.base);
117 kfree(info);
118 }
119
120 return 0;
121}
122
123static struct device_driver generic_onenand_driver = {
124 .name = DRIVER_NAME,
125 .bus = &platform_bus_type,
126 .probe = generic_onenand_probe,
127 .remove = __devexit_p(generic_onenand_remove),
128};
129
130MODULE_ALIAS(DRIVER_NAME);
131
132static int __init generic_onenand_init(void)
133{
134 return driver_register(&generic_onenand_driver);
135}
136
137static void __exit generic_onenand_exit(void)
138{
139 driver_unregister(&generic_onenand_driver);
140}
141
142module_init(generic_onenand_init);
143module_exit(generic_onenand_exit);
144
145MODULE_LICENSE("GPL");
146MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
147MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
new file mode 100644
index 000000000000..cc38fa0d45c6
--- /dev/null
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -0,0 +1,1588 @@
1/*
2 * linux/drivers/mtd/onenand/onenand_base.c
3 *
4 * Copyright (C) 2005 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
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
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/mtd/mtd.h>
16#include <linux/mtd/onenand.h>
17#include <linux/mtd/partitions.h>
18
19#include <asm/io.h>
20
21/**
22 * onenand_oob_64 - oob info for large (2KB) page
23 */
24static struct nand_oobinfo onenand_oob_64 = {
25 .useecc = MTD_NANDECC_AUTOPLACE,
26 .eccbytes = 20,
27 .eccpos = {
28 8, 9, 10, 11, 12,
29 24, 25, 26, 27, 28,
30 40, 41, 42, 43, 44,
31 56, 57, 58, 59, 60,
32 },
33 .oobfree = {
34 {2, 3}, {14, 2}, {18, 3}, {30, 2},
35 {24, 3}, {46, 2}, {40, 3}, {62, 2} }
36};
37
38/**
39 * onenand_oob_32 - oob info for middle (1KB) page
40 */
41static struct nand_oobinfo onenand_oob_32 = {
42 .useecc = MTD_NANDECC_AUTOPLACE,
43 .eccbytes = 10,
44 .eccpos = {
45 8, 9, 10, 11, 12,
46 24, 25, 26, 27, 28,
47 },
48 .oobfree = { {2, 3}, {14, 2}, {18, 3}, {30, 2} }
49};
50
51static const unsigned char ffchars[] = {
52 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
53 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 16 */
54 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
55 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 32 */
56 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
57 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 48 */
58 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
59 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 64 */
60};
61
62/**
63 * onenand_readw - [OneNAND Interface] Read OneNAND register
64 * @param addr address to read
65 *
66 * Read OneNAND register
67 */
68static unsigned short onenand_readw(void __iomem *addr)
69{
70 return readw(addr);
71}
72
73/**
74 * onenand_writew - [OneNAND Interface] Write OneNAND register with value
75 * @param value value to write
76 * @param addr address to write
77 *
78 * Write OneNAND register with value
79 */
80static void onenand_writew(unsigned short value, void __iomem *addr)
81{
82 writew(value, addr);
83}
84
85/**
86 * onenand_block_address - [DEFAULT] Get block address
87 * @param this onenand chip data structure
88 * @param block the block
89 * @return translated block address if DDP, otherwise same
90 *
91 * Setup Start Address 1 Register (F100h)
92 */
93static int onenand_block_address(struct onenand_chip *this, int block)
94{
95 if (this->device_id & ONENAND_DEVICE_IS_DDP) {
96 /* Device Flash Core select, NAND Flash Block Address */
97 int dfs = 0;
98
99 if (block & this->density_mask)
100 dfs = 1;
101
102 return (dfs << ONENAND_DDP_SHIFT) |
103 (block & (this->density_mask - 1));
104 }
105
106 return block;
107}
108
109/**
110 * onenand_bufferram_address - [DEFAULT] Get bufferram address
111 * @param this onenand chip data structure
112 * @param block the block
113 * @return set DBS value if DDP, otherwise 0
114 *
115 * Setup Start Address 2 Register (F101h) for DDP
116 */
117static int onenand_bufferram_address(struct onenand_chip *this, int block)
118{
119 if (this->device_id & ONENAND_DEVICE_IS_DDP) {
120 /* Device BufferRAM Select */
121 int dbs = 0;
122
123 if (block & this->density_mask)
124 dbs = 1;
125
126 return (dbs << ONENAND_DDP_SHIFT);
127 }
128
129 return 0;
130}
131
132/**
133 * onenand_page_address - [DEFAULT] Get page address
134 * @param page the page address
135 * @param sector the sector address
136 * @return combined page and sector address
137 *
138 * Setup Start Address 8 Register (F107h)
139 */
140static int onenand_page_address(int page, int sector)
141{
142 /* Flash Page Address, Flash Sector Address */
143 int fpa, fsa;
144
145 fpa = page & ONENAND_FPA_MASK;
146 fsa = sector & ONENAND_FSA_MASK;
147
148 return ((fpa << ONENAND_FPA_SHIFT) | fsa);
149}
150
151/**
152 * onenand_buffer_address - [DEFAULT] Get buffer address
153 * @param dataram1 DataRAM index
154 * @param sectors the sector address
155 * @param count the number of sectors
156 * @return the start buffer value
157 *
158 * Setup Start Buffer Register (F200h)
159 */
160static int onenand_buffer_address(int dataram1, int sectors, int count)
161{
162 int bsa, bsc;
163
164 /* BufferRAM Sector Address */
165 bsa = sectors & ONENAND_BSA_MASK;
166
167 if (dataram1)
168 bsa |= ONENAND_BSA_DATARAM1; /* DataRAM1 */
169 else
170 bsa |= ONENAND_BSA_DATARAM0; /* DataRAM0 */
171
172 /* BufferRAM Sector Count */
173 bsc = count & ONENAND_BSC_MASK;
174
175 return ((bsa << ONENAND_BSA_SHIFT) | bsc);
176}
177
178/**
179 * onenand_command - [DEFAULT] Send command to OneNAND device
180 * @param mtd MTD device structure
181 * @param cmd the command to be sent
182 * @param addr offset to read from or write to
183 * @param len number of bytes to read or write
184 *
185 * Send command to OneNAND device. This function is used for middle/large page
186 * devices (1KB/2KB Bytes per page)
187 */
188static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t len)
189{
190 struct onenand_chip *this = mtd->priv;
191 int value, readcmd = 0;
192 int block, page;
193 /* Now we use page size operation */
194 int sectors = 4, count = 4;
195
196 /* Address translation */
197 switch (cmd) {
198 case ONENAND_CMD_UNLOCK:
199 case ONENAND_CMD_LOCK:
200 case ONENAND_CMD_LOCK_TIGHT:
201 block = -1;
202 page = -1;
203 break;
204
205 case ONENAND_CMD_ERASE:
206 case ONENAND_CMD_BUFFERRAM:
207 block = (int) (addr >> this->erase_shift);
208 page = -1;
209 break;
210
211 default:
212 block = (int) (addr >> this->erase_shift);
213 page = (int) (addr >> this->page_shift);
214 page &= this->page_mask;
215 break;
216 }
217
218 /* NOTE: The setting order of the registers is very important! */
219 if (cmd == ONENAND_CMD_BUFFERRAM) {
220 /* Select DataRAM for DDP */
221 value = onenand_bufferram_address(this, block);
222 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2);
223
224 /* Switch to the next data buffer */
225 ONENAND_SET_NEXT_BUFFERRAM(this);
226
227 return 0;
228 }
229
230 if (block != -1) {
231 /* Write 'DFS, FBA' of Flash */
232 value = onenand_block_address(this, block);
233 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1);
234 }
235
236 if (page != -1) {
237 int dataram;
238
239 switch (cmd) {
240 case ONENAND_CMD_READ:
241 case ONENAND_CMD_READOOB:
242 dataram = ONENAND_SET_NEXT_BUFFERRAM(this);
243 readcmd = 1;
244 break;
245
246 default:
247 dataram = ONENAND_CURRENT_BUFFERRAM(this);
248 break;
249 }
250
251 /* Write 'FPA, FSA' of Flash */
252 value = onenand_page_address(page, sectors);
253 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS8);
254
255 /* Write 'BSA, BSC' of DataRAM */
256 value = onenand_buffer_address(dataram, sectors, count);
257 this->write_word(value, this->base + ONENAND_REG_START_BUFFER);
258
259 if (readcmd) {
260 /* Select DataRAM for DDP */
261 value = onenand_bufferram_address(this, block);
262 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2);
263 }
264 }
265
266 /* Interrupt clear */
267 this->write_word(ONENAND_INT_CLEAR, this->base + ONENAND_REG_INTERRUPT);
268
269 /* Write command */
270 this->write_word(cmd, this->base + ONENAND_REG_COMMAND);
271
272 return 0;
273}
274
275/**
276 * onenand_wait - [DEFAULT] wait until the command is done
277 * @param mtd MTD device structure
278 * @param state state to select the max. timeout value
279 *
280 * Wait for command done. This applies to all OneNAND command
281 * Read can take up to 30us, erase up to 2ms and program up to 350us
282 * according to general OneNAND specs
283 */
284static int onenand_wait(struct mtd_info *mtd, int state)
285{
286 struct onenand_chip * this = mtd->priv;
287 unsigned long timeout;
288 unsigned int flags = ONENAND_INT_MASTER;
289 unsigned int interrupt = 0;
290 unsigned int ctrl, ecc;
291
292 /* The 20 msec is enough */
293 timeout = jiffies + msecs_to_jiffies(20);
294 while (time_before(jiffies, timeout)) {
295 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
296
297 if (interrupt & flags)
298 break;
299
300 if (state != FL_READING)
301 cond_resched();
302 }
303 /* To get correct interrupt status in timeout case */
304 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
305
306 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS);
307
308 if (ctrl & ONENAND_CTRL_ERROR) {
309 /* It maybe occur at initial bad block */
310 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: controller error = 0x%04x\n", ctrl);
311 /* Clear other interrupt bits for preventing ECC error */
312 interrupt &= ONENAND_INT_MASTER;
313 }
314
315 if (ctrl & ONENAND_CTRL_LOCK) {
316 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: it's locked error = 0x%04x\n", ctrl);
317 return -EACCES;
318 }
319
320 if (interrupt & ONENAND_INT_READ) {
321 ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS);
322 if (ecc & ONENAND_ECC_2BIT_ALL) {
323 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: ECC error = 0x%04x\n", ecc);
324 return -EBADMSG;
325 }
326 }
327
328 return 0;
329}
330
331/**
332 * onenand_bufferram_offset - [DEFAULT] BufferRAM offset
333 * @param mtd MTD data structure
334 * @param area BufferRAM area
335 * @return offset given area
336 *
337 * Return BufferRAM offset given area
338 */
339static inline int onenand_bufferram_offset(struct mtd_info *mtd, int area)
340{
341 struct onenand_chip *this = mtd->priv;
342
343 if (ONENAND_CURRENT_BUFFERRAM(this)) {
344 if (area == ONENAND_DATARAM)
345 return mtd->oobblock;
346 if (area == ONENAND_SPARERAM)
347 return mtd->oobsize;
348 }
349
350 return 0;
351}
352
353/**
354 * onenand_read_bufferram - [OneNAND Interface] Read the bufferram area
355 * @param mtd MTD data structure
356 * @param area BufferRAM area
357 * @param buffer the databuffer to put/get data
358 * @param offset offset to read from or write to
359 * @param count number of bytes to read/write
360 *
361 * Read the BufferRAM area
362 */
363static int onenand_read_bufferram(struct mtd_info *mtd, int area,
364 unsigned char *buffer, int offset, size_t count)
365{
366 struct onenand_chip *this = mtd->priv;
367 void __iomem *bufferram;
368
369 bufferram = this->base + area;
370
371 bufferram += onenand_bufferram_offset(mtd, area);
372
373 memcpy(buffer, bufferram + offset, count);
374
375 return 0;
376}
377
378/**
379 * onenand_sync_read_bufferram - [OneNAND Interface] Read the bufferram area with Sync. Burst mode
380 * @param mtd MTD data structure
381 * @param area BufferRAM area
382 * @param buffer the databuffer to put/get data
383 * @param offset offset to read from or write to
384 * @param count number of bytes to read/write
385 *
386 * Read the BufferRAM area with Sync. Burst Mode
387 */
388static int onenand_sync_read_bufferram(struct mtd_info *mtd, int area,
389 unsigned char *buffer, int offset, size_t count)
390{
391 struct onenand_chip *this = mtd->priv;
392 void __iomem *bufferram;
393
394 bufferram = this->base + area;
395
396 bufferram += onenand_bufferram_offset(mtd, area);
397
398 this->mmcontrol(mtd, ONENAND_SYS_CFG1_SYNC_READ);
399
400 memcpy(buffer, bufferram + offset, count);
401
402 this->mmcontrol(mtd, 0);
403
404 return 0;
405}
406
407/**
408 * onenand_write_bufferram - [OneNAND Interface] Write the bufferram area
409 * @param mtd MTD data structure
410 * @param area BufferRAM area
411 * @param buffer the databuffer to put/get data
412 * @param offset offset to read from or write to
413 * @param count number of bytes to read/write
414 *
415 * Write the BufferRAM area
416 */
417static int onenand_write_bufferram(struct mtd_info *mtd, int area,
418 const unsigned char *buffer, int offset, size_t count)
419{
420 struct onenand_chip *this = mtd->priv;
421 void __iomem *bufferram;
422
423 bufferram = this->base + area;
424
425 bufferram += onenand_bufferram_offset(mtd, area);
426
427 memcpy(bufferram + offset, buffer, count);
428
429 return 0;
430}
431
432/**
433 * onenand_check_bufferram - [GENERIC] Check BufferRAM information
434 * @param mtd MTD data structure
435 * @param addr address to check
436 * @return 1 if there are valid data, otherwise 0
437 *
438 * Check bufferram if there is data we required
439 */
440static int onenand_check_bufferram(struct mtd_info *mtd, loff_t addr)
441{
442 struct onenand_chip *this = mtd->priv;
443 int block, page;
444 int i;
445
446 block = (int) (addr >> this->erase_shift);
447 page = (int) (addr >> this->page_shift);
448 page &= this->page_mask;
449
450 i = ONENAND_CURRENT_BUFFERRAM(this);
451
452 /* Is there valid data? */
453 if (this->bufferram[i].block == block &&
454 this->bufferram[i].page == page &&
455 this->bufferram[i].valid)
456 return 1;
457
458 return 0;
459}
460
461/**
462 * onenand_update_bufferram - [GENERIC] Update BufferRAM information
463 * @param mtd MTD data structure
464 * @param addr address to update
465 * @param valid valid flag
466 *
467 * Update BufferRAM information
468 */
469static int onenand_update_bufferram(struct mtd_info *mtd, loff_t addr,
470 int valid)
471{
472 struct onenand_chip *this = mtd->priv;
473 int block, page;
474 int i;
475
476 block = (int) (addr >> this->erase_shift);
477 page = (int) (addr >> this->page_shift);
478 page &= this->page_mask;
479
480 /* Invalidate BufferRAM */
481 for (i = 0; i < MAX_BUFFERRAM; i++) {
482 if (this->bufferram[i].block == block &&
483 this->bufferram[i].page == page)
484 this->bufferram[i].valid = 0;
485 }
486
487 /* Update BufferRAM */
488 i = ONENAND_CURRENT_BUFFERRAM(this);
489 this->bufferram[i].block = block;
490 this->bufferram[i].page = page;
491 this->bufferram[i].valid = valid;
492
493 return 0;
494}
495
496/**
497 * onenand_get_device - [GENERIC] Get chip for selected access
498 * @param mtd MTD device structure
499 * @param new_state the state which is requested
500 *
501 * Get the device and lock it for exclusive access
502 */
503static int onenand_get_device(struct mtd_info *mtd, int new_state)
504{
505 struct onenand_chip *this = mtd->priv;
506 DECLARE_WAITQUEUE(wait, current);
507
508 /*
509 * Grab the lock and see if the device is available
510 */
511 while (1) {
512 spin_lock(&this->chip_lock);
513 if (this->state == FL_READY) {
514 this->state = new_state;
515 spin_unlock(&this->chip_lock);
516 break;
517 }
518 if (new_state == FL_PM_SUSPENDED) {
519 spin_unlock(&this->chip_lock);
520 return (this->state == FL_PM_SUSPENDED) ? 0 : -EAGAIN;
521 }
522 set_current_state(TASK_UNINTERRUPTIBLE);
523 add_wait_queue(&this->wq, &wait);
524 spin_unlock(&this->chip_lock);
525 schedule();
526 remove_wait_queue(&this->wq, &wait);
527 }
528
529 return 0;
530}
531
532/**
533 * onenand_release_device - [GENERIC] release chip
534 * @param mtd MTD device structure
535 *
536 * Deselect, release chip lock and wake up anyone waiting on the device
537 */
538static void onenand_release_device(struct mtd_info *mtd)
539{
540 struct onenand_chip *this = mtd->priv;
541
542 /* Release the chip */
543 spin_lock(&this->chip_lock);
544 this->state = FL_READY;
545 wake_up(&this->wq);
546 spin_unlock(&this->chip_lock);
547}
548
549/**
550 * onenand_read_ecc - [MTD Interface] Read data with ECC
551 * @param mtd MTD device structure
552 * @param from offset to read from
553 * @param len number of bytes to read
554 * @param retlen pointer to variable to store the number of read bytes
555 * @param buf the databuffer to put data
556 * @param oob_buf filesystem supplied oob data buffer
557 * @param oobsel oob selection structure
558 *
559 * OneNAND read with ECC
560 */
561static int onenand_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
562 size_t *retlen, u_char *buf,
563 u_char *oob_buf, struct nand_oobinfo *oobsel)
564{
565 struct onenand_chip *this = mtd->priv;
566 int read = 0, column;
567 int thislen;
568 int ret = 0;
569
570 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read_ecc: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
571
572 /* Do not allow reads past end of device */
573 if ((from + len) > mtd->size) {
574 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_ecc: Attempt read beyond end of device\n");
575 *retlen = 0;
576 return -EINVAL;
577 }
578
579 /* Grab the lock and see if the device is available */
580 onenand_get_device(mtd, FL_READING);
581
582 /* TODO handling oob */
583
584 while (read < len) {
585 thislen = min_t(int, mtd->oobblock, len - read);
586
587 column = from & (mtd->oobblock - 1);
588 if (column + thislen > mtd->oobblock)
589 thislen = mtd->oobblock - column;
590
591 if (!onenand_check_bufferram(mtd, from)) {
592 this->command(mtd, ONENAND_CMD_READ, from, mtd->oobblock);
593
594 ret = this->wait(mtd, FL_READING);
595 /* First copy data and check return value for ECC handling */
596 onenand_update_bufferram(mtd, from, 1);
597 }
598
599 this->read_bufferram(mtd, ONENAND_DATARAM, buf, column, thislen);
600
601 read += thislen;
602
603 if (read == len)
604 break;
605
606 if (ret) {
607 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_ecc: read failed = %d\n", ret);
608 goto out;
609 }
610
611 from += thislen;
612 buf += thislen;
613 }
614
615out:
616 /* Deselect and wake up anyone waiting on the device */
617 onenand_release_device(mtd);
618
619 /*
620 * Return success, if no ECC failures, else -EBADMSG
621 * fs driver will take care of that, because
622 * retlen == desired len and result == -EBADMSG
623 */
624 *retlen = read;
625 return ret;
626}
627
628/**
629 * onenand_read - [MTD Interface] MTD compability function for onenand_read_ecc
630 * @param mtd MTD device structure
631 * @param from offset to read from
632 * @param len number of bytes to read
633 * @param retlen pointer to variable to store the number of read bytes
634 * @param buf the databuffer to put data
635 *
636 * This function simply calls onenand_read_ecc with oob buffer and oobsel = NULL
637*/
638static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
639 size_t *retlen, u_char *buf)
640{
641 return onenand_read_ecc(mtd, from, len, retlen, buf, NULL, NULL);
642}
643
644/**
645 * onenand_read_oob - [MTD Interface] OneNAND read out-of-band
646 * @param mtd MTD device structure
647 * @param from offset to read from
648 * @param len number of bytes to read
649 * @param retlen pointer to variable to store the number of read bytes
650 * @param buf the databuffer to put data
651 *
652 * OneNAND read out-of-band data from the spare area
653 */
654static int onenand_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
655 size_t *retlen, u_char *buf)
656{
657 struct onenand_chip *this = mtd->priv;
658 int read = 0, thislen, column;
659 int ret = 0;
660
661 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read_oob: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
662
663 /* Initialize return length value */
664 *retlen = 0;
665
666 /* Do not allow reads past end of device */
667 if (unlikely((from + len) > mtd->size)) {
668 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: Attempt read beyond end of device\n");
669 return -EINVAL;
670 }
671
672 /* Grab the lock and see if the device is available */
673 onenand_get_device(mtd, FL_READING);
674
675 column = from & (mtd->oobsize - 1);
676
677 while (read < len) {
678 thislen = mtd->oobsize - column;
679 thislen = min_t(int, thislen, len);
680
681 this->command(mtd, ONENAND_CMD_READOOB, from, mtd->oobsize);
682
683 onenand_update_bufferram(mtd, from, 0);
684
685 ret = this->wait(mtd, FL_READING);
686 /* First copy data and check return value for ECC handling */
687
688 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen);
689
690 read += thislen;
691
692 if (read == len)
693 break;
694
695 if (ret) {
696 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: read failed = %d\n", ret);
697 goto out;
698 }
699
700 buf += thislen;
701
702 /* Read more? */
703 if (read < len) {
704 /* Page size */
705 from += mtd->oobblock;
706 column = 0;
707 }
708 }
709
710out:
711 /* Deselect and wake up anyone waiting on the device */
712 onenand_release_device(mtd);
713
714 *retlen = read;
715 return ret;
716}
717
718#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
719/**
720 * onenand_verify_page - [GENERIC] verify the chip contents after a write
721 * @param mtd MTD device structure
722 * @param buf the databuffer to verify
723 *
724 * Check DataRAM area directly
725 */
726static int onenand_verify_page(struct mtd_info *mtd, u_char *buf, loff_t addr)
727{
728 struct onenand_chip *this = mtd->priv;
729 void __iomem *dataram0, *dataram1;
730 int ret = 0;
731
732 this->command(mtd, ONENAND_CMD_READ, addr, mtd->oobblock);
733
734 ret = this->wait(mtd, FL_READING);
735 if (ret)
736 return ret;
737
738 onenand_update_bufferram(mtd, addr, 1);
739
740 /* Check, if the two dataram areas are same */
741 dataram0 = this->base + ONENAND_DATARAM;
742 dataram1 = dataram0 + mtd->oobblock;
743
744 if (memcmp(dataram0, dataram1, mtd->oobblock))
745 return -EBADMSG;
746
747 return 0;
748}
749#else
750#define onenand_verify_page(...) (0)
751#endif
752
753#define NOTALIGNED(x) ((x & (mtd->oobblock - 1)) != 0)
754
755/**
756 * onenand_write_ecc - [MTD Interface] OneNAND write with ECC
757 * @param mtd MTD device structure
758 * @param to offset to write to
759 * @param len number of bytes to write
760 * @param retlen pointer to variable to store the number of written bytes
761 * @param buf the data to write
762 * @param eccbuf filesystem supplied oob data buffer
763 * @param oobsel oob selection structure
764 *
765 * OneNAND write with ECC
766 */
767static int onenand_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
768 size_t *retlen, const u_char *buf,
769 u_char *eccbuf, struct nand_oobinfo *oobsel)
770{
771 struct onenand_chip *this = mtd->priv;
772 int written = 0;
773 int ret = 0;
774
775 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write_ecc: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len);
776
777 /* Initialize retlen, in case of early exit */
778 *retlen = 0;
779
780 /* Do not allow writes past end of device */
781 if (unlikely((to + len) > mtd->size)) {
782 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_ecc: Attempt write to past end of device\n");
783 return -EINVAL;
784 }
785
786 /* Reject writes, which are not page aligned */
787 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(len))) {
788 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_ecc: Attempt to write not page aligned data\n");
789 return -EINVAL;
790 }
791
792 /* Grab the lock and see if the device is available */
793 onenand_get_device(mtd, FL_WRITING);
794
795 /* Loop until all data write */
796 while (written < len) {
797 int thislen = min_t(int, mtd->oobblock, len - written);
798
799 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobblock);
800
801 this->write_bufferram(mtd, ONENAND_DATARAM, buf, 0, thislen);
802 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize);
803
804 this->command(mtd, ONENAND_CMD_PROG, to, mtd->oobblock);
805
806 onenand_update_bufferram(mtd, to, 1);
807
808 ret = this->wait(mtd, FL_WRITING);
809 if (ret) {
810 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_ecc: write filaed %d\n", ret);
811 goto out;
812 }
813
814 written += thislen;
815
816 /* Only check verify write turn on */
817 ret = onenand_verify_page(mtd, (u_char *) buf, to);
818 if (ret) {
819 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_ecc: verify failed %d\n", ret);
820 goto out;
821 }
822
823 if (written == len)
824 break;
825
826 to += thislen;
827 buf += thislen;
828 }
829
830out:
831 /* Deselect and wake up anyone waiting on the device */
832 onenand_release_device(mtd);
833
834 *retlen = written;
835
836 return ret;
837}
838
839/**
840 * onenand_write - [MTD Interface] compability function for onenand_write_ecc
841 * @param mtd MTD device structure
842 * @param to offset to write to
843 * @param len number of bytes to write
844 * @param retlen pointer to variable to store the number of written bytes
845 * @param buf the data to write
846 *
847 * This function simply calls onenand_write_ecc
848 * with oob buffer and oobsel = NULL
849 */
850static int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
851 size_t *retlen, const u_char *buf)
852{
853 return onenand_write_ecc(mtd, to, len, retlen, buf, NULL, NULL);
854}
855
856/**
857 * onenand_write_oob - [MTD Interface] OneNAND write out-of-band
858 * @param mtd MTD device structure
859 * @param to offset to write to
860 * @param len number of bytes to write
861 * @param retlen pointer to variable to store the number of written bytes
862 * @param buf the data to write
863 *
864 * OneNAND write out-of-band
865 */
866static int onenand_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
867 size_t *retlen, const u_char *buf)
868{
869 struct onenand_chip *this = mtd->priv;
870 int column, status;
871 int written = 0;
872
873 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write_oob: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len);
874
875 /* Initialize retlen, in case of early exit */
876 *retlen = 0;
877
878 /* Do not allow writes past end of device */
879 if (unlikely((to + len) > mtd->size)) {
880 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_oob: Attempt write to past end of device\n");
881 return -EINVAL;
882 }
883
884 /* Grab the lock and see if the device is available */
885 onenand_get_device(mtd, FL_WRITING);
886
887 /* Loop until all data write */
888 while (written < len) {
889 int thislen = min_t(int, mtd->oobsize, len - written);
890
891 column = to & (mtd->oobsize - 1);
892
893 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize);
894
895 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize);
896 this->write_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen);
897
898 this->command(mtd, ONENAND_CMD_PROGOOB, to, mtd->oobsize);
899
900 onenand_update_bufferram(mtd, to, 0);
901
902 status = this->wait(mtd, FL_WRITING);
903 if (status)
904 goto out;
905
906 written += thislen;
907
908 if (written == len)
909 break;
910
911 to += thislen;
912 buf += thislen;
913 }
914
915out:
916 /* Deselect and wake up anyone waiting on the device */
917 onenand_release_device(mtd);
918
919 *retlen = written;
920
921 return 0;
922}
923
924/**
925 * onenand_writev_ecc - [MTD Interface] write with iovec with ecc
926 * @param mtd MTD device structure
927 * @param vecs the iovectors to write
928 * @param count number of vectors
929 * @param to offset to write to
930 * @param retlen pointer to variable to store the number of written bytes
931 * @param eccbuf filesystem supplied oob data buffer
932 * @param oobsel oob selection structure
933 *
934 * OneNAND write with iovec with ecc
935 */
936static int onenand_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
937 unsigned long count, loff_t to, size_t *retlen,
938 u_char *eccbuf, struct nand_oobinfo *oobsel)
939{
940 struct onenand_chip *this = mtd->priv;
941 unsigned char buffer[MAX_ONENAND_PAGESIZE], *pbuf;
942 size_t total_len, len;
943 int i, written = 0;
944 int ret = 0;
945
946 /* Preset written len for early exit */
947 *retlen = 0;
948
949 /* Calculate total length of data */
950 total_len = 0;
951 for (i = 0; i < count; i++)
952 total_len += vecs[i].iov_len;
953
954 DEBUG(MTD_DEBUG_LEVEL3, "onenand_writev_ecc: to = 0x%08x, len = %i, count = %ld\n", (unsigned int) to, (unsigned int) total_len, count);
955
956 /* Do not allow write past end of the device */
957 if (unlikely((to + total_len) > mtd->size)) {
958 DEBUG(MTD_DEBUG_LEVEL0, "onenand_writev_ecc: Attempted write past end of device\n");
959 return -EINVAL;
960 }
961
962 /* Reject writes, which are not page aligned */
963 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(total_len))) {
964 DEBUG(MTD_DEBUG_LEVEL0, "onenand_writev_ecc: Attempt to write not page aligned data\n");
965 return -EINVAL;
966 }
967
968 /* Grab the lock and see if the device is available */
969 onenand_get_device(mtd, FL_WRITING);
970
971 /* TODO handling oob */
972
973 /* Loop until all keve's data has been written */
974 len = 0;
975 while (count) {
976 pbuf = buffer;
977 /*
978 * If the given tuple is >= pagesize then
979 * write it out from the iov
980 */
981 if ((vecs->iov_len - len) >= mtd->oobblock) {
982 pbuf = vecs->iov_base + len;
983
984 len += mtd->oobblock;
985
986 /* Check, if we have to switch to the next tuple */
987 if (len >= (int) vecs->iov_len) {
988 vecs++;
989 len = 0;
990 count--;
991 }
992 } else {
993 int cnt = 0, thislen;
994 while (cnt < mtd->oobblock) {
995 thislen = min_t(int, mtd->oobblock - cnt, vecs->iov_len - len);
996 memcpy(buffer + cnt, vecs->iov_base + len, thislen);
997 cnt += thislen;
998 len += thislen;
999
1000 /* Check, if we have to switch to the next tuple */
1001 if (len >= (int) vecs->iov_len) {
1002 vecs++;
1003 len = 0;
1004 count--;
1005 }
1006 }
1007 }
1008
1009 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobblock);
1010
1011 this->write_bufferram(mtd, ONENAND_DATARAM, pbuf, 0, mtd->oobblock);
1012 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize);
1013
1014 this->command(mtd, ONENAND_CMD_PROG, to, mtd->oobblock);
1015
1016 onenand_update_bufferram(mtd, to, 1);
1017
1018 ret = this->wait(mtd, FL_WRITING);
1019 if (ret) {
1020 DEBUG(MTD_DEBUG_LEVEL0, "onenand_writev_ecc: write failed %d\n", ret);
1021 goto out;
1022 }
1023
1024
1025 /* Only check verify write turn on */
1026 ret = onenand_verify_page(mtd, (u_char *) pbuf, to);
1027 if (ret) {
1028 DEBUG(MTD_DEBUG_LEVEL0, "onenand_writev_ecc: verify failed %d\n", ret);
1029 goto out;
1030 }
1031
1032 written += mtd->oobblock;
1033
1034 to += mtd->oobblock;
1035 }
1036
1037out:
1038 /* Deselect and wakt up anyone waiting on the device */
1039 onenand_release_device(mtd);
1040
1041 *retlen = written;
1042
1043 return 0;
1044}
1045
1046/**
1047 * onenand_writev - [MTD Interface] compabilty function for onenand_writev_ecc
1048 * @param mtd MTD device structure
1049 * @param vecs the iovectors to write
1050 * @param count number of vectors
1051 * @param to offset to write to
1052 * @param retlen pointer to variable to store the number of written bytes
1053 *
1054 * OneNAND write with kvec. This just calls the ecc function
1055 */
1056static int onenand_writev(struct mtd_info *mtd, const struct kvec *vecs,
1057 unsigned long count, loff_t to, size_t *retlen)
1058{
1059 return onenand_writev_ecc(mtd, vecs, count, to, retlen, NULL, NULL);
1060}
1061
1062/**
1063 * onenand_block_checkbad - [GENERIC] Check if a block is marked bad
1064 * @param mtd MTD device structure
1065 * @param ofs offset from device start
1066 * @param getchip 0, if the chip is already selected
1067 * @param allowbbt 1, if its allowed to access the bbt area
1068 *
1069 * Check, if the block is bad. Either by reading the bad block table or
1070 * calling of the scan function.
1071 */
1072static int onenand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt)
1073{
1074 struct onenand_chip *this = mtd->priv;
1075 struct bbm_info *bbm = this->bbm;
1076
1077 /* Return info from the table */
1078 return bbm->isbad_bbt(mtd, ofs, allowbbt);
1079}
1080
1081/**
1082 * onenand_erase - [MTD Interface] erase block(s)
1083 * @param mtd MTD device structure
1084 * @param instr erase instruction
1085 *
1086 * Erase one ore more blocks
1087 */
1088static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
1089{
1090 struct onenand_chip *this = mtd->priv;
1091 unsigned int block_size;
1092 loff_t addr;
1093 int len;
1094 int ret = 0;
1095
1096 DEBUG(MTD_DEBUG_LEVEL3, "onenand_erase: start = 0x%08x, len = %i\n", (unsigned int) instr->addr, (unsigned int) instr->len);
1097
1098 block_size = (1 << this->erase_shift);
1099
1100 /* Start address must align on block boundary */
1101 if (unlikely(instr->addr & (block_size - 1))) {
1102 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Unaligned address\n");
1103 return -EINVAL;
1104 }
1105
1106 /* Length must align on block boundary */
1107 if (unlikely(instr->len & (block_size - 1))) {
1108 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Length not block aligned\n");
1109 return -EINVAL;
1110 }
1111
1112 /* Do not allow erase past end of device */
1113 if (unlikely((instr->len + instr->addr) > mtd->size)) {
1114 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Erase past end of device\n");
1115 return -EINVAL;
1116 }
1117
1118 instr->fail_addr = 0xffffffff;
1119
1120 /* Grab the lock and see if the device is available */
1121 onenand_get_device(mtd, FL_ERASING);
1122
1123 /* Loop throught the pages */
1124 len = instr->len;
1125 addr = instr->addr;
1126
1127 instr->state = MTD_ERASING;
1128
1129 while (len) {
1130
1131 /* Check if we have a bad block, we do not erase bad blocks */
1132 if (onenand_block_checkbad(mtd, addr, 0, 0)) {
1133 printk (KERN_WARNING "onenand_erase: attempt to erase a bad block at addr 0x%08x\n", (unsigned int) addr);
1134 instr->state = MTD_ERASE_FAILED;
1135 goto erase_exit;
1136 }
1137
1138 this->command(mtd, ONENAND_CMD_ERASE, addr, block_size);
1139
1140 ret = this->wait(mtd, FL_ERASING);
1141 /* Check, if it is write protected */
1142 if (ret) {
1143 if (ret == -EPERM)
1144 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Device is write protected!!!\n");
1145 else
1146 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Failed erase, block %d\n", (unsigned) (addr >> this->erase_shift));
1147 instr->state = MTD_ERASE_FAILED;
1148 instr->fail_addr = addr;
1149 goto erase_exit;
1150 }
1151
1152 len -= block_size;
1153 addr += block_size;
1154 }
1155
1156 instr->state = MTD_ERASE_DONE;
1157
1158erase_exit:
1159
1160 ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;
1161 /* Do call back function */
1162 if (!ret)
1163 mtd_erase_callback(instr);
1164
1165 /* Deselect and wake up anyone waiting on the device */
1166 onenand_release_device(mtd);
1167
1168 return ret;
1169}
1170
1171/**
1172 * onenand_sync - [MTD Interface] sync
1173 * @param mtd MTD device structure
1174 *
1175 * Sync is actually a wait for chip ready function
1176 */
1177static void onenand_sync(struct mtd_info *mtd)
1178{
1179 DEBUG(MTD_DEBUG_LEVEL3, "onenand_sync: called\n");
1180
1181 /* Grab the lock and see if the device is available */
1182 onenand_get_device(mtd, FL_SYNCING);
1183
1184 /* Release it and go back */
1185 onenand_release_device(mtd);
1186}
1187
1188
1189/**
1190 * onenand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad
1191 * @param mtd MTD device structure
1192 * @param ofs offset relative to mtd start
1193 *
1194 * Check whether the block is bad
1195 */
1196static int onenand_block_isbad(struct mtd_info *mtd, loff_t ofs)
1197{
1198 /* Check for invalid offset */
1199 if (ofs > mtd->size)
1200 return -EINVAL;
1201
1202 return onenand_block_checkbad(mtd, ofs, 1, 0);
1203}
1204
1205/**
1206 * onenand_default_block_markbad - [DEFAULT] mark a block bad
1207 * @param mtd MTD device structure
1208 * @param ofs offset from device start
1209 *
1210 * This is the default implementation, which can be overridden by
1211 * a hardware specific driver.
1212 */
1213static int onenand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
1214{
1215 struct onenand_chip *this = mtd->priv;
1216 struct bbm_info *bbm = this->bbm;
1217 u_char buf[2] = {0, 0};
1218 size_t retlen;
1219 int block;
1220
1221 /* Get block number */
1222 block = ((int) ofs) >> bbm->bbt_erase_shift;
1223 if (bbm->bbt)
1224 bbm->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);
1225
1226 /* We write two bytes, so we dont have to mess with 16 bit access */
1227 ofs += mtd->oobsize + (bbm->badblockpos & ~0x01);
1228 return mtd->write_oob(mtd, ofs , 2, &retlen, buf);
1229}
1230
1231/**
1232 * onenand_block_markbad - [MTD Interface] Mark the block at the given offset as bad
1233 * @param mtd MTD device structure
1234 * @param ofs offset relative to mtd start
1235 *
1236 * Mark the block as bad
1237 */
1238static int onenand_block_markbad(struct mtd_info *mtd, loff_t ofs)
1239{
1240 struct onenand_chip *this = mtd->priv;
1241 int ret;
1242
1243 ret = onenand_block_isbad(mtd, ofs);
1244 if (ret) {
1245 /* If it was bad already, return success and do nothing */
1246 if (ret > 0)
1247 return 0;
1248 return ret;
1249 }
1250
1251 return this->block_markbad(mtd, ofs);
1252}
1253
1254/**
1255 * onenand_unlock - [MTD Interface] Unlock block(s)
1256 * @param mtd MTD device structure
1257 * @param ofs offset relative to mtd start
1258 * @param len number of bytes to unlock
1259 *
1260 * Unlock one or more blocks
1261 */
1262static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1263{
1264 struct onenand_chip *this = mtd->priv;
1265 int start, end, block, value, status;
1266
1267 start = ofs >> this->erase_shift;
1268 end = len >> this->erase_shift;
1269
1270 /* Continuous lock scheme */
1271 if (this->options & ONENAND_CONT_LOCK) {
1272 /* Set start block address */
1273 this->write_word(start, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1274 /* Set end block address */
1275 this->write_word(end - 1, this->base + ONENAND_REG_END_BLOCK_ADDRESS);
1276 /* Write unlock command */
1277 this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0);
1278
1279 /* There's no return value */
1280 this->wait(mtd, FL_UNLOCKING);
1281
1282 /* Sanity check */
1283 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
1284 & ONENAND_CTRL_ONGO)
1285 continue;
1286
1287 /* Check lock status */
1288 status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
1289 if (!(status & ONENAND_WP_US))
1290 printk(KERN_ERR "wp status = 0x%x\n", status);
1291
1292 return 0;
1293 }
1294
1295 /* Block lock scheme */
1296 for (block = start; block < end; block++) {
1297 /* Set start block address */
1298 this->write_word(block, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1299 /* Write unlock command */
1300 this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0);
1301
1302 /* There's no return value */
1303 this->wait(mtd, FL_UNLOCKING);
1304
1305 /* Sanity check */
1306 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
1307 & ONENAND_CTRL_ONGO)
1308 continue;
1309
1310 /* Set block address for read block status */
1311 value = onenand_block_address(this, block);
1312 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1);
1313
1314 /* Check lock status */
1315 status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
1316 if (!(status & ONENAND_WP_US))
1317 printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status);
1318 }
1319
1320 return 0;
1321}
1322
1323/**
1324 * onenand_print_device_info - Print device ID
1325 * @param device device ID
1326 *
1327 * Print device ID
1328 */
1329static void onenand_print_device_info(int device)
1330{
1331 int vcc, demuxed, ddp, density;
1332
1333 vcc = device & ONENAND_DEVICE_VCC_MASK;
1334 demuxed = device & ONENAND_DEVICE_IS_DEMUX;
1335 ddp = device & ONENAND_DEVICE_IS_DDP;
1336 density = device >> ONENAND_DEVICE_DENSITY_SHIFT;
1337 printk(KERN_INFO "%sOneNAND%s %dMB %sV 16-bit (0x%02x)\n",
1338 demuxed ? "" : "Muxed ",
1339 ddp ? "(DDP)" : "",
1340 (16 << density),
1341 vcc ? "2.65/3.3" : "1.8",
1342 device);
1343}
1344
1345static const struct onenand_manufacturers onenand_manuf_ids[] = {
1346 {ONENAND_MFR_SAMSUNG, "Samsung"},
1347 {ONENAND_MFR_UNKNOWN, "Unknown"}
1348};
1349
1350/**
1351 * onenand_check_maf - Check manufacturer ID
1352 * @param manuf manufacturer ID
1353 *
1354 * Check manufacturer ID
1355 */
1356static int onenand_check_maf(int manuf)
1357{
1358 int i;
1359
1360 for (i = 0; onenand_manuf_ids[i].id; i++) {
1361 if (manuf == onenand_manuf_ids[i].id)
1362 break;
1363 }
1364
1365 printk(KERN_DEBUG "OneNAND Manufacturer: %s (0x%0x)\n",
1366 onenand_manuf_ids[i].name, manuf);
1367
1368 return (i != ONENAND_MFR_UNKNOWN);
1369}
1370
1371/**
1372 * onenand_probe - [OneNAND Interface] Probe the OneNAND device
1373 * @param mtd MTD device structure
1374 *
1375 * OneNAND detection method:
1376 * Compare the the values from command with ones from register
1377 */
1378static int onenand_probe(struct mtd_info *mtd)
1379{
1380 struct onenand_chip *this = mtd->priv;
1381 int bram_maf_id, bram_dev_id, maf_id, dev_id;
1382 int version_id;
1383 int density;
1384
1385 /* Send the command for reading device ID from BootRAM */
1386 this->write_word(ONENAND_CMD_READID, this->base + ONENAND_BOOTRAM);
1387
1388 /* Read manufacturer and device IDs from BootRAM */
1389 bram_maf_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x0);
1390 bram_dev_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x2);
1391
1392 /* Check manufacturer ID */
1393 if (onenand_check_maf(bram_maf_id))
1394 return -ENXIO;
1395
1396 /* Reset OneNAND to read default register values */
1397 this->write_word(ONENAND_CMD_RESET, this->base + ONENAND_BOOTRAM);
1398
1399 /* Read manufacturer and device IDs from Register */
1400 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID);
1401 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID);
1402
1403 /* Check OneNAND device */
1404 if (maf_id != bram_maf_id || dev_id != bram_dev_id)
1405 return -ENXIO;
1406
1407 /* Flash device information */
1408 onenand_print_device_info(dev_id);
1409 this->device_id = dev_id;
1410
1411 density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT;
1412 this->chipsize = (16 << density) << 20;
1413 /* Set density mask. it is used for DDP */
1414 this->density_mask = (1 << (density + 6));
1415
1416 /* OneNAND page size & block size */
1417 /* The data buffer size is equal to page size */
1418 mtd->oobblock = this->read_word(this->base + ONENAND_REG_DATA_BUFFER_SIZE);
1419 mtd->oobsize = mtd->oobblock >> 5;
1420 /* Pagers per block is always 64 in OneNAND */
1421 mtd->erasesize = mtd->oobblock << 6;
1422
1423 this->erase_shift = ffs(mtd->erasesize) - 1;
1424 this->page_shift = ffs(mtd->oobblock) - 1;
1425 this->ppb_shift = (this->erase_shift - this->page_shift);
1426 this->page_mask = (mtd->erasesize / mtd->oobblock) - 1;
1427
1428 /* REVIST: Multichip handling */
1429
1430 mtd->size = this->chipsize;
1431
1432 /* Version ID */
1433 version_id = this->read_word(this->base + ONENAND_REG_VERSION_ID);
1434 printk(KERN_DEBUG "OneNAND version = 0x%04x\n", version_id);
1435
1436 /* Lock scheme */
1437 if (density <= ONENAND_DEVICE_DENSITY_512Mb &&
1438 !(version_id >> ONENAND_VERSION_PROCESS_SHIFT)) {
1439 printk(KERN_INFO "Lock scheme is Continues Lock\n");
1440 this->options |= ONENAND_CONT_LOCK;
1441 }
1442
1443 return 0;
1444}
1445
1446/**
1447 * onenand_suspend - [MTD Interface] Suspend the OneNAND flash
1448 * @param mtd MTD device structure
1449 */
1450static int onenand_suspend(struct mtd_info *mtd)
1451{
1452 return onenand_get_device(mtd, FL_PM_SUSPENDED);
1453}
1454
1455/**
1456 * onenand_resume - [MTD Interface] Resume the OneNAND flash
1457 * @param mtd MTD device structure
1458 */
1459static void onenand_resume(struct mtd_info *mtd)
1460{
1461 struct onenand_chip *this = mtd->priv;
1462
1463 if (this->state == FL_PM_SUSPENDED)
1464 onenand_release_device(mtd);
1465 else
1466 printk(KERN_ERR "resume() called for the chip which is not"
1467 "in suspended state\n");
1468}
1469
1470
1471/**
1472 * onenand_scan - [OneNAND Interface] Scan for the OneNAND device
1473 * @param mtd MTD device structure
1474 * @param maxchips Number of chips to scan for
1475 *
1476 * This fills out all the not initialized function pointers
1477 * with the defaults.
1478 * The flash ID is read and the mtd/chip structures are
1479 * filled with the appropriate values.
1480 */
1481int onenand_scan(struct mtd_info *mtd, int maxchips)
1482{
1483 struct onenand_chip *this = mtd->priv;
1484
1485 if (!this->read_word)
1486 this->read_word = onenand_readw;
1487 if (!this->write_word)
1488 this->write_word = onenand_writew;
1489
1490 if (!this->command)
1491 this->command = onenand_command;
1492 if (!this->wait)
1493 this->wait = onenand_wait;
1494
1495 if (!this->read_bufferram)
1496 this->read_bufferram = onenand_read_bufferram;
1497 if (!this->write_bufferram)
1498 this->write_bufferram = onenand_write_bufferram;
1499
1500 if (!this->block_markbad)
1501 this->block_markbad = onenand_default_block_markbad;
1502 if (!this->scan_bbt)
1503 this->scan_bbt = onenand_default_bbt;
1504
1505 if (onenand_probe(mtd))
1506 return -ENXIO;
1507
1508 /* Set Sync. Burst Read after probing */
1509 if (this->mmcontrol) {
1510 printk(KERN_INFO "OneNAND Sync. Burst Read support\n");
1511 this->read_bufferram = onenand_sync_read_bufferram;
1512 }
1513
1514 this->state = FL_READY;
1515 init_waitqueue_head(&this->wq);
1516 spin_lock_init(&this->chip_lock);
1517
1518 switch (mtd->oobsize) {
1519 case 64:
1520 this->autooob = &onenand_oob_64;
1521 break;
1522
1523 case 32:
1524 this->autooob = &onenand_oob_32;
1525 break;
1526
1527 default:
1528 printk(KERN_WARNING "No OOB scheme defined for oobsize %d\n",
1529 mtd->oobsize);
1530 /* To prevent kernel oops */
1531 this->autooob = &onenand_oob_32;
1532 break;
1533 }
1534
1535 memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo));
1536
1537 /* Fill in remaining MTD driver data */
1538 mtd->type = MTD_NANDFLASH;
1539 mtd->flags = MTD_CAP_NANDFLASH | MTD_ECC;
1540 mtd->ecctype = MTD_ECC_SW;
1541 mtd->erase = onenand_erase;
1542 mtd->point = NULL;
1543 mtd->unpoint = NULL;
1544 mtd->read = onenand_read;
1545 mtd->write = onenand_write;
1546 mtd->read_ecc = onenand_read_ecc;
1547 mtd->write_ecc = onenand_write_ecc;
1548 mtd->read_oob = onenand_read_oob;
1549 mtd->write_oob = onenand_write_oob;
1550 mtd->readv = NULL;
1551 mtd->readv_ecc = NULL;
1552 mtd->writev = onenand_writev;
1553 mtd->writev_ecc = onenand_writev_ecc;
1554 mtd->sync = onenand_sync;
1555 mtd->lock = NULL;
1556 mtd->unlock = onenand_unlock;
1557 mtd->suspend = onenand_suspend;
1558 mtd->resume = onenand_resume;
1559 mtd->block_isbad = onenand_block_isbad;
1560 mtd->block_markbad = onenand_block_markbad;
1561 mtd->owner = THIS_MODULE;
1562
1563 /* Unlock whole block */
1564 mtd->unlock(mtd, 0x0, this->chipsize);
1565
1566 return this->scan_bbt(mtd);
1567}
1568
1569/**
1570 * onenand_release - [OneNAND Interface] Free resources held by the OneNAND device
1571 * @param mtd MTD device structure
1572 */
1573void onenand_release(struct mtd_info *mtd)
1574{
1575#ifdef CONFIG_MTD_PARTITIONS
1576 /* Deregister partitions */
1577 del_mtd_partitions (mtd);
1578#endif
1579 /* Deregister the device */
1580 del_mtd_device (mtd);
1581}
1582
1583EXPORT_SYMBOL_GPL(onenand_scan);
1584EXPORT_SYMBOL_GPL(onenand_release);
1585
1586MODULE_LICENSE("GPL");
1587MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
1588MODULE_DESCRIPTION("Generic OneNAND flash driver code");
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
new file mode 100644
index 000000000000..f40190f499e1
--- /dev/null
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -0,0 +1,246 @@
1/*
2 * linux/drivers/mtd/onenand/onenand_bbt.c
3 *
4 * Bad Block Table support for the OneNAND driver
5 *
6 * Copyright(c) 2005 Samsung Electronics
7 * Kyungmin Park <kyungmin.park@samsung.com>
8 *
9 * Derived from nand_bbt.c
10 *
11 * TODO:
12 * Split BBT core and chip specific BBT.
13 */
14
15#include <linux/slab.h>
16#include <linux/mtd/mtd.h>
17#include <linux/mtd/onenand.h>
18#include <linux/mtd/compatmac.h>
19
20/**
21 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
22 * @param buf the buffer to search
23 * @param len the length of buffer to search
24 * @param paglen the pagelength
25 * @param td search pattern descriptor
26 *
27 * Check for a pattern at the given place. Used to search bad block
28 * tables and good / bad block identifiers. Same as check_pattern, but
29 * no optional empty check and the pattern is expected to start
30 * at offset 0.
31 *
32 */
33static int check_short_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
34{
35 int i;
36 uint8_t *p = buf;
37
38 /* Compare the pattern */
39 for (i = 0; i < td->len; i++) {
40 if (p[i] != td->pattern[i])
41 return -1;
42 }
43 return 0;
44}
45
46/**
47 * create_bbt - [GENERIC] Create a bad block table by scanning the device
48 * @param mtd MTD device structure
49 * @param buf temporary buffer
50 * @param bd descriptor for the good/bad block search pattern
51 * @param chip create the table for a specific chip, -1 read all chips.
52 * Applies only if NAND_BBT_PERCHIP option is set
53 *
54 * Create a bad block table by scanning the device
55 * for the given good/bad block identify pattern
56 */
57static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip)
58{
59 struct onenand_chip *this = mtd->priv;
60 struct bbm_info *bbm = this->bbm;
61 int i, j, numblocks, len, scanlen;
62 int startblock;
63 loff_t from;
64 size_t readlen, ooblen;
65
66 printk(KERN_INFO "Scanning device for bad blocks\n");
67
68 len = 1;
69
70 /* We need only read few bytes from the OOB area */
71 scanlen = ooblen = 0;
72 readlen = bd->len;
73
74 /* chip == -1 case only */
75 /* Note that numblocks is 2 * (real numblocks) here;
76 * see i += 2 below as it makses shifting and masking less painful
77 */
78 numblocks = mtd->size >> (bbm->bbt_erase_shift - 1);
79 startblock = 0;
80 from = 0;
81
82 for (i = startblock; i < numblocks; ) {
83 int ret;
84
85 for (j = 0; j < len; j++) {
86 size_t retlen;
87
88 /* No need to read pages fully,
89 * just read required OOB bytes */
90 ret = mtd->read_oob(mtd, from + j * mtd->oobblock + bd->offs,
91 readlen, &retlen, &buf[0]);
92
93 if (ret)
94 return ret;
95
96 if (check_short_pattern(&buf[j * scanlen], scanlen, mtd->oobblock, bd)) {
97 bbm->bbt[i >> 3] |= 0x03 << (i & 0x6);
98 printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
99 i >> 1, (unsigned int) from);
100 break;
101 }
102 }
103 i += 2;
104 from += (1 << bbm->bbt_erase_shift);
105 }
106
107 return 0;
108}
109
110
111/**
112 * onenand_memory_bbt - [GENERIC] create a memory based bad block table
113 * @param mtd MTD device structure
114 * @param bd descriptor for the good/bad block search pattern
115 *
116 * The function creates a memory based bbt by scanning the device
117 * for manufacturer / software marked good / bad blocks
118 */
119static inline int onenand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
120{
121 unsigned char data_buf[MAX_ONENAND_PAGESIZE];
122
123 bd->options &= ~NAND_BBT_SCANEMPTY;
124 return create_bbt(mtd, data_buf, bd, -1);
125}
126
127/**
128 * onenand_isbad_bbt - [OneNAND Interface] Check if a block is bad
129 * @param mtd MTD device structure
130 * @param offs offset in the device
131 * @param allowbbt allow access to bad block table region
132 */
133static int onenand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
134{
135 struct onenand_chip *this = mtd->priv;
136 struct bbm_info *bbm = this->bbm;
137 int block;
138 uint8_t res;
139
140 /* Get block number * 2 */
141 block = (int) (offs >> (bbm->bbt_erase_shift - 1));
142 res = (bbm->bbt[block >> 3] >> (block & 0x06)) & 0x03;
143
144 DEBUG(MTD_DEBUG_LEVEL2, "onenand_isbad_bbt: bbt info for offs 0x%08x: (block %d) 0x%02x\n",
145 (unsigned int) offs, block >> 1, res);
146
147 switch ((int) res) {
148 case 0x00: return 0;
149 case 0x01: return 1;
150 case 0x02: return allowbbt ? 0 : 1;
151 }
152
153 return 1;
154}
155
156/**
157 * onenand_scan_bbt - [OneNAND Interface] scan, find, read and maybe create bad block table(s)
158 * @param mtd MTD device structure
159 * @param bd descriptor for the good/bad block search pattern
160 *
161 * The function checks, if a bad block table(s) is/are already
162 * available. If not it scans the device for manufacturer
163 * marked good / bad blocks and writes the bad block table(s) to
164 * the selected place.
165 *
166 * The bad block table memory is allocated here. It must be freed
167 * by calling the onenand_free_bbt function.
168 *
169 */
170int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
171{
172 struct onenand_chip *this = mtd->priv;
173 struct bbm_info *bbm = this->bbm;
174 int len, ret = 0;
175
176 len = mtd->size >> (this->erase_shift + 2);
177 /* Allocate memory (2bit per block) */
178 bbm->bbt = kmalloc(len, GFP_KERNEL);
179 if (!bbm->bbt) {
180 printk(KERN_ERR "onenand_scan_bbt: Out of memory\n");
181 return -ENOMEM;
182 }
183 /* Clear the memory bad block table */
184 memset(bbm->bbt, 0x00, len);
185
186 /* Set the bad block position */
187 bbm->badblockpos = ONENAND_BADBLOCK_POS;
188
189 /* Set erase shift */
190 bbm->bbt_erase_shift = this->erase_shift;
191
192 if (!bbm->isbad_bbt)
193 bbm->isbad_bbt = onenand_isbad_bbt;
194
195 /* Scan the device to build a memory based bad block table */
196 if ((ret = onenand_memory_bbt(mtd, bd))) {
197 printk(KERN_ERR "onenand_scan_bbt: Can't scan flash and build the RAM-based BBT\n");
198 kfree(bbm->bbt);
199 bbm->bbt = NULL;
200 }
201
202 return ret;
203}
204
205/*
206 * Define some generic bad / good block scan pattern which are used
207 * while scanning a device for factory marked good / bad blocks.
208 */
209static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
210
211static struct nand_bbt_descr largepage_memorybased = {
212 .options = 0,
213 .offs = 0,
214 .len = 2,
215 .pattern = scan_ff_pattern,
216};
217
218/**
219 * onenand_default_bbt - [OneNAND Interface] Select a default bad block table for the device
220 * @param mtd MTD device structure
221 *
222 * This function selects the default bad block table
223 * support for the device and calls the onenand_scan_bbt function
224 */
225int onenand_default_bbt(struct mtd_info *mtd)
226{
227 struct onenand_chip *this = mtd->priv;
228 struct bbm_info *bbm;
229
230 this->bbm = kmalloc(sizeof(struct bbm_info), GFP_KERNEL);
231 if (!this->bbm)
232 return -ENOMEM;
233
234 bbm = this->bbm;
235
236 memset(bbm, 0, sizeof(struct bbm_info));
237
238 /* 1KB page has same configuration as 2KB page */
239 if (!bbm->badblock_pattern)
240 bbm->badblock_pattern = &largepage_memorybased;
241
242 return onenand_scan_bbt(mtd, bbm->badblock_pattern);
243}
244
245EXPORT_SYMBOL(onenand_scan_bbt);
246EXPORT_SYMBOL(onenand_default_bbt);
diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c
index 13f9e992bef8..7b7ca5ab5ae4 100644
--- a/drivers/mtd/redboot.c
+++ b/drivers/mtd/redboot.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: redboot.c,v 1.17 2004/11/22 11:33:56 ijc Exp $ 2 * $Id: redboot.c,v 1.18 2005/11/07 11:14:21 gleixner Exp $
3 * 3 *
4 * Parse RedBoot-style Flash Image System (FIS) tables and 4 * Parse RedBoot-style Flash Image System (FIS) tables and
5 * produce a Linux partition array to match. 5 * produce a Linux partition array to match.
@@ -39,7 +39,7 @@ static inline int redboot_checksum(struct fis_image_desc *img)
39 return 1; 39 return 1;
40} 40}
41 41
42static int parse_redboot_partitions(struct mtd_info *master, 42static int parse_redboot_partitions(struct mtd_info *master,
43 struct mtd_partition **pparts, 43 struct mtd_partition **pparts,
44 unsigned long fis_origin) 44 unsigned long fis_origin)
45{ 45{
diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
new file mode 100644
index 000000000000..041ee59ea77d
--- /dev/null
+++ b/drivers/mtd/rfd_ftl.c
@@ -0,0 +1,855 @@
1/*
2 * rfd_ftl.c -- resident flash disk (flash translation layer)
3 *
4 * Copyright (C) 2005 Sean Young <sean@mess.org>
5 *
6 * $Id: rfd_ftl.c,v 1.5 2005/11/07 11:14:21 gleixner Exp $
7 *
8 * This type of flash translation layer (FTL) is used by the Embedded BIOS
9 * by General Software. It is known as the Resident Flash Disk (RFD), see:
10 *
11 * http://www.gensw.com/pages/prod/bios/rfd.htm
12 *
13 * based on ftl.c
14 */
15
16#include <linux/hdreg.h>
17#include <linux/init.h>
18#include <linux/mtd/blktrans.h>
19#include <linux/mtd/mtd.h>
20#include <linux/vmalloc.h>
21
22#include <asm/types.h>
23
24#define const_cpu_to_le16 __constant_cpu_to_le16
25
26static int block_size = 0;
27module_param(block_size, int, 0);
28MODULE_PARM_DESC(block_size, "Block size to use by RFD, defaults to erase unit size");
29
30#define PREFIX "rfd_ftl: "
31
32/* Major device # for FTL device */
33
34/* A request for this major has been sent to device@lanana.org */
35#ifndef RFD_FTL_MAJOR
36#define RFD_FTL_MAJOR 95
37#endif
38
39/* Maximum number of partitions in an FTL region */
40#define PART_BITS 4
41
42/* An erase unit should start with this value */
43#define RFD_MAGIC 0x9193
44
45/* the second value is 0xffff or 0xffc8; function unknown */
46
47/* the third value is always 0xffff, ignored */
48
49/* next is an array of mapping for each corresponding sector */
50#define HEADER_MAP_OFFSET 3
51#define SECTOR_DELETED 0x0000
52#define SECTOR_ZERO 0xfffe
53#define SECTOR_FREE 0xffff
54
55#define SECTOR_SIZE 512
56
57#define SECTORS_PER_TRACK 63
58
59struct block {
60 enum {
61 BLOCK_OK,
62 BLOCK_ERASING,
63 BLOCK_ERASED,
64 BLOCK_FAILED
65 } state;
66 int free_sectors;
67 int used_sectors;
68 int erases;
69 u_long offset;
70};
71
72struct partition {
73 struct mtd_blktrans_dev mbd;
74
75 u_int block_size; /* size of erase unit */
76 u_int total_blocks; /* number of erase units */
77 u_int header_sectors_per_block; /* header sectors in erase unit */
78 u_int data_sectors_per_block; /* data sectors in erase unit */
79 u_int sector_count; /* sectors in translated disk */
80 u_int header_size; /* bytes in header sector */
81 int reserved_block; /* block next up for reclaim */
82 int current_block; /* block to write to */
83 u16 *header_cache; /* cached header */
84
85 int is_reclaiming;
86 int cylinders;
87 int errors;
88 u_long *sector_map;
89 struct block *blocks;
90};
91
92static int rfd_ftl_writesect(struct mtd_blktrans_dev *dev, u_long sector, char *buf);
93
94static int build_block_map(struct partition *part, int block_no)
95{
96 struct block *block = &part->blocks[block_no];
97 int i;
98
99 block->offset = part->block_size * block_no;
100
101 if (le16_to_cpu(part->header_cache[0]) != RFD_MAGIC) {
102 block->state = BLOCK_ERASED; /* assumption */
103 block->free_sectors = part->data_sectors_per_block;
104 part->reserved_block = block_no;
105 return 1;
106 }
107
108 block->state = BLOCK_OK;
109
110 for (i=0; i<part->data_sectors_per_block; i++) {
111 u16 entry;
112
113 entry = le16_to_cpu(part->header_cache[HEADER_MAP_OFFSET + i]);
114
115 if (entry == SECTOR_DELETED)
116 continue;
117
118 if (entry == SECTOR_FREE) {
119 block->free_sectors++;
120 continue;
121 }
122
123 if (entry == SECTOR_ZERO)
124 entry = 0;
125
126 if (entry >= part->sector_count) {
127 printk(KERN_NOTICE PREFIX
128 "'%s': unit #%d: entry %d corrupt, "
129 "sector %d out of range\n",
130 part->mbd.mtd->name, block_no, i, entry);
131 continue;
132 }
133
134 if (part->sector_map[entry] != -1) {
135 printk(KERN_NOTICE PREFIX
136 "'%s': more than one entry for sector %d\n",
137 part->mbd.mtd->name, entry);
138 part->errors = 1;
139 continue;
140 }
141
142 part->sector_map[entry] = block->offset +
143 (i + part->header_sectors_per_block) * SECTOR_SIZE;
144
145 block->used_sectors++;
146 }
147
148 if (block->free_sectors == part->data_sectors_per_block)
149 part->reserved_block = block_no;
150
151 return 0;
152}
153
154static int scan_header(struct partition *part)
155{
156 int sectors_per_block;
157 int i, rc = -ENOMEM;
158 int blocks_found;
159 size_t retlen;
160
161 sectors_per_block = part->block_size / SECTOR_SIZE;
162 part->total_blocks = part->mbd.mtd->size / part->block_size;
163
164 if (part->total_blocks < 2)
165 return -ENOENT;
166
167 /* each erase block has three bytes header, followed by the map */
168 part->header_sectors_per_block =
169 ((HEADER_MAP_OFFSET + sectors_per_block) *
170 sizeof(u16) + SECTOR_SIZE - 1) / SECTOR_SIZE;
171
172 part->data_sectors_per_block = sectors_per_block -
173 part->header_sectors_per_block;
174
175 part->header_size = (HEADER_MAP_OFFSET +
176 part->data_sectors_per_block) * sizeof(u16);
177
178 part->cylinders = (part->data_sectors_per_block *
179 (part->total_blocks - 1) - 1) / SECTORS_PER_TRACK;
180
181 part->sector_count = part->cylinders * SECTORS_PER_TRACK;
182
183 part->current_block = -1;
184 part->reserved_block = -1;
185 part->is_reclaiming = 0;
186
187 part->header_cache = kmalloc(part->header_size, GFP_KERNEL);
188 if (!part->header_cache)
189 goto err;
190
191 part->blocks = kcalloc(part->total_blocks, sizeof(struct block),
192 GFP_KERNEL);
193 if (!part->blocks)
194 goto err;
195
196 part->sector_map = vmalloc(part->sector_count * sizeof(u_long));
197 if (!part->sector_map) {
198 printk(KERN_ERR PREFIX "'%s': unable to allocate memory for "
199 "sector map", part->mbd.mtd->name);
200 goto err;
201 }
202
203 for (i=0; i<part->sector_count; i++)
204 part->sector_map[i] = -1;
205
206 for (i=0, blocks_found=0; i<part->total_blocks; i++) {
207 rc = part->mbd.mtd->read(part->mbd.mtd,
208 i * part->block_size, part->header_size,
209 &retlen, (u_char*)part->header_cache);
210
211 if (!rc && retlen != part->header_size)
212 rc = -EIO;
213
214 if (rc)
215 goto err;
216
217 if (!build_block_map(part, i))
218 blocks_found++;
219 }
220
221 if (blocks_found == 0) {
222 printk(KERN_NOTICE PREFIX "no RFD magic found in '%s'\n",
223 part->mbd.mtd->name);
224 rc = -ENOENT;
225 goto err;
226 }
227
228 if (part->reserved_block == -1) {
229 printk(KERN_NOTICE PREFIX "'%s': no empty erase unit found\n",
230 part->mbd.mtd->name);
231
232 part->errors = 1;
233 }
234
235 return 0;
236
237err:
238 vfree(part->sector_map);
239 kfree(part->header_cache);
240 kfree(part->blocks);
241
242 return rc;
243}
244
245static int rfd_ftl_readsect(struct mtd_blktrans_dev *dev, u_long sector, char *buf)
246{
247 struct partition *part = (struct partition*)dev;
248 u_long addr;
249 size_t retlen;
250 int rc;
251
252 if (sector >= part->sector_count)
253 return -EIO;
254
255 addr = part->sector_map[sector];
256 if (addr != -1) {
257 rc = part->mbd.mtd->read(part->mbd.mtd, addr, SECTOR_SIZE,
258 &retlen, (u_char*)buf);
259 if (!rc && retlen != SECTOR_SIZE)
260 rc = -EIO;
261
262 if (rc) {
263 printk(KERN_WARNING PREFIX "error reading '%s' at "
264 "0x%lx\n", part->mbd.mtd->name, addr);
265 return rc;
266 }
267 } else
268 memset(buf, 0, SECTOR_SIZE);
269
270 return 0;
271}
272
273static void erase_callback(struct erase_info *erase)
274{
275 struct partition *part;
276 u16 magic;
277 int i, rc;
278 size_t retlen;
279
280 part = (struct partition*)erase->priv;
281
282 i = erase->addr / part->block_size;
283 if (i >= part->total_blocks || part->blocks[i].offset != erase->addr) {
284 printk(KERN_ERR PREFIX "erase callback for unknown offset %x "
285 "on '%s'\n", erase->addr, part->mbd.mtd->name);
286 return;
287 }
288
289 if (erase->state != MTD_ERASE_DONE) {
290 printk(KERN_WARNING PREFIX "erase failed at 0x%x on '%s', "
291 "state %d\n", erase->addr,
292 part->mbd.mtd->name, erase->state);
293
294 part->blocks[i].state = BLOCK_FAILED;
295 part->blocks[i].free_sectors = 0;
296 part->blocks[i].used_sectors = 0;
297
298 kfree(erase);
299
300 return;
301 }
302
303 magic = const_cpu_to_le16(RFD_MAGIC);
304
305 part->blocks[i].state = BLOCK_ERASED;
306 part->blocks[i].free_sectors = part->data_sectors_per_block;
307 part->blocks[i].used_sectors = 0;
308 part->blocks[i].erases++;
309
310 rc = part->mbd.mtd->write(part->mbd.mtd,
311 part->blocks[i].offset, sizeof(magic), &retlen,
312 (u_char*)&magic);
313
314 if (!rc && retlen != sizeof(magic))
315 rc = -EIO;
316
317 if (rc) {
318 printk(KERN_NOTICE PREFIX "'%s': unable to write RFD "
319 "header at 0x%lx\n",
320 part->mbd.mtd->name,
321 part->blocks[i].offset);
322 part->blocks[i].state = BLOCK_FAILED;
323 }
324 else
325 part->blocks[i].state = BLOCK_OK;
326
327 kfree(erase);
328}
329
330static int erase_block(struct partition *part, int block)
331{
332 struct erase_info *erase;
333 int rc = -ENOMEM;
334
335 erase = kmalloc(sizeof(struct erase_info), GFP_KERNEL);
336 if (!erase)
337 goto err;
338
339 erase->mtd = part->mbd.mtd;
340 erase->callback = erase_callback;
341 erase->addr = part->blocks[block].offset;
342 erase->len = part->block_size;
343 erase->priv = (u_long)part;
344
345 part->blocks[block].state = BLOCK_ERASING;
346 part->blocks[block].free_sectors = 0;
347
348 rc = part->mbd.mtd->erase(part->mbd.mtd, erase);
349
350 if (rc) {
351 printk(KERN_WARNING PREFIX "erase of region %x,%x on '%s' "
352 "failed\n", erase->addr, erase->len,
353 part->mbd.mtd->name);
354 kfree(erase);
355 }
356
357err:
358 return rc;
359}
360
361static int move_block_contents(struct partition *part, int block_no, u_long *old_sector)
362{
363 void *sector_data;
364 u16 *map;
365 size_t retlen;
366 int i, rc = -ENOMEM;
367
368 part->is_reclaiming = 1;
369
370 sector_data = kmalloc(SECTOR_SIZE, GFP_KERNEL);
371 if (!sector_data)
372 goto err3;
373
374 map = kmalloc(part->header_size, GFP_KERNEL);
375 if (!map)
376 goto err2;
377
378 rc = part->mbd.mtd->read(part->mbd.mtd,
379 part->blocks[block_no].offset, part->header_size,
380 &retlen, (u_char*)map);
381
382 if (!rc && retlen != part->header_size)
383 rc = -EIO;
384
385 if (rc) {
386 printk(KERN_NOTICE PREFIX "error reading '%s' at "
387 "0x%lx\n", part->mbd.mtd->name,
388 part->blocks[block_no].offset);
389
390 goto err;
391 }
392
393 for (i=0; i<part->data_sectors_per_block; i++) {
394 u16 entry = le16_to_cpu(map[HEADER_MAP_OFFSET + i]);
395 u_long addr;
396
397
398 if (entry == SECTOR_FREE || entry == SECTOR_DELETED)
399 continue;
400
401 if (entry == SECTOR_ZERO)
402 entry = 0;
403
404 /* already warned about and ignored in build_block_map() */
405 if (entry >= part->sector_count)
406 continue;
407
408 addr = part->blocks[block_no].offset +
409 (i + part->header_sectors_per_block) * SECTOR_SIZE;
410
411 if (*old_sector == addr) {
412 *old_sector = -1;
413 if (!part->blocks[block_no].used_sectors--) {
414 rc = erase_block(part, block_no);
415 break;
416 }
417 continue;
418 }
419 rc = part->mbd.mtd->read(part->mbd.mtd, addr,
420 SECTOR_SIZE, &retlen, sector_data);
421
422 if (!rc && retlen != SECTOR_SIZE)
423 rc = -EIO;
424
425 if (rc) {
426 printk(KERN_NOTICE PREFIX "'%s': Unable to "
427 "read sector for relocation\n",
428 part->mbd.mtd->name);
429
430 goto err;
431 }
432
433 rc = rfd_ftl_writesect((struct mtd_blktrans_dev*)part,
434 entry, sector_data);
435
436 if (rc)
437 goto err;
438 }
439
440err:
441 kfree(map);
442err2:
443 kfree(sector_data);
444err3:
445 part->is_reclaiming = 0;
446
447 return rc;
448}
449
450static int reclaim_block(struct partition *part, u_long *old_sector)
451{
452 int block, best_block, score, old_sector_block;
453 int rc;
454
455 /* we have a race if sync doesn't exist */
456 if (part->mbd.mtd->sync)
457 part->mbd.mtd->sync(part->mbd.mtd);
458
459 score = 0x7fffffff; /* MAX_INT */
460 best_block = -1;
461 if (*old_sector != -1)
462 old_sector_block = *old_sector / part->block_size;
463 else
464 old_sector_block = -1;
465
466 for (block=0; block<part->total_blocks; block++) {
467 int this_score;
468
469 if (block == part->reserved_block)
470 continue;
471
472 /*
473 * Postpone reclaiming if there is a free sector as
474 * more removed sectors is more efficient (have to move
475 * less).
476 */
477 if (part->blocks[block].free_sectors)
478 return 0;
479
480 this_score = part->blocks[block].used_sectors;
481
482 if (block == old_sector_block)
483 this_score--;
484 else {
485 /* no point in moving a full block */
486 if (part->blocks[block].used_sectors ==
487 part->data_sectors_per_block)
488 continue;
489 }
490
491 this_score += part->blocks[block].erases;
492
493 if (this_score < score) {
494 best_block = block;
495 score = this_score;
496 }
497 }
498
499 if (best_block == -1)
500 return -ENOSPC;
501
502 part->current_block = -1;
503 part->reserved_block = best_block;
504
505 pr_debug("reclaim_block: reclaiming block #%d with %d used "
506 "%d free sectors\n", best_block,
507 part->blocks[best_block].used_sectors,
508 part->blocks[best_block].free_sectors);
509
510 if (part->blocks[best_block].used_sectors)
511 rc = move_block_contents(part, best_block, old_sector);
512 else
513 rc = erase_block(part, best_block);
514
515 return rc;
516}
517
518/*
519 * IMPROVE: It would be best to choose the block with the most deleted sectors,
520 * because if we fill that one up first it'll have the most chance of having
521 * the least live sectors at reclaim.
522 */
523static int find_free_block(const struct partition *part)
524{
525 int block, stop;
526
527 block = part->current_block == -1 ?
528 jiffies % part->total_blocks : part->current_block;
529 stop = block;
530
531 do {
532 if (part->blocks[block].free_sectors &&
533 block != part->reserved_block)
534 return block;
535
536 if (++block >= part->total_blocks)
537 block = 0;
538
539 } while (block != stop);
540
541 return -1;
542}
543
544static int find_writeable_block(struct partition *part, u_long *old_sector)
545{
546 int rc, block;
547 size_t retlen;
548
549 block = find_free_block(part);
550
551 if (block == -1) {
552 if (!part->is_reclaiming) {
553 rc = reclaim_block(part, old_sector);
554 if (rc)
555 goto err;
556
557 block = find_free_block(part);
558 }
559
560 if (block == -1) {
561 rc = -ENOSPC;
562 goto err;
563 }
564 }
565
566 rc = part->mbd.mtd->read(part->mbd.mtd, part->blocks[block].offset,
567 part->header_size, &retlen, (u_char*)part->header_cache);
568
569 if (!rc && retlen != part->header_size)
570 rc = -EIO;
571
572 if (rc) {
573 printk(KERN_NOTICE PREFIX "'%s': unable to read header at "
574 "0x%lx\n", part->mbd.mtd->name,
575 part->blocks[block].offset);
576 goto err;
577 }
578
579 part->current_block = block;
580
581err:
582 return rc;
583}
584
585static int mark_sector_deleted(struct partition *part, u_long old_addr)
586{
587 int block, offset, rc;
588 u_long addr;
589 size_t retlen;
590 u16 del = const_cpu_to_le16(SECTOR_DELETED);
591
592 block = old_addr / part->block_size;
593 offset = (old_addr % part->block_size) / SECTOR_SIZE -
594 part->header_sectors_per_block;
595
596 addr = part->blocks[block].offset +
597 (HEADER_MAP_OFFSET + offset) * sizeof(u16);
598 rc = part->mbd.mtd->write(part->mbd.mtd, addr,
599 sizeof(del), &retlen, (u_char*)&del);
600
601 if (!rc && retlen != sizeof(del))
602 rc = -EIO;
603
604 if (rc) {
605 printk(KERN_WARNING PREFIX "error writing '%s' at "
606 "0x%lx\n", part->mbd.mtd->name, addr);
607 if (rc)
608 goto err;
609 }
610 if (block == part->current_block)
611 part->header_cache[offset + HEADER_MAP_OFFSET] = del;
612
613 part->blocks[block].used_sectors--;
614
615 if (!part->blocks[block].used_sectors &&
616 !part->blocks[block].free_sectors)
617 rc = erase_block(part, block);
618
619err:
620 return rc;
621}
622
623static int find_free_sector(const struct partition *part, const struct block *block)
624{
625 int i, stop;
626
627 i = stop = part->data_sectors_per_block - block->free_sectors;
628
629 do {
630 if (le16_to_cpu(part->header_cache[HEADER_MAP_OFFSET + i])
631 == SECTOR_FREE)
632 return i;
633
634 if (++i == part->data_sectors_per_block)
635 i = 0;
636 }
637 while(i != stop);
638
639 return -1;
640}
641
642static int do_writesect(struct mtd_blktrans_dev *dev, u_long sector, char *buf, ulong *old_addr)
643{
644 struct partition *part = (struct partition*)dev;
645 struct block *block;
646 u_long addr;
647 int i;
648 int rc;
649 size_t retlen;
650 u16 entry;
651
652 if (part->current_block == -1 ||
653 !part->blocks[part->current_block].free_sectors) {
654
655 rc = find_writeable_block(part, old_addr);
656 if (rc)
657 goto err;
658 }
659
660 block = &part->blocks[part->current_block];
661
662 i = find_free_sector(part, block);
663
664 if (i < 0) {
665 rc = -ENOSPC;
666 goto err;
667 }
668
669 addr = (i + part->header_sectors_per_block) * SECTOR_SIZE +
670 block->offset;
671 rc = part->mbd.mtd->write(part->mbd.mtd,
672 addr, SECTOR_SIZE, &retlen, (u_char*)buf);
673
674 if (!rc && retlen != SECTOR_SIZE)
675 rc = -EIO;
676
677 if (rc) {
678 printk(KERN_WARNING PREFIX "error writing '%s' at 0x%lx\n",
679 part->mbd.mtd->name, addr);
680 if (rc)
681 goto err;
682 }
683
684 part->sector_map[sector] = addr;
685
686 entry = cpu_to_le16(sector == 0 ? SECTOR_ZERO : sector);
687
688 part->header_cache[i + HEADER_MAP_OFFSET] = entry;
689
690 addr = block->offset + (HEADER_MAP_OFFSET + i) * sizeof(u16);
691 rc = part->mbd.mtd->write(part->mbd.mtd, addr,
692 sizeof(entry), &retlen, (u_char*)&entry);
693
694 if (!rc && retlen != sizeof(entry))
695 rc = -EIO;
696
697 if (rc) {
698 printk(KERN_WARNING PREFIX "error writing '%s' at 0x%lx\n",
699 part->mbd.mtd->name, addr);
700 if (rc)
701 goto err;
702 }
703 block->used_sectors++;
704 block->free_sectors--;
705
706err:
707 return rc;
708}
709
710static int rfd_ftl_writesect(struct mtd_blktrans_dev *dev, u_long sector, char *buf)
711{
712 struct partition *part = (struct partition*)dev;
713 u_long old_addr;
714 int i;
715 int rc = 0;
716
717 pr_debug("rfd_ftl_writesect(sector=0x%lx)\n", sector);
718
719 if (part->reserved_block == -1) {
720 rc = -EACCES;
721 goto err;
722 }
723
724 if (sector >= part->sector_count) {
725 rc = -EIO;
726 goto err;
727 }
728
729 old_addr = part->sector_map[sector];
730
731 for (i=0; i<SECTOR_SIZE; i++) {
732 if (!buf[i])
733 continue;
734
735 rc = do_writesect(dev, sector, buf, &old_addr);
736 if (rc)
737 goto err;
738 break;
739 }
740
741 if (i == SECTOR_SIZE)
742 part->sector_map[sector] = -1;
743
744 if (old_addr != -1)
745 rc = mark_sector_deleted(part, old_addr);
746
747err:
748 return rc;
749}
750
751static int rfd_ftl_getgeo(struct mtd_blktrans_dev *dev, struct hd_geometry *geo)
752{
753 struct partition *part = (struct partition*)dev;
754
755 geo->heads = 1;
756 geo->sectors = SECTORS_PER_TRACK;
757 geo->cylinders = part->cylinders;
758
759 return 0;
760}
761
762static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
763{
764 struct partition *part;
765
766 if (mtd->type != MTD_NORFLASH)
767 return;
768
769 part = kcalloc(1, sizeof(struct partition), GFP_KERNEL);
770 if (!part)
771 return;
772
773 part->mbd.mtd = mtd;
774
775 if (block_size)
776 part->block_size = block_size;
777 else {
778 if (!mtd->erasesize) {
779 printk(KERN_NOTICE PREFIX "please provide block_size");
780 return;
781 }
782 else
783 part->block_size = mtd->erasesize;
784 }
785
786 if (scan_header(part) == 0) {
787 part->mbd.size = part->sector_count;
788 part->mbd.blksize = SECTOR_SIZE;
789 part->mbd.tr = tr;
790 part->mbd.devnum = -1;
791 if (!(mtd->flags & MTD_WRITEABLE))
792 part->mbd.readonly = 1;
793 else if (part->errors) {
794 printk(KERN_NOTICE PREFIX "'%s': errors found, "
795 "setting read-only", mtd->name);
796 part->mbd.readonly = 1;
797 }
798
799 printk(KERN_INFO PREFIX "name: '%s' type: %d flags %x\n",
800 mtd->name, mtd->type, mtd->flags);
801
802 if (!add_mtd_blktrans_dev((void*)part))
803 return;
804 }
805
806 kfree(part);
807}
808
809static void rfd_ftl_remove_dev(struct mtd_blktrans_dev *dev)
810{
811 struct partition *part = (struct partition*)dev;
812 int i;
813
814 for (i=0; i<part->total_blocks; i++) {
815 pr_debug("rfd_ftl_remove_dev:'%s': erase unit #%02d: %d erases\n",
816 part->mbd.mtd->name, i, part->blocks[i].erases);
817 }
818
819 del_mtd_blktrans_dev(dev);
820 vfree(part->sector_map);
821 kfree(part->header_cache);
822 kfree(part->blocks);
823 kfree(part);
824}
825
826struct mtd_blktrans_ops rfd_ftl_tr = {
827 .name = "rfd",
828 .major = RFD_FTL_MAJOR,
829 .part_bits = PART_BITS,
830 .readsect = rfd_ftl_readsect,
831 .writesect = rfd_ftl_writesect,
832 .getgeo = rfd_ftl_getgeo,
833 .add_mtd = rfd_ftl_add_mtd,
834 .remove_dev = rfd_ftl_remove_dev,
835 .owner = THIS_MODULE,
836};
837
838static int __init init_rfd_ftl(void)
839{
840 return register_mtd_blktrans(&rfd_ftl_tr);
841}
842
843static void __exit cleanup_rfd_ftl(void)
844{
845 deregister_mtd_blktrans(&rfd_ftl_tr);
846}
847
848module_init(init_rfd_ftl);
849module_exit(cleanup_rfd_ftl);
850
851MODULE_LICENSE("GPL");
852MODULE_AUTHOR("Sean Young <sean@mess.org>");
853MODULE_DESCRIPTION("Support code for RFD Flash Translation Layer, "
854 "used by General Software's Embedded BIOS");
855
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index 455ba915ede7..7488ee7f7caf 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -602,7 +602,7 @@ MODULE_DEVICE_TABLE(pci, vortex_pci_tbl);
602 First the windows. There are eight register windows, with the command 602 First the windows. There are eight register windows, with the command
603 and status registers available in each. 603 and status registers available in each.
604 */ 604 */
605#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD) 605#define EL3WINDOW(win_num) iowrite16(SelectWindow + (win_num), ioaddr + EL3_CMD)
606#define EL3_CMD 0x0e 606#define EL3_CMD 0x0e
607#define EL3_STATUS 0x0e 607#define EL3_STATUS 0x0e
608 608
@@ -776,7 +776,8 @@ struct vortex_private {
776 776
777 /* PCI configuration space information. */ 777 /* PCI configuration space information. */
778 struct device *gendev; 778 struct device *gendev;
779 char __iomem *cb_fn_base; /* CardBus function status addr space. */ 779 void __iomem *ioaddr; /* IO address space */
780 void __iomem *cb_fn_base; /* CardBus function status addr space. */
780 781
781 /* Some values here only for performance evaluation and path-coverage */ 782 /* Some values here only for performance evaluation and path-coverage */
782 int rx_nocopy, rx_copy, queued_packet, rx_csumhits; 783 int rx_nocopy, rx_copy, queued_packet, rx_csumhits;
@@ -869,12 +870,12 @@ static struct {
869/* number of ETHTOOL_GSTATS u64's */ 870/* number of ETHTOOL_GSTATS u64's */
870#define VORTEX_NUM_STATS 3 871#define VORTEX_NUM_STATS 3
871 872
872static int vortex_probe1(struct device *gendev, long ioaddr, int irq, 873static int vortex_probe1(struct device *gendev, void __iomem *ioaddr, int irq,
873 int chip_idx, int card_idx); 874 int chip_idx, int card_idx);
874static void vortex_up(struct net_device *dev); 875static void vortex_up(struct net_device *dev);
875static void vortex_down(struct net_device *dev, int final); 876static void vortex_down(struct net_device *dev, int final);
876static int vortex_open(struct net_device *dev); 877static int vortex_open(struct net_device *dev);
877static void mdio_sync(long ioaddr, int bits); 878static void mdio_sync(void __iomem *ioaddr, int bits);
878static int mdio_read(struct net_device *dev, int phy_id, int location); 879static int mdio_read(struct net_device *dev, int phy_id, int location);
879static void mdio_write(struct net_device *vp, int phy_id, int location, int value); 880static void mdio_write(struct net_device *vp, int phy_id, int location, int value);
880static void vortex_timer(unsigned long arg); 881static void vortex_timer(unsigned long arg);
@@ -887,7 +888,7 @@ static irqreturn_t vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
887static irqreturn_t boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs); 888static irqreturn_t boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs);
888static int vortex_close(struct net_device *dev); 889static int vortex_close(struct net_device *dev);
889static void dump_tx_ring(struct net_device *dev); 890static void dump_tx_ring(struct net_device *dev);
890static void update_stats(long ioaddr, struct net_device *dev); 891static void update_stats(void __iomem *ioaddr, struct net_device *dev);
891static struct net_device_stats *vortex_get_stats(struct net_device *dev); 892static struct net_device_stats *vortex_get_stats(struct net_device *dev);
892static void set_rx_mode(struct net_device *dev); 893static void set_rx_mode(struct net_device *dev);
893#ifdef CONFIG_PCI 894#ifdef CONFIG_PCI
@@ -902,14 +903,16 @@ static void set_8021q_mode(struct net_device *dev, int enable);
902/* This driver uses 'options' to pass the media type, full-duplex flag, etc. */ 903/* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
903/* Option count limit only -- unlimited interfaces are supported. */ 904/* Option count limit only -- unlimited interfaces are supported. */
904#define MAX_UNITS 8 905#define MAX_UNITS 8
905static int options[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1,}; 906static int options[MAX_UNITS] = { [0 ... MAX_UNITS-1] = -1 };
906static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1}; 907static int full_duplex[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
907static int hw_checksums[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1}; 908static int hw_checksums[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
908static int flow_ctrl[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1}; 909static int flow_ctrl[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
909static int enable_wol[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1}; 910static int enable_wol[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
911static int use_mmio[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
910static int global_options = -1; 912static int global_options = -1;
911static int global_full_duplex = -1; 913static int global_full_duplex = -1;
912static int global_enable_wol = -1; 914static int global_enable_wol = -1;
915static int global_use_mmio = -1;
913 916
914/* #define dev_alloc_skb dev_alloc_skb_debug */ 917/* #define dev_alloc_skb dev_alloc_skb_debug */
915 918
@@ -934,21 +937,25 @@ module_param(compaq_ioaddr, int, 0);
934module_param(compaq_irq, int, 0); 937module_param(compaq_irq, int, 0);
935module_param(compaq_device_id, int, 0); 938module_param(compaq_device_id, int, 0);
936module_param(watchdog, int, 0); 939module_param(watchdog, int, 0);
940module_param(global_use_mmio, int, 0);
941module_param_array(use_mmio, int, NULL, 0);
937MODULE_PARM_DESC(debug, "3c59x debug level (0-6)"); 942MODULE_PARM_DESC(debug, "3c59x debug level (0-6)");
938MODULE_PARM_DESC(options, "3c59x: Bits 0-3: media type, bit 4: bus mastering, bit 9: full duplex"); 943MODULE_PARM_DESC(options, "3c59x: Bits 0-3: media type, bit 4: bus mastering, bit 9: full duplex");
939MODULE_PARM_DESC(global_options, "3c59x: same as options, but applies to all NICs if options is unset"); 944MODULE_PARM_DESC(global_options, "3c59x: same as options, but applies to all NICs if options is unset");
940MODULE_PARM_DESC(full_duplex, "3c59x full duplex setting(s) (1)"); 945MODULE_PARM_DESC(full_duplex, "3c59x full duplex setting(s) (1)");
941MODULE_PARM_DESC(global_full_duplex, "3c59x: same as full_duplex, but applies to all NICs if options is unset"); 946MODULE_PARM_DESC(global_full_duplex, "3c59x: same as full_duplex, but applies to all NICs if full_duplex is unset");
942MODULE_PARM_DESC(hw_checksums, "3c59x Hardware checksum checking by adapter(s) (0-1)"); 947MODULE_PARM_DESC(hw_checksums, "3c59x Hardware checksum checking by adapter(s) (0-1)");
943MODULE_PARM_DESC(flow_ctrl, "3c59x 802.3x flow control usage (PAUSE only) (0-1)"); 948MODULE_PARM_DESC(flow_ctrl, "3c59x 802.3x flow control usage (PAUSE only) (0-1)");
944MODULE_PARM_DESC(enable_wol, "3c59x: Turn on Wake-on-LAN for adapter(s) (0-1)"); 949MODULE_PARM_DESC(enable_wol, "3c59x: Turn on Wake-on-LAN for adapter(s) (0-1)");
945MODULE_PARM_DESC(global_enable_wol, "3c59x: same as enable_wol, but applies to all NICs if options is unset"); 950MODULE_PARM_DESC(global_enable_wol, "3c59x: same as enable_wol, but applies to all NICs if enable_wol is unset");
946MODULE_PARM_DESC(rx_copybreak, "3c59x copy breakpoint for copy-only-tiny-frames"); 951MODULE_PARM_DESC(rx_copybreak, "3c59x copy breakpoint for copy-only-tiny-frames");
947MODULE_PARM_DESC(max_interrupt_work, "3c59x maximum events handled per interrupt"); 952MODULE_PARM_DESC(max_interrupt_work, "3c59x maximum events handled per interrupt");
948MODULE_PARM_DESC(compaq_ioaddr, "3c59x PCI I/O base address (Compaq BIOS problem workaround)"); 953MODULE_PARM_DESC(compaq_ioaddr, "3c59x PCI I/O base address (Compaq BIOS problem workaround)");
949MODULE_PARM_DESC(compaq_irq, "3c59x PCI IRQ number (Compaq BIOS problem workaround)"); 954MODULE_PARM_DESC(compaq_irq, "3c59x PCI IRQ number (Compaq BIOS problem workaround)");
950MODULE_PARM_DESC(compaq_device_id, "3c59x PCI device ID (Compaq BIOS problem workaround)"); 955MODULE_PARM_DESC(compaq_device_id, "3c59x PCI device ID (Compaq BIOS problem workaround)");
951MODULE_PARM_DESC(watchdog, "3c59x transmit timeout in milliseconds"); 956MODULE_PARM_DESC(watchdog, "3c59x transmit timeout in milliseconds");
957MODULE_PARM_DESC(global_use_mmio, "3c59x: same as use_mmio, but applies to all NICs if options is unset");
958MODULE_PARM_DESC(use_mmio, "3c59x: use memory-mapped PCI I/O resource (0-1)");
952 959
953#ifdef CONFIG_NET_POLL_CONTROLLER 960#ifdef CONFIG_NET_POLL_CONTROLLER
954static void poll_vortex(struct net_device *dev) 961static void poll_vortex(struct net_device *dev)
@@ -1029,18 +1036,19 @@ static struct eisa_driver vortex_eisa_driver = {
1029 1036
1030static int vortex_eisa_probe (struct device *device) 1037static int vortex_eisa_probe (struct device *device)
1031{ 1038{
1032 long ioaddr; 1039 void __iomem *ioaddr;
1033 struct eisa_device *edev; 1040 struct eisa_device *edev;
1034 1041
1035 edev = to_eisa_device (device); 1042 edev = to_eisa_device (device);
1036 ioaddr = edev->base_addr;
1037 1043
1038 if (!request_region(ioaddr, VORTEX_TOTAL_SIZE, DRV_NAME)) 1044 if (!request_region(edev->base_addr, VORTEX_TOTAL_SIZE, DRV_NAME))
1039 return -EBUSY; 1045 return -EBUSY;
1040 1046
1041 if (vortex_probe1(device, ioaddr, inw(ioaddr + 0xC88) >> 12, 1047 ioaddr = ioport_map(edev->base_addr, VORTEX_TOTAL_SIZE);
1048
1049 if (vortex_probe1(device, ioaddr, ioread16(ioaddr + 0xC88) >> 12,
1042 edev->id.driver_data, vortex_cards_found)) { 1050 edev->id.driver_data, vortex_cards_found)) {
1043 release_region (ioaddr, VORTEX_TOTAL_SIZE); 1051 release_region (edev->base_addr, VORTEX_TOTAL_SIZE);
1044 return -ENODEV; 1052 return -ENODEV;
1045 } 1053 }
1046 1054
@@ -1054,7 +1062,7 @@ static int vortex_eisa_remove (struct device *device)
1054 struct eisa_device *edev; 1062 struct eisa_device *edev;
1055 struct net_device *dev; 1063 struct net_device *dev;
1056 struct vortex_private *vp; 1064 struct vortex_private *vp;
1057 long ioaddr; 1065 void __iomem *ioaddr;
1058 1066
1059 edev = to_eisa_device (device); 1067 edev = to_eisa_device (device);
1060 dev = eisa_get_drvdata (edev); 1068 dev = eisa_get_drvdata (edev);
@@ -1065,11 +1073,11 @@ static int vortex_eisa_remove (struct device *device)
1065 } 1073 }
1066 1074
1067 vp = netdev_priv(dev); 1075 vp = netdev_priv(dev);
1068 ioaddr = dev->base_addr; 1076 ioaddr = vp->ioaddr;
1069 1077
1070 unregister_netdev (dev); 1078 unregister_netdev (dev);
1071 outw (TotalReset|0x14, ioaddr + EL3_CMD); 1079 iowrite16 (TotalReset|0x14, ioaddr + EL3_CMD);
1072 release_region (ioaddr, VORTEX_TOTAL_SIZE); 1080 release_region (dev->base_addr, VORTEX_TOTAL_SIZE);
1073 1081
1074 free_netdev (dev); 1082 free_netdev (dev);
1075 return 0; 1083 return 0;
@@ -1096,8 +1104,8 @@ static int __init vortex_eisa_init (void)
1096 1104
1097 /* Special code to work-around the Compaq PCI BIOS32 problem. */ 1105 /* Special code to work-around the Compaq PCI BIOS32 problem. */
1098 if (compaq_ioaddr) { 1106 if (compaq_ioaddr) {
1099 vortex_probe1(NULL, compaq_ioaddr, compaq_irq, 1107 vortex_probe1(NULL, ioport_map(compaq_ioaddr, VORTEX_TOTAL_SIZE),
1100 compaq_device_id, vortex_cards_found++); 1108 compaq_irq, compaq_device_id, vortex_cards_found++);
1101 } 1109 }
1102 1110
1103 return vortex_cards_found - orig_cards_found + eisa_found; 1111 return vortex_cards_found - orig_cards_found + eisa_found;
@@ -1107,15 +1115,32 @@ static int __init vortex_eisa_init (void)
1107static int __devinit vortex_init_one (struct pci_dev *pdev, 1115static int __devinit vortex_init_one (struct pci_dev *pdev,
1108 const struct pci_device_id *ent) 1116 const struct pci_device_id *ent)
1109{ 1117{
1110 int rc; 1118 int rc, unit, pci_bar;
1119 struct vortex_chip_info *vci;
1120 void __iomem *ioaddr;
1111 1121
1112 /* wake up and enable device */ 1122 /* wake up and enable device */
1113 rc = pci_enable_device (pdev); 1123 rc = pci_enable_device (pdev);
1114 if (rc < 0) 1124 if (rc < 0)
1115 goto out; 1125 goto out;
1116 1126
1117 rc = vortex_probe1 (&pdev->dev, pci_resource_start (pdev, 0), 1127 unit = vortex_cards_found;
1118 pdev->irq, ent->driver_data, vortex_cards_found); 1128
1129 if (global_use_mmio < 0 && (unit >= MAX_UNITS || use_mmio[unit] < 0)) {
1130 /* Determine the default if the user didn't override us */
1131 vci = &vortex_info_tbl[ent->driver_data];
1132 pci_bar = vci->drv_flags & (IS_CYCLONE | IS_TORNADO) ? 1 : 0;
1133 } else if (unit < MAX_UNITS && use_mmio[unit] >= 0)
1134 pci_bar = use_mmio[unit] ? 1 : 0;
1135 else
1136 pci_bar = global_use_mmio ? 1 : 0;
1137
1138 ioaddr = pci_iomap(pdev, pci_bar, 0);
1139 if (!ioaddr) /* If mapping fails, fall-back to BAR 0... */
1140 ioaddr = pci_iomap(pdev, 0, 0);
1141
1142 rc = vortex_probe1(&pdev->dev, ioaddr, pdev->irq,
1143 ent->driver_data, unit);
1119 if (rc < 0) { 1144 if (rc < 0) {
1120 pci_disable_device (pdev); 1145 pci_disable_device (pdev);
1121 goto out; 1146 goto out;
@@ -1134,7 +1159,7 @@ out:
1134 * NOTE: pdev can be NULL, for the case of a Compaq device 1159 * NOTE: pdev can be NULL, for the case of a Compaq device
1135 */ 1160 */
1136static int __devinit vortex_probe1(struct device *gendev, 1161static int __devinit vortex_probe1(struct device *gendev,
1137 long ioaddr, int irq, 1162 void __iomem *ioaddr, int irq,
1138 int chip_idx, int card_idx) 1163 int chip_idx, int card_idx)
1139{ 1164{
1140 struct vortex_private *vp; 1165 struct vortex_private *vp;
@@ -1202,15 +1227,16 @@ static int __devinit vortex_probe1(struct device *gendev,
1202 if (print_info) 1227 if (print_info)
1203 printk (KERN_INFO "See Documentation/networking/vortex.txt\n"); 1228 printk (KERN_INFO "See Documentation/networking/vortex.txt\n");
1204 1229
1205 printk(KERN_INFO "%s: 3Com %s %s at 0x%lx. Vers " DRV_VERSION "\n", 1230 printk(KERN_INFO "%s: 3Com %s %s at %p. Vers " DRV_VERSION "\n",
1206 print_name, 1231 print_name,
1207 pdev ? "PCI" : "EISA", 1232 pdev ? "PCI" : "EISA",
1208 vci->name, 1233 vci->name,
1209 ioaddr); 1234 ioaddr);
1210 1235
1211 dev->base_addr = ioaddr; 1236 dev->base_addr = (unsigned long)ioaddr;
1212 dev->irq = irq; 1237 dev->irq = irq;
1213 dev->mtu = mtu; 1238 dev->mtu = mtu;
1239 vp->ioaddr = ioaddr;
1214 vp->large_frames = mtu > 1500; 1240 vp->large_frames = mtu > 1500;
1215 vp->drv_flags = vci->drv_flags; 1241 vp->drv_flags = vci->drv_flags;
1216 vp->has_nway = (vci->drv_flags & HAS_NWAY) ? 1 : 0; 1242 vp->has_nway = (vci->drv_flags & HAS_NWAY) ? 1 : 0;
@@ -1226,7 +1252,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1226 if (pdev) { 1252 if (pdev) {
1227 /* EISA resources already marked, so only PCI needs to do this here */ 1253 /* EISA resources already marked, so only PCI needs to do this here */
1228 /* Ignore return value, because Cardbus drivers already allocate for us */ 1254 /* Ignore return value, because Cardbus drivers already allocate for us */
1229 if (request_region(ioaddr, vci->io_size, print_name) != NULL) 1255 if (request_region(dev->base_addr, vci->io_size, print_name) != NULL)
1230 vp->must_free_region = 1; 1256 vp->must_free_region = 1;
1231 1257
1232 /* enable bus-mastering if necessary */ 1258 /* enable bus-mastering if necessary */
@@ -1316,14 +1342,14 @@ static int __devinit vortex_probe1(struct device *gendev,
1316 1342
1317 for (i = 0; i < 0x40; i++) { 1343 for (i = 0; i < 0x40; i++) {
1318 int timer; 1344 int timer;
1319 outw(base + i, ioaddr + Wn0EepromCmd); 1345 iowrite16(base + i, ioaddr + Wn0EepromCmd);
1320 /* Pause for at least 162 us. for the read to take place. */ 1346 /* Pause for at least 162 us. for the read to take place. */
1321 for (timer = 10; timer >= 0; timer--) { 1347 for (timer = 10; timer >= 0; timer--) {
1322 udelay(162); 1348 udelay(162);
1323 if ((inw(ioaddr + Wn0EepromCmd) & 0x8000) == 0) 1349 if ((ioread16(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
1324 break; 1350 break;
1325 } 1351 }
1326 eeprom[i] = inw(ioaddr + Wn0EepromData); 1352 eeprom[i] = ioread16(ioaddr + Wn0EepromData);
1327 } 1353 }
1328 } 1354 }
1329 for (i = 0; i < 0x18; i++) 1355 for (i = 0; i < 0x18; i++)
@@ -1338,6 +1364,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1338 printk(" ***INVALID CHECKSUM %4.4x*** ", checksum); 1364 printk(" ***INVALID CHECKSUM %4.4x*** ", checksum);
1339 for (i = 0; i < 3; i++) 1365 for (i = 0; i < 3; i++)
1340 ((u16 *)dev->dev_addr)[i] = htons(eeprom[i + 10]); 1366 ((u16 *)dev->dev_addr)[i] = htons(eeprom[i + 10]);
1367 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
1341 if (print_info) { 1368 if (print_info) {
1342 for (i = 0; i < 6; i++) 1369 for (i = 0; i < 6; i++)
1343 printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]); 1370 printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
@@ -1351,7 +1378,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1351 } 1378 }
1352 EL3WINDOW(2); 1379 EL3WINDOW(2);
1353 for (i = 0; i < 6; i++) 1380 for (i = 0; i < 6; i++)
1354 outb(dev->dev_addr[i], ioaddr + i); 1381 iowrite8(dev->dev_addr[i], ioaddr + i);
1355 1382
1356#ifdef __sparc__ 1383#ifdef __sparc__
1357 if (print_info) 1384 if (print_info)
@@ -1366,7 +1393,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1366#endif 1393#endif
1367 1394
1368 EL3WINDOW(4); 1395 EL3WINDOW(4);
1369 step = (inb(ioaddr + Wn4_NetDiag) & 0x1e) >> 1; 1396 step = (ioread8(ioaddr + Wn4_NetDiag) & 0x1e) >> 1;
1370 if (print_info) { 1397 if (print_info) {
1371 printk(KERN_INFO " product code %02x%02x rev %02x.%d date %02d-" 1398 printk(KERN_INFO " product code %02x%02x rev %02x.%d date %02d-"
1372 "%02d-%02d\n", eeprom[6]&0xff, eeprom[6]>>8, eeprom[0x14], 1399 "%02d-%02d\n", eeprom[6]&0xff, eeprom[6]>>8, eeprom[0x14],
@@ -1375,31 +1402,30 @@ static int __devinit vortex_probe1(struct device *gendev,
1375 1402
1376 1403
1377 if (pdev && vci->drv_flags & HAS_CB_FNS) { 1404 if (pdev && vci->drv_flags & HAS_CB_FNS) {
1378 unsigned long fn_st_addr; /* Cardbus function status space */
1379 unsigned short n; 1405 unsigned short n;
1380 1406
1381 fn_st_addr = pci_resource_start (pdev, 2); 1407 vp->cb_fn_base = pci_iomap(pdev, 2, 0);
1382 if (fn_st_addr) { 1408 if (!vp->cb_fn_base) {
1383 vp->cb_fn_base = ioremap(fn_st_addr, 128);
1384 retval = -ENOMEM; 1409 retval = -ENOMEM;
1385 if (!vp->cb_fn_base) 1410 goto free_ring;
1386 goto free_ring;
1387 } 1411 }
1412
1388 if (print_info) { 1413 if (print_info) {
1389 printk(KERN_INFO "%s: CardBus functions mapped %8.8lx->%p\n", 1414 printk(KERN_INFO "%s: CardBus functions mapped %8.8lx->%p\n",
1390 print_name, fn_st_addr, vp->cb_fn_base); 1415 print_name, pci_resource_start(pdev, 2),
1416 vp->cb_fn_base);
1391 } 1417 }
1392 EL3WINDOW(2); 1418 EL3WINDOW(2);
1393 1419
1394 n = inw(ioaddr + Wn2_ResetOptions) & ~0x4010; 1420 n = ioread16(ioaddr + Wn2_ResetOptions) & ~0x4010;
1395 if (vp->drv_flags & INVERT_LED_PWR) 1421 if (vp->drv_flags & INVERT_LED_PWR)
1396 n |= 0x10; 1422 n |= 0x10;
1397 if (vp->drv_flags & INVERT_MII_PWR) 1423 if (vp->drv_flags & INVERT_MII_PWR)
1398 n |= 0x4000; 1424 n |= 0x4000;
1399 outw(n, ioaddr + Wn2_ResetOptions); 1425 iowrite16(n, ioaddr + Wn2_ResetOptions);
1400 if (vp->drv_flags & WNO_XCVR_PWR) { 1426 if (vp->drv_flags & WNO_XCVR_PWR) {
1401 EL3WINDOW(0); 1427 EL3WINDOW(0);
1402 outw(0x0800, ioaddr); 1428 iowrite16(0x0800, ioaddr);
1403 } 1429 }
1404 } 1430 }
1405 1431
@@ -1418,13 +1444,13 @@ static int __devinit vortex_probe1(struct device *gendev,
1418 static const char * ram_split[] = {"5:3", "3:1", "1:1", "3:5"}; 1444 static const char * ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
1419 unsigned int config; 1445 unsigned int config;
1420 EL3WINDOW(3); 1446 EL3WINDOW(3);
1421 vp->available_media = inw(ioaddr + Wn3_Options); 1447 vp->available_media = ioread16(ioaddr + Wn3_Options);
1422 if ((vp->available_media & 0xff) == 0) /* Broken 3c916 */ 1448 if ((vp->available_media & 0xff) == 0) /* Broken 3c916 */
1423 vp->available_media = 0x40; 1449 vp->available_media = 0x40;
1424 config = inl(ioaddr + Wn3_Config); 1450 config = ioread32(ioaddr + Wn3_Config);
1425 if (print_info) { 1451 if (print_info) {
1426 printk(KERN_DEBUG " Internal config register is %4.4x, " 1452 printk(KERN_DEBUG " Internal config register is %4.4x, "
1427 "transceivers %#x.\n", config, inw(ioaddr + Wn3_Options)); 1453 "transceivers %#x.\n", config, ioread16(ioaddr + Wn3_Options));
1428 printk(KERN_INFO " %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n", 1454 printk(KERN_INFO " %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
1429 8 << RAM_SIZE(config), 1455 8 << RAM_SIZE(config),
1430 RAM_WIDTH(config) ? "word" : "byte", 1456 RAM_WIDTH(config) ? "word" : "byte",
@@ -1455,7 +1481,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1455 if (vp->drv_flags & EXTRA_PREAMBLE) 1481 if (vp->drv_flags & EXTRA_PREAMBLE)
1456 mii_preamble_required++; 1482 mii_preamble_required++;
1457 mdio_sync(ioaddr, 32); 1483 mdio_sync(ioaddr, 32);
1458 mdio_read(dev, 24, 1); 1484 mdio_read(dev, 24, MII_BMSR);
1459 for (phy = 0; phy < 32 && phy_idx < 1; phy++) { 1485 for (phy = 0; phy < 32 && phy_idx < 1; phy++) {
1460 int mii_status, phyx; 1486 int mii_status, phyx;
1461 1487
@@ -1469,7 +1495,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1469 phyx = phy - 1; 1495 phyx = phy - 1;
1470 else 1496 else
1471 phyx = phy; 1497 phyx = phy;
1472 mii_status = mdio_read(dev, phyx, 1); 1498 mii_status = mdio_read(dev, phyx, MII_BMSR);
1473 if (mii_status && mii_status != 0xffff) { 1499 if (mii_status && mii_status != 0xffff) {
1474 vp->phys[phy_idx++] = phyx; 1500 vp->phys[phy_idx++] = phyx;
1475 if (print_info) { 1501 if (print_info) {
@@ -1485,7 +1511,7 @@ static int __devinit vortex_probe1(struct device *gendev,
1485 printk(KERN_WARNING" ***WARNING*** No MII transceivers found!\n"); 1511 printk(KERN_WARNING" ***WARNING*** No MII transceivers found!\n");
1486 vp->phys[0] = 24; 1512 vp->phys[0] = 24;
1487 } else { 1513 } else {
1488 vp->advertising = mdio_read(dev, vp->phys[0], 4); 1514 vp->advertising = mdio_read(dev, vp->phys[0], MII_ADVERTISE);
1489 if (vp->full_duplex) { 1515 if (vp->full_duplex) {
1490 /* Only advertise the FD media types. */ 1516 /* Only advertise the FD media types. */
1491 vp->advertising &= ~0x02A0; 1517 vp->advertising &= ~0x02A0;
@@ -1510,10 +1536,10 @@ static int __devinit vortex_probe1(struct device *gendev,
1510 if (vp->full_bus_master_tx) { 1536 if (vp->full_bus_master_tx) {
1511 dev->hard_start_xmit = boomerang_start_xmit; 1537 dev->hard_start_xmit = boomerang_start_xmit;
1512 /* Actually, it still should work with iommu. */ 1538 /* Actually, it still should work with iommu. */
1513 dev->features |= NETIF_F_SG; 1539 if (card_idx < MAX_UNITS &&
1514 if (((hw_checksums[card_idx] == -1) && (vp->drv_flags & HAS_HWCKSM)) || 1540 ((hw_checksums[card_idx] == -1 && (vp->drv_flags & HAS_HWCKSM)) ||
1515 (hw_checksums[card_idx] == 1)) { 1541 hw_checksums[card_idx] == 1)) {
1516 dev->features |= NETIF_F_IP_CSUM; 1542 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
1517 } 1543 }
1518 } else { 1544 } else {
1519 dev->hard_start_xmit = vortex_start_xmit; 1545 dev->hard_start_xmit = vortex_start_xmit;
@@ -1555,7 +1581,7 @@ free_ring:
1555 vp->rx_ring_dma); 1581 vp->rx_ring_dma);
1556free_region: 1582free_region:
1557 if (vp->must_free_region) 1583 if (vp->must_free_region)
1558 release_region(ioaddr, vci->io_size); 1584 release_region(dev->base_addr, vci->io_size);
1559 free_netdev(dev); 1585 free_netdev(dev);
1560 printk(KERN_ERR PFX "vortex_probe1 fails. Returns %d\n", retval); 1586 printk(KERN_ERR PFX "vortex_probe1 fails. Returns %d\n", retval);
1561out: 1587out:
@@ -1565,17 +1591,19 @@ out:
1565static void 1591static void
1566issue_and_wait(struct net_device *dev, int cmd) 1592issue_and_wait(struct net_device *dev, int cmd)
1567{ 1593{
1594 struct vortex_private *vp = netdev_priv(dev);
1595 void __iomem *ioaddr = vp->ioaddr;
1568 int i; 1596 int i;
1569 1597
1570 outw(cmd, dev->base_addr + EL3_CMD); 1598 iowrite16(cmd, ioaddr + EL3_CMD);
1571 for (i = 0; i < 2000; i++) { 1599 for (i = 0; i < 2000; i++) {
1572 if (!(inw(dev->base_addr + EL3_STATUS) & CmdInProgress)) 1600 if (!(ioread16(ioaddr + EL3_STATUS) & CmdInProgress))
1573 return; 1601 return;
1574 } 1602 }
1575 1603
1576 /* OK, that didn't work. Do it the slow way. One second */ 1604 /* OK, that didn't work. Do it the slow way. One second */
1577 for (i = 0; i < 100000; i++) { 1605 for (i = 0; i < 100000; i++) {
1578 if (!(inw(dev->base_addr + EL3_STATUS) & CmdInProgress)) { 1606 if (!(ioread16(ioaddr + EL3_STATUS) & CmdInProgress)) {
1579 if (vortex_debug > 1) 1607 if (vortex_debug > 1)
1580 printk(KERN_INFO "%s: command 0x%04x took %d usecs\n", 1608 printk(KERN_INFO "%s: command 0x%04x took %d usecs\n",
1581 dev->name, cmd, i * 10); 1609 dev->name, cmd, i * 10);
@@ -1584,14 +1612,14 @@ issue_and_wait(struct net_device *dev, int cmd)
1584 udelay(10); 1612 udelay(10);
1585 } 1613 }
1586 printk(KERN_ERR "%s: command 0x%04x did not complete! Status=0x%x\n", 1614 printk(KERN_ERR "%s: command 0x%04x did not complete! Status=0x%x\n",
1587 dev->name, cmd, inw(dev->base_addr + EL3_STATUS)); 1615 dev->name, cmd, ioread16(ioaddr + EL3_STATUS));
1588} 1616}
1589 1617
1590static void 1618static void
1591vortex_up(struct net_device *dev) 1619vortex_up(struct net_device *dev)
1592{ 1620{
1593 long ioaddr = dev->base_addr;
1594 struct vortex_private *vp = netdev_priv(dev); 1621 struct vortex_private *vp = netdev_priv(dev);
1622 void __iomem *ioaddr = vp->ioaddr;
1595 unsigned int config; 1623 unsigned int config;
1596 int i; 1624 int i;
1597 1625
@@ -1604,7 +1632,7 @@ vortex_up(struct net_device *dev)
1604 1632
1605 /* Before initializing select the active media port. */ 1633 /* Before initializing select the active media port. */
1606 EL3WINDOW(3); 1634 EL3WINDOW(3);
1607 config = inl(ioaddr + Wn3_Config); 1635 config = ioread32(ioaddr + Wn3_Config);
1608 1636
1609 if (vp->media_override != 7) { 1637 if (vp->media_override != 7) {
1610 printk(KERN_INFO "%s: Media override to transceiver %d (%s).\n", 1638 printk(KERN_INFO "%s: Media override to transceiver %d (%s).\n",
@@ -1651,14 +1679,14 @@ vortex_up(struct net_device *dev)
1651 config = BFINS(config, dev->if_port, 20, 4); 1679 config = BFINS(config, dev->if_port, 20, 4);
1652 if (vortex_debug > 6) 1680 if (vortex_debug > 6)
1653 printk(KERN_DEBUG "vortex_up(): writing 0x%x to InternalConfig\n", config); 1681 printk(KERN_DEBUG "vortex_up(): writing 0x%x to InternalConfig\n", config);
1654 outl(config, ioaddr + Wn3_Config); 1682 iowrite32(config, ioaddr + Wn3_Config);
1655 1683
1656 if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) { 1684 if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
1657 int mii_reg1, mii_reg5; 1685 int mii_reg1, mii_reg5;
1658 EL3WINDOW(4); 1686 EL3WINDOW(4);
1659 /* Read BMSR (reg1) only to clear old status. */ 1687 /* Read BMSR (reg1) only to clear old status. */
1660 mii_reg1 = mdio_read(dev, vp->phys[0], 1); 1688 mii_reg1 = mdio_read(dev, vp->phys[0], MII_BMSR);
1661 mii_reg5 = mdio_read(dev, vp->phys[0], 5); 1689 mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);
1662 if (mii_reg5 == 0xffff || mii_reg5 == 0x0000) { 1690 if (mii_reg5 == 0xffff || mii_reg5 == 0x0000) {
1663 netif_carrier_off(dev); /* No MII device or no link partner report */ 1691 netif_carrier_off(dev); /* No MII device or no link partner report */
1664 } else { 1692 } else {
@@ -1679,7 +1707,7 @@ vortex_up(struct net_device *dev)
1679 } 1707 }
1680 1708
1681 /* Set the full-duplex bit. */ 1709 /* Set the full-duplex bit. */
1682 outw( ((vp->info1 & 0x8000) || vp->full_duplex ? 0x20 : 0) | 1710 iowrite16( ((vp->info1 & 0x8000) || vp->full_duplex ? 0x20 : 0) |
1683 (vp->large_frames ? 0x40 : 0) | 1711 (vp->large_frames ? 0x40 : 0) |
1684 ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0), 1712 ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0),
1685 ioaddr + Wn3_MAC_Ctrl); 1713 ioaddr + Wn3_MAC_Ctrl);
@@ -1695,51 +1723,51 @@ vortex_up(struct net_device *dev)
1695 */ 1723 */
1696 issue_and_wait(dev, RxReset|0x04); 1724 issue_and_wait(dev, RxReset|0x04);
1697 1725
1698 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD); 1726 iowrite16(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
1699 1727
1700 if (vortex_debug > 1) { 1728 if (vortex_debug > 1) {
1701 EL3WINDOW(4); 1729 EL3WINDOW(4);
1702 printk(KERN_DEBUG "%s: vortex_up() irq %d media status %4.4x.\n", 1730 printk(KERN_DEBUG "%s: vortex_up() irq %d media status %4.4x.\n",
1703 dev->name, dev->irq, inw(ioaddr + Wn4_Media)); 1731 dev->name, dev->irq, ioread16(ioaddr + Wn4_Media));
1704 } 1732 }
1705 1733
1706 /* Set the station address and mask in window 2 each time opened. */ 1734 /* Set the station address and mask in window 2 each time opened. */
1707 EL3WINDOW(2); 1735 EL3WINDOW(2);
1708 for (i = 0; i < 6; i++) 1736 for (i = 0; i < 6; i++)
1709 outb(dev->dev_addr[i], ioaddr + i); 1737 iowrite8(dev->dev_addr[i], ioaddr + i);
1710 for (; i < 12; i+=2) 1738 for (; i < 12; i+=2)
1711 outw(0, ioaddr + i); 1739 iowrite16(0, ioaddr + i);
1712 1740
1713 if (vp->cb_fn_base) { 1741 if (vp->cb_fn_base) {
1714 unsigned short n = inw(ioaddr + Wn2_ResetOptions) & ~0x4010; 1742 unsigned short n = ioread16(ioaddr + Wn2_ResetOptions) & ~0x4010;
1715 if (vp->drv_flags & INVERT_LED_PWR) 1743 if (vp->drv_flags & INVERT_LED_PWR)
1716 n |= 0x10; 1744 n |= 0x10;
1717 if (vp->drv_flags & INVERT_MII_PWR) 1745 if (vp->drv_flags & INVERT_MII_PWR)
1718 n |= 0x4000; 1746 n |= 0x4000;
1719 outw(n, ioaddr + Wn2_ResetOptions); 1747 iowrite16(n, ioaddr + Wn2_ResetOptions);
1720 } 1748 }
1721 1749
1722 if (dev->if_port == XCVR_10base2) 1750 if (dev->if_port == XCVR_10base2)
1723 /* Start the thinnet transceiver. We should really wait 50ms...*/ 1751 /* Start the thinnet transceiver. We should really wait 50ms...*/
1724 outw(StartCoax, ioaddr + EL3_CMD); 1752 iowrite16(StartCoax, ioaddr + EL3_CMD);
1725 if (dev->if_port != XCVR_NWAY) { 1753 if (dev->if_port != XCVR_NWAY) {
1726 EL3WINDOW(4); 1754 EL3WINDOW(4);
1727 outw((inw(ioaddr + Wn4_Media) & ~(Media_10TP|Media_SQE)) | 1755 iowrite16((ioread16(ioaddr + Wn4_Media) & ~(Media_10TP|Media_SQE)) |
1728 media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media); 1756 media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
1729 } 1757 }
1730 1758
1731 /* Switch to the stats window, and clear all stats by reading. */ 1759 /* Switch to the stats window, and clear all stats by reading. */
1732 outw(StatsDisable, ioaddr + EL3_CMD); 1760 iowrite16(StatsDisable, ioaddr + EL3_CMD);
1733 EL3WINDOW(6); 1761 EL3WINDOW(6);
1734 for (i = 0; i < 10; i++) 1762 for (i = 0; i < 10; i++)
1735 inb(ioaddr + i); 1763 ioread8(ioaddr + i);
1736 inw(ioaddr + 10); 1764 ioread16(ioaddr + 10);
1737 inw(ioaddr + 12); 1765 ioread16(ioaddr + 12);
1738 /* New: On the Vortex we must also clear the BadSSD counter. */ 1766 /* New: On the Vortex we must also clear the BadSSD counter. */
1739 EL3WINDOW(4); 1767 EL3WINDOW(4);
1740 inb(ioaddr + 12); 1768 ioread8(ioaddr + 12);
1741 /* ..and on the Boomerang we enable the extra statistics bits. */ 1769 /* ..and on the Boomerang we enable the extra statistics bits. */
1742 outw(0x0040, ioaddr + Wn4_NetDiag); 1770 iowrite16(0x0040, ioaddr + Wn4_NetDiag);
1743 1771
1744 /* Switch to register set 7 for normal use. */ 1772 /* Switch to register set 7 for normal use. */
1745 EL3WINDOW(7); 1773 EL3WINDOW(7);
@@ -1747,30 +1775,30 @@ vortex_up(struct net_device *dev)
1747 if (vp->full_bus_master_rx) { /* Boomerang bus master. */ 1775 if (vp->full_bus_master_rx) { /* Boomerang bus master. */
1748 vp->cur_rx = vp->dirty_rx = 0; 1776 vp->cur_rx = vp->dirty_rx = 0;
1749 /* Initialize the RxEarly register as recommended. */ 1777 /* Initialize the RxEarly register as recommended. */
1750 outw(SetRxThreshold + (1536>>2), ioaddr + EL3_CMD); 1778 iowrite16(SetRxThreshold + (1536>>2), ioaddr + EL3_CMD);
1751 outl(0x0020, ioaddr + PktStatus); 1779 iowrite32(0x0020, ioaddr + PktStatus);
1752 outl(vp->rx_ring_dma, ioaddr + UpListPtr); 1780 iowrite32(vp->rx_ring_dma, ioaddr + UpListPtr);
1753 } 1781 }
1754 if (vp->full_bus_master_tx) { /* Boomerang bus master Tx. */ 1782 if (vp->full_bus_master_tx) { /* Boomerang bus master Tx. */
1755 vp->cur_tx = vp->dirty_tx = 0; 1783 vp->cur_tx = vp->dirty_tx = 0;
1756 if (vp->drv_flags & IS_BOOMERANG) 1784 if (vp->drv_flags & IS_BOOMERANG)
1757 outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold); /* Room for a packet. */ 1785 iowrite8(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold); /* Room for a packet. */
1758 /* Clear the Rx, Tx rings. */ 1786 /* Clear the Rx, Tx rings. */
1759 for (i = 0; i < RX_RING_SIZE; i++) /* AKPM: this is done in vortex_open, too */ 1787 for (i = 0; i < RX_RING_SIZE; i++) /* AKPM: this is done in vortex_open, too */
1760 vp->rx_ring[i].status = 0; 1788 vp->rx_ring[i].status = 0;
1761 for (i = 0; i < TX_RING_SIZE; i++) 1789 for (i = 0; i < TX_RING_SIZE; i++)
1762 vp->tx_skbuff[i] = NULL; 1790 vp->tx_skbuff[i] = NULL;
1763 outl(0, ioaddr + DownListPtr); 1791 iowrite32(0, ioaddr + DownListPtr);
1764 } 1792 }
1765 /* Set receiver mode: presumably accept b-case and phys addr only. */ 1793 /* Set receiver mode: presumably accept b-case and phys addr only. */
1766 set_rx_mode(dev); 1794 set_rx_mode(dev);
1767 /* enable 802.1q tagged frames */ 1795 /* enable 802.1q tagged frames */
1768 set_8021q_mode(dev, 1); 1796 set_8021q_mode(dev, 1);
1769 outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */ 1797 iowrite16(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
1770 1798
1771// issue_and_wait(dev, SetTxStart|0x07ff); 1799// issue_and_wait(dev, SetTxStart|0x07ff);
1772 outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */ 1800 iowrite16(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
1773 outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */ 1801 iowrite16(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
1774 /* Allow status bits to be seen. */ 1802 /* Allow status bits to be seen. */
1775 vp->status_enable = SetStatusEnb | HostError|IntReq|StatsFull|TxComplete| 1803 vp->status_enable = SetStatusEnb | HostError|IntReq|StatsFull|TxComplete|
1776 (vp->full_bus_master_tx ? DownComplete : TxAvailable) | 1804 (vp->full_bus_master_tx ? DownComplete : TxAvailable) |
@@ -1780,13 +1808,13 @@ vortex_up(struct net_device *dev)
1780 (vp->full_bus_master_rx ? 0 : RxComplete) | 1808 (vp->full_bus_master_rx ? 0 : RxComplete) |
1781 StatsFull | HostError | TxComplete | IntReq 1809 StatsFull | HostError | TxComplete | IntReq
1782 | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete; 1810 | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete;
1783 outw(vp->status_enable, ioaddr + EL3_CMD); 1811 iowrite16(vp->status_enable, ioaddr + EL3_CMD);
1784 /* Ack all pending events, and set active indicator mask. */ 1812 /* Ack all pending events, and set active indicator mask. */
1785 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq, 1813 iowrite16(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
1786 ioaddr + EL3_CMD); 1814 ioaddr + EL3_CMD);
1787 outw(vp->intr_enable, ioaddr + EL3_CMD); 1815 iowrite16(vp->intr_enable, ioaddr + EL3_CMD);
1788 if (vp->cb_fn_base) /* The PCMCIA people are idiots. */ 1816 if (vp->cb_fn_base) /* The PCMCIA people are idiots. */
1789 writel(0x8000, vp->cb_fn_base + 4); 1817 iowrite32(0x8000, vp->cb_fn_base + 4);
1790 netif_start_queue (dev); 1818 netif_start_queue (dev);
1791} 1819}
1792 1820
@@ -1852,7 +1880,7 @@ vortex_timer(unsigned long data)
1852{ 1880{
1853 struct net_device *dev = (struct net_device *)data; 1881 struct net_device *dev = (struct net_device *)data;
1854 struct vortex_private *vp = netdev_priv(dev); 1882 struct vortex_private *vp = netdev_priv(dev);
1855 long ioaddr = dev->base_addr; 1883 void __iomem *ioaddr = vp->ioaddr;
1856 int next_tick = 60*HZ; 1884 int next_tick = 60*HZ;
1857 int ok = 0; 1885 int ok = 0;
1858 int media_status, mii_status, old_window; 1886 int media_status, mii_status, old_window;
@@ -1866,9 +1894,9 @@ vortex_timer(unsigned long data)
1866 if (vp->medialock) 1894 if (vp->medialock)
1867 goto leave_media_alone; 1895 goto leave_media_alone;
1868 disable_irq(dev->irq); 1896 disable_irq(dev->irq);
1869 old_window = inw(ioaddr + EL3_CMD) >> 13; 1897 old_window = ioread16(ioaddr + EL3_CMD) >> 13;
1870 EL3WINDOW(4); 1898 EL3WINDOW(4);
1871 media_status = inw(ioaddr + Wn4_Media); 1899 media_status = ioread16(ioaddr + Wn4_Media);
1872 switch (dev->if_port) { 1900 switch (dev->if_port) {
1873 case XCVR_10baseT: case XCVR_100baseTx: case XCVR_100baseFx: 1901 case XCVR_10baseT: case XCVR_100baseTx: case XCVR_100baseFx:
1874 if (media_status & Media_LnkBeat) { 1902 if (media_status & Media_LnkBeat) {
@@ -1888,14 +1916,17 @@ vortex_timer(unsigned long data)
1888 case XCVR_MII: case XCVR_NWAY: 1916 case XCVR_MII: case XCVR_NWAY:
1889 { 1917 {
1890 spin_lock_bh(&vp->lock); 1918 spin_lock_bh(&vp->lock);
1891 mii_status = mdio_read(dev, vp->phys[0], 1); 1919 mii_status = mdio_read(dev, vp->phys[0], MII_BMSR);
1892 mii_status = mdio_read(dev, vp->phys[0], 1); 1920 if (!(mii_status & BMSR_LSTATUS)) {
1921 /* Re-read to get actual link status */
1922 mii_status = mdio_read(dev, vp->phys[0], MII_BMSR);
1923 }
1893 ok = 1; 1924 ok = 1;
1894 if (vortex_debug > 2) 1925 if (vortex_debug > 2)
1895 printk(KERN_DEBUG "%s: MII transceiver has status %4.4x.\n", 1926 printk(KERN_DEBUG "%s: MII transceiver has status %4.4x.\n",
1896 dev->name, mii_status); 1927 dev->name, mii_status);
1897 if (mii_status & BMSR_LSTATUS) { 1928 if (mii_status & BMSR_LSTATUS) {
1898 int mii_reg5 = mdio_read(dev, vp->phys[0], 5); 1929 int mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);
1899 if (! vp->force_fd && mii_reg5 != 0xffff) { 1930 if (! vp->force_fd && mii_reg5 != 0xffff) {
1900 int duplex; 1931 int duplex;
1901 1932
@@ -1909,7 +1940,7 @@ vortex_timer(unsigned long data)
1909 vp->phys[0], mii_reg5); 1940 vp->phys[0], mii_reg5);
1910 /* Set the full-duplex bit. */ 1941 /* Set the full-duplex bit. */
1911 EL3WINDOW(3); 1942 EL3WINDOW(3);
1912 outw( (vp->full_duplex ? 0x20 : 0) | 1943 iowrite16( (vp->full_duplex ? 0x20 : 0) |
1913 (vp->large_frames ? 0x40 : 0) | 1944 (vp->large_frames ? 0x40 : 0) |
1914 ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0), 1945 ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0),
1915 ioaddr + Wn3_MAC_Ctrl); 1946 ioaddr + Wn3_MAC_Ctrl);
@@ -1950,15 +1981,15 @@ vortex_timer(unsigned long data)
1950 dev->name, media_tbl[dev->if_port].name); 1981 dev->name, media_tbl[dev->if_port].name);
1951 next_tick = media_tbl[dev->if_port].wait; 1982 next_tick = media_tbl[dev->if_port].wait;
1952 } 1983 }
1953 outw((media_status & ~(Media_10TP|Media_SQE)) | 1984 iowrite16((media_status & ~(Media_10TP|Media_SQE)) |
1954 media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media); 1985 media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
1955 1986
1956 EL3WINDOW(3); 1987 EL3WINDOW(3);
1957 config = inl(ioaddr + Wn3_Config); 1988 config = ioread32(ioaddr + Wn3_Config);
1958 config = BFINS(config, dev->if_port, 20, 4); 1989 config = BFINS(config, dev->if_port, 20, 4);
1959 outl(config, ioaddr + Wn3_Config); 1990 iowrite32(config, ioaddr + Wn3_Config);
1960 1991
1961 outw(dev->if_port == XCVR_10base2 ? StartCoax : StopCoax, 1992 iowrite16(dev->if_port == XCVR_10base2 ? StartCoax : StopCoax,
1962 ioaddr + EL3_CMD); 1993 ioaddr + EL3_CMD);
1963 if (vortex_debug > 1) 1994 if (vortex_debug > 1)
1964 printk(KERN_DEBUG "wrote 0x%08x to Wn3_Config\n", config); 1995 printk(KERN_DEBUG "wrote 0x%08x to Wn3_Config\n", config);
@@ -1974,29 +2005,29 @@ leave_media_alone:
1974 2005
1975 mod_timer(&vp->timer, RUN_AT(next_tick)); 2006 mod_timer(&vp->timer, RUN_AT(next_tick));
1976 if (vp->deferred) 2007 if (vp->deferred)
1977 outw(FakeIntr, ioaddr + EL3_CMD); 2008 iowrite16(FakeIntr, ioaddr + EL3_CMD);
1978 return; 2009 return;
1979} 2010}
1980 2011
1981static void vortex_tx_timeout(struct net_device *dev) 2012static void vortex_tx_timeout(struct net_device *dev)
1982{ 2013{
1983 struct vortex_private *vp = netdev_priv(dev); 2014 struct vortex_private *vp = netdev_priv(dev);
1984 long ioaddr = dev->base_addr; 2015 void __iomem *ioaddr = vp->ioaddr;
1985 2016
1986 printk(KERN_ERR "%s: transmit timed out, tx_status %2.2x status %4.4x.\n", 2017 printk(KERN_ERR "%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
1987 dev->name, inb(ioaddr + TxStatus), 2018 dev->name, ioread8(ioaddr + TxStatus),
1988 inw(ioaddr + EL3_STATUS)); 2019 ioread16(ioaddr + EL3_STATUS));
1989 EL3WINDOW(4); 2020 EL3WINDOW(4);
1990 printk(KERN_ERR " diagnostics: net %04x media %04x dma %08x fifo %04x\n", 2021 printk(KERN_ERR " diagnostics: net %04x media %04x dma %08x fifo %04x\n",
1991 inw(ioaddr + Wn4_NetDiag), 2022 ioread16(ioaddr + Wn4_NetDiag),
1992 inw(ioaddr + Wn4_Media), 2023 ioread16(ioaddr + Wn4_Media),
1993 inl(ioaddr + PktStatus), 2024 ioread32(ioaddr + PktStatus),
1994 inw(ioaddr + Wn4_FIFODiag)); 2025 ioread16(ioaddr + Wn4_FIFODiag));
1995 /* Slight code bloat to be user friendly. */ 2026 /* Slight code bloat to be user friendly. */
1996 if ((inb(ioaddr + TxStatus) & 0x88) == 0x88) 2027 if ((ioread8(ioaddr + TxStatus) & 0x88) == 0x88)
1997 printk(KERN_ERR "%s: Transmitter encountered 16 collisions --" 2028 printk(KERN_ERR "%s: Transmitter encountered 16 collisions --"
1998 " network cable problem?\n", dev->name); 2029 " network cable problem?\n", dev->name);
1999 if (inw(ioaddr + EL3_STATUS) & IntLatch) { 2030 if (ioread16(ioaddr + EL3_STATUS) & IntLatch) {
2000 printk(KERN_ERR "%s: Interrupt posted but not delivered --" 2031 printk(KERN_ERR "%s: Interrupt posted but not delivered --"
2001 " IRQ blocked by another device?\n", dev->name); 2032 " IRQ blocked by another device?\n", dev->name);
2002 /* Bad idea here.. but we might as well handle a few events. */ 2033 /* Bad idea here.. but we might as well handle a few events. */
@@ -2022,21 +2053,21 @@ static void vortex_tx_timeout(struct net_device *dev)
2022 vp->stats.tx_errors++; 2053 vp->stats.tx_errors++;
2023 if (vp->full_bus_master_tx) { 2054 if (vp->full_bus_master_tx) {
2024 printk(KERN_DEBUG "%s: Resetting the Tx ring pointer.\n", dev->name); 2055 printk(KERN_DEBUG "%s: Resetting the Tx ring pointer.\n", dev->name);
2025 if (vp->cur_tx - vp->dirty_tx > 0 && inl(ioaddr + DownListPtr) == 0) 2056 if (vp->cur_tx - vp->dirty_tx > 0 && ioread32(ioaddr + DownListPtr) == 0)
2026 outl(vp->tx_ring_dma + (vp->dirty_tx % TX_RING_SIZE) * sizeof(struct boom_tx_desc), 2057 iowrite32(vp->tx_ring_dma + (vp->dirty_tx % TX_RING_SIZE) * sizeof(struct boom_tx_desc),
2027 ioaddr + DownListPtr); 2058 ioaddr + DownListPtr);
2028 if (vp->cur_tx - vp->dirty_tx < TX_RING_SIZE) 2059 if (vp->cur_tx - vp->dirty_tx < TX_RING_SIZE)
2029 netif_wake_queue (dev); 2060 netif_wake_queue (dev);
2030 if (vp->drv_flags & IS_BOOMERANG) 2061 if (vp->drv_flags & IS_BOOMERANG)
2031 outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold); 2062 iowrite8(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold);
2032 outw(DownUnstall, ioaddr + EL3_CMD); 2063 iowrite16(DownUnstall, ioaddr + EL3_CMD);
2033 } else { 2064 } else {
2034 vp->stats.tx_dropped++; 2065 vp->stats.tx_dropped++;
2035 netif_wake_queue(dev); 2066 netif_wake_queue(dev);
2036 } 2067 }
2037 2068
2038 /* Issue Tx Enable */ 2069 /* Issue Tx Enable */
2039 outw(TxEnable, ioaddr + EL3_CMD); 2070 iowrite16(TxEnable, ioaddr + EL3_CMD);
2040 dev->trans_start = jiffies; 2071 dev->trans_start = jiffies;
2041 2072
2042 /* Switch to register set 7 for normal use. */ 2073 /* Switch to register set 7 for normal use. */
@@ -2051,7 +2082,7 @@ static void
2051vortex_error(struct net_device *dev, int status) 2082vortex_error(struct net_device *dev, int status)
2052{ 2083{
2053 struct vortex_private *vp = netdev_priv(dev); 2084 struct vortex_private *vp = netdev_priv(dev);
2054 long ioaddr = dev->base_addr; 2085 void __iomem *ioaddr = vp->ioaddr;
2055 int do_tx_reset = 0, reset_mask = 0; 2086 int do_tx_reset = 0, reset_mask = 0;
2056 unsigned char tx_status = 0; 2087 unsigned char tx_status = 0;
2057 2088
@@ -2060,7 +2091,7 @@ vortex_error(struct net_device *dev, int status)
2060 } 2091 }
2061 2092
2062 if (status & TxComplete) { /* Really "TxError" for us. */ 2093 if (status & TxComplete) { /* Really "TxError" for us. */
2063 tx_status = inb(ioaddr + TxStatus); 2094 tx_status = ioread8(ioaddr + TxStatus);
2064 /* Presumably a tx-timeout. We must merely re-enable. */ 2095 /* Presumably a tx-timeout. We must merely re-enable. */
2065 if (vortex_debug > 2 2096 if (vortex_debug > 2
2066 || (tx_status != 0x88 && vortex_debug > 0)) { 2097 || (tx_status != 0x88 && vortex_debug > 0)) {
@@ -2074,20 +2105,20 @@ vortex_error(struct net_device *dev, int status)
2074 } 2105 }
2075 if (tx_status & 0x14) vp->stats.tx_fifo_errors++; 2106 if (tx_status & 0x14) vp->stats.tx_fifo_errors++;
2076 if (tx_status & 0x38) vp->stats.tx_aborted_errors++; 2107 if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
2077 outb(0, ioaddr + TxStatus); 2108 iowrite8(0, ioaddr + TxStatus);
2078 if (tx_status & 0x30) { /* txJabber or txUnderrun */ 2109 if (tx_status & 0x30) { /* txJabber or txUnderrun */
2079 do_tx_reset = 1; 2110 do_tx_reset = 1;
2080 } else if ((tx_status & 0x08) && (vp->drv_flags & MAX_COLLISION_RESET)) { /* maxCollisions */ 2111 } else if ((tx_status & 0x08) && (vp->drv_flags & MAX_COLLISION_RESET)) { /* maxCollisions */
2081 do_tx_reset = 1; 2112 do_tx_reset = 1;
2082 reset_mask = 0x0108; /* Reset interface logic, but not download logic */ 2113 reset_mask = 0x0108; /* Reset interface logic, but not download logic */
2083 } else { /* Merely re-enable the transmitter. */ 2114 } else { /* Merely re-enable the transmitter. */
2084 outw(TxEnable, ioaddr + EL3_CMD); 2115 iowrite16(TxEnable, ioaddr + EL3_CMD);
2085 } 2116 }
2086 } 2117 }
2087 2118
2088 if (status & RxEarly) { /* Rx early is unused. */ 2119 if (status & RxEarly) { /* Rx early is unused. */
2089 vortex_rx(dev); 2120 vortex_rx(dev);
2090 outw(AckIntr | RxEarly, ioaddr + EL3_CMD); 2121 iowrite16(AckIntr | RxEarly, ioaddr + EL3_CMD);
2091 } 2122 }
2092 if (status & StatsFull) { /* Empty statistics. */ 2123 if (status & StatsFull) { /* Empty statistics. */
2093 static int DoneDidThat; 2124 static int DoneDidThat;
@@ -2097,29 +2128,29 @@ vortex_error(struct net_device *dev, int status)
2097 /* HACK: Disable statistics as an interrupt source. */ 2128 /* HACK: Disable statistics as an interrupt source. */
2098 /* This occurs when we have the wrong media type! */ 2129 /* This occurs when we have the wrong media type! */
2099 if (DoneDidThat == 0 && 2130 if (DoneDidThat == 0 &&
2100 inw(ioaddr + EL3_STATUS) & StatsFull) { 2131 ioread16(ioaddr + EL3_STATUS) & StatsFull) {
2101 printk(KERN_WARNING "%s: Updating statistics failed, disabling " 2132 printk(KERN_WARNING "%s: Updating statistics failed, disabling "
2102 "stats as an interrupt source.\n", dev->name); 2133 "stats as an interrupt source.\n", dev->name);
2103 EL3WINDOW(5); 2134 EL3WINDOW(5);
2104 outw(SetIntrEnb | (inw(ioaddr + 10) & ~StatsFull), ioaddr + EL3_CMD); 2135 iowrite16(SetIntrEnb | (ioread16(ioaddr + 10) & ~StatsFull), ioaddr + EL3_CMD);
2105 vp->intr_enable &= ~StatsFull; 2136 vp->intr_enable &= ~StatsFull;
2106 EL3WINDOW(7); 2137 EL3WINDOW(7);
2107 DoneDidThat++; 2138 DoneDidThat++;
2108 } 2139 }
2109 } 2140 }
2110 if (status & IntReq) { /* Restore all interrupt sources. */ 2141 if (status & IntReq) { /* Restore all interrupt sources. */
2111 outw(vp->status_enable, ioaddr + EL3_CMD); 2142 iowrite16(vp->status_enable, ioaddr + EL3_CMD);
2112 outw(vp->intr_enable, ioaddr + EL3_CMD); 2143 iowrite16(vp->intr_enable, ioaddr + EL3_CMD);
2113 } 2144 }
2114 if (status & HostError) { 2145 if (status & HostError) {
2115 u16 fifo_diag; 2146 u16 fifo_diag;
2116 EL3WINDOW(4); 2147 EL3WINDOW(4);
2117 fifo_diag = inw(ioaddr + Wn4_FIFODiag); 2148 fifo_diag = ioread16(ioaddr + Wn4_FIFODiag);
2118 printk(KERN_ERR "%s: Host error, FIFO diagnostic register %4.4x.\n", 2149 printk(KERN_ERR "%s: Host error, FIFO diagnostic register %4.4x.\n",
2119 dev->name, fifo_diag); 2150 dev->name, fifo_diag);
2120 /* Adapter failure requires Tx/Rx reset and reinit. */ 2151 /* Adapter failure requires Tx/Rx reset and reinit. */
2121 if (vp->full_bus_master_tx) { 2152 if (vp->full_bus_master_tx) {
2122 int bus_status = inl(ioaddr + PktStatus); 2153 int bus_status = ioread32(ioaddr + PktStatus);
2123 /* 0x80000000 PCI master abort. */ 2154 /* 0x80000000 PCI master abort. */
2124 /* 0x40000000 PCI target abort. */ 2155 /* 0x40000000 PCI target abort. */
2125 if (vortex_debug) 2156 if (vortex_debug)
@@ -2139,14 +2170,14 @@ vortex_error(struct net_device *dev, int status)
2139 set_rx_mode(dev); 2170 set_rx_mode(dev);
2140 /* enable 802.1q VLAN tagged frames */ 2171 /* enable 802.1q VLAN tagged frames */
2141 set_8021q_mode(dev, 1); 2172 set_8021q_mode(dev, 1);
2142 outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */ 2173 iowrite16(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
2143 outw(AckIntr | HostError, ioaddr + EL3_CMD); 2174 iowrite16(AckIntr | HostError, ioaddr + EL3_CMD);
2144 } 2175 }
2145 } 2176 }
2146 2177
2147 if (do_tx_reset) { 2178 if (do_tx_reset) {
2148 issue_and_wait(dev, TxReset|reset_mask); 2179 issue_and_wait(dev, TxReset|reset_mask);
2149 outw(TxEnable, ioaddr + EL3_CMD); 2180 iowrite16(TxEnable, ioaddr + EL3_CMD);
2150 if (!vp->full_bus_master_tx) 2181 if (!vp->full_bus_master_tx)
2151 netif_wake_queue(dev); 2182 netif_wake_queue(dev);
2152 } 2183 }
@@ -2156,29 +2187,29 @@ static int
2156vortex_start_xmit(struct sk_buff *skb, struct net_device *dev) 2187vortex_start_xmit(struct sk_buff *skb, struct net_device *dev)
2157{ 2188{
2158 struct vortex_private *vp = netdev_priv(dev); 2189 struct vortex_private *vp = netdev_priv(dev);
2159 long ioaddr = dev->base_addr; 2190 void __iomem *ioaddr = vp->ioaddr;
2160 2191
2161 /* Put out the doubleword header... */ 2192 /* Put out the doubleword header... */
2162 outl(skb->len, ioaddr + TX_FIFO); 2193 iowrite32(skb->len, ioaddr + TX_FIFO);
2163 if (vp->bus_master) { 2194 if (vp->bus_master) {
2164 /* Set the bus-master controller to transfer the packet. */ 2195 /* Set the bus-master controller to transfer the packet. */
2165 int len = (skb->len + 3) & ~3; 2196 int len = (skb->len + 3) & ~3;
2166 outl( vp->tx_skb_dma = pci_map_single(VORTEX_PCI(vp), skb->data, len, PCI_DMA_TODEVICE), 2197 iowrite32( vp->tx_skb_dma = pci_map_single(VORTEX_PCI(vp), skb->data, len, PCI_DMA_TODEVICE),
2167 ioaddr + Wn7_MasterAddr); 2198 ioaddr + Wn7_MasterAddr);
2168 outw(len, ioaddr + Wn7_MasterLen); 2199 iowrite16(len, ioaddr + Wn7_MasterLen);
2169 vp->tx_skb = skb; 2200 vp->tx_skb = skb;
2170 outw(StartDMADown, ioaddr + EL3_CMD); 2201 iowrite16(StartDMADown, ioaddr + EL3_CMD);
2171 /* netif_wake_queue() will be called at the DMADone interrupt. */ 2202 /* netif_wake_queue() will be called at the DMADone interrupt. */
2172 } else { 2203 } else {
2173 /* ... and the packet rounded to a doubleword. */ 2204 /* ... and the packet rounded to a doubleword. */
2174 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2); 2205 iowrite32_rep(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
2175 dev_kfree_skb (skb); 2206 dev_kfree_skb (skb);
2176 if (inw(ioaddr + TxFree) > 1536) { 2207 if (ioread16(ioaddr + TxFree) > 1536) {
2177 netif_start_queue (dev); /* AKPM: redundant? */ 2208 netif_start_queue (dev); /* AKPM: redundant? */
2178 } else { 2209 } else {
2179 /* Interrupt us when the FIFO has room for max-sized packet. */ 2210 /* Interrupt us when the FIFO has room for max-sized packet. */
2180 netif_stop_queue(dev); 2211 netif_stop_queue(dev);
2181 outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD); 2212 iowrite16(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
2182 } 2213 }
2183 } 2214 }
2184 2215
@@ -2189,7 +2220,7 @@ vortex_start_xmit(struct sk_buff *skb, struct net_device *dev)
2189 int tx_status; 2220 int tx_status;
2190 int i = 32; 2221 int i = 32;
2191 2222
2192 while (--i > 0 && (tx_status = inb(ioaddr + TxStatus)) > 0) { 2223 while (--i > 0 && (tx_status = ioread8(ioaddr + TxStatus)) > 0) {
2193 if (tx_status & 0x3C) { /* A Tx-disabling error occurred. */ 2224 if (tx_status & 0x3C) { /* A Tx-disabling error occurred. */
2194 if (vortex_debug > 2) 2225 if (vortex_debug > 2)
2195 printk(KERN_DEBUG "%s: Tx error, status %2.2x.\n", 2226 printk(KERN_DEBUG "%s: Tx error, status %2.2x.\n",
@@ -2199,9 +2230,9 @@ vortex_start_xmit(struct sk_buff *skb, struct net_device *dev)
2199 if (tx_status & 0x30) { 2230 if (tx_status & 0x30) {
2200 issue_and_wait(dev, TxReset); 2231 issue_and_wait(dev, TxReset);
2201 } 2232 }
2202 outw(TxEnable, ioaddr + EL3_CMD); 2233 iowrite16(TxEnable, ioaddr + EL3_CMD);
2203 } 2234 }
2204 outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */ 2235 iowrite8(0x00, ioaddr + TxStatus); /* Pop the status stack. */
2205 } 2236 }
2206 } 2237 }
2207 return 0; 2238 return 0;
@@ -2211,7 +2242,7 @@ static int
2211boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev) 2242boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
2212{ 2243{
2213 struct vortex_private *vp = netdev_priv(dev); 2244 struct vortex_private *vp = netdev_priv(dev);
2214 long ioaddr = dev->base_addr; 2245 void __iomem *ioaddr = vp->ioaddr;
2215 /* Calculate the next Tx descriptor entry. */ 2246 /* Calculate the next Tx descriptor entry. */
2216 int entry = vp->cur_tx % TX_RING_SIZE; 2247 int entry = vp->cur_tx % TX_RING_SIZE;
2217 struct boom_tx_desc *prev_entry = &vp->tx_ring[(vp->cur_tx-1) % TX_RING_SIZE]; 2248 struct boom_tx_desc *prev_entry = &vp->tx_ring[(vp->cur_tx-1) % TX_RING_SIZE];
@@ -2275,8 +2306,8 @@ boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
2275 /* Wait for the stall to complete. */ 2306 /* Wait for the stall to complete. */
2276 issue_and_wait(dev, DownStall); 2307 issue_and_wait(dev, DownStall);
2277 prev_entry->next = cpu_to_le32(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc)); 2308 prev_entry->next = cpu_to_le32(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc));
2278 if (inl(ioaddr + DownListPtr) == 0) { 2309 if (ioread32(ioaddr + DownListPtr) == 0) {
2279 outl(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc), ioaddr + DownListPtr); 2310 iowrite32(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc), ioaddr + DownListPtr);
2280 vp->queued_packet++; 2311 vp->queued_packet++;
2281 } 2312 }
2282 2313
@@ -2291,7 +2322,7 @@ boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
2291 prev_entry->status &= cpu_to_le32(~TxIntrUploaded); 2322 prev_entry->status &= cpu_to_le32(~TxIntrUploaded);
2292#endif 2323#endif
2293 } 2324 }
2294 outw(DownUnstall, ioaddr + EL3_CMD); 2325 iowrite16(DownUnstall, ioaddr + EL3_CMD);
2295 spin_unlock_irqrestore(&vp->lock, flags); 2326 spin_unlock_irqrestore(&vp->lock, flags);
2296 dev->trans_start = jiffies; 2327 dev->trans_start = jiffies;
2297 return 0; 2328 return 0;
@@ -2310,15 +2341,15 @@ vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2310{ 2341{
2311 struct net_device *dev = dev_id; 2342 struct net_device *dev = dev_id;
2312 struct vortex_private *vp = netdev_priv(dev); 2343 struct vortex_private *vp = netdev_priv(dev);
2313 long ioaddr; 2344 void __iomem *ioaddr;
2314 int status; 2345 int status;
2315 int work_done = max_interrupt_work; 2346 int work_done = max_interrupt_work;
2316 int handled = 0; 2347 int handled = 0;
2317 2348
2318 ioaddr = dev->base_addr; 2349 ioaddr = vp->ioaddr;
2319 spin_lock(&vp->lock); 2350 spin_lock(&vp->lock);
2320 2351
2321 status = inw(ioaddr + EL3_STATUS); 2352 status = ioread16(ioaddr + EL3_STATUS);
2322 2353
2323 if (vortex_debug > 6) 2354 if (vortex_debug > 6)
2324 printk("vortex_interrupt(). status=0x%4x\n", status); 2355 printk("vortex_interrupt(). status=0x%4x\n", status);
@@ -2337,7 +2368,7 @@ vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2337 2368
2338 if (vortex_debug > 4) 2369 if (vortex_debug > 4)
2339 printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n", 2370 printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n",
2340 dev->name, status, inb(ioaddr + Timer)); 2371 dev->name, status, ioread8(ioaddr + Timer));
2341 2372
2342 do { 2373 do {
2343 if (vortex_debug > 5) 2374 if (vortex_debug > 5)
@@ -2350,16 +2381,16 @@ vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2350 if (vortex_debug > 5) 2381 if (vortex_debug > 5)
2351 printk(KERN_DEBUG " TX room bit was handled.\n"); 2382 printk(KERN_DEBUG " TX room bit was handled.\n");
2352 /* There's room in the FIFO for a full-sized packet. */ 2383 /* There's room in the FIFO for a full-sized packet. */
2353 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD); 2384 iowrite16(AckIntr | TxAvailable, ioaddr + EL3_CMD);
2354 netif_wake_queue (dev); 2385 netif_wake_queue (dev);
2355 } 2386 }
2356 2387
2357 if (status & DMADone) { 2388 if (status & DMADone) {
2358 if (inw(ioaddr + Wn7_MasterStatus) & 0x1000) { 2389 if (ioread16(ioaddr + Wn7_MasterStatus) & 0x1000) {
2359 outw(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */ 2390 iowrite16(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */
2360 pci_unmap_single(VORTEX_PCI(vp), vp->tx_skb_dma, (vp->tx_skb->len + 3) & ~3, PCI_DMA_TODEVICE); 2391 pci_unmap_single(VORTEX_PCI(vp), vp->tx_skb_dma, (vp->tx_skb->len + 3) & ~3, PCI_DMA_TODEVICE);
2361 dev_kfree_skb_irq(vp->tx_skb); /* Release the transferred buffer */ 2392 dev_kfree_skb_irq(vp->tx_skb); /* Release the transferred buffer */
2362 if (inw(ioaddr + TxFree) > 1536) { 2393 if (ioread16(ioaddr + TxFree) > 1536) {
2363 /* 2394 /*
2364 * AKPM: FIXME: I don't think we need this. If the queue was stopped due to 2395 * AKPM: FIXME: I don't think we need this. If the queue was stopped due to
2365 * insufficient FIFO room, the TxAvailable test will succeed and call 2396 * insufficient FIFO room, the TxAvailable test will succeed and call
@@ -2367,7 +2398,7 @@ vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2367 */ 2398 */
2368 netif_wake_queue(dev); 2399 netif_wake_queue(dev);
2369 } else { /* Interrupt when FIFO has room for max-sized packet. */ 2400 } else { /* Interrupt when FIFO has room for max-sized packet. */
2370 outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD); 2401 iowrite16(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
2371 netif_stop_queue(dev); 2402 netif_stop_queue(dev);
2372 } 2403 }
2373 } 2404 }
@@ -2385,17 +2416,17 @@ vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2385 /* Disable all pending interrupts. */ 2416 /* Disable all pending interrupts. */
2386 do { 2417 do {
2387 vp->deferred |= status; 2418 vp->deferred |= status;
2388 outw(SetStatusEnb | (~vp->deferred & vp->status_enable), 2419 iowrite16(SetStatusEnb | (~vp->deferred & vp->status_enable),
2389 ioaddr + EL3_CMD); 2420 ioaddr + EL3_CMD);
2390 outw(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD); 2421 iowrite16(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
2391 } while ((status = inw(ioaddr + EL3_CMD)) & IntLatch); 2422 } while ((status = ioread16(ioaddr + EL3_CMD)) & IntLatch);
2392 /* The timer will reenable interrupts. */ 2423 /* The timer will reenable interrupts. */
2393 mod_timer(&vp->timer, jiffies + 1*HZ); 2424 mod_timer(&vp->timer, jiffies + 1*HZ);
2394 break; 2425 break;
2395 } 2426 }
2396 /* Acknowledge the IRQ. */ 2427 /* Acknowledge the IRQ. */
2397 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD); 2428 iowrite16(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
2398 } while ((status = inw(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete)); 2429 } while ((status = ioread16(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
2399 2430
2400 if (vortex_debug > 4) 2431 if (vortex_debug > 4)
2401 printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n", 2432 printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
@@ -2415,11 +2446,11 @@ boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2415{ 2446{
2416 struct net_device *dev = dev_id; 2447 struct net_device *dev = dev_id;
2417 struct vortex_private *vp = netdev_priv(dev); 2448 struct vortex_private *vp = netdev_priv(dev);
2418 long ioaddr; 2449 void __iomem *ioaddr;
2419 int status; 2450 int status;
2420 int work_done = max_interrupt_work; 2451 int work_done = max_interrupt_work;
2421 2452
2422 ioaddr = dev->base_addr; 2453 ioaddr = vp->ioaddr;
2423 2454
2424 /* 2455 /*
2425 * It seems dopey to put the spinlock this early, but we could race against vortex_tx_timeout 2456 * It seems dopey to put the spinlock this early, but we could race against vortex_tx_timeout
@@ -2427,7 +2458,7 @@ boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2427 */ 2458 */
2428 spin_lock(&vp->lock); 2459 spin_lock(&vp->lock);
2429 2460
2430 status = inw(ioaddr + EL3_STATUS); 2461 status = ioread16(ioaddr + EL3_STATUS);
2431 2462
2432 if (vortex_debug > 6) 2463 if (vortex_debug > 6)
2433 printk(KERN_DEBUG "boomerang_interrupt. status=0x%4x\n", status); 2464 printk(KERN_DEBUG "boomerang_interrupt. status=0x%4x\n", status);
@@ -2448,13 +2479,13 @@ boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2448 2479
2449 if (vortex_debug > 4) 2480 if (vortex_debug > 4)
2450 printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n", 2481 printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n",
2451 dev->name, status, inb(ioaddr + Timer)); 2482 dev->name, status, ioread8(ioaddr + Timer));
2452 do { 2483 do {
2453 if (vortex_debug > 5) 2484 if (vortex_debug > 5)
2454 printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n", 2485 printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
2455 dev->name, status); 2486 dev->name, status);
2456 if (status & UpComplete) { 2487 if (status & UpComplete) {
2457 outw(AckIntr | UpComplete, ioaddr + EL3_CMD); 2488 iowrite16(AckIntr | UpComplete, ioaddr + EL3_CMD);
2458 if (vortex_debug > 5) 2489 if (vortex_debug > 5)
2459 printk(KERN_DEBUG "boomerang_interrupt->boomerang_rx\n"); 2490 printk(KERN_DEBUG "boomerang_interrupt->boomerang_rx\n");
2460 boomerang_rx(dev); 2491 boomerang_rx(dev);
@@ -2463,11 +2494,11 @@ boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2463 if (status & DownComplete) { 2494 if (status & DownComplete) {
2464 unsigned int dirty_tx = vp->dirty_tx; 2495 unsigned int dirty_tx = vp->dirty_tx;
2465 2496
2466 outw(AckIntr | DownComplete, ioaddr + EL3_CMD); 2497 iowrite16(AckIntr | DownComplete, ioaddr + EL3_CMD);
2467 while (vp->cur_tx - dirty_tx > 0) { 2498 while (vp->cur_tx - dirty_tx > 0) {
2468 int entry = dirty_tx % TX_RING_SIZE; 2499 int entry = dirty_tx % TX_RING_SIZE;
2469#if 1 /* AKPM: the latter is faster, but cyclone-only */ 2500#if 1 /* AKPM: the latter is faster, but cyclone-only */
2470 if (inl(ioaddr + DownListPtr) == 2501 if (ioread32(ioaddr + DownListPtr) ==
2471 vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc)) 2502 vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc))
2472 break; /* It still hasn't been processed. */ 2503 break; /* It still hasn't been processed. */
2473#else 2504#else
@@ -2514,20 +2545,20 @@ boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2514 /* Disable all pending interrupts. */ 2545 /* Disable all pending interrupts. */
2515 do { 2546 do {
2516 vp->deferred |= status; 2547 vp->deferred |= status;
2517 outw(SetStatusEnb | (~vp->deferred & vp->status_enable), 2548 iowrite16(SetStatusEnb | (~vp->deferred & vp->status_enable),
2518 ioaddr + EL3_CMD); 2549 ioaddr + EL3_CMD);
2519 outw(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD); 2550 iowrite16(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
2520 } while ((status = inw(ioaddr + EL3_CMD)) & IntLatch); 2551 } while ((status = ioread16(ioaddr + EL3_CMD)) & IntLatch);
2521 /* The timer will reenable interrupts. */ 2552 /* The timer will reenable interrupts. */
2522 mod_timer(&vp->timer, jiffies + 1*HZ); 2553 mod_timer(&vp->timer, jiffies + 1*HZ);
2523 break; 2554 break;
2524 } 2555 }
2525 /* Acknowledge the IRQ. */ 2556 /* Acknowledge the IRQ. */
2526 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD); 2557 iowrite16(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
2527 if (vp->cb_fn_base) /* The PCMCIA people are idiots. */ 2558 if (vp->cb_fn_base) /* The PCMCIA people are idiots. */
2528 writel(0x8000, vp->cb_fn_base + 4); 2559 iowrite32(0x8000, vp->cb_fn_base + 4);
2529 2560
2530 } while ((status = inw(ioaddr + EL3_STATUS)) & IntLatch); 2561 } while ((status = ioread16(ioaddr + EL3_STATUS)) & IntLatch);
2531 2562
2532 if (vortex_debug > 4) 2563 if (vortex_debug > 4)
2533 printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n", 2564 printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
@@ -2540,16 +2571,16 @@ handler_exit:
2540static int vortex_rx(struct net_device *dev) 2571static int vortex_rx(struct net_device *dev)
2541{ 2572{
2542 struct vortex_private *vp = netdev_priv(dev); 2573 struct vortex_private *vp = netdev_priv(dev);
2543 long ioaddr = dev->base_addr; 2574 void __iomem *ioaddr = vp->ioaddr;
2544 int i; 2575 int i;
2545 short rx_status; 2576 short rx_status;
2546 2577
2547 if (vortex_debug > 5) 2578 if (vortex_debug > 5)
2548 printk(KERN_DEBUG "vortex_rx(): status %4.4x, rx_status %4.4x.\n", 2579 printk(KERN_DEBUG "vortex_rx(): status %4.4x, rx_status %4.4x.\n",
2549 inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus)); 2580 ioread16(ioaddr+EL3_STATUS), ioread16(ioaddr+RxStatus));
2550 while ((rx_status = inw(ioaddr + RxStatus)) > 0) { 2581 while ((rx_status = ioread16(ioaddr + RxStatus)) > 0) {
2551 if (rx_status & 0x4000) { /* Error, update stats. */ 2582 if (rx_status & 0x4000) { /* Error, update stats. */
2552 unsigned char rx_error = inb(ioaddr + RxErrors); 2583 unsigned char rx_error = ioread8(ioaddr + RxErrors);
2553 if (vortex_debug > 2) 2584 if (vortex_debug > 2)
2554 printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error); 2585 printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
2555 vp->stats.rx_errors++; 2586 vp->stats.rx_errors++;
@@ -2572,34 +2603,35 @@ static int vortex_rx(struct net_device *dev)
2572 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 2603 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
2573 /* 'skb_put()' points to the start of sk_buff data area. */ 2604 /* 'skb_put()' points to the start of sk_buff data area. */
2574 if (vp->bus_master && 2605 if (vp->bus_master &&
2575 ! (inw(ioaddr + Wn7_MasterStatus) & 0x8000)) { 2606 ! (ioread16(ioaddr + Wn7_MasterStatus) & 0x8000)) {
2576 dma_addr_t dma = pci_map_single(VORTEX_PCI(vp), skb_put(skb, pkt_len), 2607 dma_addr_t dma = pci_map_single(VORTEX_PCI(vp), skb_put(skb, pkt_len),
2577 pkt_len, PCI_DMA_FROMDEVICE); 2608 pkt_len, PCI_DMA_FROMDEVICE);
2578 outl(dma, ioaddr + Wn7_MasterAddr); 2609 iowrite32(dma, ioaddr + Wn7_MasterAddr);
2579 outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen); 2610 iowrite16((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
2580 outw(StartDMAUp, ioaddr + EL3_CMD); 2611 iowrite16(StartDMAUp, ioaddr + EL3_CMD);
2581 while (inw(ioaddr + Wn7_MasterStatus) & 0x8000) 2612 while (ioread16(ioaddr + Wn7_MasterStatus) & 0x8000)
2582 ; 2613 ;
2583 pci_unmap_single(VORTEX_PCI(vp), dma, pkt_len, PCI_DMA_FROMDEVICE); 2614 pci_unmap_single(VORTEX_PCI(vp), dma, pkt_len, PCI_DMA_FROMDEVICE);
2584 } else { 2615 } else {
2585 insl(ioaddr + RX_FIFO, skb_put(skb, pkt_len), 2616 ioread32_rep(ioaddr + RX_FIFO,
2586 (pkt_len + 3) >> 2); 2617 skb_put(skb, pkt_len),
2618 (pkt_len + 3) >> 2);
2587 } 2619 }
2588 outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */ 2620 iowrite16(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
2589 skb->protocol = eth_type_trans(skb, dev); 2621 skb->protocol = eth_type_trans(skb, dev);
2590 netif_rx(skb); 2622 netif_rx(skb);
2591 dev->last_rx = jiffies; 2623 dev->last_rx = jiffies;
2592 vp->stats.rx_packets++; 2624 vp->stats.rx_packets++;
2593 /* Wait a limited time to go to next packet. */ 2625 /* Wait a limited time to go to next packet. */
2594 for (i = 200; i >= 0; i--) 2626 for (i = 200; i >= 0; i--)
2595 if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress)) 2627 if ( ! (ioread16(ioaddr + EL3_STATUS) & CmdInProgress))
2596 break; 2628 break;
2597 continue; 2629 continue;
2598 } else if (vortex_debug > 0) 2630 } else if (vortex_debug > 0)
2599 printk(KERN_NOTICE "%s: No memory to allocate a sk_buff of " 2631 printk(KERN_NOTICE "%s: No memory to allocate a sk_buff of "
2600 "size %d.\n", dev->name, pkt_len); 2632 "size %d.\n", dev->name, pkt_len);
2633 vp->stats.rx_dropped++;
2601 } 2634 }
2602 vp->stats.rx_dropped++;
2603 issue_and_wait(dev, RxDiscard); 2635 issue_and_wait(dev, RxDiscard);
2604 } 2636 }
2605 2637
@@ -2611,12 +2643,12 @@ boomerang_rx(struct net_device *dev)
2611{ 2643{
2612 struct vortex_private *vp = netdev_priv(dev); 2644 struct vortex_private *vp = netdev_priv(dev);
2613 int entry = vp->cur_rx % RX_RING_SIZE; 2645 int entry = vp->cur_rx % RX_RING_SIZE;
2614 long ioaddr = dev->base_addr; 2646 void __iomem *ioaddr = vp->ioaddr;
2615 int rx_status; 2647 int rx_status;
2616 int rx_work_limit = vp->dirty_rx + RX_RING_SIZE - vp->cur_rx; 2648 int rx_work_limit = vp->dirty_rx + RX_RING_SIZE - vp->cur_rx;
2617 2649
2618 if (vortex_debug > 5) 2650 if (vortex_debug > 5)
2619 printk(KERN_DEBUG "boomerang_rx(): status %4.4x\n", inw(ioaddr+EL3_STATUS)); 2651 printk(KERN_DEBUG "boomerang_rx(): status %4.4x\n", ioread16(ioaddr+EL3_STATUS));
2620 2652
2621 while ((rx_status = le32_to_cpu(vp->rx_ring[entry].status)) & RxDComplete){ 2653 while ((rx_status = le32_to_cpu(vp->rx_ring[entry].status)) & RxDComplete){
2622 if (--rx_work_limit < 0) 2654 if (--rx_work_limit < 0)
@@ -2699,7 +2731,7 @@ boomerang_rx(struct net_device *dev)
2699 vp->rx_skbuff[entry] = skb; 2731 vp->rx_skbuff[entry] = skb;
2700 } 2732 }
2701 vp->rx_ring[entry].status = 0; /* Clear complete bit. */ 2733 vp->rx_ring[entry].status = 0; /* Clear complete bit. */
2702 outw(UpUnstall, ioaddr + EL3_CMD); 2734 iowrite16(UpUnstall, ioaddr + EL3_CMD);
2703 } 2735 }
2704 return 0; 2736 return 0;
2705} 2737}
@@ -2728,7 +2760,7 @@ static void
2728vortex_down(struct net_device *dev, int final_down) 2760vortex_down(struct net_device *dev, int final_down)
2729{ 2761{
2730 struct vortex_private *vp = netdev_priv(dev); 2762 struct vortex_private *vp = netdev_priv(dev);
2731 long ioaddr = dev->base_addr; 2763 void __iomem *ioaddr = vp->ioaddr;
2732 2764
2733 netif_stop_queue (dev); 2765 netif_stop_queue (dev);
2734 2766
@@ -2736,26 +2768,26 @@ vortex_down(struct net_device *dev, int final_down)
2736 del_timer_sync(&vp->timer); 2768 del_timer_sync(&vp->timer);
2737 2769
2738 /* Turn off statistics ASAP. We update vp->stats below. */ 2770 /* Turn off statistics ASAP. We update vp->stats below. */
2739 outw(StatsDisable, ioaddr + EL3_CMD); 2771 iowrite16(StatsDisable, ioaddr + EL3_CMD);
2740 2772
2741 /* Disable the receiver and transmitter. */ 2773 /* Disable the receiver and transmitter. */
2742 outw(RxDisable, ioaddr + EL3_CMD); 2774 iowrite16(RxDisable, ioaddr + EL3_CMD);
2743 outw(TxDisable, ioaddr + EL3_CMD); 2775 iowrite16(TxDisable, ioaddr + EL3_CMD);
2744 2776
2745 /* Disable receiving 802.1q tagged frames */ 2777 /* Disable receiving 802.1q tagged frames */
2746 set_8021q_mode(dev, 0); 2778 set_8021q_mode(dev, 0);
2747 2779
2748 if (dev->if_port == XCVR_10base2) 2780 if (dev->if_port == XCVR_10base2)
2749 /* Turn off thinnet power. Green! */ 2781 /* Turn off thinnet power. Green! */
2750 outw(StopCoax, ioaddr + EL3_CMD); 2782 iowrite16(StopCoax, ioaddr + EL3_CMD);
2751 2783
2752 outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD); 2784 iowrite16(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
2753 2785
2754 update_stats(ioaddr, dev); 2786 update_stats(ioaddr, dev);
2755 if (vp->full_bus_master_rx) 2787 if (vp->full_bus_master_rx)
2756 outl(0, ioaddr + UpListPtr); 2788 iowrite32(0, ioaddr + UpListPtr);
2757 if (vp->full_bus_master_tx) 2789 if (vp->full_bus_master_tx)
2758 outl(0, ioaddr + DownListPtr); 2790 iowrite32(0, ioaddr + DownListPtr);
2759 2791
2760 if (final_down && VORTEX_PCI(vp)) { 2792 if (final_down && VORTEX_PCI(vp)) {
2761 vp->pm_state_valid = 1; 2793 vp->pm_state_valid = 1;
@@ -2768,7 +2800,7 @@ static int
2768vortex_close(struct net_device *dev) 2800vortex_close(struct net_device *dev)
2769{ 2801{
2770 struct vortex_private *vp = netdev_priv(dev); 2802 struct vortex_private *vp = netdev_priv(dev);
2771 long ioaddr = dev->base_addr; 2803 void __iomem *ioaddr = vp->ioaddr;
2772 int i; 2804 int i;
2773 2805
2774 if (netif_device_present(dev)) 2806 if (netif_device_present(dev))
@@ -2776,17 +2808,18 @@ vortex_close(struct net_device *dev)
2776 2808
2777 if (vortex_debug > 1) { 2809 if (vortex_debug > 1) {
2778 printk(KERN_DEBUG"%s: vortex_close() status %4.4x, Tx status %2.2x.\n", 2810 printk(KERN_DEBUG"%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
2779 dev->name, inw(ioaddr + EL3_STATUS), inb(ioaddr + TxStatus)); 2811 dev->name, ioread16(ioaddr + EL3_STATUS), ioread8(ioaddr + TxStatus));
2780 printk(KERN_DEBUG "%s: vortex close stats: rx_nocopy %d rx_copy %d" 2812 printk(KERN_DEBUG "%s: vortex close stats: rx_nocopy %d rx_copy %d"
2781 " tx_queued %d Rx pre-checksummed %d.\n", 2813 " tx_queued %d Rx pre-checksummed %d.\n",
2782 dev->name, vp->rx_nocopy, vp->rx_copy, vp->queued_packet, vp->rx_csumhits); 2814 dev->name, vp->rx_nocopy, vp->rx_copy, vp->queued_packet, vp->rx_csumhits);
2783 } 2815 }
2784 2816
2785#if DO_ZEROCOPY 2817#if DO_ZEROCOPY
2786 if ( vp->rx_csumhits && 2818 if (vp->rx_csumhits &&
2787 ((vp->drv_flags & HAS_HWCKSM) == 0) && 2819 (vp->drv_flags & HAS_HWCKSM) == 0 &&
2788 (hw_checksums[vp->card_idx] == -1)) { 2820 (vp->card_idx >= MAX_UNITS || hw_checksums[vp->card_idx] == -1)) {
2789 printk(KERN_WARNING "%s supports hardware checksums, and we're not using them!\n", dev->name); 2821 printk(KERN_WARNING "%s supports hardware checksums, and we're "
2822 "not using them!\n", dev->name);
2790 } 2823 }
2791#endif 2824#endif
2792 2825
@@ -2830,18 +2863,18 @@ dump_tx_ring(struct net_device *dev)
2830{ 2863{
2831 if (vortex_debug > 0) { 2864 if (vortex_debug > 0) {
2832 struct vortex_private *vp = netdev_priv(dev); 2865 struct vortex_private *vp = netdev_priv(dev);
2833 long ioaddr = dev->base_addr; 2866 void __iomem *ioaddr = vp->ioaddr;
2834 2867
2835 if (vp->full_bus_master_tx) { 2868 if (vp->full_bus_master_tx) {
2836 int i; 2869 int i;
2837 int stalled = inl(ioaddr + PktStatus) & 0x04; /* Possible racy. But it's only debug stuff */ 2870 int stalled = ioread32(ioaddr + PktStatus) & 0x04; /* Possible racy. But it's only debug stuff */
2838 2871
2839 printk(KERN_ERR " Flags; bus-master %d, dirty %d(%d) current %d(%d)\n", 2872 printk(KERN_ERR " Flags; bus-master %d, dirty %d(%d) current %d(%d)\n",
2840 vp->full_bus_master_tx, 2873 vp->full_bus_master_tx,
2841 vp->dirty_tx, vp->dirty_tx % TX_RING_SIZE, 2874 vp->dirty_tx, vp->dirty_tx % TX_RING_SIZE,
2842 vp->cur_tx, vp->cur_tx % TX_RING_SIZE); 2875 vp->cur_tx, vp->cur_tx % TX_RING_SIZE);
2843 printk(KERN_ERR " Transmit list %8.8x vs. %p.\n", 2876 printk(KERN_ERR " Transmit list %8.8x vs. %p.\n",
2844 inl(ioaddr + DownListPtr), 2877 ioread32(ioaddr + DownListPtr),
2845 &vp->tx_ring[vp->dirty_tx % TX_RING_SIZE]); 2878 &vp->tx_ring[vp->dirty_tx % TX_RING_SIZE]);
2846 issue_and_wait(dev, DownStall); 2879 issue_and_wait(dev, DownStall);
2847 for (i = 0; i < TX_RING_SIZE; i++) { 2880 for (i = 0; i < TX_RING_SIZE; i++) {
@@ -2855,7 +2888,7 @@ dump_tx_ring(struct net_device *dev)
2855 le32_to_cpu(vp->tx_ring[i].status)); 2888 le32_to_cpu(vp->tx_ring[i].status));
2856 } 2889 }
2857 if (!stalled) 2890 if (!stalled)
2858 outw(DownUnstall, ioaddr + EL3_CMD); 2891 iowrite16(DownUnstall, ioaddr + EL3_CMD);
2859 } 2892 }
2860 } 2893 }
2861} 2894}
@@ -2863,11 +2896,12 @@ dump_tx_ring(struct net_device *dev)
2863static struct net_device_stats *vortex_get_stats(struct net_device *dev) 2896static struct net_device_stats *vortex_get_stats(struct net_device *dev)
2864{ 2897{
2865 struct vortex_private *vp = netdev_priv(dev); 2898 struct vortex_private *vp = netdev_priv(dev);
2899 void __iomem *ioaddr = vp->ioaddr;
2866 unsigned long flags; 2900 unsigned long flags;
2867 2901
2868 if (netif_device_present(dev)) { /* AKPM: Used to be netif_running */ 2902 if (netif_device_present(dev)) { /* AKPM: Used to be netif_running */
2869 spin_lock_irqsave (&vp->lock, flags); 2903 spin_lock_irqsave (&vp->lock, flags);
2870 update_stats(dev->base_addr, dev); 2904 update_stats(ioaddr, dev);
2871 spin_unlock_irqrestore (&vp->lock, flags); 2905 spin_unlock_irqrestore (&vp->lock, flags);
2872 } 2906 }
2873 return &vp->stats; 2907 return &vp->stats;
@@ -2880,37 +2914,37 @@ static struct net_device_stats *vortex_get_stats(struct net_device *dev)
2880 table. This is done by checking that the ASM (!) code generated uses 2914 table. This is done by checking that the ASM (!) code generated uses
2881 atomic updates with '+='. 2915 atomic updates with '+='.
2882 */ 2916 */
2883static void update_stats(long ioaddr, struct net_device *dev) 2917static void update_stats(void __iomem *ioaddr, struct net_device *dev)
2884{ 2918{
2885 struct vortex_private *vp = netdev_priv(dev); 2919 struct vortex_private *vp = netdev_priv(dev);
2886 int old_window = inw(ioaddr + EL3_CMD); 2920 int old_window = ioread16(ioaddr + EL3_CMD);
2887 2921
2888 if (old_window == 0xffff) /* Chip suspended or ejected. */ 2922 if (old_window == 0xffff) /* Chip suspended or ejected. */
2889 return; 2923 return;
2890 /* Unlike the 3c5x9 we need not turn off stats updates while reading. */ 2924 /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
2891 /* Switch to the stats window, and read everything. */ 2925 /* Switch to the stats window, and read everything. */
2892 EL3WINDOW(6); 2926 EL3WINDOW(6);
2893 vp->stats.tx_carrier_errors += inb(ioaddr + 0); 2927 vp->stats.tx_carrier_errors += ioread8(ioaddr + 0);
2894 vp->stats.tx_heartbeat_errors += inb(ioaddr + 1); 2928 vp->stats.tx_heartbeat_errors += ioread8(ioaddr + 1);
2895 vp->stats.collisions += inb(ioaddr + 3); 2929 vp->stats.collisions += ioread8(ioaddr + 3);
2896 vp->stats.tx_window_errors += inb(ioaddr + 4); 2930 vp->stats.tx_window_errors += ioread8(ioaddr + 4);
2897 vp->stats.rx_fifo_errors += inb(ioaddr + 5); 2931 vp->stats.rx_fifo_errors += ioread8(ioaddr + 5);
2898 vp->stats.tx_packets += inb(ioaddr + 6); 2932 vp->stats.tx_packets += ioread8(ioaddr + 6);
2899 vp->stats.tx_packets += (inb(ioaddr + 9)&0x30) << 4; 2933 vp->stats.tx_packets += (ioread8(ioaddr + 9)&0x30) << 4;
2900 /* Rx packets */ inb(ioaddr + 7); /* Must read to clear */ 2934 /* Rx packets */ ioread8(ioaddr + 7); /* Must read to clear */
2901 /* Don't bother with register 9, an extension of registers 6&7. 2935 /* Don't bother with register 9, an extension of registers 6&7.
2902 If we do use the 6&7 values the atomic update assumption above 2936 If we do use the 6&7 values the atomic update assumption above
2903 is invalid. */ 2937 is invalid. */
2904 vp->stats.rx_bytes += inw(ioaddr + 10); 2938 vp->stats.rx_bytes += ioread16(ioaddr + 10);
2905 vp->stats.tx_bytes += inw(ioaddr + 12); 2939 vp->stats.tx_bytes += ioread16(ioaddr + 12);
2906 /* Extra stats for get_ethtool_stats() */ 2940 /* Extra stats for get_ethtool_stats() */
2907 vp->xstats.tx_multiple_collisions += inb(ioaddr + 2); 2941 vp->xstats.tx_multiple_collisions += ioread8(ioaddr + 2);
2908 vp->xstats.tx_deferred += inb(ioaddr + 8); 2942 vp->xstats.tx_deferred += ioread8(ioaddr + 8);
2909 EL3WINDOW(4); 2943 EL3WINDOW(4);
2910 vp->xstats.rx_bad_ssd += inb(ioaddr + 12); 2944 vp->xstats.rx_bad_ssd += ioread8(ioaddr + 12);
2911 2945
2912 { 2946 {
2913 u8 up = inb(ioaddr + 13); 2947 u8 up = ioread8(ioaddr + 13);
2914 vp->stats.rx_bytes += (up & 0x0f) << 16; 2948 vp->stats.rx_bytes += (up & 0x0f) << 16;
2915 vp->stats.tx_bytes += (up & 0xf0) << 12; 2949 vp->stats.tx_bytes += (up & 0xf0) << 12;
2916 } 2950 }
@@ -2922,7 +2956,7 @@ static void update_stats(long ioaddr, struct net_device *dev)
2922static int vortex_nway_reset(struct net_device *dev) 2956static int vortex_nway_reset(struct net_device *dev)
2923{ 2957{
2924 struct vortex_private *vp = netdev_priv(dev); 2958 struct vortex_private *vp = netdev_priv(dev);
2925 long ioaddr = dev->base_addr; 2959 void __iomem *ioaddr = vp->ioaddr;
2926 unsigned long flags; 2960 unsigned long flags;
2927 int rc; 2961 int rc;
2928 2962
@@ -2936,7 +2970,7 @@ static int vortex_nway_reset(struct net_device *dev)
2936static u32 vortex_get_link(struct net_device *dev) 2970static u32 vortex_get_link(struct net_device *dev)
2937{ 2971{
2938 struct vortex_private *vp = netdev_priv(dev); 2972 struct vortex_private *vp = netdev_priv(dev);
2939 long ioaddr = dev->base_addr; 2973 void __iomem *ioaddr = vp->ioaddr;
2940 unsigned long flags; 2974 unsigned long flags;
2941 int rc; 2975 int rc;
2942 2976
@@ -2950,7 +2984,7 @@ static u32 vortex_get_link(struct net_device *dev)
2950static int vortex_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 2984static int vortex_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2951{ 2985{
2952 struct vortex_private *vp = netdev_priv(dev); 2986 struct vortex_private *vp = netdev_priv(dev);
2953 long ioaddr = dev->base_addr; 2987 void __iomem *ioaddr = vp->ioaddr;
2954 unsigned long flags; 2988 unsigned long flags;
2955 int rc; 2989 int rc;
2956 2990
@@ -2964,7 +2998,7 @@ static int vortex_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2964static int vortex_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 2998static int vortex_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2965{ 2999{
2966 struct vortex_private *vp = netdev_priv(dev); 3000 struct vortex_private *vp = netdev_priv(dev);
2967 long ioaddr = dev->base_addr; 3001 void __iomem *ioaddr = vp->ioaddr;
2968 unsigned long flags; 3002 unsigned long flags;
2969 int rc; 3003 int rc;
2970 3004
@@ -2994,10 +3028,11 @@ static void vortex_get_ethtool_stats(struct net_device *dev,
2994 struct ethtool_stats *stats, u64 *data) 3028 struct ethtool_stats *stats, u64 *data)
2995{ 3029{
2996 struct vortex_private *vp = netdev_priv(dev); 3030 struct vortex_private *vp = netdev_priv(dev);
3031 void __iomem *ioaddr = vp->ioaddr;
2997 unsigned long flags; 3032 unsigned long flags;
2998 3033
2999 spin_lock_irqsave(&vp->lock, flags); 3034 spin_lock_irqsave(&vp->lock, flags);
3000 update_stats(dev->base_addr, dev); 3035 update_stats(ioaddr, dev);
3001 spin_unlock_irqrestore(&vp->lock, flags); 3036 spin_unlock_irqrestore(&vp->lock, flags);
3002 3037
3003 data[0] = vp->xstats.tx_deferred; 3038 data[0] = vp->xstats.tx_deferred;
@@ -3047,6 +3082,7 @@ static struct ethtool_ops vortex_ethtool_ops = {
3047 .set_settings = vortex_set_settings, 3082 .set_settings = vortex_set_settings,
3048 .get_link = vortex_get_link, 3083 .get_link = vortex_get_link,
3049 .nway_reset = vortex_nway_reset, 3084 .nway_reset = vortex_nway_reset,
3085 .get_perm_addr = ethtool_op_get_perm_addr,
3050}; 3086};
3051 3087
3052#ifdef CONFIG_PCI 3088#ifdef CONFIG_PCI
@@ -3057,7 +3093,7 @@ static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3057{ 3093{
3058 int err; 3094 int err;
3059 struct vortex_private *vp = netdev_priv(dev); 3095 struct vortex_private *vp = netdev_priv(dev);
3060 long ioaddr = dev->base_addr; 3096 void __iomem *ioaddr = vp->ioaddr;
3061 unsigned long flags; 3097 unsigned long flags;
3062 int state = 0; 3098 int state = 0;
3063 3099
@@ -3085,7 +3121,8 @@ static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3085 the chip has a very clean way to set the mode, unlike many others. */ 3121 the chip has a very clean way to set the mode, unlike many others. */
3086static void set_rx_mode(struct net_device *dev) 3122static void set_rx_mode(struct net_device *dev)
3087{ 3123{
3088 long ioaddr = dev->base_addr; 3124 struct vortex_private *vp = netdev_priv(dev);
3125 void __iomem *ioaddr = vp->ioaddr;
3089 int new_mode; 3126 int new_mode;
3090 3127
3091 if (dev->flags & IFF_PROMISC) { 3128 if (dev->flags & IFF_PROMISC) {
@@ -3097,7 +3134,7 @@ static void set_rx_mode(struct net_device *dev)
3097 } else 3134 } else
3098 new_mode = SetRxFilter | RxStation | RxBroadcast; 3135 new_mode = SetRxFilter | RxStation | RxBroadcast;
3099 3136
3100 outw(new_mode, ioaddr + EL3_CMD); 3137 iowrite16(new_mode, ioaddr + EL3_CMD);
3101} 3138}
3102 3139
3103#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) 3140#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
@@ -3111,8 +3148,8 @@ static void set_rx_mode(struct net_device *dev)
3111static void set_8021q_mode(struct net_device *dev, int enable) 3148static void set_8021q_mode(struct net_device *dev, int enable)
3112{ 3149{
3113 struct vortex_private *vp = netdev_priv(dev); 3150 struct vortex_private *vp = netdev_priv(dev);
3114 long ioaddr = dev->base_addr; 3151 void __iomem *ioaddr = vp->ioaddr;
3115 int old_window = inw(ioaddr + EL3_CMD); 3152 int old_window = ioread16(ioaddr + EL3_CMD);
3116 int mac_ctrl; 3153 int mac_ctrl;
3117 3154
3118 if ((vp->drv_flags&IS_CYCLONE) || (vp->drv_flags&IS_TORNADO)) { 3155 if ((vp->drv_flags&IS_CYCLONE) || (vp->drv_flags&IS_TORNADO)) {
@@ -3124,24 +3161,24 @@ static void set_8021q_mode(struct net_device *dev, int enable)
3124 max_pkt_size += 4; /* 802.1Q VLAN tag */ 3161 max_pkt_size += 4; /* 802.1Q VLAN tag */
3125 3162
3126 EL3WINDOW(3); 3163 EL3WINDOW(3);
3127 outw(max_pkt_size, ioaddr+Wn3_MaxPktSize); 3164 iowrite16(max_pkt_size, ioaddr+Wn3_MaxPktSize);
3128 3165
3129 /* set VlanEtherType to let the hardware checksumming 3166 /* set VlanEtherType to let the hardware checksumming
3130 treat tagged frames correctly */ 3167 treat tagged frames correctly */
3131 EL3WINDOW(7); 3168 EL3WINDOW(7);
3132 outw(VLAN_ETHER_TYPE, ioaddr+Wn7_VlanEtherType); 3169 iowrite16(VLAN_ETHER_TYPE, ioaddr+Wn7_VlanEtherType);
3133 } else { 3170 } else {
3134 /* on older cards we have to enable large frames */ 3171 /* on older cards we have to enable large frames */
3135 3172
3136 vp->large_frames = dev->mtu > 1500 || enable; 3173 vp->large_frames = dev->mtu > 1500 || enable;
3137 3174
3138 EL3WINDOW(3); 3175 EL3WINDOW(3);
3139 mac_ctrl = inw(ioaddr+Wn3_MAC_Ctrl); 3176 mac_ctrl = ioread16(ioaddr+Wn3_MAC_Ctrl);
3140 if (vp->large_frames) 3177 if (vp->large_frames)
3141 mac_ctrl |= 0x40; 3178 mac_ctrl |= 0x40;
3142 else 3179 else
3143 mac_ctrl &= ~0x40; 3180 mac_ctrl &= ~0x40;
3144 outw(mac_ctrl, ioaddr+Wn3_MAC_Ctrl); 3181 iowrite16(mac_ctrl, ioaddr+Wn3_MAC_Ctrl);
3145 } 3182 }
3146 3183
3147 EL3WINDOW(old_window); 3184 EL3WINDOW(old_window);
@@ -3163,7 +3200,7 @@ static void set_8021q_mode(struct net_device *dev, int enable)
3163/* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually 3200/* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually
3164 met by back-to-back PCI I/O cycles, but we insert a delay to avoid 3201 met by back-to-back PCI I/O cycles, but we insert a delay to avoid
3165 "overclocking" issues. */ 3202 "overclocking" issues. */
3166#define mdio_delay() inl(mdio_addr) 3203#define mdio_delay() ioread32(mdio_addr)
3167 3204
3168#define MDIO_SHIFT_CLK 0x01 3205#define MDIO_SHIFT_CLK 0x01
3169#define MDIO_DIR_WRITE 0x04 3206#define MDIO_DIR_WRITE 0x04
@@ -3174,15 +3211,15 @@ static void set_8021q_mode(struct net_device *dev, int enable)
3174 3211
3175/* Generate the preamble required for initial synchronization and 3212/* Generate the preamble required for initial synchronization and
3176 a few older transceivers. */ 3213 a few older transceivers. */
3177static void mdio_sync(long ioaddr, int bits) 3214static void mdio_sync(void __iomem *ioaddr, int bits)
3178{ 3215{
3179 long mdio_addr = ioaddr + Wn4_PhysicalMgmt; 3216 void __iomem *mdio_addr = ioaddr + Wn4_PhysicalMgmt;
3180 3217
3181 /* Establish sync by sending at least 32 logic ones. */ 3218 /* Establish sync by sending at least 32 logic ones. */
3182 while (-- bits >= 0) { 3219 while (-- bits >= 0) {
3183 outw(MDIO_DATA_WRITE1, mdio_addr); 3220 iowrite16(MDIO_DATA_WRITE1, mdio_addr);
3184 mdio_delay(); 3221 mdio_delay();
3185 outw(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr); 3222 iowrite16(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
3186 mdio_delay(); 3223 mdio_delay();
3187 } 3224 }
3188} 3225}
@@ -3190,10 +3227,11 @@ static void mdio_sync(long ioaddr, int bits)
3190static int mdio_read(struct net_device *dev, int phy_id, int location) 3227static int mdio_read(struct net_device *dev, int phy_id, int location)
3191{ 3228{
3192 int i; 3229 int i;
3193 long ioaddr = dev->base_addr; 3230 struct vortex_private *vp = netdev_priv(dev);
3231 void __iomem *ioaddr = vp->ioaddr;
3194 int read_cmd = (0xf6 << 10) | (phy_id << 5) | location; 3232 int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
3195 unsigned int retval = 0; 3233 unsigned int retval = 0;
3196 long mdio_addr = ioaddr + Wn4_PhysicalMgmt; 3234 void __iomem *mdio_addr = ioaddr + Wn4_PhysicalMgmt;
3197 3235
3198 if (mii_preamble_required) 3236 if (mii_preamble_required)
3199 mdio_sync(ioaddr, 32); 3237 mdio_sync(ioaddr, 32);
@@ -3201,17 +3239,17 @@ static int mdio_read(struct net_device *dev, int phy_id, int location)
3201 /* Shift the read command bits out. */ 3239 /* Shift the read command bits out. */
3202 for (i = 14; i >= 0; i--) { 3240 for (i = 14; i >= 0; i--) {
3203 int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0; 3241 int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
3204 outw(dataval, mdio_addr); 3242 iowrite16(dataval, mdio_addr);
3205 mdio_delay(); 3243 mdio_delay();
3206 outw(dataval | MDIO_SHIFT_CLK, mdio_addr); 3244 iowrite16(dataval | MDIO_SHIFT_CLK, mdio_addr);
3207 mdio_delay(); 3245 mdio_delay();
3208 } 3246 }
3209 /* Read the two transition, 16 data, and wire-idle bits. */ 3247 /* Read the two transition, 16 data, and wire-idle bits. */
3210 for (i = 19; i > 0; i--) { 3248 for (i = 19; i > 0; i--) {
3211 outw(MDIO_ENB_IN, mdio_addr); 3249 iowrite16(MDIO_ENB_IN, mdio_addr);
3212 mdio_delay(); 3250 mdio_delay();
3213 retval = (retval << 1) | ((inw(mdio_addr) & MDIO_DATA_READ) ? 1 : 0); 3251 retval = (retval << 1) | ((ioread16(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
3214 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr); 3252 iowrite16(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
3215 mdio_delay(); 3253 mdio_delay();
3216 } 3254 }
3217 return retval & 0x20000 ? 0xffff : retval>>1 & 0xffff; 3255 return retval & 0x20000 ? 0xffff : retval>>1 & 0xffff;
@@ -3219,9 +3257,10 @@ static int mdio_read(struct net_device *dev, int phy_id, int location)
3219 3257
3220static void mdio_write(struct net_device *dev, int phy_id, int location, int value) 3258static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
3221{ 3259{
3222 long ioaddr = dev->base_addr; 3260 struct vortex_private *vp = netdev_priv(dev);
3261 void __iomem *ioaddr = vp->ioaddr;
3223 int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value; 3262 int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
3224 long mdio_addr = ioaddr + Wn4_PhysicalMgmt; 3263 void __iomem *mdio_addr = ioaddr + Wn4_PhysicalMgmt;
3225 int i; 3264 int i;
3226 3265
3227 if (mii_preamble_required) 3266 if (mii_preamble_required)
@@ -3230,16 +3269,16 @@ static void mdio_write(struct net_device *dev, int phy_id, int location, int val
3230 /* Shift the command bits out. */ 3269 /* Shift the command bits out. */
3231 for (i = 31; i >= 0; i--) { 3270 for (i = 31; i >= 0; i--) {
3232 int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0; 3271 int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
3233 outw(dataval, mdio_addr); 3272 iowrite16(dataval, mdio_addr);
3234 mdio_delay(); 3273 mdio_delay();
3235 outw(dataval | MDIO_SHIFT_CLK, mdio_addr); 3274 iowrite16(dataval | MDIO_SHIFT_CLK, mdio_addr);
3236 mdio_delay(); 3275 mdio_delay();
3237 } 3276 }
3238 /* Leave the interface idle. */ 3277 /* Leave the interface idle. */
3239 for (i = 1; i >= 0; i--) { 3278 for (i = 1; i >= 0; i--) {
3240 outw(MDIO_ENB_IN, mdio_addr); 3279 iowrite16(MDIO_ENB_IN, mdio_addr);
3241 mdio_delay(); 3280 mdio_delay();
3242 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr); 3281 iowrite16(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
3243 mdio_delay(); 3282 mdio_delay();
3244 } 3283 }
3245 return; 3284 return;
@@ -3250,15 +3289,15 @@ static void mdio_write(struct net_device *dev, int phy_id, int location, int val
3250static void acpi_set_WOL(struct net_device *dev) 3289static void acpi_set_WOL(struct net_device *dev)
3251{ 3290{
3252 struct vortex_private *vp = netdev_priv(dev); 3291 struct vortex_private *vp = netdev_priv(dev);
3253 long ioaddr = dev->base_addr; 3292 void __iomem *ioaddr = vp->ioaddr;
3254 3293
3255 if (vp->enable_wol) { 3294 if (vp->enable_wol) {
3256 /* Power up on: 1==Downloaded Filter, 2==Magic Packets, 4==Link Status. */ 3295 /* Power up on: 1==Downloaded Filter, 2==Magic Packets, 4==Link Status. */
3257 EL3WINDOW(7); 3296 EL3WINDOW(7);
3258 outw(2, ioaddr + 0x0c); 3297 iowrite16(2, ioaddr + 0x0c);
3259 /* The RxFilter must accept the WOL frames. */ 3298 /* The RxFilter must accept the WOL frames. */
3260 outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD); 3299 iowrite16(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
3261 outw(RxEnable, ioaddr + EL3_CMD); 3300 iowrite16(RxEnable, ioaddr + EL3_CMD);
3262 3301
3263 pci_enable_wake(VORTEX_PCI(vp), 0, 1); 3302 pci_enable_wake(VORTEX_PCI(vp), 0, 1);
3264 3303
@@ -3280,10 +3319,9 @@ static void __devexit vortex_remove_one (struct pci_dev *pdev)
3280 3319
3281 vp = netdev_priv(dev); 3320 vp = netdev_priv(dev);
3282 3321
3283 /* AKPM: FIXME: we should have 3322 if (vp->cb_fn_base)
3284 * if (vp->cb_fn_base) iounmap(vp->cb_fn_base); 3323 pci_iounmap(VORTEX_PCI(vp), vp->cb_fn_base);
3285 * here 3324
3286 */
3287 unregister_netdev(dev); 3325 unregister_netdev(dev);
3288 3326
3289 if (VORTEX_PCI(vp)) { 3327 if (VORTEX_PCI(vp)) {
@@ -3293,8 +3331,10 @@ static void __devexit vortex_remove_one (struct pci_dev *pdev)
3293 pci_disable_device(VORTEX_PCI(vp)); 3331 pci_disable_device(VORTEX_PCI(vp));
3294 } 3332 }
3295 /* Should really use issue_and_wait() here */ 3333 /* Should really use issue_and_wait() here */
3296 outw(TotalReset | ((vp->drv_flags & EEPROM_RESET) ? 0x04 : 0x14), 3334 iowrite16(TotalReset | ((vp->drv_flags & EEPROM_RESET) ? 0x04 : 0x14),
3297 dev->base_addr + EL3_CMD); 3335 vp->ioaddr + EL3_CMD);
3336
3337 pci_iounmap(VORTEX_PCI(vp), vp->ioaddr);
3298 3338
3299 pci_free_consistent(pdev, 3339 pci_free_consistent(pdev,
3300 sizeof(struct boom_rx_desc) * RX_RING_SIZE 3340 sizeof(struct boom_rx_desc) * RX_RING_SIZE
@@ -3342,7 +3382,7 @@ static int __init vortex_init (void)
3342static void __exit vortex_eisa_cleanup (void) 3382static void __exit vortex_eisa_cleanup (void)
3343{ 3383{
3344 struct vortex_private *vp; 3384 struct vortex_private *vp;
3345 long ioaddr; 3385 void __iomem *ioaddr;
3346 3386
3347#ifdef CONFIG_EISA 3387#ifdef CONFIG_EISA
3348 /* Take care of the EISA devices */ 3388 /* Take care of the EISA devices */
@@ -3351,11 +3391,13 @@ static void __exit vortex_eisa_cleanup (void)
3351 3391
3352 if (compaq_net_device) { 3392 if (compaq_net_device) {
3353 vp = compaq_net_device->priv; 3393 vp = compaq_net_device->priv;
3354 ioaddr = compaq_net_device->base_addr; 3394 ioaddr = ioport_map(compaq_net_device->base_addr,
3395 VORTEX_TOTAL_SIZE);
3355 3396
3356 unregister_netdev (compaq_net_device); 3397 unregister_netdev (compaq_net_device);
3357 outw (TotalReset, ioaddr + EL3_CMD); 3398 iowrite16 (TotalReset, ioaddr + EL3_CMD);
3358 release_region (ioaddr, VORTEX_TOTAL_SIZE); 3399 release_region(compaq_net_device->base_addr,
3400 VORTEX_TOTAL_SIZE);
3359 3401
3360 free_netdev (compaq_net_device); 3402 free_netdev (compaq_net_device);
3361 } 3403 }
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 85504fb900da..bd6983d1afba 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -18,8 +18,8 @@
18 * Much better multiple PHY support by Magnus Damm. 18 * Much better multiple PHY support by Magnus Damm.
19 * Copyright (c) 2000 Ericsson Radio Systems AB. 19 * Copyright (c) 2000 Ericsson Radio Systems AB.
20 * 20 *
21 * Support for FEC controller of ColdFire/5270/5271/5272/5274/5275/5280/5282. 21 * Support for FEC controller of ColdFire processors.
22 * Copyright (c) 2001-2004 Greg Ungerer (gerg@snapgear.com) 22 * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
23 * 23 *
24 * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be) 24 * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
25 * Copyright (c) 2004-2005 Macq Electronique SA. 25 * Copyright (c) 2004-2005 Macq Electronique SA.
@@ -50,7 +50,8 @@
50#include <asm/pgtable.h> 50#include <asm/pgtable.h>
51 51
52#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || \ 52#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || \
53 defined(CONFIG_M5272) || defined(CONFIG_M528x) 53 defined(CONFIG_M5272) || defined(CONFIG_M528x) || \
54 defined(CONFIG_M520x)
54#include <asm/coldfire.h> 55#include <asm/coldfire.h>
55#include <asm/mcfsim.h> 56#include <asm/mcfsim.h>
56#include "fec.h" 57#include "fec.h"
@@ -77,6 +78,8 @@ static unsigned int fec_hw[] = {
77 (MCF_MBAR + 0x1800), 78 (MCF_MBAR + 0x1800),
78#elif defined(CONFIG_M523x) || defined(CONFIG_M528x) 79#elif defined(CONFIG_M523x) || defined(CONFIG_M528x)
79 (MCF_MBAR + 0x1000), 80 (MCF_MBAR + 0x1000),
81#elif defined(CONFIG_M520x)
82 (MCF_MBAR+0x30000),
80#else 83#else
81 &(((immap_t *)IMAP_ADDR)->im_cpm.cp_fec), 84 &(((immap_t *)IMAP_ADDR)->im_cpm.cp_fec),
82#endif 85#endif
@@ -139,6 +142,10 @@ typedef struct {
139#define TX_RING_SIZE 16 /* Must be power of two */ 142#define TX_RING_SIZE 16 /* Must be power of two */
140#define TX_RING_MOD_MASK 15 /* for this to work */ 143#define TX_RING_MOD_MASK 15 /* for this to work */
141 144
145#if (((RX_RING_SIZE + TX_RING_SIZE) * 8) > PAGE_SIZE)
146#error "FEC: descriptor ring size contants too large"
147#endif
148
142/* Interrupt events/masks. 149/* Interrupt events/masks.
143*/ 150*/
144#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */ 151#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
@@ -164,7 +171,8 @@ typedef struct {
164 * size bits. Other FEC hardware does not, so we need to take that into 171 * size bits. Other FEC hardware does not, so we need to take that into
165 * account when setting it. 172 * account when setting it.
166 */ 173 */
167#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) 174#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
175 defined(CONFIG_M520x)
168#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16) 176#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
169#else 177#else
170#define OPT_FRAME_SIZE 0 178#define OPT_FRAME_SIZE 0
@@ -1137,6 +1145,65 @@ static phy_info_t const phy_info_ks8721bl = {
1137}; 1145};
1138 1146
1139/* ------------------------------------------------------------------------- */ 1147/* ------------------------------------------------------------------------- */
1148/* register definitions for the DP83848 */
1149
1150#define MII_DP8384X_PHYSTST 16 /* PHY Status Register */
1151
1152static void mii_parse_dp8384x_sr2(uint mii_reg, struct net_device *dev)
1153{
1154 struct fec_enet_private *fep = dev->priv;
1155 volatile uint *s = &(fep->phy_status);
1156
1157 *s &= ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC);
1158
1159 /* Link up */
1160 if (mii_reg & 0x0001) {
1161 fep->link = 1;
1162 *s |= PHY_STAT_LINK;
1163 } else
1164 fep->link = 0;
1165 /* Status of link */
1166 if (mii_reg & 0x0010) /* Autonegotioation complete */
1167 *s |= PHY_STAT_ANC;
1168 if (mii_reg & 0x0002) { /* 10MBps? */
1169 if (mii_reg & 0x0004) /* Full Duplex? */
1170 *s |= PHY_STAT_10FDX;
1171 else
1172 *s |= PHY_STAT_10HDX;
1173 } else { /* 100 Mbps? */
1174 if (mii_reg & 0x0004) /* Full Duplex? */
1175 *s |= PHY_STAT_100FDX;
1176 else
1177 *s |= PHY_STAT_100HDX;
1178 }
1179 if (mii_reg & 0x0008)
1180 *s |= PHY_STAT_FAULT;
1181}
1182
1183static phy_info_t phy_info_dp83848= {
1184 0x020005c9,
1185 "DP83848",
1186
1187 (const phy_cmd_t []) { /* config */
1188 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1189 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1190 { mk_mii_read(MII_DP8384X_PHYSTST), mii_parse_dp8384x_sr2 },
1191 { mk_mii_end, }
1192 },
1193 (const phy_cmd_t []) { /* startup - enable interrupts */
1194 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
1195 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1196 { mk_mii_end, }
1197 },
1198 (const phy_cmd_t []) { /* ack_int - never happens, no interrupt */
1199 { mk_mii_end, }
1200 },
1201 (const phy_cmd_t []) { /* shutdown */
1202 { mk_mii_end, }
1203 },
1204};
1205
1206/* ------------------------------------------------------------------------- */
1140 1207
1141static phy_info_t const * const phy_info[] = { 1208static phy_info_t const * const phy_info[] = {
1142 &phy_info_lxt970, 1209 &phy_info_lxt970,
@@ -1144,6 +1211,7 @@ static phy_info_t const * const phy_info[] = {
1144 &phy_info_qs6612, 1211 &phy_info_qs6612,
1145 &phy_info_am79c874, 1212 &phy_info_am79c874,
1146 &phy_info_ks8721bl, 1213 &phy_info_ks8721bl,
1214 &phy_info_dp83848,
1147 NULL 1215 NULL
1148}; 1216};
1149 1217
@@ -1422,6 +1490,134 @@ static void __inline__ fec_uncache(unsigned long addr)
1422 1490
1423/* ------------------------------------------------------------------------- */ 1491/* ------------------------------------------------------------------------- */
1424 1492
1493#elif defined(CONFIG_M520x)
1494
1495/*
1496 * Code specific to Coldfire 520x
1497 */
1498static void __inline__ fec_request_intrs(struct net_device *dev)
1499{
1500 struct fec_enet_private *fep;
1501 int b;
1502 static const struct idesc {
1503 char *name;
1504 unsigned short irq;
1505 } *idp, id[] = {
1506 { "fec(TXF)", 23 },
1507 { "fec(TXB)", 24 },
1508 { "fec(TXFIFO)", 25 },
1509 { "fec(TXCR)", 26 },
1510 { "fec(RXF)", 27 },
1511 { "fec(RXB)", 28 },
1512 { "fec(MII)", 29 },
1513 { "fec(LC)", 30 },
1514 { "fec(HBERR)", 31 },
1515 { "fec(GRA)", 32 },
1516 { "fec(EBERR)", 33 },
1517 { "fec(BABT)", 34 },
1518 { "fec(BABR)", 35 },
1519 { NULL },
1520 };
1521
1522 fep = netdev_priv(dev);
1523 b = 64 + 13;
1524
1525 /* Setup interrupt handlers. */
1526 for (idp = id; idp->name; idp++) {
1527 if (request_irq(b+idp->irq,fec_enet_interrupt,0,idp->name,dev)!=0)
1528 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, b+idp->irq);
1529 }
1530
1531 /* Unmask interrupts at ColdFire interrupt controller */
1532 {
1533 volatile unsigned char *icrp;
1534 volatile unsigned long *imrp;
1535
1536 icrp = (volatile unsigned char *) (MCF_IPSBAR + MCFICM_INTC0 +
1537 MCFINTC_ICR0);
1538 for (b = 36; (b < 49); b++)
1539 icrp[b] = 0x04;
1540 imrp = (volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 +
1541 MCFINTC_IMRH);
1542 *imrp &= ~0x0001FFF0;
1543 }
1544 *(volatile unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FEC) |= 0xf0;
1545 *(volatile unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FECI2C) |= 0x0f;
1546}
1547
1548static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
1549{
1550 volatile fec_t *fecp;
1551
1552 fecp = fep->hwp;
1553 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
1554 fecp->fec_x_cntrl = 0x00;
1555
1556 /*
1557 * Set MII speed to 2.5 MHz
1558 * See 5282 manual section 17.5.4.7: MSCR
1559 */
1560 fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
1561 fecp->fec_mii_speed = fep->phy_speed;
1562
1563 fec_restart(dev, 0);
1564}
1565
1566static void __inline__ fec_get_mac(struct net_device *dev)
1567{
1568 struct fec_enet_private *fep = netdev_priv(dev);
1569 volatile fec_t *fecp;
1570 unsigned char *iap, tmpaddr[ETH_ALEN];
1571
1572 fecp = fep->hwp;
1573
1574 if (FEC_FLASHMAC) {
1575 /*
1576 * Get MAC address from FLASH.
1577 * If it is all 1's or 0's, use the default.
1578 */
1579 iap = FEC_FLASHMAC;
1580 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1581 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1582 iap = fec_mac_default;
1583 if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
1584 (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
1585 iap = fec_mac_default;
1586 } else {
1587 *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
1588 *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
1589 iap = &tmpaddr[0];
1590 }
1591
1592 memcpy(dev->dev_addr, iap, ETH_ALEN);
1593
1594 /* Adjust MAC if using default MAC address */
1595 if (iap == fec_mac_default)
1596 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
1597}
1598
1599static void __inline__ fec_enable_phy_intr(void)
1600{
1601}
1602
1603static void __inline__ fec_disable_phy_intr(void)
1604{
1605}
1606
1607static void __inline__ fec_phy_ack_intr(void)
1608{
1609}
1610
1611static void __inline__ fec_localhw_setup(void)
1612{
1613}
1614
1615static void __inline__ fec_uncache(unsigned long addr)
1616{
1617}
1618
1619/* ------------------------------------------------------------------------- */
1620
1425#else 1621#else
1426 1622
1427/* 1623/*
@@ -1952,6 +2148,14 @@ int __init fec_enet_init(struct net_device *dev)
1952 if (index >= FEC_MAX_PORTS) 2148 if (index >= FEC_MAX_PORTS)
1953 return -ENXIO; 2149 return -ENXIO;
1954 2150
2151 /* Allocate memory for buffer descriptors.
2152 */
2153 mem_addr = __get_free_page(GFP_KERNEL);
2154 if (mem_addr == 0) {
2155 printk("FEC: allocate descriptor memory failed?\n");
2156 return -ENOMEM;
2157 }
2158
1955 /* Create an Ethernet device instance. 2159 /* Create an Ethernet device instance.
1956 */ 2160 */
1957 fecp = (volatile fec_t *) fec_hw[index]; 2161 fecp = (volatile fec_t *) fec_hw[index];
@@ -1964,16 +2168,6 @@ int __init fec_enet_init(struct net_device *dev)
1964 fecp->fec_ecntrl = 1; 2168 fecp->fec_ecntrl = 1;
1965 udelay(10); 2169 udelay(10);
1966 2170
1967 /* Clear and enable interrupts */
1968 fecp->fec_ievent = 0xffc00000;
1969 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB |
1970 FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII);
1971 fecp->fec_hash_table_high = 0;
1972 fecp->fec_hash_table_low = 0;
1973 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
1974 fecp->fec_ecntrl = 2;
1975 fecp->fec_r_des_active = 0x01000000;
1976
1977 /* Set the Ethernet address. If using multiple Enets on the 8xx, 2171 /* Set the Ethernet address. If using multiple Enets on the 8xx,
1978 * this needs some work to get unique addresses. 2172 * this needs some work to get unique addresses.
1979 * 2173 *
@@ -1982,14 +2176,6 @@ int __init fec_enet_init(struct net_device *dev)
1982 */ 2176 */
1983 fec_get_mac(dev); 2177 fec_get_mac(dev);
1984 2178
1985 /* Allocate memory for buffer descriptors.
1986 */
1987 if (((RX_RING_SIZE + TX_RING_SIZE) * sizeof(cbd_t)) > PAGE_SIZE) {
1988 printk("FEC init error. Need more space.\n");
1989 printk("FEC initialization failed.\n");
1990 return 1;
1991 }
1992 mem_addr = __get_free_page(GFP_KERNEL);
1993 cbd_base = (cbd_t *)mem_addr; 2179 cbd_base = (cbd_t *)mem_addr;
1994 /* XXX: missing check for allocation failure */ 2180 /* XXX: missing check for allocation failure */
1995 2181
@@ -2067,6 +2253,16 @@ int __init fec_enet_init(struct net_device *dev)
2067 */ 2253 */
2068 fec_request_intrs(dev); 2254 fec_request_intrs(dev);
2069 2255
2256 /* Clear and enable interrupts */
2257 fecp->fec_ievent = 0xffc00000;
2258 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB |
2259 FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII);
2260 fecp->fec_hash_table_high = 0;
2261 fecp->fec_hash_table_low = 0;
2262 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
2263 fecp->fec_ecntrl = 2;
2264 fecp->fec_r_des_active = 0x01000000;
2265
2070 dev->base_addr = (unsigned long)fecp; 2266 dev->base_addr = (unsigned long)fecp;
2071 2267
2072 /* The FEC Ethernet specific entries in the device structure. */ 2268 /* The FEC Ethernet specific entries in the device structure. */
diff --git a/drivers/net/fec.h b/drivers/net/fec.h
index 045761b8a600..965c5c49fcdc 100644
--- a/drivers/net/fec.h
+++ b/drivers/net/fec.h
@@ -1,11 +1,10 @@
1/****************************************************************************/ 1/****************************************************************************/
2 2
3/* 3/*
4 * fec.h -- Fast Ethernet Controller for Motorola ColdFire 5230, 4 * fec.h -- Fast Ethernet Controller for Motorola ColdFire SoC
5 * 5231, 5232, 5234, 5235, 5270, 5271, 5272, 5274, 5275, 5 * processors.
6 * 5280 and 5282.
7 * 6 *
8 * (C) Copyright 2000-2003, Greg Ungerer (gerg@snapgear.com) 7 * (C) Copyright 2000-2005, Greg Ungerer (gerg@snapgear.com)
9 * (C) Copyright 2000-2001, Lineo (www.lineo.com) 8 * (C) Copyright 2000-2001, Lineo (www.lineo.com)
10 */ 9 */
11 10
@@ -14,7 +13,8 @@
14#define FEC_H 13#define FEC_H
15/****************************************************************************/ 14/****************************************************************************/
16 15
17#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) 16#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
17 defined(CONFIG_M520x)
18/* 18/*
19 * Just figures, Motorola would have to change the offsets for 19 * Just figures, Motorola would have to change the offsets for
20 * registers in the same peripheral device on different models 20 * registers in the same peripheral device on different models
diff --git a/drivers/parport/probe.c b/drivers/parport/probe.c
index 6e6f42d01e64..4b48b31ec235 100644
--- a/drivers/parport/probe.c
+++ b/drivers/parport/probe.c
@@ -78,17 +78,15 @@ static void parse_data(struct parport *port, int device, char *str)
78 u++; 78 u++;
79 } 79 }
80 if (!strcmp(p, "MFG") || !strcmp(p, "MANUFACTURER")) { 80 if (!strcmp(p, "MFG") || !strcmp(p, "MANUFACTURER")) {
81 if (info->mfr) 81 kfree(info->mfr);
82 kfree (info->mfr);
83 info->mfr = kstrdup(sep, GFP_KERNEL); 82 info->mfr = kstrdup(sep, GFP_KERNEL);
84 } else if (!strcmp(p, "MDL") || !strcmp(p, "MODEL")) { 83 } else if (!strcmp(p, "MDL") || !strcmp(p, "MODEL")) {
85 if (info->model) 84 kfree(info->model);
86 kfree (info->model);
87 info->model = kstrdup(sep, GFP_KERNEL); 85 info->model = kstrdup(sep, GFP_KERNEL);
88 } else if (!strcmp(p, "CLS") || !strcmp(p, "CLASS")) { 86 } else if (!strcmp(p, "CLS") || !strcmp(p, "CLASS")) {
89 int i; 87 int i;
90 if (info->class_name) 88
91 kfree (info->class_name); 89 kfree(info->class_name);
92 info->class_name = kstrdup(sep, GFP_KERNEL); 90 info->class_name = kstrdup(sep, GFP_KERNEL);
93 for (u = sep; *u; u++) 91 for (u = sep; *u; u++)
94 *u = toupper(*u); 92 *u = toupper(*u);
@@ -102,21 +100,22 @@ static void parse_data(struct parport *port, int device, char *str)
102 info->class = PARPORT_CLASS_OTHER; 100 info->class = PARPORT_CLASS_OTHER;
103 } else if (!strcmp(p, "CMD") || 101 } else if (!strcmp(p, "CMD") ||
104 !strcmp(p, "COMMAND SET")) { 102 !strcmp(p, "COMMAND SET")) {
105 if (info->cmdset) 103 kfree(info->cmdset);
106 kfree (info->cmdset);
107 info->cmdset = kstrdup(sep, GFP_KERNEL); 104 info->cmdset = kstrdup(sep, GFP_KERNEL);
108 /* if it speaks printer language, it's 105 /* if it speaks printer language, it's
109 probably a printer */ 106 probably a printer */
110 if (strstr(sep, "PJL") || strstr(sep, "PCL")) 107 if (strstr(sep, "PJL") || strstr(sep, "PCL"))
111 guessed_class = PARPORT_CLASS_PRINTER; 108 guessed_class = PARPORT_CLASS_PRINTER;
112 } else if (!strcmp(p, "DES") || !strcmp(p, "DESCRIPTION")) { 109 } else if (!strcmp(p, "DES") || !strcmp(p, "DESCRIPTION")) {
113 if (info->description) 110 kfree(info->description);
114 kfree (info->description);
115 info->description = kstrdup(sep, GFP_KERNEL); 111 info->description = kstrdup(sep, GFP_KERNEL);
116 } 112 }
117 } 113 }
118 rock_on: 114 rock_on:
119 if (q) p = q+1; else p=NULL; 115 if (q)
116 p = q + 1;
117 else
118 p = NULL;
120 } 119 }
121 120
122 /* If the device didn't tell us its class, maybe we have managed to 121 /* If the device didn't tell us its class, maybe we have managed to
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index ae7becf7efa5..9cb3ab156b09 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -202,16 +202,11 @@ static void free_port (struct parport *port)
202 list_del(&port->full_list); 202 list_del(&port->full_list);
203 spin_unlock(&full_list_lock); 203 spin_unlock(&full_list_lock);
204 for (d = 0; d < 5; d++) { 204 for (d = 0; d < 5; d++) {
205 if (port->probe_info[d].class_name) 205 kfree(port->probe_info[d].class_name);
206 kfree (port->probe_info[d].class_name); 206 kfree(port->probe_info[d].mfr);
207 if (port->probe_info[d].mfr) 207 kfree(port->probe_info[d].model);
208 kfree (port->probe_info[d].mfr); 208 kfree(port->probe_info[d].cmdset);
209 if (port->probe_info[d].model) 209 kfree(port->probe_info[d].description);
210 kfree (port->probe_info[d].model);
211 if (port->probe_info[d].cmdset)
212 kfree (port->probe_info[d].cmdset);
213 if (port->probe_info[d].description)
214 kfree (port->probe_info[d].description);
215 } 210 }
216 211
217 kfree(port->name); 212 kfree(port->name);
@@ -618,9 +613,9 @@ parport_register_device(struct parport *port, const char *name,
618 return tmp; 613 return tmp;
619 614
620 out_free_all: 615 out_free_all:
621 kfree (tmp->state); 616 kfree(tmp->state);
622 out_free_pardevice: 617 out_free_pardevice:
623 kfree (tmp); 618 kfree(tmp);
624 out: 619 out:
625 parport_put_port (port); 620 parport_put_port (port);
626 module_put(port->ops->owner); 621 module_put(port->ops->owner);
diff --git a/drivers/pci/hotplug/cpqphp_pci.c b/drivers/pci/hotplug/cpqphp_pci.c
index 93e39c4096a9..00b81a7bdd26 100644
--- a/drivers/pci/hotplug/cpqphp_pci.c
+++ b/drivers/pci/hotplug/cpqphp_pci.c
@@ -259,8 +259,7 @@ static int PCI_GetBusDevHelper(struct controller *ctrl, u8 *bus_num, u8 *dev_num
259 sizeof(struct irq_routing_table)) / sizeof(struct irq_info); 259 sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
260 // Make sure I got at least one entry 260 // Make sure I got at least one entry
261 if (len == 0) { 261 if (len == 0) {
262 if (PCIIRQRoutingInfoLength != NULL) 262 kfree(PCIIRQRoutingInfoLength );
263 kfree(PCIIRQRoutingInfoLength );
264 return -1; 263 return -1;
265 } 264 }
266 265
@@ -275,8 +274,7 @@ static int PCI_GetBusDevHelper(struct controller *ctrl, u8 *bus_num, u8 *dev_num
275 ctrl->pci_bus->number = tbus; 274 ctrl->pci_bus->number = tbus;
276 pci_bus_read_config_dword (ctrl->pci_bus, *dev_num, PCI_VENDOR_ID, &work); 275 pci_bus_read_config_dword (ctrl->pci_bus, *dev_num, PCI_VENDOR_ID, &work);
277 if (!nobridge || (work == 0xffffffff)) { 276 if (!nobridge || (work == 0xffffffff)) {
278 if (PCIIRQRoutingInfoLength != NULL) 277 kfree(PCIIRQRoutingInfoLength );
279 kfree(PCIIRQRoutingInfoLength );
280 return 0; 278 return 0;
281 } 279 }
282 280
@@ -289,20 +287,17 @@ static int PCI_GetBusDevHelper(struct controller *ctrl, u8 *bus_num, u8 *dev_num
289 dbg("Scan bus for Non Bridge: bus %d\n", tbus); 287 dbg("Scan bus for Non Bridge: bus %d\n", tbus);
290 if (PCI_ScanBusForNonBridge(ctrl, tbus, dev_num) == 0) { 288 if (PCI_ScanBusForNonBridge(ctrl, tbus, dev_num) == 0) {
291 *bus_num = tbus; 289 *bus_num = tbus;
292 if (PCIIRQRoutingInfoLength != NULL) 290 kfree(PCIIRQRoutingInfoLength );
293 kfree(PCIIRQRoutingInfoLength );
294 return 0; 291 return 0;
295 } 292 }
296 } else { 293 } else {
297 if (PCIIRQRoutingInfoLength != NULL) 294 kfree(PCIIRQRoutingInfoLength );
298 kfree(PCIIRQRoutingInfoLength );
299 return 0; 295 return 0;
300 } 296 }
301 297
302 } 298 }
303 } 299 }
304 if (PCIIRQRoutingInfoLength != NULL) 300 kfree(PCIIRQRoutingInfoLength );
305 kfree(PCIIRQRoutingInfoLength );
306 return -1; 301 return -1;
307} 302}
308 303
diff --git a/drivers/pci/hotplug/pciehprm_nonacpi.c b/drivers/pci/hotplug/pciehprm_nonacpi.c
index 33b2c69a0829..76c727c74cc0 100644
--- a/drivers/pci/hotplug/pciehprm_nonacpi.c
+++ b/drivers/pci/hotplug/pciehprm_nonacpi.c
@@ -31,6 +31,7 @@
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/sched.h>
34#include <linux/pci.h> 35#include <linux/pci.h>
35#include <linux/init.h> 36#include <linux/init.h>
36#include <linux/slab.h> 37#include <linux/slab.h>
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index ae986e590b48..94e68c54d273 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -10,6 +10,7 @@
10#include <linux/mempolicy.h> 10#include <linux/mempolicy.h>
11#include <linux/string.h> 11#include <linux/string.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/sched.h>
13#include "pci.h" 14#include "pci.h"
14 15
15/* 16/*
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index 3afb682255a0..2dc3e611a9a3 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -334,10 +334,8 @@ void destroy_cis_cache(struct pcmcia_socket *s)
334 /* 334 /*
335 * If there was a fake CIS, destroy that as well. 335 * If there was a fake CIS, destroy that as well.
336 */ 336 */
337 if (s->fake_cis) { 337 kfree(s->fake_cis);
338 kfree(s->fake_cis); 338 s->fake_cis = NULL;
339 s->fake_cis = NULL;
340 }
341} 339}
342EXPORT_SYMBOL(destroy_cis_cache); 340EXPORT_SYMBOL(destroy_cis_cache);
343 341
@@ -386,10 +384,8 @@ int verify_cis_cache(struct pcmcia_socket *s)
386 384
387int pcmcia_replace_cis(struct pcmcia_socket *s, cisdump_t *cis) 385int pcmcia_replace_cis(struct pcmcia_socket *s, cisdump_t *cis)
388{ 386{
389 if (s->fake_cis != NULL) { 387 kfree(s->fake_cis);
390 kfree(s->fake_cis); 388 s->fake_cis = NULL;
391 s->fake_cis = NULL;
392 }
393 if (cis->Length > CISTPL_MAX_CIS_SIZE) 389 if (cis->Length > CISTPL_MAX_CIS_SIZE)
394 return CS_BAD_SIZE; 390 return CS_BAD_SIZE;
395 s->fake_cis = kmalloc(cis->Length, GFP_KERNEL); 391 s->fake_cis = kmalloc(cis->Length, GFP_KERNEL);
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index d5e76423a0ee..234cdca6fe13 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -331,10 +331,8 @@ static void shutdown_socket(struct pcmcia_socket *s)
331 cb_free(s); 331 cb_free(s);
332#endif 332#endif
333 s->functions = 0; 333 s->functions = 0;
334 if (s->config) { 334 kfree(s->config);
335 kfree(s->config); 335 s->config = NULL;
336 s->config = NULL;
337 }
338 336
339 { 337 {
340 int status; 338 int status;
diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c
index e95ed67d4f05..bd7c966ea2d7 100644
--- a/drivers/pnp/card.c
+++ b/drivers/pnp/card.c
@@ -12,7 +12,7 @@
12#include "base.h" 12#include "base.h"
13 13
14LIST_HEAD(pnp_cards); 14LIST_HEAD(pnp_cards);
15LIST_HEAD(pnp_card_drivers); 15static LIST_HEAD(pnp_card_drivers);
16 16
17 17
18static const struct pnp_card_device_id * match_card(struct pnp_card_driver * drv, struct pnp_card * card) 18static const struct pnp_card_device_id * match_card(struct pnp_card_driver * drv, struct pnp_card * card)
@@ -374,11 +374,13 @@ void pnp_unregister_card_driver(struct pnp_card_driver * drv)
374 pnp_unregister_driver(&drv->link); 374 pnp_unregister_driver(&drv->link);
375} 375}
376 376
377#if 0
377EXPORT_SYMBOL(pnp_add_card); 378EXPORT_SYMBOL(pnp_add_card);
378EXPORT_SYMBOL(pnp_remove_card); 379EXPORT_SYMBOL(pnp_remove_card);
379EXPORT_SYMBOL(pnp_add_card_device); 380EXPORT_SYMBOL(pnp_add_card_device);
380EXPORT_SYMBOL(pnp_remove_card_device); 381EXPORT_SYMBOL(pnp_remove_card_device);
381EXPORT_SYMBOL(pnp_add_card_id); 382EXPORT_SYMBOL(pnp_add_card_id);
383#endif /* 0 */
382EXPORT_SYMBOL(pnp_request_card_device); 384EXPORT_SYMBOL(pnp_request_card_device);
383EXPORT_SYMBOL(pnp_release_card_device); 385EXPORT_SYMBOL(pnp_release_card_device);
384EXPORT_SYMBOL(pnp_register_card_driver); 386EXPORT_SYMBOL(pnp_register_card_driver);
diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
index deed92459bc5..aec83ec5ea23 100644
--- a/drivers/pnp/core.c
+++ b/drivers/pnp/core.c
@@ -158,13 +158,14 @@ void __pnp_remove_device(struct pnp_dev *dev)
158 * 158 *
159 * this function will free all mem used by dev 159 * this function will free all mem used by dev
160 */ 160 */
161 161#if 0
162void pnp_remove_device(struct pnp_dev *dev) 162void pnp_remove_device(struct pnp_dev *dev)
163{ 163{
164 if (!dev || dev->card) 164 if (!dev || dev->card)
165 return; 165 return;
166 __pnp_remove_device(dev); 166 __pnp_remove_device(dev);
167} 167}
168#endif /* 0 */
168 169
169static int __init pnp_init(void) 170static int __init pnp_init(void)
170{ 171{
@@ -174,7 +175,9 @@ static int __init pnp_init(void)
174 175
175subsys_initcall(pnp_init); 176subsys_initcall(pnp_init);
176 177
178#if 0
177EXPORT_SYMBOL(pnp_register_protocol); 179EXPORT_SYMBOL(pnp_register_protocol);
178EXPORT_SYMBOL(pnp_unregister_protocol); 180EXPORT_SYMBOL(pnp_unregister_protocol);
179EXPORT_SYMBOL(pnp_add_device); 181EXPORT_SYMBOL(pnp_add_device);
180EXPORT_SYMBOL(pnp_remove_device); 182EXPORT_SYMBOL(pnp_remove_device);
183#endif /* 0 */
diff --git a/drivers/pnp/driver.c b/drivers/pnp/driver.c
index 33da25f3213f..d3ccce706ab4 100644
--- a/drivers/pnp/driver.c
+++ b/drivers/pnp/driver.c
@@ -214,6 +214,8 @@ int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev)
214 214
215EXPORT_SYMBOL(pnp_register_driver); 215EXPORT_SYMBOL(pnp_register_driver);
216EXPORT_SYMBOL(pnp_unregister_driver); 216EXPORT_SYMBOL(pnp_unregister_driver);
217#if 0
217EXPORT_SYMBOL(pnp_add_id); 218EXPORT_SYMBOL(pnp_add_id);
219#endif
218EXPORT_SYMBOL(pnp_device_attach); 220EXPORT_SYMBOL(pnp_device_attach);
219EXPORT_SYMBOL(pnp_device_detach); 221EXPORT_SYMBOL(pnp_device_detach);
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
index beedd86800f4..57fd60314d59 100644
--- a/drivers/pnp/isapnp/core.c
+++ b/drivers/pnp/isapnp/core.c
@@ -941,7 +941,9 @@ EXPORT_SYMBOL(isapnp_protocol);
941EXPORT_SYMBOL(isapnp_present); 941EXPORT_SYMBOL(isapnp_present);
942EXPORT_SYMBOL(isapnp_cfg_begin); 942EXPORT_SYMBOL(isapnp_cfg_begin);
943EXPORT_SYMBOL(isapnp_cfg_end); 943EXPORT_SYMBOL(isapnp_cfg_end);
944#if 0
944EXPORT_SYMBOL(isapnp_read_byte); 945EXPORT_SYMBOL(isapnp_read_byte);
946#endif
945EXPORT_SYMBOL(isapnp_write_byte); 947EXPORT_SYMBOL(isapnp_write_byte);
946 948
947static int isapnp_read_resources(struct pnp_dev *dev, struct pnp_resource_table *res) 949static int isapnp_read_resources(struct pnp_dev *dev, struct pnp_resource_table *res)
diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c
index cbb2749db178..261668618b2d 100644
--- a/drivers/pnp/manager.c
+++ b/drivers/pnp/manager.c
@@ -555,7 +555,9 @@ void pnp_resource_change(struct resource *resource, unsigned long start, unsigne
555 555
556 556
557EXPORT_SYMBOL(pnp_manual_config_dev); 557EXPORT_SYMBOL(pnp_manual_config_dev);
558#if 0
558EXPORT_SYMBOL(pnp_auto_config_dev); 559EXPORT_SYMBOL(pnp_auto_config_dev);
560#endif
559EXPORT_SYMBOL(pnp_activate_dev); 561EXPORT_SYMBOL(pnp_activate_dev);
560EXPORT_SYMBOL(pnp_disable_dev); 562EXPORT_SYMBOL(pnp_disable_dev);
561EXPORT_SYMBOL(pnp_resource_change); 563EXPORT_SYMBOL(pnp_resource_change);
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index 1a8915e74160..816479ad217b 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -117,7 +117,7 @@ static int pnpacpi_disable_resources(struct pnp_dev *dev)
117 return ACPI_FAILURE(status) ? -ENODEV : 0; 117 return ACPI_FAILURE(status) ? -ENODEV : 0;
118} 118}
119 119
120struct pnp_protocol pnpacpi_protocol = { 120static struct pnp_protocol pnpacpi_protocol = {
121 .name = "Plug and Play ACPI", 121 .name = "Plug and Play ACPI",
122 .get = pnpacpi_get_resources, 122 .get = pnpacpi_get_resources,
123 .set = pnpacpi_set_resources, 123 .set = pnpacpi_set_resources,
@@ -234,7 +234,7 @@ static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
234} 234}
235 235
236int pnpacpi_disabled __initdata; 236int pnpacpi_disabled __initdata;
237int __init pnpacpi_init(void) 237static int __init pnpacpi_init(void)
238{ 238{
239 if (acpi_disabled || pnpacpi_disabled) { 239 if (acpi_disabled || pnpacpi_disabled) {
240 pnp_info("PnP ACPI: disabled"); 240 pnp_info("PnP ACPI: disabled");
@@ -258,4 +258,6 @@ static int __init pnpacpi_setup(char *str)
258} 258}
259__setup("pnpacpi=", pnpacpi_setup); 259__setup("pnpacpi=", pnpacpi_setup);
260 260
261#if 0
261EXPORT_SYMBOL(pnpacpi_protocol); 262EXPORT_SYMBOL(pnpacpi_protocol);
263#endif
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index 887ad8939349..6ded527169f4 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -477,12 +477,14 @@ int pnp_check_dma(struct pnp_dev * dev, int idx)
477} 477}
478 478
479 479
480#if 0
480EXPORT_SYMBOL(pnp_register_dependent_option); 481EXPORT_SYMBOL(pnp_register_dependent_option);
481EXPORT_SYMBOL(pnp_register_independent_option); 482EXPORT_SYMBOL(pnp_register_independent_option);
482EXPORT_SYMBOL(pnp_register_irq_resource); 483EXPORT_SYMBOL(pnp_register_irq_resource);
483EXPORT_SYMBOL(pnp_register_dma_resource); 484EXPORT_SYMBOL(pnp_register_dma_resource);
484EXPORT_SYMBOL(pnp_register_port_resource); 485EXPORT_SYMBOL(pnp_register_port_resource);
485EXPORT_SYMBOL(pnp_register_mem_resource); 486EXPORT_SYMBOL(pnp_register_mem_resource);
487#endif /* 0 */
486 488
487 489
488/* format is: pnp_reserve_irq=irq1[,irq2] .... */ 490/* format is: pnp_reserve_irq=irq1[,irq2] .... */
diff --git a/drivers/rapidio/Kconfig b/drivers/rapidio/Kconfig
new file mode 100644
index 000000000000..0b2d2c3579a7
--- /dev/null
+++ b/drivers/rapidio/Kconfig
@@ -0,0 +1,18 @@
1#
2# RapidIO configuration
3#
4config RAPIDIO_8_BIT_TRANSPORT
5 bool "8-bit transport addressing"
6 depends on RAPIDIO
7 ---help---
8 By default, the kernel assumes a 16-bit addressed RapidIO
9 network. By selecting this option, the kernel will support
10 an 8-bit addressed network.
11
12config RAPIDIO_DISC_TIMEOUT
13 int "Discovery timeout duration (seconds)"
14 depends on RAPIDIO
15 default "30"
16 ---help---
17 Amount of time a discovery node waits for a host to complete
18 enumeration beforing giving up.
diff --git a/drivers/rapidio/Makefile b/drivers/rapidio/Makefile
new file mode 100644
index 000000000000..7c0e1818de51
--- /dev/null
+++ b/drivers/rapidio/Makefile
@@ -0,0 +1,6 @@
1#
2# Makefile for RapidIO interconnect services
3#
4obj-y += rio.o rio-access.o rio-driver.o rio-scan.o rio-sysfs.o
5
6obj-$(CONFIG_RAPIDIO) += switches/
diff --git a/drivers/rapidio/rio-access.c b/drivers/rapidio/rio-access.c
new file mode 100644
index 000000000000..b9fab2ae3a36
--- /dev/null
+++ b/drivers/rapidio/rio-access.c
@@ -0,0 +1,175 @@
1/*
2 * RapidIO configuration space access support
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/rio.h>
14#include <linux/module.h>
15
16/*
17 * These interrupt-safe spinlocks protect all accesses to RIO
18 * configuration space and doorbell access.
19 */
20static spinlock_t rio_config_lock = SPIN_LOCK_UNLOCKED;
21static spinlock_t rio_doorbell_lock = SPIN_LOCK_UNLOCKED;
22
23/*
24 * Wrappers for all RIO configuration access functions. They just check
25 * alignment, do locking and call the low-level functions pointed to
26 * by rio_mport->ops.
27 */
28
29#define RIO_8_BAD 0
30#define RIO_16_BAD (offset & 1)
31#define RIO_32_BAD (offset & 3)
32
33/**
34 * RIO_LOP_READ - Generate rio_local_read_config_* functions
35 * @size: Size of configuration space read (8, 16, 32 bits)
36 * @type: C type of value argument
37 * @len: Length of configuration space read (1, 2, 4 bytes)
38 *
39 * Generates rio_local_read_config_* functions used to access
40 * configuration space registers on the local device.
41 */
42#define RIO_LOP_READ(size,type,len) \
43int __rio_local_read_config_##size \
44 (struct rio_mport *mport, u32 offset, type *value) \
45{ \
46 int res; \
47 unsigned long flags; \
48 u32 data = 0; \
49 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
50 spin_lock_irqsave(&rio_config_lock, flags); \
51 res = mport->ops->lcread(mport->id, offset, len, &data); \
52 *value = (type)data; \
53 spin_unlock_irqrestore(&rio_config_lock, flags); \
54 return res; \
55}
56
57/**
58 * RIO_LOP_WRITE - Generate rio_local_write_config_* functions
59 * @size: Size of configuration space write (8, 16, 32 bits)
60 * @type: C type of value argument
61 * @len: Length of configuration space write (1, 2, 4 bytes)
62 *
63 * Generates rio_local_write_config_* functions used to access
64 * configuration space registers on the local device.
65 */
66#define RIO_LOP_WRITE(size,type,len) \
67int __rio_local_write_config_##size \
68 (struct rio_mport *mport, u32 offset, type value) \
69{ \
70 int res; \
71 unsigned long flags; \
72 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
73 spin_lock_irqsave(&rio_config_lock, flags); \
74 res = mport->ops->lcwrite(mport->id, offset, len, value); \
75 spin_unlock_irqrestore(&rio_config_lock, flags); \
76 return res; \
77}
78
79RIO_LOP_READ(8, u8, 1)
80RIO_LOP_READ(16, u16, 2)
81RIO_LOP_READ(32, u32, 4)
82RIO_LOP_WRITE(8, u8, 1)
83RIO_LOP_WRITE(16, u16, 2)
84RIO_LOP_WRITE(32, u32, 4)
85
86EXPORT_SYMBOL_GPL(__rio_local_read_config_8);
87EXPORT_SYMBOL_GPL(__rio_local_read_config_16);
88EXPORT_SYMBOL_GPL(__rio_local_read_config_32);
89EXPORT_SYMBOL_GPL(__rio_local_write_config_8);
90EXPORT_SYMBOL_GPL(__rio_local_write_config_16);
91EXPORT_SYMBOL_GPL(__rio_local_write_config_32);
92
93/**
94 * RIO_OP_READ - Generate rio_mport_read_config_* functions
95 * @size: Size of configuration space read (8, 16, 32 bits)
96 * @type: C type of value argument
97 * @len: Length of configuration space read (1, 2, 4 bytes)
98 *
99 * Generates rio_mport_read_config_* functions used to access
100 * configuration space registers on the local device.
101 */
102#define RIO_OP_READ(size,type,len) \
103int rio_mport_read_config_##size \
104 (struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type *value) \
105{ \
106 int res; \
107 unsigned long flags; \
108 u32 data = 0; \
109 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
110 spin_lock_irqsave(&rio_config_lock, flags); \
111 res = mport->ops->cread(mport->id, destid, hopcount, offset, len, &data); \
112 *value = (type)data; \
113 spin_unlock_irqrestore(&rio_config_lock, flags); \
114 return res; \
115}
116
117/**
118 * RIO_OP_WRITE - Generate rio_mport_write_config_* functions
119 * @size: Size of configuration space write (8, 16, 32 bits)
120 * @type: C type of value argument
121 * @len: Length of configuration space write (1, 2, 4 bytes)
122 *
123 * Generates rio_mport_write_config_* functions used to access
124 * configuration space registers on the local device.
125 */
126#define RIO_OP_WRITE(size,type,len) \
127int rio_mport_write_config_##size \
128 (struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type value) \
129{ \
130 int res; \
131 unsigned long flags; \
132 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
133 spin_lock_irqsave(&rio_config_lock, flags); \
134 res = mport->ops->cwrite(mport->id, destid, hopcount, offset, len, value); \
135 spin_unlock_irqrestore(&rio_config_lock, flags); \
136 return res; \
137}
138
139RIO_OP_READ(8, u8, 1)
140RIO_OP_READ(16, u16, 2)
141RIO_OP_READ(32, u32, 4)
142RIO_OP_WRITE(8, u8, 1)
143RIO_OP_WRITE(16, u16, 2)
144RIO_OP_WRITE(32, u32, 4)
145
146EXPORT_SYMBOL_GPL(rio_mport_read_config_8);
147EXPORT_SYMBOL_GPL(rio_mport_read_config_16);
148EXPORT_SYMBOL_GPL(rio_mport_read_config_32);
149EXPORT_SYMBOL_GPL(rio_mport_write_config_8);
150EXPORT_SYMBOL_GPL(rio_mport_write_config_16);
151EXPORT_SYMBOL_GPL(rio_mport_write_config_32);
152
153/**
154 * rio_mport_send_doorbell - Send a doorbell message
155 *
156 * @mport: RIO master port
157 * @destid: RIO device destination ID
158 * @data: Doorbell message data
159 *
160 * Send a doorbell message to a RIO device. The doorbell message
161 * has a 16-bit info field provided by the data argument.
162 */
163int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid, u16 data)
164{
165 int res;
166 unsigned long flags;
167
168 spin_lock_irqsave(&rio_doorbell_lock, flags);
169 res = mport->ops->dsend(mport->id, destid, data);
170 spin_unlock_irqrestore(&rio_doorbell_lock, flags);
171
172 return res;
173}
174
175EXPORT_SYMBOL_GPL(rio_mport_send_doorbell);
diff --git a/drivers/rapidio/rio-driver.c b/drivers/rapidio/rio-driver.c
new file mode 100644
index 000000000000..dc749609699a
--- /dev/null
+++ b/drivers/rapidio/rio-driver.c
@@ -0,0 +1,229 @@
1/*
2 * RapidIO driver support
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/rio.h>
16#include <linux/rio_ids.h>
17
18#include "rio.h"
19
20/**
21 * rio_match_device - Tell if a RIO device has a matching RIO device id structure
22 * @id: the RIO device id structure to match against
23 * @rdev: the RIO device structure to match against
24 *
25 * Used from driver probe and bus matching to check whether a RIO device
26 * matches a device id structure provided by a RIO driver. Returns the
27 * matching &struct rio_device_id or %NULL if there is no match.
28 */
29static const struct rio_device_id *rio_match_device(const struct rio_device_id
30 *id,
31 const struct rio_dev *rdev)
32{
33 while (id->vid || id->asm_vid) {
34 if (((id->vid == RIO_ANY_ID) || (id->vid == rdev->vid)) &&
35 ((id->did == RIO_ANY_ID) || (id->did == rdev->did)) &&
36 ((id->asm_vid == RIO_ANY_ID)
37 || (id->asm_vid == rdev->asm_vid))
38 && ((id->asm_did == RIO_ANY_ID)
39 || (id->asm_did == rdev->asm_did)))
40 return id;
41 id++;
42 }
43 return NULL;
44}
45
46/**
47 * rio_dev_get - Increments the reference count of the RIO device structure
48 *
49 * @rdev: RIO device being referenced
50 *
51 * Each live reference to a device should be refcounted.
52 *
53 * Drivers for RIO devices should normally record such references in
54 * their probe() methods, when they bind to a device, and release
55 * them by calling rio_dev_put(), in their disconnect() methods.
56 */
57struct rio_dev *rio_dev_get(struct rio_dev *rdev)
58{
59 if (rdev)
60 get_device(&rdev->dev);
61
62 return rdev;
63}
64
65/**
66 * rio_dev_put - Release a use of the RIO device structure
67 *
68 * @rdev: RIO device being disconnected
69 *
70 * Must be called when a user of a device is finished with it.
71 * When the last user of the device calls this function, the
72 * memory of the device is freed.
73 */
74void rio_dev_put(struct rio_dev *rdev)
75{
76 if (rdev)
77 put_device(&rdev->dev);
78}
79
80/**
81 * rio_device_probe - Tell if a RIO device structure has a matching RIO
82 * device id structure
83 * @id: the RIO device id structure to match against
84 * @dev: the RIO device structure to match against
85 *
86 * return 0 and set rio_dev->driver when drv claims rio_dev, else error
87 */
88static int rio_device_probe(struct device *dev)
89{
90 struct rio_driver *rdrv = to_rio_driver(dev->driver);
91 struct rio_dev *rdev = to_rio_dev(dev);
92 int error = -ENODEV;
93 const struct rio_device_id *id;
94
95 if (!rdev->driver && rdrv->probe) {
96 if (!rdrv->id_table)
97 return error;
98 id = rio_match_device(rdrv->id_table, rdev);
99 rio_dev_get(rdev);
100 if (id)
101 error = rdrv->probe(rdev, id);
102 if (error >= 0) {
103 rdev->driver = rdrv;
104 error = 0;
105 rio_dev_put(rdev);
106 }
107 }
108 return error;
109}
110
111/**
112 * rio_device_remove - Remove a RIO device from the system
113 *
114 * @dev: the RIO device structure to match against
115 *
116 * Remove a RIO device from the system. If it has an associated
117 * driver, then run the driver remove() method. Then update
118 * the reference count.
119 */
120static int rio_device_remove(struct device *dev)
121{
122 struct rio_dev *rdev = to_rio_dev(dev);
123 struct rio_driver *rdrv = rdev->driver;
124
125 if (rdrv) {
126 if (rdrv->remove)
127 rdrv->remove(rdev);
128 rdev->driver = NULL;
129 }
130
131 rio_dev_put(rdev);
132
133 return 0;
134}
135
136/**
137 * rio_register_driver - register a new RIO driver
138 * @rdrv: the RIO driver structure to register
139 *
140 * Adds a &struct rio_driver to the list of registered drivers
141 * Returns a negative value on error, otherwise 0. If no error
142 * occurred, the driver remains registered even if no device
143 * was claimed during registration.
144 */
145int rio_register_driver(struct rio_driver *rdrv)
146{
147 /* initialize common driver fields */
148 rdrv->driver.name = rdrv->name;
149 rdrv->driver.bus = &rio_bus_type;
150 rdrv->driver.probe = rio_device_probe;
151 rdrv->driver.remove = rio_device_remove;
152
153 /* register with core */
154 return driver_register(&rdrv->driver);
155}
156
157/**
158 * rio_unregister_driver - unregister a RIO driver
159 * @rdrv: the RIO driver structure to unregister
160 *
161 * Deletes the &struct rio_driver from the list of registered RIO
162 * drivers, gives it a chance to clean up by calling its remove()
163 * function for each device it was responsible for, and marks those
164 * devices as driverless.
165 */
166void rio_unregister_driver(struct rio_driver *rdrv)
167{
168 driver_unregister(&rdrv->driver);
169}
170
171/**
172 * rio_match_bus - Tell if a RIO device structure has a matching RIO
173 * driver device id structure
174 * @dev: the standard device structure to match against
175 * @drv: the standard driver structure containing the ids to match against
176 *
177 * Used by a driver to check whether a RIO device present in the
178 * system is in its list of supported devices. Returns 1 if
179 * there is a matching &struct rio_device_id or 0 if there is
180 * no match.
181 */
182static int rio_match_bus(struct device *dev, struct device_driver *drv)
183{
184 struct rio_dev *rdev = to_rio_dev(dev);
185 struct rio_driver *rdrv = to_rio_driver(drv);
186 const struct rio_device_id *id = rdrv->id_table;
187 const struct rio_device_id *found_id;
188
189 if (!id)
190 goto out;
191
192 found_id = rio_match_device(id, rdev);
193
194 if (found_id)
195 return 1;
196
197 out:return 0;
198}
199
200static struct device rio_bus = {
201 .bus_id = "rapidio",
202};
203
204struct bus_type rio_bus_type = {
205 .name = "rapidio",
206 .match = rio_match_bus,
207 .dev_attrs = rio_dev_attrs
208};
209
210/**
211 * rio_bus_init - Register the RapidIO bus with the device model
212 *
213 * Registers the RIO bus device and RIO bus type with the Linux
214 * device model.
215 */
216static int __init rio_bus_init(void)
217{
218 if (device_register(&rio_bus) < 0)
219 printk("RIO: failed to register RIO bus device\n");
220 return bus_register(&rio_bus_type);
221}
222
223postcore_initcall(rio_bus_init);
224
225EXPORT_SYMBOL_GPL(rio_register_driver);
226EXPORT_SYMBOL_GPL(rio_unregister_driver);
227EXPORT_SYMBOL_GPL(rio_bus_type);
228EXPORT_SYMBOL_GPL(rio_dev_get);
229EXPORT_SYMBOL_GPL(rio_dev_put);
diff --git a/drivers/rapidio/rio-scan.c b/drivers/rapidio/rio-scan.c
new file mode 100644
index 000000000000..4f7ed4bd3be9
--- /dev/null
+++ b/drivers/rapidio/rio-scan.c
@@ -0,0 +1,945 @@
1/*
2 * RapidIO enumeration and discovery support
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/config.h>
14#include <linux/types.h>
15#include <linux/kernel.h>
16
17#include <linux/delay.h>
18#include <linux/dma-mapping.h>
19#include <linux/init.h>
20#include <linux/rio.h>
21#include <linux/rio_drv.h>
22#include <linux/rio_ids.h>
23#include <linux/rio_regs.h>
24#include <linux/module.h>
25#include <linux/spinlock.h>
26#include <linux/timer.h>
27
28#include "rio.h"
29
30LIST_HEAD(rio_devices);
31static LIST_HEAD(rio_switches);
32
33#define RIO_ENUM_CMPL_MAGIC 0xdeadbeef
34
35static void rio_enum_timeout(unsigned long);
36
37DEFINE_SPINLOCK(rio_global_list_lock);
38
39static int next_destid = 0;
40static int next_switchid = 0;
41static int next_net = 0;
42
43static struct timer_list rio_enum_timer =
44TIMER_INITIALIZER(rio_enum_timeout, 0, 0);
45
46static int rio_mport_phys_table[] = {
47 RIO_EFB_PAR_EP_ID,
48 RIO_EFB_PAR_EP_REC_ID,
49 RIO_EFB_SER_EP_ID,
50 RIO_EFB_SER_EP_REC_ID,
51 -1,
52};
53
54static int rio_sport_phys_table[] = {
55 RIO_EFB_PAR_EP_FREE_ID,
56 RIO_EFB_SER_EP_FREE_ID,
57 -1,
58};
59
60/**
61 * rio_get_device_id - Get the base/extended device id for a device
62 * @port: RIO master port
63 * @destid: Destination ID of device
64 * @hopcount: Hopcount to device
65 *
66 * Reads the base/extended device id from a device. Returns the
67 * 8/16-bit device ID.
68 */
69static u16 rio_get_device_id(struct rio_mport *port, u16 destid, u8 hopcount)
70{
71 u32 result;
72
73 rio_mport_read_config_32(port, destid, hopcount, RIO_DID_CSR, &result);
74
75 return RIO_GET_DID(result);
76}
77
78/**
79 * rio_set_device_id - Set the base/extended device id for a device
80 * @port: RIO master port
81 * @destid: Destination ID of device
82 * @hopcount: Hopcount to device
83 * @did: Device ID value to be written
84 *
85 * Writes the base/extended device id from a device.
86 */
87static void rio_set_device_id(struct rio_mport *port, u16 destid, u8 hopcount, u16 did)
88{
89 rio_mport_write_config_32(port, destid, hopcount, RIO_DID_CSR,
90 RIO_SET_DID(did));
91}
92
93/**
94 * rio_local_set_device_id - Set the base/extended device id for a port
95 * @port: RIO master port
96 * @did: Device ID value to be written
97 *
98 * Writes the base/extended device id from a device.
99 */
100static void rio_local_set_device_id(struct rio_mport *port, u16 did)
101{
102 rio_local_write_config_32(port, RIO_DID_CSR, RIO_SET_DID(did));
103}
104
105/**
106 * rio_clear_locks- Release all host locks and signal enumeration complete
107 * @port: Master port to issue transaction
108 *
109 * Marks the component tag CSR on each device with the enumeration
110 * complete flag. When complete, it then release the host locks on
111 * each device. Returns 0 on success or %-EINVAL on failure.
112 */
113static int rio_clear_locks(struct rio_mport *port)
114{
115 struct rio_dev *rdev;
116 u32 result;
117 int ret = 0;
118
119 /* Write component tag CSR magic complete value */
120 rio_local_write_config_32(port, RIO_COMPONENT_TAG_CSR,
121 RIO_ENUM_CMPL_MAGIC);
122 list_for_each_entry(rdev, &rio_devices, global_list)
123 rio_write_config_32(rdev, RIO_COMPONENT_TAG_CSR,
124 RIO_ENUM_CMPL_MAGIC);
125
126 /* Release host device id locks */
127 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR,
128 port->host_deviceid);
129 rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result);
130 if ((result & 0xffff) != 0xffff) {
131 printk(KERN_INFO
132 "RIO: badness when releasing host lock on master port, result %8.8x\n",
133 result);
134 ret = -EINVAL;
135 }
136 list_for_each_entry(rdev, &rio_devices, global_list) {
137 rio_write_config_32(rdev, RIO_HOST_DID_LOCK_CSR,
138 port->host_deviceid);
139 rio_read_config_32(rdev, RIO_HOST_DID_LOCK_CSR, &result);
140 if ((result & 0xffff) != 0xffff) {
141 printk(KERN_INFO
142 "RIO: badness when releasing host lock on vid %4.4x did %4.4x\n",
143 rdev->vid, rdev->did);
144 ret = -EINVAL;
145 }
146 }
147
148 return ret;
149}
150
151/**
152 * rio_enum_host- Set host lock and initialize host destination ID
153 * @port: Master port to issue transaction
154 *
155 * Sets the local host master port lock and destination ID register
156 * with the host device ID value. The host device ID value is provided
157 * by the platform. Returns %0 on success or %-1 on failure.
158 */
159static int rio_enum_host(struct rio_mport *port)
160{
161 u32 result;
162
163 /* Set master port host device id lock */
164 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR,
165 port->host_deviceid);
166
167 rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result);
168 if ((result & 0xffff) != port->host_deviceid)
169 return -1;
170
171 /* Set master port destid and init destid ctr */
172 rio_local_set_device_id(port, port->host_deviceid);
173
174 if (next_destid == port->host_deviceid)
175 next_destid++;
176
177 return 0;
178}
179
180/**
181 * rio_device_has_destid- Test if a device contains a destination ID register
182 * @port: Master port to issue transaction
183 * @src_ops: RIO device source operations
184 * @dst_ops: RIO device destination operations
185 *
186 * Checks the provided @src_ops and @dst_ops for the necessary transaction
187 * capabilities that indicate whether or not a device will implement a
188 * destination ID register. Returns 1 if true or 0 if false.
189 */
190static int rio_device_has_destid(struct rio_mport *port, int src_ops,
191 int dst_ops)
192{
193 u32 mask = RIO_OPS_READ | RIO_OPS_WRITE | RIO_OPS_ATOMIC_TST_SWP | RIO_OPS_ATOMIC_INC | RIO_OPS_ATOMIC_DEC | RIO_OPS_ATOMIC_SET | RIO_OPS_ATOMIC_CLR;
194
195 return !!((src_ops | dst_ops) & mask);
196}
197
198/**
199 * rio_release_dev- Frees a RIO device struct
200 * @dev: LDM device associated with a RIO device struct
201 *
202 * Gets the RIO device struct associated a RIO device struct.
203 * The RIO device struct is freed.
204 */
205static void rio_release_dev(struct device *dev)
206{
207 struct rio_dev *rdev;
208
209 rdev = to_rio_dev(dev);
210 kfree(rdev);
211}
212
213/**
214 * rio_is_switch- Tests if a RIO device has switch capabilities
215 * @rdev: RIO device
216 *
217 * Gets the RIO device Processing Element Features register
218 * contents and tests for switch capabilities. Returns 1 if
219 * the device is a switch or 0 if it is not a switch.
220 * The RIO device struct is freed.
221 */
222static int rio_is_switch(struct rio_dev *rdev)
223{
224 if (rdev->pef & RIO_PEF_SWITCH)
225 return 1;
226 return 0;
227}
228
229/**
230 * rio_route_set_ops- Sets routing operations for a particular vendor switch
231 * @rdev: RIO device
232 *
233 * Searches the RIO route ops table for known switch types. If the vid
234 * and did match a switch table entry, then set the add_entry() and
235 * get_entry() ops to the table entry values.
236 */
237static void rio_route_set_ops(struct rio_dev *rdev)
238{
239 struct rio_route_ops *cur = __start_rio_route_ops;
240 struct rio_route_ops *end = __end_rio_route_ops;
241
242 while (cur < end) {
243 if ((cur->vid == rdev->vid) && (cur->did == rdev->did)) {
244 pr_debug("RIO: adding routing ops for %s\n", rio_name(rdev));
245 rdev->rswitch->add_entry = cur->add_hook;
246 rdev->rswitch->get_entry = cur->get_hook;
247 }
248 cur++;
249 }
250
251 if (!rdev->rswitch->add_entry || !rdev->rswitch->get_entry)
252 printk(KERN_ERR "RIO: missing routing ops for %s\n",
253 rio_name(rdev));
254}
255
256/**
257 * rio_add_device- Adds a RIO device to the device model
258 * @rdev: RIO device
259 *
260 * Adds the RIO device to the global device list and adds the RIO
261 * device to the RIO device list. Creates the generic sysfs nodes
262 * for an RIO device.
263 */
264static void __devinit rio_add_device(struct rio_dev *rdev)
265{
266 device_add(&rdev->dev);
267
268 spin_lock(&rio_global_list_lock);
269 list_add_tail(&rdev->global_list, &rio_devices);
270 spin_unlock(&rio_global_list_lock);
271
272 rio_create_sysfs_dev_files(rdev);
273}
274
275/**
276 * rio_setup_device- Allocates and sets up a RIO device
277 * @net: RIO network
278 * @port: Master port to send transactions
279 * @destid: Current destination ID
280 * @hopcount: Current hopcount
281 * @do_enum: Enumeration/Discovery mode flag
282 *
283 * Allocates a RIO device and configures fields based on configuration
284 * space contents. If device has a destination ID register, a destination
285 * ID is either assigned in enumeration mode or read from configuration
286 * space in discovery mode. If the device has switch capabilities, then
287 * a switch is allocated and configured appropriately. Returns a pointer
288 * to a RIO device on success or NULL on failure.
289 *
290 */
291static struct rio_dev *rio_setup_device(struct rio_net *net,
292 struct rio_mport *port, u16 destid,
293 u8 hopcount, int do_enum)
294{
295 struct rio_dev *rdev;
296 struct rio_switch *rswitch;
297 int result, rdid;
298
299 rdev = kmalloc(sizeof(struct rio_dev), GFP_KERNEL);
300 if (!rdev)
301 goto out;
302
303 memset(rdev, 0, sizeof(struct rio_dev));
304 rdev->net = net;
305 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR,
306 &result);
307 rdev->did = result >> 16;
308 rdev->vid = result & 0xffff;
309 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_INFO_CAR,
310 &rdev->device_rev);
311 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_ID_CAR,
312 &result);
313 rdev->asm_did = result >> 16;
314 rdev->asm_vid = result & 0xffff;
315 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR,
316 &result);
317 rdev->asm_rev = result >> 16;
318 rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR,
319 &rdev->pef);
320 if (rdev->pef & RIO_PEF_EXT_FEATURES)
321 rdev->efptr = result & 0xffff;
322
323 rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR,
324 &rdev->src_ops);
325 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR,
326 &rdev->dst_ops);
327
328 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)
329 && do_enum) {
330 rio_set_device_id(port, destid, hopcount, next_destid);
331 rdev->destid = next_destid++;
332 if (next_destid == port->host_deviceid)
333 next_destid++;
334 } else
335 rdev->destid = rio_get_device_id(port, destid, hopcount);
336
337 /* If a PE has both switch and other functions, show it as a switch */
338 if (rio_is_switch(rdev)) {
339 rio_mport_read_config_32(port, destid, hopcount,
340 RIO_SWP_INFO_CAR, &rdev->swpinfo);
341 rswitch = kmalloc(sizeof(struct rio_switch), GFP_KERNEL);
342 if (!rswitch) {
343 kfree(rdev);
344 rdev = NULL;
345 goto out;
346 }
347 rswitch->switchid = next_switchid;
348 rswitch->hopcount = hopcount;
349 rswitch->destid = 0xffff;
350 /* Initialize switch route table */
351 for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES; rdid++)
352 rswitch->route_table[rdid] = RIO_INVALID_ROUTE;
353 rdev->rswitch = rswitch;
354 sprintf(rio_name(rdev), "%02x:s:%04x", rdev->net->id,
355 rdev->rswitch->switchid);
356 rio_route_set_ops(rdev);
357
358 list_add_tail(&rswitch->node, &rio_switches);
359
360 } else
361 sprintf(rio_name(rdev), "%02x:e:%04x", rdev->net->id,
362 rdev->destid);
363
364 rdev->dev.bus = &rio_bus_type;
365
366 device_initialize(&rdev->dev);
367 rdev->dev.release = rio_release_dev;
368 rio_dev_get(rdev);
369
370 rdev->dma_mask = DMA_32BIT_MASK;
371 rdev->dev.dma_mask = &rdev->dma_mask;
372 rdev->dev.coherent_dma_mask = DMA_32BIT_MASK;
373
374 if ((rdev->pef & RIO_PEF_INB_DOORBELL) &&
375 (rdev->dst_ops & RIO_DST_OPS_DOORBELL))
376 rio_init_dbell_res(&rdev->riores[RIO_DOORBELL_RESOURCE],
377 0, 0xffff);
378
379 rio_add_device(rdev);
380
381 out:
382 return rdev;
383}
384
385/**
386 * rio_sport_is_active- Tests if a switch port has an active connection.
387 * @port: Master port to send transaction
388 * @destid: Associated destination ID for switch
389 * @hopcount: Hopcount to reach switch
390 * @sport: Switch port number
391 *
392 * Reads the port error status CSR for a particular switch port to
393 * determine if the port has an active link. Returns
394 * %PORT_N_ERR_STS_PORT_OK if the port is active or %0 if it is
395 * inactive.
396 */
397static int
398rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport)
399{
400 u32 result;
401 u32 ext_ftr_ptr;
402
403 int *entry = rio_sport_phys_table;
404
405 do {
406 if ((ext_ftr_ptr =
407 rio_mport_get_feature(port, 0, destid, hopcount, *entry)))
408
409 break;
410 } while (*++entry >= 0);
411
412 if (ext_ftr_ptr)
413 rio_mport_read_config_32(port, destid, hopcount,
414 ext_ftr_ptr +
415 RIO_PORT_N_ERR_STS_CSR(sport),
416 &result);
417
418 return (result & PORT_N_ERR_STS_PORT_OK);
419}
420
421/**
422 * rio_route_add_entry- Add a route entry to a switch routing table
423 * @mport: Master port to send transaction
424 * @rdev: Switch device
425 * @table: Routing table ID
426 * @route_destid: Destination ID to be routed
427 * @route_port: Port number to be routed
428 *
429 * Calls the switch specific add_entry() method to add a route entry
430 * on a switch. The route table can be specified using the @table
431 * argument if a switch has per port routing tables or the normal
432 * use is to specific all tables (or the global table) by passing
433 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
434 * on failure.
435 */
436static int rio_route_add_entry(struct rio_mport *mport, struct rio_dev *rdev,
437 u16 table, u16 route_destid, u8 route_port)
438{
439 return rdev->rswitch->add_entry(mport, rdev->rswitch->destid,
440 rdev->rswitch->hopcount, table,
441 route_destid, route_port);
442}
443
444/**
445 * rio_route_get_entry- Read a route entry in a switch routing table
446 * @mport: Master port to send transaction
447 * @rdev: Switch device
448 * @table: Routing table ID
449 * @route_destid: Destination ID to be routed
450 * @route_port: Pointer to read port number into
451 *
452 * Calls the switch specific get_entry() method to read a route entry
453 * in a switch. The route table can be specified using the @table
454 * argument if a switch has per port routing tables or the normal
455 * use is to specific all tables (or the global table) by passing
456 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
457 * on failure.
458 */
459static int
460rio_route_get_entry(struct rio_mport *mport, struct rio_dev *rdev, u16 table,
461 u16 route_destid, u8 * route_port)
462{
463 return rdev->rswitch->get_entry(mport, rdev->rswitch->destid,
464 rdev->rswitch->hopcount, table,
465 route_destid, route_port);
466}
467
468/**
469 * rio_get_host_deviceid_lock- Reads the Host Device ID Lock CSR on a device
470 * @port: Master port to send transaction
471 * @hopcount: Number of hops to the device
472 *
473 * Used during enumeration to read the Host Device ID Lock CSR on a
474 * RIO device. Returns the value of the lock register.
475 */
476static u16 rio_get_host_deviceid_lock(struct rio_mport *port, u8 hopcount)
477{
478 u32 result;
479
480 rio_mport_read_config_32(port, RIO_ANY_DESTID, hopcount,
481 RIO_HOST_DID_LOCK_CSR, &result);
482
483 return (u16) (result & 0xffff);
484}
485
486/**
487 * rio_get_swpinfo_inport- Gets the ingress port number
488 * @mport: Master port to send transaction
489 * @destid: Destination ID associated with the switch
490 * @hopcount: Number of hops to the device
491 *
492 * Returns port number being used to access the switch device.
493 */
494static u8
495rio_get_swpinfo_inport(struct rio_mport *mport, u16 destid, u8 hopcount)
496{
497 u32 result;
498
499 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
500 &result);
501
502 return (u8) (result & 0xff);
503}
504
505/**
506 * rio_get_swpinfo_tports- Gets total number of ports on the switch
507 * @mport: Master port to send transaction
508 * @destid: Destination ID associated with the switch
509 * @hopcount: Number of hops to the device
510 *
511 * Returns total numbers of ports implemented by the switch device.
512 */
513static u8 rio_get_swpinfo_tports(struct rio_mport *mport, u16 destid,
514 u8 hopcount)
515{
516 u32 result;
517
518 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
519 &result);
520
521 return RIO_GET_TOTAL_PORTS(result);
522}
523
524/**
525 * rio_net_add_mport- Add a master port to a RIO network
526 * @net: RIO network
527 * @port: Master port to add
528 *
529 * Adds a master port to the network list of associated master
530 * ports..
531 */
532static void rio_net_add_mport(struct rio_net *net, struct rio_mport *port)
533{
534 spin_lock(&rio_global_list_lock);
535 list_add_tail(&port->nnode, &net->mports);
536 spin_unlock(&rio_global_list_lock);
537}
538
539/**
540 * rio_enum_peer- Recursively enumerate a RIO network through a master port
541 * @net: RIO network being enumerated
542 * @port: Master port to send transactions
543 * @hopcount: Number of hops into the network
544 *
545 * Recursively enumerates a RIO network. Transactions are sent via the
546 * master port passed in @port.
547 */
548static int rio_enum_peer(struct rio_net *net, struct rio_mport *port,
549 u8 hopcount)
550{
551 int port_num;
552 int num_ports;
553 int cur_destid;
554 struct rio_dev *rdev;
555 u16 destid;
556 int tmp;
557
558 if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) {
559 pr_debug("RIO: PE already discovered by this host\n");
560 /*
561 * Already discovered by this host. Add it as another
562 * master port for the current network.
563 */
564 rio_net_add_mport(net, port);
565 return 0;
566 }
567
568 /* Attempt to acquire device lock */
569 rio_mport_write_config_32(port, RIO_ANY_DESTID, hopcount,
570 RIO_HOST_DID_LOCK_CSR, port->host_deviceid);
571 while ((tmp = rio_get_host_deviceid_lock(port, hopcount))
572 < port->host_deviceid) {
573 /* Delay a bit */
574 mdelay(1);
575 /* Attempt to acquire device lock again */
576 rio_mport_write_config_32(port, RIO_ANY_DESTID, hopcount,
577 RIO_HOST_DID_LOCK_CSR,
578 port->host_deviceid);
579 }
580
581 if (rio_get_host_deviceid_lock(port, hopcount) > port->host_deviceid) {
582 pr_debug(
583 "RIO: PE locked by a higher priority host...retreating\n");
584 return -1;
585 }
586
587 /* Setup new RIO device */
588 if ((rdev = rio_setup_device(net, port, RIO_ANY_DESTID, hopcount, 1))) {
589 /* Add device to the global and bus/net specific list. */
590 list_add_tail(&rdev->net_list, &net->devices);
591 } else
592 return -1;
593
594 if (rio_is_switch(rdev)) {
595 next_switchid++;
596
597 for (destid = 0; destid < next_destid; destid++) {
598 rio_route_add_entry(port, rdev, RIO_GLOBAL_TABLE,
599 destid, rio_get_swpinfo_inport(port,
600 RIO_ANY_DESTID,
601 hopcount));
602 rdev->rswitch->route_table[destid] =
603 rio_get_swpinfo_inport(port, RIO_ANY_DESTID,
604 hopcount);
605 }
606
607 num_ports =
608 rio_get_swpinfo_tports(port, RIO_ANY_DESTID, hopcount);
609 pr_debug(
610 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
611 rio_name(rdev), rdev->vid, rdev->did, num_ports);
612 for (port_num = 0; port_num < num_ports; port_num++) {
613 if (rio_get_swpinfo_inport
614 (port, RIO_ANY_DESTID, hopcount) == port_num)
615 continue;
616
617 cur_destid = next_destid;
618
619 if (rio_sport_is_active
620 (port, RIO_ANY_DESTID, hopcount, port_num)) {
621 pr_debug(
622 "RIO: scanning device on port %d\n",
623 port_num);
624 rio_route_add_entry(port, rdev,
625 RIO_GLOBAL_TABLE,
626 RIO_ANY_DESTID, port_num);
627
628 if (rio_enum_peer(net, port, hopcount + 1) < 0)
629 return -1;
630
631 /* Update routing tables */
632 if (next_destid > cur_destid) {
633 for (destid = cur_destid;
634 destid < next_destid; destid++) {
635 rio_route_add_entry(port, rdev,
636 RIO_GLOBAL_TABLE,
637 destid,
638 port_num);
639 rdev->rswitch->
640 route_table[destid] =
641 port_num;
642 }
643 rdev->rswitch->destid = cur_destid;
644 }
645 }
646 }
647 } else
648 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
649 rio_name(rdev), rdev->vid, rdev->did);
650
651 return 0;
652}
653
654/**
655 * rio_enum_complete- Tests if enumeration of a network is complete
656 * @port: Master port to send transaction
657 *
658 * Tests the Component Tag CSR for presence of the magic enumeration
659 * complete flag. Return %1 if enumeration is complete or %0 if
660 * enumeration is incomplete.
661 */
662static int rio_enum_complete(struct rio_mport *port)
663{
664 u32 tag_csr;
665 int ret = 0;
666
667 rio_local_read_config_32(port, RIO_COMPONENT_TAG_CSR, &tag_csr);
668
669 if (tag_csr == RIO_ENUM_CMPL_MAGIC)
670 ret = 1;
671
672 return ret;
673}
674
675/**
676 * rio_disc_peer- Recursively discovers a RIO network through a master port
677 * @net: RIO network being discovered
678 * @port: Master port to send transactions
679 * @destid: Current destination ID in network
680 * @hopcount: Number of hops into the network
681 *
682 * Recursively discovers a RIO network. Transactions are sent via the
683 * master port passed in @port.
684 */
685static int
686rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
687 u8 hopcount)
688{
689 u8 port_num, route_port;
690 int num_ports;
691 struct rio_dev *rdev;
692 u16 ndestid;
693
694 /* Setup new RIO device */
695 if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) {
696 /* Add device to the global and bus/net specific list. */
697 list_add_tail(&rdev->net_list, &net->devices);
698 } else
699 return -1;
700
701 if (rio_is_switch(rdev)) {
702 next_switchid++;
703
704 /* Associated destid is how we accessed this switch */
705 rdev->rswitch->destid = destid;
706
707 num_ports = rio_get_swpinfo_tports(port, destid, hopcount);
708 pr_debug(
709 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
710 rio_name(rdev), rdev->vid, rdev->did, num_ports);
711 for (port_num = 0; port_num < num_ports; port_num++) {
712 if (rio_get_swpinfo_inport(port, destid, hopcount) ==
713 port_num)
714 continue;
715
716 if (rio_sport_is_active
717 (port, destid, hopcount, port_num)) {
718 pr_debug(
719 "RIO: scanning device on port %d\n",
720 port_num);
721 for (ndestid = 0; ndestid < RIO_ANY_DESTID;
722 ndestid++) {
723 rio_route_get_entry(port, rdev,
724 RIO_GLOBAL_TABLE,
725 ndestid,
726 &route_port);
727 if (route_port == port_num)
728 break;
729 }
730
731 if (rio_disc_peer
732 (net, port, ndestid, hopcount + 1) < 0)
733 return -1;
734 }
735 }
736 } else
737 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
738 rio_name(rdev), rdev->vid, rdev->did);
739
740 return 0;
741}
742
743/**
744 * rio_mport_is_active- Tests if master port link is active
745 * @port: Master port to test
746 *
747 * Reads the port error status CSR for the master port to
748 * determine if the port has an active link. Returns
749 * %PORT_N_ERR_STS_PORT_OK if the master port is active
750 * or %0 if it is inactive.
751 */
752static int rio_mport_is_active(struct rio_mport *port)
753{
754 u32 result = 0;
755 u32 ext_ftr_ptr;
756 int *entry = rio_mport_phys_table;
757
758 do {
759 if ((ext_ftr_ptr =
760 rio_mport_get_feature(port, 1, 0, 0, *entry)))
761 break;
762 } while (*++entry >= 0);
763
764 if (ext_ftr_ptr)
765 rio_local_read_config_32(port,
766 ext_ftr_ptr +
767 RIO_PORT_N_ERR_STS_CSR(port->index),
768 &result);
769
770 return (result & PORT_N_ERR_STS_PORT_OK);
771}
772
773/**
774 * rio_alloc_net- Allocate and configure a new RIO network
775 * @port: Master port associated with the RIO network
776 *
777 * Allocates a RIO network structure, initializes per-network
778 * list heads, and adds the associated master port to the
779 * network list of associated master ports. Returns a
780 * RIO network pointer on success or %NULL on failure.
781 */
782static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port)
783{
784 struct rio_net *net;
785
786 net = kmalloc(sizeof(struct rio_net), GFP_KERNEL);
787 if (net) {
788 memset(net, 0, sizeof(struct rio_net));
789 INIT_LIST_HEAD(&net->node);
790 INIT_LIST_HEAD(&net->devices);
791 INIT_LIST_HEAD(&net->mports);
792 list_add_tail(&port->nnode, &net->mports);
793 net->hport = port;
794 net->id = next_net++;
795 }
796 return net;
797}
798
799/**
800 * rio_enum_mport- Start enumeration through a master port
801 * @mport: Master port to send transactions
802 *
803 * Starts the enumeration process. If somebody has enumerated our
804 * master port device, then give up. If not and we have an active
805 * link, then start recursive peer enumeration. Returns %0 if
806 * enumeration succeeds or %-EBUSY if enumeration fails.
807 */
808int rio_enum_mport(struct rio_mport *mport)
809{
810 struct rio_net *net = NULL;
811 int rc = 0;
812
813 printk(KERN_INFO "RIO: enumerate master port %d, %s\n", mport->id,
814 mport->name);
815 /* If somebody else enumerated our master port device, bail. */
816 if (rio_enum_host(mport) < 0) {
817 printk(KERN_INFO
818 "RIO: master port %d device has been enumerated by a remote host\n",
819 mport->id);
820 rc = -EBUSY;
821 goto out;
822 }
823
824 /* If master port has an active link, allocate net and enum peers */
825 if (rio_mport_is_active(mport)) {
826 if (!(net = rio_alloc_net(mport))) {
827 printk(KERN_ERR "RIO: failed to allocate new net\n");
828 rc = -ENOMEM;
829 goto out;
830 }
831 if (rio_enum_peer(net, mport, 0) < 0) {
832 /* A higher priority host won enumeration, bail. */
833 printk(KERN_INFO
834 "RIO: master port %d device has lost enumeration to a remote host\n",
835 mport->id);
836 rio_clear_locks(mport);
837 rc = -EBUSY;
838 goto out;
839 }
840 rio_clear_locks(mport);
841 } else {
842 printk(KERN_INFO "RIO: master port %d link inactive\n",
843 mport->id);
844 rc = -EINVAL;
845 }
846
847 out:
848 return rc;
849}
850
851/**
852 * rio_build_route_tables- Generate route tables from switch route entries
853 *
854 * For each switch device, generate a route table by copying existing
855 * route entries from the switch.
856 */
857static void rio_build_route_tables(void)
858{
859 struct rio_dev *rdev;
860 int i;
861 u8 sport;
862
863 list_for_each_entry(rdev, &rio_devices, global_list)
864 if (rio_is_switch(rdev))
865 for (i = 0; i < RIO_MAX_ROUTE_ENTRIES; i++) {
866 if (rio_route_get_entry
867 (rdev->net->hport, rdev, RIO_GLOBAL_TABLE, i,
868 &sport) < 0)
869 continue;
870 rdev->rswitch->route_table[i] = sport;
871 }
872}
873
874/**
875 * rio_enum_timeout- Signal that enumeration timed out
876 * @data: Address of timeout flag.
877 *
878 * When the enumeration complete timer expires, set a flag that
879 * signals to the discovery process that enumeration did not
880 * complete in a sane amount of time.
881 */
882static void rio_enum_timeout(unsigned long data)
883{
884 /* Enumeration timed out, set flag */
885 *(int *)data = 1;
886}
887
888/**
889 * rio_disc_mport- Start discovery through a master port
890 * @mport: Master port to send transactions
891 *
892 * Starts the discovery process. If we have an active link,
893 * then wait for the signal that enumeration is complete.
894 * When enumeration completion is signaled, start recursive
895 * peer discovery. Returns %0 if discovery succeeds or %-EBUSY
896 * on failure.
897 */
898int rio_disc_mport(struct rio_mport *mport)
899{
900 struct rio_net *net = NULL;
901 int enum_timeout_flag = 0;
902
903 printk(KERN_INFO "RIO: discover master port %d, %s\n", mport->id,
904 mport->name);
905
906 /* If master port has an active link, allocate net and discover peers */
907 if (rio_mport_is_active(mport)) {
908 if (!(net = rio_alloc_net(mport))) {
909 printk(KERN_ERR "RIO: Failed to allocate new net\n");
910 goto bail;
911 }
912
913 pr_debug("RIO: wait for enumeration complete...");
914
915 rio_enum_timer.expires =
916 jiffies + CONFIG_RAPIDIO_DISC_TIMEOUT * HZ;
917 rio_enum_timer.data = (unsigned long)&enum_timeout_flag;
918 add_timer(&rio_enum_timer);
919 while (!rio_enum_complete(mport)) {
920 mdelay(1);
921 if (enum_timeout_flag) {
922 del_timer_sync(&rio_enum_timer);
923 goto timeout;
924 }
925 }
926 del_timer_sync(&rio_enum_timer);
927
928 pr_debug("done\n");
929 if (rio_disc_peer(net, mport, RIO_ANY_DESTID, 0) < 0) {
930 printk(KERN_INFO
931 "RIO: master port %d device has failed discovery\n",
932 mport->id);
933 goto bail;
934 }
935
936 rio_build_route_tables();
937 }
938
939 return 0;
940
941 timeout:
942 pr_debug("timeout\n");
943 bail:
944 return -EBUSY;
945}
diff --git a/drivers/rapidio/rio-sysfs.c b/drivers/rapidio/rio-sysfs.c
new file mode 100644
index 000000000000..30a11436e241
--- /dev/null
+++ b/drivers/rapidio/rio-sysfs.c
@@ -0,0 +1,230 @@
1/*
2 * RapidIO sysfs attributes and support
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/config.h>
14#include <linux/kernel.h>
15#include <linux/rio.h>
16#include <linux/rio_drv.h>
17#include <linux/stat.h>
18
19#include "rio.h"
20
21/* Sysfs support */
22#define rio_config_attr(field, format_string) \
23static ssize_t \
24field##_show(struct device *dev, struct device_attribute *attr, char *buf) \
25{ \
26 struct rio_dev *rdev = to_rio_dev(dev); \
27 \
28 return sprintf(buf, format_string, rdev->field); \
29} \
30
31rio_config_attr(did, "0x%04x\n");
32rio_config_attr(vid, "0x%04x\n");
33rio_config_attr(device_rev, "0x%08x\n");
34rio_config_attr(asm_did, "0x%04x\n");
35rio_config_attr(asm_vid, "0x%04x\n");
36rio_config_attr(asm_rev, "0x%04x\n");
37
38static ssize_t routes_show(struct device *dev, struct device_attribute *attr, char *buf)
39{
40 struct rio_dev *rdev = to_rio_dev(dev);
41 char *str = buf;
42 int i;
43
44 if (!rdev->rswitch)
45 goto out;
46
47 for (i = 0; i < RIO_MAX_ROUTE_ENTRIES; i++) {
48 if (rdev->rswitch->route_table[i] == RIO_INVALID_ROUTE)
49 continue;
50 str +=
51 sprintf(str, "%04x %02x\n", i,
52 rdev->rswitch->route_table[i]);
53 }
54
55 out:
56 return (str - buf);
57}
58
59struct device_attribute rio_dev_attrs[] = {
60 __ATTR_RO(did),
61 __ATTR_RO(vid),
62 __ATTR_RO(device_rev),
63 __ATTR_RO(asm_did),
64 __ATTR_RO(asm_vid),
65 __ATTR_RO(asm_rev),
66 __ATTR_RO(routes),
67 __ATTR_NULL,
68};
69
70static ssize_t
71rio_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
72{
73 struct rio_dev *dev =
74 to_rio_dev(container_of(kobj, struct device, kobj));
75 unsigned int size = 0x100;
76 loff_t init_off = off;
77 u8 *data = (u8 *) buf;
78
79 /* Several chips lock up trying to read undefined config space */
80 if (capable(CAP_SYS_ADMIN))
81 size = 0x200000;
82
83 if (off > size)
84 return 0;
85 if (off + count > size) {
86 size -= off;
87 count = size;
88 } else {
89 size = count;
90 }
91
92 if ((off & 1) && size) {
93 u8 val;
94 rio_read_config_8(dev, off, &val);
95 data[off - init_off] = val;
96 off++;
97 size--;
98 }
99
100 if ((off & 3) && size > 2) {
101 u16 val;
102 rio_read_config_16(dev, off, &val);
103 data[off - init_off] = (val >> 8) & 0xff;
104 data[off - init_off + 1] = val & 0xff;
105 off += 2;
106 size -= 2;
107 }
108
109 while (size > 3) {
110 u32 val;
111 rio_read_config_32(dev, off, &val);
112 data[off - init_off] = (val >> 24) & 0xff;
113 data[off - init_off + 1] = (val >> 16) & 0xff;
114 data[off - init_off + 2] = (val >> 8) & 0xff;
115 data[off - init_off + 3] = val & 0xff;
116 off += 4;
117 size -= 4;
118 }
119
120 if (size >= 2) {
121 u16 val;
122 rio_read_config_16(dev, off, &val);
123 data[off - init_off] = (val >> 8) & 0xff;
124 data[off - init_off + 1] = val & 0xff;
125 off += 2;
126 size -= 2;
127 }
128
129 if (size > 0) {
130 u8 val;
131 rio_read_config_8(dev, off, &val);
132 data[off - init_off] = val;
133 off++;
134 --size;
135 }
136
137 return count;
138}
139
140static ssize_t
141rio_write_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
142{
143 struct rio_dev *dev =
144 to_rio_dev(container_of(kobj, struct device, kobj));
145 unsigned int size = count;
146 loff_t init_off = off;
147 u8 *data = (u8 *) buf;
148
149 if (off > 0x200000)
150 return 0;
151 if (off + count > 0x200000) {
152 size = 0x200000 - off;
153 count = size;
154 }
155
156 if ((off & 1) && size) {
157 rio_write_config_8(dev, off, data[off - init_off]);
158 off++;
159 size--;
160 }
161
162 if ((off & 3) && (size > 2)) {
163 u16 val = data[off - init_off + 1];
164 val |= (u16) data[off - init_off] << 8;
165 rio_write_config_16(dev, off, val);
166 off += 2;
167 size -= 2;
168 }
169
170 while (size > 3) {
171 u32 val = data[off - init_off + 3];
172 val |= (u32) data[off - init_off + 2] << 8;
173 val |= (u32) data[off - init_off + 1] << 16;
174 val |= (u32) data[off - init_off] << 24;
175 rio_write_config_32(dev, off, val);
176 off += 4;
177 size -= 4;
178 }
179
180 if (size >= 2) {
181 u16 val = data[off - init_off + 1];
182 val |= (u16) data[off - init_off] << 8;
183 rio_write_config_16(dev, off, val);
184 off += 2;
185 size -= 2;
186 }
187
188 if (size) {
189 rio_write_config_8(dev, off, data[off - init_off]);
190 off++;
191 --size;
192 }
193
194 return count;
195}
196
197static struct bin_attribute rio_config_attr = {
198 .attr = {
199 .name = "config",
200 .mode = S_IRUGO | S_IWUSR,
201 .owner = THIS_MODULE,
202 },
203 .size = 0x200000,
204 .read = rio_read_config,
205 .write = rio_write_config,
206};
207
208/**
209 * rio_create_sysfs_dev_files - create RIO specific sysfs files
210 * @rdev: device whose entries should be created
211 *
212 * Create files when @rdev is added to sysfs.
213 */
214int rio_create_sysfs_dev_files(struct rio_dev *rdev)
215{
216 sysfs_create_bin_file(&rdev->dev.kobj, &rio_config_attr);
217
218 return 0;
219}
220
221/**
222 * rio_remove_sysfs_dev_files - cleanup RIO specific sysfs files
223 * @rdev: device whose entries we should free
224 *
225 * Cleanup when @rdev is removed from sysfs.
226 */
227void rio_remove_sysfs_dev_files(struct rio_dev *rdev)
228{
229 sysfs_remove_bin_file(&rdev->dev.kobj, &rio_config_attr);
230}
diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c
new file mode 100644
index 000000000000..3ca1011ceaac
--- /dev/null
+++ b/drivers/rapidio/rio.c
@@ -0,0 +1,510 @@
1/*
2 * RapidIO interconnect services
3 * (RapidIO Interconnect Specification, http://www.rapidio.org)
4 *
5 * Copyright 2005 MontaVista Software, Inc.
6 * Matt Porter <mporter@kernel.crashing.org>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/config.h>
15#include <linux/types.h>
16#include <linux/kernel.h>
17
18#include <linux/delay.h>
19#include <linux/init.h>
20#include <linux/rio.h>
21#include <linux/rio_drv.h>
22#include <linux/rio_ids.h>
23#include <linux/rio_regs.h>
24#include <linux/module.h>
25#include <linux/spinlock.h>
26
27#include "rio.h"
28
29static LIST_HEAD(rio_mports);
30
31/**
32 * rio_local_get_device_id - Get the base/extended device id for a port
33 * @port: RIO master port from which to get the deviceid
34 *
35 * Reads the base/extended device id from the local device
36 * implementing the master port. Returns the 8/16-bit device
37 * id.
38 */
39u16 rio_local_get_device_id(struct rio_mport *port)
40{
41 u32 result;
42
43 rio_local_read_config_32(port, RIO_DID_CSR, &result);
44
45 return (RIO_GET_DID(result));
46}
47
48/**
49 * rio_request_inb_mbox - request inbound mailbox service
50 * @mport: RIO master port from which to allocate the mailbox resource
51 * @dev_id: Device specific pointer to pass on event
52 * @mbox: Mailbox number to claim
53 * @entries: Number of entries in inbound mailbox queue
54 * @minb: Callback to execute when inbound message is received
55 *
56 * Requests ownership of an inbound mailbox resource and binds
57 * a callback function to the resource. Returns %0 on success.
58 */
59int rio_request_inb_mbox(struct rio_mport *mport,
60 void *dev_id,
61 int mbox,
62 int entries,
63 void (*minb) (struct rio_mport * mport, void *dev_id, int mbox,
64 int slot))
65{
66 int rc = 0;
67
68 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
69
70 if (res) {
71 rio_init_mbox_res(res, mbox, mbox);
72
73 /* Make sure this mailbox isn't in use */
74 if ((rc =
75 request_resource(&mport->riores[RIO_INB_MBOX_RESOURCE],
76 res)) < 0) {
77 kfree(res);
78 goto out;
79 }
80
81 mport->inb_msg[mbox].res = res;
82
83 /* Hook the inbound message callback */
84 mport->inb_msg[mbox].mcback = minb;
85
86 rc = rio_open_inb_mbox(mport, dev_id, mbox, entries);
87 } else
88 rc = -ENOMEM;
89
90 out:
91 return rc;
92}
93
94/**
95 * rio_release_inb_mbox - release inbound mailbox message service
96 * @mport: RIO master port from which to release the mailbox resource
97 * @mbox: Mailbox number to release
98 *
99 * Releases ownership of an inbound mailbox resource. Returns 0
100 * if the request has been satisfied.
101 */
102int rio_release_inb_mbox(struct rio_mport *mport, int mbox)
103{
104 rio_close_inb_mbox(mport, mbox);
105
106 /* Release the mailbox resource */
107 return release_resource(mport->inb_msg[mbox].res);
108}
109
110/**
111 * rio_request_outb_mbox - request outbound mailbox service
112 * @mport: RIO master port from which to allocate the mailbox resource
113 * @dev_id: Device specific pointer to pass on event
114 * @mbox: Mailbox number to claim
115 * @entries: Number of entries in outbound mailbox queue
116 * @moutb: Callback to execute when outbound message is sent
117 *
118 * Requests ownership of an outbound mailbox resource and binds
119 * a callback function to the resource. Returns 0 on success.
120 */
121int rio_request_outb_mbox(struct rio_mport *mport,
122 void *dev_id,
123 int mbox,
124 int entries,
125 void (*moutb) (struct rio_mport * mport, void *dev_id, int mbox, int slot))
126{
127 int rc = 0;
128
129 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
130
131 if (res) {
132 rio_init_mbox_res(res, mbox, mbox);
133
134 /* Make sure this outbound mailbox isn't in use */
135 if ((rc =
136 request_resource(&mport->riores[RIO_OUTB_MBOX_RESOURCE],
137 res)) < 0) {
138 kfree(res);
139 goto out;
140 }
141
142 mport->outb_msg[mbox].res = res;
143
144 /* Hook the inbound message callback */
145 mport->outb_msg[mbox].mcback = moutb;
146
147 rc = rio_open_outb_mbox(mport, dev_id, mbox, entries);
148 } else
149 rc = -ENOMEM;
150
151 out:
152 return rc;
153}
154
155/**
156 * rio_release_outb_mbox - release outbound mailbox message service
157 * @mport: RIO master port from which to release the mailbox resource
158 * @mbox: Mailbox number to release
159 *
160 * Releases ownership of an inbound mailbox resource. Returns 0
161 * if the request has been satisfied.
162 */
163int rio_release_outb_mbox(struct rio_mport *mport, int mbox)
164{
165 rio_close_outb_mbox(mport, mbox);
166
167 /* Release the mailbox resource */
168 return release_resource(mport->outb_msg[mbox].res);
169}
170
171/**
172 * rio_setup_inb_dbell - bind inbound doorbell callback
173 * @mport: RIO master port to bind the doorbell callback
174 * @dev_id: Device specific pointer to pass on event
175 * @res: Doorbell message resource
176 * @dinb: Callback to execute when doorbell is received
177 *
178 * Adds a doorbell resource/callback pair into a port's
179 * doorbell event list. Returns 0 if the request has been
180 * satisfied.
181 */
182static int
183rio_setup_inb_dbell(struct rio_mport *mport, void *dev_id, struct resource *res,
184 void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src, u16 dst,
185 u16 info))
186{
187 int rc = 0;
188 struct rio_dbell *dbell;
189
190 if (!(dbell = kmalloc(sizeof(struct rio_dbell), GFP_KERNEL))) {
191 rc = -ENOMEM;
192 goto out;
193 }
194
195 dbell->res = res;
196 dbell->dinb = dinb;
197 dbell->dev_id = dev_id;
198
199 list_add_tail(&dbell->node, &mport->dbells);
200
201 out:
202 return rc;
203}
204
205/**
206 * rio_request_inb_dbell - request inbound doorbell message service
207 * @mport: RIO master port from which to allocate the doorbell resource
208 * @dev_id: Device specific pointer to pass on event
209 * @start: Doorbell info range start
210 * @end: Doorbell info range end
211 * @dinb: Callback to execute when doorbell is received
212 *
213 * Requests ownership of an inbound doorbell resource and binds
214 * a callback function to the resource. Returns 0 if the request
215 * has been satisfied.
216 */
217int rio_request_inb_dbell(struct rio_mport *mport,
218 void *dev_id,
219 u16 start,
220 u16 end,
221 void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src,
222 u16 dst, u16 info))
223{
224 int rc = 0;
225
226 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
227
228 if (res) {
229 rio_init_dbell_res(res, start, end);
230
231 /* Make sure these doorbells aren't in use */
232 if ((rc =
233 request_resource(&mport->riores[RIO_DOORBELL_RESOURCE],
234 res)) < 0) {
235 kfree(res);
236 goto out;
237 }
238
239 /* Hook the doorbell callback */
240 rc = rio_setup_inb_dbell(mport, dev_id, res, dinb);
241 } else
242 rc = -ENOMEM;
243
244 out:
245 return rc;
246}
247
248/**
249 * rio_release_inb_dbell - release inbound doorbell message service
250 * @mport: RIO master port from which to release the doorbell resource
251 * @start: Doorbell info range start
252 * @end: Doorbell info range end
253 *
254 * Releases ownership of an inbound doorbell resource and removes
255 * callback from the doorbell event list. Returns 0 if the request
256 * has been satisfied.
257 */
258int rio_release_inb_dbell(struct rio_mport *mport, u16 start, u16 end)
259{
260 int rc = 0, found = 0;
261 struct rio_dbell *dbell;
262
263 list_for_each_entry(dbell, &mport->dbells, node) {
264 if ((dbell->res->start == start) && (dbell->res->end == end)) {
265 found = 1;
266 break;
267 }
268 }
269
270 /* If we can't find an exact match, fail */
271 if (!found) {
272 rc = -EINVAL;
273 goto out;
274 }
275
276 /* Delete from list */
277 list_del(&dbell->node);
278
279 /* Release the doorbell resource */
280 rc = release_resource(dbell->res);
281
282 /* Free the doorbell event */
283 kfree(dbell);
284
285 out:
286 return rc;
287}
288
289/**
290 * rio_request_outb_dbell - request outbound doorbell message range
291 * @rdev: RIO device from which to allocate the doorbell resource
292 * @start: Doorbell message range start
293 * @end: Doorbell message range end
294 *
295 * Requests ownership of a doorbell message range. Returns a resource
296 * if the request has been satisfied or %NULL on failure.
297 */
298struct resource *rio_request_outb_dbell(struct rio_dev *rdev, u16 start,
299 u16 end)
300{
301 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
302
303 if (res) {
304 rio_init_dbell_res(res, start, end);
305
306 /* Make sure these doorbells aren't in use */
307 if (request_resource(&rdev->riores[RIO_DOORBELL_RESOURCE], res)
308 < 0) {
309 kfree(res);
310 res = NULL;
311 }
312 }
313
314 return res;
315}
316
317/**
318 * rio_release_outb_dbell - release outbound doorbell message range
319 * @rdev: RIO device from which to release the doorbell resource
320 * @res: Doorbell resource to be freed
321 *
322 * Releases ownership of a doorbell message range. Returns 0 if the
323 * request has been satisfied.
324 */
325int rio_release_outb_dbell(struct rio_dev *rdev, struct resource *res)
326{
327 int rc = release_resource(res);
328
329 kfree(res);
330
331 return rc;
332}
333
334/**
335 * rio_mport_get_feature - query for devices' extended features
336 * @port: Master port to issue transaction
337 * @local: Indicate a local master port or remote device access
338 * @destid: Destination ID of the device
339 * @hopcount: Number of switch hops to the device
340 * @ftr: Extended feature code
341 *
342 * Tell if a device supports a given RapidIO capability.
343 * Returns the offset of the requested extended feature
344 * block within the device's RIO configuration space or
345 * 0 in case the device does not support it. Possible
346 * values for @ftr:
347 *
348 * %RIO_EFB_PAR_EP_ID LP/LVDS EP Devices
349 *
350 * %RIO_EFB_PAR_EP_REC_ID LP/LVDS EP Recovery Devices
351 *
352 * %RIO_EFB_PAR_EP_FREE_ID LP/LVDS EP Free Devices
353 *
354 * %RIO_EFB_SER_EP_ID LP/Serial EP Devices
355 *
356 * %RIO_EFB_SER_EP_REC_ID LP/Serial EP Recovery Devices
357 *
358 * %RIO_EFB_SER_EP_FREE_ID LP/Serial EP Free Devices
359 */
360u32
361rio_mport_get_feature(struct rio_mport * port, int local, u16 destid,
362 u8 hopcount, int ftr)
363{
364 u32 asm_info, ext_ftr_ptr, ftr_header;
365
366 if (local)
367 rio_local_read_config_32(port, RIO_ASM_INFO_CAR, &asm_info);
368 else
369 rio_mport_read_config_32(port, destid, hopcount,
370 RIO_ASM_INFO_CAR, &asm_info);
371
372 ext_ftr_ptr = asm_info & RIO_EXT_FTR_PTR_MASK;
373
374 while (ext_ftr_ptr) {
375 if (local)
376 rio_local_read_config_32(port, ext_ftr_ptr,
377 &ftr_header);
378 else
379 rio_mport_read_config_32(port, destid, hopcount,
380 ext_ftr_ptr, &ftr_header);
381 if (RIO_GET_BLOCK_ID(ftr_header) == ftr)
382 return ext_ftr_ptr;
383 if (!(ext_ftr_ptr = RIO_GET_BLOCK_PTR(ftr_header)))
384 break;
385 }
386
387 return 0;
388}
389
390/**
391 * rio_get_asm - Begin or continue searching for a RIO device by vid/did/asm_vid/asm_did
392 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
393 * @did: RIO did to match or %RIO_ANY_ID to match all dids
394 * @asm_vid: RIO asm_vid to match or %RIO_ANY_ID to match all asm_vids
395 * @asm_did: RIO asm_did to match or %RIO_ANY_ID to match all asm_dids
396 * @from: Previous RIO device found in search, or %NULL for new search
397 *
398 * Iterates through the list of known RIO devices. If a RIO device is
399 * found with a matching @vid, @did, @asm_vid, @asm_did, the reference
400 * count to the device is incrememted and a pointer to its device
401 * structure is returned. Otherwise, %NULL is returned. A new search
402 * is initiated by passing %NULL to the @from argument. Otherwise, if
403 * @from is not %NULL, searches continue from next device on the global
404 * list. The reference count for @from is always decremented if it is
405 * not %NULL.
406 */
407struct rio_dev *rio_get_asm(u16 vid, u16 did,
408 u16 asm_vid, u16 asm_did, struct rio_dev *from)
409{
410 struct list_head *n;
411 struct rio_dev *rdev;
412
413 WARN_ON(in_interrupt());
414 spin_lock(&rio_global_list_lock);
415 n = from ? from->global_list.next : rio_devices.next;
416
417 while (n && (n != &rio_devices)) {
418 rdev = rio_dev_g(n);
419 if ((vid == RIO_ANY_ID || rdev->vid == vid) &&
420 (did == RIO_ANY_ID || rdev->did == did) &&
421 (asm_vid == RIO_ANY_ID || rdev->asm_vid == asm_vid) &&
422 (asm_did == RIO_ANY_ID || rdev->asm_did == asm_did))
423 goto exit;
424 n = n->next;
425 }
426 rdev = NULL;
427 exit:
428 rio_dev_put(from);
429 rdev = rio_dev_get(rdev);
430 spin_unlock(&rio_global_list_lock);
431 return rdev;
432}
433
434/**
435 * rio_get_device - Begin or continue searching for a RIO device by vid/did
436 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
437 * @did: RIO did to match or %RIO_ANY_ID to match all dids
438 * @from: Previous RIO device found in search, or %NULL for new search
439 *
440 * Iterates through the list of known RIO devices. If a RIO device is
441 * found with a matching @vid and @did, the reference count to the
442 * device is incrememted and a pointer to its device structure is returned.
443 * Otherwise, %NULL is returned. A new search is initiated by passing %NULL
444 * to the @from argument. Otherwise, if @from is not %NULL, searches
445 * continue from next device on the global list. The reference count for
446 * @from is always decremented if it is not %NULL.
447 */
448struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from)
449{
450 return rio_get_asm(vid, did, RIO_ANY_ID, RIO_ANY_ID, from);
451}
452
453static void rio_fixup_device(struct rio_dev *dev)
454{
455}
456
457static int __devinit rio_init(void)
458{
459 struct rio_dev *dev = NULL;
460
461 while ((dev = rio_get_device(RIO_ANY_ID, RIO_ANY_ID, dev)) != NULL) {
462 rio_fixup_device(dev);
463 }
464 return 0;
465}
466
467device_initcall(rio_init);
468
469int rio_init_mports(void)
470{
471 int rc = 0;
472 struct rio_mport *port;
473
474 list_for_each_entry(port, &rio_mports, node) {
475 if (!request_mem_region(port->iores.start,
476 port->iores.end - port->iores.start,
477 port->name)) {
478 printk(KERN_ERR
479 "RIO: Error requesting master port region %8.8lx-%8.8lx\n",
480 port->iores.start, port->iores.end - 1);
481 rc = -ENOMEM;
482 goto out;
483 }
484
485 if (port->host_deviceid >= 0)
486 rio_enum_mport(port);
487 else
488 rio_disc_mport(port);
489 }
490
491 out:
492 return rc;
493}
494
495void rio_register_mport(struct rio_mport *port)
496{
497 list_add_tail(&port->node, &rio_mports);
498}
499
500EXPORT_SYMBOL_GPL(rio_local_get_device_id);
501EXPORT_SYMBOL_GPL(rio_get_device);
502EXPORT_SYMBOL_GPL(rio_get_asm);
503EXPORT_SYMBOL_GPL(rio_request_inb_dbell);
504EXPORT_SYMBOL_GPL(rio_release_inb_dbell);
505EXPORT_SYMBOL_GPL(rio_request_outb_dbell);
506EXPORT_SYMBOL_GPL(rio_release_outb_dbell);
507EXPORT_SYMBOL_GPL(rio_request_inb_mbox);
508EXPORT_SYMBOL_GPL(rio_release_inb_mbox);
509EXPORT_SYMBOL_GPL(rio_request_outb_mbox);
510EXPORT_SYMBOL_GPL(rio_release_outb_mbox);
diff --git a/drivers/rapidio/rio.h b/drivers/rapidio/rio.h
new file mode 100644
index 000000000000..b242cee656e7
--- /dev/null
+++ b/drivers/rapidio/rio.h
@@ -0,0 +1,60 @@
1/*
2 * RapidIO interconnect services
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/device.h>
14#include <linux/list.h>
15#include <linux/rio.h>
16
17/* Functions internal to the RIO core code */
18
19extern u32 rio_mport_get_feature(struct rio_mport *mport, int local, u16 destid,
20 u8 hopcount, int ftr);
21extern int rio_create_sysfs_dev_files(struct rio_dev *rdev);
22extern int rio_enum_mport(struct rio_mport *mport);
23extern int rio_disc_mport(struct rio_mport *mport);
24
25/* Structures internal to the RIO core code */
26extern struct device_attribute rio_dev_attrs[];
27extern spinlock_t rio_global_list_lock;
28
29extern struct rio_route_ops __start_rio_route_ops[];
30extern struct rio_route_ops __end_rio_route_ops[];
31
32/* Helpers internal to the RIO core code */
33#define DECLARE_RIO_ROUTE_SECTION(section, vid, did, add_hook, get_hook) \
34 static struct rio_route_ops __rio_route_ops __attribute_used__ \
35 __attribute__((__section__(#section))) = { vid, did, add_hook, get_hook };
36
37/**
38 * DECLARE_RIO_ROUTE_OPS - Registers switch routing operations
39 * @vid: RIO vendor ID
40 * @did: RIO device ID
41 * @add_hook: Callback that adds a route entry
42 * @get_hook: Callback that gets a route entry
43 *
44 * Manipulating switch route tables in RIO is switch specific. This
45 * registers a switch by vendor and device ID with two callbacks for
46 * modifying and retrieving route entries in a switch. A &struct
47 * rio_route_ops is initialized with the ops and placed into a
48 * RIO-specific kernel section.
49 */
50#define DECLARE_RIO_ROUTE_OPS(vid, did, add_hook, get_hook) \
51 DECLARE_RIO_ROUTE_SECTION(.rio_route_ops, \
52 vid, did, add_hook, get_hook)
53
54#ifdef CONFIG_RAPIDIO_8_BIT_TRANSPORT
55#define RIO_GET_DID(x) ((x & 0x00ff0000) >> 16)
56#define RIO_SET_DID(x) ((x & 0x000000ff) << 16)
57#else
58#define RIO_GET_DID(x) (x & 0xffff)
59#define RIO_SET_DID(x) (x & 0xffff)
60#endif
diff --git a/drivers/rapidio/switches/Makefile b/drivers/rapidio/switches/Makefile
new file mode 100644
index 000000000000..b924f8301761
--- /dev/null
+++ b/drivers/rapidio/switches/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for RIO switches
3#
4
5obj-$(CONFIG_RAPIDIO) += tsi500.o
diff --git a/drivers/rapidio/switches/tsi500.c b/drivers/rapidio/switches/tsi500.c
new file mode 100644
index 000000000000..c77c23bd9840
--- /dev/null
+++ b/drivers/rapidio/switches/tsi500.c
@@ -0,0 +1,60 @@
1/*
2 * RapidIO Tsi500 switch support
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/rio.h>
14#include <linux/rio_drv.h>
15#include <linux/rio_ids.h>
16#include "../rio.h"
17
18static int
19tsi500_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount, u16 table, u16 route_destid, u8 route_port)
20{
21 int i;
22 u32 offset = 0x10000 + 0xa00 + ((route_destid / 2)&~0x3);
23 u32 result;
24
25 if (table == 0xff) {
26 rio_mport_read_config_32(mport, destid, hopcount, offset, &result);
27 result &= ~(0xf << (4*(route_destid & 0x7)));
28 for (i=0;i<4;i++)
29 rio_mport_write_config_32(mport, destid, hopcount, offset + (0x20000*i), result | (route_port << (4*(route_destid & 0x7))));
30 }
31 else {
32 rio_mport_read_config_32(mport, destid, hopcount, offset + (0x20000*table), &result);
33 result &= ~(0xf << (4*(route_destid & 0x7)));
34 rio_mport_write_config_32(mport, destid, hopcount, offset + (0x20000*table), result | (route_port << (4*(route_destid & 0x7))));
35 }
36
37 return 0;
38}
39
40static int
41tsi500_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount, u16 table, u16 route_destid, u8 *route_port)
42{
43 int ret = 0;
44 u32 offset = 0x10000 + 0xa00 + ((route_destid / 2)&~0x3);
45 u32 result;
46
47 if (table == 0xff)
48 rio_mport_read_config_32(mport, destid, hopcount, offset, &result);
49 else
50 rio_mport_read_config_32(mport, destid, hopcount, offset + (0x20000*table), &result);
51
52 result &= 0xf << (4*(route_destid & 0x7));
53 *route_port = result >> (4*(route_destid & 0x7));
54 if (*route_port > 3)
55 ret = -1;
56
57 return ret;
58}
59
60DECLARE_RIO_ROUTE_OPS(RIO_VID_TUNDRA, RIO_DID_TSI500, tsi500_route_add_entry, tsi500_route_get_entry);
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 8fc891a9d47f..7008d32433bf 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -115,8 +115,7 @@ dasd_alloc_device(void)
115void 115void
116dasd_free_device(struct dasd_device *device) 116dasd_free_device(struct dasd_device *device)
117{ 117{
118 if (device->private) 118 kfree(device->private);
119 kfree(device->private);
120 free_page((unsigned long) device->erp_mem); 119 free_page((unsigned long) device->erp_mem);
121 free_pages((unsigned long) device->ccw_mem, 1); 120 free_pages((unsigned long) device->ccw_mem, 1);
122 kfree(device); 121 kfree(device);
@@ -539,8 +538,7 @@ dasd_kmalloc_request(char *magic, int cplength, int datasize,
539 if (datasize > 0) { 538 if (datasize > 0) {
540 cqr->data = kmalloc(datasize, GFP_ATOMIC | GFP_DMA); 539 cqr->data = kmalloc(datasize, GFP_ATOMIC | GFP_DMA);
541 if (cqr->data == NULL) { 540 if (cqr->data == NULL) {
542 if (cqr->cpaddr != NULL) 541 kfree(cqr->cpaddr);
543 kfree(cqr->cpaddr);
544 kfree(cqr); 542 kfree(cqr);
545 return ERR_PTR(-ENOMEM); 543 return ERR_PTR(-ENOMEM);
546 } 544 }
@@ -615,10 +613,8 @@ dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
615 clear_normalized_cda(ccw); 613 clear_normalized_cda(ccw);
616 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC)); 614 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
617#endif 615#endif
618 if (cqr->cpaddr != NULL) 616 kfree(cqr->cpaddr);
619 kfree(cqr->cpaddr); 617 kfree(cqr->data);
620 if (cqr->data != NULL)
621 kfree(cqr->data);
622 kfree(cqr); 618 kfree(cqr);
623 dasd_put_device(device); 619 dasd_put_device(device);
624} 620}
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index bda896d9d788..caee16a3dc62 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -387,8 +387,7 @@ dasd_add_busid(char *bus_id, int features)
387 new = 0; 387 new = 0;
388 } 388 }
389 spin_unlock(&dasd_devmap_lock); 389 spin_unlock(&dasd_devmap_lock);
390 if (new) 390 kfree(new);
391 kfree(new);
392 return devmap; 391 return devmap;
393} 392}
394 393
diff --git a/drivers/s390/block/dasd_diag.c b/drivers/s390/block/dasd_diag.c
index 7478423b53bb..ab8754e566bc 100644
--- a/drivers/s390/block/dasd_diag.c
+++ b/drivers/s390/block/dasd_diag.c
@@ -6,7 +6,7 @@
6 * Bugreports.to..: <Linux390@de.ibm.com> 6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 7 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
8 * 8 *
9 * $Revision: 1.49 $ 9 * $Revision: 1.51 $
10 */ 10 */
11 11
12#include <linux/config.h> 12#include <linux/config.h>
@@ -67,9 +67,9 @@ static const u8 DASD_DIAG_CMS1[] = { 0xc3, 0xd4, 0xe2, 0xf1 };/* EBCDIC CMS1 */
67static __inline__ int 67static __inline__ int
68dia250(void *iob, int cmd) 68dia250(void *iob, int cmd)
69{ 69{
70 typedef struct { 70 typedef union {
71 char _[max(sizeof (struct dasd_diag_init_io), 71 struct dasd_diag_init_io init_io;
72 sizeof (struct dasd_diag_rw_io))]; 72 struct dasd_diag_rw_io rw_io;
73 } addr_type; 73 } addr_type;
74 int rc; 74 int rc;
75 75
@@ -190,7 +190,7 @@ dasd_start_diag(struct dasd_ccw_req * cqr)
190 private->iob.flags = DASD_DIAG_RWFLAG_ASYNC; 190 private->iob.flags = DASD_DIAG_RWFLAG_ASYNC;
191 private->iob.block_count = dreq->block_count; 191 private->iob.block_count = dreq->block_count;
192 private->iob.interrupt_params = (addr_t) cqr; 192 private->iob.interrupt_params = (addr_t) cqr;
193 private->iob.bio_list = __pa(dreq->bio); 193 private->iob.bio_list = dreq->bio;
194 private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT; 194 private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT;
195 195
196 cqr->startclk = get_clock(); 196 cqr->startclk = get_clock();
@@ -394,47 +394,57 @@ dasd_diag_check_device(struct dasd_device *device)
394 memset(&bio, 0, sizeof (struct dasd_diag_bio)); 394 memset(&bio, 0, sizeof (struct dasd_diag_bio));
395 bio.type = MDSK_READ_REQ; 395 bio.type = MDSK_READ_REQ;
396 bio.block_number = private->pt_block + 1; 396 bio.block_number = private->pt_block + 1;
397 bio.buffer = __pa(label); 397 bio.buffer = label;
398 memset(&private->iob, 0, sizeof (struct dasd_diag_rw_io)); 398 memset(&private->iob, 0, sizeof (struct dasd_diag_rw_io));
399 private->iob.dev_nr = rdc_data->dev_nr; 399 private->iob.dev_nr = rdc_data->dev_nr;
400 private->iob.key = 0; 400 private->iob.key = 0;
401 private->iob.flags = 0; /* do synchronous io */ 401 private->iob.flags = 0; /* do synchronous io */
402 private->iob.block_count = 1; 402 private->iob.block_count = 1;
403 private->iob.interrupt_params = 0; 403 private->iob.interrupt_params = 0;
404 private->iob.bio_list = __pa(&bio); 404 private->iob.bio_list = &bio;
405 private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT; 405 private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT;
406 rc = dia250(&private->iob, RW_BIO); 406 rc = dia250(&private->iob, RW_BIO);
407 if (rc == 0 || rc == 3) 407 if (rc == 3) {
408 break; 408 DEV_MESSAGE(KERN_WARNING, device, "%s",
409 "DIAG call failed");
410 rc = -EOPNOTSUPP;
411 goto out;
412 }
409 mdsk_term_io(device); 413 mdsk_term_io(device);
414 if (rc == 0)
415 break;
410 } 416 }
411 if (rc == 3) { 417 if (bsize > PAGE_SIZE) {
412 DEV_MESSAGE(KERN_WARNING, device, "%s", "DIAG call failed");
413 rc = -EOPNOTSUPP;
414 } else if (rc != 0) {
415 DEV_MESSAGE(KERN_WARNING, device, "device access failed " 418 DEV_MESSAGE(KERN_WARNING, device, "device access failed "
416 "(rc=%d)", rc); 419 "(rc=%d)", rc);
417 rc = -EIO; 420 rc = -EIO;
421 goto out;
422 }
423 /* check for label block */
424 if (memcmp(label->label_id, DASD_DIAG_CMS1,
425 sizeof(DASD_DIAG_CMS1)) == 0) {
426 /* get formatted blocksize from label block */
427 bsize = (unsigned int) label->block_size;
428 device->blocks = (unsigned long) label->block_count;
429 } else
430 device->blocks = end_block;
431 device->bp_block = bsize;
432 device->s2b_shift = 0; /* bits to shift 512 to get a block */
433 for (sb = 512; sb < bsize; sb = sb << 1)
434 device->s2b_shift++;
435 rc = mdsk_init_io(device, device->bp_block, 0, NULL);
436 if (rc) {
437 DEV_MESSAGE(KERN_WARNING, device, "DIAG initialization "
438 "failed (rc=%d)", rc);
439 rc = -EIO;
418 } else { 440 } else {
419 if (memcmp(label->label_id, DASD_DIAG_CMS1,
420 sizeof(DASD_DIAG_CMS1)) == 0) {
421 /* get formatted blocksize from label block */
422 bsize = (unsigned int) label->block_size;
423 device->blocks = (unsigned long) label->block_count;
424 } else
425 device->blocks = end_block;
426 device->bp_block = bsize;
427 device->s2b_shift = 0; /* bits to shift 512 to get a block */
428 for (sb = 512; sb < bsize; sb = sb << 1)
429 device->s2b_shift++;
430
431 DEV_MESSAGE(KERN_INFO, device, 441 DEV_MESSAGE(KERN_INFO, device,
432 "(%ld B/blk): %ldkB", 442 "(%ld B/blk): %ldkB",
433 (unsigned long) device->bp_block, 443 (unsigned long) device->bp_block,
434 (unsigned long) (device->blocks << 444 (unsigned long) (device->blocks <<
435 device->s2b_shift) >> 1); 445 device->s2b_shift) >> 1);
436 rc = 0;
437 } 446 }
447out:
438 free_page((long) label); 448 free_page((long) label);
439 return rc; 449 return rc;
440} 450}
@@ -529,7 +539,7 @@ dasd_diag_build_cp(struct dasd_device * device, struct request *req)
529 memset(dbio, 0, sizeof (struct dasd_diag_bio)); 539 memset(dbio, 0, sizeof (struct dasd_diag_bio));
530 dbio->type = rw_cmd; 540 dbio->type = rw_cmd;
531 dbio->block_number = recid + 1; 541 dbio->block_number = recid + 1;
532 dbio->buffer = __pa(dst); 542 dbio->buffer = dst;
533 dbio++; 543 dbio++;
534 dst += blksize; 544 dst += blksize;
535 recid++; 545 recid++;
diff --git a/drivers/s390/block/dasd_diag.h b/drivers/s390/block/dasd_diag.h
index b26eb28df4bf..df31484d73a7 100644
--- a/drivers/s390/block/dasd_diag.h
+++ b/drivers/s390/block/dasd_diag.h
@@ -6,7 +6,7 @@
6 * Bugreports.to..: <Linux390@de.ibm.com> 6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 7 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
8 * 8 *
9 * $Revision: 1.7 $ 9 * $Revision: 1.8 $
10 */ 10 */
11 11
12#define MDSK_WRITE_REQ 0x01 12#define MDSK_WRITE_REQ 0x01
@@ -78,7 +78,7 @@ struct dasd_diag_bio {
78 u8 spare1[2]; 78 u8 spare1[2];
79 u32 alet; 79 u32 alet;
80 blocknum_t block_number; 80 blocknum_t block_number;
81 u64 buffer; 81 void *buffer;
82} __attribute__ ((packed, aligned(8))); 82} __attribute__ ((packed, aligned(8)));
83 83
84struct dasd_diag_init_io { 84struct dasd_diag_init_io {
@@ -104,7 +104,7 @@ struct dasd_diag_rw_io {
104 u32 alet; 104 u32 alet;
105 u8 spare3[4]; 105 u8 spare3[4];
106 u64 interrupt_params; 106 u64 interrupt_params;
107 u64 bio_list; 107 struct dasd_diag_bio *bio_list;
108 u8 spare4[8]; 108 u8 spare4[8];
109} __attribute__ ((packed, aligned(8))); 109} __attribute__ ((packed, aligned(8)));
110#else /* CONFIG_ARCH_S390X */ 110#else /* CONFIG_ARCH_S390X */
@@ -119,7 +119,7 @@ struct dasd_diag_bio {
119 u16 spare1; 119 u16 spare1;
120 blocknum_t block_number; 120 blocknum_t block_number;
121 u32 alet; 121 u32 alet;
122 u32 buffer; 122 void *buffer;
123} __attribute__ ((packed, aligned(8))); 123} __attribute__ ((packed, aligned(8)));
124 124
125struct dasd_diag_init_io { 125struct dasd_diag_init_io {
@@ -142,7 +142,7 @@ struct dasd_diag_rw_io {
142 u8 spare2[2]; 142 u8 spare2[2];
143 u32 block_count; 143 u32 block_count;
144 u32 alet; 144 u32 alet;
145 u32 bio_list; 145 struct dasd_diag_bio *bio_list;
146 u32 interrupt_params; 146 u32 interrupt_params;
147 u8 spare3[20]; 147 u8 spare3[20];
148} __attribute__ ((packed, aligned(8))); 148} __attribute__ ((packed, aligned(8)));
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index f11a67fda40e..75419cf9d353 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -727,8 +727,7 @@ raw3215_remove (struct ccw_device *cdev)
727 raw = cdev->dev.driver_data; 727 raw = cdev->dev.driver_data;
728 if (raw) { 728 if (raw) {
729 cdev->dev.driver_data = NULL; 729 cdev->dev.driver_data = NULL;
730 if (raw->buffer) 730 kfree(raw->buffer);
731 kfree(raw->buffer);
732 kfree(raw); 731 kfree(raw);
733 } 732 }
734} 733}
diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
index fd43d99b45a3..5bda2340a39d 100644
--- a/drivers/s390/char/keyboard.c
+++ b/drivers/s390/char/keyboard.c
@@ -99,13 +99,11 @@ out_fn_handler:
99 kfree(kbd->fn_handler); 99 kfree(kbd->fn_handler);
100out_func: 100out_func:
101 for (i = 0; i < ARRAY_SIZE(func_table); i++) 101 for (i = 0; i < ARRAY_SIZE(func_table); i++)
102 if (kbd->func_table[i]) 102 kfree(kbd->func_table[i]);
103 kfree(kbd->func_table[i]);
104 kfree(kbd->func_table); 103 kfree(kbd->func_table);
105out_maps: 104out_maps:
106 for (i = 0; i < ARRAY_SIZE(key_maps); i++) 105 for (i = 0; i < ARRAY_SIZE(key_maps); i++)
107 if (kbd->key_maps[i]) 106 kfree(kbd->key_maps[i]);
108 kfree(kbd->key_maps[i]);
109 kfree(kbd->key_maps); 107 kfree(kbd->key_maps);
110out_kbd: 108out_kbd:
111 kfree(kbd); 109 kfree(kbd);
@@ -121,12 +119,10 @@ kbd_free(struct kbd_data *kbd)
121 kfree(kbd->accent_table); 119 kfree(kbd->accent_table);
122 kfree(kbd->fn_handler); 120 kfree(kbd->fn_handler);
123 for (i = 0; i < ARRAY_SIZE(func_table); i++) 121 for (i = 0; i < ARRAY_SIZE(func_table); i++)
124 if (kbd->func_table[i]) 122 kfree(kbd->func_table[i]);
125 kfree(kbd->func_table[i]);
126 kfree(kbd->func_table); 123 kfree(kbd->func_table);
127 for (i = 0; i < ARRAY_SIZE(key_maps); i++) 124 for (i = 0; i < ARRAY_SIZE(key_maps); i++)
128 if (kbd->key_maps[i]) 125 kfree(kbd->key_maps[i]);
129 kfree(kbd->key_maps[i]);
130 kfree(kbd->key_maps); 126 kfree(kbd->key_maps);
131 kfree(kbd); 127 kfree(kbd);
132} 128}
@@ -452,8 +448,7 @@ do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs,
452 return -EFAULT; 448 return -EFAULT;
453 } 449 }
454 p[len] = 0; 450 p[len] = 0;
455 if (kbd->func_table[kb_func]) 451 kfree(kbd->func_table[kb_func]);
456 kfree(kbd->func_table[kb_func]);
457 kbd->func_table[kb_func] = p; 452 kbd->func_table[kb_func] = p;
458 break; 453 break;
459 } 454 }
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index d66946443dfc..f5b7d360fc10 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -183,8 +183,7 @@ raw3270_request_alloc_bootmem(size_t size)
183void 183void
184raw3270_request_free (struct raw3270_request *rq) 184raw3270_request_free (struct raw3270_request *rq)
185{ 185{
186 if (rq->buffer) 186 kfree(rq->buffer);
187 kfree(rq->buffer);
188 kfree(rq); 187 kfree(rq);
189} 188}
190 189
diff --git a/drivers/s390/char/tape_core.c b/drivers/s390/char/tape_core.c
index 6c52e8307dc5..8f486e1a8507 100644
--- a/drivers/s390/char/tape_core.c
+++ b/drivers/s390/char/tape_core.c
@@ -682,8 +682,7 @@ tape_alloc_request(int cplength, int datasize)
682 request->cpdata = kmalloc(datasize, GFP_KERNEL | GFP_DMA); 682 request->cpdata = kmalloc(datasize, GFP_KERNEL | GFP_DMA);
683 if (request->cpdata == NULL) { 683 if (request->cpdata == NULL) {
684 DBF_EXCEPTION(1, "cqra nomem\n"); 684 DBF_EXCEPTION(1, "cqra nomem\n");
685 if (request->cpaddr != NULL) 685 kfree(request->cpaddr);
686 kfree(request->cpaddr);
687 kfree(request); 686 kfree(request);
688 return ERR_PTR(-ENOMEM); 687 return ERR_PTR(-ENOMEM);
689 } 688 }
@@ -706,10 +705,8 @@ tape_free_request (struct tape_request * request)
706 if (request->device != NULL) { 705 if (request->device != NULL) {
707 request->device = tape_put_device(request->device); 706 request->device = tape_put_device(request->device);
708 } 707 }
709 if (request->cpdata != NULL) 708 kfree(request->cpdata);
710 kfree(request->cpdata); 709 kfree(request->cpaddr);
711 if (request->cpaddr != NULL)
712 kfree(request->cpaddr);
713 kfree(request); 710 kfree(request);
714} 711}
715 712
diff --git a/drivers/s390/char/vmcp.c b/drivers/s390/char/vmcp.c
index 8990d8076e7d..19762f3476aa 100644
--- a/drivers/s390/char/vmcp.c
+++ b/drivers/s390/char/vmcp.c
@@ -103,8 +103,10 @@ vmcp_write(struct file *file, const char __user * buff, size_t count,
103 } 103 }
104 cmd[count] = '\0'; 104 cmd[count] = '\0';
105 session = (struct vmcp_session *)file->private_data; 105 session = (struct vmcp_session *)file->private_data;
106 if (down_interruptible(&session->mutex)) 106 if (down_interruptible(&session->mutex)) {
107 kfree(cmd);
107 return -ERESTARTSYS; 108 return -ERESTARTSYS;
109 }
108 if (!session->response) 110 if (!session->response)
109 session->response = (char *)__get_free_pages(GFP_KERNEL 111 session->response = (char *)__get_free_pages(GFP_KERNEL
110 | __GFP_REPEAT | GFP_DMA, 112 | __GFP_REPEAT | GFP_DMA,
diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index dbb3eb0e330b..e7bd7f37f080 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * drivers/s390/cio/ccwgroup.c 2 * drivers/s390/cio/ccwgroup.c
3 * bus driver for ccwgroup 3 * bus driver for ccwgroup
4 * $Revision: 1.29 $ 4 * $Revision: 1.32 $
5 * 5 *
6 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, 6 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
7 * IBM Corporation 7 * IBM Corporation
@@ -274,7 +274,7 @@ ccwgroup_set_online(struct ccwgroup_device *gdev)
274 goto out; 274 goto out;
275 } 275 }
276 gdrv = to_ccwgroupdrv (gdev->dev.driver); 276 gdrv = to_ccwgroupdrv (gdev->dev.driver);
277 if ((ret = gdrv->set_online(gdev))) 277 if ((ret = gdrv->set_online ? gdrv->set_online(gdev) : 0))
278 goto out; 278 goto out;
279 279
280 gdev->state = CCWGROUP_ONLINE; 280 gdev->state = CCWGROUP_ONLINE;
@@ -300,7 +300,7 @@ ccwgroup_set_offline(struct ccwgroup_device *gdev)
300 goto out; 300 goto out;
301 } 301 }
302 gdrv = to_ccwgroupdrv (gdev->dev.driver); 302 gdrv = to_ccwgroupdrv (gdev->dev.driver);
303 if ((ret = gdrv->set_offline(gdev))) 303 if ((ret = gdrv->set_offline ? gdrv->set_offline(gdev) : 0))
304 goto out; 304 goto out;
305 305
306 gdev->state = CCWGROUP_OFFLINE; 306 gdev->state = CCWGROUP_OFFLINE;
diff --git a/drivers/s390/cio/cmf.c b/drivers/s390/cio/cmf.c
index c05b069c2996..b978f7fe8327 100644
--- a/drivers/s390/cio/cmf.c
+++ b/drivers/s390/cio/cmf.c
@@ -642,8 +642,7 @@ static void
642free_cmbe (struct ccw_device *cdev) 642free_cmbe (struct ccw_device *cdev)
643{ 643{
644 spin_lock_irq(cdev->ccwlock); 644 spin_lock_irq(cdev->ccwlock);
645 if (cdev->private->cmb) 645 kfree(cdev->private->cmb);
646 kfree(cdev->private->cmb);
647 cdev->private->cmb = NULL; 646 cdev->private->cmb = NULL;
648 spin_unlock_irq(cdev->ccwlock); 647 spin_unlock_irq(cdev->ccwlock);
649 648
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index ad3fe5aeb663..85a3026e6900 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -550,10 +550,8 @@ ccw_device_stlck(struct ccw_device *cdev)
550 /* Clear irb. */ 550 /* Clear irb. */
551 memset(&cdev->private->irb, 0, sizeof(struct irb)); 551 memset(&cdev->private->irb, 0, sizeof(struct irb));
552out_unlock: 552out_unlock:
553 if (buf) 553 kfree(buf);
554 kfree(buf); 554 kfree(buf2);
555 if (buf2)
556 kfree(buf2);
557 spin_unlock_irqrestore(&sch->lock, flags); 555 spin_unlock_irqrestore(&sch->lock, flags);
558 return ret; 556 return ret;
559} 557}
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c
index 381f339e3200..eb39218b925e 100644
--- a/drivers/s390/cio/qdio.c
+++ b/drivers/s390/cio/qdio.c
@@ -56,7 +56,7 @@
56#include "ioasm.h" 56#include "ioasm.h"
57#include "chsc.h" 57#include "chsc.h"
58 58
59#define VERSION_QDIO_C "$Revision: 1.101 $" 59#define VERSION_QDIO_C "$Revision: 1.108 $"
60 60
61/****************** MODULE PARAMETER VARIABLES ********************/ 61/****************** MODULE PARAMETER VARIABLES ********************/
62MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>"); 62MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>");
@@ -1338,16 +1338,14 @@ qdio_release_irq_memory(struct qdio_irq *irq_ptr)
1338 if (!irq_ptr->input_qs[i]) 1338 if (!irq_ptr->input_qs[i])
1339 goto next; 1339 goto next;
1340 1340
1341 if (irq_ptr->input_qs[i]->slib) 1341 kfree(irq_ptr->input_qs[i]->slib);
1342 kfree(irq_ptr->input_qs[i]->slib);
1343 kfree(irq_ptr->input_qs[i]); 1342 kfree(irq_ptr->input_qs[i]);
1344 1343
1345next: 1344next:
1346 if (!irq_ptr->output_qs[i]) 1345 if (!irq_ptr->output_qs[i])
1347 continue; 1346 continue;
1348 1347
1349 if (irq_ptr->output_qs[i]->slib) 1348 kfree(irq_ptr->output_qs[i]->slib);
1350 kfree(irq_ptr->output_qs[i]->slib);
1351 kfree(irq_ptr->output_qs[i]); 1349 kfree(irq_ptr->output_qs[i]);
1352 1350
1353 } 1351 }
@@ -2873,10 +2871,10 @@ qdio_establish(struct qdio_initialize *init_data)
2873 return result; 2871 return result;
2874 } 2872 }
2875 2873
2876 wait_event_interruptible_timeout(cdev->private->wait_q, 2874 /* Timeout is cared for already by using ccw_device_start_timeout(). */
2875 wait_event_interruptible(cdev->private->wait_q,
2877 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED || 2876 irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED ||
2878 irq_ptr->state == QDIO_IRQ_STATE_ERR, 2877 irq_ptr->state == QDIO_IRQ_STATE_ERR);
2879 QDIO_ESTABLISH_TIMEOUT);
2880 2878
2881 if (irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED) 2879 if (irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED)
2882 result = 0; 2880 result = 0;
@@ -3315,8 +3313,7 @@ qdio_get_qdio_memory(void)
3315static void 3313static void
3316qdio_release_qdio_memory(void) 3314qdio_release_qdio_memory(void)
3317{ 3315{
3318 if (indicators) 3316 kfree(indicators);
3319 kfree(indicators);
3320} 3317}
3321 3318
3322static void 3319static void
diff --git a/drivers/s390/crypto/z90main.c b/drivers/s390/crypto/z90main.c
index 0cb47eca91f3..04c2ef778ec6 100644
--- a/drivers/s390/crypto/z90main.c
+++ b/drivers/s390/crypto/z90main.c
@@ -3051,8 +3051,7 @@ destroy_crypto_device(int index)
3051 if (dev_ptr) { 3051 if (dev_ptr) {
3052 disabledFlag = dev_ptr->disabled; 3052 disabledFlag = dev_ptr->disabled;
3053 t = dev_ptr->dev_type; 3053 t = dev_ptr->dev_type;
3054 if (dev_ptr->dev_resp_p) 3054 kfree(dev_ptr->dev_resp_p);
3055 kfree(dev_ptr->dev_resp_p);
3056 kfree(dev_ptr); 3055 kfree(dev_ptr);
3057 } else { 3056 } else {
3058 disabledFlag = 0; 3057 disabledFlag = 0;
@@ -3080,11 +3079,11 @@ static void
3080destroy_z90crypt(void) 3079destroy_z90crypt(void)
3081{ 3080{
3082 int i; 3081 int i;
3082
3083 for (i = 0; i < z90crypt.max_count; i++) 3083 for (i = 0; i < z90crypt.max_count; i++)
3084 if (z90crypt.device_p[i]) 3084 if (z90crypt.device_p[i])
3085 destroy_crypto_device(i); 3085 destroy_crypto_device(i);
3086 if (z90crypt.hdware_info) 3086 kfree(z90crypt.hdware_info);
3087 kfree((void *)z90crypt.hdware_info);
3088 memset((void *)&z90crypt, 0, sizeof(z90crypt)); 3087 memset((void *)&z90crypt, 0, sizeof(z90crypt));
3089} 3088}
3090 3089
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index 3092473991a7..1a1c3decea72 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -2743,14 +2743,10 @@ probe_error( struct ccwgroup_device *cgdev)
2743#endif 2743#endif
2744 privptr=(struct claw_privbk *)cgdev->dev.driver_data; 2744 privptr=(struct claw_privbk *)cgdev->dev.driver_data;
2745 if (privptr!=NULL) { 2745 if (privptr!=NULL) {
2746 if (privptr->p_env != NULL) { 2746 kfree(privptr->p_env);
2747 kfree(privptr->p_env); 2747 privptr->p_env=NULL;
2748 privptr->p_env=NULL; 2748 kfree(privptr->p_mtc_envelope);
2749 } 2749 privptr->p_mtc_envelope=NULL;
2750 if (privptr->p_mtc_envelope!=NULL) {
2751 kfree(privptr->p_mtc_envelope);
2752 privptr->p_mtc_envelope=NULL;
2753 }
2754 kfree(privptr); 2750 kfree(privptr);
2755 privptr=NULL; 2751 privptr=NULL;
2756 } 2752 }
@@ -4121,22 +4117,14 @@ claw_remove_device(struct ccwgroup_device *cgdev)
4121 if (cgdev->state == CCWGROUP_ONLINE) 4117 if (cgdev->state == CCWGROUP_ONLINE)
4122 claw_shutdown_device(cgdev); 4118 claw_shutdown_device(cgdev);
4123 claw_remove_files(&cgdev->dev); 4119 claw_remove_files(&cgdev->dev);
4124 if (priv->p_mtc_envelope!=NULL) { 4120 kfree(priv->p_mtc_envelope);
4125 kfree(priv->p_mtc_envelope); 4121 priv->p_mtc_envelope=NULL;
4126 priv->p_mtc_envelope=NULL; 4122 kfree(priv->p_env);
4127 } 4123 priv->p_env=NULL;
4128 if (priv->p_env != NULL) { 4124 kfree(priv->channel[0].irb);
4129 kfree(priv->p_env); 4125 priv->channel[0].irb=NULL;
4130 priv->p_env=NULL; 4126 kfree(priv->channel[1].irb);
4131 } 4127 priv->channel[1].irb=NULL;
4132 if (priv->channel[0].irb != NULL) {
4133 kfree(priv->channel[0].irb);
4134 priv->channel[0].irb=NULL;
4135 }
4136 if (priv->channel[1].irb != NULL) {
4137 kfree(priv->channel[1].irb);
4138 priv->channel[1].irb=NULL;
4139 }
4140 kfree(priv); 4128 kfree(priv);
4141 cgdev->dev.driver_data=NULL; 4129 cgdev->dev.driver_data=NULL;
4142 cgdev->cdev[READ]->dev.driver_data = NULL; 4130 cgdev->cdev[READ]->dev.driver_data = NULL;
diff --git a/drivers/s390/net/fsm.c b/drivers/s390/net/fsm.c
index 38f50b7129a2..24029bd9c7d0 100644
--- a/drivers/s390/net/fsm.c
+++ b/drivers/s390/net/fsm.c
@@ -78,8 +78,7 @@ kfree_fsm(fsm_instance *this)
78{ 78{
79 if (this) { 79 if (this) {
80 if (this->f) { 80 if (this->f) {
81 if (this->f->jumpmatrix) 81 kfree(this->f->jumpmatrix);
82 kfree(this->f->jumpmatrix);
83 kfree(this->f); 82 kfree(this->f);
84 } 83 }
85 kfree(this); 84 kfree(this);
diff --git a/drivers/s390/net/iucv.c b/drivers/s390/net/iucv.c
index e08e74e16124..df7647c3c100 100644
--- a/drivers/s390/net/iucv.c
+++ b/drivers/s390/net/iucv.c
@@ -447,14 +447,10 @@ static void
447iucv_exit(void) 447iucv_exit(void)
448{ 448{
449 iucv_retrieve_buffer(); 449 iucv_retrieve_buffer();
450 if (iucv_external_int_buffer) { 450 kfree(iucv_external_int_buffer);
451 kfree(iucv_external_int_buffer); 451 iucv_external_int_buffer = NULL;
452 iucv_external_int_buffer = NULL; 452 kfree(iucv_param_pool);
453 } 453 iucv_param_pool = NULL;
454 if (iucv_param_pool) {
455 kfree(iucv_param_pool);
456 iucv_param_pool = NULL;
457 }
458 s390_root_dev_unregister(iucv_root); 454 s390_root_dev_unregister(iucv_root);
459 bus_unregister(&iucv_bus); 455 bus_unregister(&iucv_bus);
460 printk(KERN_INFO "IUCV lowlevel driver unloaded\n"); 456 printk(KERN_INFO "IUCV lowlevel driver unloaded\n");
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index 46f34ba93ac5..1c8ad2fcad8a 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -145,8 +145,7 @@ lcs_free_channel(struct lcs_channel *channel)
145 145
146 LCS_DBF_TEXT(2, setup, "ichfree"); 146 LCS_DBF_TEXT(2, setup, "ichfree");
147 for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) { 147 for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) {
148 if (channel->iob[cnt].data != NULL) 148 kfree(channel->iob[cnt].data);
149 kfree(channel->iob[cnt].data);
150 channel->iob[cnt].data = NULL; 149 channel->iob[cnt].data = NULL;
151 } 150 }
152} 151}
diff --git a/drivers/s390/net/qeth_eddp.c b/drivers/s390/net/qeth_eddp.c
index f94f1f25eec6..011915d5e243 100644
--- a/drivers/s390/net/qeth_eddp.c
+++ b/drivers/s390/net/qeth_eddp.c
@@ -62,8 +62,7 @@ qeth_eddp_free_context(struct qeth_eddp_context *ctx)
62 for (i = 0; i < ctx->num_pages; ++i) 62 for (i = 0; i < ctx->num_pages; ++i)
63 free_page((unsigned long)ctx->pages[i]); 63 free_page((unsigned long)ctx->pages[i]);
64 kfree(ctx->pages); 64 kfree(ctx->pages);
65 if (ctx->elements != NULL) 65 kfree(ctx->elements);
66 kfree(ctx->elements);
67 kfree(ctx); 66 kfree(ctx);
68} 67}
69 68
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index cab098556b44..c218b5c944a6 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -450,8 +450,7 @@ zfcp_cfdc_dev_ioctl(struct file *file, unsigned int command,
450 kfree(sg_list); 450 kfree(sg_list);
451 } 451 }
452 452
453 if (sense_data != NULL) 453 kfree(sense_data);
454 kfree(sense_data);
455 454
456 return retval; 455 return retval;
457} 456}
diff --git a/drivers/sbus/char/cpwatchdog.c b/drivers/sbus/char/cpwatchdog.c
index c82abeb59d3a..071ae24be892 100644
--- a/drivers/sbus/char/cpwatchdog.c
+++ b/drivers/sbus/char/cpwatchdog.c
@@ -26,6 +26,7 @@
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/ioport.h> 27#include <linux/ioport.h>
28#include <linux/timer.h> 28#include <linux/timer.h>
29#include <linux/smp_lock.h>
29#include <asm/irq.h> 30#include <asm/irq.h>
30#include <asm/ebus.h> 31#include <asm/ebus.h>
31#include <asm/oplib.h> 32#include <asm/oplib.h>
@@ -394,6 +395,28 @@ static int wd_ioctl(struct inode *inode, struct file *file,
394 return(0); 395 return(0);
395} 396}
396 397
398static long wd_compat_ioctl(struct file *file, unsigned int cmd,
399 unsigned long arg)
400{
401 int rval = -ENOIOCTLCMD;
402
403 switch (cmd) {
404 /* solaris ioctls are specific to this driver */
405 case WIOCSTART:
406 case WIOCSTOP:
407 case WIOCGSTAT:
408 lock_kernel();
409 rval = wd_ioctl(file->f_dentry->d_inode, file, cmd, arg);
410 lock_kernel();
411 break;
412 /* everything else is handled by the generic compat layer */
413 default:
414 break;
415 }
416
417 return rval;
418}
419
397static ssize_t wd_write(struct file *file, 420static ssize_t wd_write(struct file *file,
398 const char __user *buf, 421 const char __user *buf,
399 size_t count, 422 size_t count,
@@ -441,6 +464,7 @@ static irqreturn_t wd_interrupt(int irq, void *dev_id, struct pt_regs *regs)
441static struct file_operations wd_fops = { 464static struct file_operations wd_fops = {
442 .owner = THIS_MODULE, 465 .owner = THIS_MODULE,
443 .ioctl = wd_ioctl, 466 .ioctl = wd_ioctl,
467 .compat_ioctl = wd_compat_ioctl,
444 .open = wd_open, 468 .open = wd_open,
445 .write = wd_write, 469 .write = wd_write,
446 .read = wd_read, 470 .read = wd_read,
diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c
index 24ed5893b4f0..39f54213a6d5 100644
--- a/drivers/sbus/char/display7seg.c
+++ b/drivers/sbus/char/display7seg.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/miscdevice.h> 16#include <linux/miscdevice.h>
17#include <linux/ioport.h> /* request_region */ 17#include <linux/ioport.h> /* request_region */
18#include <linux/smp_lock.h>
18#include <asm/atomic.h> 19#include <asm/atomic.h>
19#include <asm/ebus.h> /* EBus device */ 20#include <asm/ebus.h> /* EBus device */
20#include <asm/oplib.h> /* OpenProm Library */ 21#include <asm/oplib.h> /* OpenProm Library */
@@ -114,22 +115,25 @@ static int d7s_release(struct inode *inode, struct file *f)
114 return 0; 115 return 0;
115} 116}
116 117
117static int d7s_ioctl(struct inode *inode, struct file *f, 118static long d7s_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
118 unsigned int cmd, unsigned long arg)
119{ 119{
120 __u8 regs = readb(d7s_regs); 120 __u8 regs = readb(d7s_regs);
121 __u8 ireg = 0; 121 __u8 ireg = 0;
122 int error = 0
122 123
123 if (D7S_MINOR != iminor(inode)) 124 if (D7S_MINOR != iminor(file->f_dentry->d_inode))
124 return -ENODEV; 125 return -ENODEV;
125 126
127 lock_kernel();
126 switch (cmd) { 128 switch (cmd) {
127 case D7SIOCWR: 129 case D7SIOCWR:
128 /* assign device register values 130 /* assign device register values
129 * we mask-out D7S_FLIP if in sol_compat mode 131 * we mask-out D7S_FLIP if in sol_compat mode
130 */ 132 */
131 if (get_user(ireg, (int __user *) arg)) 133 if (get_user(ireg, (int __user *) arg)) {
132 return -EFAULT; 134 error = -EFAULT;
135 break;
136 }
133 if (0 != sol_compat) { 137 if (0 != sol_compat) {
134 (regs & D7S_FLIP) ? 138 (regs & D7S_FLIP) ?
135 (ireg |= D7S_FLIP) : (ireg &= ~D7S_FLIP); 139 (ireg |= D7S_FLIP) : (ireg &= ~D7S_FLIP);
@@ -144,8 +148,10 @@ static int d7s_ioctl(struct inode *inode, struct file *f,
144 * This driver will not misinform you about the state 148 * This driver will not misinform you about the state
145 * of your hardware while in sol_compat mode 149 * of your hardware while in sol_compat mode
146 */ 150 */
147 if (put_user(regs, (int __user *) arg)) 151 if (put_user(regs, (int __user *) arg)) {
148 return -EFAULT; 152 error = -EFAULT;
153 break;
154 }
149 break; 155 break;
150 156
151 case D7SIOCTM: 157 case D7SIOCTM:
@@ -155,15 +161,17 @@ static int d7s_ioctl(struct inode *inode, struct file *f,
155 writeb(regs, d7s_regs); 161 writeb(regs, d7s_regs);
156 break; 162 break;
157 }; 163 };
164 lock_kernel();
158 165
159 return 0; 166 return error;
160} 167}
161 168
162static struct file_operations d7s_fops = { 169static struct file_operations d7s_fops = {
163 .owner = THIS_MODULE, 170 .owner = THIS_MODULE,
164 .ioctl = d7s_ioctl, 171 .unlocked_ioctl = d7s_ioctl,
165 .open = d7s_open, 172 .compat_ioctl = d7s_ioctl,
166 .release = d7s_release, 173 .open = d7s_open,
174 .release = d7s_release,
167}; 175};
168 176
169static struct miscdevice d7s_miscdev = { D7S_MINOR, D7S_DEVNAME, &d7s_fops }; 177static struct miscdevice d7s_miscdev = { D7S_MINOR, D7S_DEVNAME, &d7s_fops };
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index b0cc3c2588fd..19e8eddf887a 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -654,9 +654,8 @@ envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
654/* Function Description: Command what to read. Mapped to user ioctl(). 654/* Function Description: Command what to read. Mapped to user ioctl().
655 * Return: Gives 0 for implemented commands, -EINVAL otherwise. 655 * Return: Gives 0 for implemented commands, -EINVAL otherwise.
656 */ 656 */
657static int 657static long
658envctrl_ioctl(struct inode *inode, struct file *file, 658envctrl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
659 unsigned int cmd, unsigned long arg)
660{ 659{
661 char __user *infobuf; 660 char __user *infobuf;
662 661
@@ -715,11 +714,14 @@ envctrl_release(struct inode *inode, struct file *file)
715} 714}
716 715
717static struct file_operations envctrl_fops = { 716static struct file_operations envctrl_fops = {
718 .owner = THIS_MODULE, 717 .owner = THIS_MODULE,
719 .read = envctrl_read, 718 .read = envctrl_read,
720 .ioctl = envctrl_ioctl, 719 .unlocked_ioctl = envctrl_ioctl,
721 .open = envctrl_open, 720#ifdef CONFIG_COMPAT
722 .release = envctrl_release, 721 .compat_ioctl = envctrl_ioctl,
722#endif
723 .open = envctrl_open,
724 .release = envctrl_release,
723}; 725};
724 726
725static struct miscdevice envctrl_dev = { 727static struct miscdevice envctrl_dev = {
@@ -1125,10 +1127,9 @@ out_deregister:
1125 misc_deregister(&envctrl_dev); 1127 misc_deregister(&envctrl_dev);
1126out_iounmap: 1128out_iounmap:
1127 iounmap(i2c); 1129 iounmap(i2c);
1128 for (i = 0; i < ENVCTRL_MAX_CPU * 2; i++) { 1130 for (i = 0; i < ENVCTRL_MAX_CPU * 2; i++)
1129 if (i2c_childlist[i].tables) 1131 kfree(i2c_childlist[i].tables);
1130 kfree(i2c_childlist[i].tables); 1132
1131 }
1132 return err; 1133 return err;
1133} 1134}
1134 1135
@@ -1141,10 +1142,8 @@ static void __exit envctrl_cleanup(void)
1141 iounmap(i2c); 1142 iounmap(i2c);
1142 misc_deregister(&envctrl_dev); 1143 misc_deregister(&envctrl_dev);
1143 1144
1144 for (i = 0; i < ENVCTRL_MAX_CPU * 2; i++) { 1145 for (i = 0; i < ENVCTRL_MAX_CPU * 2; i++)
1145 if (i2c_childlist[i].tables) 1146 kfree(i2c_childlist[i].tables);
1146 kfree(i2c_childlist[i].tables);
1147 }
1148} 1147}
1149 1148
1150module_init(envctrl_init); 1149module_init(envctrl_init);
diff --git a/drivers/sbus/char/openprom.c b/drivers/sbus/char/openprom.c
index 58ed33749571..5028ac214326 100644
--- a/drivers/sbus/char/openprom.c
+++ b/drivers/sbus/char/openprom.c
@@ -39,6 +39,7 @@
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/string.h> 40#include <linux/string.h>
41#include <linux/miscdevice.h> 41#include <linux/miscdevice.h>
42#include <linux/smp_lock.h>
42#include <linux/init.h> 43#include <linux/init.h>
43#include <linux/fs.h> 44#include <linux/fs.h>
44#include <asm/oplib.h> 45#include <asm/oplib.h>
@@ -565,6 +566,38 @@ static int openprom_ioctl(struct inode * inode, struct file * file,
565 } 566 }
566} 567}
567 568
569static long openprom_compat_ioctl(struct file *file, unsigned int cmd,
570 unsigned long arg)
571{
572 long rval = -ENOTTY;
573
574 /*
575 * SunOS/Solaris only, the NetBSD one's have embedded pointers in
576 * the arg which we'd need to clean up...
577 */
578 switch (cmd) {
579 case OPROMGETOPT:
580 case OPROMSETOPT:
581 case OPROMNXTOPT:
582 case OPROMSETOPT2:
583 case OPROMNEXT:
584 case OPROMCHILD:
585 case OPROMGETPROP:
586 case OPROMNXTPROP:
587 case OPROMU2P:
588 case OPROMGETCONS:
589 case OPROMGETFBNAME:
590 case OPROMGETBOOTARGS:
591 case OPROMSETCUR:
592 case OPROMPCI2NODE:
593 case OPROMPATH2NODE:
594 lock_kernel();
595 rval = openprom_ioctl(file->f_dentry->d_inode, file, cmd, arg);
596 lock_kernel();
597 break;
598 }
599}
600
568static int openprom_open(struct inode * inode, struct file * file) 601static int openprom_open(struct inode * inode, struct file * file)
569{ 602{
570 DATA *data; 603 DATA *data;
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index d06ee65d668d..3ff74f472249 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -1017,8 +1017,7 @@ static void twa_free_device_extension(TW_Device_Extension *tw_dev)
1017 tw_dev->generic_buffer_virt[0], 1017 tw_dev->generic_buffer_virt[0],
1018 tw_dev->generic_buffer_phys[0]); 1018 tw_dev->generic_buffer_phys[0]);
1019 1019
1020 if (tw_dev->event_queue[0]) 1020 kfree(tw_dev->event_queue[0]);
1021 kfree(tw_dev->event_queue[0]);
1022} /* End twa_free_device_extension() */ 1021} /* End twa_free_device_extension() */
1023 1022
1024/* This function will free a request id */ 1023/* This function will free a request id */
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index cc9ecb35b412..cba9655d0f14 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -606,10 +606,7 @@ static int __init NCR5380_probe_irq(struct Scsi_Host *instance, int possible)
606 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA | ICR_ASSERT_SEL); 606 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA | ICR_ASSERT_SEL);
607 607
608 while (probe_irq == SCSI_IRQ_NONE && time_before(jiffies, timeout)) 608 while (probe_irq == SCSI_IRQ_NONE && time_before(jiffies, timeout))
609 { 609 schedule_timeout_uninterruptible(1);
610 set_current_state(TASK_UNINTERRUPTIBLE);
611 schedule_timeout(1);
612 }
613 610
614 NCR5380_write(SELECT_ENABLE_REG, 0); 611 NCR5380_write(SELECT_ENABLE_REG, 0);
615 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 612 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index ee9067255930..723c0cea7c04 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -1164,7 +1164,7 @@ int aac_command_thread(struct aac_dev * dev)
1164 kfree(hw_fib_pool); 1164 kfree(hw_fib_pool);
1165 hw_fib_pool = NULL; 1165 hw_fib_pool = NULL;
1166 } 1166 }
1167 } else if (hw_fib_pool) { 1167 } else {
1168 kfree(hw_fib_pool); 1168 kfree(hw_fib_pool);
1169 hw_fib_pool = NULL; 1169 hw_fib_pool = NULL;
1170 } 1170 }
@@ -1247,17 +1247,13 @@ int aac_command_thread(struct aac_dev * dev)
1247 hw_fib_p = hw_fib_pool; 1247 hw_fib_p = hw_fib_pool;
1248 fib_p = fib_pool; 1248 fib_p = fib_pool;
1249 while (hw_fib_p < &hw_fib_pool[num]) { 1249 while (hw_fib_p < &hw_fib_pool[num]) {
1250 if (*hw_fib_p) 1250 kfree(*hw_fib_p);
1251 kfree(*hw_fib_p); 1251 kfree(*fib_p);
1252 if (*fib_p)
1253 kfree(*fib_p);
1254 ++fib_p; 1252 ++fib_p;
1255 ++hw_fib_p; 1253 ++hw_fib_p;
1256 } 1254 }
1257 if (hw_fib_pool) 1255 kfree(hw_fib_pool);
1258 kfree(hw_fib_pool); 1256 kfree(fib_pool);
1259 if (fib_pool)
1260 kfree(fib_pool);
1261 } 1257 }
1262 kfree(fib); 1258 kfree(fib);
1263 spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags); 1259 spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
diff --git a/drivers/scsi/aacraid/rkt.c b/drivers/scsi/aacraid/rkt.c
index fc4c73c2a6a9..e9b775d6bec9 100644
--- a/drivers/scsi/aacraid/rkt.c
+++ b/drivers/scsi/aacraid/rkt.c
@@ -183,8 +183,7 @@ static int rkt_sync_cmd(struct aac_dev *dev, u32 command,
183 /* 183 /*
184 * Yield the processor in case we are slow 184 * Yield the processor in case we are slow
185 */ 185 */
186 set_current_state(TASK_UNINTERRUPTIBLE); 186 schedule_timeout_uninterruptible(1);
187 schedule_timeout(1);
188 } 187 }
189 if (ok != 1) { 188 if (ok != 1) {
190 /* 189 /*
@@ -452,8 +451,7 @@ int aac_rkt_init(struct aac_dev *dev)
452 dev->name, instance, status); 451 dev->name, instance, status);
453 goto error_iounmap; 452 goto error_iounmap;
454 } 453 }
455 set_current_state(TASK_UNINTERRUPTIBLE); 454 schedule_timeout_uninterruptible(1);
456 schedule_timeout(1);
457 } 455 }
458 if (request_irq(dev->scsi_host_ptr->irq, aac_rkt_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev)<0) 456 if (request_irq(dev->scsi_host_ptr->irq, aac_rkt_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev)<0)
459 { 457 {
diff --git a/drivers/scsi/aacraid/rx.c b/drivers/scsi/aacraid/rx.c
index da99046e5393..6998bc877dd6 100644
--- a/drivers/scsi/aacraid/rx.c
+++ b/drivers/scsi/aacraid/rx.c
@@ -183,8 +183,7 @@ static int rx_sync_cmd(struct aac_dev *dev, u32 command,
183 /* 183 /*
184 * Yield the processor in case we are slow 184 * Yield the processor in case we are slow
185 */ 185 */
186 set_current_state(TASK_UNINTERRUPTIBLE); 186 schedule_timeout_uninterruptible(1);
187 schedule_timeout(1);
188 } 187 }
189 if (ok != 1) { 188 if (ok != 1) {
190 /* 189 /*
@@ -452,8 +451,7 @@ int aac_rx_init(struct aac_dev *dev)
452 dev->name, instance, status); 451 dev->name, instance, status);
453 goto error_iounmap; 452 goto error_iounmap;
454 } 453 }
455 set_current_state(TASK_UNINTERRUPTIBLE); 454 schedule_timeout_uninterruptible(1);
456 schedule_timeout(1);
457 } 455 }
458 if (request_irq(dev->scsi_host_ptr->irq, aac_rx_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev)<0) 456 if (request_irq(dev->scsi_host_ptr->irq, aac_rx_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev)<0)
459 { 457 {
diff --git a/drivers/scsi/aacraid/sa.c b/drivers/scsi/aacraid/sa.c
index 8b9596209164..466f05cfbf0c 100644
--- a/drivers/scsi/aacraid/sa.c
+++ b/drivers/scsi/aacraid/sa.c
@@ -189,8 +189,7 @@ static int sa_sync_cmd(struct aac_dev *dev, u32 command,
189 ok = 1; 189 ok = 1;
190 break; 190 break;
191 } 191 }
192 set_current_state(TASK_UNINTERRUPTIBLE); 192 schedule_timeout_uninterruptible(1);
193 schedule_timeout(1);
194 } 193 }
195 194
196 if (ok != 1) 195 if (ok != 1)
@@ -325,8 +324,7 @@ int aac_sa_init(struct aac_dev *dev)
325 name, instance, status); 324 name, instance, status);
326 goto error_iounmap; 325 goto error_iounmap;
327 } 326 }
328 set_current_state(TASK_UNINTERRUPTIBLE); 327 schedule_timeout_uninterruptible(1);
329 schedule_timeout(1);
330 } 328 }
331 329
332 if (request_irq(dev->scsi_host_ptr->irq, aac_sa_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev ) < 0) { 330 if (request_irq(dev->scsi_host_ptr->irq, aac_sa_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev ) < 0) {
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 37ec5411e325..f4cfb8f29620 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -5402,10 +5402,8 @@ advansys_detect(struct scsi_host_template *tpnt)
5402 release_region(shp->io_port, boardp->asc_n_io_port); 5402 release_region(shp->io_port, boardp->asc_n_io_port);
5403 if (ASC_WIDE_BOARD(boardp)) { 5403 if (ASC_WIDE_BOARD(boardp)) {
5404 iounmap(boardp->ioremap_addr); 5404 iounmap(boardp->ioremap_addr);
5405 if (boardp->orig_carrp) { 5405 kfree(boardp->orig_carrp);
5406 kfree(boardp->orig_carrp); 5406 boardp->orig_carrp = NULL;
5407 boardp->orig_carrp = NULL;
5408 }
5409 if (boardp->orig_reqp) { 5407 if (boardp->orig_reqp) {
5410 kfree(boardp->orig_reqp); 5408 kfree(boardp->orig_reqp);
5411 boardp->orig_reqp = boardp->adv_reqp = NULL; 5409 boardp->orig_reqp = boardp->adv_reqp = NULL;
@@ -5457,10 +5455,8 @@ advansys_release(struct Scsi_Host *shp)
5457 adv_sgblk_t *sgp = NULL; 5455 adv_sgblk_t *sgp = NULL;
5458 5456
5459 iounmap(boardp->ioremap_addr); 5457 iounmap(boardp->ioremap_addr);
5460 if (boardp->orig_carrp) { 5458 kfree(boardp->orig_carrp);
5461 kfree(boardp->orig_carrp); 5459 boardp->orig_carrp = NULL;
5462 boardp->orig_carrp = NULL;
5463 }
5464 if (boardp->orig_reqp) { 5460 if (boardp->orig_reqp) {
5465 kfree(boardp->orig_reqp); 5461 kfree(boardp->orig_reqp);
5466 boardp->orig_reqp = boardp->adv_reqp = NULL; 5462 boardp->orig_reqp = boardp->adv_reqp = NULL;
diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c
index adda750412f2..1b1adfb384cb 100644
--- a/drivers/scsi/aha1542.c
+++ b/drivers/scsi/aha1542.c
@@ -543,10 +543,8 @@ static void aha1542_intr_handle(struct Scsi_Host *shost, void *dev_id, struct pt
543 return; 543 return;
544 } 544 }
545 my_done = SCtmp->scsi_done; 545 my_done = SCtmp->scsi_done;
546 if (SCtmp->host_scribble) { 546 kfree(SCtmp->host_scribble);
547 kfree(SCtmp->host_scribble); 547 SCtmp->host_scribble = NULL;
548 SCtmp->host_scribble = NULL;
549 }
550 /* Fetch the sense data, and tuck it away, in the required slot. The 548 /* Fetch the sense data, and tuck it away, in the required slot. The
551 Adaptec automatically fetches it, and there is no guarantee that 549 Adaptec automatically fetches it, and there is no guarantee that
552 we will still have it in the cdb when we come back */ 550 we will still have it in the cdb when we come back */
@@ -1432,10 +1430,8 @@ static int aha1542_dev_reset(Scsi_Cmnd * SCpnt)
1432 HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target) { 1430 HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target) {
1433 Scsi_Cmnd *SCtmp; 1431 Scsi_Cmnd *SCtmp;
1434 SCtmp = HOSTDATA(SCpnt->host)->SCint[i]; 1432 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1435 if (SCtmp->host_scribble) { 1433 kfree(SCtmp->host_scribble);
1436 kfree(SCtmp->host_scribble); 1434 SCtmp->host_scribble = NULL;
1437 SCtmp->host_scribble = NULL;
1438 }
1439 HOSTDATA(SCpnt->host)->SCint[i] = NULL; 1435 HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1440 HOSTDATA(SCpnt->host)->mb[i].status = 0; 1436 HOSTDATA(SCpnt->host)->mb[i].status = 0;
1441 } 1437 }
@@ -1495,10 +1491,8 @@ static int aha1542_bus_reset(Scsi_Cmnd * SCpnt)
1495 */ 1491 */
1496 continue; 1492 continue;
1497 } 1493 }
1498 if (SCtmp->host_scribble) { 1494 kfree(SCtmp->host_scribble);
1499 kfree(SCtmp->host_scribble); 1495 SCtmp->host_scribble = NULL;
1500 SCtmp->host_scribble = NULL;
1501 }
1502 HOSTDATA(SCpnt->device->host)->SCint[i] = NULL; 1496 HOSTDATA(SCpnt->device->host)->SCint[i] = NULL;
1503 HOSTDATA(SCpnt->device->host)->mb[i].status = 0; 1497 HOSTDATA(SCpnt->device->host)->mb[i].status = 0;
1504 } 1498 }
@@ -1565,10 +1559,8 @@ static int aha1542_host_reset(Scsi_Cmnd * SCpnt)
1565 */ 1559 */
1566 continue; 1560 continue;
1567 } 1561 }
1568 if (SCtmp->host_scribble) { 1562 kfree(SCtmp->host_scribble);
1569 kfree(SCtmp->host_scribble); 1563 SCtmp->host_scribble = NULL;
1570 SCtmp->host_scribble = NULL;
1571 }
1572 HOSTDATA(SCpnt->device->host)->SCint[i] = NULL; 1564 HOSTDATA(SCpnt->device->host)->SCint[i] = NULL;
1573 HOSTDATA(SCpnt->device->host)->mb[i].status = 0; 1565 HOSTDATA(SCpnt->device->host)->mb[i].status = 0;
1574 } 1566 }
@@ -1711,10 +1703,8 @@ static int aha1542_old_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
1711 Scsi_Cmnd *SCtmp; 1703 Scsi_Cmnd *SCtmp;
1712 SCtmp = HOSTDATA(SCpnt->host)->SCint[i]; 1704 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1713 SCtmp->result = DID_RESET << 16; 1705 SCtmp->result = DID_RESET << 16;
1714 if (SCtmp->host_scribble) { 1706 kfree(SCtmp->host_scribble);
1715 kfree(SCtmp->host_scribble); 1707 SCtmp->host_scribble = NULL;
1716 SCtmp->host_scribble = NULL;
1717 }
1718 printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target); 1708 printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target);
1719 SCtmp->scsi_done(SCpnt); 1709 SCtmp->scsi_done(SCpnt);
1720 1710
@@ -1757,10 +1747,8 @@ fail:
1757 Scsi_Cmnd *SCtmp; 1747 Scsi_Cmnd *SCtmp;
1758 SCtmp = HOSTDATA(SCpnt->host)->SCint[i]; 1748 SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1759 SCtmp->result = DID_RESET << 16; 1749 SCtmp->result = DID_RESET << 16;
1760 if (SCtmp->host_scribble) { 1750 kfree(SCtmp->host_scribble);
1761 kfree(SCtmp->host_scribble); 1751 SCtmp->host_scribble = NULL;
1762 SCtmp->host_scribble = NULL;
1763 }
1764 printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target); 1752 printk(KERN_WARNING "Sending DID_RESET for target %d\n", SCpnt->target);
1765 SCtmp->scsi_done(SCpnt); 1753 SCtmp->scsi_done(SCpnt);
1766 1754
diff --git a/drivers/scsi/aic7xxx_old.c b/drivers/scsi/aic7xxx_old.c
index 52b72d7794f5..880e2d9ffe9b 100644
--- a/drivers/scsi/aic7xxx_old.c
+++ b/drivers/scsi/aic7xxx_old.c
@@ -8492,8 +8492,7 @@ aic7xxx_free(struct aic7xxx_host *p)
8492 - scb_dma->dma_offset), 8492 - scb_dma->dma_offset),
8493 scb_dma->dma_address); 8493 scb_dma->dma_address);
8494 } 8494 }
8495 if (p->scb_data->scb_array[i]->kmalloc_ptr != NULL) 8495 kfree(p->scb_data->scb_array[i]->kmalloc_ptr);
8496 kfree(p->scb_data->scb_array[i]->kmalloc_ptr);
8497 p->scb_data->scb_array[i] = NULL; 8496 p->scb_data->scb_array[i] = NULL;
8498 } 8497 }
8499 8498
diff --git a/drivers/scsi/arm/queue.c b/drivers/scsi/arm/queue.c
index e6d159270d29..b10750bb5c09 100644
--- a/drivers/scsi/arm/queue.c
+++ b/drivers/scsi/arm/queue.c
@@ -91,8 +91,7 @@ void queue_free (Queue_t *queue)
91{ 91{
92 if (!list_empty(&queue->head)) 92 if (!list_empty(&queue->head))
93 printk(KERN_WARNING "freeing non-empty queue %p\n", queue); 93 printk(KERN_WARNING "freeing non-empty queue %p\n", queue);
94 if (queue->alloc) 94 kfree(queue->alloc);
95 kfree(queue->alloc);
96} 95}
97 96
98 97
diff --git a/drivers/scsi/atari_dma_emul.c b/drivers/scsi/atari_dma_emul.c
index 7026045527fd..8d5d2a5da961 100644
--- a/drivers/scsi/atari_dma_emul.c
+++ b/drivers/scsi/atari_dma_emul.c
@@ -19,6 +19,8 @@
19 * this code. 19 * this code.
20 */ 20 */
21 21
22#include <linux/compiler.h>
23#include <asm/thread_info.h>
22#include <asm/uaccess.h> 24#include <asm/uaccess.h>
23 25
24#define hades_dma_ctrl (*(unsigned char *) 0xffff8717) 26#define hades_dma_ctrl (*(unsigned char *) 0xffff8717)
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index c44af5795b10..c8a32cf47d73 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -4270,8 +4270,7 @@ static void adapter_sg_tables_free(struct AdapterCtlBlk *acb)
4270 const unsigned srbs_per_page = PAGE_SIZE/SEGMENTX_LEN; 4270 const unsigned srbs_per_page = PAGE_SIZE/SEGMENTX_LEN;
4271 4271
4272 for (i = 0; i < DC395x_MAX_SRB_CNT; i += srbs_per_page) 4272 for (i = 0; i < DC395x_MAX_SRB_CNT; i += srbs_per_page)
4273 if (acb->srb_array[i].segment_x) 4273 kfree(acb->srb_array[i].segment_x);
4274 kfree(acb->srb_array[i].segment_x);
4275} 4274}
4276 4275
4277 4276
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 7235f94f1191..c28e3aea1c3c 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -1037,18 +1037,10 @@ static void adpt_i2o_delete_hba(adpt_hba* pHba)
1037 if(pHba->msg_addr_virt != pHba->base_addr_virt){ 1037 if(pHba->msg_addr_virt != pHba->base_addr_virt){
1038 iounmap(pHba->msg_addr_virt); 1038 iounmap(pHba->msg_addr_virt);
1039 } 1039 }
1040 if(pHba->hrt) { 1040 kfree(pHba->hrt);
1041 kfree(pHba->hrt); 1041 kfree(pHba->lct);
1042 } 1042 kfree(pHba->status_block);
1043 if(pHba->lct){ 1043 kfree(pHba->reply_pool);
1044 kfree(pHba->lct);
1045 }
1046 if(pHba->status_block) {
1047 kfree(pHba->status_block);
1048 }
1049 if(pHba->reply_pool){
1050 kfree(pHba->reply_pool);
1051 }
1052 1044
1053 for(d = pHba->devices; d ; d = next){ 1045 for(d = pHba->devices; d ; d = next){
1054 next = d->next; 1046 next = d->next;
@@ -1218,8 +1210,7 @@ static s32 adpt_i2o_post_this(adpt_hba* pHba, u32* data, int len)
1218 printk(KERN_WARNING"dpti%d: Timeout waiting for message frame!\n", pHba->unit); 1210 printk(KERN_WARNING"dpti%d: Timeout waiting for message frame!\n", pHba->unit);
1219 return -ETIMEDOUT; 1211 return -ETIMEDOUT;
1220 } 1212 }
1221 set_current_state(TASK_UNINTERRUPTIBLE); 1213 schedule_timeout_uninterruptible(1);
1222 schedule_timeout(1);
1223 } while(m == EMPTY_QUEUE); 1214 } while(m == EMPTY_QUEUE);
1224 1215
1225 msg = pHba->msg_addr_virt + m; 1216 msg = pHba->msg_addr_virt + m;
@@ -1294,8 +1285,7 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1294 printk(KERN_WARNING"Timeout waiting for message!\n"); 1285 printk(KERN_WARNING"Timeout waiting for message!\n");
1295 return -ETIMEDOUT; 1286 return -ETIMEDOUT;
1296 } 1287 }
1297 set_current_state(TASK_UNINTERRUPTIBLE); 1288 schedule_timeout_uninterruptible(1);
1298 schedule_timeout(1);
1299 } while (m == EMPTY_QUEUE); 1289 } while (m == EMPTY_QUEUE);
1300 1290
1301 status = (u8*)kmalloc(4, GFP_KERNEL|ADDR32); 1291 status = (u8*)kmalloc(4, GFP_KERNEL|ADDR32);
@@ -1327,8 +1317,7 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1327 return -ETIMEDOUT; 1317 return -ETIMEDOUT;
1328 } 1318 }
1329 rmb(); 1319 rmb();
1330 set_current_state(TASK_UNINTERRUPTIBLE); 1320 schedule_timeout_uninterruptible(1);
1331 schedule_timeout(1);
1332 } 1321 }
1333 1322
1334 if(*status == 0x01 /*I2O_EXEC_IOP_RESET_IN_PROGRESS*/) { 1323 if(*status == 0x01 /*I2O_EXEC_IOP_RESET_IN_PROGRESS*/) {
@@ -1345,8 +1334,7 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1345 printk(KERN_ERR "%s:Timeout waiting for IOP Reset.\n",pHba->name); 1334 printk(KERN_ERR "%s:Timeout waiting for IOP Reset.\n",pHba->name);
1346 return -ETIMEDOUT; 1335 return -ETIMEDOUT;
1347 } 1336 }
1348 set_current_state(TASK_UNINTERRUPTIBLE); 1337 schedule_timeout_uninterruptible(1);
1349 schedule_timeout(1);
1350 } while (m == EMPTY_QUEUE); 1338 } while (m == EMPTY_QUEUE);
1351 // Flush the offset 1339 // Flush the offset
1352 adpt_send_nop(pHba, m); 1340 adpt_send_nop(pHba, m);
@@ -1917,11 +1905,8 @@ static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd,
1917 return -ENXIO; 1905 return -ENXIO;
1918 } 1906 }
1919 1907
1920 while((volatile u32) pHba->state & DPTI_STATE_RESET ) { 1908 while((volatile u32) pHba->state & DPTI_STATE_RESET )
1921 set_task_state(current,TASK_UNINTERRUPTIBLE); 1909 schedule_timeout_uninterruptible(2);
1922 schedule_timeout(2);
1923
1924 }
1925 1910
1926 switch (cmd) { 1911 switch (cmd) {
1927 // TODO: handle 3 cases 1912 // TODO: handle 3 cases
@@ -2635,8 +2620,7 @@ static s32 adpt_send_nop(adpt_hba*pHba,u32 m)
2635 printk(KERN_ERR "%s: Timeout waiting for message frame!\n",pHba->name); 2620 printk(KERN_ERR "%s: Timeout waiting for message frame!\n",pHba->name);
2636 return 2; 2621 return 2;
2637 } 2622 }
2638 set_current_state(TASK_UNINTERRUPTIBLE); 2623 schedule_timeout_uninterruptible(1);
2639 schedule_timeout(1);
2640 } 2624 }
2641 msg = (u32 __iomem *)(pHba->msg_addr_virt + m); 2625 msg = (u32 __iomem *)(pHba->msg_addr_virt + m);
2642 writel( THREE_WORD_MSG_SIZE | SGL_OFFSET_0,&msg[0]); 2626 writel( THREE_WORD_MSG_SIZE | SGL_OFFSET_0,&msg[0]);
@@ -2670,8 +2654,7 @@ static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
2670 printk(KERN_WARNING"%s: Timeout waiting for message frame\n",pHba->name); 2654 printk(KERN_WARNING"%s: Timeout waiting for message frame\n",pHba->name);
2671 return -ETIMEDOUT; 2655 return -ETIMEDOUT;
2672 } 2656 }
2673 set_current_state(TASK_UNINTERRUPTIBLE); 2657 schedule_timeout_uninterruptible(1);
2674 schedule_timeout(1);
2675 } while(m == EMPTY_QUEUE); 2658 } while(m == EMPTY_QUEUE);
2676 2659
2677 msg=(u32 __iomem *)(pHba->msg_addr_virt+m); 2660 msg=(u32 __iomem *)(pHba->msg_addr_virt+m);
@@ -2709,21 +2692,18 @@ static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
2709 printk(KERN_WARNING"%s: Timeout Initializing\n",pHba->name); 2692 printk(KERN_WARNING"%s: Timeout Initializing\n",pHba->name);
2710 return -ETIMEDOUT; 2693 return -ETIMEDOUT;
2711 } 2694 }
2712 set_current_state(TASK_UNINTERRUPTIBLE); 2695 schedule_timeout_uninterruptible(1);
2713 schedule_timeout(1);
2714 } while (1); 2696 } while (1);
2715 2697
2716 // If the command was successful, fill the fifo with our reply 2698 // If the command was successful, fill the fifo with our reply
2717 // message packets 2699 // message packets
2718 if(*status != 0x04 /*I2O_EXEC_OUTBOUND_INIT_COMPLETE*/) { 2700 if(*status != 0x04 /*I2O_EXEC_OUTBOUND_INIT_COMPLETE*/) {
2719 kfree((void*)status); 2701 kfree(status);
2720 return -2; 2702 return -2;
2721 } 2703 }
2722 kfree((void*)status); 2704 kfree(status);
2723 2705
2724 if(pHba->reply_pool != NULL){ 2706 kfree(pHba->reply_pool);
2725 kfree(pHba->reply_pool);
2726 }
2727 2707
2728 pHba->reply_pool = (u32*)kmalloc(pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4, GFP_KERNEL|ADDR32); 2708 pHba->reply_pool = (u32*)kmalloc(pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4, GFP_KERNEL|ADDR32);
2729 if(!pHba->reply_pool){ 2709 if(!pHba->reply_pool){
@@ -2788,8 +2768,7 @@ static s32 adpt_i2o_status_get(adpt_hba* pHba)
2788 pHba->name); 2768 pHba->name);
2789 return -ETIMEDOUT; 2769 return -ETIMEDOUT;
2790 } 2770 }
2791 set_current_state(TASK_UNINTERRUPTIBLE); 2771 schedule_timeout_uninterruptible(1);
2792 schedule_timeout(1);
2793 } while(m==EMPTY_QUEUE); 2772 } while(m==EMPTY_QUEUE);
2794 2773
2795 2774
@@ -2816,8 +2795,7 @@ static s32 adpt_i2o_status_get(adpt_hba* pHba)
2816 return -ETIMEDOUT; 2795 return -ETIMEDOUT;
2817 } 2796 }
2818 rmb(); 2797 rmb();
2819 set_current_state(TASK_UNINTERRUPTIBLE); 2798 schedule_timeout_uninterruptible(1);
2820 schedule_timeout(1);
2821 } 2799 }
2822 2800
2823 // Set up our number of outbound and inbound messages 2801 // Set up our number of outbound and inbound messages
@@ -2941,8 +2919,7 @@ static int adpt_i2o_build_sys_table(void)
2941 sys_tbl_len = sizeof(struct i2o_sys_tbl) + // Header + IOPs 2919 sys_tbl_len = sizeof(struct i2o_sys_tbl) + // Header + IOPs
2942 (hba_count) * sizeof(struct i2o_sys_tbl_entry); 2920 (hba_count) * sizeof(struct i2o_sys_tbl_entry);
2943 2921
2944 if(sys_tbl) 2922 kfree(sys_tbl);
2945 kfree(sys_tbl);
2946 2923
2947 sys_tbl = kmalloc(sys_tbl_len, GFP_KERNEL|ADDR32); 2924 sys_tbl = kmalloc(sys_tbl_len, GFP_KERNEL|ADDR32);
2948 if(!sys_tbl) { 2925 if(!sys_tbl) {
diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
index b45a4c730230..b3f9de8f7595 100644
--- a/drivers/scsi/eata.c
+++ b/drivers/scsi/eata.c
@@ -2580,8 +2580,7 @@ static int eata2x_release(struct Scsi_Host *shost)
2580 unsigned int i; 2580 unsigned int i;
2581 2581
2582 for (i = 0; i < shost->can_queue; i++) 2582 for (i = 0; i < shost->can_queue; i++)
2583 if ((&ha->cp[i])->sglist) 2583 kfree((&ha->cp[i])->sglist);
2584 kfree((&ha->cp[i])->sglist);
2585 2584
2586 for (i = 0; i < shost->can_queue; i++) 2585 for (i = 0; i < shost->can_queue; i++)
2587 pci_unmap_single(ha->pdev, ha->cp[i].cp_dma_addr, 2586 pci_unmap_single(ha->pdev, ha->cp[i].cp_dma_addr,
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index f04f3289938d..c888af4a4562 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -331,9 +331,9 @@ static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_co
331 rq = kmalloc (sizeof (struct request), GFP_ATOMIC); 331 rq = kmalloc (sizeof (struct request), GFP_ATOMIC);
332 buf = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC); 332 buf = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC);
333 if (pc == NULL || rq == NULL || buf == NULL) { 333 if (pc == NULL || rq == NULL || buf == NULL) {
334 if (pc) kfree(pc); 334 kfree(buf);
335 if (rq) kfree(rq); 335 kfree(rq);
336 if (buf) kfree(buf); 336 kfree(pc);
337 return -ENOMEM; 337 return -ENOMEM;
338 } 338 }
339 memset (pc, 0, sizeof (idescsi_pc_t)); 339 memset (pc, 0, sizeof (idescsi_pc_t));
@@ -949,8 +949,8 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
949 spin_lock_irq(host->host_lock); 949 spin_lock_irq(host->host_lock);
950 return 0; 950 return 0;
951abort: 951abort:
952 if (pc) kfree (pc); 952 kfree (pc);
953 if (rq) kfree (rq); 953 kfree (rq);
954 cmd->result = DID_ERROR << 16; 954 cmd->result = DID_ERROR << 16;
955 done(cmd); 955 done(cmd);
956 return 0; 956 return 0;
diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index 68e5b2ab27c4..cd9b95db5a7d 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -4517,10 +4517,8 @@ ips_free(ips_ha_t * ha)
4517 ha->enq = NULL; 4517 ha->enq = NULL;
4518 } 4518 }
4519 4519
4520 if (ha->conf) { 4520 kfree(ha->conf);
4521 kfree(ha->conf); 4521 ha->conf = NULL;
4522 ha->conf = NULL;
4523 }
4524 4522
4525 if (ha->adapt) { 4523 if (ha->adapt) {
4526 pci_free_consistent(ha->pcidev, 4524 pci_free_consistent(ha->pcidev,
@@ -4538,15 +4536,11 @@ ips_free(ips_ha_t * ha)
4538 ha->logical_drive_info = NULL; 4536 ha->logical_drive_info = NULL;
4539 } 4537 }
4540 4538
4541 if (ha->nvram) { 4539 kfree(ha->nvram);
4542 kfree(ha->nvram); 4540 ha->nvram = NULL;
4543 ha->nvram = NULL;
4544 }
4545 4541
4546 if (ha->subsys) { 4542 kfree(ha->subsys);
4547 kfree(ha->subsys); 4543 ha->subsys = NULL;
4548 ha->subsys = NULL;
4549 }
4550 4544
4551 if (ha->ioctl_data) { 4545 if (ha->ioctl_data) {
4552 pci_free_consistent(ha->pcidev, ha->ioctl_len, 4546 pci_free_consistent(ha->pcidev, ha->ioctl_len,
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 08a0c00cfc30..bcc29ec126dc 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -127,8 +127,7 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba,
127 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) || 127 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
128 ((pcmd->virt = lpfc_mbuf_alloc(phba, 128 ((pcmd->virt = lpfc_mbuf_alloc(phba,
129 MEM_PRI, &(pcmd->phys))) == 0)) { 129 MEM_PRI, &(pcmd->phys))) == 0)) {
130 if (pcmd) 130 kfree(pcmd);
131 kfree(pcmd);
132 131
133 spin_lock_irq(phba->host->host_lock); 132 spin_lock_irq(phba->host->host_lock);
134 lpfc_sli_release_iocbq(phba, elsiocb); 133 lpfc_sli_release_iocbq(phba, elsiocb);
@@ -145,8 +144,7 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba,
145 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, 144 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
146 &prsp->phys); 145 &prsp->phys);
147 if (prsp == 0 || prsp->virt == 0) { 146 if (prsp == 0 || prsp->virt == 0) {
148 if (prsp) 147 kfree(prsp);
149 kfree(prsp);
150 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); 148 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
151 kfree(pcmd); 149 kfree(pcmd);
152 spin_lock_irq(phba->host->host_lock); 150 spin_lock_irq(phba->host->host_lock);
@@ -172,8 +170,7 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba,
172 lpfc_mbuf_free(phba, prsp->virt, prsp->phys); 170 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
173 kfree(pcmd); 171 kfree(pcmd);
174 kfree(prsp); 172 kfree(prsp);
175 if (pbuflist) 173 kfree(pbuflist);
176 kfree(pbuflist);
177 return NULL; 174 return NULL;
178 } 175 }
179 176
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 4e04470321a2..c90723860a04 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -894,8 +894,7 @@ lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
894 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, 894 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
895 &mp1->phys); 895 &mp1->phys);
896 if (mp1 == 0 || mp1->virt == 0) { 896 if (mp1 == 0 || mp1->virt == 0) {
897 if (mp1) 897 kfree(mp1);
898 kfree(mp1);
899 spin_lock_irq(phba->host->host_lock); 898 spin_lock_irq(phba->host->host_lock);
900 lpfc_sli_release_iocbq(phba, iocb); 899 lpfc_sli_release_iocbq(phba, iocb);
901 spin_unlock_irq(phba->host->host_lock); 900 spin_unlock_irq(phba->host->host_lock);
@@ -911,8 +910,7 @@ lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
911 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, 910 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
912 &mp2->phys); 911 &mp2->phys);
913 if (mp2 == 0 || mp2->virt == 0) { 912 if (mp2 == 0 || mp2->virt == 0) {
914 if (mp2) 913 kfree(mp2);
915 kfree(mp2);
916 lpfc_mbuf_free(phba, mp1->virt, mp1->phys); 914 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
917 kfree(mp1); 915 kfree(mp1);
918 spin_lock_irq(phba->host->host_lock); 916 spin_lock_irq(phba->host->host_lock);
diff --git a/drivers/scsi/lpfc/lpfc_mbox.c b/drivers/scsi/lpfc/lpfc_mbox.c
index 31c20cc00609..e3bc8d3f7302 100644
--- a/drivers/scsi/lpfc/lpfc_mbox.c
+++ b/drivers/scsi/lpfc/lpfc_mbox.c
@@ -248,8 +248,7 @@ lpfc_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
248 248
249 if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) || 249 if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
250 ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) { 250 ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
251 if (mp) 251 kfree(mp);
252 kfree(mp);
253 mb->mbxCommand = MBX_READ_SPARM64; 252 mb->mbxCommand = MBX_READ_SPARM64;
254 /* READ_SPARAM: no buffers */ 253 /* READ_SPARAM: no buffers */
255 lpfc_printf_log(phba, 254 lpfc_printf_log(phba,
@@ -363,9 +362,7 @@ lpfc_reg_login(struct lpfc_hba * phba,
363 /* Get a buffer to hold NPorts Service Parameters */ 362 /* Get a buffer to hold NPorts Service Parameters */
364 if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == NULL) || 363 if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == NULL) ||
365 ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) { 364 ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
366 if (mp) 365 kfree(mp);
367 kfree(mp);
368
369 mb->mbxCommand = MBX_REG_LOGIN64; 366 mb->mbxCommand = MBX_REG_LOGIN64;
370 /* REG_LOGIN: no buffers */ 367 /* REG_LOGIN: no buffers */
371 lpfc_printf_log(phba, 368 lpfc_printf_log(phba,
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index c34d3cf4f19c..c63275e66e2e 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -825,8 +825,7 @@ __lpfc_abort_handler(struct scsi_cmnd *cmnd)
825 while (lpfc_cmd->pCmd == cmnd) 825 while (lpfc_cmd->pCmd == cmnd)
826 { 826 {
827 spin_unlock_irq(phba->host->host_lock); 827 spin_unlock_irq(phba->host->host_lock);
828 set_current_state(TASK_UNINTERRUPTIBLE); 828 schedule_timeout_uninterruptible(LPFC_ABORT_WAIT*HZ);
829 schedule_timeout(LPFC_ABORT_WAIT*HZ);
830 spin_lock_irq(phba->host->host_lock); 829 spin_lock_irq(phba->host->host_lock);
831 if (++loop_count 830 if (++loop_count
832 > (2 * phba->cfg_nodev_tmo)/LPFC_ABORT_WAIT) 831 > (2 * phba->cfg_nodev_tmo)/LPFC_ABORT_WAIT)
@@ -885,8 +884,7 @@ __lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
885 884
886 if (pnode->nlp_state != NLP_STE_MAPPED_NODE) { 885 if (pnode->nlp_state != NLP_STE_MAPPED_NODE) {
887 spin_unlock_irq(phba->host->host_lock); 886 spin_unlock_irq(phba->host->host_lock);
888 set_current_state(TASK_UNINTERRUPTIBLE); 887 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
889 schedule_timeout( HZ/2);
890 spin_lock_irq(phba->host->host_lock); 888 spin_lock_irq(phba->host->host_lock);
891 } 889 }
892 if ((pnode) && (pnode->nlp_state == NLP_STE_MAPPED_NODE)) 890 if ((pnode) && (pnode->nlp_state == NLP_STE_MAPPED_NODE))
@@ -939,8 +937,7 @@ __lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
939 cmnd->device->id, cmnd->device->lun, 937 cmnd->device->id, cmnd->device->lun,
940 LPFC_CTX_LUN))) { 938 LPFC_CTX_LUN))) {
941 spin_unlock_irq(phba->host->host_lock); 939 spin_unlock_irq(phba->host->host_lock);
942 set_current_state(TASK_UNINTERRUPTIBLE); 940 schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ);
943 schedule_timeout(LPFC_RESET_WAIT*HZ);
944 spin_lock_irq(phba->host->host_lock); 941 spin_lock_irq(phba->host->host_lock);
945 942
946 if (++loopcnt 943 if (++loopcnt
@@ -1038,8 +1035,7 @@ __lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
1038 &phba->sli.ring[phba->sli.fcp_ring], 1035 &phba->sli.ring[phba->sli.fcp_ring],
1039 0, 0, LPFC_CTX_HOST))) { 1036 0, 0, LPFC_CTX_HOST))) {
1040 spin_unlock_irq(phba->host->host_lock); 1037 spin_unlock_irq(phba->host->host_lock);
1041 set_current_state(TASK_UNINTERRUPTIBLE); 1038 schedule_timeout_uninterruptible(LPFC_RESET_WAIT*HZ);
1042 schedule_timeout(LPFC_RESET_WAIT*HZ);
1043 spin_lock_irq(phba->host->host_lock); 1039 spin_lock_irq(phba->host->host_lock);
1044 1040
1045 if (++loopcnt 1041 if (++loopcnt
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 508710001ed6..e2c08c5d83fb 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -2269,11 +2269,8 @@ lpfc_sli_hba_down(struct lpfc_hba * phba)
2269 2269
2270 INIT_LIST_HEAD(&(pring->txq)); 2270 INIT_LIST_HEAD(&(pring->txq));
2271 2271
2272 if (pring->fast_lookup) { 2272 kfree(pring->fast_lookup);
2273 kfree(pring->fast_lookup); 2273 pring->fast_lookup = NULL;
2274 pring->fast_lookup = NULL;
2275 }
2276
2277 } 2274 }
2278 2275
2279 spin_unlock_irqrestore(phba->host->host_lock, flags); 2276 spin_unlock_irqrestore(phba->host->host_lock, flags);
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index c9e743ba09ec..1a3d195a2d36 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -3937,9 +3937,8 @@ megaraid_sysfs_free_resources(adapter_t *adapter)
3937{ 3937{
3938 mraid_device_t *raid_dev = ADAP2RAIDDEV(adapter); 3938 mraid_device_t *raid_dev = ADAP2RAIDDEV(adapter);
3939 3939
3940 if (raid_dev->sysfs_uioc) kfree(raid_dev->sysfs_uioc); 3940 kfree(raid_dev->sysfs_uioc);
3941 3941 kfree(raid_dev->sysfs_mbox64);
3942 if (raid_dev->sysfs_mbox64) kfree(raid_dev->sysfs_mbox64);
3943 3942
3944 if (raid_dev->sysfs_buffer) { 3943 if (raid_dev->sysfs_buffer) {
3945 pci_free_consistent(adapter->pdev, PAGE_SIZE, 3944 pci_free_consistent(adapter->pdev, PAGE_SIZE,
diff --git a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
index 37d110e864c4..8f3ce0432295 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -995,17 +995,13 @@ pthru_dma_pool_error:
995 995
996memalloc_error: 996memalloc_error:
997 997
998 if (adapter->kioc_list) 998 kfree(adapter->kioc_list);
999 kfree(adapter->kioc_list); 999 kfree(adapter->mbox_list);
1000
1001 if (adapter->mbox_list)
1002 kfree(adapter->mbox_list);
1003 1000
1004 if (adapter->pthru_dma_pool) 1001 if (adapter->pthru_dma_pool)
1005 pci_pool_destroy(adapter->pthru_dma_pool); 1002 pci_pool_destroy(adapter->pthru_dma_pool);
1006 1003
1007 if (adapter) 1004 kfree(adapter);
1008 kfree(adapter);
1009 1005
1010 return rval; 1006 return rval;
1011} 1007}
@@ -1157,7 +1153,6 @@ mraid_mm_free_adp_resources(mraid_mmadp_t *adp)
1157 } 1153 }
1158 1154
1159 kfree(adp->kioc_list); 1155 kfree(adp->kioc_list);
1160
1161 kfree(adp->mbox_list); 1156 kfree(adp->mbox_list);
1162 1157
1163 pci_pool_destroy(adp->pthru_dma_pool); 1158 pci_pool_destroy(adp->pthru_dma_pool);
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 1cf11c3322fb..d9946bd95492 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -862,8 +862,7 @@ static int osst_recover_wait_frame(struct osst_tape * STp, struct scsi_request *
862 retval = osst_write_error_recovery(STp, aSRpnt, 0); 862 retval = osst_write_error_recovery(STp, aSRpnt, 0);
863 break; 863 break;
864 } 864 }
865 set_current_state(TASK_INTERRUPTIBLE); 865 schedule_timeout_interruptible(HZ / OSST_POLL_PER_SEC);
866 schedule_timeout (HZ / OSST_POLL_PER_SEC);
867 866
868 STp->buffer->b_data = mybuf; STp->buffer->buffer_size = 24; 867 STp->buffer->b_data = mybuf; STp->buffer->buffer_size = 24;
869 memset(cmd, 0, MAX_COMMAND_SIZE); 868 memset(cmd, 0, MAX_COMMAND_SIZE);
@@ -1558,8 +1557,7 @@ static int osst_reposition_and_retry(struct osst_tape * STp, struct scsi_request
1558 osst_set_frame_position(STp, aSRpnt, frame + skip, 1); 1557 osst_set_frame_position(STp, aSRpnt, frame + skip, 1);
1559 flag = 0; 1558 flag = 0;
1560 attempts--; 1559 attempts--;
1561 set_current_state(TASK_INTERRUPTIBLE); 1560 schedule_timeout_interruptible(msecs_to_jiffies(100));
1562 schedule_timeout(HZ / 10);
1563 } 1561 }
1564 if (osst_get_frame_position(STp, aSRpnt) < 0) { /* additional write error */ 1562 if (osst_get_frame_position(STp, aSRpnt) < 0) { /* additional write error */
1565#if DEBUG 1563#if DEBUG
@@ -1620,8 +1618,7 @@ static int osst_reposition_and_retry(struct osst_tape * STp, struct scsi_request
1620 debugging = 0; 1618 debugging = 0;
1621 } 1619 }
1622#endif 1620#endif
1623 set_current_state(TASK_INTERRUPTIBLE); 1621 schedule_timeout_interruptible(msecs_to_jiffies(100));
1624 schedule_timeout(HZ / 10);
1625 } 1622 }
1626 printk(KERN_ERR "%s:E: Failed to find valid tape media\n", name); 1623 printk(KERN_ERR "%s:E: Failed to find valid tape media\n", name);
1627#if DEBUG 1624#if DEBUG
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 290a6b92616c..72d9090df3df 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -1977,8 +1977,7 @@ qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1977 } 1977 }
1978 1978
1979cleanup_allocation: 1979cleanup_allocation:
1980 if (new_fcport) 1980 kfree(new_fcport);
1981 kfree(new_fcport);
1982 1981
1983 if (rval != QLA_SUCCESS) { 1982 if (rval != QLA_SUCCESS) {
1984 DEBUG2(printk("scsi(%ld): Configure local loop error exit: " 1983 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
@@ -2348,8 +2347,7 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2348 /* Allocate temporary fcport for any new fcports discovered. */ 2347 /* Allocate temporary fcport for any new fcports discovered. */
2349 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL); 2348 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2350 if (new_fcport == NULL) { 2349 if (new_fcport == NULL) {
2351 if (swl) 2350 kfree(swl);
2352 kfree(swl);
2353 return (QLA_MEMORY_ALLOC_FAILED); 2351 return (QLA_MEMORY_ALLOC_FAILED);
2354 } 2352 }
2355 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); 2353 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
@@ -2485,19 +2483,15 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2485 nxt_d_id.b24 = new_fcport->d_id.b24; 2483 nxt_d_id.b24 = new_fcport->d_id.b24;
2486 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL); 2484 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2487 if (new_fcport == NULL) { 2485 if (new_fcport == NULL) {
2488 if (swl) 2486 kfree(swl);
2489 kfree(swl);
2490 return (QLA_MEMORY_ALLOC_FAILED); 2487 return (QLA_MEMORY_ALLOC_FAILED);
2491 } 2488 }
2492 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); 2489 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2493 new_fcport->d_id.b24 = nxt_d_id.b24; 2490 new_fcport->d_id.b24 = nxt_d_id.b24;
2494 } 2491 }
2495 2492
2496 if (swl) 2493 kfree(swl);
2497 kfree(swl); 2494 kfree(new_fcport);
2498
2499 if (new_fcport)
2500 kfree(new_fcport);
2501 2495
2502 if (!list_empty(new_fcports)) 2496 if (!list_empty(new_fcports))
2503 ha->device_flags |= DFLG_FABRIC_DEVICES; 2497 ha->device_flags |= DFLG_FABRIC_DEVICES;
diff --git a/drivers/scsi/raid_class.c b/drivers/scsi/raid_class.c
index f1ea5027865f..caa0c3629626 100644
--- a/drivers/scsi/raid_class.c
+++ b/drivers/scsi/raid_class.c
@@ -4,6 +4,8 @@
4#include <linux/init.h> 4#include <linux/init.h>
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/list.h> 6#include <linux/list.h>
7#include <linux/slab.h>
8#include <linux/string.h>
7#include <linux/raid_class.h> 9#include <linux/raid_class.h>
8#include <scsi/scsi_device.h> 10#include <scsi/scsi_device.h>
9#include <scsi/scsi_host.h> 11#include <scsi/scsi_host.h>
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index 0cc766a9aa65..edabbd05d258 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -26,6 +26,8 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/slab.h>
30#include <linux/string.h>
29 31
30#include <scsi/scsi_device.h> 32#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h> 33#include <scsi/scsi_host.h>
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 4f30a37db63c..62e3f340cc52 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -476,8 +476,7 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
476 sg_finish_rem_req(srp); 476 sg_finish_rem_req(srp);
477 retval = count; 477 retval = count;
478free_old_hdr: 478free_old_hdr:
479 if (old_hdr) 479 kfree(old_hdr);
480 kfree(old_hdr);
481 return retval; 480 return retval;
482} 481}
483 482
@@ -1703,10 +1702,8 @@ exit_sg(void)
1703 sg_sysfs_valid = 0; 1702 sg_sysfs_valid = 0;
1704 unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0), 1703 unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0),
1705 SG_MAX_DEVS); 1704 SG_MAX_DEVS);
1706 if (sg_dev_arr != NULL) { 1705 kfree((char *)sg_dev_arr);
1707 kfree((char *) sg_dev_arr); 1706 sg_dev_arr = NULL;
1708 sg_dev_arr = NULL;
1709 }
1710 sg_dev_max = 0; 1707 sg_dev_max = 0;
1711} 1708}
1712 1709
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 6b85f84c8397..770c4324f3d5 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4107,8 +4107,7 @@ out_free_tape:
4107 write_unlock(&st_dev_arr_lock); 4107 write_unlock(&st_dev_arr_lock);
4108out_put_disk: 4108out_put_disk:
4109 put_disk(disk); 4109 put_disk(disk);
4110 if (tpnt) 4110 kfree(tpnt);
4111 kfree(tpnt);
4112out_buffer_free: 4111out_buffer_free:
4113 kfree(buffer); 4112 kfree(buffer);
4114out: 4113out:
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.c b/drivers/scsi/sym53c8xx_2/sym_hipd.c
index a1a58e1d5ad3..a7420cad4547 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.c
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.c
@@ -39,6 +39,7 @@
39 */ 39 */
40 40
41#include <linux/slab.h> 41#include <linux/slab.h>
42#include <asm/param.h> /* for timeouts in units of HZ */
42 43
43#include "sym_glue.h" 44#include "sym_glue.h"
44#include "sym_nvram.h" 45#include "sym_nvram.h"
diff --git a/drivers/scsi/u14-34f.c b/drivers/scsi/u14-34f.c
index cfab8f197084..1ce29ba683eb 100644
--- a/drivers/scsi/u14-34f.c
+++ b/drivers/scsi/u14-34f.c
@@ -1953,11 +1953,11 @@ static int u14_34f_release(struct Scsi_Host *shpnt) {
1953 1953
1954 for (j = 0; sh[j] != NULL && sh[j] != shpnt; j++); 1954 for (j = 0; sh[j] != NULL && sh[j] != shpnt; j++);
1955 1955
1956 if (sh[j] == NULL) panic("%s: release, invalid Scsi_Host pointer.\n", 1956 if (sh[j] == NULL)
1957 driver_name); 1957 panic("%s: release, invalid Scsi_Host pointer.\n", driver_name);
1958 1958
1959 for (i = 0; i < sh[j]->can_queue; i++) 1959 for (i = 0; i < sh[j]->can_queue; i++)
1960 if ((&HD(j)->cp[i])->sglist) kfree((&HD(j)->cp[i])->sglist); 1960 kfree((&HD(j)->cp[i])->sglist);
1961 1961
1962 for (i = 0; i < sh[j]->can_queue; i++) 1962 for (i = 0; i < sh[j]->can_queue; i++)
1963 pci_unmap_single(HD(j)->pdev, HD(j)->cp[i].cp_dma_addr, 1963 pci_unmap_single(HD(j)->pdev, HD(j)->cp[i].cp_dma_addr,
@@ -1965,7 +1965,8 @@ static int u14_34f_release(struct Scsi_Host *shpnt) {
1965 1965
1966 free_irq(sh[j]->irq, &sha[j]); 1966 free_irq(sh[j]->irq, &sha[j]);
1967 1967
1968 if (sh[j]->dma_channel != NO_DMA) free_dma(sh[j]->dma_channel); 1968 if (sh[j]->dma_channel != NO_DMA)
1969 free_dma(sh[j]->dma_channel);
1969 1970
1970 release_region(sh[j]->io_port, sh[j]->n_io_port); 1971 release_region(sh[j]->io_port, sh[j]->n_io_port);
1971 scsi_unregister(sh[j]); 1972 scsi_unregister(sh[j]);
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 186e96c47b3d..98820603e75f 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -40,6 +40,7 @@
40#include <linux/serial_core.h> 40#include <linux/serial_core.h>
41#include <linux/serial.h> 41#include <linux/serial.h>
42#include <linux/serial_8250.h> 42#include <linux/serial_8250.h>
43#include <linux/nmi.h>
43 44
44#include <asm/io.h> 45#include <asm/io.h>
45#include <asm/irq.h> 46#include <asm/irq.h>
@@ -2208,6 +2209,8 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count)
2208 unsigned int ier; 2209 unsigned int ier;
2209 int i; 2210 int i;
2210 2211
2212 touch_nmi_watchdog();
2213
2211 /* 2214 /*
2212 * First save the UER then disable the interrupts 2215 * First save the UER then disable the interrupts
2213 */ 2216 */
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index 40d3e7139cfe..08c42c000188 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -4416,10 +4416,8 @@ rs_close(struct tty_struct *tty, struct file * filp)
4416 info->event = 0; 4416 info->event = 0;
4417 info->tty = 0; 4417 info->tty = 0;
4418 if (info->blocked_open) { 4418 if (info->blocked_open) {
4419 if (info->close_delay) { 4419 if (info->close_delay)
4420 set_current_state(TASK_INTERRUPTIBLE); 4420 schedule_timeout_interruptible(info->close_delay);
4421 schedule_timeout(info->close_delay);
4422 }
4423 wake_up_interruptible(&info->open_wait); 4421 wake_up_interruptible(&info->open_wait);
4424 } 4422 }
4425 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 4423 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
@@ -4469,8 +4467,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
4469 while (info->xmit.head != info->xmit.tail || /* More in send queue */ 4467 while (info->xmit.head != info->xmit.tail || /* More in send queue */
4470 (*info->ostatusadr & 0x007f) || /* more in FIFO */ 4468 (*info->ostatusadr & 0x007f) || /* more in FIFO */
4471 (elapsed_usec < 2*info->char_time_usec)) { 4469 (elapsed_usec < 2*info->char_time_usec)) {
4472 set_current_state(TASK_INTERRUPTIBLE); 4470 schedule_timeout_interruptible(1);
4473 schedule_timeout(1);
4474 if (signal_pending(current)) 4471 if (signal_pending(current))
4475 break; 4472 break;
4476 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 4473 if (timeout && time_after(jiffies, orig_jiffies + timeout))
diff --git a/drivers/serial/mcfserial.c b/drivers/serial/mcfserial.c
index e2ebdcad553c..47f7404cb045 100644
--- a/drivers/serial/mcfserial.c
+++ b/drivers/serial/mcfserial.c
@@ -57,7 +57,8 @@ struct timer_list mcfrs_timer_struct;
57 * keep going. Perhaps one day the cflag settings for the 57 * keep going. Perhaps one day the cflag settings for the
58 * console can be used instead. 58 * console can be used instead.
59 */ 59 */
60#if defined(CONFIG_ARNEWSH) || defined(CONFIG_MOTOROLA) || defined(CONFIG_senTec) || defined(CONFIG_SNEHA) 60#if defined(CONFIG_ARNEWSH) || defined(CONFIG_FREESCALE) || \
61 defined(CONFIG_senTec) || defined(CONFIG_SNEHA)
61#define CONSOLE_BAUD_RATE 19200 62#define CONSOLE_BAUD_RATE 19200
62#define DEFAULT_CBAUD B19200 63#define DEFAULT_CBAUD B19200
63#endif 64#endif
@@ -67,7 +68,7 @@ struct timer_list mcfrs_timer_struct;
67#define DEFAULT_CBAUD B38400 68#define DEFAULT_CBAUD B38400
68#endif 69#endif
69 70
70#if defined(CONFIG_MOD5272) 71#if defined(CONFIG_MOD5272) || defined(CONFIG_M5208EVB)
71#define CONSOLE_BAUD_RATE 115200 72#define CONSOLE_BAUD_RATE 115200
72#define DEFAULT_CBAUD B115200 73#define DEFAULT_CBAUD B115200
73#endif 74#endif
@@ -95,7 +96,8 @@ static struct tty_driver *mcfrs_serial_driver;
95#undef SERIAL_DEBUG_OPEN 96#undef SERIAL_DEBUG_OPEN
96#undef SERIAL_DEBUG_FLOW 97#undef SERIAL_DEBUG_FLOW
97 98
98#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) 99#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
100 defined(CONFIG_M520x)
99#define IRQBASE (MCFINT_VECBASE+MCFINT_UART0) 101#define IRQBASE (MCFINT_VECBASE+MCFINT_UART0)
100#else 102#else
101#define IRQBASE 73 103#define IRQBASE 73
@@ -1528,6 +1530,35 @@ static void mcfrs_irqinit(struct mcf_serial *info)
1528 imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 + 1530 imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 +
1529 MCFINTC_IMRL); 1531 MCFINTC_IMRL);
1530 *imrp &= ~((1 << (info->irq - MCFINT_VECBASE)) | 1); 1532 *imrp &= ~((1 << (info->irq - MCFINT_VECBASE)) | 1);
1533#elif defined(CONFIG_M520x)
1534 volatile unsigned char *icrp, *uartp;
1535 volatile unsigned long *imrp;
1536
1537 uartp = info->addr;
1538
1539 icrp = (volatile unsigned char *) (MCF_MBAR + MCFICM_INTC0 +
1540 MCFINTC_ICR0 + MCFINT_UART0 + info->line);
1541 *icrp = 0x03;
1542
1543 imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 +
1544 MCFINTC_IMRL);
1545 *imrp &= ~((1 << (info->irq - MCFINT_VECBASE)) | 1);
1546 if (info->line < 2) {
1547 unsigned short *uart_par;
1548 uart_par = (unsigned short *)(MCF_IPSBAR + MCF_GPIO_PAR_UART);
1549 if (info->line == 0)
1550 *uart_par |= MCF_GPIO_PAR_UART_PAR_UTXD0
1551 | MCF_GPIO_PAR_UART_PAR_URXD0;
1552 else if (info->line == 1)
1553 *uart_par |= MCF_GPIO_PAR_UART_PAR_UTXD1
1554 | MCF_GPIO_PAR_UART_PAR_URXD1;
1555 } else if (info->line == 2) {
1556 unsigned char *feci2c_par;
1557 feci2c_par = (unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FECI2C);
1558 *feci2c_par &= ~0x0F;
1559 *feci2c_par |= MCF_GPIO_PAR_FECI2C_PAR_SCL_UTXD2
1560 | MCF_GPIO_PAR_FECI2C_PAR_SDA_URXD2;
1561 }
1531#else 1562#else
1532 volatile unsigned char *icrp, *uartp; 1563 volatile unsigned char *icrp, *uartp;
1533 1564
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index 656c0e8d160e..f0738533f39a 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -1441,7 +1441,7 @@ static void sunsu_console_write(struct console *co, const char *s,
1441 * - initialize the serial port 1441 * - initialize the serial port
1442 * Return non-zero if we didn't find a serial port. 1442 * Return non-zero if we didn't find a serial port.
1443 */ 1443 */
1444static int __init sunsu_console_setup(struct console *co, char *options) 1444static int sunsu_console_setup(struct console *co, char *options)
1445{ 1445{
1446 struct uart_port *port; 1446 struct uart_port *port;
1447 int baud = 9600; 1447 int baud = 9600;
diff --git a/drivers/sh/superhyway/superhyway-sysfs.c b/drivers/sh/superhyway/superhyway-sysfs.c
index dc119ce68e3e..55434330867b 100644
--- a/drivers/sh/superhyway/superhyway-sysfs.c
+++ b/drivers/sh/superhyway/superhyway-sysfs.c
@@ -30,7 +30,7 @@ superhyway_ro_attr(bot_mb, "0x%02x\n", vcr.bot_mb);
30superhyway_ro_attr(top_mb, "0x%02x\n", vcr.top_mb); 30superhyway_ro_attr(top_mb, "0x%02x\n", vcr.top_mb);
31 31
32/* Misc */ 32/* Misc */
33superhyway_ro_attr(resource, "0x%08lx\n", resource.start); 33superhyway_ro_attr(resource, "0x%08lx\n", resource[0].start);
34 34
35struct device_attribute superhyway_dev_attrs[] = { 35struct device_attribute superhyway_dev_attrs[] = {
36 __ATTR_RO(perr_flags), 36 __ATTR_RO(perr_flags),
diff --git a/drivers/sh/superhyway/superhyway.c b/drivers/sh/superhyway/superhyway.c
index 28757cb9d246..7bdab2a7f59c 100644
--- a/drivers/sh/superhyway/superhyway.c
+++ b/drivers/sh/superhyway/superhyway.c
@@ -27,19 +27,20 @@ static struct device superhyway_bus_device = {
27 27
28static void superhyway_device_release(struct device *dev) 28static void superhyway_device_release(struct device *dev)
29{ 29{
30 kfree(to_superhyway_device(dev)); 30 struct superhyway_device *sdev = to_superhyway_device(dev);
31
32 kfree(sdev->resource);
33 kfree(sdev);
31} 34}
32 35
33/** 36/**
34 * superhyway_add_device - Add a SuperHyway module 37 * superhyway_add_device - Add a SuperHyway module
35 * @mod_id: Module ID (taken from MODULE.VCR.MOD_ID).
36 * @base: Physical address where module is mapped. 38 * @base: Physical address where module is mapped.
37 * @vcr: VCR value. 39 * @sdev: SuperHyway device to add, or NULL to allocate a new one.
40 * @bus: Bus where SuperHyway module resides.
38 * 41 *
39 * This is responsible for adding a new SuperHyway module. This sets up a new 42 * This is responsible for adding a new SuperHyway module. This sets up a new
40 * struct superhyway_device for the module being added. Each one of @mod_id, 43 * struct superhyway_device for the module being added if @sdev == NULL.
41 * @base, and @vcr are registered with the new device for further use
42 * elsewhere.
43 * 44 *
44 * Devices are initially added in the order that they are scanned (from the 45 * Devices are initially added in the order that they are scanned (from the
45 * top-down of the memory map), and are assigned an ID based on the order that 46 * top-down of the memory map), and are assigned an ID based on the order that
@@ -49,28 +50,40 @@ static void superhyway_device_release(struct device *dev)
49 * Further work can and should be done in superhyway_scan_bus(), to be sure 50 * Further work can and should be done in superhyway_scan_bus(), to be sure
50 * that any new modules are properly discovered and subsequently registered. 51 * that any new modules are properly discovered and subsequently registered.
51 */ 52 */
52int superhyway_add_device(unsigned int mod_id, unsigned long base, 53int superhyway_add_device(unsigned long base, struct superhyway_device *sdev,
53 unsigned long long vcr) 54 struct superhyway_bus *bus)
54{ 55{
55 struct superhyway_device *dev; 56 struct superhyway_device *dev = sdev;
57
58 if (!dev) {
59 dev = kmalloc(sizeof(struct superhyway_device), GFP_KERNEL);
60 if (!dev)
61 return -ENOMEM;
56 62
57 dev = kmalloc(sizeof(struct superhyway_device), GFP_KERNEL); 63 memset(dev, 0, sizeof(struct superhyway_device));
58 if (!dev) 64 }
59 return -ENOMEM;
60 65
61 memset(dev, 0, sizeof(struct superhyway_device)); 66 dev->bus = bus;
67 superhyway_read_vcr(dev, base, &dev->vcr);
62 68
63 dev->id.id = mod_id; 69 if (!dev->resource) {
64 sprintf(dev->name, "SuperHyway device %04x", dev->id.id); 70 dev->resource = kmalloc(sizeof(struct resource), GFP_KERNEL);
71 if (!dev->resource) {
72 kfree(dev);
73 return -ENOMEM;
74 }
75
76 dev->resource->name = dev->name;
77 dev->resource->start = base;
78 dev->resource->end = dev->resource->start + 0x01000000;
79 }
65 80
66 dev->vcr = *((struct vcr_info *)(&vcr));
67 dev->resource.name = dev->name;
68 dev->resource.start = base;
69 dev->resource.end = dev->resource.start + 0x01000000;
70 dev->dev.parent = &superhyway_bus_device; 81 dev->dev.parent = &superhyway_bus_device;
71 dev->dev.bus = &superhyway_bus_type; 82 dev->dev.bus = &superhyway_bus_type;
72 dev->dev.release = superhyway_device_release; 83 dev->dev.release = superhyway_device_release;
84 dev->id.id = dev->vcr.mod_id;
73 85
86 sprintf(dev->name, "SuperHyway device %04x", dev->id.id);
74 sprintf(dev->dev.bus_id, "%02x", superhyway_devices); 87 sprintf(dev->dev.bus_id, "%02x", superhyway_devices);
75 88
76 superhyway_devices++; 89 superhyway_devices++;
@@ -78,10 +91,31 @@ int superhyway_add_device(unsigned int mod_id, unsigned long base,
78 return device_register(&dev->dev); 91 return device_register(&dev->dev);
79} 92}
80 93
94int superhyway_add_devices(struct superhyway_bus *bus,
95 struct superhyway_device **devices,
96 int nr_devices)
97{
98 int i, ret = 0;
99
100 for (i = 0; i < nr_devices; i++) {
101 struct superhyway_device *dev = devices[i];
102 ret |= superhyway_add_device(dev->resource[0].start, dev, bus);
103 }
104
105 return ret;
106}
107
81static int __init superhyway_init(void) 108static int __init superhyway_init(void)
82{ 109{
110 struct superhyway_bus *bus;
111 int ret = 0;
112
83 device_register(&superhyway_bus_device); 113 device_register(&superhyway_bus_device);
84 return superhyway_scan_bus(); 114
115 for (bus = superhyway_channels; bus->ops; bus++)
116 ret |= superhyway_scan_bus(bus);
117
118 return ret;
85} 119}
86 120
87postcore_initcall(superhyway_init); 121postcore_initcall(superhyway_init);
@@ -197,6 +231,7 @@ module_exit(superhyway_bus_exit);
197 231
198EXPORT_SYMBOL(superhyway_bus_type); 232EXPORT_SYMBOL(superhyway_bus_type);
199EXPORT_SYMBOL(superhyway_add_device); 233EXPORT_SYMBOL(superhyway_add_device);
234EXPORT_SYMBOL(superhyway_add_devices);
200EXPORT_SYMBOL(superhyway_register_driver); 235EXPORT_SYMBOL(superhyway_register_driver);
201EXPORT_SYMBOL(superhyway_unregister_driver); 236EXPORT_SYMBOL(superhyway_unregister_driver);
202 237
diff --git a/drivers/tc/.gitignore b/drivers/tc/.gitignore
new file mode 100644
index 000000000000..acc0e1e6a650
--- /dev/null
+++ b/drivers/tc/.gitignore
@@ -0,0 +1 @@
lk201-map.c
diff --git a/drivers/video/68328fb.c b/drivers/video/68328fb.c
index 6a3cfbdc6dc9..3b0ddc55236b 100644
--- a/drivers/video/68328fb.c
+++ b/drivers/video/68328fb.c
@@ -113,7 +113,6 @@ static struct fb_ops mc68x328fb_ops = {
113 .fb_fillrect = cfb_fillrect, 113 .fb_fillrect = cfb_fillrect,
114 .fb_copyarea = cfb_copyarea, 114 .fb_copyarea = cfb_copyarea,
115 .fb_imageblit = cfb_imageblit, 115 .fb_imageblit = cfb_imageblit,
116 .fb_cursor = soft_cursor,
117 .fb_mmap = mc68x328fb_mmap, 116 .fb_mmap = mc68x328fb_mmap,
118}; 117};
119 118
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 7192b770bfb6..44b6ca290ce3 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -65,15 +65,6 @@ config FB_CFB_IMAGEBLIT
65 blitting. This is used by drivers that don't provide their own 65 blitting. This is used by drivers that don't provide their own
66 (accelerated) version. 66 (accelerated) version.
67 67
68config FB_SOFT_CURSOR
69 tristate
70 depends on FB
71 default n
72 ---help---
73 Include the soft_cursor function for generic software cursor support.
74 This is used by drivers that don't provide their own (accelerated)
75 version.
76
77config FB_MACMODES 68config FB_MACMODES
78 tristate 69 tristate
79 depends on FB 70 depends on FB
@@ -114,7 +105,6 @@ config FB_CIRRUS
114 select FB_CFB_FILLRECT 105 select FB_CFB_FILLRECT
115 select FB_CFB_COPYAREA 106 select FB_CFB_COPYAREA
116 select FB_CFB_IMAGEBLIT 107 select FB_CFB_IMAGEBLIT
117 select FB_SOFT_CURSOR
118 ---help--- 108 ---help---
119 This enables support for Cirrus Logic GD542x/543x based boards on 109 This enables support for Cirrus Logic GD542x/543x based boards on
120 Amiga: SD64, Piccolo, Picasso II/II+, Picasso IV, or EGS Spectrum. 110 Amiga: SD64, Piccolo, Picasso II/II+, Picasso IV, or EGS Spectrum.
@@ -133,7 +123,6 @@ config FB_PM2
133 select FB_CFB_FILLRECT 123 select FB_CFB_FILLRECT
134 select FB_CFB_COPYAREA 124 select FB_CFB_COPYAREA
135 select FB_CFB_IMAGEBLIT 125 select FB_CFB_IMAGEBLIT
136 select FB_SOFT_CURSOR
137 help 126 help
138 This is the frame buffer device driver for the Permedia2 AGP frame 127 This is the frame buffer device driver for the Permedia2 AGP frame
139 buffer card from ASK, aka `Graphic Blaster Exxtreme'. There is a 128 buffer card from ASK, aka `Graphic Blaster Exxtreme'. There is a
@@ -152,7 +141,6 @@ config FB_ARMCLCD
152 select FB_CFB_FILLRECT 141 select FB_CFB_FILLRECT
153 select FB_CFB_COPYAREA 142 select FB_CFB_COPYAREA
154 select FB_CFB_IMAGEBLIT 143 select FB_CFB_IMAGEBLIT
155 select FB_SOFT_CURSOR
156 help 144 help
157 This framebuffer device driver is for the ARM PrimeCell PL110 145 This framebuffer device driver is for the ARM PrimeCell PL110
158 Colour LCD controller. ARM PrimeCells provide the building 146 Colour LCD controller. ARM PrimeCells provide the building
@@ -169,7 +157,6 @@ config FB_ACORN
169 select FB_CFB_FILLRECT 157 select FB_CFB_FILLRECT
170 select FB_CFB_COPYAREA 158 select FB_CFB_COPYAREA
171 select FB_CFB_IMAGEBLIT 159 select FB_CFB_IMAGEBLIT
172 select FB_SOFT_CURSOR
173 help 160 help
174 This is the frame buffer device driver for the Acorn VIDC graphics 161 This is the frame buffer device driver for the Acorn VIDC graphics
175 hardware found in Acorn RISC PCs and other ARM-based machines. If 162 hardware found in Acorn RISC PCs and other ARM-based machines. If
@@ -181,7 +168,9 @@ config FB_CLPS711X
181 select FB_CFB_FILLRECT 168 select FB_CFB_FILLRECT
182 select FB_CFB_COPYAREA 169 select FB_CFB_COPYAREA
183 select FB_CFB_IMAGEBLIT 170 select FB_CFB_IMAGEBLIT
184 select FB_SOFT_CURSOR 171 help
172 Say Y to enable the Framebuffer driver for the CLPS7111 and
173 EP7212 processors.
185 174
186config FB_SA1100 175config FB_SA1100
187 bool "SA-1100 LCD support" 176 bool "SA-1100 LCD support"
@@ -189,7 +178,6 @@ config FB_SA1100
189 select FB_CFB_FILLRECT 178 select FB_CFB_FILLRECT
190 select FB_CFB_COPYAREA 179 select FB_CFB_COPYAREA
191 select FB_CFB_IMAGEBLIT 180 select FB_CFB_IMAGEBLIT
192 select FB_SOFT_CURSOR
193 help 181 help
194 This is a framebuffer device for the SA-1100 LCD Controller. 182 This is a framebuffer device for the SA-1100 LCD Controller.
195 See <http://www.linux-fbdev.org/> for information on framebuffer 183 See <http://www.linux-fbdev.org/> for information on framebuffer
@@ -204,7 +192,6 @@ config FB_IMX
204 select FB_CFB_FILLRECT 192 select FB_CFB_FILLRECT
205 select FB_CFB_COPYAREA 193 select FB_CFB_COPYAREA
206 select FB_CFB_IMAGEBLIT 194 select FB_CFB_IMAGEBLIT
207 select FB_SOFT_CURSOR
208 195
209config FB_CYBER2000 196config FB_CYBER2000
210 tristate "CyberPro 2000/2010/5000 support" 197 tristate "CyberPro 2000/2010/5000 support"
@@ -212,7 +199,6 @@ config FB_CYBER2000
212 select FB_CFB_FILLRECT 199 select FB_CFB_FILLRECT
213 select FB_CFB_COPYAREA 200 select FB_CFB_COPYAREA
214 select FB_CFB_IMAGEBLIT 201 select FB_CFB_IMAGEBLIT
215 select FB_SOFT_CURSOR
216 help 202 help
217 This enables support for the Integraphics CyberPro 20x0 and 5000 203 This enables support for the Integraphics CyberPro 20x0 and 5000
218 VGA chips used in the Rebel.com Netwinder and other machines. 204 VGA chips used in the Rebel.com Netwinder and other machines.
@@ -225,7 +211,6 @@ config FB_APOLLO
225 default y 211 default y
226 select FB_CFB_FILLRECT 212 select FB_CFB_FILLRECT
227 select FB_CFB_IMAGEBLIT 213 select FB_CFB_IMAGEBLIT
228 select FB_SOFT_CURSOR
229 214
230config FB_Q40 215config FB_Q40
231 bool 216 bool
@@ -234,12 +219,10 @@ config FB_Q40
234 select FB_CFB_FILLRECT 219 select FB_CFB_FILLRECT
235 select FB_CFB_COPYAREA 220 select FB_CFB_COPYAREA
236 select FB_CFB_IMAGEBLIT 221 select FB_CFB_IMAGEBLIT
237 select FB_SOFT_CURSOR
238 222
239config FB_AMIGA 223config FB_AMIGA
240 tristate "Amiga native chipset support" 224 tristate "Amiga native chipset support"
241 depends on FB && AMIGA 225 depends on FB && AMIGA
242 select FB_SOFT_CURSOR
243 help 226 help
244 This is the frame buffer device driver for the builtin graphics 227 This is the frame buffer device driver for the builtin graphics
245 chipset found in Amigas. 228 chipset found in Amigas.
@@ -279,7 +262,6 @@ config FB_CYBER
279 select FB_CFB_FILLRECT 262 select FB_CFB_FILLRECT
280 select FB_CFB_COPYAREA 263 select FB_CFB_COPYAREA
281 select FB_CFB_IMAGEBLIT 264 select FB_CFB_IMAGEBLIT
282 select FB_SOFT_CURSOR
283 help 265 help
284 This enables support for the Cybervision 64 graphics card from 266 This enables support for the Cybervision 64 graphics card from
285 Phase5. Please note that its use is not all that intuitive (i.e. if 267 Phase5. Please note that its use is not all that intuitive (i.e. if
@@ -294,7 +276,6 @@ config FB_VIRGE
294 select FB_CFB_FILLRECT 276 select FB_CFB_FILLRECT
295 select FB_CFB_COPYAREA 277 select FB_CFB_COPYAREA
296 select FB_CFB_IMAGEBLIT 278 select FB_CFB_IMAGEBLIT
297 select FB_SOFT_CURSOR
298 help 279 help
299 This enables support for the Cybervision 64/3D graphics card from 280 This enables support for the Cybervision 64/3D graphics card from
300 Phase5. Please note that its use is not all that intuitive (i.e. if 281 Phase5. Please note that its use is not all that intuitive (i.e. if
@@ -317,7 +298,6 @@ config FB_FM2
317 select FB_CFB_FILLRECT 298 select FB_CFB_FILLRECT
318 select FB_CFB_COPYAREA 299 select FB_CFB_COPYAREA
319 select FB_CFB_IMAGEBLIT 300 select FB_CFB_IMAGEBLIT
320 select FB_SOFT_CURSOR
321 help 301 help
322 This is the frame buffer device driver for the Amiga FrameMaster 302 This is the frame buffer device driver for the Amiga FrameMaster
323 card from BSC (exhibited 1992 but not shipped as a CBM product). 303 card from BSC (exhibited 1992 but not shipped as a CBM product).
@@ -328,7 +308,6 @@ config FB_ARC
328 select FB_CFB_FILLRECT 308 select FB_CFB_FILLRECT
329 select FB_CFB_COPYAREA 309 select FB_CFB_COPYAREA
330 select FB_CFB_IMAGEBLIT 310 select FB_CFB_IMAGEBLIT
331 select FB_SOFT_CURSOR
332 help 311 help
333 This enables support for the Arc Monochrome LCD board. The board 312 This enables support for the Arc Monochrome LCD board. The board
334 is based on the KS-108 lcd controller and is typically a matrix 313 is based on the KS-108 lcd controller and is typically a matrix
@@ -351,7 +330,6 @@ config FB_OF
351 select FB_CFB_FILLRECT 330 select FB_CFB_FILLRECT
352 select FB_CFB_COPYAREA 331 select FB_CFB_COPYAREA
353 select FB_CFB_IMAGEBLIT 332 select FB_CFB_IMAGEBLIT
354 select FB_SOFT_CURSOR
355 select FB_MACMODES 333 select FB_MACMODES
356 help 334 help
357 Say Y if you want support with Open Firmware for your graphics 335 Say Y if you want support with Open Firmware for your graphics
@@ -363,7 +341,6 @@ config FB_CONTROL
363 select FB_CFB_FILLRECT 341 select FB_CFB_FILLRECT
364 select FB_CFB_COPYAREA 342 select FB_CFB_COPYAREA
365 select FB_CFB_IMAGEBLIT 343 select FB_CFB_IMAGEBLIT
366 select FB_SOFT_CURSOR
367 select FB_MACMODES 344 select FB_MACMODES
368 help 345 help
369 This driver supports a frame buffer for the graphics adapter in the 346 This driver supports a frame buffer for the graphics adapter in the
@@ -375,7 +352,6 @@ config FB_PLATINUM
375 select FB_CFB_FILLRECT 352 select FB_CFB_FILLRECT
376 select FB_CFB_COPYAREA 353 select FB_CFB_COPYAREA
377 select FB_CFB_IMAGEBLIT 354 select FB_CFB_IMAGEBLIT
378 select FB_SOFT_CURSOR
379 select FB_MACMODES 355 select FB_MACMODES
380 help 356 help
381 This driver supports a frame buffer for the "platinum" graphics 357 This driver supports a frame buffer for the "platinum" graphics
@@ -387,7 +363,6 @@ config FB_VALKYRIE
387 select FB_CFB_FILLRECT 363 select FB_CFB_FILLRECT
388 select FB_CFB_COPYAREA 364 select FB_CFB_COPYAREA
389 select FB_CFB_IMAGEBLIT 365 select FB_CFB_IMAGEBLIT
390 select FB_SOFT_CURSOR
391 select FB_MACMODES 366 select FB_MACMODES
392 help 367 help
393 This driver supports a frame buffer for the "valkyrie" graphics 368 This driver supports a frame buffer for the "valkyrie" graphics
@@ -399,42 +374,32 @@ config FB_CT65550
399 select FB_CFB_FILLRECT 374 select FB_CFB_FILLRECT
400 select FB_CFB_COPYAREA 375 select FB_CFB_COPYAREA
401 select FB_CFB_IMAGEBLIT 376 select FB_CFB_IMAGEBLIT
402 select FB_SOFT_CURSOR
403 help 377 help
404 This is the frame buffer device driver for the Chips & Technologies 378 This is the frame buffer device driver for the Chips & Technologies
405 65550 graphics chip in PowerBooks. 379 65550 graphics chip in PowerBooks.
406 380
407config FB_ASILIANT 381config FB_ASILIANT
408 bool "Chips 69000 display support" 382 bool "Asiliant (Chips) 69000 display support"
409 depends on (FB = y) && PCI 383 depends on (FB = y) && PCI
410 select FB_CFB_FILLRECT 384 select FB_CFB_FILLRECT
411 select FB_CFB_COPYAREA 385 select FB_CFB_COPYAREA
412 select FB_CFB_IMAGEBLIT 386 select FB_CFB_IMAGEBLIT
413 select FB_SOFT_CURSOR
414 387
415config FB_IMSTT 388config FB_IMSTT
416 bool "IMS Twin Turbo display support" 389 bool "IMS Twin Turbo display support"
417 depends on (FB = y) && PCI 390 depends on (FB = y) && PCI
418 select FB_CFB_IMAGEBLIT 391 select FB_CFB_IMAGEBLIT
419 select FB_SOFT_CURSOR
420 select FB_MACMODES if PPC 392 select FB_MACMODES if PPC
421 help 393 help
422 The IMS Twin Turbo is a PCI-based frame buffer card bundled with 394 The IMS Twin Turbo is a PCI-based frame buffer card bundled with
423 many Macintosh and compatible computers. 395 many Macintosh and compatible computers.
424 396
425config FB_S3TRIO
426 bool "S3 Trio display support"
427 depends on (FB = y) && PPC && BROKEN
428 help
429 If you have a S3 Trio say Y. Say N for S3 Virge.
430
431config FB_VGA16 397config FB_VGA16
432 tristate "VGA 16-color graphics support" 398 tristate "VGA 16-color graphics support"
433 depends on FB && (X86 || PPC) 399 depends on FB && (X86 || PPC)
434 select FB_CFB_FILLRECT 400 select FB_CFB_FILLRECT
435 select FB_CFB_COPYAREA 401 select FB_CFB_COPYAREA
436 select FB_CFB_IMAGEBLIT 402 select FB_CFB_IMAGEBLIT
437 select FB_SOFT_CURSOR
438 help 403 help
439 This is the frame buffer device driver for VGA 16 color graphic 404 This is the frame buffer device driver for VGA 16 color graphic
440 cards. Say Y if you have such a card. 405 cards. Say Y if you have such a card.
@@ -448,7 +413,6 @@ config FB_STI
448 select FB_CFB_FILLRECT 413 select FB_CFB_FILLRECT
449 select FB_CFB_COPYAREA 414 select FB_CFB_COPYAREA
450 select FB_CFB_IMAGEBLIT 415 select FB_CFB_IMAGEBLIT
451 select FB_SOFT_CURSOR
452 default y 416 default y
453 ---help--- 417 ---help---
454 STI refers to the HP "Standard Text Interface" which is a set of 418 STI refers to the HP "Standard Text Interface" which is a set of
@@ -469,7 +433,6 @@ config FB_MAC
469 select FB_CFB_FILLRECT 433 select FB_CFB_FILLRECT
470 select FB_CFB_COPYAREA 434 select FB_CFB_COPYAREA
471 select FB_CFB_IMAGEBLIT 435 select FB_CFB_IMAGEBLIT
472 select FB_SOFT_CURSOR
473 select FB_MACMODES 436 select FB_MACMODES
474 437
475# bool ' Apple DAFB display support' CONFIG_FB_DAFB 438# bool ' Apple DAFB display support' CONFIG_FB_DAFB
@@ -478,7 +441,6 @@ config FB_HP300
478 depends on (FB = y) && HP300 441 depends on (FB = y) && HP300
479 select FB_CFB_FILLRECT 442 select FB_CFB_FILLRECT
480 select FB_CFB_IMAGEBLIT 443 select FB_CFB_IMAGEBLIT
481 select FB_SOFT_CURSOR
482 default y 444 default y
483 445
484config FB_TGA 446config FB_TGA
@@ -487,7 +449,6 @@ config FB_TGA
487 select FB_CFB_FILLRECT 449 select FB_CFB_FILLRECT
488 select FB_CFB_COPYAREA 450 select FB_CFB_COPYAREA
489 select FB_CFB_IMAGEBLIT 451 select FB_CFB_IMAGEBLIT
490 select FB_SOFT_CURSOR
491 help 452 help
492 This is the frame buffer device driver for generic TGA graphic 453 This is the frame buffer device driver for generic TGA graphic
493 cards. Say Y if you have one of those. 454 cards. Say Y if you have one of those.
@@ -498,7 +459,6 @@ config FB_VESA
498 select FB_CFB_FILLRECT 459 select FB_CFB_FILLRECT
499 select FB_CFB_COPYAREA 460 select FB_CFB_COPYAREA
500 select FB_CFB_IMAGEBLIT 461 select FB_CFB_IMAGEBLIT
501 select FB_SOFT_CURSOR
502 help 462 help
503 This is the frame buffer device driver for generic VESA 2.0 463 This is the frame buffer device driver for generic VESA 2.0
504 compliant graphic cards. The older VESA 1.2 cards are not supported. 464 compliant graphic cards. The older VESA 1.2 cards are not supported.
@@ -516,7 +476,6 @@ config FB_HGA
516 select FB_CFB_FILLRECT 476 select FB_CFB_FILLRECT
517 select FB_CFB_COPYAREA 477 select FB_CFB_COPYAREA
518 select FB_CFB_IMAGEBLIT 478 select FB_CFB_IMAGEBLIT
519 select FB_SOFT_CURSOR
520 help 479 help
521 Say Y here if you have a Hercules mono graphics card. 480 Say Y here if you have a Hercules mono graphics card.
522 481
@@ -545,7 +504,6 @@ config FB_SGIVW
545 select FB_CFB_FILLRECT 504 select FB_CFB_FILLRECT
546 select FB_CFB_COPYAREA 505 select FB_CFB_COPYAREA
547 select FB_CFB_IMAGEBLIT 506 select FB_CFB_IMAGEBLIT
548 select FB_SOFT_CURSOR
549 help 507 help
550 SGI Visual Workstation support for framebuffer graphics. 508 SGI Visual Workstation support for framebuffer graphics.
551 509
@@ -555,7 +513,6 @@ config FB_GBE
555 select FB_CFB_FILLRECT 513 select FB_CFB_FILLRECT
556 select FB_CFB_COPYAREA 514 select FB_CFB_COPYAREA
557 select FB_CFB_IMAGEBLIT 515 select FB_CFB_IMAGEBLIT
558 select FB_SOFT_CURSOR
559 help 516 help
560 This is the frame buffer device driver for SGI Graphics Backend. 517 This is the frame buffer device driver for SGI Graphics Backend.
561 This chip is used in SGI O2 and Visual Workstation 320/540. 518 This chip is used in SGI O2 and Visual Workstation 320/540.
@@ -583,7 +540,6 @@ config FB_BW2
583 select FB_CFB_FILLRECT 540 select FB_CFB_FILLRECT
584 select FB_CFB_COPYAREA 541 select FB_CFB_COPYAREA
585 select FB_CFB_IMAGEBLIT 542 select FB_CFB_IMAGEBLIT
586 select FB_SOFT_CURSOR
587 help 543 help
588 This is the frame buffer device driver for the BWtwo frame buffer. 544 This is the frame buffer device driver for the BWtwo frame buffer.
589 545
@@ -592,7 +548,6 @@ config FB_CG3
592 depends on (FB = y) && ((SPARC32 || SPARC64) && FB_SBUS || (SUN3 || SUN3X) && FB_SUN3) 548 depends on (FB = y) && ((SPARC32 || SPARC64) && FB_SBUS || (SUN3 || SUN3X) && FB_SUN3)
593 select FB_CFB_COPYAREA 549 select FB_CFB_COPYAREA
594 select FB_CFB_IMAGEBLIT 550 select FB_CFB_IMAGEBLIT
595 select FB_SOFT_CURSOR
596 help 551 help
597 This is the frame buffer device driver for the CGthree frame buffer. 552 This is the frame buffer device driver for the CGthree frame buffer.
598 553
@@ -601,7 +556,6 @@ config FB_CG6
601 depends on (FB = y) && ((SPARC32 || SPARC64) && FB_SBUS || (SUN3 || SUN3X) && FB_SUN3) 556 depends on (FB = y) && ((SPARC32 || SPARC64) && FB_SBUS || (SUN3 || SUN3X) && FB_SUN3)
602 select FB_CFB_COPYAREA 557 select FB_CFB_COPYAREA
603 select FB_CFB_IMAGEBLIT 558 select FB_CFB_IMAGEBLIT
604 select FB_SOFT_CURSOR
605 help 559 help
606 This is the frame buffer device driver for the CGsix (GX, TurboGX) 560 This is the frame buffer device driver for the CGsix (GX, TurboGX)
607 frame buffer. 561 frame buffer.
@@ -612,7 +566,6 @@ config FB_PVR2
612 select FB_CFB_FILLRECT 566 select FB_CFB_FILLRECT
613 select FB_CFB_COPYAREA 567 select FB_CFB_COPYAREA
614 select FB_CFB_IMAGEBLIT 568 select FB_CFB_IMAGEBLIT
615 select FB_SOFT_CURSOR
616 ---help--- 569 ---help---
617 Say Y here if you have a PowerVR 2 card in your box. If you plan to 570 Say Y here if you have a PowerVR 2 card in your box. If you plan to
618 run linux on your Dreamcast, you will have to say Y here. 571 run linux on your Dreamcast, you will have to say Y here.
@@ -634,13 +587,55 @@ config FB_EPSON1355
634 select FB_CFB_FILLRECT 587 select FB_CFB_FILLRECT
635 select FB_CFB_COPYAREA 588 select FB_CFB_COPYAREA
636 select FB_CFB_IMAGEBLIT 589 select FB_CFB_IMAGEBLIT
637 select FB_SOFT_CURSOR
638 help 590 help
639 Build in support for the SED1355 Epson Research Embedded RAMDAC 591 Build in support for the SED1355 Epson Research Embedded RAMDAC
640 LCD/CRT Controller (since redesignated as the S1D13505) as a 592 LCD/CRT Controller (since redesignated as the S1D13505) as a
641 framebuffer. Product specs at 593 framebuffer. Product specs at
642 <http://www.erd.epson.com/vdc/html/products.htm>. 594 <http://www.erd.epson.com/vdc/html/products.htm>.
643 595
596config FB_E1356
597 tristate "Epson SED1356 framebuffer support"
598 depends on FB && EXPERIMENTAL && PCI && MIPS
599
600config PB1000_CRT
601 bool "Use CRT on Pb1000 (J65)"
602 depends on MIPS_PB1000=y && FB_E1356
603
604config PB1000_NTSC
605 bool "Use Compsite NTSC on Pb1000 (J63)"
606 depends on MIPS_PB1000=y && FB_E1356
607
608config PB1000_TFT
609 bool "Use TFT Panel on Pb1000 (J64)"
610 depends on MIPS_PB1000=y && FB_E1356
611
612config PB1500_CRT
613 bool "Use CRT on Pb1500 " if MIPS_PB1500=y
614 depends on FB_E1356
615
616config PB1500_CRT
617 prompt "Use CRT on Pb1100 "
618 depends on FB_E1356 && MIPS_PB1100=y
619
620config PB1500_TFT
621 bool "Use TFT Panel on Pb1500 " if MIPS_PB1500=y
622 depends on FB_E1356
623
624config PB1500_TFT
625 prompt "Use TFT Panel on Pb1100 "
626 depends on FB_E1356 && MIPS_PB1100=y
627
628config FB_S1D13XXX
629 tristate "Epson S1D13XXX framebuffer support"
630 depends on FB
631 select FB_CFB_FILLRECT
632 select FB_CFB_COPYAREA
633 select FB_CFB_IMAGEBLIT
634 help
635 Support for S1D13XXX framebuffer device family (currently only
636 working with S1D13806). Product specs at
637 <http://www.erd.epson.com/vdc/html/legacy_13xxx.htm>
638
644config FB_NVIDIA 639config FB_NVIDIA
645 tristate "nVidia Framebuffer Support" 640 tristate "nVidia Framebuffer Support"
646 depends on FB && PCI 641 depends on FB && PCI
@@ -650,7 +645,6 @@ config FB_NVIDIA
650 select FB_CFB_FILLRECT 645 select FB_CFB_FILLRECT
651 select FB_CFB_COPYAREA 646 select FB_CFB_COPYAREA
652 select FB_CFB_IMAGEBLIT 647 select FB_CFB_IMAGEBLIT
653 select FB_SOFT_CURSOR
654 help 648 help
655 This driver supports graphics boards with the nVidia chips, TNT 649 This driver supports graphics boards with the nVidia chips, TNT
656 and newer. For very old chipsets, such as the RIVA128, then use 650 and newer. For very old chipsets, such as the RIVA128, then use
@@ -662,7 +656,7 @@ config FB_NVIDIA
662 656
663config FB_NVIDIA_I2C 657config FB_NVIDIA_I2C
664 bool "Enable DDC Support" 658 bool "Enable DDC Support"
665 depends on FB_NVIDIA && !PPC_OF 659 depends on FB_NVIDIA
666 help 660 help
667 This enables I2C support for nVidia Chipsets. This is used 661 This enables I2C support for nVidia Chipsets. This is used
668 only for getting EDID information from the attached display 662 only for getting EDID information from the attached display
@@ -768,7 +762,6 @@ config FB_INTEL
768 select FB_CFB_FILLRECT 762 select FB_CFB_FILLRECT
769 select FB_CFB_COPYAREA 763 select FB_CFB_COPYAREA
770 select FB_CFB_IMAGEBLIT 764 select FB_CFB_IMAGEBLIT
771 select FB_SOFT_CURSOR
772 help 765 help
773 This driver supports the on-board graphics built in to the Intel 766 This driver supports the on-board graphics built in to the Intel
774 830M/845G/852GM/855GM/865G chipsets. 767 830M/845G/852GM/855GM/865G chipsets.
@@ -791,7 +784,6 @@ config FB_MATROX
791 select FB_CFB_FILLRECT 784 select FB_CFB_FILLRECT
792 select FB_CFB_COPYAREA 785 select FB_CFB_COPYAREA
793 select FB_CFB_IMAGEBLIT 786 select FB_CFB_IMAGEBLIT
794 select FB_SOFT_CURSOR
795 select FB_TILEBLITTING 787 select FB_TILEBLITTING
796 select FB_MACMODES if PPC_PMAC 788 select FB_MACMODES if PPC_PMAC
797 ---help--- 789 ---help---
@@ -932,7 +924,6 @@ config FB_RADEON_OLD
932 select FB_CFB_FILLRECT 924 select FB_CFB_FILLRECT
933 select FB_CFB_COPYAREA 925 select FB_CFB_COPYAREA
934 select FB_CFB_IMAGEBLIT 926 select FB_CFB_IMAGEBLIT
935 select FB_SOFT_CURSOR
936 select FB_MACMODES if PPC 927 select FB_MACMODES if PPC
937 help 928 help
938 Choose this option if you want to use an ATI Radeon graphics card as 929 Choose this option if you want to use an ATI Radeon graphics card as
@@ -950,7 +941,6 @@ config FB_RADEON
950 select FB_CFB_FILLRECT 941 select FB_CFB_FILLRECT
951 select FB_CFB_COPYAREA 942 select FB_CFB_COPYAREA
952 select FB_CFB_IMAGEBLIT 943 select FB_CFB_IMAGEBLIT
953 select FB_SOFT_CURSOR
954 select FB_MACMODES if PPC_OF 944 select FB_MACMODES if PPC_OF
955 help 945 help
956 Choose this option if you want to use an ATI Radeon graphics card as 946 Choose this option if you want to use an ATI Radeon graphics card as
@@ -988,7 +978,6 @@ config FB_ATY128
988 select FB_CFB_FILLRECT 978 select FB_CFB_FILLRECT
989 select FB_CFB_COPYAREA 979 select FB_CFB_COPYAREA
990 select FB_CFB_IMAGEBLIT 980 select FB_CFB_IMAGEBLIT
991 select FB_SOFT_CURSOR
992 select FB_MACMODES if PPC_PMAC 981 select FB_MACMODES if PPC_PMAC
993 help 982 help
994 This driver supports graphics boards with the ATI Rage128 chips. 983 This driver supports graphics boards with the ATI Rage128 chips.
@@ -1004,7 +993,6 @@ config FB_ATY
1004 select FB_CFB_FILLRECT 993 select FB_CFB_FILLRECT
1005 select FB_CFB_COPYAREA 994 select FB_CFB_COPYAREA
1006 select FB_CFB_IMAGEBLIT 995 select FB_CFB_IMAGEBLIT
1007 select FB_SOFT_CURSOR
1008 select FB_MACMODES if PPC 996 select FB_MACMODES if PPC
1009 help 997 help
1010 This driver supports graphics boards with the ATI Mach64 chips. 998 This driver supports graphics boards with the ATI Mach64 chips.
@@ -1047,6 +1035,12 @@ config FB_ATY_GX
1047 is at 1035 is at
1048 <http://support.ati.com/products/pc/mach64/graphics_xpression.html>. 1036 <http://support.ati.com/products/pc/mach64/graphics_xpression.html>.
1049 1037
1038config FB_S3TRIO
1039 bool "S3 Trio display support"
1040 depends on (FB = y) && PPC && BROKEN
1041 help
1042 If you have a S3 Trio say Y. Say N for S3 Virge.
1043
1050config FB_SAVAGE 1044config FB_SAVAGE
1051 tristate "S3 Savage support" 1045 tristate "S3 Savage support"
1052 depends on FB && PCI && EXPERIMENTAL 1046 depends on FB && PCI && EXPERIMENTAL
@@ -1056,7 +1050,6 @@ config FB_SAVAGE
1056 select FB_CFB_FILLRECT 1050 select FB_CFB_FILLRECT
1057 select FB_CFB_COPYAREA 1051 select FB_CFB_COPYAREA
1058 select FB_CFB_IMAGEBLIT 1052 select FB_CFB_IMAGEBLIT
1059 select FB_SOFT_CURSOR
1060 help 1053 help
1061 This driver supports notebooks and computers with S3 Savage PCI/AGP 1054 This driver supports notebooks and computers with S3 Savage PCI/AGP
1062 chips. 1055 chips.
@@ -1093,7 +1086,6 @@ config FB_SIS
1093 select FB_CFB_FILLRECT 1086 select FB_CFB_FILLRECT
1094 select FB_CFB_COPYAREA 1087 select FB_CFB_COPYAREA
1095 select FB_CFB_IMAGEBLIT 1088 select FB_CFB_IMAGEBLIT
1096 select FB_SOFT_CURSOR
1097 help 1089 help
1098 This is the frame buffer device driver for the SiS 300, 315, 330 1090 This is the frame buffer device driver for the SiS 300, 315, 330
1099 and 340 series as well as XGI V3XT, V5, V8, Z7 graphics chipsets. 1091 and 340 series as well as XGI V3XT, V5, V8, Z7 graphics chipsets.
@@ -1123,7 +1115,6 @@ config FB_NEOMAGIC
1123 select FB_CFB_FILLRECT 1115 select FB_CFB_FILLRECT
1124 select FB_CFB_COPYAREA 1116 select FB_CFB_COPYAREA
1125 select FB_CFB_IMAGEBLIT 1117 select FB_CFB_IMAGEBLIT
1126 select FB_SOFT_CURSOR
1127 help 1118 help
1128 This driver supports notebooks with NeoMagic PCI chips. 1119 This driver supports notebooks with NeoMagic PCI chips.
1129 Say Y if you have such a graphics card. 1120 Say Y if you have such a graphics card.
@@ -1137,7 +1128,6 @@ config FB_KYRO
1137 select FB_CFB_FILLRECT 1128 select FB_CFB_FILLRECT
1138 select FB_CFB_COPYAREA 1129 select FB_CFB_COPYAREA
1139 select FB_CFB_IMAGEBLIT 1130 select FB_CFB_IMAGEBLIT
1140 select FB_SOFT_CURSOR
1141 help 1131 help
1142 Say Y here if you have a STG4000 / Kyro / PowerVR 3 based 1132 Say Y here if you have a STG4000 / Kyro / PowerVR 3 based
1143 graphics board. 1133 graphics board.
@@ -1151,7 +1141,6 @@ config FB_3DFX
1151 select FB_CFB_IMAGEBLIT 1141 select FB_CFB_IMAGEBLIT
1152 select FB_CFB_FILLRECT 1142 select FB_CFB_FILLRECT
1153 select FB_CFB_COPYAREA 1143 select FB_CFB_COPYAREA
1154 select FB_SOFT_CURSOR
1155 help 1144 help
1156 This driver supports graphics boards with the 3Dfx Banshee/Voodoo3 1145 This driver supports graphics boards with the 3Dfx Banshee/Voodoo3
1157 chips. Say Y if you have such a graphics board. 1146 chips. Say Y if you have such a graphics board.
@@ -1173,7 +1162,6 @@ config FB_VOODOO1
1173 select FB_CFB_FILLRECT 1162 select FB_CFB_FILLRECT
1174 select FB_CFB_COPYAREA 1163 select FB_CFB_COPYAREA
1175 select FB_CFB_IMAGEBLIT 1164 select FB_CFB_IMAGEBLIT
1176 select FB_SOFT_CURSOR
1177 ---help--- 1165 ---help---
1178 Say Y here if you have a 3Dfx Voodoo Graphics (Voodoo1/sst1) or 1166 Say Y here if you have a 3Dfx Voodoo Graphics (Voodoo1/sst1) or
1179 Voodoo2 (cvg) based graphics card. 1167 Voodoo2 (cvg) based graphics card.
@@ -1190,7 +1178,6 @@ config FB_CYBLA
1190 tristate "Cyberblade/i1 support" 1178 tristate "Cyberblade/i1 support"
1191 depends on FB && PCI 1179 depends on FB && PCI
1192 select FB_CFB_IMAGEBLIT 1180 select FB_CFB_IMAGEBLIT
1193 select FB_SOFT_CURSOR
1194 select VIDEO_SELECT 1181 select VIDEO_SELECT
1195 ---help--- 1182 ---help---
1196 This driver is supposed to support the Trident Cyberblade/i1 1183 This driver is supposed to support the Trident Cyberblade/i1
@@ -1218,7 +1205,6 @@ config FB_TRIDENT
1218 select FB_CFB_FILLRECT 1205 select FB_CFB_FILLRECT
1219 select FB_CFB_COPYAREA 1206 select FB_CFB_COPYAREA
1220 select FB_CFB_IMAGEBLIT 1207 select FB_CFB_IMAGEBLIT
1221 select FB_SOFT_CURSOR
1222 ---help--- 1208 ---help---
1223 This driver is supposed to support graphics boards with the 1209 This driver is supposed to support graphics boards with the
1224 Trident CyberXXXX/Image/CyberBlade chips mostly found in laptops 1210 Trident CyberXXXX/Image/CyberBlade chips mostly found in laptops
@@ -1250,38 +1236,6 @@ config FB_PM3
1250 similar boards, 3DLabs Permedia3 Create!, Appian Jeronimo 2000 1236 similar boards, 3DLabs Permedia3 Create!, Appian Jeronimo 2000
1251 and maybe other boards. 1237 and maybe other boards.
1252 1238
1253config FB_E1356
1254 tristate "Epson SED1356 framebuffer support"
1255 depends on FB && EXPERIMENTAL && PCI && MIPS
1256
1257config PB1000_CRT
1258 bool "Use CRT on Pb1000 (J65)"
1259 depends on MIPS_PB1000=y && FB_E1356
1260
1261config PB1000_NTSC
1262 bool "Use Compsite NTSC on Pb1000 (J63)"
1263 depends on MIPS_PB1000=y && FB_E1356
1264
1265config PB1000_TFT
1266 bool "Use TFT Panel on Pb1000 (J64)"
1267 depends on MIPS_PB1000=y && FB_E1356
1268
1269config PB1500_CRT
1270 bool "Use CRT on Pb1500 " if MIPS_PB1500=y
1271 depends on FB_E1356
1272
1273config PB1500_CRT
1274 prompt "Use CRT on Pb1100 "
1275 depends on FB_E1356 && MIPS_PB1100=y
1276
1277config PB1500_TFT
1278 bool "Use TFT Panel on Pb1500 " if MIPS_PB1500=y
1279 depends on FB_E1356
1280
1281config PB1500_TFT
1282 prompt "Use TFT Panel on Pb1100 "
1283 depends on FB_E1356 && MIPS_PB1100=y
1284
1285config FB_AU1100 1239config FB_AU1100
1286 bool "Au1100 LCD Driver" 1240 bool "Au1100 LCD Driver"
1287 depends on (FB = y) && EXPERIMENTAL && PCI && MIPS && MIPS_PB1100=y 1241 depends on (FB = y) && EXPERIMENTAL && PCI && MIPS && MIPS_PB1100=y
@@ -1299,7 +1253,6 @@ config FB_FFB
1299 depends on FB_SBUS && SPARC64 1253 depends on FB_SBUS && SPARC64
1300 select FB_CFB_COPYAREA 1254 select FB_CFB_COPYAREA
1301 select FB_CFB_IMAGEBLIT 1255 select FB_CFB_IMAGEBLIT
1302 select FB_SOFT_CURSOR
1303 help 1256 help
1304 This is the frame buffer device driver for the Creator, Creator3D, 1257 This is the frame buffer device driver for the Creator, Creator3D,
1305 and Elite3D graphics boards. 1258 and Elite3D graphics boards.
@@ -1310,7 +1263,6 @@ config FB_TCX
1310 select FB_CFB_FILLRECT 1263 select FB_CFB_FILLRECT
1311 select FB_CFB_COPYAREA 1264 select FB_CFB_COPYAREA
1312 select FB_CFB_IMAGEBLIT 1265 select FB_CFB_IMAGEBLIT
1313 select FB_SOFT_CURSOR
1314 help 1266 help
1315 This is the frame buffer device driver for the TCX 24/8bit frame 1267 This is the frame buffer device driver for the TCX 24/8bit frame
1316 buffer. 1268 buffer.
@@ -1321,7 +1273,6 @@ config FB_CG14
1321 select FB_CFB_FILLRECT 1273 select FB_CFB_FILLRECT
1322 select FB_CFB_COPYAREA 1274 select FB_CFB_COPYAREA
1323 select FB_CFB_IMAGEBLIT 1275 select FB_CFB_IMAGEBLIT
1324 select FB_SOFT_CURSOR
1325 help 1276 help
1326 This is the frame buffer device driver for the CGfourteen frame 1277 This is the frame buffer device driver for the CGfourteen frame
1327 buffer on Desktop SPARCsystems with the SX graphics option. 1278 buffer on Desktop SPARCsystems with the SX graphics option.
@@ -1332,7 +1283,6 @@ config FB_P9100
1332 select FB_CFB_FILLRECT 1283 select FB_CFB_FILLRECT
1333 select FB_CFB_COPYAREA 1284 select FB_CFB_COPYAREA
1334 select FB_CFB_IMAGEBLIT 1285 select FB_CFB_IMAGEBLIT
1335 select FB_SOFT_CURSOR
1336 help 1286 help
1337 This is the frame buffer device driver for the P9100 card 1287 This is the frame buffer device driver for the P9100 card
1338 supported on Sparcbook 3 machines. 1288 supported on Sparcbook 3 machines.
@@ -1343,7 +1293,6 @@ config FB_LEO
1343 select FB_CFB_FILLRECT 1293 select FB_CFB_FILLRECT
1344 select FB_CFB_COPYAREA 1294 select FB_CFB_COPYAREA
1345 select FB_CFB_IMAGEBLIT 1295 select FB_CFB_IMAGEBLIT
1346 select FB_SOFT_CURSOR
1347 help 1296 help
1348 This is the frame buffer device driver for the SBUS-based Sun ZX 1297 This is the frame buffer device driver for the SBUS-based Sun ZX
1349 (leo) frame buffer cards. 1298 (leo) frame buffer cards.
@@ -1358,7 +1307,6 @@ config FB_IGA
1358 select FB_CFB_FILLRECT 1307 select FB_CFB_FILLRECT
1359 select FB_CFB_COPYAREA 1308 select FB_CFB_COPYAREA
1360 select FB_CFB_IMAGEBLIT 1309 select FB_CFB_IMAGEBLIT
1361 select FB_SOFT_CURSOR
1362 help 1310 help
1363 This is the framebuffer device for the INTERGRAPHICS 1680 and 1311 This is the framebuffer device for the INTERGRAPHICS 1680 and
1364 successor frame buffer cards. 1312 successor frame buffer cards.
@@ -1369,7 +1317,6 @@ config FB_HIT
1369 select FB_CFB_FILLRECT 1317 select FB_CFB_FILLRECT
1370 select FB_CFB_COPYAREA 1318 select FB_CFB_COPYAREA
1371 select FB_CFB_IMAGEBLIT 1319 select FB_CFB_IMAGEBLIT
1372 select FB_SOFT_CURSOR
1373 help 1320 help
1374 This is the frame buffer device driver for the Hitachi HD64461 LCD 1321 This is the frame buffer device driver for the Hitachi HD64461 LCD
1375 frame buffer card. 1322 frame buffer card.
@@ -1380,7 +1327,6 @@ config FB_PMAG_AA
1380 select FB_CFB_FILLRECT 1327 select FB_CFB_FILLRECT
1381 select FB_CFB_COPYAREA 1328 select FB_CFB_COPYAREA
1382 select FB_CFB_IMAGEBLIT 1329 select FB_CFB_IMAGEBLIT
1383 select FB_SOFT_CURSOR
1384 help 1330 help
1385 Support for the PMAG-AA TURBOchannel framebuffer card (1280x1024x1) 1331 Support for the PMAG-AA TURBOchannel framebuffer card (1280x1024x1)
1386 used mainly in the MIPS-based DECstation series. 1332 used mainly in the MIPS-based DECstation series.
@@ -1391,7 +1337,6 @@ config FB_PMAG_BA
1391 select FB_CFB_FILLRECT 1337 select FB_CFB_FILLRECT
1392 select FB_CFB_COPYAREA 1338 select FB_CFB_COPYAREA
1393 select FB_CFB_IMAGEBLIT 1339 select FB_CFB_IMAGEBLIT
1394 select FB_SOFT_CURSOR
1395 help 1340 help
1396 Support for the PMAG-BA TURBOchannel framebuffer card (1024x864x8) 1341 Support for the PMAG-BA TURBOchannel framebuffer card (1024x864x8)
1397 used mainly in the MIPS-based DECstation series. 1342 used mainly in the MIPS-based DECstation series.
@@ -1402,7 +1347,6 @@ config FB_PMAGB_B
1402 select FB_CFB_FILLRECT 1347 select FB_CFB_FILLRECT
1403 select FB_CFB_COPYAREA 1348 select FB_CFB_COPYAREA
1404 select FB_CFB_IMAGEBLIT 1349 select FB_CFB_IMAGEBLIT
1405 select FB_SOFT_CURSOR
1406 help 1350 help
1407 Support for the PMAGB-B TURBOchannel framebuffer card used mainly 1351 Support for the PMAGB-B TURBOchannel framebuffer card used mainly
1408 in the MIPS-based DECstation series. The card is currently only 1352 in the MIPS-based DECstation series. The card is currently only
@@ -1414,7 +1358,6 @@ config FB_MAXINE
1414 select FB_CFB_FILLRECT 1358 select FB_CFB_FILLRECT
1415 select FB_CFB_COPYAREA 1359 select FB_CFB_COPYAREA
1416 select FB_CFB_IMAGEBLIT 1360 select FB_CFB_IMAGEBLIT
1417 select FB_SOFT_CURSOR
1418 help 1361 help
1419 Support for the onboard framebuffer (1024x768x8) in the Personal 1362 Support for the onboard framebuffer (1024x768x8) in the Personal
1420 DECstation series (Personal DECstation 5000/20, /25, /33, /50, 1363 DECstation series (Personal DECstation 5000/20, /25, /33, /50,
@@ -1426,7 +1369,6 @@ config FB_TX3912
1426 select FB_CFB_FILLRECT 1369 select FB_CFB_FILLRECT
1427 select FB_CFB_COPYAREA 1370 select FB_CFB_COPYAREA
1428 select FB_CFB_IMAGEBLIT 1371 select FB_CFB_IMAGEBLIT
1429 select FB_SOFT_CURSOR
1430 help 1372 help
1431 The TX3912 is a Toshiba RISC processor based on the MIPS 3900 core 1373 The TX3912 is a Toshiba RISC processor based on the MIPS 3900 core
1432 see <http://www.toshiba.com/taec/components/Generic/risc/tx3912.htm>. 1374 see <http://www.toshiba.com/taec/components/Generic/risc/tx3912.htm>.
@@ -1439,7 +1381,6 @@ config FB_G364
1439 select FB_CFB_FILLRECT 1381 select FB_CFB_FILLRECT
1440 select FB_CFB_COPYAREA 1382 select FB_CFB_COPYAREA
1441 select FB_CFB_IMAGEBLIT 1383 select FB_CFB_IMAGEBLIT
1442 select FB_SOFT_CURSOR
1443 help 1384 help
1444 The G364 driver is the framebuffer used in MIPS Magnum 4000 and 1385 The G364 driver is the framebuffer used in MIPS Magnum 4000 and
1445 Olivetti M700-10 systems. 1386 Olivetti M700-10 systems.
@@ -1450,7 +1391,6 @@ config FB_68328
1450 select FB_CFB_FILLRECT 1391 select FB_CFB_FILLRECT
1451 select FB_CFB_COPYAREA 1392 select FB_CFB_COPYAREA
1452 select FB_CFB_IMAGEBLIT 1393 select FB_CFB_IMAGEBLIT
1453 select FB_SOFT_CURSOR
1454 help 1394 help
1455 Say Y here if you want to support the built-in frame buffer of 1395 Say Y here if you want to support the built-in frame buffer of
1456 the Motorola 68328 CPU family. 1396 the Motorola 68328 CPU family.
@@ -1461,7 +1401,6 @@ config FB_PXA
1461 select FB_CFB_FILLRECT 1401 select FB_CFB_FILLRECT
1462 select FB_CFB_COPYAREA 1402 select FB_CFB_COPYAREA
1463 select FB_CFB_IMAGEBLIT 1403 select FB_CFB_IMAGEBLIT
1464 select FB_SOFT_CURSOR
1465 ---help--- 1404 ---help---
1466 Frame buffer driver for the built-in LCD controller in the Intel 1405 Frame buffer driver for the built-in LCD controller in the Intel
1467 PXA2x0 processor. 1406 PXA2x0 processor.
@@ -1473,23 +1412,6 @@ config FB_PXA
1473 1412
1474 If unsure, say N. 1413 If unsure, say N.
1475 1414
1476config FB_W100
1477 tristate "W100 frame buffer support"
1478 depends on FB && PXA_SHARPSL
1479 select FB_CFB_FILLRECT
1480 select FB_CFB_COPYAREA
1481 select FB_CFB_IMAGEBLIT
1482 select FB_SOFT_CURSOR
1483 ---help---
1484 Frame buffer driver for the w100 as found on the Sharp SL-Cxx series.
1485
1486 This driver is also available as a module ( = code which can be
1487 inserted and removed from the running kernel whenever you want). The
1488 module will be called vfb. If you want to compile it as a module,
1489 say M here and read <file:Documentation/modules.txt>.
1490
1491 If unsure, say N.
1492
1493config FB_PXA_PARAMETERS 1415config FB_PXA_PARAMETERS
1494 bool "PXA LCD command line parameters" 1416 bool "PXA LCD command line parameters"
1495 default n 1417 default n
@@ -1507,17 +1429,21 @@ config FB_PXA_PARAMETERS
1507 1429
1508 <file:Documentation/fb/pxafb.txt> describes the available parameters. 1430 <file:Documentation/fb/pxafb.txt> describes the available parameters.
1509 1431
1510config FB_S1D13XXX 1432config FB_W100
1511 tristate "Epson S1D13XXX framebuffer support" 1433 tristate "W100 frame buffer support"
1512 depends on FB 1434 depends on FB && PXA_SHARPSL
1513 select FB_CFB_FILLRECT 1435 select FB_CFB_FILLRECT
1514 select FB_CFB_COPYAREA 1436 select FB_CFB_COPYAREA
1515 select FB_CFB_IMAGEBLIT 1437 select FB_CFB_IMAGEBLIT
1516 select FB_SOFT_CURSOR 1438 ---help---
1517 help 1439 Frame buffer driver for the w100 as found on the Sharp SL-Cxx series.
1518 Support for S1D13XXX framebuffer device family (currently only 1440
1519 working with S1D13806). Product specs at 1441 This driver is also available as a module ( = code which can be
1520 <http://www.erd.epson.com/vdc/html/legacy_13xxx.htm> 1442 inserted and removed from the running kernel whenever you want). The
1443 module will be called vfb. If you want to compile it as a module,
1444 say M here and read <file:Documentation/modules.txt>.
1445
1446 If unsure, say N.
1521 1447
1522config FB_S3C2410 1448config FB_S3C2410
1523 tristate "S3C2410 LCD framebuffer support" 1449 tristate "S3C2410 LCD framebuffer support"
@@ -1525,7 +1451,6 @@ config FB_S3C2410
1525 select FB_CFB_FILLRECT 1451 select FB_CFB_FILLRECT
1526 select FB_CFB_COPYAREA 1452 select FB_CFB_COPYAREA
1527 select FB_CFB_IMAGEBLIT 1453 select FB_CFB_IMAGEBLIT
1528 select FB_SOFT_CURSOR
1529 ---help--- 1454 ---help---
1530 Frame buffer driver for the built-in LCD controller in the Samsung 1455 Frame buffer driver for the built-in LCD controller in the Samsung
1531 S3C2410 processor. 1456 S3C2410 processor.
@@ -1549,7 +1474,6 @@ config FB_VIRTUAL
1549 select FB_CFB_FILLRECT 1474 select FB_CFB_FILLRECT
1550 select FB_CFB_COPYAREA 1475 select FB_CFB_COPYAREA
1551 select FB_CFB_IMAGEBLIT 1476 select FB_CFB_IMAGEBLIT
1552 select FB_SOFT_CURSOR
1553 ---help--- 1477 ---help---
1554 This is a `virtual' frame buffer device. It operates on a chunk of 1478 This is a `virtual' frame buffer device. It operates on a chunk of
1555 unswappable kernel memory instead of on the memory of a graphics 1479 unswappable kernel memory instead of on the memory of a graphics
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 97c5d03ac8d9..aa434e725c0d 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -16,7 +16,6 @@ fb-objs := $(fb-y)
16obj-$(CONFIG_FB_CFB_FILLRECT) += cfbfillrect.o 16obj-$(CONFIG_FB_CFB_FILLRECT) += cfbfillrect.o
17obj-$(CONFIG_FB_CFB_COPYAREA) += cfbcopyarea.o 17obj-$(CONFIG_FB_CFB_COPYAREA) += cfbcopyarea.o
18obj-$(CONFIG_FB_CFB_IMAGEBLIT) += cfbimgblt.o 18obj-$(CONFIG_FB_CFB_IMAGEBLIT) += cfbimgblt.o
19obj-$(CONFIG_FB_SOFT_CURSOR) += softcursor.o
20obj-$(CONFIG_FB_MACMODES) += macmodes.o 19obj-$(CONFIG_FB_MACMODES) += macmodes.o
21 20
22# Hardware specific drivers go first 21# Hardware specific drivers go first
diff --git a/drivers/video/acornfb.c b/drivers/video/acornfb.c
index 9b6a39348f81..193b482570c7 100644
--- a/drivers/video/acornfb.c
+++ b/drivers/video/acornfb.c
@@ -926,7 +926,6 @@ static struct fb_ops acornfb_ops = {
926 .fb_copyarea = cfb_copyarea, 926 .fb_copyarea = cfb_copyarea,
927 .fb_imageblit = cfb_imageblit, 927 .fb_imageblit = cfb_imageblit,
928 .fb_mmap = acornfb_mmap, 928 .fb_mmap = acornfb_mmap,
929 .fb_cursor = soft_cursor,
930}; 929};
931 930
932/* 931/*
diff --git a/drivers/video/amba-clcd.c b/drivers/video/amba-clcd.c
index 4fc93dc2b4d3..467a1d7ebbde 100644
--- a/drivers/video/amba-clcd.c
+++ b/drivers/video/amba-clcd.c
@@ -333,7 +333,6 @@ static struct fb_ops clcdfb_ops = {
333 .fb_fillrect = cfb_fillrect, 333 .fb_fillrect = cfb_fillrect,
334 .fb_copyarea = cfb_copyarea, 334 .fb_copyarea = cfb_copyarea,
335 .fb_imageblit = cfb_imageblit, 335 .fb_imageblit = cfb_imageblit,
336 .fb_cursor = soft_cursor,
337 .fb_mmap = clcdfb_mmap, 336 .fb_mmap = clcdfb_mmap,
338}; 337};
339 338
diff --git a/drivers/video/amifb.c b/drivers/video/amifb.c
index cf8bb67462dc..d549e215f3c5 100644
--- a/drivers/video/amifb.c
+++ b/drivers/video/amifb.c
@@ -1185,7 +1185,6 @@ static struct fb_ops amifb_ops = {
1185 .fb_fillrect = amifb_fillrect, 1185 .fb_fillrect = amifb_fillrect,
1186 .fb_copyarea = amifb_copyarea, 1186 .fb_copyarea = amifb_copyarea,
1187 .fb_imageblit = amifb_imageblit, 1187 .fb_imageblit = amifb_imageblit,
1188 .fb_cursor = soft_cursor,
1189 .fb_ioctl = amifb_ioctl, 1188 .fb_ioctl = amifb_ioctl,
1190}; 1189};
1191 1190
diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
index 6aa9f824c185..a1fc8bbb1090 100644
--- a/drivers/video/arcfb.c
+++ b/drivers/video/arcfb.c
@@ -511,7 +511,6 @@ static struct fb_ops arcfb_ops = {
511 .fb_fillrect = arcfb_fillrect, 511 .fb_fillrect = arcfb_fillrect,
512 .fb_copyarea = arcfb_copyarea, 512 .fb_copyarea = arcfb_copyarea,
513 .fb_imageblit = arcfb_imageblit, 513 .fb_imageblit = arcfb_imageblit,
514 .fb_cursor = soft_cursor,
515 .fb_ioctl = arcfb_ioctl, 514 .fb_ioctl = arcfb_ioctl,
516}; 515};
517 516
diff --git a/drivers/video/asiliantfb.c b/drivers/video/asiliantfb.c
index f4729f4df8ce..c64de59398f4 100644
--- a/drivers/video/asiliantfb.c
+++ b/drivers/video/asiliantfb.c
@@ -106,7 +106,6 @@ static struct fb_ops asiliantfb_ops = {
106 .fb_fillrect = cfb_fillrect, 106 .fb_fillrect = cfb_fillrect,
107 .fb_copyarea = cfb_copyarea, 107 .fb_copyarea = cfb_copyarea,
108 .fb_imageblit = cfb_imageblit, 108 .fb_imageblit = cfb_imageblit,
109 .fb_cursor = soft_cursor,
110}; 109};
111 110
112/* Calculate the ratios for the dot clocks without using a single long long 111/* Calculate the ratios for the dot clocks without using a single long long
diff --git a/drivers/video/aty/ati_ids.h b/drivers/video/aty/ati_ids.h
index 13321c689cf6..39ab483fc250 100644
--- a/drivers/video/aty/ati_ids.h
+++ b/drivers/video/aty/ati_ids.h
@@ -150,6 +150,7 @@
150#define PCI_CHIP_RV200_QX 0x5158 150#define PCI_CHIP_RV200_QX 0x5158
151#define PCI_CHIP_RV100_QY 0x5159 151#define PCI_CHIP_RV100_QY 0x5159
152#define PCI_CHIP_RV100_QZ 0x515A 152#define PCI_CHIP_RV100_QZ 0x515A
153#define PCI_CHIP_RN50 0x515E
153#define PCI_CHIP_RAGE128RE 0x5245 154#define PCI_CHIP_RAGE128RE 0x5245
154#define PCI_CHIP_RAGE128RF 0x5246 155#define PCI_CHIP_RAGE128RF 0x5246
155#define PCI_CHIP_RAGE128RG 0x5247 156#define PCI_CHIP_RAGE128RG 0x5247
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index e380ee8b0247..e686185a076d 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -478,7 +478,6 @@ static struct fb_ops aty128fb_ops = {
478 .fb_fillrect = cfb_fillrect, 478 .fb_fillrect = cfb_fillrect,
479 .fb_copyarea = cfb_copyarea, 479 .fb_copyarea = cfb_copyarea,
480 .fb_imageblit = cfb_imageblit, 480 .fb_imageblit = cfb_imageblit,
481 .fb_cursor = soft_cursor,
482}; 481};
483 482
484#ifdef CONFIG_PMAC_BACKLIGHT 483#ifdef CONFIG_PMAC_BACKLIGHT
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 037fe9d32fe3..08edbfcfca58 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -292,7 +292,6 @@ static struct fb_ops atyfb_ops = {
292 .fb_fillrect = atyfb_fillrect, 292 .fb_fillrect = atyfb_fillrect,
293 .fb_copyarea = atyfb_copyarea, 293 .fb_copyarea = atyfb_copyarea,
294 .fb_imageblit = atyfb_imageblit, 294 .fb_imageblit = atyfb_imageblit,
295 .fb_cursor = soft_cursor,
296#ifdef __sparc__ 295#ifdef __sparc__
297 .fb_mmap = atyfb_mmap, 296 .fb_mmap = atyfb_mmap,
298#endif 297#endif
@@ -2157,11 +2156,38 @@ static void __init aty_calc_mem_refresh(struct atyfb_par *par, int xclk)
2157 2156
2158static struct fb_info *fb_list = NULL; 2157static struct fb_info *fb_list = NULL;
2159 2158
2159#if defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD)
2160static int __devinit atyfb_get_timings_from_lcd(struct atyfb_par *par,
2161 struct fb_var_screeninfo *var)
2162{
2163 int ret = -EINVAL;
2164
2165 if (par->lcd_table != 0 && (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
2166 *var = default_var;
2167 var->xres = var->xres_virtual = par->lcd_hdisp;
2168 var->right_margin = par->lcd_right_margin;
2169 var->left_margin = par->lcd_hblank_len -
2170 (par->lcd_right_margin + par->lcd_hsync_dly +
2171 par->lcd_hsync_len);
2172 var->hsync_len = par->lcd_hsync_len + par->lcd_hsync_dly;
2173 var->yres = var->yres_virtual = par->lcd_vdisp;
2174 var->lower_margin = par->lcd_lower_margin;
2175 var->upper_margin = par->lcd_vblank_len -
2176 (par->lcd_lower_margin + par->lcd_vsync_len);
2177 var->vsync_len = par->lcd_vsync_len;
2178 var->pixclock = par->lcd_pixclock;
2179 ret = 0;
2180 }
2181
2182 return ret;
2183}
2184#endif /* defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD) */
2185
2160static int __init aty_init(struct fb_info *info, const char *name) 2186static int __init aty_init(struct fb_info *info, const char *name)
2161{ 2187{
2162 struct atyfb_par *par = (struct atyfb_par *) info->par; 2188 struct atyfb_par *par = (struct atyfb_par *) info->par;
2163 const char *ramname = NULL, *xtal; 2189 const char *ramname = NULL, *xtal;
2164 int gtb_memsize; 2190 int gtb_memsize, has_var = 0;
2165 struct fb_var_screeninfo var; 2191 struct fb_var_screeninfo var;
2166 u8 pll_ref_div; 2192 u8 pll_ref_div;
2167 u32 i; 2193 u32 i;
@@ -2469,8 +2495,8 @@ static int __init aty_init(struct fb_info *info, const char *name)
2469 * applies to all Mac video cards 2495 * applies to all Mac video cards
2470 */ 2496 */
2471 if (mode) { 2497 if (mode) {
2472 if (!mac_find_mode(&var, info, mode, 8)) 2498 if (mac_find_mode(&var, info, mode, 8))
2473 var = default_var; 2499 has_var = 1;
2474 } else { 2500 } else {
2475 if (default_vmode == VMODE_CHOOSE) { 2501 if (default_vmode == VMODE_CHOOSE) {
2476 if (M64_HAS(G3_PB_1024x768)) 2502 if (M64_HAS(G3_PB_1024x768))
@@ -2492,20 +2518,23 @@ static int __init aty_init(struct fb_info *info, const char *name)
2492 default_vmode = VMODE_640_480_60; 2518 default_vmode = VMODE_640_480_60;
2493 if (default_cmode < CMODE_8 || default_cmode > CMODE_32) 2519 if (default_cmode < CMODE_8 || default_cmode > CMODE_32)
2494 default_cmode = CMODE_8; 2520 default_cmode = CMODE_8;
2495 if (mac_vmode_to_var(default_vmode, default_cmode, &var)) 2521 if (!mac_vmode_to_var(default_vmode, default_cmode,
2496 var = default_var; 2522 &var))
2523 has_var = 1;
2497 } 2524 }
2498 } else 2525 }
2526
2499#endif /* !CONFIG_PPC */ 2527#endif /* !CONFIG_PPC */
2500 if ( 2528
2501#if defined(CONFIG_SPARC32) || defined(CONFIG_SPARC64) 2529#if defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD)
2502 /* On Sparc, unless the user gave a specific mode 2530 if (!atyfb_get_timings_from_lcd(par, &var))
2503 * specification, use the PROM probed values in 2531 has_var = 1;
2504 * default_var.
2505 */
2506 !mode ||
2507#endif 2532#endif
2508 !fb_find_mode(&var, info, mode, NULL, 0, &defmode, 8)) 2533
2534 if (mode && fb_find_mode(&var, info, mode, NULL, 0, &defmode, 8))
2535 has_var = 1;
2536
2537 if (!has_var)
2509 var = default_var; 2538 var = default_var;
2510 2539
2511 if (noaccel) 2540 if (noaccel)
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index 8a24a66d9ba8..4f01ccc02aa4 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -69,7 +69,6 @@
69#include <linux/pci.h> 69#include <linux/pci.h>
70#include <linux/vmalloc.h> 70#include <linux/vmalloc.h>
71#include <linux/device.h> 71#include <linux/device.h>
72#include <linux/i2c.h>
73 72
74#include <asm/io.h> 73#include <asm/io.h>
75#include <asm/uaccess.h> 74#include <asm/uaccess.h>
@@ -113,6 +112,7 @@ static struct pci_device_id radeonfb_pci_table[] = {
113 /* Radeon VE/7000 */ 112 /* Radeon VE/7000 */
114 CHIP_DEF(PCI_CHIP_RV100_QY, RV100, CHIP_HAS_CRTC2), 113 CHIP_DEF(PCI_CHIP_RV100_QY, RV100, CHIP_HAS_CRTC2),
115 CHIP_DEF(PCI_CHIP_RV100_QZ, RV100, CHIP_HAS_CRTC2), 114 CHIP_DEF(PCI_CHIP_RV100_QZ, RV100, CHIP_HAS_CRTC2),
115 CHIP_DEF(PCI_CHIP_RN50, RV100, CHIP_HAS_CRTC2),
116 /* Radeon IGP320M (U1) */ 116 /* Radeon IGP320M (U1) */
117 CHIP_DEF(PCI_CHIP_RS100_4336, RS100, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY), 117 CHIP_DEF(PCI_CHIP_RS100_4336, RS100, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
118 /* Radeon IGP320 (A3) */ 118 /* Radeon IGP320 (A3) */
@@ -1874,7 +1874,6 @@ static struct fb_ops radeonfb_ops = {
1874 .fb_fillrect = radeonfb_fillrect, 1874 .fb_fillrect = radeonfb_fillrect,
1875 .fb_copyarea = radeonfb_copyarea, 1875 .fb_copyarea = radeonfb_copyarea,
1876 .fb_imageblit = radeonfb_imageblit, 1876 .fb_imageblit = radeonfb_imageblit,
1877 .fb_cursor = soft_cursor,
1878}; 1877};
1879 1878
1880 1879
diff --git a/drivers/video/aty/radeonfb.h b/drivers/video/aty/radeonfb.h
index 01b8b2f78514..217e00ab4a2d 100644
--- a/drivers/video/aty/radeonfb.h
+++ b/drivers/video/aty/radeonfb.h
@@ -10,9 +10,10 @@
10#include <linux/fb.h> 10#include <linux/fb.h>
11 11
12 12
13#ifdef CONFIG_FB_RADEON_I2C
13#include <linux/i2c.h> 14#include <linux/i2c.h>
14#include <linux/i2c-id.h>
15#include <linux/i2c-algo-bit.h> 15#include <linux/i2c-algo-bit.h>
16#endif
16 17
17#include <asm/io.h> 18#include <asm/io.h>
18 19
diff --git a/drivers/video/bw2.c b/drivers/video/bw2.c
index 3d20b2d47d46..f53bf3ba1278 100644
--- a/drivers/video/bw2.c
+++ b/drivers/video/bw2.c
@@ -51,7 +51,6 @@ static struct fb_ops bw2_ops = {
51 .fb_imageblit = cfb_imageblit, 51 .fb_imageblit = cfb_imageblit,
52 .fb_mmap = bw2_mmap, 52 .fb_mmap = bw2_mmap,
53 .fb_ioctl = bw2_ioctl, 53 .fb_ioctl = bw2_ioctl,
54 .fb_cursor = soft_cursor,
55}; 54};
56 55
57/* OBio addresses for the bwtwo registers */ 56/* OBio addresses for the bwtwo registers */
diff --git a/drivers/video/cfbcopyarea.c b/drivers/video/cfbcopyarea.c
index 67711f7b11b1..cdc71572cf35 100644
--- a/drivers/video/cfbcopyarea.c
+++ b/drivers/video/cfbcopyarea.c
@@ -349,46 +349,10 @@ void cfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
349 unsigned long __iomem *dst = NULL, *src = NULL; 349 unsigned long __iomem *dst = NULL, *src = NULL;
350 int bits = BITS_PER_LONG, bytes = bits >> 3; 350 int bits = BITS_PER_LONG, bytes = bits >> 3;
351 int dst_idx = 0, src_idx = 0, rev_copy = 0; 351 int dst_idx = 0, src_idx = 0, rev_copy = 0;
352 int x2, y2, vxres, vyres;
353 352
354 if (p->state != FBINFO_STATE_RUNNING) 353 if (p->state != FBINFO_STATE_RUNNING)
355 return; 354 return;
356 355
357 /* We want rotation but lack hardware to do it for us. */
358 if (!p->fbops->fb_rotate && p->var.rotate) {
359 }
360
361 vxres = p->var.xres_virtual;
362 vyres = p->var.yres_virtual;
363
364 if (area->dx > vxres || area->sx > vxres ||
365 area->dy > vyres || area->sy > vyres)
366 return;
367
368 /* clip the destination
369 * We could use hardware clipping but on many cards you get around
370 * hardware clipping by writing to framebuffer directly.
371 */
372 x2 = area->dx + area->width;
373 y2 = area->dy + area->height;
374 dx = area->dx > 0 ? area->dx : 0;
375 dy = area->dy > 0 ? area->dy : 0;
376 x2 = x2 < vxres ? x2 : vxres;
377 y2 = y2 < vyres ? y2 : vyres;
378 width = x2 - dx;
379 height = y2 - dy;
380
381 if ((width==0) ||(height==0))
382 return;
383
384 /* update sx1,sy1 */
385 sx += (dx - area->dx);
386 sy += (dy - area->dy);
387
388 /* the source must be completely inside the virtual screen */
389 if (sx < 0 || sy < 0 || (sx + width) > vxres || (sy + height) > vyres)
390 return;
391
392 /* if the beginning of the target area might overlap with the end of 356 /* if the beginning of the target area might overlap with the end of
393 the source area, be have to copy the area reverse. */ 357 the source area, be have to copy the area reverse. */
394 if ((dy == sy && dx > sx) || (dy > sy)) { 358 if ((dy == sy && dx > sx) || (dy > sy)) {
diff --git a/drivers/video/cfbfillrect.c b/drivers/video/cfbfillrect.c
index e4fc42b013eb..167d9314e6eb 100644
--- a/drivers/video/cfbfillrect.c
+++ b/drivers/video/cfbfillrect.c
@@ -344,7 +344,8 @@ bitfill_unaligned_rev(unsigned long __iomem *dst, int dst_idx, unsigned long pat
344 344
345void cfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect) 345void cfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
346{ 346{
347 unsigned long x2, y2, vxres, vyres, height, width, pat, fg; 347 unsigned long pat, fg;
348 unsigned long width = rect->width, height = rect->height;
348 int bits = BITS_PER_LONG, bytes = bits >> 3; 349 int bits = BITS_PER_LONG, bytes = bits >> 3;
349 u32 bpp = p->var.bits_per_pixel; 350 u32 bpp = p->var.bits_per_pixel;
350 unsigned long __iomem *dst; 351 unsigned long __iomem *dst;
@@ -353,27 +354,6 @@ void cfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
353 if (p->state != FBINFO_STATE_RUNNING) 354 if (p->state != FBINFO_STATE_RUNNING)
354 return; 355 return;
355 356
356 /* We want rotation but lack hardware to do it for us. */
357 if (!p->fbops->fb_rotate && p->var.rotate) {
358 }
359
360 vxres = p->var.xres_virtual;
361 vyres = p->var.yres_virtual;
362
363 if (!rect->width || !rect->height ||
364 rect->dx > vxres || rect->dy > vyres)
365 return;
366
367 /* We could use hardware clipping but on many cards you get around
368 * hardware clipping by writing to framebuffer directly. */
369
370 x2 = rect->dx + rect->width;
371 y2 = rect->dy + rect->height;
372 x2 = x2 < vxres ? x2 : vxres;
373 y2 = y2 < vyres ? y2 : vyres;
374 width = x2 - rect->dx;
375 height = y2 - rect->dy;
376
377 if (p->fix.visual == FB_VISUAL_TRUECOLOR || 357 if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
378 p->fix.visual == FB_VISUAL_DIRECTCOLOR ) 358 p->fix.visual == FB_VISUAL_DIRECTCOLOR )
379 fg = ((u32 *) (p->pseudo_palette))[rect->color]; 359 fg = ((u32 *) (p->pseudo_palette))[rect->color];
diff --git a/drivers/video/cfbimgblt.c b/drivers/video/cfbimgblt.c
index 4c123abaa843..da664cea7eca 100644
--- a/drivers/video/cfbimgblt.c
+++ b/drivers/video/cfbimgblt.c
@@ -272,33 +272,13 @@ void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
272{ 272{
273 u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0; 273 u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
274 u32 bpl = sizeof(u32), bpp = p->var.bits_per_pixel; 274 u32 bpl = sizeof(u32), bpp = p->var.bits_per_pixel;
275 u32 width = image->width, height = image->height; 275 u32 width = image->width;
276 u32 dx = image->dx, dy = image->dy; 276 u32 dx = image->dx, dy = image->dy;
277 int x2, y2, vxres, vyres;
278 u8 __iomem *dst1; 277 u8 __iomem *dst1;
279 278
280 if (p->state != FBINFO_STATE_RUNNING) 279 if (p->state != FBINFO_STATE_RUNNING)
281 return; 280 return;
282 281
283 vxres = p->var.xres_virtual;
284 vyres = p->var.yres_virtual;
285 /*
286 * We could use hardware clipping but on many cards you get around
287 * hardware clipping by writing to framebuffer directly like we are
288 * doing here.
289 */
290 if (image->dx > vxres || image->dy > vyres)
291 return;
292
293 x2 = image->dx + image->width;
294 y2 = image->dy + image->height;
295 dx = image->dx > 0 ? image->dx : 0;
296 dy = image->dy > 0 ? image->dy : 0;
297 x2 = x2 < vxres ? x2 : vxres;
298 y2 = y2 < vyres ? y2 : vyres;
299 width = x2 - dx;
300 height = y2 - dy;
301
302 bitstart = (dy * p->fix.line_length * 8) + (dx * bpp); 282 bitstart = (dy * p->fix.line_length * 8) + (dx * bpp);
303 start_index = bitstart & (32 - 1); 283 start_index = bitstart & (32 - 1);
304 pitch_index = (p->fix.line_length & (bpl - 1)) * 8; 284 pitch_index = (p->fix.line_length & (bpl - 1)) * 8;
diff --git a/drivers/video/cg14.c b/drivers/video/cg14.c
index 18e60b941e21..030d4b13b1c2 100644
--- a/drivers/video/cg14.c
+++ b/drivers/video/cg14.c
@@ -49,7 +49,6 @@ static struct fb_ops cg14_ops = {
49 .fb_imageblit = cfb_imageblit, 49 .fb_imageblit = cfb_imageblit,
50 .fb_mmap = cg14_mmap, 50 .fb_mmap = cg14_mmap,
51 .fb_ioctl = cg14_ioctl, 51 .fb_ioctl = cg14_ioctl,
52 .fb_cursor = soft_cursor,
53}; 52};
54 53
55#define CG14_MCR_INTENABLE_SHIFT 7 54#define CG14_MCR_INTENABLE_SHIFT 7
diff --git a/drivers/video/cg3.c b/drivers/video/cg3.c
index 6e7d8d45dc68..b94eee8c42d5 100644
--- a/drivers/video/cg3.c
+++ b/drivers/video/cg3.c
@@ -50,7 +50,6 @@ static struct fb_ops cg3_ops = {
50 .fb_imageblit = cfb_imageblit, 50 .fb_imageblit = cfb_imageblit,
51 .fb_mmap = cg3_mmap, 51 .fb_mmap = cg3_mmap,
52 .fb_ioctl = cg3_ioctl, 52 .fb_ioctl = cg3_ioctl,
53 .fb_cursor = soft_cursor,
54}; 53};
55 54
56 55
diff --git a/drivers/video/cg6.c b/drivers/video/cg6.c
index 49a2545671d9..414c4409e924 100644
--- a/drivers/video/cg6.c
+++ b/drivers/video/cg6.c
@@ -54,7 +54,6 @@ static struct fb_ops cg6_ops = {
54 .fb_sync = cg6_sync, 54 .fb_sync = cg6_sync,
55 .fb_mmap = cg6_mmap, 55 .fb_mmap = cg6_mmap,
56 .fb_ioctl = cg6_ioctl, 56 .fb_ioctl = cg6_ioctl,
57 .fb_cursor = soft_cursor,
58}; 57};
59 58
60/* Offset of interesting structures in the OBIO space */ 59/* Offset of interesting structures in the OBIO space */
@@ -654,12 +653,6 @@ static void cg6_chip_init(struct fb_info *info)
654 sbus_writel(0, &fbc->clipminy); 653 sbus_writel(0, &fbc->clipminy);
655 sbus_writel(info->var.xres - 1, &fbc->clipmaxx); 654 sbus_writel(info->var.xres - 1, &fbc->clipmaxx);
656 sbus_writel(info->var.yres - 1, &fbc->clipmaxy); 655 sbus_writel(info->var.yres - 1, &fbc->clipmaxy);
657
658 /* Disable cursor in Brooktree DAC. */
659 sbus_writel(0x06 << 24, &par->bt->addr);
660 tmp = sbus_readl(&par->bt->control);
661 tmp &= ~(0x03 << 24);
662 sbus_writel(tmp, &par->bt->control);
663} 656}
664 657
665struct all_info { 658struct all_info {
diff --git a/drivers/video/chipsfb.c b/drivers/video/chipsfb.c
index 4131243cfdf8..bc061d4ec786 100644
--- a/drivers/video/chipsfb.c
+++ b/drivers/video/chipsfb.c
@@ -91,7 +91,6 @@ static struct fb_ops chipsfb_ops = {
91 .fb_fillrect = cfb_fillrect, 91 .fb_fillrect = cfb_fillrect,
92 .fb_copyarea = cfb_copyarea, 92 .fb_copyarea = cfb_copyarea,
93 .fb_imageblit = cfb_imageblit, 93 .fb_imageblit = cfb_imageblit,
94 .fb_cursor = soft_cursor,
95}; 94};
96 95
97static int chipsfb_check_var(struct fb_var_screeninfo *var, 96static int chipsfb_check_var(struct fb_var_screeninfo *var,
diff --git a/drivers/video/cirrusfb.c b/drivers/video/cirrusfb.c
index 3a26f9cc8585..2858c5c8ba3c 100644
--- a/drivers/video/cirrusfb.c
+++ b/drivers/video/cirrusfb.c
@@ -548,7 +548,6 @@ static struct fb_ops cirrusfb_ops = {
548 .fb_fillrect = cirrusfb_fillrect, 548 .fb_fillrect = cirrusfb_fillrect,
549 .fb_copyarea = cirrusfb_copyarea, 549 .fb_copyarea = cirrusfb_copyarea,
550 .fb_imageblit = cirrusfb_imageblit, 550 .fb_imageblit = cirrusfb_imageblit,
551 .fb_cursor = soft_cursor,
552}; 551};
553 552
554/*--- Hardware Specific Routines -------------------------------------------*/ 553/*--- Hardware Specific Routines -------------------------------------------*/
diff --git a/drivers/video/clps711xfb.c b/drivers/video/clps711xfb.c
index 8692e002986b..50b78af0fa24 100644
--- a/drivers/video/clps711xfb.c
+++ b/drivers/video/clps711xfb.c
@@ -219,7 +219,6 @@ static struct fb_ops clps7111fb_ops = {
219 .fb_fillrect = cfb_fillrect, 219 .fb_fillrect = cfb_fillrect,
220 .fb_copyarea = cfb_copyarea, 220 .fb_copyarea = cfb_copyarea,
221 .fb_imageblit = cfb_imageblit, 221 .fb_imageblit = cfb_imageblit,
222 .fb_cursor = soft_cursor,
223}; 222};
224 223
225static int 224static int
diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig
index 6a9ae2b3d1ab..fadf7c5d216e 100644
--- a/drivers/video/console/Kconfig
+++ b/drivers/video/console/Kconfig
@@ -98,6 +98,8 @@ config FRAMEBUFFER_CONSOLE
98 tristate "Framebuffer Console support" 98 tristate "Framebuffer Console support"
99 depends on FB 99 depends on FB
100 select CRC32 100 select CRC32
101 help
102 Low-level framebuffer-based console driver.
101 103
102config STI_CONSOLE 104config STI_CONSOLE
103 tristate "STI text console" 105 tristate "STI text console"
@@ -203,5 +205,12 @@ config FONT_10x18
203 big letters. It fits between the sun 12x22 and the normal 8x16 font. 205 big letters. It fits between the sun 12x22 and the normal 8x16 font.
204 If other fonts are too big or too small for you, say Y, otherwise say N. 206 If other fonts are too big or too small for you, say Y, otherwise say N.
205 207
208config FONT_RL
209 bool "console Roman Large 8x16 font" if FONTS
210 depends on FRAMEBUFFER_CONSOLE
211 help
212 This is the visually-appealing "RL" console font that is
213 included with the kbd package.
214
206endmenu 215endmenu
207 216
diff --git a/drivers/video/console/Makefile b/drivers/video/console/Makefile
index 42c7b8dcd220..5222628accce 100644
--- a/drivers/video/console/Makefile
+++ b/drivers/video/console/Makefile
@@ -15,6 +15,7 @@ font-objs-$(CONFIG_FONT_10x18) += font_10x18.o
15font-objs-$(CONFIG_FONT_PEARL_8x8) += font_pearl_8x8.o 15font-objs-$(CONFIG_FONT_PEARL_8x8) += font_pearl_8x8.o
16font-objs-$(CONFIG_FONT_ACORN_8x8) += font_acorn_8x8.o 16font-objs-$(CONFIG_FONT_ACORN_8x8) += font_acorn_8x8.o
17font-objs-$(CONFIG_FONT_MINI_4x6) += font_mini_4x6.o 17font-objs-$(CONFIG_FONT_MINI_4x6) += font_mini_4x6.o
18font-objs-$(CONFIG_FONT_RL) += font_rl.o
18 19
19font-objs += $(font-objs-y) 20font-objs += $(font-objs-y)
20 21
@@ -26,7 +27,7 @@ obj-$(CONFIG_PROM_CONSOLE) += promcon.o promcon_tbl.o
26obj-$(CONFIG_STI_CONSOLE) += sticon.o sticore.o font.o 27obj-$(CONFIG_STI_CONSOLE) += sticon.o sticore.o font.o
27obj-$(CONFIG_VGA_CONSOLE) += vgacon.o 28obj-$(CONFIG_VGA_CONSOLE) += vgacon.o
28obj-$(CONFIG_MDA_CONSOLE) += mdacon.o 29obj-$(CONFIG_MDA_CONSOLE) += mdacon.o
29obj-$(CONFIG_FRAMEBUFFER_CONSOLE) += fbcon.o bitblit.o font.o 30obj-$(CONFIG_FRAMEBUFFER_CONSOLE) += fbcon.o bitblit.o font.o softcursor.o
30ifeq ($(CONFIG_FB_TILEBLITTING),y) 31ifeq ($(CONFIG_FB_TILEBLITTING),y)
31obj-$(CONFIG_FRAMEBUFFER_CONSOLE) += tileblit.o 32obj-$(CONFIG_FRAMEBUFFER_CONSOLE) += tileblit.o
32endif 33endif
diff --git a/drivers/video/console/bitblit.c b/drivers/video/console/bitblit.c
index 9f70e512b88b..67857b3cfc8b 100644
--- a/drivers/video/console/bitblit.c
+++ b/drivers/video/console/bitblit.c
@@ -272,6 +272,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info,
272 int w = (vc->vc_font.width + 7) >> 3, c; 272 int w = (vc->vc_font.width + 7) >> 3, c;
273 int y = real_y(p, vc->vc_y); 273 int y = real_y(p, vc->vc_y);
274 int attribute, use_sw = (vc->vc_cursor_type & 0x10); 274 int attribute, use_sw = (vc->vc_cursor_type & 0x10);
275 int err = 1;
275 char *src; 276 char *src;
276 277
277 cursor.set = 0; 278 cursor.set = 0;
@@ -408,7 +409,11 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info,
408 cursor.image.depth = 1; 409 cursor.image.depth = 1;
409 cursor.rop = ROP_XOR; 410 cursor.rop = ROP_XOR;
410 411
411 info->fbops->fb_cursor(info, &cursor); 412 if (info->fbops->fb_cursor)
413 err = info->fbops->fb_cursor(info, &cursor);
414
415 if (err)
416 soft_cursor(info, &cursor);
412 417
413 ops->cursor_reset = 0; 418 ops->cursor_reset = 0;
414} 419}
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 0fc8bb499c3f..3cf1b61ff1f8 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -281,6 +281,18 @@ static inline int get_color(struct vc_data *vc, struct fb_info *info,
281 return color; 281 return color;
282} 282}
283 283
284static void fbcon_update_softback(struct vc_data *vc)
285{
286 int l = fbcon_softback_size / vc->vc_size_row;
287
288 if (l > 5)
289 softback_end = softback_buf + l * vc->vc_size_row;
290 else
291 /* Smaller scrollback makes no sense, and 0 would screw
292 the operation totally */
293 softback_top = 0;
294}
295
284static void fb_flashcursor(void *private) 296static void fb_flashcursor(void *private)
285{ 297{
286 struct fb_info *info = private; 298 struct fb_info *info = private;
@@ -618,6 +630,15 @@ static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
618 kfree(oldinfo->fbcon_par); 630 kfree(oldinfo->fbcon_par);
619 oldinfo->fbcon_par = NULL; 631 oldinfo->fbcon_par = NULL;
620 module_put(oldinfo->fbops->owner); 632 module_put(oldinfo->fbops->owner);
633 /*
634 If oldinfo and newinfo are driving the same hardware,
635 the fb_release() method of oldinfo may attempt to
636 restore the hardware state. This will leave the
637 newinfo in an undefined state. Thus, a call to
638 fb_set_par() may be needed for the newinfo.
639 */
640 if (newinfo->fbops->fb_set_par)
641 newinfo->fbops->fb_set_par(newinfo);
621 } 642 }
622 643
623 return err; 644 return err;
@@ -1007,16 +1028,8 @@ static void fbcon_init(struct vc_data *vc, int init)
1007 if (logo) 1028 if (logo)
1008 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows); 1029 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1009 1030
1010 if (vc == svc && softback_buf) { 1031 if (vc == svc && softback_buf)
1011 int l = fbcon_softback_size / vc->vc_size_row; 1032 fbcon_update_softback(vc);
1012 if (l > 5)
1013 softback_end = softback_buf + l * vc->vc_size_row;
1014 else {
1015 /* Smaller scrollback makes no sense, and 0 would screw
1016 the operation totally */
1017 softback_top = 0;
1018 }
1019 }
1020} 1033}
1021 1034
1022static void fbcon_deinit(struct vc_data *vc) 1035static void fbcon_deinit(struct vc_data *vc)
@@ -1223,18 +1236,8 @@ static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1223 vc_resize(vc, cols, rows); 1236 vc_resize(vc, cols, rows);
1224 if (CON_IS_VISIBLE(vc)) { 1237 if (CON_IS_VISIBLE(vc)) {
1225 update_screen(vc); 1238 update_screen(vc);
1226 if (softback_buf) { 1239 if (softback_buf)
1227 int l = fbcon_softback_size / vc->vc_size_row; 1240 fbcon_update_softback(vc);
1228
1229 if (l > 5)
1230 softback_end = softback_buf + l *
1231 vc->vc_size_row;
1232 else {
1233 /* Smaller scrollback makes no sense, and 0
1234 would screw the operation totally */
1235 softback_top = 0;
1236 }
1237 }
1238 } 1241 }
1239} 1242}
1240 1243
@@ -1892,24 +1895,11 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width,
1892 mode = fb_find_best_mode(&var, &info->modelist); 1895 mode = fb_find_best_mode(&var, &info->modelist);
1893 if (mode == NULL) 1896 if (mode == NULL)
1894 return -EINVAL; 1897 return -EINVAL;
1898 display_to_var(&var, p);
1895 fb_videomode_to_var(&var, mode); 1899 fb_videomode_to_var(&var, mode);
1900
1896 if (width > var.xres/fw || height > var.yres/fh) 1901 if (width > var.xres/fw || height > var.yres/fh)
1897 return -EINVAL; 1902 return -EINVAL;
1898 /*
1899 * The following can probably have any value... Do we need to
1900 * set all of them?
1901 */
1902 var.bits_per_pixel = p->bits_per_pixel;
1903 var.xres_virtual = p->xres_virtual;
1904 var.yres_virtual = p->yres_virtual;
1905 var.accel_flags = p->accel_flags;
1906 var.width = p->width;
1907 var.height = p->height;
1908 var.red = p->red;
1909 var.green = p->green;
1910 var.blue = p->blue;
1911 var.transp = p->transp;
1912 var.nonstd = p->nonstd;
1913 1903
1914 DPRINTK("resize now %ix%i\n", var.xres, var.yres); 1904 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
1915 if (CON_IS_VISIBLE(vc)) { 1905 if (CON_IS_VISIBLE(vc)) {
@@ -1933,19 +1923,11 @@ static int fbcon_switch(struct vc_data *vc)
1933 info = registered_fb[con2fb_map[vc->vc_num]]; 1923 info = registered_fb[con2fb_map[vc->vc_num]];
1934 1924
1935 if (softback_top) { 1925 if (softback_top) {
1936 int l = fbcon_softback_size / vc->vc_size_row;
1937 if (softback_lines) 1926 if (softback_lines)
1938 fbcon_set_origin(vc); 1927 fbcon_set_origin(vc);
1939 softback_top = softback_curr = softback_in = softback_buf; 1928 softback_top = softback_curr = softback_in = softback_buf;
1940 softback_lines = 0; 1929 softback_lines = 0;
1941 1930 fbcon_update_softback(vc);
1942 if (l > 5)
1943 softback_end = softback_buf + l * vc->vc_size_row;
1944 else {
1945 /* Smaller scrollback makes no sense, and 0 would screw
1946 the operation totally */
1947 softback_top = 0;
1948 }
1949 } 1931 }
1950 1932
1951 if (logo_shown >= 0) { 1933 if (logo_shown >= 0) {
@@ -2235,17 +2217,8 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2235 /* reset wrap/pan */ 2217 /* reset wrap/pan */
2236 info->var.xoffset = info->var.yoffset = p->yscroll = 0; 2218 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
2237 vc_resize(vc, info->var.xres / w, info->var.yres / h); 2219 vc_resize(vc, info->var.xres / w, info->var.yres / h);
2238 if (CON_IS_VISIBLE(vc) && softback_buf) { 2220 if (CON_IS_VISIBLE(vc) && softback_buf)
2239 int l = fbcon_softback_size / vc->vc_size_row; 2221 fbcon_update_softback(vc);
2240 if (l > 5)
2241 softback_end =
2242 softback_buf + l * vc->vc_size_row;
2243 else {
2244 /* Smaller scrollback makes no sense, and 0 would screw
2245 the operation totally */
2246 softback_top = 0;
2247 }
2248 }
2249 } else if (CON_IS_VISIBLE(vc) 2222 } else if (CON_IS_VISIBLE(vc)
2250 && vc->vc_mode == KD_TEXT) { 2223 && vc->vc_mode == KD_TEXT) {
2251 fbcon_clear_margins(vc, 0); 2224 fbcon_clear_margins(vc, 0);
@@ -2615,16 +2588,8 @@ static void fbcon_modechanged(struct fb_info *info)
2615 update_var(vc->vc_num, info); 2588 update_var(vc->vc_num, info);
2616 fbcon_set_palette(vc, color_table); 2589 fbcon_set_palette(vc, color_table);
2617 update_screen(vc); 2590 update_screen(vc);
2618 if (softback_buf) { 2591 if (softback_buf)
2619 int l = fbcon_softback_size / vc->vc_size_row; 2592 fbcon_update_softback(vc);
2620 if (l > 5)
2621 softback_end = softback_buf + l * vc->vc_size_row;
2622 else {
2623 /* Smaller scrollback makes no sense, and 0
2624 would screw the operation totally */
2625 softback_top = 0;
2626 }
2627 }
2628 } 2593 }
2629} 2594}
2630 2595
@@ -2659,16 +2624,8 @@ static void fbcon_set_all_vcs(struct fb_info *info)
2659 update_var(vc->vc_num, info); 2624 update_var(vc->vc_num, info);
2660 fbcon_set_palette(vc, color_table); 2625 fbcon_set_palette(vc, color_table);
2661 update_screen(vc); 2626 update_screen(vc);
2662 if (softback_buf) { 2627 if (softback_buf)
2663 int l = fbcon_softback_size / vc->vc_size_row; 2628 fbcon_update_softback(vc);
2664 if (l > 5)
2665 softback_end = softback_buf + l * vc->vc_size_row;
2666 else {
2667 /* Smaller scrollback makes no sense, and 0
2668 would screw the operation totally */
2669 softback_top = 0;
2670 }
2671 }
2672 } 2629 }
2673 } 2630 }
2674} 2631}
@@ -2758,7 +2715,8 @@ static void fbcon_new_modelist(struct fb_info *info)
2758 continue; 2715 continue;
2759 vc = vc_cons[i].d; 2716 vc = vc_cons[i].d;
2760 display_to_var(&var, &fb_display[i]); 2717 display_to_var(&var, &fb_display[i]);
2761 mode = fb_find_nearest_mode(&var, &info->modelist); 2718 mode = fb_find_nearest_mode(fb_display[i].mode,
2719 &info->modelist);
2762 fb_videomode_to_var(&var, mode); 2720 fb_videomode_to_var(&var, mode);
2763 2721
2764 if (vc) 2722 if (vc)
diff --git a/drivers/video/console/fbcon.h b/drivers/video/console/fbcon.h
index 0738cd62def2..b68e0e2c2d16 100644
--- a/drivers/video/console/fbcon.h
+++ b/drivers/video/console/fbcon.h
@@ -167,5 +167,5 @@ extern void fbcon_set_tileops(struct vc_data *vc, struct fb_info *info,
167 struct display *p, struct fbcon_ops *ops); 167 struct display *p, struct fbcon_ops *ops);
168#endif 168#endif
169extern void fbcon_set_bitops(struct fbcon_ops *ops); 169extern void fbcon_set_bitops(struct fbcon_ops *ops);
170 170extern int soft_cursor(struct fb_info *info, struct fb_cursor *cursor);
171#endif /* _VIDEO_FBCON_H */ 171#endif /* _VIDEO_FBCON_H */
diff --git a/drivers/video/console/font_rl.c b/drivers/video/console/font_rl.c
new file mode 100644
index 000000000000..dfecc27d8ded
--- /dev/null
+++ b/drivers/video/console/font_rl.c
@@ -0,0 +1,4374 @@
1
2/* This font is simply the "rl.fnt" console font from the kbd utility.
3 * Converted by Zack T Smith, fbui@comcast.net.
4 * The original binary file is covered under the GNU Public License.
5 */
6
7#include <linux/font.h>
8
9#define FONTDATAMAX 4096
10
11static unsigned char patterns[4096] = {
120x00,
130x00,
140x00,
150x00,
160x00,
170x00,
180x00,
190x00,
200x00,
210x00,
220x00,
230x00,
240x00,
250x00,
260x00,
270x00,
28
290x00,
300x00,
310x3c,
320x42,
330x81,
340xe7,
350xa5,
360x99,
370x81,
380x81,
390x99,
400x42,
410x3c,
420x00,
430x00,
440x00,
45
460x00,
470x00,
480x3c,
490x7e,
500xff,
510x99,
520xdb,
530xe7,
540xff,
550xff,
560xe7,
570x7e,
580x3c,
590x00,
600x00,
610x00,
62
630x00,
640x00,
650x00,
660x6c,
670xfe,
680xfe,
690xfe,
700xfe,
710xfe,
720x7c,
730x38,
740x10,
750x00,
760x00,
770x00,
780x00,
79
800x00,
810x00,
820x00,
830x00,
840x10,
850x38,
860x7c,
870xfe,
880x7c,
890x38,
900x10,
910x00,
920x00,
930x00,
940x00,
950x00,
96
970x00,
980x00,
990x38,
1000x38,
1010x10,
1020xd6,
1030xfe,
1040xd6,
1050x10,
1060x10,
1070x38,
1080x7c,
1090x00,
1100x00,
1110x00,
1120x00,
113
1140x00,
1150x00,
1160x10,
1170x38,
1180x7c,
1190xfe,
1200xfe,
1210x54,
1220x10,
1230x10,
1240x38,
1250x7c,
1260x00,
1270x00,
1280x00,
1290x00,
130
1310x00,
1320x00,
1330x00,
1340x00,
1350x00,
1360x00,
1370x18,
1380x3c,
1390x3c,
1400x18,
1410x00,
1420x00,
1430x00,
1440x00,
1450x00,
1460x00,
147
1480xff,
1490xff,
1500xff,
1510xff,
1520xff,
1530xff,
1540xe7,
1550xc3,
1560xc3,
1570xe7,
1580xff,
1590xff,
1600xff,
1610xff,
1620xff,
1630xff,
164
1650x00,
1660x00,
1670x00,
1680x00,
1690x00,
1700x3c,
1710x66,
1720x42,
1730x42,
1740x66,
1750x3c,
1760x00,
1770x00,
1780x00,
1790x00,
1800x00,
181
1820xff,
1830xff,
1840xff,
1850xff,
1860xff,
1870xc3,
1880x99,
1890xbd,
1900xbd,
1910x99,
1920xc3,
1930xff,
1940xff,
1950xff,
1960xff,
1970xff,
198
1990x00,
2000x00,
2010x0f,
2020x07,
2030x0d,
2040x18,
2050x78,
2060xcc,
2070xcc,
2080xcc,
2090xcc,
2100x78,
2110x00,
2120x00,
2130x00,
2140x00,
215
2160x00,
2170x00,
2180x3c,
2190x66,
2200x66,
2210x66,
2220x3c,
2230x18,
2240x7e,
2250x18,
2260x18,
2270x18,
2280x00,
2290x00,
2300x00,
2310x00,
232
2330x00,
2340x08,
2350x0c,
2360x0a,
2370x0a,
2380x0a,
2390x08,
2400x08,
2410x08,
2420x38,
2430x78,
2440x30,
2450x00,
2460x00,
2470x00,
2480x00,
249
2500x00,
2510x10,
2520x18,
2530x1c,
2540x1e,
2550x1e,
2560x16,
2570x12,
2580x72,
2590xf2,
2600x62,
2610x0e,
2620x1e,
2630x0c,
2640x00,
2650x00,
266
2670x00,
2680x00,
2690x00,
2700x10,
2710x92,
2720x54,
2730x38,
2740xfe,
2750x38,
2760x54,
2770x92,
2780x10,
2790x00,
2800x00,
2810x00,
2820x00,
283
2840x00,
2850x00,
2860x00,
2870x80,
2880xc0,
2890xe0,
2900xb8,
2910x8e,
2920xb8,
2930xe0,
2940xc0,
2950x80,
2960x00,
2970x00,
2980x00,
2990x00,
300
3010x00,
3020x00,
3030x00,
3040x02,
3050x06,
3060x0e,
3070x3a,
3080xe2,
3090x3a,
3100x0e,
3110x06,
3120x02,
3130x00,
3140x00,
3150x00,
3160x00,
317
3180x00,
3190x00,
3200x10,
3210x38,
3220x7c,
3230xd6,
3240x10,
3250x10,
3260x10,
3270x10,
3280xd6,
3290x7c,
3300x38,
3310x10,
3320x00,
3330x00,
334
3350x00,
3360x42,
3370xe7,
3380xe7,
3390xe7,
3400xe7,
3410x42,
3420x42,
3430x42,
3440x00,
3450x66,
3460x66,
3470x66,
3480x00,
3490x00,
3500x00,
351
3520x00,
3530x7f,
3540xca,
3550xca,
3560xca,
3570xca,
3580x7a,
3590x0a,
3600x0a,
3610x0a,
3620x0a,
3630x0a,
3640x1b,
3650x00,
3660x00,
3670x00,
368
3690x00,
3700x1e,
3710x31,
3720x78,
3730xcc,
3740xc6,
3750xc3,
3760x63,
3770x33,
3780x1e,
3790x8c,
3800x78,
3810x00,
3820x00,
3830x00,
3840x00,
385
3860x00,
3870x00,
3880x00,
3890x00,
3900x00,
3910x00,
3920x00,
3930x00,
3940xfe,
3950xfe,
3960xfe,
3970xfe,
3980x00,
3990x00,
4000x00,
4010x00,
402
4030x00,
4040x00,
4050x10,
4060x38,
4070x7c,
4080xd6,
4090x10,
4100x10,
4110x10,
4120x10,
4130xd6,
4140x7c,
4150x38,
4160x10,
4170xfe,
4180x00,
419
4200x00,
4210x00,
4220x10,
4230x38,
4240x7c,
4250xd6,
4260x10,
4270x10,
4280x10,
4290x10,
4300x10,
4310x10,
4320x10,
4330x10,
4340x00,
4350x00,
436
4370x00,
4380x00,
4390x10,
4400x10,
4410x10,
4420x10,
4430x10,
4440x10,
4450x10,
4460x10,
4470xd6,
4480x7c,
4490x38,
4500x10,
4510x00,
4520x00,
453
4540x00,
4550x00,
4560x00,
4570x00,
4580x00,
4590x08,
4600x0c,
4610x06,
4620xff,
4630x06,
4640x0c,
4650x08,
4660x00,
4670x00,
4680x00,
4690x00,
470
4710x00,
4720x00,
4730x00,
4740x00,
4750x00,
4760x10,
4770x30,
4780x60,
4790xff,
4800x60,
4810x30,
4820x10,
4830x00,
4840x00,
4850x00,
4860x00,
487
4880x22,
4890x44,
4900x88,
4910xcc,
4920xee,
4930x44,
4940x00,
4950x00,
4960x00,
4970x00,
4980x00,
4990x00,
5000x00,
5010x00,
5020x00,
5030x00,
504
5050x00,
5060x00,
5070x00,
5080x00,
5090x00,
5100x24,
5110x42,
5120xff,
5130x42,
5140x24,
5150x00,
5160x00,
5170x00,
5180x00,
5190x00,
5200x00,
521
5220x00,
5230x00,
5240x00,
5250x10,
5260x38,
5270x38,
5280x6c,
5290x6c,
5300xc6,
5310xfe,
5320x00,
5330x00,
5340x00,
5350x00,
5360x00,
5370x00,
538
5390x00,
5400x00,
5410x00,
5420xfe,
5430xc6,
5440x6c,
5450x6c,
5460x38,
5470x38,
5480x10,
5490x00,
5500x00,
5510x00,
5520x00,
5530x00,
5540x00,
555
5560x00,
5570x00,
5580x00,
5590x00,
5600x00,
5610x00,
5620x00,
5630x00,
5640x00,
5650x00,
5660x00,
5670x00,
5680x00,
5690x00,
5700x00,
5710x00,
572
5730x00,
5740x18,
5750x3c,
5760x3c,
5770x3c,
5780x3c,
5790x18,
5800x18,
5810x18,
5820x10,
5830x00,
5840x18,
5850x18,
5860x00,
5870x00,
5880x00,
589
5900x22,
5910x77,
5920x33,
5930x11,
5940x22,
5950x44,
5960x00,
5970x00,
5980x00,
5990x00,
6000x00,
6010x00,
6020x00,
6030x00,
6040x00,
6050x00,
606
6070x00,
6080x00,
6090x12,
6100x12,
6110x12,
6120x7f,
6130x24,
6140x24,
6150x24,
6160xfe,
6170x48,
6180x48,
6190x48,
6200x00,
6210x00,
6220x00,
623
6240x10,
6250x10,
6260x7c,
6270xd2,
6280xd0,
6290xd0,
6300xd0,
6310x7c,
6320x16,
6330x16,
6340x16,
6350x96,
6360x7c,
6370x10,
6380x10,
6390x00,
640
6410x00,
6420x42,
6430xbe,
6440x44,
6450x0c,
6460x08,
6470x18,
6480x10,
6490x30,
6500x20,
6510x64,
6520x4a,
6530xc4,
6540x00,
6550x00,
6560x00,
657
6580x00,
6590x38,
6600x6c,
6610x6c,
6620x6c,
6630x38,
6640x37,
6650x72,
6660xdc,
6670xcc,
6680xcc,
6690xcc,
6700x77,
6710x00,
6720x00,
6730x00,
674
6750x10,
6760x38,
6770x18,
6780x08,
6790x10,
6800x20,
6810x00,
6820x00,
6830x00,
6840x00,
6850x00,
6860x00,
6870x00,
6880x00,
6890x00,
6900x00,
691
6920x00,
6930x04,
6940x08,
6950x10,
6960x10,
6970x30,
6980x30,
6990x30,
7000x30,
7010x30,
7020x10,
7030x10,
7040x08,
7050x04,
7060x00,
7070x00,
708
7090x00,
7100x20,
7110x10,
7120x08,
7130x08,
7140x0c,
7150x0c,
7160x0c,
7170x0c,
7180x0c,
7190x08,
7200x08,
7210x10,
7220x20,
7230x00,
7240x00,
725
7260x00,
7270x00,
7280x00,
7290x00,
7300x44,
7310x28,
7320x38,
7330xfe,
7340x38,
7350x28,
7360x44,
7370x00,
7380x00,
7390x00,
7400x00,
7410x00,
742
7430x00,
7440x00,
7450x00,
7460x00,
7470x00,
7480x18,
7490x18,
7500x7e,
7510x18,
7520x18,
7530x00,
7540x00,
7550x00,
7560x00,
7570x00,
7580x00,
759
7600x00,
7610x00,
7620x00,
7630x00,
7640x00,
7650x00,
7660x00,
7670x00,
7680x00,
7690x00,
7700x10,
7710x38,
7720x18,
7730x08,
7740x10,
7750x20,
776
7770x00,
7780x00,
7790x00,
7800x00,
7810x00,
7820x00,
7830x00,
7840x7e,
7850x00,
7860x00,
7870x00,
7880x00,
7890x00,
7900x00,
7910x00,
7920x00,
793
7940x00,
7950x00,
7960x00,
7970x00,
7980x00,
7990x00,
8000x00,
8010x00,
8020x00,
8030x00,
8040x10,
8050x38,
8060x10,
8070x00,
8080x00,
8090x00,
810
8110x00,
8120x06,
8130x06,
8140x0c,
8150x0c,
8160x18,
8170x18,
8180x30,
8190x30,
8200x60,
8210x60,
8220xc0,
8230xc0,
8240x00,
8250x00,
8260x00,
827
8280x00,
8290x00,
8300x00,
8310x00,
8320x3c,
8330x46,
8340xc6,
8350xc6,
8360xc6,
8370xc6,
8380xc6,
8390xc4,
8400x78,
8410x00,
8420x00,
8430x00,
844
8450x00,
8460x00,
8470x00,
8480x00,
8490x08,
8500x18,
8510x78,
8520x18,
8530x18,
8540x18,
8550x18,
8560x18,
8570x7e,
8580x00,
8590x00,
8600x00,
861
8620x00,
8630x00,
8640x00,
8650x00,
8660x7c,
8670x86,
8680x06,
8690x0c,
8700x18,
8710x20,
8720x40,
8730xc1,
8740xfe,
8750x00,
8760x00,
8770x00,
878
8790x00,
8800x00,
8810x00,
8820x00,
8830x3c,
8840x46,
8850x04,
8860x08,
8870x1c,
8880x06,
8890x06,
8900x06,
8910x06,
8920x0c,
8930x70,
8940x00,
895
8960x00,
8970x00,
8980x00,
8990x00,
9000x04,
9010x08,
9020x10,
9030x2c,
9040x4c,
9050x8c,
9060x8c,
9070xfe,
9080x0c,
9090x0c,
9100x0c,
9110x00,
912
9130x00,
9140x00,
9150x00,
9160x02,
9170x3c,
9180x20,
9190x20,
9200x70,
9210x0c,
9220x06,
9230x06,
9240x06,
9250x06,
9260x0c,
9270x70,
9280x00,
929
9300x00,
9310x00,
9320x18,
9330x20,
9340x40,
9350xc0,
9360xdc,
9370xc6,
9380xc6,
9390xc6,
9400xc6,
9410x44,
9420x38,
9430x00,
9440x00,
9450x00,
946
9470x00,
9480x00,
9490x00,
9500x40,
9510x7e,
9520x82,
9530x06,
9540x04,
9550x0c,
9560x18,
9570x18,
9580x30,
9590x30,
9600x30,
9610x30,
9620x00,
963
9640x00,
9650x00,
9660x7c,
9670xc6,
9680xc6,
9690x64,
9700x38,
9710x4c,
9720xc6,
9730xc6,
9740xc6,
9750xc6,
9760x7c,
9770x00,
9780x00,
9790x00,
980
9810x00,
9820x00,
9830x00,
9840x00,
9850x38,
9860x44,
9870xc6,
9880xc6,
9890x76,
9900x06,
9910x06,
9920x06,
9930x04,
9940x08,
9950x30,
9960x00,
997
9980x00,
9990x00,
10000x00,
10010x00,
10020x10,
10030x38,
10040x10,
10050x00,
10060x00,
10070x00,
10080x10,
10090x38,
10100x10,
10110x00,
10120x00,
10130x00,
1014
10150x00,
10160x00,
10170x00,
10180x00,
10190x10,
10200x38,
10210x10,
10220x00,
10230x00,
10240x00,
10250x10,
10260x38,
10270x18,
10280x08,
10290x10,
10300x20,
1031
10320x00,
10330x06,
10340x0c,
10350x18,
10360x30,
10370x60,
10380xa0,
10390xa0,
10400x60,
10410x30,
10420x18,
10430x0c,
10440x06,
10450x00,
10460x00,
10470x00,
1048
10490x00,
10500x00,
10510x00,
10520x00,
10530x00,
10540x7e,
10550x00,
10560x00,
10570x7e,
10580x00,
10590x00,
10600x00,
10610x00,
10620x00,
10630x00,
10640x00,
1065
10660x00,
10670x60,
10680x30,
10690x18,
10700x0c,
10710x06,
10720x05,
10730x05,
10740x06,
10750x0c,
10760x18,
10770x30,
10780x60,
10790x00,
10800x00,
10810x00,
1082
10830x00,
10840x7c,
10850x86,
10860xc6,
10870x06,
10880x04,
10890x08,
10900x10,
10910x10,
10920x18,
10930x00,
10940x18,
10950x18,
10960x00,
10970x00,
10980x00,
1099
11000x00,
11010x00,
11020x3c,
11030x46,
11040xc6,
11050xce,
11060xd6,
11070xd6,
11080xd6,
11090xdc,
11100xc0,
11110xc4,
11120x78,
11130x00,
11140x00,
11150x00,
1116
11170x00,
11180x18,
11190x18,
11200x18,
11210x3c,
11220x2c,
11230x2c,
11240x2c,
11250x7e,
11260x46,
11270x46,
11280x46,
11290xef,
11300x00,
11310x00,
11320x00,
1133
11340x00,
11350xfc,
11360x66,
11370x66,
11380x66,
11390x66,
11400x7c,
11410x66,
11420x66,
11430x66,
11440x66,
11450x66,
11460xfc,
11470x00,
11480x00,
11490x00,
1150
11510x00,
11520x3a,
11530x66,
11540xc2,
11550xc0,
11560xc0,
11570xc0,
11580xc0,
11590xc0,
11600xc0,
11610xc0,
11620x62,
11630x3c,
11640x00,
11650x00,
11660x00,
1167
11680x00,
11690xfc,
11700x66,
11710x63,
11720x63,
11730x63,
11740x63,
11750x63,
11760x63,
11770x63,
11780x63,
11790x66,
11800xfc,
11810x00,
11820x00,
11830x00,
1184
11850x00,
11860xff,
11870x61,
11880x60,
11890x60,
11900x64,
11910x7c,
11920x64,
11930x60,
11940x60,
11950x60,
11960x61,
11970xfe,
11980x00,
11990x00,
12000x00,
1201
12020x00,
12030xff,
12040x61,
12050x61,
12060x60,
12070x64,
12080x7c,
12090x64,
12100x60,
12110x60,
12120x60,
12130x60,
12140xf0,
12150x00,
12160x00,
12170x00,
1218
12190x00,
12200x3a,
12210x66,
12220xc2,
12230xc0,
12240xc0,
12250xc0,
12260xcf,
12270xc6,
12280xc6,
12290xc6,
12300x66,
12310x38,
12320x00,
12330x00,
12340x00,
1235
12360x00,
12370xf7,
12380x62,
12390x62,
12400x62,
12410x62,
12420x7e,
12430x62,
12440x62,
12450x62,
12460x62,
12470x62,
12480xf7,
12490x00,
12500x00,
12510x00,
1252
12530x00,
12540x3c,
12550x18,
12560x18,
12570x18,
12580x18,
12590x18,
12600x18,
12610x18,
12620x18,
12630x18,
12640x18,
12650x3c,
12660x00,
12670x00,
12680x00,
1269
12700x00,
12710x1e,
12720x0c,
12730x0c,
12740x0c,
12750x0c,
12760x0c,
12770x0c,
12780x0c,
12790x0c,
12800x0c,
12810x0c,
12820x0c,
12830x0c,
12840x08,
12850xf0,
1286
12870x00,
12880xf7,
12890x64,
12900x6c,
12910x68,
12920x68,
12930x78,
12940x6c,
12950x6c,
12960x6c,
12970x66,
12980x66,
12990xf7,
13000x00,
13010x00,
13020x00,
1303
13040x00,
13050xf8,
13060x60,
13070x60,
13080x60,
13090x60,
13100x60,
13110x60,
13120x60,
13130x60,
13140x60,
13150x61,
13160xfe,
13170x00,
13180x00,
13190x00,
1320
13210x00,
13220xc3,
13230x66,
13240x76,
13250x7e,
13260x56,
13270x56,
13280x46,
13290x46,
13300x46,
13310x46,
13320x46,
13330xef,
13340x00,
13350x00,
13360x00,
1337
13380x00,
13390xe7,
13400x62,
13410x62,
13420x72,
13430x52,
13440x5a,
13450x4a,
13460x4e,
13470x46,
13480x46,
13490x42,
13500xe2,
13510x00,
13520x00,
13530x00,
1354
13550x00,
13560x3c,
13570x66,
13580xc3,
13590xc3,
13600xc3,
13610xc3,
13620xc3,
13630xc3,
13640xc3,
13650xc3,
13660x66,
13670x3c,
13680x00,
13690x00,
13700x00,
1371
13720x00,
13730xfc,
13740x66,
13750x66,
13760x66,
13770x66,
13780x6c,
13790x60,
13800x60,
13810x60,
13820x60,
13830x60,
13840xf0,
13850x00,
13860x00,
13870x00,
1388
13890x00,
13900x3c,
13910x66,
13920xc3,
13930xc3,
13940xc3,
13950xc3,
13960xc3,
13970xc3,
13980xc3,
13990xc3,
14000x66,
14010x3c,
14020x10,
14030x39,
14040x0e,
1405
14060x00,
14070xfc,
14080x66,
14090x66,
14100x66,
14110x66,
14120x7c,
14130x6c,
14140x66,
14150x66,
14160x66,
14170x66,
14180xf3,
14190x00,
14200x00,
14210x00,
1422
14230x00,
14240x7a,
14250xc6,
14260xc2,
14270xc0,
14280x70,
14290x3c,
14300x0e,
14310x06,
14320x06,
14330x86,
14340xc6,
14350xbc,
14360x00,
14370x00,
14380x00,
1439
14400x00,
14410xff,
14420x99,
14430x18,
14440x18,
14450x18,
14460x18,
14470x18,
14480x18,
14490x18,
14500x18,
14510x18,
14520x3c,
14530x00,
14540x00,
14550x00,
1456
14570x00,
14580xf7,
14590x62,
14600x62,
14610x62,
14620x62,
14630x62,
14640x62,
14650x62,
14660x62,
14670x62,
14680x62,
14690x3c,
14700x00,
14710x00,
14720x00,
1473
14740x00,
14750xf7,
14760x62,
14770x62,
14780x62,
14790x76,
14800x34,
14810x34,
14820x34,
14830x3c,
14840x18,
14850x18,
14860x18,
14870x00,
14880x00,
14890x00,
1490
14910x00,
14920xf7,
14930x62,
14940x62,
14950x62,
14960x62,
14970x6a,
14980x6a,
14990x6a,
15000x6a,
15010x7e,
15020x7e,
15030x34,
15040x00,
15050x00,
15060x00,
1507
15080x00,
15090xf7,
15100x62,
15110x62,
15120x34,
15130x34,
15140x18,
15150x18,
15160x2c,
15170x2c,
15180x46,
15190x46,
15200xef,
15210x00,
15220x00,
15230x00,
1524
15250x00,
15260xf7,
15270x62,
15280x62,
15290x62,
15300x34,
15310x34,
15320x18,
15330x18,
15340x18,
15350x18,
15360x18,
15370x3c,
15380x00,
15390x00,
15400x00,
1541
15420x00,
15430x7f,
15440x46,
15450x86,
15460x0c,
15470x0c,
15480x18,
15490x18,
15500x30,
15510x30,
15520x61,
15530x62,
15540xfe,
15550x00,
15560x00,
15570x00,
1558
15590x00,
15600x3c,
15610x30,
15620x30,
15630x30,
15640x30,
15650x30,
15660x30,
15670x30,
15680x30,
15690x30,
15700x30,
15710x3c,
15720x00,
15730x00,
15740x00,
1575
15760x00,
15770xc0,
15780xc0,
15790x60,
15800x60,
15810x30,
15820x30,
15830x18,
15840x18,
15850x0c,
15860x0c,
15870x06,
15880x06,
15890x00,
15900x00,
15910x00,
1592
15930x00,
15940x3c,
15950x0c,
15960x0c,
15970x0c,
15980x0c,
15990x0c,
16000x0c,
16010x0c,
16020x0c,
16030x0c,
16040x0c,
16050x3c,
16060x00,
16070x00,
16080x00,
1609
16100x00,
16110x10,
16120x38,
16130x4c,
16140x86,
16150x00,
16160x00,
16170x00,
16180x00,
16190x00,
16200x00,
16210x00,
16220x00,
16230x00,
16240x00,
16250x00,
1626
16270x00,
16280x00,
16290x00,
16300x00,
16310x00,
16320x00,
16330x00,
16340x00,
16350x00,
16360x00,
16370x00,
16380x00,
16390x00,
16400xff,
16410x00,
16420x00,
1643
16440x00,
16450x18,
16460x20,
16470x30,
16480x38,
16490x10,
16500x00,
16510x00,
16520x00,
16530x00,
16540x00,
16550x00,
16560x00,
16570x00,
16580x00,
16590x00,
1660
16610x00,
16620x00,
16630x00,
16640x00,
16650x00,
16660x78,
16670x8c,
16680x0c,
16690x3c,
16700xcc,
16710xcc,
16720xcd,
16730x76,
16740x00,
16750x00,
16760x00,
1677
16780x00,
16790x20,
16800xe0,
16810x60,
16820x60,
16830x6c,
16840x76,
16850x66,
16860x66,
16870x66,
16880x66,
16890x76,
16900x6c,
16910x00,
16920x00,
16930x00,
1694
16950x00,
16960x00,
16970x00,
16980x00,
16990x00,
17000x3c,
17010x66,
17020x60,
17030x60,
17040x60,
17050x60,
17060x62,
17070x3c,
17080x00,
17090x00,
17100x00,
1711
17120x00,
17130x04,
17140x1c,
17150x0c,
17160x0c,
17170x6c,
17180xdc,
17190xcc,
17200xcc,
17210xcc,
17220xcc,
17230xdc,
17240x66,
17250x00,
17260x00,
17270x00,
1728
17290x00,
17300x00,
17310x00,
17320x00,
17330x00,
17340x3c,
17350x66,
17360x7e,
17370x60,
17380x60,
17390x60,
17400x62,
17410x3c,
17420x00,
17430x00,
17440x00,
1745
17460x00,
17470x1e,
17480x31,
17490x33,
17500x30,
17510x30,
17520x78,
17530x30,
17540x30,
17550x30,
17560x30,
17570x30,
17580x78,
17590x00,
17600x00,
17610x00,
1762
17630x00,
17640x00,
17650x00,
17660x00,
17670x00,
17680x7b,
17690xce,
17700xcc,
17710xcc,
17720xcc,
17730x78,
17740x60,
17750x7c,
17760x86,
17770xc6,
17780x7c,
1779
17800x00,
17810x20,
17820xe0,
17830x60,
17840x60,
17850x6c,
17860x76,
17870x66,
17880x66,
17890x66,
17900x66,
17910x66,
17920xf7,
17930x00,
17940x00,
17950x00,
1796
17970x00,
17980x10,
17990x38,
18000x10,
18010x00,
18020x18,
18030x38,
18040x18,
18050x18,
18060x18,
18070x18,
18080x18,
18090x3c,
18100x00,
18110x00,
18120x00,
1813
18140x00,
18150x08,
18160x1c,
18170x08,
18180x00,
18190x0c,
18200x1c,
18210x0c,
18220x0c,
18230x0c,
18240x0c,
18250x0c,
18260x6c,
18270x4c,
18280x38,
18290x00,
1830
18310x00,
18320x20,
18330xe0,
18340x60,
18350x60,
18360x67,
18370x66,
18380x6c,
18390x78,
18400x6c,
18410x6c,
18420x66,
18430xe7,
18440x00,
18450x00,
18460x00,
1847
18480x00,
18490x08,
18500x38,
18510x18,
18520x18,
18530x18,
18540x18,
18550x18,
18560x18,
18570x18,
18580x18,
18590x18,
18600x3c,
18610x00,
18620x00,
18630x00,
1864
18650x00,
18660x00,
18670x00,
18680x00,
18690x00,
18700x6a,
18710xfe,
18720x6a,
18730x6a,
18740x6a,
18750x62,
18760x62,
18770xf7,
18780x00,
18790x00,
18800x00,
1881
18820x00,
18830x00,
18840x00,
18850x00,
18860x00,
18870x5c,
18880xf6,
18890x66,
18900x66,
18910x66,
18920x66,
18930x66,
18940xf7,
18950x00,
18960x00,
18970x00,
1898
18990x00,
19000x00,
19010x00,
19020x00,
19030x00,
19040x3c,
19050x66,
19060x66,
19070x66,
19080x66,
19090x66,
19100x66,
19110x3c,
19120x00,
19130x00,
19140x00,
1915
19160x00,
19170x00,
19180x00,
19190x00,
19200x00,
19210x5c,
19220xe6,
19230x66,
19240x66,
19250x66,
19260x66,
19270x66,
19280x7c,
19290x60,
19300x60,
19310xf0,
1932
19330x00,
19340x00,
19350x00,
19360x00,
19370x00,
19380x76,
19390xcc,
19400xcc,
19410xcc,
19420xcc,
19430xcc,
19440xcc,
19450x7c,
19460x0c,
19470x0c,
19480x1e,
1949
19500x00,
19510x00,
19520x00,
19530x00,
19540x00,
19550x5e,
19560xf6,
19570x60,
19580x60,
19590x60,
19600x60,
19610x60,
19620xf0,
19630x00,
19640x00,
19650x00,
1966
19670x00,
19680x00,
19690x00,
19700x00,
19710x00,
19720x7a,
19730xc6,
19740x72,
19750x1c,
19760x06,
19770x86,
19780xc6,
19790xbc,
19800x00,
19810x00,
19820x00,
1983
19840x00,
19850x00,
19860x00,
19870x10,
19880x30,
19890x7c,
19900x30,
19910x30,
19920x30,
19930x30,
19940x30,
19950x34,
19960x18,
19970x00,
19980x00,
19990x00,
2000
20010x00,
20020x00,
20030x00,
20040x00,
20050x00,
20060xee,
20070x66,
20080x66,
20090x66,
20100x66,
20110x66,
20120x67,
20130x3a,
20140x00,
20150x00,
20160x00,
2017
20180x00,
20190x00,
20200x00,
20210x00,
20220x00,
20230xf7,
20240x62,
20250x76,
20260x34,
20270x34,
20280x3c,
20290x18,
20300x18,
20310x00,
20320x00,
20330x00,
2034
20350x00,
20360x00,
20370x00,
20380x00,
20390x00,
20400xf7,
20410x62,
20420x6a,
20430x6a,
20440x6a,
20450x6a,
20460x7e,
20470x24,
20480x00,
20490x00,
20500x00,
2051
20520x00,
20530x00,
20540x00,
20550x00,
20560x00,
20570xf7,
20580x62,
20590x34,
20600x18,
20610x2c,
20620x46,
20630x46,
20640xef,
20650x00,
20660x00,
20670x00,
2068
20690x00,
20700x00,
20710x00,
20720x00,
20730x00,
20740xf7,
20750x62,
20760x62,
20770x34,
20780x34,
20790x18,
20800x18,
20810x18,
20820x10,
20830xb0,
20840xe0,
2085
20860x00,
20870x00,
20880x00,
20890x00,
20900x00,
20910xfe,
20920x8c,
20930x18,
20940x30,
20950x30,
20960x60,
20970xc2,
20980xfe,
20990x00,
21000x00,
21010x00,
2102
21030x00,
21040x0e,
21050x18,
21060x10,
21070x10,
21080x08,
21090x70,
21100x70,
21110x08,
21120x10,
21130x10,
21140x18,
21150x0e,
21160x00,
21170x00,
21180x00,
2119
21200x18,
21210x18,
21220x18,
21230x18,
21240x18,
21250x18,
21260x18,
21270x18,
21280x18,
21290x18,
21300x18,
21310x18,
21320x18,
21330x18,
21340x00,
21350x00,
2136
21370x00,
21380x70,
21390x18,
21400x08,
21410x08,
21420x10,
21430x0e,
21440x0e,
21450x10,
21460x08,
21470x08,
21480x18,
21490x70,
21500x00,
21510x00,
21520x00,
2153
21540x00,
21550x00,
21560x00,
21570x00,
21580x00,
21590x00,
21600x76,
21610xdc,
21620x00,
21630x00,
21640x00,
21650x00,
21660x00,
21670x00,
21680x00,
21690x00,
2170
21710x00,
21720x00,
21730x00,
21740x00,
21750x10,
21760x38,
21770x6c,
21780xc6,
21790xc6,
21800xc6,
21810xfe,
21820x00,
21830x00,
21840x00,
21850x00,
21860x00,
2187
21880x00,
21890x00,
21900x3a,
21910x66,
21920xc2,
21930xc0,
21940xc0,
21950xc0,
21960xc0,
21970xc0,
21980x62,
21990x3c,
22000x18,
22010x0c,
22020x24,
22030x18,
2204
22050x00,
22060x00,
22070x66,
22080x00,
22090x00,
22100xee,
22110x66,
22120x66,
22130x66,
22140x66,
22150x66,
22160x66,
22170x3b,
22180x00,
22190x00,
22200x00,
2221
22220x00,
22230x0c,
22240x18,
22250x20,
22260x00,
22270x3c,
22280x66,
22290x7e,
22300x60,
22310x60,
22320x60,
22330x62,
22340x3c,
22350x00,
22360x00,
22370x00,
2238
22390x00,
22400x30,
22410x58,
22420x8c,
22430x00,
22440x78,
22450x8c,
22460x0c,
22470x3c,
22480xcc,
22490xcc,
22500xcd,
22510x76,
22520x00,
22530x00,
22540x00,
2255
22560x00,
22570x00,
22580x66,
22590x00,
22600x00,
22610x78,
22620x8c,
22630x0c,
22640x3c,
22650xcc,
22660xcc,
22670xcd,
22680x76,
22690x00,
22700x00,
22710x00,
2272
22730x00,
22740x30,
22750x18,
22760x04,
22770x00,
22780x78,
22790x8c,
22800x0c,
22810x3c,
22820xcc,
22830xcc,
22840xcd,
22850x76,
22860x00,
22870x00,
22880x00,
2289
22900x38,
22910x44,
22920x44,
22930x38,
22940x00,
22950x78,
22960x8c,
22970x0c,
22980x3c,
22990xcc,
23000xcc,
23010xcd,
23020x76,
23030x00,
23040x00,
23050x00,
2306
23070x00,
23080x00,
23090x00,
23100x00,
23110x00,
23120x3c,
23130x66,
23140x60,
23150x60,
23160x60,
23170x60,
23180x62,
23190x3c,
23200x08,
23210x24,
23220x18,
2323
23240x00,
23250x18,
23260x2c,
23270x46,
23280x00,
23290x3c,
23300x66,
23310x7e,
23320x60,
23330x60,
23340x60,
23350x62,
23360x3c,
23370x00,
23380x00,
23390x00,
2340
23410x00,
23420x00,
23430x66,
23440x00,
23450x00,
23460x3c,
23470x66,
23480x7e,
23490x60,
23500x60,
23510x60,
23520x62,
23530x3c,
23540x00,
23550x00,
23560x00,
2357
23580x00,
23590x30,
23600x18,
23610x04,
23620x00,
23630x3c,
23640x66,
23650x7e,
23660x60,
23670x60,
23680x60,
23690x62,
23700x3c,
23710x00,
23720x00,
23730x00,
2374
23750x00,
23760x00,
23770x66,
23780x00,
23790x00,
23800x38,
23810x18,
23820x18,
23830x18,
23840x18,
23850x18,
23860x18,
23870x3c,
23880x00,
23890x00,
23900x00,
2391
23920x00,
23930x18,
23940x2c,
23950x46,
23960x00,
23970x38,
23980x18,
23990x18,
24000x18,
24010x18,
24020x18,
24030x18,
24040x3c,
24050x00,
24060x00,
24070x00,
2408
24090x00,
24100x60,
24110x30,
24120x08,
24130x00,
24140x38,
24150x18,
24160x18,
24170x18,
24180x18,
24190x18,
24200x18,
24210x3c,
24220x00,
24230x00,
24240x00,
2425
24260x66,
24270x18,
24280x18,
24290x18,
24300x3c,
24310x2c,
24320x2c,
24330x2c,
24340x7e,
24350x46,
24360x46,
24370x46,
24380xef,
24390x00,
24400x00,
24410x00,
2442
24430x18,
24440x24,
24450x18,
24460x18,
24470x3c,
24480x2c,
24490x2c,
24500x2c,
24510x7e,
24520x46,
24530x46,
24540x46,
24550xef,
24560x00,
24570x00,
24580x00,
2459
24600x0c,
24610x18,
24620xff,
24630x61,
24640x60,
24650x60,
24660x64,
24670x7c,
24680x64,
24690x60,
24700x60,
24710x61,
24720xfe,
24730x00,
24740x00,
24750x00,
2476
24770x00,
24780x00,
24790x00,
24800x00,
24810x00,
24820x76,
24830x9b,
24840x1b,
24850x3f,
24860xd8,
24870xd8,
24880xd9,
24890x6e,
24900x00,
24910x00,
24920x00,
2493
24940x00,
24950x1f,
24960x1d,
24970x1d,
24980x3c,
24990x2c,
25000x2e,
25010x2c,
25020x7c,
25030x4c,
25040x4c,
25050x4d,
25060xef,
25070x00,
25080x00,
25090x00,
2510
25110x00,
25120x18,
25130x2c,
25140x46,
25150x00,
25160x3c,
25170x66,
25180x66,
25190x66,
25200x66,
25210x66,
25220x66,
25230x3c,
25240x00,
25250x00,
25260x00,
2527
25280x00,
25290x00,
25300x66,
25310x00,
25320x00,
25330x3c,
25340x66,
25350x66,
25360x66,
25370x66,
25380x66,
25390x66,
25400x3c,
25410x00,
25420x00,
25430x00,
2544
25450x00,
25460x30,
25470x18,
25480x04,
25490x00,
25500x3c,
25510x66,
25520x66,
25530x66,
25540x66,
25550x66,
25560x66,
25570x3c,
25580x00,
25590x00,
25600x00,
2561
25620x00,
25630x18,
25640x2c,
25650x46,
25660x00,
25670xee,
25680x66,
25690x66,
25700x66,
25710x66,
25720x66,
25730x67,
25740x3a,
25750x00,
25760x00,
25770x00,
2578
25790x00,
25800x30,
25810x18,
25820x04,
25830x00,
25840xee,
25850x66,
25860x66,
25870x66,
25880x66,
25890x66,
25900x67,
25910x3a,
25920x00,
25930x00,
25940x00,
2595
25960x00,
25970x00,
25980x66,
25990x00,
26000x00,
26010xf7,
26020x62,
26030x62,
26040x34,
26050x34,
26060x18,
26070x18,
26080x18,
26090x10,
26100xb0,
26110xe0,
2612
26130x66,
26140x00,
26150x3c,
26160x66,
26170xc3,
26180xc3,
26190xc3,
26200xc3,
26210xc3,
26220xc3,
26230xc3,
26240x66,
26250x3c,
26260x00,
26270x00,
26280x00,
2629
26300x66,
26310x00,
26320xf7,
26330x62,
26340x62,
26350x62,
26360x62,
26370x62,
26380x62,
26390x62,
26400x62,
26410x62,
26420x3c,
26430x00,
26440x00,
26450x00,
2646
26470x00,
26480x00,
26490x10,
26500x10,
26510x10,
26520x7c,
26530xc6,
26540xc0,
26550xc0,
26560xc0,
26570xc0,
26580xc2,
26590x7c,
26600x10,
26610x10,
26620x00,
2663
26640x00,
26650x38,
26660x64,
26670x6c,
26680x60,
26690x60,
26700xf0,
26710x60,
26720x60,
26730x60,
26740x60,
26750x66,
26760xfc,
26770x00,
26780x00,
26790x00,
2680
26810x00,
26820x81,
26830xc3,
26840x66,
26850x3c,
26860x18,
26870xff,
26880x18,
26890x18,
26900xff,
26910x18,
26920x18,
26930x18,
26940x00,
26950x00,
26960x00,
2697
26980x00,
26990xfe,
27000x63,
27010x63,
27020x63,
27030x63,
27040x6e,
27050x60,
27060x64,
27070x6e,
27080x64,
27090x64,
27100xf5,
27110x06,
27120x00,
27130x00,
2714
27150x00,
27160x0e,
27170x19,
27180x1b,
27190x18,
27200x18,
27210x3c,
27220x18,
27230x18,
27240x18,
27250x18,
27260xd8,
27270x98,
27280x70,
27290x00,
27300x00,
2731
27320x00,
27330x0c,
27340x18,
27350x20,
27360x00,
27370x78,
27380x8c,
27390x0c,
27400x3c,
27410xcc,
27420xcc,
27430xcd,
27440x76,
27450x00,
27460x00,
27470x00,
2748
27490x00,
27500x06,
27510x0c,
27520x10,
27530x00,
27540x38,
27550x18,
27560x18,
27570x18,
27580x18,
27590x18,
27600x18,
27610x3c,
27620x00,
27630x00,
27640x00,
2765
27660x00,
27670x0c,
27680x18,
27690x20,
27700x00,
27710x3c,
27720x66,
27730x66,
27740x66,
27750x66,
27760x66,
27770x66,
27780x3c,
27790x00,
27800x00,
27810x00,
2782
27830x00,
27840x0c,
27850x18,
27860x20,
27870x00,
27880xee,
27890x66,
27900x66,
27910x66,
27920x66,
27930x66,
27940x67,
27950x3a,
27960x00,
27970x00,
27980x00,
2799
28000x00,
28010x00,
28020x32,
28030x4c,
28040x00,
28050x5c,
28060xf6,
28070x66,
28080x66,
28090x66,
28100x66,
28110x66,
28120xf7,
28130x00,
28140x00,
28150x00,
2816
28170x32,
28180x4c,
28190x00,
28200xe7,
28210x72,
28220x52,
28230x5a,
28240x4a,
28250x4e,
28260x46,
28270x46,
28280x42,
28290xe2,
28300x00,
28310x00,
28320x00,
2833
28340x00,
28350x78,
28360x8c,
28370x0c,
28380x3c,
28390xcc,
28400xcc,
28410xcd,
28420x76,
28430x00,
28440xfe,
28450x00,
28460x00,
28470x00,
28480x00,
28490x00,
2850
28510x00,
28520x3c,
28530x66,
28540x66,
28550x66,
28560x66,
28570x66,
28580x66,
28590x3c,
28600x00,
28610x7e,
28620x00,
28630x00,
28640x00,
28650x00,
28660x00,
2867
28680x00,
28690x30,
28700x30,
28710x00,
28720x30,
28730x10,
28740x10,
28750x20,
28760x40,
28770xc0,
28780xc6,
28790xc2,
28800x7c,
28810x00,
28820x00,
28830x00,
2884
28850x00,
28860x00,
28870x00,
28880x00,
28890x00,
28900x00,
28910xfe,
28920xc0,
28930xc0,
28940xc0,
28950xc0,
28960x00,
28970x00,
28980x00,
28990x00,
29000x00,
2901
29020x00,
29030x00,
29040x00,
29050x00,
29060x00,
29070x00,
29080xfe,
29090x06,
29100x06,
29110x06,
29120x06,
29130x00,
29140x00,
29150x00,
29160x00,
29170x00,
2918
29190x00,
29200x20,
29210xe0,
29220x63,
29230x66,
29240xfc,
29250x18,
29260x30,
29270x60,
29280xce,
29290x93,
29300x06,
29310x0c,
29320x1f,
29330x00,
29340x00,
2935
29360x00,
29370x20,
29380xe0,
29390x63,
29400x66,
29410xfc,
29420x18,
29430x30,
29440x64,
29450xc8,
29460x96,
29470x3f,
29480x06,
29490x06,
29500x00,
29510x00,
2952
29530x00,
29540x18,
29550x18,
29560x00,
29570x08,
29580x18,
29590x18,
29600x18,
29610x3c,
29620x3c,
29630x3c,
29640x3c,
29650x18,
29660x00,
29670x00,
29680x00,
2969
29700x00,
29710x00,
29720x00,
29730x00,
29740x00,
29750x36,
29760x6c,
29770xd8,
29780xd8,
29790x6c,
29800x36,
29810x00,
29820x00,
29830x00,
29840x00,
29850x00,
2986
29870x00,
29880x00,
29890x00,
29900x00,
29910x00,
29920xd8,
29930x6c,
29940x36,
29950x36,
29960x6c,
29970xd8,
29980x00,
29990x00,
30000x00,
30010x00,
30020x00,
3003
30040x82,
30050x10,
30060x82,
30070x10,
30080x82,
30090x10,
30100x82,
30110x10,
30120x82,
30130x10,
30140x82,
30150x10,
30160x82,
30170x10,
30180x82,
30190x10,
3020
30210x00,
30220x95,
30230x00,
30240xa9,
30250x00,
30260x95,
30270x00,
30280xa9,
30290x00,
30300x95,
30310x00,
30320xa9,
30330x00,
30340x95,
30350x00,
30360xa9,
3037
30380x92,
30390x49,
30400x92,
30410x49,
30420x92,
30430x49,
30440x92,
30450x49,
30460x92,
30470x49,
30480x92,
30490x49,
30500x92,
30510x49,
30520x92,
30530x49,
3054
30550x18,
30560x18,
30570x18,
30580x18,
30590x18,
30600x18,
30610x18,
30620x18,
30630x18,
30640x18,
30650x18,
30660x18,
30670x18,
30680x18,
30690x18,
30700x18,
3071
30720x18,
30730x18,
30740x18,
30750x18,
30760x18,
30770x18,
30780x18,
30790xf8,
30800x18,
30810x18,
30820x18,
30830x18,
30840x18,
30850x18,
30860x18,
30870x18,
3088
30890x18,
30900x18,
30910x18,
30920x18,
30930x18,
30940x18,
30950xf8,
30960x18,
30970x18,
30980xf8,
30990x18,
31000x18,
31010x18,
31020x18,
31030x18,
31040x18,
3105
31060x66,
31070x66,
31080x66,
31090x66,
31100x66,
31110x66,
31120x66,
31130xe6,
31140x66,
31150x66,
31160x66,
31170x66,
31180x66,
31190x66,
31200x66,
31210x66,
3122
31230x00,
31240x00,
31250x00,
31260x00,
31270x00,
31280x00,
31290x00,
31300xfe,
31310x66,
31320x66,
31330x66,
31340x66,
31350x66,
31360x66,
31370x66,
31380x66,
3139
31400x00,
31410x00,
31420x00,
31430x00,
31440x00,
31450x00,
31460xf8,
31470x18,
31480x18,
31490xf8,
31500x18,
31510x18,
31520x18,
31530x18,
31540x18,
31550x18,
3156
31570x66,
31580x66,
31590x66,
31600x66,
31610x66,
31620x66,
31630xe6,
31640x06,
31650x06,
31660xe6,
31670x66,
31680x66,
31690x66,
31700x66,
31710x66,
31720x66,
3173
31740x66,
31750x66,
31760x66,
31770x66,
31780x66,
31790x66,
31800x66,
31810x66,
31820x66,
31830x66,
31840x66,
31850x66,
31860x66,
31870x66,
31880x66,
31890x66,
3190
31910x00,
31920x00,
31930x00,
31940x00,
31950x00,
31960x00,
31970xfe,
31980x06,
31990x06,
32000xe6,
32010x66,
32020x66,
32030x66,
32040x66,
32050x66,
32060x66,
3207
32080x66,
32090x66,
32100x66,
32110x66,
32120x66,
32130x66,
32140xe6,
32150x06,
32160x06,
32170xfe,
32180x00,
32190x00,
32200x00,
32210x00,
32220x00,
32230x00,
3224
32250x66,
32260x66,
32270x66,
32280x66,
32290x66,
32300x66,
32310x66,
32320xfe,
32330x00,
32340x00,
32350x00,
32360x00,
32370x00,
32380x00,
32390x00,
32400x00,
3241
32420x18,
32430x18,
32440x18,
32450x18,
32460x18,
32470x18,
32480xf8,
32490x18,
32500x18,
32510xf8,
32520x00,
32530x00,
32540x00,
32550x00,
32560x00,
32570x00,
3258
32590x00,
32600x00,
32610x00,
32620x00,
32630x00,
32640x00,
32650x00,
32660xf8,
32670x18,
32680x18,
32690x18,
32700x18,
32710x18,
32720x18,
32730x18,
32740x18,
3275
32760x18,
32770x18,
32780x18,
32790x18,
32800x18,
32810x18,
32820x18,
32830x1f,
32840x00,
32850x00,
32860x00,
32870x00,
32880x00,
32890x00,
32900x00,
32910x00,
3292
32930x18,
32940x18,
32950x18,
32960x18,
32970x18,
32980x18,
32990x18,
33000xff,
33010x00,
33020x00,
33030x00,
33040x00,
33050x00,
33060x00,
33070x00,
33080x00,
3309
33100x00,
33110x00,
33120x00,
33130x00,
33140x00,
33150x00,
33160x00,
33170xff,
33180x18,
33190x18,
33200x18,
33210x18,
33220x18,
33230x18,
33240x18,
33250x18,
3326
33270x18,
33280x18,
33290x18,
33300x18,
33310x18,
33320x18,
33330x18,
33340x1f,
33350x18,
33360x18,
33370x18,
33380x18,
33390x18,
33400x18,
33410x18,
33420x18,
3343
33440x00,
33450x00,
33460x00,
33470x00,
33480x00,
33490x00,
33500x00,
33510xff,
33520x00,
33530x00,
33540x00,
33550x00,
33560x00,
33570x00,
33580x00,
33590x00,
3360
33610x18,
33620x18,
33630x18,
33640x18,
33650x18,
33660x18,
33670x18,
33680xff,
33690x18,
33700x18,
33710x18,
33720x18,
33730x18,
33740x18,
33750x18,
33760x18,
3377
33780x18,
33790x18,
33800x18,
33810x18,
33820x18,
33830x18,
33840x1f,
33850x18,
33860x18,
33870x1f,
33880x18,
33890x18,
33900x18,
33910x18,
33920x18,
33930x18,
3394
33950x66,
33960x66,
33970x66,
33980x66,
33990x66,
34000x66,
34010x66,
34020x67,
34030x66,
34040x66,
34050x66,
34060x66,
34070x66,
34080x66,
34090x66,
34100x66,
3411
34120x66,
34130x66,
34140x66,
34150x66,
34160x66,
34170x66,
34180x67,
34190x60,
34200x60,
34210x7f,
34220x00,
34230x00,
34240x00,
34250x00,
34260x00,
34270x00,
3428
34290x00,
34300x00,
34310x00,
34320x00,
34330x00,
34340x00,
34350x7f,
34360x60,
34370x60,
34380x67,
34390x66,
34400x66,
34410x66,
34420x66,
34430x66,
34440x66,
3445
34460x66,
34470x66,
34480x66,
34490x66,
34500x66,
34510x66,
34520xe7,
34530x00,
34540x00,
34550xff,
34560x00,
34570x00,
34580x00,
34590x00,
34600x00,
34610x00,
3462
34630x00,
34640x00,
34650x00,
34660x00,
34670x00,
34680x00,
34690xff,
34700x00,
34710x00,
34720xe7,
34730x66,
34740x66,
34750x66,
34760x66,
34770x66,
34780x66,
3479
34800x66,
34810x66,
34820x66,
34830x66,
34840x66,
34850x66,
34860x67,
34870x60,
34880x60,
34890x67,
34900x66,
34910x66,
34920x66,
34930x66,
34940x66,
34950x66,
3496
34970x00,
34980x00,
34990x00,
35000x00,
35010x00,
35020x00,
35030xff,
35040x00,
35050x00,
35060xff,
35070x00,
35080x00,
35090x00,
35100x00,
35110x00,
35120x00,
3513
35140x66,
35150x66,
35160x66,
35170x66,
35180x66,
35190x66,
35200xe7,
35210x00,
35220x00,
35230xe7,
35240x66,
35250x66,
35260x66,
35270x66,
35280x66,
35290x66,
3530
35310x18,
35320x18,
35330x18,
35340x18,
35350x18,
35360x18,
35370xff,
35380x00,
35390x00,
35400xff,
35410x00,
35420x00,
35430x00,
35440x00,
35450x00,
35460x00,
3547
35480x66,
35490x66,
35500x66,
35510x66,
35520x66,
35530x66,
35540x66,
35550xff,
35560x00,
35570x00,
35580x00,
35590x00,
35600x00,
35610x00,
35620x00,
35630x00,
3564
35650x00,
35660x00,
35670x00,
35680x00,
35690x00,
35700x00,
35710xff,
35720x00,
35730x00,
35740xff,
35750x18,
35760x18,
35770x18,
35780x18,
35790x18,
35800x18,
3581
35820x00,
35830x00,
35840x00,
35850x00,
35860x00,
35870x00,
35880x00,
35890xff,
35900x66,
35910x66,
35920x66,
35930x66,
35940x66,
35950x66,
35960x66,
35970x66,
3598
35990x66,
36000x66,
36010x66,
36020x66,
36030x66,
36040x66,
36050x66,
36060x7f,
36070x00,
36080x00,
36090x00,
36100x00,
36110x00,
36120x00,
36130x00,
36140x00,
3615
36160x18,
36170x18,
36180x18,
36190x18,
36200x18,
36210x18,
36220x1f,
36230x18,
36240x18,
36250x1f,
36260x00,
36270x00,
36280x00,
36290x00,
36300x00,
36310x00,
3632
36330x00,
36340x00,
36350x00,
36360x00,
36370x00,
36380x00,
36390x1f,
36400x18,
36410x18,
36420x1f,
36430x18,
36440x18,
36450x18,
36460x18,
36470x18,
36480x18,
3649
36500x00,
36510x00,
36520x00,
36530x00,
36540x00,
36550x00,
36560x00,
36570x7f,
36580x66,
36590x66,
36600x66,
36610x66,
36620x66,
36630x66,
36640x66,
36650x66,
3666
36670x66,
36680x66,
36690x66,
36700x66,
36710x66,
36720x66,
36730x66,
36740xff,
36750x66,
36760x66,
36770x66,
36780x66,
36790x66,
36800x66,
36810x66,
36820x66,
3683
36840x18,
36850x18,
36860x18,
36870x18,
36880x18,
36890x18,
36900xff,
36910x00,
36920x00,
36930xff,
36940x18,
36950x18,
36960x18,
36970x18,
36980x18,
36990x18,
3700
37010x18,
37020x18,
37030x18,
37040x18,
37050x18,
37060x18,
37070x18,
37080xf8,
37090x00,
37100x00,
37110x00,
37120x00,
37130x00,
37140x00,
37150x00,
37160x00,
3717
37180x00,
37190x00,
37200x00,
37210x00,
37220x00,
37230x00,
37240x00,
37250x1f,
37260x18,
37270x18,
37280x18,
37290x18,
37300x18,
37310x18,
37320x18,
37330x18,
3734
37350xff,
37360xff,
37370xff,
37380xff,
37390xff,
37400xff,
37410xff,
37420xff,
37430xff,
37440xff,
37450xff,
37460xff,
37470xff,
37480xff,
37490xff,
37500xff,
3751
37520x00,
37530x00,
37540x00,
37550x00,
37560x00,
37570x00,
37580x00,
37590x00,
37600xff,
37610xff,
37620xff,
37630xff,
37640xff,
37650xff,
37660xff,
37670xff,
3768
37690xf0,
37700xf0,
37710xf0,
37720xf0,
37730xf0,
37740xf0,
37750xf0,
37760xf0,
37770xf0,
37780xf0,
37790xf0,
37800xf0,
37810xf0,
37820xf0,
37830xf0,
37840xf0,
3785
37860x0f,
37870x0f,
37880x0f,
37890x0f,
37900x0f,
37910x0f,
37920x0f,
37930x0f,
37940x0f,
37950x0f,
37960x0f,
37970x0f,
37980x0f,
37990x0f,
38000x0f,
38010x0f,
3802
38030xff,
38040xff,
38050xff,
38060xff,
38070xff,
38080xff,
38090xff,
38100xff,
38110x00,
38120x00,
38130x00,
38140x00,
38150x00,
38160x00,
38170x00,
38180x00,
3819
38200x00,
38210x00,
38220x00,
38230x00,
38240x00,
38250x00,
38260x77,
38270xcc,
38280xcc,
38290xcc,
38300xcc,
38310xde,
38320x73,
38330x00,
38340x00,
38350x00,
3836
38370x00,
38380x7c,
38390xc6,
38400xc6,
38410xc6,
38420xc4,
38430xc8,
38440xc4,
38450xc6,
38460xc6,
38470xc6,
38480xc6,
38490xdc,
38500xc0,
38510xc0,
38520x00,
3853
38540x00,
38550xff,
38560x61,
38570x60,
38580x60,
38590x60,
38600x60,
38610x60,
38620x60,
38630x60,
38640x60,
38650x60,
38660xf0,
38670x00,
38680x00,
38690x00,
3870
38710x00,
38720x00,
38730x00,
38740x00,
38750x01,
38760x7e,
38770xa4,
38780x24,
38790x2c,
38800x6c,
38810x6c,
38820x6c,
38830x48,
38840x00,
38850x00,
38860x00,
3887
38880x00,
38890xff,
38900xc1,
38910x60,
38920x30,
38930x18,
38940x0c,
38950x18,
38960x30,
38970x60,
38980xc0,
38990xc1,
39000xfe,
39010x00,
39020x00,
39030x00,
3904
39050x00,
39060x00,
39070x00,
39080x00,
39090x00,
39100x7f,
39110xc8,
39120xc8,
39130xc8,
39140xc8,
39150xc8,
39160xc8,
39170x70,
39180x00,
39190x00,
39200x00,
3921
39220x00,
39230x00,
39240x00,
39250x00,
39260x00,
39270x22,
39280x66,
39290x66,
39300x66,
39310x66,
39320x66,
39330x7c,
39340x60,
39350x60,
39360x60,
39370xc0,
3938
39390x00,
39400x00,
39410x00,
39420x00,
39430x00,
39440x76,
39450xdc,
39460x18,
39470x18,
39480x18,
39490x18,
39500x18,
39510x10,
39520x00,
39530x00,
39540x00,
3955
39560x00,
39570x38,
39580x10,
39590x7c,
39600xd6,
39610xd6,
39620xd6,
39630xd6,
39640xd6,
39650xd6,
39660x7c,
39670x10,
39680x38,
39690x00,
39700x00,
39710x00,
3972
39730x00,
39740x38,
39750x6c,
39760xc6,
39770xc6,
39780xc6,
39790xfe,
39800xc6,
39810xc6,
39820xc6,
39830xc6,
39840x6c,
39850x38,
39860x00,
39870x00,
39880x00,
3989
39900x00,
39910x3c,
39920x66,
39930xc3,
39940xc3,
39950xc3,
39960xc3,
39970xc3,
39980x66,
39990x24,
40000x24,
40010xa5,
40020xe7,
40030x00,
40040x00,
40050x00,
4006
40070x00,
40080x1e,
40090x31,
40100x30,
40110x18,
40120x0c,
40130x3e,
40140x66,
40150x66,
40160x66,
40170x66,
40180x66,
40190x3c,
40200x00,
40210x00,
40220x00,
4023
40240x00,
40250x00,
40260x00,
40270x00,
40280x6e,
40290xff,
40300x99,
40310x99,
40320x99,
40330x99,
40340xff,
40350x76,
40360x00,
40370x00,
40380x00,
40390x00,
4040
40410x00,
40420x00,
40430x00,
40440x02,
40450x04,
40460x7c,
40470xca,
40480x92,
40490xa6,
40500x7c,
40510x40,
40520x80,
40530x00,
40540x00,
40550x00,
40560x00,
4057
40580x00,
40590x1c,
40600x30,
40610x60,
40620x60,
40630x60,
40640x7c,
40650x60,
40660x60,
40670x60,
40680x60,
40690x30,
40700x1c,
40710x00,
40720x00,
40730x00,
4074
40750x00,
40760x00,
40770x7c,
40780xc6,
40790xc6,
40800xc6,
40810xc6,
40820xc6,
40830xc6,
40840xc6,
40850xc6,
40860xc6,
40870xc6,
40880x00,
40890x00,
40900x00,
4091
40920x00,
40930x00,
40940x00,
40950xfe,
40960x00,
40970x00,
40980x00,
40990x7c,
41000x00,
41010x00,
41020x00,
41030xfe,
41040x00,
41050x00,
41060x00,
41070x00,
4108
41090x00,
41100x00,
41110x00,
41120x00,
41130x18,
41140x18,
41150x7e,
41160x18,
41170x18,
41180x00,
41190x00,
41200x7e,
41210x00,
41220x00,
41230x00,
41240x00,
4125
41260x00,
41270x00,
41280x00,
41290x30,
41300x18,
41310x0c,
41320x06,
41330x0c,
41340x18,
41350x30,
41360x00,
41370x7e,
41380x00,
41390x00,
41400x00,
41410x00,
4142
41430x00,
41440x00,
41450x00,
41460x0c,
41470x18,
41480x30,
41490x60,
41500x30,
41510x18,
41520x0c,
41530x00,
41540x7e,
41550x00,
41560x00,
41570x00,
41580x00,
4159
41600x00,
41610x00,
41620x00,
41630x0e,
41640x19,
41650x1b,
41660x18,
41670x18,
41680x18,
41690x18,
41700x18,
41710x18,
41720x18,
41730x18,
41740x18,
41750x18,
4176
41770x18,
41780x18,
41790x18,
41800x18,
41810x18,
41820x18,
41830x18,
41840x18,
41850x18,
41860xd8,
41870x98,
41880x70,
41890x00,
41900x00,
41910x00,
41920x00,
4193
41940x00,
41950x00,
41960x00,
41970x00,
41980x18,
41990x18,
42000x00,
42010x7e,
42020x00,
42030x18,
42040x18,
42050x00,
42060x00,
42070x00,
42080x00,
42090x00,
4210
42110x00,
42120x00,
42130x00,
42140x00,
42150x00,
42160x76,
42170xdc,
42180x00,
42190x00,
42200x76,
42210xdc,
42220x00,
42230x00,
42240x00,
42250x00,
42260x00,
4227
42280x00,
42290x38,
42300x44,
42310x44,
42320x44,
42330x38,
42340x00,
42350x00,
42360x00,
42370x00,
42380x00,
42390x00,
42400x00,
42410x00,
42420x00,
42430x00,
4244
42450x00,
42460x00,
42470x00,
42480x00,
42490x00,
42500x00,
42510x00,
42520x18,
42530x18,
42540x00,
42550x00,
42560x00,
42570x00,
42580x00,
42590x00,
42600x00,
4261
42620x00,
42630x00,
42640x00,
42650x00,
42660x00,
42670x00,
42680x00,
42690x00,
42700x18,
42710x00,
42720x00,
42730x00,
42740x00,
42750x00,
42760x00,
42770x00,
4278
42790x00,
42800x00,
42810x07,
42820x06,
42830x06,
42840x0c,
42850x0c,
42860x08,
42870x98,
42880xd0,
42890xf0,
42900x60,
42910x20,
42920x00,
42930x00,
42940x00,
4295
42960x00,
42970xcc,
42980x76,
42990x66,
43000x66,
43010x66,
43020x66,
43030xf7,
43040x00,
43050x00,
43060x00,
43070x00,
43080x00,
43090x00,
43100x00,
43110x00,
4312
43130x00,
43140x70,
43150x98,
43160x18,
43170x30,
43180x60,
43190x88,
43200xf8,
43210x00,
43220x00,
43230x00,
43240x00,
43250x00,
43260x00,
43270x00,
43280x00,
4329
43300x00,
43310x00,
43320x00,
43330x00,
43340x00,
43350x7c,
43360x64,
43370x64,
43380x64,
43390x64,
43400x64,
43410x7c,
43420x00,
43430x00,
43440x00,
43450x00,
4346
43470x00,
43480x00,
43490x00,
43500x00,
43510x00,
43520x00,
43530x00,
43540x00,
43550x00,
43560x00,
43570x00,
43580x00,
43590x00,
43600x00,
43610x00,
43620x00,
4363
4364};
4365
4366
4367const struct font_desc font_rl = {
4368 RL_IDX,
4369 "RomanLarge",
4370 8,
4371 16,
4372 patterns,
4373 -1
4374};
diff --git a/drivers/video/console/fonts.c b/drivers/video/console/fonts.c
index 4fd07d9eca03..9be83bed1959 100644
--- a/drivers/video/console/fonts.c
+++ b/drivers/video/console/fonts.c
@@ -64,6 +64,10 @@ static const struct font_desc *fonts[] = {
64#undef NO_FONTS 64#undef NO_FONTS
65 &font_mini_4x6, 65 &font_mini_4x6,
66#endif 66#endif
67#ifdef CONFIG_FONT_RL
68#undef NO_FONTS
69 &font_rl,
70#endif
67}; 71};
68 72
69#define num_fonts (sizeof(fonts)/sizeof(*fonts)) 73#define num_fonts (sizeof(fonts)/sizeof(*fonts))
diff --git a/drivers/video/softcursor.c b/drivers/video/console/softcursor.c
index 229c4bc35079..8529bf08db28 100644
--- a/drivers/video/softcursor.c
+++ b/drivers/video/console/softcursor.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * linux/drivers/video/softcursor.c -- Generic software cursor for frame buffer devices 2 * linux/drivers/video/softcursor.c -- Generic software cursor for frame buffer devices
3 * 3 *
4 * Created 14 Nov 2002 by James Simmons 4 * Created 14 Nov 2002 by James Simmons
5 * 5 *
6 * This file is subject to the terms and conditions of the GNU General Public 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 7 * License. See the file COPYING in the main directory of this archive
@@ -55,9 +55,9 @@ int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
55 src[i] = image->data[i] & cursor->mask[i]; 55 src[i] = image->data[i] & cursor->mask[i];
56 break; 56 break;
57 } 57 }
58 } else 58 } else
59 memcpy(src, image->data, dsize); 59 memcpy(src, image->data, dsize);
60 60
61 fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height); 61 fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height);
62 image->data = dst; 62 image->data = dst;
63 info->fbops->fb_imageblit(info, image); 63 info->fbops->fb_imageblit(info, image);
@@ -66,7 +66,7 @@ int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
66} 66}
67 67
68EXPORT_SYMBOL(soft_cursor); 68EXPORT_SYMBOL(soft_cursor);
69 69
70MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>"); 70MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
71MODULE_DESCRIPTION("Generic software cursor"); 71MODULE_DESCRIPTION("Generic software cursor");
72MODULE_LICENSE("GPL"); 72MODULE_LICENSE("GPL");
diff --git a/drivers/video/controlfb.c b/drivers/video/controlfb.c
index 989e700159e0..403d17377f8d 100644
--- a/drivers/video/controlfb.c
+++ b/drivers/video/controlfb.c
@@ -176,7 +176,6 @@ static struct fb_ops controlfb_ops = {
176 .fb_fillrect = cfb_fillrect, 176 .fb_fillrect = cfb_fillrect,
177 .fb_copyarea = cfb_copyarea, 177 .fb_copyarea = cfb_copyarea,
178 .fb_imageblit = cfb_imageblit, 178 .fb_imageblit = cfb_imageblit,
179 .fb_cursor = soft_cursor,
180}; 179};
181 180
182 181
diff --git a/drivers/video/cyber2000fb.c b/drivers/video/cyber2000fb.c
index 3894b2a501d6..c589d23e7f91 100644
--- a/drivers/video/cyber2000fb.c
+++ b/drivers/video/cyber2000fb.c
@@ -1064,7 +1064,6 @@ static struct fb_ops cyber2000fb_ops = {
1064 .fb_fillrect = cyber2000fb_fillrect, 1064 .fb_fillrect = cyber2000fb_fillrect,
1065 .fb_copyarea = cyber2000fb_copyarea, 1065 .fb_copyarea = cyber2000fb_copyarea,
1066 .fb_imageblit = cyber2000fb_imageblit, 1066 .fb_imageblit = cyber2000fb_imageblit,
1067 .fb_cursor = soft_cursor,
1068 .fb_sync = cyber2000fb_sync, 1067 .fb_sync = cyber2000fb_sync,
1069}; 1068};
1070 1069
diff --git a/drivers/video/cyblafb.c b/drivers/video/cyblafb.c
index 6992100a508c..03fbe83d71a8 100644
--- a/drivers/video/cyblafb.c
+++ b/drivers/video/cyblafb.c
@@ -968,7 +968,6 @@ static struct fb_ops cyblafb_ops __devinitdata = {
968 .fb_fillrect = cyblafb_fillrect, 968 .fb_fillrect = cyblafb_fillrect,
969 .fb_copyarea= cyblafb_copyarea, 969 .fb_copyarea= cyblafb_copyarea,
970 .fb_imageblit = cyblafb_imageblit, 970 .fb_imageblit = cyblafb_imageblit,
971 .fb_cursor = soft_cursor,
972}; 971};
973 972
974//========================================================================== 973//==========================================================================
diff --git a/drivers/video/dnfb.c b/drivers/video/dnfb.c
index 1785686a7f11..957a3ada2b75 100644
--- a/drivers/video/dnfb.c
+++ b/drivers/video/dnfb.c
@@ -116,7 +116,6 @@ static struct fb_ops dn_fb_ops = {
116 .fb_fillrect = cfb_fillrect, 116 .fb_fillrect = cfb_fillrect,
117 .fb_copyarea = dnfb_copyarea, 117 .fb_copyarea = dnfb_copyarea,
118 .fb_imageblit = cfb_imageblit, 118 .fb_imageblit = cfb_imageblit,
119 .fb_cursor = soft_cursor,
120}; 119};
121 120
122struct fb_var_screeninfo dnfb_var __devinitdata = { 121struct fb_var_screeninfo dnfb_var __devinitdata = {
diff --git a/drivers/video/epson1355fb.c b/drivers/video/epson1355fb.c
index 7363d0b25fdf..6a81a1dd8f3d 100644
--- a/drivers/video/epson1355fb.c
+++ b/drivers/video/epson1355fb.c
@@ -484,7 +484,6 @@ static struct fb_ops epson1355fb_fbops = {
484 .fb_imageblit = cfb_imageblit, 484 .fb_imageblit = cfb_imageblit,
485 .fb_read = epson1355fb_read, 485 .fb_read = epson1355fb_read,
486 .fb_write = epson1355fb_write, 486 .fb_write = epson1355fb_write,
487 .fb_cursor = soft_cursor,
488}; 487};
489 488
490/* ------------------------------------------------------------------------- */ 489/* ------------------------------------------------------------------------- */
diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 713226cdf3c6..fc7965b66775 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -538,25 +538,12 @@ static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize)
538 538
539 *dbsize = 0; 539 *dbsize = 0;
540 540
541 DPRINTK(" Supported VESA Modes\n");
542 block = edid + ESTABLISHED_TIMING_1;
543 num += get_est_timing(block, &mode[num]);
544
545 DPRINTK(" Standard Timings\n");
546 block = edid + STD_TIMING_DESCRIPTIONS_START;
547 for (i = 0; i < STD_TIMING; i++, block += STD_TIMING_DESCRIPTION_SIZE)
548 num += get_std_timing(block, &mode[num]);
549
550 DPRINTK(" Detailed Timings\n"); 541 DPRINTK(" Detailed Timings\n");
551 block = edid + DETAILED_TIMING_DESCRIPTIONS_START; 542 block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
552 for (i = 0; i < 4; i++, block+= DETAILED_TIMING_DESCRIPTION_SIZE) { 543 for (i = 0; i < 4; i++, block+= DETAILED_TIMING_DESCRIPTION_SIZE) {
553 int first = 1; 544 int first = 1;
554 545
555 if (block[0] == 0x00 && block[1] == 0x00) { 546 if (!(block[0] == 0x00 && block[1] == 0x00)) {
556 if (block[3] == 0xfa) {
557 num += get_dst_timing(block + 5, &mode[num]);
558 }
559 } else {
560 get_detailed_timing(block, &mode[num]); 547 get_detailed_timing(block, &mode[num]);
561 if (first) { 548 if (first) {
562 mode[num].flag |= FB_MODE_IS_FIRST; 549 mode[num].flag |= FB_MODE_IS_FIRST;
@@ -565,6 +552,21 @@ static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize)
565 num++; 552 num++;
566 } 553 }
567 } 554 }
555
556 DPRINTK(" Supported VESA Modes\n");
557 block = edid + ESTABLISHED_TIMING_1;
558 num += get_est_timing(block, &mode[num]);
559
560 DPRINTK(" Standard Timings\n");
561 block = edid + STD_TIMING_DESCRIPTIONS_START;
562 for (i = 0; i < STD_TIMING; i++, block += STD_TIMING_DESCRIPTION_SIZE)
563 num += get_std_timing(block, &mode[num]);
564
565 block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
566 for (i = 0; i < 4; i++, block+= DETAILED_TIMING_DESCRIPTION_SIZE) {
567 if (block[0] == 0x00 && block[1] == 0x00 && block[3] == 0xfa)
568 num += get_dst_timing(block + 5, &mode[num]);
569 }
568 570
569 /* Yikes, EDID data is totally useless */ 571 /* Yikes, EDID data is totally useless */
570 if (!num) { 572 if (!num) {
@@ -827,7 +829,7 @@ int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
827void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs) 829void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs)
828{ 830{
829 unsigned char *block; 831 unsigned char *block;
830 int i; 832 int i, found = 0;
831 833
832 if (edid == NULL) 834 if (edid == NULL)
833 return; 835 return;
@@ -869,6 +871,22 @@ void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs)
869 get_monspecs(edid, specs); 871 get_monspecs(edid, specs);
870 872
871 specs->modedb = fb_create_modedb(edid, &specs->modedb_len); 873 specs->modedb = fb_create_modedb(edid, &specs->modedb_len);
874
875 /*
876 * Workaround for buggy EDIDs that sets that the first
877 * detailed timing is preferred but has not detailed
878 * timing specified
879 */
880 for (i = 0; i < specs->modedb_len; i++) {
881 if (specs->modedb[i].flag & FB_MODE_IS_DETAILED) {
882 found = 1;
883 break;
884 }
885 }
886
887 if (!found)
888 specs->misc &= ~FB_MISC_1ST_DETAIL;
889
872 DPRINTK("========================================\n"); 890 DPRINTK("========================================\n");
873} 891}
874 892
diff --git a/drivers/video/ffb.c b/drivers/video/ffb.c
index 10cd05059fe9..04417dc16c2e 100644
--- a/drivers/video/ffb.c
+++ b/drivers/video/ffb.c
@@ -57,9 +57,6 @@ static struct fb_ops ffb_ops = {
57 .fb_sync = ffb_sync, 57 .fb_sync = ffb_sync,
58 .fb_mmap = ffb_mmap, 58 .fb_mmap = ffb_mmap,
59 .fb_ioctl = ffb_ioctl, 59 .fb_ioctl = ffb_ioctl,
60
61 /* XXX Use FFB hw cursor once fb cursor API is better understood... */
62 .fb_cursor = soft_cursor,
63}; 60};
64 61
65/* Register layout and definitions */ 62/* Register layout and definitions */
diff --git a/drivers/video/fm2fb.c b/drivers/video/fm2fb.c
index a0763283d776..998374cfae6d 100644
--- a/drivers/video/fm2fb.c
+++ b/drivers/video/fm2fb.c
@@ -172,7 +172,6 @@ static struct fb_ops fm2fb_ops = {
172 .fb_fillrect = cfb_fillrect, 172 .fb_fillrect = cfb_fillrect,
173 .fb_copyarea = cfb_copyarea, 173 .fb_copyarea = cfb_copyarea,
174 .fb_imageblit = cfb_imageblit, 174 .fb_imageblit = cfb_imageblit,
175 .fb_cursor = soft_cursor,
176}; 175};
177 176
178 /* 177 /*
diff --git a/drivers/video/gbefb.c b/drivers/video/gbefb.c
index ed853bef19e9..9d5e4f342110 100644
--- a/drivers/video/gbefb.c
+++ b/drivers/video/gbefb.c
@@ -1038,7 +1038,6 @@ static struct fb_ops gbefb_ops = {
1038 .fb_fillrect = cfb_fillrect, 1038 .fb_fillrect = cfb_fillrect,
1039 .fb_copyarea = cfb_copyarea, 1039 .fb_copyarea = cfb_copyarea,
1040 .fb_imageblit = cfb_imageblit, 1040 .fb_imageblit = cfb_imageblit,
1041 .fb_cursor = soft_cursor,
1042}; 1041};
1043 1042
1044/* 1043/*
diff --git a/drivers/video/geode/Kconfig b/drivers/video/geode/Kconfig
index 5a9b89c3831b..42fb9a89a792 100644
--- a/drivers/video/geode/Kconfig
+++ b/drivers/video/geode/Kconfig
@@ -14,7 +14,6 @@ config FB_GEODE_GX1
14 select FB_CFB_FILLRECT 14 select FB_CFB_FILLRECT
15 select FB_CFB_COPYAREA 15 select FB_CFB_COPYAREA
16 select FB_CFB_IMAGEBLIT 16 select FB_CFB_IMAGEBLIT
17 select FB_SOFT_CURSOR
18 ---help--- 17 ---help---
19 Framebuffer driver for the display controller integrated into the 18 Framebuffer driver for the display controller integrated into the
20 AMD Geode GX1 processor. 19 AMD Geode GX1 processor.
diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
index 74a5fca86b8a..8e8da7433994 100644
--- a/drivers/video/geode/gx1fb_core.c
+++ b/drivers/video/geode/gx1fb_core.c
@@ -275,7 +275,6 @@ static struct fb_ops gx1fb_ops = {
275 .fb_fillrect = cfb_fillrect, 275 .fb_fillrect = cfb_fillrect,
276 .fb_copyarea = cfb_copyarea, 276 .fb_copyarea = cfb_copyarea,
277 .fb_imageblit = cfb_imageblit, 277 .fb_imageblit = cfb_imageblit,
278 .fb_cursor = soft_cursor,
279}; 278};
280 279
281static struct fb_info * __init gx1fb_init_fbinfo(struct device *dev) 280static struct fb_info * __init gx1fb_init_fbinfo(struct device *dev)
diff --git a/drivers/video/hitfb.c b/drivers/video/hitfb.c
index 0d376ba54814..f04ca721f94c 100644
--- a/drivers/video/hitfb.c
+++ b/drivers/video/hitfb.c
@@ -262,7 +262,6 @@ static struct fb_ops hitfb_ops = {
262 .fb_fillrect = hitfb_fillrect, 262 .fb_fillrect = hitfb_fillrect,
263 .fb_copyarea = hitfb_copyarea, 263 .fb_copyarea = hitfb_copyarea,
264 .fb_imageblit = cfb_imageblit, 264 .fb_imageblit = cfb_imageblit,
265 .fb_cursor = soft_cursor,
266}; 265};
267 266
268int __init hitfb_init(void) 267int __init hitfb_init(void)
diff --git a/drivers/video/hpfb.c b/drivers/video/hpfb.c
index e97fe8481d59..bebdac59d231 100644
--- a/drivers/video/hpfb.c
+++ b/drivers/video/hpfb.c
@@ -193,7 +193,6 @@ static struct fb_ops hpfb_ops = {
193 .fb_fillrect = hpfb_fillrect, 193 .fb_fillrect = hpfb_fillrect,
194 .fb_copyarea = hpfb_copyarea, 194 .fb_copyarea = hpfb_copyarea,
195 .fb_imageblit = cfb_imageblit, 195 .fb_imageblit = cfb_imageblit,
196 .fb_cursor = soft_cursor,
197 .fb_sync = hpfb_sync, 196 .fb_sync = hpfb_sync,
198}; 197};
199 198
diff --git a/drivers/video/i810/i810-i2c.c b/drivers/video/i810/i810-i2c.c
index 689d2586366d..c61bad0da20f 100644
--- a/drivers/video/i810/i810-i2c.c
+++ b/drivers/video/i810/i810-i2c.c
@@ -46,92 +46,45 @@ static void i810i2c_setscl(void *data, int state)
46 struct i810fb_par *par = chan->par; 46 struct i810fb_par *par = chan->par;
47 u8 __iomem *mmio = par->mmio_start_virtual; 47 u8 __iomem *mmio = par->mmio_start_virtual;
48 48
49 i810_writel(mmio, GPIOB, (state ? SCL_VAL_OUT : 0) | SCL_DIR | 49 i810_writel(mmio, chan->ddc_base, (state ? SCL_VAL_OUT : 0) | SCL_DIR |
50 SCL_DIR_MASK | SCL_VAL_MASK); 50 SCL_DIR_MASK | SCL_VAL_MASK);
51 i810_readl(mmio, GPIOB); /* flush posted write */ 51 i810_readl(mmio, chan->ddc_base); /* flush posted write */
52} 52}
53 53
54static void i810i2c_setsda(void *data, int state) 54static void i810i2c_setsda(void *data, int state)
55{ 55{
56 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data; 56 struct i810fb_i2c_chan *chan = data;
57 struct i810fb_par *par = chan->par; 57 struct i810fb_par *par = chan->par;
58 u8 __iomem *mmio = par->mmio_start_virtual; 58 u8 __iomem *mmio = par->mmio_start_virtual;
59 59
60 i810_writel(mmio, GPIOB, (state ? SDA_VAL_OUT : 0) | SDA_DIR | 60 i810_writel(mmio, chan->ddc_base, (state ? SDA_VAL_OUT : 0) | SDA_DIR |
61 SDA_DIR_MASK | SDA_VAL_MASK); 61 SDA_DIR_MASK | SDA_VAL_MASK);
62 i810_readl(mmio, GPIOB); /* flush posted write */ 62 i810_readl(mmio, chan->ddc_base); /* flush posted write */
63} 63}
64 64
65static int i810i2c_getscl(void *data) 65static int i810i2c_getscl(void *data)
66{ 66{
67 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data; 67 struct i810fb_i2c_chan *chan = data;
68 struct i810fb_par *par = chan->par; 68 struct i810fb_par *par = chan->par;
69 u8 __iomem *mmio = par->mmio_start_virtual; 69 u8 __iomem *mmio = par->mmio_start_virtual;
70 70
71 i810_writel(mmio, GPIOB, SCL_DIR_MASK); 71 i810_writel(mmio, chan->ddc_base, SCL_DIR_MASK);
72 i810_writel(mmio, GPIOB, 0); 72 i810_writel(mmio, chan->ddc_base, 0);
73 return (0 != (i810_readl(mmio, GPIOB) & SCL_VAL_IN)); 73 return ((i810_readl(mmio, chan->ddc_base) & SCL_VAL_IN) != 0);
74} 74}
75 75
76static int i810i2c_getsda(void *data) 76static int i810i2c_getsda(void *data)
77{ 77{
78 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data; 78 struct i810fb_i2c_chan *chan = data;
79 struct i810fb_par *par = chan->par; 79 struct i810fb_par *par = chan->par;
80 u8 __iomem *mmio = par->mmio_start_virtual; 80 u8 __iomem *mmio = par->mmio_start_virtual;
81 81
82 i810_writel(mmio, GPIOB, SDA_DIR_MASK); 82 i810_writel(mmio, chan->ddc_base, SDA_DIR_MASK);
83 i810_writel(mmio, GPIOB, 0); 83 i810_writel(mmio, chan->ddc_base, 0);
84 return (0 != (i810_readl(mmio, GPIOB) & SDA_VAL_IN)); 84 return ((i810_readl(mmio, chan->ddc_base) & SDA_VAL_IN) != 0);
85}
86
87static void i810ddc_setscl(void *data, int state)
88{
89 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
90 struct i810fb_par *par = chan->par;
91 u8 __iomem *mmio = par->mmio_start_virtual;
92
93 i810_writel(mmio, GPIOA, (state ? SCL_VAL_OUT : 0) | SCL_DIR |
94 SCL_DIR_MASK | SCL_VAL_MASK);
95 i810_readl(mmio, GPIOA); /* flush posted write */
96}
97
98static void i810ddc_setsda(void *data, int state)
99{
100 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
101 struct i810fb_par *par = chan->par;
102 u8 __iomem *mmio = par->mmio_start_virtual;
103
104 i810_writel(mmio, GPIOA, (state ? SDA_VAL_OUT : 0) | SDA_DIR |
105 SDA_DIR_MASK | SDA_VAL_MASK);
106 i810_readl(mmio, GPIOA); /* flush posted write */
107}
108
109static int i810ddc_getscl(void *data)
110{
111 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
112 struct i810fb_par *par = chan->par;
113 u8 __iomem *mmio = par->mmio_start_virtual;
114
115 i810_writel(mmio, GPIOA, SCL_DIR_MASK);
116 i810_writel(mmio, GPIOA, 0);
117 return (0 != (i810_readl(mmio, GPIOA) & SCL_VAL_IN));
118}
119
120static int i810ddc_getsda(void *data)
121{
122 struct i810fb_i2c_chan *chan = (struct i810fb_i2c_chan *)data;
123 struct i810fb_par *par = chan->par;
124 u8 __iomem *mmio = par->mmio_start_virtual;
125
126 i810_writel(mmio, GPIOA, SDA_DIR_MASK);
127 i810_writel(mmio, GPIOA, 0);
128 return (0 != (i810_readl(mmio, GPIOA) & SDA_VAL_IN));
129} 85}
130 86
131#define I2C_ALGO_DDC_I810 0x0e0000 87static int i810_setup_i2c_bus(struct i810fb_i2c_chan *chan, const char *name)
132#define I2C_ALGO_I2C_I810 0x0f0000
133static int i810_setup_i2c_bus(struct i810fb_i2c_chan *chan, const char *name,
134 int conn)
135{ 88{
136 int rc; 89 int rc;
137 90
@@ -139,22 +92,11 @@ static int i810_setup_i2c_bus(struct i810fb_i2c_chan *chan, const char *name,
139 chan->adapter.owner = THIS_MODULE; 92 chan->adapter.owner = THIS_MODULE;
140 chan->adapter.algo_data = &chan->algo; 93 chan->adapter.algo_data = &chan->algo;
141 chan->adapter.dev.parent = &chan->par->dev->dev; 94 chan->adapter.dev.parent = &chan->par->dev->dev;
142 switch (conn) { 95 chan->adapter.id = I2C_HW_B_I810;
143 case 1: 96 chan->algo.setsda = i810i2c_setsda;
144 chan->adapter.id = I2C_ALGO_DDC_I810; 97 chan->algo.setscl = i810i2c_setscl;
145 chan->algo.setsda = i810ddc_setsda; 98 chan->algo.getsda = i810i2c_getsda;
146 chan->algo.setscl = i810ddc_setscl; 99 chan->algo.getscl = i810i2c_getscl;
147 chan->algo.getsda = i810ddc_getsda;
148 chan->algo.getscl = i810ddc_getscl;
149 break;
150 case 2:
151 chan->adapter.id = I2C_ALGO_I2C_I810;
152 chan->algo.setsda = i810i2c_setsda;
153 chan->algo.setscl = i810i2c_setscl;
154 chan->algo.getsda = i810i2c_getsda;
155 chan->algo.getscl = i810i2c_getscl;
156 break;
157 }
158 chan->algo.udelay = 10; 100 chan->algo.udelay = 10;
159 chan->algo.mdelay = 10; 101 chan->algo.mdelay = 10;
160 chan->algo.timeout = (HZ/2); 102 chan->algo.timeout = (HZ/2);
@@ -168,11 +110,15 @@ static int i810_setup_i2c_bus(struct i810fb_i2c_chan *chan, const char *name,
168 udelay(20); 110 udelay(20);
169 111
170 rc = i2c_bit_add_bus(&chan->adapter); 112 rc = i2c_bit_add_bus(&chan->adapter);
113
171 if (rc == 0) 114 if (rc == 0)
172 dev_dbg(&chan->par->dev->dev, "I2C bus %s registered.\n",name); 115 dev_dbg(&chan->par->dev->dev, "I2C bus %s registered.\n",name);
173 else 116 else {
174 dev_warn(&chan->par->dev->dev, "Failed to register I2C bus " 117 dev_warn(&chan->par->dev->dev, "Failed to register I2C bus "
175 "%s.\n", name); 118 "%s.\n", name);
119 chan->par = NULL;
120 }
121
176 return rc; 122 return rc;
177} 123}
178 124
@@ -180,8 +126,14 @@ void i810_create_i2c_busses(struct i810fb_par *par)
180{ 126{
181 par->chan[0].par = par; 127 par->chan[0].par = par;
182 par->chan[1].par = par; 128 par->chan[1].par = par;
183 i810_setup_i2c_bus(&par->chan[0], "I810-DDC", 1); 129 par->chan[2].par = par;
184 i810_setup_i2c_bus(&par->chan[1], "I810-I2C", 2); 130
131 par->chan[0].ddc_base = GPIOA;
132 i810_setup_i2c_bus(&par->chan[0], "I810-DDC");
133 par->chan[1].ddc_base = GPIOB;
134 i810_setup_i2c_bus(&par->chan[1], "I810-I2C");
135 par->chan[2].ddc_base = GPIOC;
136 i810_setup_i2c_bus(&par->chan[2], "I810-GPIOC");
185} 137}
186 138
187void i810_delete_i2c_busses(struct i810fb_par *par) 139void i810_delete_i2c_busses(struct i810fb_par *par)
@@ -189,9 +141,14 @@ void i810_delete_i2c_busses(struct i810fb_par *par)
189 if (par->chan[0].par) 141 if (par->chan[0].par)
190 i2c_bit_del_bus(&par->chan[0].adapter); 142 i2c_bit_del_bus(&par->chan[0].adapter);
191 par->chan[0].par = NULL; 143 par->chan[0].par = NULL;
144
192 if (par->chan[1].par) 145 if (par->chan[1].par)
193 i2c_bit_del_bus(&par->chan[1].adapter); 146 i2c_bit_del_bus(&par->chan[1].adapter);
194 par->chan[1].par = NULL; 147 par->chan[1].par = NULL;
148
149 if (par->chan[2].par)
150 i2c_bit_del_bus(&par->chan[2].adapter);
151 par->chan[2].par = NULL;
195} 152}
196 153
197static u8 *i810_do_probe_i2c_edid(struct i810fb_i2c_chan *chan) 154static u8 *i810_do_probe_i2c_edid(struct i810fb_i2c_chan *chan)
@@ -221,6 +178,7 @@ static u8 *i810_do_probe_i2c_edid(struct i810fb_i2c_chan *chan)
221 DPRINTK("i810-i2c: I2C Transfer successful\n"); 178 DPRINTK("i810-i2c: I2C Transfer successful\n");
222 return buf; 179 return buf;
223 } 180 }
181
224 DPRINTK("i810-i2c: Unable to read EDID block.\n"); 182 DPRINTK("i810-i2c: Unable to read EDID block.\n");
225 kfree(buf); 183 kfree(buf);
226 return NULL; 184 return NULL;
@@ -233,7 +191,7 @@ int i810_probe_i2c_connector(struct fb_info *info, u8 **out_edid, int conn)
233 int i; 191 int i;
234 192
235 DPRINTK("i810-i2c: Probe DDC%i Bus\n", conn); 193 DPRINTK("i810-i2c: Probe DDC%i Bus\n", conn);
236 if (conn < 3) { 194 if (conn < 4) {
237 for (i = 0; i < 3; i++) { 195 for (i = 0; i < 3; i++) {
238 /* Do the real work */ 196 /* Do the real work */
239 edid = i810_do_probe_i2c_edid(&par->chan[conn-1]); 197 edid = i810_do_probe_i2c_edid(&par->chan[conn-1]);
@@ -241,11 +199,14 @@ int i810_probe_i2c_connector(struct fb_info *info, u8 **out_edid, int conn)
241 break; 199 break;
242 } 200 }
243 } else { 201 } else {
244 DPRINTK("i810-i2c: Getting EDID from BIOS\n"); 202 const u8 *e = fb_firmware_edid(info->device);
245 edid = kmalloc(EDID_LENGTH, GFP_KERNEL); 203
246 if (edid) 204 if (e != NULL) {
247 memcpy(edid, fb_firmware_edid(info->device), 205 DPRINTK("i810-i2c: Getting EDID from BIOS\n");
248 EDID_LENGTH); 206 edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
207 if (edid)
208 memcpy(edid, e, EDID_LENGTH);
209 }
249 } 210 }
250 211
251 if (out_edid) 212 if (out_edid)
@@ -253,5 +214,3 @@ int i810_probe_i2c_connector(struct fb_info *info, u8 **out_edid, int conn)
253 214
254 return (edid) ? 0 : 1; 215 return (edid) ? 0 : 1;
255} 216}
256
257
diff --git a/drivers/video/i810/i810.h b/drivers/video/i810/i810.h
index d48949ceaacc..6c187d5fe951 100644
--- a/drivers/video/i810/i810.h
+++ b/drivers/video/i810/i810.h
@@ -249,6 +249,7 @@ struct i810fb_i2c_chan {
249 struct i810fb_par *par; 249 struct i810fb_par *par;
250 struct i2c_adapter adapter; 250 struct i2c_adapter adapter;
251 struct i2c_algo_bit_data algo; 251 struct i2c_algo_bit_data algo;
252 unsigned long ddc_base;
252}; 253};
253 254
254struct i810fb_par { 255struct i810fb_par {
@@ -262,7 +263,7 @@ struct i810fb_par {
262 struct heap_data iring; 263 struct heap_data iring;
263 struct heap_data cursor_heap; 264 struct heap_data cursor_heap;
264 struct vgastate state; 265 struct vgastate state;
265 struct i810fb_i2c_chan chan[2]; 266 struct i810fb_i2c_chan chan[3];
266 atomic_t use_count; 267 atomic_t use_count;
267 u32 pseudo_palette[17]; 268 u32 pseudo_palette[17];
268 unsigned long mmio_start_phys; 269 unsigned long mmio_start_phys;
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index 0dbc9ddb6766..c0c974b1afaa 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -1854,7 +1854,7 @@ static void __devinit i810fb_find_init_mode(struct fb_info *info)
1854#ifdef CONFIG_FB_I810_I2C 1854#ifdef CONFIG_FB_I810_I2C
1855 i810_create_i2c_busses(par); 1855 i810_create_i2c_busses(par);
1856 1856
1857 for (i = 0; i < 3; i++) { 1857 for (i = 0; i < 4; i++) {
1858 err = i810_probe_i2c_connector(info, &par->edid, i+1); 1858 err = i810_probe_i2c_connector(info, &par->edid, i+1);
1859 if (!err) 1859 if (!err)
1860 break; 1860 break;
@@ -1871,27 +1871,18 @@ static void __devinit i810fb_find_init_mode(struct fb_info *info)
1871 fb_videomode_to_modelist(specs->modedb, specs->modedb_len, 1871 fb_videomode_to_modelist(specs->modedb, specs->modedb_len,
1872 &info->modelist); 1872 &info->modelist);
1873 if (specs->modedb != NULL) { 1873 if (specs->modedb != NULL) {
1874 if (xres && yres) { 1874 struct fb_videomode *m;
1875 struct fb_videomode *m;
1876 1875
1876 if (xres && yres) {
1877 if ((m = fb_find_best_mode(&var, &info->modelist))) { 1877 if ((m = fb_find_best_mode(&var, &info->modelist))) {
1878 mode = *m; 1878 mode = *m;
1879 found = 1; 1879 found = 1;
1880 } 1880 }
1881 } 1881 }
1882 1882
1883 if (!found && specs->misc & FB_MISC_1ST_DETAIL) {
1884 for (i = 0; i < specs->modedb_len; i++) {
1885 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
1886 mode = specs->modedb[i];
1887 found = 1;
1888 break;
1889 }
1890 }
1891 }
1892
1893 if (!found) { 1883 if (!found) {
1894 mode = specs->modedb[0]; 1884 m = fb_find_best_display(&info->monspecs, &info->modelist);
1885 mode = *m;
1895 found = 1; 1886 found = 1;
1896 } 1887 }
1897 1888
@@ -2066,8 +2057,7 @@ static void i810fb_release_resource(struct fb_info *info,
2066 iounmap(par->mmio_start_virtual); 2057 iounmap(par->mmio_start_virtual);
2067 if (par->aperture.virtual) 2058 if (par->aperture.virtual)
2068 iounmap(par->aperture.virtual); 2059 iounmap(par->aperture.virtual);
2069 if (par->edid) 2060 kfree(par->edid);
2070 kfree(par->edid);
2071 if (par->res_flags & FRAMEBUFFER_REQ) 2061 if (par->res_flags & FRAMEBUFFER_REQ)
2072 release_mem_region(par->aperture.physical, 2062 release_mem_region(par->aperture.physical,
2073 par->aperture.size); 2063 par->aperture.size);
diff --git a/drivers/video/i810/i810_regs.h b/drivers/video/i810/i810_regs.h
index 6e4b9afa4d98..91c6bd9d0d0d 100644
--- a/drivers/video/i810/i810_regs.h
+++ b/drivers/video/i810/i810_regs.h
@@ -70,6 +70,7 @@
70#define HVSYNC 0x05000 70#define HVSYNC 0x05000
71#define GPIOA 0x05010 71#define GPIOA 0x05010
72#define GPIOB 0x05014 72#define GPIOB 0x05014
73#define GPIOC 0x0501C
73 74
74/* Clock Control and Power Management Registers (06000h 06FFFh) */ 75/* Clock Control and Power Management Registers (06000h 06FFFh) */
75#define DCLK_0D 0x06000 76#define DCLK_0D 0x06000
diff --git a/drivers/video/imsttfb.c b/drivers/video/imsttfb.c
index 7b9bf45ab6fe..7fbe24206b19 100644
--- a/drivers/video/imsttfb.c
+++ b/drivers/video/imsttfb.c
@@ -1344,7 +1344,6 @@ static struct fb_ops imsttfb_ops = {
1344 .fb_fillrect = imsttfb_fillrect, 1344 .fb_fillrect = imsttfb_fillrect,
1345 .fb_copyarea = imsttfb_copyarea, 1345 .fb_copyarea = imsttfb_copyarea,
1346 .fb_imageblit = cfb_imageblit, 1346 .fb_imageblit = cfb_imageblit,
1347 .fb_cursor = soft_cursor,
1348 .fb_ioctl = imsttfb_ioctl, 1347 .fb_ioctl = imsttfb_ioctl,
1349}; 1348};
1350 1349
diff --git a/drivers/video/imxfb.c b/drivers/video/imxfb.c
index 64d9bcc38da3..e20b9f3a255f 100644
--- a/drivers/video/imxfb.c
+++ b/drivers/video/imxfb.c
@@ -298,7 +298,6 @@ static struct fb_ops imxfb_ops = {
298 .fb_copyarea = cfb_copyarea, 298 .fb_copyarea = cfb_copyarea,
299 .fb_imageblit = cfb_imageblit, 299 .fb_imageblit = cfb_imageblit,
300 .fb_blank = imxfb_blank, 300 .fb_blank = imxfb_blank,
301 .fb_cursor = soft_cursor, /* FIXME: i.MX can do hardware cursor */
302}; 301};
303 302
304/* 303/*
diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h
index 011e11626558..f077ca34faba 100644
--- a/drivers/video/intelfb/intelfb.h
+++ b/drivers/video/intelfb/intelfb.h
@@ -10,7 +10,7 @@
10/*** Version/name ***/ 10/*** Version/name ***/
11#define INTELFB_VERSION "0.9.2" 11#define INTELFB_VERSION "0.9.2"
12#define INTELFB_MODULE_NAME "intelfb" 12#define INTELFB_MODULE_NAME "intelfb"
13#define SUPPORTED_CHIPSETS "830M/845G/852GM/855GM/865G/915G" 13#define SUPPORTED_CHIPSETS "830M/845G/852GM/855GM/865G/915G/915GM"
14 14
15 15
16/*** Debug/feature defines ***/ 16/*** Debug/feature defines ***/
@@ -47,6 +47,7 @@
47#define PCI_DEVICE_ID_INTEL_85XGM 0x3582 47#define PCI_DEVICE_ID_INTEL_85XGM 0x3582
48#define PCI_DEVICE_ID_INTEL_865G 0x2572 48#define PCI_DEVICE_ID_INTEL_865G 0x2572
49#define PCI_DEVICE_ID_INTEL_915G 0x2582 49#define PCI_DEVICE_ID_INTEL_915G 0x2582
50#define PCI_DEVICE_ID_INTEL_915GM 0x2592
50 51
51/* Size of MMIO region */ 52/* Size of MMIO region */
52#define INTEL_REG_SIZE 0x80000 53#define INTEL_REG_SIZE 0x80000
@@ -119,7 +120,8 @@ enum intel_chips {
119 INTEL_855GM, 120 INTEL_855GM,
120 INTEL_855GME, 121 INTEL_855GME,
121 INTEL_865G, 122 INTEL_865G,
122 INTEL_915G 123 INTEL_915G,
124 INTEL_915GM
123}; 125};
124 126
125struct intelfb_hwstate { 127struct intelfb_hwstate {
diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c
index 80a09344f1aa..0799b999b314 100644
--- a/drivers/video/intelfb/intelfbdrv.c
+++ b/drivers/video/intelfb/intelfbdrv.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * intelfb 2 * intelfb
3 * 3 *
4 * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G 4 * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G/915GM
5 * integrated graphics chips. 5 * integrated graphics chips.
6 * 6 *
7 * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org> 7 * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org>
@@ -186,6 +186,7 @@ static struct pci_device_id intelfb_pci_table[] __devinitdata = {
186 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_85XGM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_85XGM }, 186 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_85XGM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_85XGM },
187 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_865G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_865G }, 187 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_865G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_865G },
188 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915G }, 188 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915G },
189 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915GM },
189 { 0, } 190 { 0, }
190}; 191};
191 192
@@ -549,10 +550,11 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
549 } 550 }
550 551
551 /* Set base addresses. */ 552 /* Set base addresses. */
552 if (ent->device == PCI_DEVICE_ID_INTEL_915G) { 553 if ((ent->device == PCI_DEVICE_ID_INTEL_915G) ||
554 (ent->device == PCI_DEVICE_ID_INTEL_915GM)) {
553 aperture_bar = 2; 555 aperture_bar = 2;
554 mmio_bar = 0; 556 mmio_bar = 0;
555 /* Disable HW cursor on 915G (not implemented yet) */ 557 /* Disable HW cursor on 915G/M (not implemented yet) */
556 hwcursor = 0; 558 hwcursor = 0;
557 } 559 }
558 dinfo->aperture.physical = pci_resource_start(pdev, aperture_bar); 560 dinfo->aperture.physical = pci_resource_start(pdev, aperture_bar);
@@ -1483,7 +1485,7 @@ intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1483#endif 1485#endif
1484 1486
1485 if (!dinfo->hwcursor) 1487 if (!dinfo->hwcursor)
1486 return soft_cursor(info, cursor); 1488 return -ENODEV;
1487 1489
1488 intelfbhw_cursor_hide(dinfo); 1490 intelfbhw_cursor_hide(dinfo);
1489 1491
diff --git a/drivers/video/intelfb/intelfbhw.c b/drivers/video/intelfb/intelfbhw.c
index 5bafc3c54db7..ac94c2e5ff85 100644
--- a/drivers/video/intelfb/intelfbhw.c
+++ b/drivers/video/intelfb/intelfbhw.c
@@ -99,6 +99,11 @@ intelfbhw_get_chipset(struct pci_dev *pdev, const char **name, int *chipset,
99 *chipset = INTEL_915G; 99 *chipset = INTEL_915G;
100 *mobile = 0; 100 *mobile = 0;
101 return 0; 101 return 0;
102 case PCI_DEVICE_ID_INTEL_915GM:
103 *name = "Intel(R) 915GM";
104 *chipset = INTEL_915GM;
105 *mobile = 1;
106 return 0;
102 default: 107 default:
103 return 1; 108 return 1;
104 } 109 }
diff --git a/drivers/video/kyro/fbdev.c b/drivers/video/kyro/fbdev.c
index d8bac9e97842..5eb4d5c177bd 100644
--- a/drivers/video/kyro/fbdev.c
+++ b/drivers/video/kyro/fbdev.c
@@ -669,7 +669,6 @@ static struct fb_ops kyrofb_ops = {
669 .fb_fillrect = cfb_fillrect, 669 .fb_fillrect = cfb_fillrect,
670 .fb_copyarea = cfb_copyarea, 670 .fb_copyarea = cfb_copyarea,
671 .fb_imageblit = cfb_imageblit, 671 .fb_imageblit = cfb_imageblit,
672 .fb_cursor = soft_cursor,
673}; 672};
674 673
675static int __devinit kyrofb_probe(struct pci_dev *pdev, 674static int __devinit kyrofb_probe(struct pci_dev *pdev,
diff --git a/drivers/video/leo.c b/drivers/video/leo.c
index 7e1e7fb168bd..84a7fe435bb8 100644
--- a/drivers/video/leo.c
+++ b/drivers/video/leo.c
@@ -51,7 +51,6 @@ static struct fb_ops leo_ops = {
51 .fb_imageblit = cfb_imageblit, 51 .fb_imageblit = cfb_imageblit,
52 .fb_mmap = leo_mmap, 52 .fb_mmap = leo_mmap,
53 .fb_ioctl = leo_ioctl, 53 .fb_ioctl = leo_ioctl,
54 .fb_cursor = soft_cursor,
55}; 54};
56 55
57#define LEO_OFF_LC_SS0_KRN 0x00200000UL 56#define LEO_OFF_LC_SS0_KRN 0x00200000UL
diff --git a/drivers/video/logo/Kconfig b/drivers/video/logo/Kconfig
index 3e9ccf370ab2..8cb7fb4db441 100644
--- a/drivers/video/logo/Kconfig
+++ b/drivers/video/logo/Kconfig
@@ -7,6 +7,8 @@ menu "Logo configuration"
7config LOGO 7config LOGO
8 bool "Bootup logo" 8 bool "Bootup logo"
9 depends on FB || SGI_NEWPORT_CONSOLE 9 depends on FB || SGI_NEWPORT_CONSOLE
10 help
11 Enable and select frame buffer bootup logos.
10 12
11config LOGO_LINUX_MONO 13config LOGO_LINUX_MONO
12 bool "Standard black and white Linux logo" 14 bool "Standard black and white Linux logo"
diff --git a/drivers/video/macfb.c b/drivers/video/macfb.c
index 4945a4c02209..cfc748e94272 100644
--- a/drivers/video/macfb.c
+++ b/drivers/video/macfb.c
@@ -589,7 +589,6 @@ static struct fb_ops macfb_ops = {
589 .fb_fillrect = cfb_fillrect, 589 .fb_fillrect = cfb_fillrect,
590 .fb_copyarea = cfb_copyarea, 590 .fb_copyarea = cfb_copyarea,
591 .fb_imageblit = cfb_imageblit, 591 .fb_imageblit = cfb_imageblit,
592 .fb_cursor = soft_cursor,
593}; 592};
594 593
595void __init macfb_setup(char *options) 594void __init macfb_setup(char *options)
diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
index 149680f8bcf0..0fbd9b5149f1 100644
--- a/drivers/video/matrox/matroxfb_DAC1064.c
+++ b/drivers/video/matrox/matroxfb_DAC1064.c
@@ -657,7 +657,6 @@ static int MGA1064_preinit(WPMINFO2) {
657 /* ACCESS_FBINFO(capable.cfb4) = 0; ... preinitialized by 0 */ 657 /* ACCESS_FBINFO(capable.cfb4) = 0; ... preinitialized by 0 */
658 ACCESS_FBINFO(capable.text) = 1; 658 ACCESS_FBINFO(capable.text) = 1;
659 ACCESS_FBINFO(capable.vxres) = vxres_mystique; 659 ACCESS_FBINFO(capable.vxres) = vxres_mystique;
660 ACCESS_FBINFO(features.accel.has_cacheflush) = 1;
661 660
662 ACCESS_FBINFO(outputs[0]).output = &m1064; 661 ACCESS_FBINFO(outputs[0]).output = &m1064;
663 ACCESS_FBINFO(outputs[0]).src = ACCESS_FBINFO(outputs[0]).default_src; 662 ACCESS_FBINFO(outputs[0]).src = ACCESS_FBINFO(outputs[0]).default_src;
@@ -842,7 +841,6 @@ static int MGAG100_preinit(WPMINFO2) {
842 /* ACCESS_FBINFO(capable.cfb4) = 0; ... preinitialized by 0 */ 841 /* ACCESS_FBINFO(capable.cfb4) = 0; ... preinitialized by 0 */
843 ACCESS_FBINFO(capable.text) = 1; 842 ACCESS_FBINFO(capable.text) = 1;
844 ACCESS_FBINFO(capable.vxres) = vxres_g100; 843 ACCESS_FBINFO(capable.vxres) = vxres_g100;
845 ACCESS_FBINFO(features.accel.has_cacheflush) = 1;
846 ACCESS_FBINFO(capable.plnwt) = ACCESS_FBINFO(devflags.accelerator) == FB_ACCEL_MATROX_MGAG100 844 ACCESS_FBINFO(capable.plnwt) = ACCESS_FBINFO(devflags.accelerator) == FB_ACCEL_MATROX_MGAG100
847 ? ACCESS_FBINFO(devflags.sgram) : 1; 845 ? ACCESS_FBINFO(devflags.sgram) : 1;
848 846
@@ -980,7 +978,7 @@ static void MGAG100_reset(WPMINFO2) {
980 hw->MXoptionReg |= 0x40; /* FIXME... */ 978 hw->MXoptionReg |= 0x40; /* FIXME... */
981 pci_write_config_dword(ACCESS_FBINFO(pcidev), PCI_OPTION_REG, hw->MXoptionReg); 979 pci_write_config_dword(ACCESS_FBINFO(pcidev), PCI_OPTION_REG, hw->MXoptionReg);
982 } 980 }
983 mga_setr(M_EXTVGA_INDEX, 0x06, 0x50); 981 mga_setr(M_EXTVGA_INDEX, 0x06, 0x00);
984 } 982 }
985 } 983 }
986 if (ACCESS_FBINFO(devflags.g450dac)) { 984 if (ACCESS_FBINFO(devflags.g450dac)) {
diff --git a/drivers/video/matrox/matroxfb_accel.c b/drivers/video/matrox/matroxfb_accel.c
index c7f3e1321224..a5c825d99466 100644
--- a/drivers/video/matrox/matroxfb_accel.c
+++ b/drivers/video/matrox/matroxfb_accel.c
@@ -122,7 +122,7 @@ void matrox_cfbX_init(WPMINFO2) {
122 ACCESS_FBINFO(fbops).fb_copyarea = cfb_copyarea; 122 ACCESS_FBINFO(fbops).fb_copyarea = cfb_copyarea;
123 ACCESS_FBINFO(fbops).fb_fillrect = cfb_fillrect; 123 ACCESS_FBINFO(fbops).fb_fillrect = cfb_fillrect;
124 ACCESS_FBINFO(fbops).fb_imageblit = cfb_imageblit; 124 ACCESS_FBINFO(fbops).fb_imageblit = cfb_imageblit;
125 ACCESS_FBINFO(fbops).fb_cursor = soft_cursor; 125 ACCESS_FBINFO(fbops).fb_cursor = NULL;
126 126
127 accel = (ACCESS_FBINFO(fbcon).var.accel_flags & FB_ACCELF_TEXT) == FB_ACCELF_TEXT; 127 accel = (ACCESS_FBINFO(fbcon).var.accel_flags & FB_ACCELF_TEXT) == FB_ACCELF_TEXT;
128 128
diff --git a/drivers/video/matrox/matroxfb_base.c b/drivers/video/matrox/matroxfb_base.c
index e02da41f1b26..1e74f4cca53b 100644
--- a/drivers/video/matrox/matroxfb_base.c
+++ b/drivers/video/matrox/matroxfb_base.c
@@ -264,7 +264,6 @@ static void matroxfb_disable_irq(WPMINFO2) {
264} 264}
265 265
266int matroxfb_wait_for_sync(WPMINFO u_int32_t crtc) { 266int matroxfb_wait_for_sync(WPMINFO u_int32_t crtc) {
267 wait_queue_t __wait;
268 struct matrox_vsync *vs; 267 struct matrox_vsync *vs;
269 unsigned int cnt; 268 unsigned int cnt;
270 int ret; 269 int ret;
@@ -286,7 +285,6 @@ int matroxfb_wait_for_sync(WPMINFO u_int32_t crtc) {
286 if (ret) { 285 if (ret) {
287 return ret; 286 return ret;
288 } 287 }
289 init_waitqueue_entry(&__wait, current);
290 288
291 cnt = vs->cnt; 289 cnt = vs->cnt;
292 ret = wait_event_interruptible_timeout(vs->wait, cnt != vs->cnt, HZ/10); 290 ret = wait_event_interruptible_timeout(vs->wait, cnt != vs->cnt, HZ/10);
@@ -500,10 +498,6 @@ static int matroxfb_pitch_adjust(CPMINFO int xres, int bpp) {
500 } else { 498 } else {
501 xres_new = matroxfb_test_and_set_rounding(PMINFO xres, bpp); 499 xres_new = matroxfb_test_and_set_rounding(PMINFO xres, bpp);
502 } 500 }
503 if (!xres_new) return 0;
504 if (xres != xres_new) {
505 printk(KERN_INFO "matroxfb: cannot set xres to %d, rounded up to %d\n", xres, xres_new);
506 }
507 return xres_new; 501 return xres_new;
508} 502}
509 503
@@ -1285,7 +1279,7 @@ static int matroxfb_getmemory(WPMINFO unsigned int maxSize, unsigned int *realSi
1285 vaddr_t vm; 1279 vaddr_t vm;
1286 unsigned int offs; 1280 unsigned int offs;
1287 unsigned int offs2; 1281 unsigned int offs2;
1288 unsigned char store, orig; 1282 unsigned char orig;
1289 unsigned char bytes[32]; 1283 unsigned char bytes[32];
1290 unsigned char* tmp; 1284 unsigned char* tmp;
1291 1285
@@ -1301,16 +1295,12 @@ static int matroxfb_getmemory(WPMINFO unsigned int maxSize, unsigned int *realSi
1301 orig = mga_inb(M_EXTVGA_DATA); 1295 orig = mga_inb(M_EXTVGA_DATA);
1302 mga_outb(M_EXTVGA_DATA, orig | 0x80); 1296 mga_outb(M_EXTVGA_DATA, orig | 0x80);
1303 1297
1304 store = mga_readb(vm, 0x1234);
1305 tmp = bytes; 1298 tmp = bytes;
1306 for (offs = 0x100000; offs < maxSize; offs += 0x200000) 1299 for (offs = 0x100000; offs < maxSize; offs += 0x200000)
1307 *tmp++ = mga_readb(vm, offs); 1300 *tmp++ = mga_readb(vm, offs);
1308 for (offs = 0x100000; offs < maxSize; offs += 0x200000) 1301 for (offs = 0x100000; offs < maxSize; offs += 0x200000)
1309 mga_writeb(vm, offs, 0x02); 1302 mga_writeb(vm, offs, 0x02);
1310 if (ACCESS_FBINFO(features.accel.has_cacheflush)) 1303 mga_outb(M_CACHEFLUSH, 0x00);
1311 mga_outb(M_CACHEFLUSH, 0x00);
1312 else
1313 mga_writeb(vm, 0x1234, 0x99);
1314 for (offs = 0x100000; offs < maxSize; offs += 0x200000) { 1304 for (offs = 0x100000; offs < maxSize; offs += 0x200000) {
1315 if (mga_readb(vm, offs) != 0x02) 1305 if (mga_readb(vm, offs) != 0x02)
1316 break; 1306 break;
@@ -1321,7 +1311,6 @@ static int matroxfb_getmemory(WPMINFO unsigned int maxSize, unsigned int *realSi
1321 tmp = bytes; 1311 tmp = bytes;
1322 for (offs2 = 0x100000; offs2 < maxSize; offs2 += 0x200000) 1312 for (offs2 = 0x100000; offs2 < maxSize; offs2 += 0x200000)
1323 mga_writeb(vm, offs2, *tmp++); 1313 mga_writeb(vm, offs2, *tmp++);
1324 mga_writeb(vm, 0x1234, store);
1325 1314
1326 mga_outb(M_EXTVGA_INDEX, 0x03); 1315 mga_outb(M_EXTVGA_INDEX, 0x03);
1327 mga_outb(M_EXTVGA_DATA, orig); 1316 mga_outb(M_EXTVGA_DATA, orig);
@@ -1430,6 +1419,20 @@ static struct board {
1430 MGA_1164, 1419 MGA_1164,
1431 &vbMystique, 1420 &vbMystique,
1432 "Mystique 220 (PCI)"}, 1421 "Mystique 220 (PCI)"},
1422 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS_AGP, 0x02,
1423 0, 0,
1424 DEVF_VIDEO64BIT | DEVF_CROSS4MB,
1425 180000,
1426 MGA_1064,
1427 &vbMystique,
1428 "Mystique (AGP)"},
1429 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS_AGP, 0xFF,
1430 0, 0,
1431 DEVF_VIDEO64BIT | DEVF_SWAPS | DEVF_CROSS4MB,
1432 220000,
1433 MGA_1164,
1434 &vbMystique,
1435 "Mystique 220 (AGP)"},
1433#endif 1436#endif
1434#ifdef CONFIG_FB_MATROX_G 1437#ifdef CONFIG_FB_MATROX_G
1435 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_MM, 0xFF, 1438 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_MM, 0xFF,
diff --git a/drivers/video/matrox/matroxfb_base.h b/drivers/video/matrox/matroxfb_base.h
index 85a0b2558452..a8c47ad2cdb6 100644
--- a/drivers/video/matrox/matroxfb_base.h
+++ b/drivers/video/matrox/matroxfb_base.h
@@ -272,10 +272,6 @@ struct matrox_DAC1064_features {
272 u_int8_t xmiscctrl; 272 u_int8_t xmiscctrl;
273}; 273};
274 274
275struct matrox_accel_features {
276 int has_cacheflush;
277};
278
279/* current hardware status */ 275/* current hardware status */
280struct mavenregs { 276struct mavenregs {
281 u_int8_t regs[256]; 277 u_int8_t regs[256];
@@ -440,7 +436,6 @@ struct matrox_fb_info {
440 struct { 436 struct {
441 struct matrox_pll_features pll; 437 struct matrox_pll_features pll;
442 struct matrox_DAC1064_features DAC1064; 438 struct matrox_DAC1064_features DAC1064;
443 struct matrox_accel_features accel;
444 } features; 439 } features;
445 struct { 440 struct {
446 spinlock_t DAC; 441 spinlock_t DAC;
diff --git a/drivers/video/matrox/matroxfb_crtc2.c b/drivers/video/matrox/matroxfb_crtc2.c
index 429047ac615a..d52d7d825c41 100644
--- a/drivers/video/matrox/matroxfb_crtc2.c
+++ b/drivers/video/matrox/matroxfb_crtc2.c
@@ -576,7 +576,6 @@ static struct fb_ops matroxfb_dh_ops = {
576 .fb_fillrect = cfb_fillrect, 576 .fb_fillrect = cfb_fillrect,
577 .fb_copyarea = cfb_copyarea, 577 .fb_copyarea = cfb_copyarea,
578 .fb_imageblit = cfb_imageblit, 578 .fb_imageblit = cfb_imageblit,
579 .fb_cursor = soft_cursor,
580}; 579};
581 580
582static struct fb_var_screeninfo matroxfb_dh_defined = { 581static struct fb_var_screeninfo matroxfb_dh_defined = {
diff --git a/drivers/video/maxinefb.c b/drivers/video/maxinefb.c
index f192d995d030..743e7ad26acc 100644
--- a/drivers/video/maxinefb.c
+++ b/drivers/video/maxinefb.c
@@ -113,7 +113,6 @@ static struct fb_ops maxinefb_ops = {
113 .fb_fillrect = cfb_fillrect, 113 .fb_fillrect = cfb_fillrect,
114 .fb_copyarea = cfb_copyarea, 114 .fb_copyarea = cfb_copyarea,
115 .fb_imageblit = cfb_imageblit, 115 .fb_imageblit = cfb_imageblit,
116 .fb_cursor = soft_cursor,
117}; 116};
118 117
119int __init maxinefb_init(void) 118int __init maxinefb_init(void)
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index 47516c44a390..1789a52d776a 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -676,6 +676,8 @@ void fb_var_to_videomode(struct fb_videomode *mode,
676 mode->sync = var->sync; 676 mode->sync = var->sync;
677 mode->vmode = var->vmode & FB_VMODE_MASK; 677 mode->vmode = var->vmode & FB_VMODE_MASK;
678 mode->flag = FB_MODE_IS_FROM_VAR; 678 mode->flag = FB_MODE_IS_FROM_VAR;
679 mode->refresh = 0;
680
679 if (!var->pixclock) 681 if (!var->pixclock)
680 return; 682 return;
681 683
@@ -785,39 +787,39 @@ struct fb_videomode *fb_find_best_mode(struct fb_var_screeninfo *var,
785} 787}
786 788
787/** 789/**
788 * fb_find_nearest_mode - find mode closest video mode 790 * fb_find_nearest_mode - find closest videomode
789 * 791 *
790 * @var: pointer to struct fb_var_screeninfo 792 * @mode: pointer to struct fb_videomode
791 * @head: pointer to modelist 793 * @head: pointer to modelist
792 * 794 *
793 * Finds best matching videomode, smaller or greater in dimension. 795 * Finds best matching videomode, smaller or greater in dimension.
794 * If more than 1 videomode is found, will return the videomode with 796 * If more than 1 videomode is found, will return the videomode with
795 * the closest refresh rate 797 * the closest refresh rate.
796 */ 798 */
797struct fb_videomode *fb_find_nearest_mode(struct fb_var_screeninfo *var, 799struct fb_videomode *fb_find_nearest_mode(struct fb_videomode *mode,
798 struct list_head *head) 800 struct list_head *head)
799{ 801{
800 struct list_head *pos; 802 struct list_head *pos;
801 struct fb_modelist *modelist; 803 struct fb_modelist *modelist;
802 struct fb_videomode *mode, *best = NULL; 804 struct fb_videomode *cmode, *best = NULL;
803 u32 diff = -1, diff_refresh = -1; 805 u32 diff = -1, diff_refresh = -1;
804 806
805 list_for_each(pos, head) { 807 list_for_each(pos, head) {
806 u32 d; 808 u32 d;
807 809
808 modelist = list_entry(pos, struct fb_modelist, list); 810 modelist = list_entry(pos, struct fb_modelist, list);
809 mode = &modelist->mode; 811 cmode = &modelist->mode;
810 812
811 d = abs(mode->xres - var->xres) + 813 d = abs(cmode->xres - mode->xres) +
812 abs(mode->yres - var->yres); 814 abs(cmode->yres - mode->yres);
813 if (diff > d) { 815 if (diff > d) {
814 diff = d; 816 diff = d;
815 best = mode; 817 best = cmode;
816 } else if (diff == d) { 818 } else if (diff == d) {
817 d = abs(mode->refresh - best->refresh); 819 d = abs(cmode->refresh - mode->refresh);
818 if (diff_refresh > d) { 820 if (diff_refresh > d) {
819 diff_refresh = d; 821 diff_refresh = d;
820 best = mode; 822 best = cmode;
821 } 823 }
822 } 824 }
823 } 825 }
@@ -942,6 +944,66 @@ void fb_videomode_to_modelist(struct fb_videomode *modedb, int num,
942 } 944 }
943} 945}
944 946
947struct fb_videomode *fb_find_best_display(struct fb_monspecs *specs,
948 struct list_head *head)
949{
950 struct list_head *pos;
951 struct fb_modelist *modelist;
952 struct fb_videomode *m, *m1 = NULL, *md = NULL, *best = NULL;
953 int first = 0;
954
955 if (!head->prev || !head->next || list_empty(head))
956 goto finished;
957
958 /* get the first detailed mode and the very first mode */
959 list_for_each(pos, head) {
960 modelist = list_entry(pos, struct fb_modelist, list);
961 m = &modelist->mode;
962
963 if (!first) {
964 m1 = m;
965 first = 1;
966 }
967
968 if (m->flag & FB_MODE_IS_FIRST) {
969 md = m;
970 break;
971 }
972 }
973
974 /* first detailed timing is preferred */
975 if (specs->misc & FB_MISC_1ST_DETAIL) {
976 best = md;
977 goto finished;
978 }
979
980 /* find best mode based on display width and height */
981 if (specs->max_x && specs->max_y) {
982 struct fb_var_screeninfo var;
983
984 memset(&var, 0, sizeof(struct fb_var_screeninfo));
985 var.xres = (specs->max_x * 7200)/254;
986 var.yres = (specs->max_y * 7200)/254;
987 m = fb_find_best_mode(&var, head);
988 if (m) {
989 best = m;
990 goto finished;
991 }
992 }
993
994 /* use first detailed mode */
995 if (md) {
996 best = md;
997 goto finished;
998 }
999
1000 /* last resort, use the very first mode */
1001 best = m1;
1002finished:
1003 return best;
1004}
1005EXPORT_SYMBOL(fb_find_best_display);
1006
945EXPORT_SYMBOL(fb_videomode_to_var); 1007EXPORT_SYMBOL(fb_videomode_to_var);
946EXPORT_SYMBOL(fb_var_to_videomode); 1008EXPORT_SYMBOL(fb_var_to_videomode);
947EXPORT_SYMBOL(fb_mode_is_equal); 1009EXPORT_SYMBOL(fb_mode_is_equal);
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c
index 5d424a30270a..8486e77872dc 100644
--- a/drivers/video/neofb.c
+++ b/drivers/video/neofb.c
@@ -1665,7 +1665,6 @@ static struct fb_ops neofb_ops = {
1665 .fb_fillrect = neofb_fillrect, 1665 .fb_fillrect = neofb_fillrect,
1666 .fb_copyarea = neofb_copyarea, 1666 .fb_copyarea = neofb_copyarea,
1667 .fb_imageblit = neofb_imageblit, 1667 .fb_imageblit = neofb_imageblit,
1668 .fb_cursor = soft_cursor,
1669}; 1668};
1670 1669
1671/* --------------------------------------------------------------------- */ 1670/* --------------------------------------------------------------------- */
diff --git a/drivers/video/nvidia/nv_local.h b/drivers/video/nvidia/nv_local.h
index afee284fc73c..4243d7fae972 100644
--- a/drivers/video/nvidia/nv_local.h
+++ b/drivers/video/nvidia/nv_local.h
@@ -105,7 +105,7 @@ do { \
105 *a = byte_rev[*a]; \ 105 *a = byte_rev[*a]; \
106} while(0) 106} while(0)
107#else 107#else
108#define reverse_order(l) 108#define reverse_order(l) do { } while(0)
109#endif /* __LITTLE_ENDIAN */ 109#endif /* __LITTLE_ENDIAN */
110 110
111#endif /* __NV_LOCAL_H__ */ 111#endif /* __NV_LOCAL_H__ */
diff --git a/drivers/video/nvidia/nv_of.c b/drivers/video/nvidia/nv_of.c
index 4fa2cf9a8af2..7a03d040b1a3 100644
--- a/drivers/video/nvidia/nv_of.c
+++ b/drivers/video/nvidia/nv_of.c
@@ -27,34 +27,60 @@
27#include "nv_local.h" 27#include "nv_local.h"
28#include "nv_proto.h" 28#include "nv_proto.h"
29 29
30void nvidia_create_i2c_busses(struct nvidia_par *par) {} 30#include "../edid.h"
31void nvidia_delete_i2c_busses(struct nvidia_par *par) {}
32 31
33int nvidia_probe_i2c_connector(struct fb_info *info, int conn, u8 **out_edid) 32int nvidia_probe_of_connector(struct fb_info *info, int conn, u8 **out_edid)
34{ 33{
35 struct nvidia_par *par = info->par; 34 struct nvidia_par *par = info->par;
36 struct device_node *dp; 35 struct device_node *parent, *dp;
37 unsigned char *pedid = NULL; 36 unsigned char *pedid = NULL;
38 unsigned char *disptype = NULL;
39 static char *propnames[] = { 37 static char *propnames[] = {
40 "DFP,EDID", "LCD,EDID", "EDID", "EDID1", "EDID,B", "EDID,A", NULL }; 38 "DFP,EDID", "LCD,EDID", "EDID", "EDID1",
39 "EDID,B", "EDID,A", NULL };
41 int i; 40 int i;
42 41
43 dp = pci_device_to_OF_node(par->pci_dev); 42 parent = pci_device_to_OF_node(par->pci_dev);
44 for (; dp != NULL; dp = dp->child) { 43 if (parent == NULL)
45 disptype = (unsigned char *)get_property(dp, "display-type", NULL); 44 return -1;
46 if (disptype == NULL) 45 if (par->twoHeads) {
47 continue; 46 char *pname;
48 if (strncmp(disptype, "LCD", 3) != 0) 47 int len;
49 continue; 48
49 for (dp = NULL;
50 (dp = of_get_next_child(parent, dp)) != NULL;) {
51 pname = (char *)get_property(dp, "name", NULL);
52 if (!pname)
53 continue;
54 len = strlen(pname);
55 if ((pname[len-1] == 'A' && conn == 1) ||
56 (pname[len-1] == 'B' && conn == 2)) {
57 for (i = 0; propnames[i] != NULL; ++i) {
58 pedid = (unsigned char *)
59 get_property(dp, propnames[i],
60 NULL);
61 if (pedid != NULL)
62 break;
63 }
64 of_node_put(dp);
65 break;
66 }
67 }
68 }
69 if (pedid == NULL) {
50 for (i = 0; propnames[i] != NULL; ++i) { 70 for (i = 0; propnames[i] != NULL; ++i) {
51 pedid = (unsigned char *) 71 pedid = (unsigned char *)
52 get_property(dp, propnames[i], NULL); 72 get_property(parent, propnames[i], NULL);
53 if (pedid != NULL) { 73 if (pedid != NULL)
54 *out_edid = pedid; 74 break;
55 return 0;
56 }
57 } 75 }
58 } 76 }
59 return 1; 77 if (pedid) {
78 *out_edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
79 if (*out_edid == NULL)
80 return -1;
81 memcpy(*out_edid, pedid, EDID_LENGTH);
82 printk(KERN_DEBUG "nvidiafb: Found OF EDID for head %d\n", conn);
83 return 0;
84 }
85 return -1;
60} 86}
diff --git a/drivers/video/nvidia/nv_proto.h b/drivers/video/nvidia/nv_proto.h
index cac44fc7f587..f60b1f432270 100644
--- a/drivers/video/nvidia/nv_proto.h
+++ b/drivers/video/nvidia/nv_proto.h
@@ -31,7 +31,7 @@ int NVShowHideCursor(struct nvidia_par *par, int);
31void NVLockUnlock(struct nvidia_par *par, int); 31void NVLockUnlock(struct nvidia_par *par, int);
32 32
33/* in nvidia-i2c.c */ 33/* in nvidia-i2c.c */
34#if defined(CONFIG_FB_NVIDIA_I2C) || defined (CONFIG_PPC_OF) 34#ifdef CONFIG_FB_NVIDIA_I2C
35void nvidia_create_i2c_busses(struct nvidia_par *par); 35void nvidia_create_i2c_busses(struct nvidia_par *par);
36void nvidia_delete_i2c_busses(struct nvidia_par *par); 36void nvidia_delete_i2c_busses(struct nvidia_par *par);
37int nvidia_probe_i2c_connector(struct fb_info *info, int conn, 37int nvidia_probe_i2c_connector(struct fb_info *info, int conn,
@@ -39,10 +39,18 @@ int nvidia_probe_i2c_connector(struct fb_info *info, int conn,
39#else 39#else
40#define nvidia_create_i2c_busses(...) 40#define nvidia_create_i2c_busses(...)
41#define nvidia_delete_i2c_busses(...) 41#define nvidia_delete_i2c_busses(...)
42#define nvidia_probe_i2c_connector(p, c, edid) \ 42#define nvidia_probe_i2c_connector(p, c, edid) (-1)
43do { \ 43#endif
44 *(edid) = NULL; \ 44
45} while(0) 45#ifdef CONFIG_FB_OF
46int nvidia_probe_of_connector(struct fb_info *info, int conn,
47 u8 ** out_edid);
48#else
49static inline int nvidia_probe_of_connector(struct fb_info *info, int conn,
50 u8 ** out_edid)
51{
52 return -1;
53}
46#endif 54#endif
47 55
48/* in nv_accel.c */ 56/* in nv_accel.c */
diff --git a/drivers/video/nvidia/nv_setup.c b/drivers/video/nvidia/nv_setup.c
index 11c84178f420..1f06a9f1bd0f 100644
--- a/drivers/video/nvidia/nv_setup.c
+++ b/drivers/video/nvidia/nv_setup.c
@@ -190,9 +190,9 @@ static int NVIsConnected(struct nvidia_par *par, int output)
190 present = (NV_RD32(PRAMDAC, 0x0608) & (1 << 28)) ? 1 : 0; 190 present = (NV_RD32(PRAMDAC, 0x0608) & (1 << 28)) ? 1 : 0;
191 191
192 if (present) 192 if (present)
193 printk("nvidiafb: CRTC%i found\n", output); 193 printk("nvidiafb: CRTC%i analog found\n", output);
194 else 194 else
195 printk("nvidiafb: CRTC%i not found\n", output); 195 printk("nvidiafb: CRTC%i analog not found\n", output);
196 196
197 NV_WR32(par->PRAMDAC0, 0x0608, NV_RD32(par->PRAMDAC0, 0x0608) & 197 NV_WR32(par->PRAMDAC0, 0x0608, NV_RD32(par->PRAMDAC0, 0x0608) &
198 0x0000EFFF); 198 0x0000EFFF);
@@ -305,6 +305,9 @@ void NVCommonSetup(struct fb_info *info)
305 int FlatPanel = -1; /* really means the CRTC is slaved */ 305 int FlatPanel = -1; /* really means the CRTC is slaved */
306 int Television = 0; 306 int Television = 0;
307 307
308 memset(&monitorA, 0, sizeof(struct fb_monspecs));
309 memset(&monitorB, 0, sizeof(struct fb_monspecs));
310
308 par->PRAMIN = par->REGS + (0x00710000 / 4); 311 par->PRAMIN = par->REGS + (0x00710000 / 4);
309 par->PCRTC0 = par->REGS + (0x00600000 / 4); 312 par->PCRTC0 = par->REGS + (0x00600000 / 4);
310 par->PRAMDAC0 = par->REGS + (0x00680000 / 4); 313 par->PRAMDAC0 = par->REGS + (0x00680000 / 4);
@@ -401,7 +404,8 @@ void NVCommonSetup(struct fb_info *info)
401 nvidia_create_i2c_busses(par); 404 nvidia_create_i2c_busses(par);
402 if (!par->twoHeads) { 405 if (!par->twoHeads) {
403 par->CRTCnumber = 0; 406 par->CRTCnumber = 0;
404 nvidia_probe_i2c_connector(info, 1, &edidA); 407 if (nvidia_probe_i2c_connector(info, 1, &edidA))
408 nvidia_probe_of_connector(info, 1, &edidA);
405 if (edidA && !fb_parse_edid(edidA, &var)) { 409 if (edidA && !fb_parse_edid(edidA, &var)) {
406 printk("nvidiafb: EDID found from BUS1\n"); 410 printk("nvidiafb: EDID found from BUS1\n");
407 monA = &monitorA; 411 monA = &monitorA;
@@ -488,14 +492,16 @@ void NVCommonSetup(struct fb_info *info)
488 oldhead = NV_RD32(par->PCRTC0, 0x00000860); 492 oldhead = NV_RD32(par->PCRTC0, 0x00000860);
489 NV_WR32(par->PCRTC0, 0x00000860, oldhead | 0x00000010); 493 NV_WR32(par->PCRTC0, 0x00000860, oldhead | 0x00000010);
490 494
491 nvidia_probe_i2c_connector(info, 1, &edidA); 495 if (nvidia_probe_i2c_connector(info, 1, &edidA))
496 nvidia_probe_of_connector(info, 1, &edidA);
492 if (edidA && !fb_parse_edid(edidA, &var)) { 497 if (edidA && !fb_parse_edid(edidA, &var)) {
493 printk("nvidiafb: EDID found from BUS1\n"); 498 printk("nvidiafb: EDID found from BUS1\n");
494 monA = &monitorA; 499 monA = &monitorA;
495 fb_edid_to_monspecs(edidA, monA); 500 fb_edid_to_monspecs(edidA, monA);
496 } 501 }
497 502
498 nvidia_probe_i2c_connector(info, 2, &edidB); 503 if (nvidia_probe_i2c_connector(info, 2, &edidB))
504 nvidia_probe_of_connector(info, 2, &edidB);
499 if (edidB && !fb_parse_edid(edidB, &var)) { 505 if (edidB && !fb_parse_edid(edidB, &var)) {
500 printk("nvidiafb: EDID found from BUS2\n"); 506 printk("nvidiafb: EDID found from BUS2\n");
501 monB = &monitorB; 507 monB = &monitorB;
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index 308defc389a2..0b40a2a721c1 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -411,6 +411,7 @@ MODULE_DEVICE_TABLE(pci, nvidiafb_pci_tbl);
411 411
412/* command line data, set in nvidiafb_setup() */ 412/* command line data, set in nvidiafb_setup() */
413static int flatpanel __devinitdata = -1; /* Autodetect later */ 413static int flatpanel __devinitdata = -1; /* Autodetect later */
414static int fpdither __devinitdata = -1;
414static int forceCRTC __devinitdata = -1; 415static int forceCRTC __devinitdata = -1;
415static int hwcur __devinitdata = 0; 416static int hwcur __devinitdata = 0;
416static int noaccel __devinitdata = 0; 417static int noaccel __devinitdata = 0;
@@ -627,41 +628,85 @@ static void nvidia_save_vga(struct nvidia_par *par,
627 NVTRACE_LEAVE(); 628 NVTRACE_LEAVE();
628} 629}
629 630
631#undef DUMP_REG
632
630static void nvidia_write_regs(struct nvidia_par *par) 633static void nvidia_write_regs(struct nvidia_par *par)
631{ 634{
632 struct _riva_hw_state *state = &par->ModeReg; 635 struct _riva_hw_state *state = &par->ModeReg;
633 int i; 636 int i;
634 637
635 NVTRACE_ENTER(); 638 NVTRACE_ENTER();
636 NVWriteCrtc(par, 0x11, 0x00);
637
638 NVLockUnlock(par, 0);
639 639
640 NVLoadStateExt(par, state); 640 NVLoadStateExt(par, state);
641 641
642 NVWriteMiscOut(par, state->misc_output); 642 NVWriteMiscOut(par, state->misc_output);
643 643
644 for (i = 1; i < NUM_SEQ_REGS; i++) {
645#ifdef DUMP_REG
646 printk(" SEQ[%02x] = %08x\n", i, state->seq[i]);
647#endif
648 NVWriteSeq(par, i, state->seq[i]);
649 }
650
651 /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 of CRTC[17] */
652 NVWriteCrtc(par, 0x11, state->crtc[0x11] & ~0x80);
653
644 for (i = 0; i < NUM_CRT_REGS; i++) { 654 for (i = 0; i < NUM_CRT_REGS; i++) {
645 switch (i) { 655 switch (i) {
646 case 0x19: 656 case 0x19:
647 case 0x20 ... 0x40: 657 case 0x20 ... 0x40:
648 break; 658 break;
649 default: 659 default:
660#ifdef DUMP_REG
661 printk("CRTC[%02x] = %08x\n", i, state->crtc[i]);
662#endif
650 NVWriteCrtc(par, i, state->crtc[i]); 663 NVWriteCrtc(par, i, state->crtc[i]);
651 } 664 }
652 } 665 }
653 666
654 for (i = 0; i < NUM_ATC_REGS; i++) 667 for (i = 0; i < NUM_GRC_REGS; i++) {
655 NVWriteAttr(par, i, state->attr[i]); 668#ifdef DUMP_REG
656 669 printk(" GRA[%02x] = %08x\n", i, state->gra[i]);
657 for (i = 0; i < NUM_GRC_REGS; i++) 670#endif
658 NVWriteGr(par, i, state->gra[i]); 671 NVWriteGr(par, i, state->gra[i]);
672 }
673
674 for (i = 0; i < NUM_ATC_REGS; i++) {
675#ifdef DUMP_REG
676 printk("ATTR[%02x] = %08x\n", i, state->attr[i]);
677#endif
678 NVWriteAttr(par, i, state->attr[i]);
679 }
659 680
660 for (i = 0; i < NUM_SEQ_REGS; i++)
661 NVWriteSeq(par, i, state->seq[i]);
662 NVTRACE_LEAVE(); 681 NVTRACE_LEAVE();
663} 682}
664 683
684static void nvidia_vga_protect(struct nvidia_par *par, int on)
685{
686 unsigned char tmp;
687
688 if (on) {
689 /*
690 * Turn off screen and disable sequencer.
691 */
692 tmp = NVReadSeq(par, 0x01);
693
694 NVWriteSeq(par, 0x00, 0x01); /* Synchronous Reset */
695 NVWriteSeq(par, 0x01, tmp | 0x20); /* disable the display */
696 } else {
697 /*
698 * Reenable sequencer, then turn on screen.
699 */
700
701 tmp = NVReadSeq(par, 0x01);
702
703 NVWriteSeq(par, 0x01, tmp & ~0x20); /* reenable display */
704 NVWriteSeq(par, 0x00, 0x03); /* End Reset */
705 }
706}
707
708
709
665static int nvidia_calc_regs(struct fb_info *info) 710static int nvidia_calc_regs(struct fb_info *info)
666{ 711{
667 struct nvidia_par *par = info->par; 712 struct nvidia_par *par = info->par;
@@ -868,7 +913,7 @@ static void nvidia_init_vga(struct fb_info *info)
868 for (i = 0; i < 0x10; i++) 913 for (i = 0; i < 0x10; i++)
869 state->attr[i] = i; 914 state->attr[i] = i;
870 state->attr[0x10] = 0x41; 915 state->attr[0x10] = 0x41;
871 state->attr[0x11] = 0x01; 916 state->attr[0x11] = 0xff;
872 state->attr[0x12] = 0x0f; 917 state->attr[0x12] = 0x0f;
873 state->attr[0x13] = 0x00; 918 state->attr[0x13] = 0x00;
874 state->attr[0x14] = 0x00; 919 state->attr[0x14] = 0x00;
@@ -982,16 +1027,24 @@ static int nvidiafb_set_par(struct fb_info *info)
982 NVTRACE_ENTER(); 1027 NVTRACE_ENTER();
983 1028
984 NVLockUnlock(par, 1); 1029 NVLockUnlock(par, 1);
985 if (!par->FlatPanel || (info->var.bits_per_pixel != 24) || 1030 if (!par->FlatPanel || !par->twoHeads)
986 !par->twoHeads)
987 par->FPDither = 0; 1031 par->FPDither = 0;
988 1032
1033 if (par->FPDither < 0) {
1034 if ((par->Chipset & 0x0ff0) == 0x0110)
1035 par->FPDither = !!(NV_RD32(par->PRAMDAC, 0x0528)
1036 & 0x00010000);
1037 else
1038 par->FPDither = !!(NV_RD32(par->PRAMDAC, 0x083C) & 1);
1039 printk(KERN_INFO PFX "Flat panel dithering %s\n",
1040 par->FPDither ? "enabled" : "disabled");
1041 }
1042
989 info->fix.visual = (info->var.bits_per_pixel == 8) ? 1043 info->fix.visual = (info->var.bits_per_pixel == 8) ?
990 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR; 1044 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
991 1045
992 nvidia_init_vga(info); 1046 nvidia_init_vga(info);
993 nvidia_calc_regs(info); 1047 nvidia_calc_regs(info);
994 nvidia_write_regs(par);
995 1048
996 NVLockUnlock(par, 0); 1049 NVLockUnlock(par, 0);
997 if (par->twoHeads) { 1050 if (par->twoHeads) {
@@ -1000,7 +1053,22 @@ static int nvidiafb_set_par(struct fb_info *info)
1000 NVLockUnlock(par, 0); 1053 NVLockUnlock(par, 0);
1001 } 1054 }
1002 1055
1003 NVWriteCrtc(par, 0x11, 0x00); 1056 nvidia_vga_protect(par, 1);
1057
1058 nvidia_write_regs(par);
1059
1060#if defined (__BIG_ENDIAN)
1061 /* turn on LFB swapping */
1062 {
1063 unsigned char tmp;
1064
1065 VGA_WR08(par->PCIO, 0x3d4, 0x46);
1066 tmp = VGA_RD08(par->PCIO, 0x3d5);
1067 tmp |= (1 << 7);
1068 VGA_WR08(par->PCIO, 0x3d5, tmp);
1069 }
1070#endif
1071
1004 info->fix.line_length = (info->var.xres_virtual * 1072 info->fix.line_length = (info->var.xres_virtual *
1005 info->var.bits_per_pixel) >> 3; 1073 info->var.bits_per_pixel) >> 3;
1006 if (info->var.accel_flags) { 1074 if (info->var.accel_flags) {
@@ -1022,7 +1090,7 @@ static int nvidiafb_set_par(struct fb_info *info)
1022 1090
1023 par->cursor_reset = 1; 1091 par->cursor_reset = 1;
1024 1092
1025 NVWriteCrtc(par, 0x11, 0xff); 1093 nvidia_vga_protect(par, 0);
1026 1094
1027 NVTRACE_LEAVE(); 1095 NVTRACE_LEAVE();
1028 return 0; 1096 return 0;
@@ -1315,22 +1383,10 @@ static int __devinit nvidia_set_fbinfo(struct fb_info *info)
1315 fb_var_to_videomode(&modedb, &nvidiafb_default_var); 1383 fb_var_to_videomode(&modedb, &nvidiafb_default_var);
1316 1384
1317 if (specs->modedb != NULL) { 1385 if (specs->modedb != NULL) {
1318 /* get preferred timing */ 1386 struct fb_videomode *modedb;
1319 if (specs->misc & FB_MISC_1ST_DETAIL) {
1320 int i;
1321
1322 for (i = 0; i < specs->modedb_len; i++) {
1323 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
1324 modedb = specs->modedb[i];
1325 break;
1326 }
1327 }
1328 } else {
1329 /* otherwise, get first mode in database */
1330 modedb = specs->modedb[0];
1331 }
1332 1387
1333 fb_videomode_to_var(&nvidiafb_default_var, &modedb); 1388 modedb = fb_find_best_display(specs, &info->modelist);
1389 fb_videomode_to_var(&nvidiafb_default_var, modedb);
1334 nvidiafb_default_var.bits_per_pixel = 8; 1390 nvidiafb_default_var.bits_per_pixel = 8;
1335 } else if (par->fpWidth && par->fpHeight) { 1391 } else if (par->fpWidth && par->fpHeight) {
1336 char buf[16]; 1392 char buf[16];
@@ -1365,7 +1421,7 @@ static int __devinit nvidia_set_fbinfo(struct fb_info *info)
1365 info->pixmap.flags = FB_PIXMAP_SYSTEM; 1421 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1366 1422
1367 if (!hwcur) 1423 if (!hwcur)
1368 info->fbops->fb_cursor = soft_cursor; 1424 info->fbops->fb_cursor = NULL;
1369 1425
1370 info->var.accel_flags = (!noaccel); 1426 info->var.accel_flags = (!noaccel);
1371 1427
@@ -1490,9 +1546,9 @@ static int __devinit nvidiafb_probe(struct pci_dev *pd,
1490 sprintf(nvidiafb_fix.id, "NV%x", (pd->device & 0x0ff0) >> 4); 1546 sprintf(nvidiafb_fix.id, "NV%x", (pd->device & 0x0ff0) >> 4);
1491 1547
1492 par->FlatPanel = flatpanel; 1548 par->FlatPanel = flatpanel;
1493
1494 if (flatpanel == 1) 1549 if (flatpanel == 1)
1495 printk(KERN_INFO PFX "flatpanel support enabled\n"); 1550 printk(KERN_INFO PFX "flatpanel support enabled\n");
1551 par->FPDither = fpdither;
1496 1552
1497 par->CRTCnumber = forceCRTC; 1553 par->CRTCnumber = forceCRTC;
1498 par->FpScale = (!noscale); 1554 par->FpScale = (!noscale);
@@ -1671,6 +1727,8 @@ static int __devinit nvidiafb_setup(char *options)
1671 } else if (!strncmp(this_opt, "nomtrr", 6)) { 1727 } else if (!strncmp(this_opt, "nomtrr", 6)) {
1672 nomtrr = 1; 1728 nomtrr = 1;
1673#endif 1729#endif
1730 } else if (!strncmp(this_opt, "fpdither:", 9)) {
1731 fpdither = simple_strtol(this_opt+9, NULL, 0);
1674 } else 1732 } else
1675 mode_option = this_opt; 1733 mode_option = this_opt;
1676 } 1734 }
@@ -1717,7 +1775,11 @@ module_exit(nvidiafb_exit);
1717module_param(flatpanel, int, 0); 1775module_param(flatpanel, int, 0);
1718MODULE_PARM_DESC(flatpanel, 1776MODULE_PARM_DESC(flatpanel,
1719 "Enables experimental flat panel support for some chipsets. " 1777 "Enables experimental flat panel support for some chipsets. "
1720 "(0 or 1=enabled) (default=0)"); 1778 "(0=disabled, 1=enabled, -1=autodetect) (default=-1)");
1779module_param(fpdither, int, 0);
1780MODULE_PARM_DESC(fpdither,
1781 "Enables dithering of flat panel for 6 bits panels. "
1782 "(0=disabled, 1=enabled, -1=autodetect) (default=-1)");
1721module_param(hwcur, int, 0); 1783module_param(hwcur, int, 0);
1722MODULE_PARM_DESC(hwcur, 1784MODULE_PARM_DESC(hwcur,
1723 "Enables hardware cursor implementation. (0 or 1=enabled) " 1785 "Enables hardware cursor implementation. (0 or 1=enabled) "
diff --git a/drivers/video/offb.c b/drivers/video/offb.c
index 611922c0b22f..2c856838694e 100644
--- a/drivers/video/offb.c
+++ b/drivers/video/offb.c
@@ -85,7 +85,6 @@ static struct fb_ops offb_ops = {
85 .fb_fillrect = cfb_fillrect, 85 .fb_fillrect = cfb_fillrect,
86 .fb_copyarea = cfb_copyarea, 86 .fb_copyarea = cfb_copyarea,
87 .fb_imageblit = cfb_imageblit, 87 .fb_imageblit = cfb_imageblit,
88 .fb_cursor = soft_cursor,
89}; 88};
90 89
91 /* 90 /*
diff --git a/drivers/video/p9100.c b/drivers/video/p9100.c
index b76a5a9a125b..9aaf65fb623a 100644
--- a/drivers/video/p9100.c
+++ b/drivers/video/p9100.c
@@ -48,7 +48,6 @@ static struct fb_ops p9100_ops = {
48 .fb_imageblit = cfb_imageblit, 48 .fb_imageblit = cfb_imageblit,
49 .fb_mmap = p9100_mmap, 49 .fb_mmap = p9100_mmap,
50 .fb_ioctl = p9100_ioctl, 50 .fb_ioctl = p9100_ioctl,
51 .fb_cursor = soft_cursor,
52}; 51};
53 52
54/* P9100 control registers */ 53/* P9100 control registers */
diff --git a/drivers/video/platinumfb.c b/drivers/video/platinumfb.c
index b00887e9851c..ca4082ae5a18 100644
--- a/drivers/video/platinumfb.c
+++ b/drivers/video/platinumfb.c
@@ -109,7 +109,6 @@ static struct fb_ops platinumfb_ops = {
109 .fb_fillrect = cfb_fillrect, 109 .fb_fillrect = cfb_fillrect,
110 .fb_copyarea = cfb_copyarea, 110 .fb_copyarea = cfb_copyarea,
111 .fb_imageblit = cfb_imageblit, 111 .fb_imageblit = cfb_imageblit,
112 .fb_cursor = soft_cursor,
113}; 112};
114 113
115/* 114/*
diff --git a/drivers/video/pm2fb.c b/drivers/video/pm2fb.c
index 42c17efa9fb0..0277ce031e5e 100644
--- a/drivers/video/pm2fb.c
+++ b/drivers/video/pm2fb.c
@@ -1034,7 +1034,6 @@ static struct fb_ops pm2fb_ops = {
1034 .fb_fillrect = cfb_fillrect, 1034 .fb_fillrect = cfb_fillrect,
1035 .fb_copyarea = cfb_copyarea, 1035 .fb_copyarea = cfb_copyarea,
1036 .fb_imageblit = cfb_imageblit, 1036 .fb_imageblit = cfb_imageblit,
1037 .fb_cursor = soft_cursor,
1038}; 1037};
1039 1038
1040/* 1039/*
@@ -1121,6 +1120,22 @@ static int __devinit pm2fb_probe(struct pci_dev *pdev,
1121 default_par->mem_control, default_par->boot_address, 1120 default_par->mem_control, default_par->boot_address,
1122 default_par->mem_config); 1121 default_par->mem_config);
1123 1122
1123 if(default_par->mem_control == 0 &&
1124 default_par->boot_address == 0x31 &&
1125 default_par->mem_config == 0x259fffff &&
1126 pdev->subsystem_vendor == 0x1048 &&
1127 pdev->subsystem_device == 0x0a31) {
1128 DPRINTK("subsystem_vendor: %04x, subsystem_device: %04x\n",
1129 pdev->subsystem_vendor, pdev->subsystem_device);
1130 DPRINTK("We have not been initialized by VGA BIOS "
1131 "and are running on an Elsa Winner 2000 Office\n");
1132 DPRINTK("Initializing card timings manually...\n");
1133 default_par->mem_control=0;
1134 default_par->boot_address=0x20;
1135 default_par->mem_config=0xe6002021;
1136 default_par->memclock=100000;
1137 }
1138
1124 /* Now work out how big lfb is going to be. */ 1139 /* Now work out how big lfb is going to be. */
1125 switch(default_par->mem_config & PM2F_MEM_CONFIG_RAM_MASK) { 1140 switch(default_par->mem_config & PM2F_MEM_CONFIG_RAM_MASK) {
1126 case PM2F_MEM_BANKS_1: 1141 case PM2F_MEM_BANKS_1:
diff --git a/drivers/video/pmag-ba-fb.c b/drivers/video/pmag-ba-fb.c
index c98f1c8d7dc2..f3927b6cda9d 100644
--- a/drivers/video/pmag-ba-fb.c
+++ b/drivers/video/pmag-ba-fb.c
@@ -128,7 +128,6 @@ static struct fb_ops pmagbafb_ops = {
128 .fb_fillrect = cfb_fillrect, 128 .fb_fillrect = cfb_fillrect,
129 .fb_copyarea = cfb_copyarea, 129 .fb_copyarea = cfb_copyarea,
130 .fb_imageblit = cfb_imageblit, 130 .fb_imageblit = cfb_imageblit,
131 .fb_cursor = soft_cursor,
132}; 131};
133 132
134 133
diff --git a/drivers/video/pmagb-b-fb.c b/drivers/video/pmagb-b-fb.c
index a483b13e117b..25148de5fe67 100644
--- a/drivers/video/pmagb-b-fb.c
+++ b/drivers/video/pmagb-b-fb.c
@@ -132,7 +132,6 @@ static struct fb_ops pmagbbfb_ops = {
132 .fb_fillrect = cfb_fillrect, 132 .fb_fillrect = cfb_fillrect,
133 .fb_copyarea = cfb_copyarea, 133 .fb_copyarea = cfb_copyarea,
134 .fb_imageblit = cfb_imageblit, 134 .fb_imageblit = cfb_imageblit,
135 .fb_cursor = soft_cursor,
136}; 135};
137 136
138 137
diff --git a/drivers/video/pvr2fb.c b/drivers/video/pvr2fb.c
index 31c547fd383b..ec4bacf9dd2e 100644
--- a/drivers/video/pvr2fb.c
+++ b/drivers/video/pvr2fb.c
@@ -230,7 +230,6 @@ static struct fb_ops pvr2fb_ops = {
230 .fb_fillrect = cfb_fillrect, 230 .fb_fillrect = cfb_fillrect,
231 .fb_copyarea = cfb_copyarea, 231 .fb_copyarea = cfb_copyarea,
232 .fb_imageblit = cfb_imageblit, 232 .fb_imageblit = cfb_imageblit,
233 .fb_cursor = soft_cursor,
234}; 233};
235 234
236static struct fb_videomode pvr2_modedb[] __initdata = { 235static struct fb_videomode pvr2_modedb[] __initdata = {
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c
index efd9333b05c2..f305a5b77b23 100644
--- a/drivers/video/pxafb.c
+++ b/drivers/video/pxafb.c
@@ -418,7 +418,6 @@ static struct fb_ops pxafb_ops = {
418 .fb_copyarea = cfb_copyarea, 418 .fb_copyarea = cfb_copyarea,
419 .fb_imageblit = cfb_imageblit, 419 .fb_imageblit = cfb_imageblit,
420 .fb_blank = pxafb_blank, 420 .fb_blank = pxafb_blank,
421 .fb_cursor = soft_cursor,
422 .fb_mmap = pxafb_mmap, 421 .fb_mmap = pxafb_mmap,
423}; 422};
424 423
diff --git a/drivers/video/q40fb.c b/drivers/video/q40fb.c
index 8416b2e2b501..bfc41f2c902a 100644
--- a/drivers/video/q40fb.c
+++ b/drivers/video/q40fb.c
@@ -84,7 +84,6 @@ static struct fb_ops q40fb_ops = {
84 .fb_fillrect = cfb_fillrect, 84 .fb_fillrect = cfb_fillrect,
85 .fb_copyarea = cfb_copyarea, 85 .fb_copyarea = cfb_copyarea,
86 .fb_imageblit = cfb_imageblit, 86 .fb_imageblit = cfb_imageblit,
87 .fb_cursor = soft_cursor,
88}; 87};
89 88
90static int __init q40fb_probe(struct device *device) 89static int __init q40fb_probe(struct device *device)
diff --git a/drivers/video/radeonfb.c b/drivers/video/radeonfb.c
index a78b9bd8f897..600318f708f2 100644
--- a/drivers/video/radeonfb.c
+++ b/drivers/video/radeonfb.c
@@ -2218,7 +2218,6 @@ static struct fb_ops radeonfb_ops = {
2218 .fb_copyarea = cfb_copyarea, 2218 .fb_copyarea = cfb_copyarea,
2219 .fb_imageblit = cfb_imageblit, 2219 .fb_imageblit = cfb_imageblit,
2220#endif 2220#endif
2221 .fb_cursor = soft_cursor,
2222}; 2221};
2223 2222
2224 2223
diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
index f4437430dc5f..3edbd14c5c46 100644
--- a/drivers/video/s1d13xxxfb.c
+++ b/drivers/video/s1d13xxxfb.c
@@ -388,7 +388,6 @@ static struct fb_ops s1d13xxxfb_fbops = {
388 .fb_fillrect = cfb_fillrect, 388 .fb_fillrect = cfb_fillrect,
389 .fb_copyarea = cfb_copyarea, 389 .fb_copyarea = cfb_copyarea,
390 .fb_imageblit = cfb_imageblit, 390 .fb_imageblit = cfb_imageblit,
391 .fb_cursor = soft_cursor
392}; 391};
393 392
394static int s1d13xxxfb_width_tab[2][4] __devinitdata = { 393static int s1d13xxxfb_width_tab[2][4] __devinitdata = {
diff --git a/drivers/video/s3c2410fb.c b/drivers/video/s3c2410fb.c
index 3cef90456a4b..855a6778b9eb 100644
--- a/drivers/video/s3c2410fb.c
+++ b/drivers/video/s3c2410fb.c
@@ -495,7 +495,6 @@ static struct fb_ops s3c2410fb_ops = {
495 .fb_fillrect = cfb_fillrect, 495 .fb_fillrect = cfb_fillrect,
496 .fb_copyarea = cfb_copyarea, 496 .fb_copyarea = cfb_copyarea,
497 .fb_imageblit = cfb_imageblit, 497 .fb_imageblit = cfb_imageblit,
498 .fb_cursor = soft_cursor,
499}; 498};
500 499
501 500
@@ -885,6 +884,7 @@ static int s3c2410fb_resume(struct device *dev)
885 884
886static struct device_driver s3c2410fb_driver = { 885static struct device_driver s3c2410fb_driver = {
887 .name = "s3c2410-lcd", 886 .name = "s3c2410-lcd",
887 .owner = THIS_MODULE,
888 .bus = &platform_bus_type, 888 .bus = &platform_bus_type,
889 .probe = s3c2410fb_probe, 889 .probe = s3c2410fb_probe,
890 .suspend = s3c2410fb_suspend, 890 .suspend = s3c2410fb_suspend,
diff --git a/drivers/video/sa1100fb.c b/drivers/video/sa1100fb.c
index 3d35b28aaac7..a5184575cfae 100644
--- a/drivers/video/sa1100fb.c
+++ b/drivers/video/sa1100fb.c
@@ -853,7 +853,6 @@ static struct fb_ops sa1100fb_ops = {
853 .fb_copyarea = cfb_copyarea, 853 .fb_copyarea = cfb_copyarea,
854 .fb_imageblit = cfb_imageblit, 854 .fb_imageblit = cfb_imageblit,
855 .fb_blank = sa1100fb_blank, 855 .fb_blank = sa1100fb_blank,
856 .fb_cursor = soft_cursor,
857 .fb_mmap = sa1100fb_mmap, 856 .fb_mmap = sa1100fb_mmap,
858}; 857};
859 858
diff --git a/drivers/video/savage/savagefb.h b/drivers/video/savage/savagefb.h
index ea17f7e0482c..58cfdfb41833 100644
--- a/drivers/video/savage/savagefb.h
+++ b/drivers/video/savage/savagefb.h
@@ -169,6 +169,7 @@ struct savagefb_par {
169 struct savagefb_i2c_chan chan; 169 struct savagefb_i2c_chan chan;
170 unsigned char *edid; 170 unsigned char *edid;
171 u32 pseudo_palette[16]; 171 u32 pseudo_palette[16];
172 int paletteEnabled;
172 int pm_state; 173 int pm_state;
173 int display_type; 174 int display_type;
174 int dvi; 175 int dvi;
@@ -244,105 +245,150 @@ struct savagefb_par {
244 245
245 246
246/* IO functions */ 247/* IO functions */
248static inline u8 savage_in8(u32 addr, struct savagefb_par *par)
249{
250 return readb(par->mmio.vbase + addr);
251}
252
253static inline u16 savage_in16(u32 addr, struct savagefb_par *par)
254{
255 return readw(par->mmio.vbase + addr);
256}
257
258static inline u32 savage_in32(u32 addr, struct savagefb_par *par)
259{
260 return readl(par->mmio.vbase + addr);
261}
262
263static inline void savage_out8(u32 addr, u8 val, struct savagefb_par *par)
264{
265 writeb(val, par->mmio.vbase + addr);
266}
267
268static inline void savage_out16(u32 addr, u16 val, struct savagefb_par *par)
269{
270 writew(val, par->mmio.vbase + addr);
271}
272
273static inline void savage_out32(u32 addr, u32 val, struct savagefb_par *par)
274{
275 writel(val, par->mmio.vbase + addr);
276}
277
278static inline u8 vga_in8(int addr, struct savagefb_par *par)
279{
280 return savage_in8(0x8000 + addr, par);
281}
282
283static inline u16 vga_in16(int addr, struct savagefb_par *par)
284{
285 return savage_in16(0x8000 + addr, par);
286}
287
288static inline u8 vga_in32(int addr, struct savagefb_par *par)
289{
290 return savage_in32(0x8000 + addr, par);
291}
292
293static inline void vga_out8(int addr, u8 val, struct savagefb_par *par)
294{
295 savage_out8(0x8000 + addr, val, par);
296}
297
298static inline void vga_out16(int addr, u16 val, struct savagefb_par *par)
299{
300 savage_out16(0x8000 + addr, val, par);
301}
302
303static inline void vga_out32(int addr, u32 val, struct savagefb_par *par)
304{
305 savage_out32(0x8000 + addr, val, par);
306}
247 307
248#define vga_in8(addr) (inb (addr)) 308static inline u8 VGArCR (u8 index, struct savagefb_par *par)
249#define vga_in16(addr) (inw (addr)) 309{
250#define vga_in32(addr) (inl (addr)) 310 vga_out8(0x3d4, index, par);
311 return vga_in8(0x3d5, par);
312}
313
314static inline u8 VGArGR (u8 index, struct savagefb_par *par)
315{
316 vga_out8(0x3ce, index, par);
317 return vga_in8(0x3cf, par);
318}
319
320static inline u8 VGArSEQ (u8 index, struct savagefb_par *par)
321{
322 vga_out8(0x3c4, index, par);
323 return vga_in8(0x3c5, par);
324}
251 325
252#define vga_out8(addr,val) (outb ((val), (addr))) 326static inline void VGAwCR(u8 index, u8 val, struct savagefb_par *par)
253#define vga_out16(addr,val) (outw ((val), (addr))) 327{
254#define vga_out32(addr,val) (outl ((val), (addr))) 328 vga_out8(0x3d4, index, par);
329 vga_out8(0x3d5, val, par);
330}
255 331
256#define savage_in16(addr) readw(par->mmio.vbase + (addr)) 332static inline void VGAwGR(u8 index, u8 val, struct savagefb_par *par)
257#define savage_in32(addr) readl(par->mmio.vbase + (addr)) 333{
334 vga_out8(0x3ce, index, par);
335 vga_out8(0x3cf, val, par);
336}
258 337
259#define savage_out16(addr,val) writew((val), par->mmio.vbase + (addr)) 338static inline void VGAwSEQ(u8 index, u8 val, struct savagefb_par *par)
260#define savage_out32(addr,val) writel((val), par->mmio.vbase + (addr)) 339{
340 vga_out8(0x3c4, index, par);
341 vga_out8 (0x3c5, val, par);
342}
261 343
262static inline u8 VGArCR (u8 index) 344static inline void VGAenablePalette(struct savagefb_par *par)
263{ 345{
264 outb (index, 0x3d4); 346 u8 tmp;
265 return inb (0x3d5); 347
348 tmp = vga_in8(0x3da, par);
349 vga_out8(0x3c0, 0x00, par);
350 par->paletteEnabled = 1;
266} 351}
267 352
268static inline u8 VGArGR (u8 index) 353static inline void VGAdisablePalette(struct savagefb_par *par)
269{ 354{
270 outb (index, 0x3ce); 355 u8 tmp;
271 return inb (0x3cf); 356
357 tmp = vga_in8(0x3da, par);
358 vga_out8(0x3c0, 0x20, par);
359 par->paletteEnabled = 0;
272} 360}
273 361
274static inline u8 VGArSEQ (u8 index) 362static inline void VGAwATTR(u8 index, u8 value, struct savagefb_par *par)
275{ 363{
276 outb (index, 0x3c4); 364 u8 tmp;
277 return inb (0x3c5); 365
366 if (par->paletteEnabled)
367 index &= ~0x20;
368 else
369 index |= 0x20;
370
371 tmp = vga_in8(0x3da, par);
372 vga_out8(0x3c0, index, par);
373 vga_out8 (0x3c0, value, par);
278} 374}
279 375
280#define VGAwCR(index, val) \ 376static inline void VGAwMISC(u8 value, struct savagefb_par *par)
281do { \ 377{
282 vga_out8 (0x3d4, index); \ 378 vga_out8(0x3c2, value, par);
283 vga_out8 (0x3d5, val); \ 379}
284} while (0)
285
286#define VGAwGR(index, val) \
287do { \
288 vga_out8 (0x3ce, index); \
289 vga_out8 (0x3cf, val); \
290} while (0)
291
292#define VGAwSEQ(index, val) \
293do { \
294 vga_out8 (0x3c4, index); \
295 vga_out8 (0x3c5, val); \
296} while (0)
297
298#define VGAenablePalette() \
299do { \
300 u8 tmp; \
301 \
302 tmp = vga_in8 (0x3da); \
303 vga_out8 (0x3c0, 0x00); \
304 paletteEnabled = 1; \
305} while (0)
306
307#define VGAdisablePalette() \
308do { \
309 u8 tmp; \
310 \
311 tmp = vga_in8 (0x3da); \
312 vga_out8 (0x3c0, 0x20); \
313 paletteEnabled = 0; \
314} while (0)
315
316#define VGAwATTR(index, value) \
317do { \
318 u8 tmp; \
319 \
320 if (paletteEnabled) \
321 index &= ~0x20; \
322 else \
323 index |= 0x20; \
324 \
325 tmp = vga_in8 (0x3da); \
326 vga_out8 (0x3c0, index); \
327 vga_out8 (0x3c0, value); \
328} while (0)
329
330#define VGAwMISC(value) \
331do { \
332 vga_out8 (0x3c2, value); \
333} while (0)
334 380
335#ifndef CONFIG_FB_SAVAGE_ACCEL 381#ifndef CONFIG_FB_SAVAGE_ACCEL
336#define savagefb_set_clip(x) 382#define savagefb_set_clip(x)
337#endif 383#endif
338 384
339#define VerticalRetraceWait() \ 385static inline void VerticalRetraceWait(struct savagefb_par *par)
340{ \ 386{
341 vga_out8 (0x3d4, 0x17); \ 387 vga_out8(0x3d4, 0x17, par);
342 if (vga_in8 (0x3d5) & 0x80) { \ 388 if (vga_in8(0x3d5, par) & 0x80) {
343 while ((vga_in8(0x3da) & 0x08) == 0x08) ; \ 389 while ((vga_in8(0x3da, par) & 0x08) == 0x08);
344 while ((vga_in8(0x3da) & 0x08) == 0x00) ; \ 390 while ((vga_in8(0x3da, par) & 0x08) == 0x00);
345 } \ 391 }
346} 392}
347 393
348extern int savagefb_probe_i2c_connector(struct fb_info *info, 394extern int savagefb_probe_i2c_connector(struct fb_info *info,
diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c
index 7c285455c924..f0dfb35e3191 100644
--- a/drivers/video/savage/savagefb_driver.c
+++ b/drivers/video/savage/savagefb_driver.c
@@ -74,7 +74,6 @@
74 74
75 75
76static char *mode_option __initdata = NULL; 76static char *mode_option __initdata = NULL;
77static int paletteEnabled = 0;
78 77
79#ifdef MODULE 78#ifdef MODULE
80 79
@@ -90,9 +89,9 @@ MODULE_DESCRIPTION("FBDev driver for S3 Savage PCI/AGP Chips");
90static void vgaHWSeqReset (struct savagefb_par *par, int start) 89static void vgaHWSeqReset (struct savagefb_par *par, int start)
91{ 90{
92 if (start) 91 if (start)
93 VGAwSEQ (0x00, 0x01); /* Synchronous Reset */ 92 VGAwSEQ (0x00, 0x01, par); /* Synchronous Reset */
94 else 93 else
95 VGAwSEQ (0x00, 0x03); /* End Reset */ 94 VGAwSEQ (0x00, 0x03, par); /* End Reset */
96} 95}
97 96
98static void vgaHWProtect (struct savagefb_par *par, int on) 97static void vgaHWProtect (struct savagefb_par *par, int on)
@@ -103,23 +102,23 @@ static void vgaHWProtect (struct savagefb_par *par, int on)
103 /* 102 /*
104 * Turn off screen and disable sequencer. 103 * Turn off screen and disable sequencer.
105 */ 104 */
106 tmp = VGArSEQ (0x01); 105 tmp = VGArSEQ (0x01, par);
107 106
108 vgaHWSeqReset (par, 1); /* start synchronous reset */ 107 vgaHWSeqReset (par, 1); /* start synchronous reset */
109 VGAwSEQ (0x01, tmp | 0x20); /* disable the display */ 108 VGAwSEQ (0x01, tmp | 0x20, par);/* disable the display */
110 109
111 VGAenablePalette(); 110 VGAenablePalette(par);
112 } else { 111 } else {
113 /* 112 /*
114 * Reenable sequencer, then turn on screen. 113 * Reenable sequencer, then turn on screen.
115 */ 114 */
116 115
117 tmp = VGArSEQ (0x01); 116 tmp = VGArSEQ (0x01, par);
118 117
119 VGAwSEQ (0x01, tmp & ~0x20); /* reenable display */ 118 VGAwSEQ (0x01, tmp & ~0x20, par);/* reenable display */
120 vgaHWSeqReset (par, 0); /* clear synchronous reset */ 119 vgaHWSeqReset (par, 0); /* clear synchronous reset */
121 120
122 VGAdisablePalette(); 121 VGAdisablePalette(par);
123 } 122 }
124} 123}
125 124
@@ -127,27 +126,27 @@ static void vgaHWRestore (struct savagefb_par *par)
127{ 126{
128 int i; 127 int i;
129 128
130 VGAwMISC (par->MiscOutReg); 129 VGAwMISC (par->MiscOutReg, par);
131 130
132 for (i = 1; i < 5; i++) 131 for (i = 1; i < 5; i++)
133 VGAwSEQ (i, par->Sequencer[i]); 132 VGAwSEQ (i, par->Sequencer[i], par);
134 133
135 /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 or 134 /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 or
136 CRTC[17] */ 135 CRTC[17] */
137 VGAwCR (17, par->CRTC[17] & ~0x80); 136 VGAwCR (17, par->CRTC[17] & ~0x80, par);
138 137
139 for (i = 0; i < 25; i++) 138 for (i = 0; i < 25; i++)
140 VGAwCR (i, par->CRTC[i]); 139 VGAwCR (i, par->CRTC[i], par);
141 140
142 for (i = 0; i < 9; i++) 141 for (i = 0; i < 9; i++)
143 VGAwGR (i, par->Graphics[i]); 142 VGAwGR (i, par->Graphics[i], par);
144 143
145 VGAenablePalette(); 144 VGAenablePalette(par);
146 145
147 for (i = 0; i < 21; i++) 146 for (i = 0; i < 21; i++)
148 VGAwATTR (i, par->Attribute[i]); 147 VGAwATTR (i, par->Attribute[i], par);
149 148
150 VGAdisablePalette(); 149 VGAdisablePalette(par);
151} 150}
152 151
153static void vgaHWInit (struct fb_var_screeninfo *var, 152static void vgaHWInit (struct fb_var_screeninfo *var,
@@ -267,7 +266,7 @@ savage3D_waitfifo(struct savagefb_par *par, int space)
267{ 266{
268 int slots = MAXFIFO - space; 267 int slots = MAXFIFO - space;
269 268
270 while ((savage_in32(0x48C00) & 0x0000ffff) > slots); 269 while ((savage_in32(0x48C00, par) & 0x0000ffff) > slots);
271} 270}
272 271
273static void 272static void
@@ -275,7 +274,7 @@ savage4_waitfifo(struct savagefb_par *par, int space)
275{ 274{
276 int slots = MAXFIFO - space; 275 int slots = MAXFIFO - space;
277 276
278 while ((savage_in32(0x48C60) & 0x001fffff) > slots); 277 while ((savage_in32(0x48C60, par) & 0x001fffff) > slots);
279} 278}
280 279
281static void 280static void
@@ -283,26 +282,26 @@ savage2000_waitfifo(struct savagefb_par *par, int space)
283{ 282{
284 int slots = MAXFIFO - space; 283 int slots = MAXFIFO - space;
285 284
286 while ((savage_in32(0x48C60) & 0x0000ffff) > slots); 285 while ((savage_in32(0x48C60, par) & 0x0000ffff) > slots);
287} 286}
288 287
289/* Wait for idle accelerator */ 288/* Wait for idle accelerator */
290static void 289static void
291savage3D_waitidle(struct savagefb_par *par) 290savage3D_waitidle(struct savagefb_par *par)
292{ 291{
293 while ((savage_in32(0x48C00) & 0x0008ffff) != 0x80000); 292 while ((savage_in32(0x48C00, par) & 0x0008ffff) != 0x80000);
294} 293}
295 294
296static void 295static void
297savage4_waitidle(struct savagefb_par *par) 296savage4_waitidle(struct savagefb_par *par)
298{ 297{
299 while ((savage_in32(0x48C60) & 0x00a00000) != 0x00a00000); 298 while ((savage_in32(0x48C60, par) & 0x00a00000) != 0x00a00000);
300} 299}
301 300
302static void 301static void
303savage2000_waitidle(struct savagefb_par *par) 302savage2000_waitidle(struct savagefb_par *par)
304{ 303{
305 while ((savage_in32(0x48C60) & 0x009fffff)); 304 while ((savage_in32(0x48C60, par) & 0x009fffff));
306} 305}
307 306
308 307
@@ -319,59 +318,64 @@ SavageSetup2DEngine (struct savagefb_par *par)
319 case S3_SAVAGE3D: 318 case S3_SAVAGE3D:
320 case S3_SAVAGE_MX: 319 case S3_SAVAGE_MX:
321 /* Disable BCI */ 320 /* Disable BCI */
322 savage_out32(0x48C18, savage_in32(0x48C18) & 0x3FF0); 321 savage_out32(0x48C18, savage_in32(0x48C18, par) & 0x3FF0, par);
323 /* Setup BCI command overflow buffer */ 322 /* Setup BCI command overflow buffer */
324 savage_out32(0x48C14, (par->cob_offset >> 11) | (par->cob_index << 29)); 323 savage_out32(0x48C14,
324 (par->cob_offset >> 11) | (par->cob_index << 29),
325 par);
325 /* Program shadow status update. */ 326 /* Program shadow status update. */
326 savage_out32(0x48C10, 0x78207220); 327 savage_out32(0x48C10, 0x78207220, par);
327 savage_out32(0x48C0C, 0); 328 savage_out32(0x48C0C, 0, par);
328 /* Enable BCI and command overflow buffer */ 329 /* Enable BCI and command overflow buffer */
329 savage_out32(0x48C18, savage_in32(0x48C18) | 0x0C); 330 savage_out32(0x48C18, savage_in32(0x48C18, par) | 0x0C, par);
330 break; 331 break;
331 case S3_SAVAGE4: 332 case S3_SAVAGE4:
332 case S3_PROSAVAGE: 333 case S3_PROSAVAGE:
333 case S3_SUPERSAVAGE: 334 case S3_SUPERSAVAGE:
334 /* Disable BCI */ 335 /* Disable BCI */
335 savage_out32(0x48C18, savage_in32(0x48C18) & 0x3FF0); 336 savage_out32(0x48C18, savage_in32(0x48C18, par) & 0x3FF0, par);
336 /* Program shadow status update */ 337 /* Program shadow status update */
337 savage_out32(0x48C10, 0x00700040); 338 savage_out32(0x48C10, 0x00700040, par);
338 savage_out32(0x48C0C, 0); 339 savage_out32(0x48C0C, 0, par);
339 /* Enable BCI without the COB */ 340 /* Enable BCI without the COB */
340 savage_out32(0x48C18, savage_in32(0x48C18) | 0x08); 341 savage_out32(0x48C18, savage_in32(0x48C18, par) | 0x08, par);
341 break; 342 break;
342 case S3_SAVAGE2000: 343 case S3_SAVAGE2000:
343 /* Disable BCI */ 344 /* Disable BCI */
344 savage_out32(0x48C18, 0); 345 savage_out32(0x48C18, 0, par);
345 /* Setup BCI command overflow buffer */ 346 /* Setup BCI command overflow buffer */
346 savage_out32(0x48C18, (par->cob_offset >> 7) | (par->cob_index)); 347 savage_out32(0x48C18,
348 (par->cob_offset >> 7) | (par->cob_index),
349 par);
347 /* Disable shadow status update */ 350 /* Disable shadow status update */
348 savage_out32(0x48A30, 0); 351 savage_out32(0x48A30, 0, par);
349 /* Enable BCI and command overflow buffer */ 352 /* Enable BCI and command overflow buffer */
350 savage_out32(0x48C18, savage_in32(0x48C18) | 0x00280000 ); 353 savage_out32(0x48C18, savage_in32(0x48C18, par) | 0x00280000,
354 par);
351 break; 355 break;
352 default: 356 default:
353 break; 357 break;
354 } 358 }
355 /* Turn on 16-bit register access. */ 359 /* Turn on 16-bit register access. */
356 vga_out8(0x3d4, 0x31); 360 vga_out8(0x3d4, 0x31, par);
357 vga_out8(0x3d5, 0x0c); 361 vga_out8(0x3d5, 0x0c, par);
358 362
359 /* Set stride to use GBD. */ 363 /* Set stride to use GBD. */
360 vga_out8 (0x3d4, 0x50); 364 vga_out8 (0x3d4, 0x50, par);
361 vga_out8 (0x3d5, vga_in8 (0x3d5 ) | 0xC1); 365 vga_out8 (0x3d5, vga_in8(0x3d5, par) | 0xC1, par);
362 366
363 /* Enable 2D engine. */ 367 /* Enable 2D engine. */
364 vga_out8 (0x3d4, 0x40 ); 368 vga_out8 (0x3d4, 0x40, par);
365 vga_out8 (0x3d5, 0x01 ); 369 vga_out8 (0x3d5, 0x01, par);
366 370
367 savage_out32 (MONO_PAT_0, ~0); 371 savage_out32 (MONO_PAT_0, ~0, par);
368 savage_out32 (MONO_PAT_1, ~0); 372 savage_out32 (MONO_PAT_1, ~0, par);
369 373
370 /* Setup plane masks */ 374 /* Setup plane masks */
371 savage_out32 (0x8128, ~0 ); /* enable all write planes */ 375 savage_out32 (0x8128, ~0, par); /* enable all write planes */
372 savage_out32 (0x812C, ~0 ); /* enable all read planes */ 376 savage_out32 (0x812C, ~0, par); /* enable all read planes */
373 savage_out16 (0x8134, 0x27 ); 377 savage_out16 (0x8134, 0x27, par);
374 savage_out16 (0x8136, 0x07 ); 378 savage_out16 (0x8136, 0x07, par);
375 379
376 /* Now set the GBD */ 380 /* Now set the GBD */
377 par->bci_ptr = 0; 381 par->bci_ptr = 0;
@@ -489,8 +493,8 @@ static void SavagePrintRegs(void)
489 for( i = 0; i < 0x70; i++ ) { 493 for( i = 0; i < 0x70; i++ ) {
490 if( !(i % 16) ) 494 if( !(i % 16) )
491 printk(KERN_DEBUG "\nSR%xx ", i >> 4 ); 495 printk(KERN_DEBUG "\nSR%xx ", i >> 4 );
492 vga_out8( 0x3c4, i ); 496 vga_out8( 0x3c4, i, par);
493 printk(KERN_DEBUG " %02x", vga_in8(0x3c5) ); 497 printk(KERN_DEBUG " %02x", vga_in8(0x3c5, par) );
494 } 498 }
495 499
496 printk(KERN_DEBUG "\n\nCR x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC " 500 printk(KERN_DEBUG "\n\nCR x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC "
@@ -499,8 +503,8 @@ static void SavagePrintRegs(void)
499 for( i = 0; i < 0xB7; i++ ) { 503 for( i = 0; i < 0xB7; i++ ) {
500 if( !(i % 16) ) 504 if( !(i % 16) )
501 printk(KERN_DEBUG "\nCR%xx ", i >> 4 ); 505 printk(KERN_DEBUG "\nCR%xx ", i >> 4 );
502 vga_out8( vgaCRIndex, i ); 506 vga_out8( vgaCRIndex, i, par);
503 printk(KERN_DEBUG " %02x", vga_in8(vgaCRReg) ); 507 printk(KERN_DEBUG " %02x", vga_in8(vgaCRReg, par) );
504 } 508 }
505 509
506 printk(KERN_DEBUG "\n\n"); 510 printk(KERN_DEBUG "\n\n");
@@ -513,152 +517,152 @@ static void savage_get_default_par(struct savagefb_par *par)
513{ 517{
514 unsigned char cr3a, cr53, cr66; 518 unsigned char cr3a, cr53, cr66;
515 519
516 vga_out16 (0x3d4, 0x4838); 520 vga_out16 (0x3d4, 0x4838, par);
517 vga_out16 (0x3d4, 0xa039); 521 vga_out16 (0x3d4, 0xa039, par);
518 vga_out16 (0x3c4, 0x0608); 522 vga_out16 (0x3c4, 0x0608, par);
519 523
520 vga_out8 (0x3d4, 0x66); 524 vga_out8 (0x3d4, 0x66, par);
521 cr66 = vga_in8 (0x3d5); 525 cr66 = vga_in8 (0x3d5, par);
522 vga_out8 (0x3d5, cr66 | 0x80); 526 vga_out8 (0x3d5, cr66 | 0x80, par);
523 vga_out8 (0x3d4, 0x3a); 527 vga_out8 (0x3d4, 0x3a, par);
524 cr3a = vga_in8 (0x3d5); 528 cr3a = vga_in8 (0x3d5, par);
525 vga_out8 (0x3d5, cr3a | 0x80); 529 vga_out8 (0x3d5, cr3a | 0x80, par);
526 vga_out8 (0x3d4, 0x53); 530 vga_out8 (0x3d4, 0x53, par);
527 cr53 = vga_in8 (0x3d5); 531 cr53 = vga_in8 (0x3d5, par);
528 vga_out8 (0x3d5, cr53 & 0x7f); 532 vga_out8 (0x3d5, cr53 & 0x7f, par);
529 533
530 vga_out8 (0x3d4, 0x66); 534 vga_out8 (0x3d4, 0x66, par);
531 vga_out8 (0x3d5, cr66); 535 vga_out8 (0x3d5, cr66, par);
532 vga_out8 (0x3d4, 0x3a); 536 vga_out8 (0x3d4, 0x3a, par);
533 vga_out8 (0x3d5, cr3a); 537 vga_out8 (0x3d5, cr3a, par);
534 538
535 vga_out8 (0x3d4, 0x66); 539 vga_out8 (0x3d4, 0x66, par);
536 vga_out8 (0x3d5, cr66); 540 vga_out8 (0x3d5, cr66, par);
537 vga_out8 (0x3d4, 0x3a); 541 vga_out8 (0x3d4, 0x3a, par);
538 vga_out8 (0x3d5, cr3a); 542 vga_out8 (0x3d5, cr3a, par);
539 543
540 /* unlock extended seq regs */ 544 /* unlock extended seq regs */
541 vga_out8 (0x3c4, 0x08); 545 vga_out8 (0x3c4, 0x08, par);
542 par->SR08 = vga_in8 (0x3c5); 546 par->SR08 = vga_in8 (0x3c5, par);
543 vga_out8 (0x3c5, 0x06); 547 vga_out8 (0x3c5, 0x06, par);
544 548
545 /* now save all the extended regs we need */ 549 /* now save all the extended regs we need */
546 vga_out8 (0x3d4, 0x31); 550 vga_out8 (0x3d4, 0x31, par);
547 par->CR31 = vga_in8 (0x3d5); 551 par->CR31 = vga_in8 (0x3d5, par);
548 vga_out8 (0x3d4, 0x32); 552 vga_out8 (0x3d4, 0x32, par);
549 par->CR32 = vga_in8 (0x3d5); 553 par->CR32 = vga_in8 (0x3d5, par);
550 vga_out8 (0x3d4, 0x34); 554 vga_out8 (0x3d4, 0x34, par);
551 par->CR34 = vga_in8 (0x3d5); 555 par->CR34 = vga_in8 (0x3d5, par);
552 vga_out8 (0x3d4, 0x36); 556 vga_out8 (0x3d4, 0x36, par);
553 par->CR36 = vga_in8 (0x3d5); 557 par->CR36 = vga_in8 (0x3d5, par);
554 vga_out8 (0x3d4, 0x3a); 558 vga_out8 (0x3d4, 0x3a, par);
555 par->CR3A = vga_in8 (0x3d5); 559 par->CR3A = vga_in8 (0x3d5, par);
556 vga_out8 (0x3d4, 0x40); 560 vga_out8 (0x3d4, 0x40, par);
557 par->CR40 = vga_in8 (0x3d5); 561 par->CR40 = vga_in8 (0x3d5, par);
558 vga_out8 (0x3d4, 0x42); 562 vga_out8 (0x3d4, 0x42, par);
559 par->CR42 = vga_in8 (0x3d5); 563 par->CR42 = vga_in8 (0x3d5, par);
560 vga_out8 (0x3d4, 0x45); 564 vga_out8 (0x3d4, 0x45, par);
561 par->CR45 = vga_in8 (0x3d5); 565 par->CR45 = vga_in8 (0x3d5, par);
562 vga_out8 (0x3d4, 0x50); 566 vga_out8 (0x3d4, 0x50, par);
563 par->CR50 = vga_in8 (0x3d5); 567 par->CR50 = vga_in8 (0x3d5, par);
564 vga_out8 (0x3d4, 0x51); 568 vga_out8 (0x3d4, 0x51, par);
565 par->CR51 = vga_in8 (0x3d5); 569 par->CR51 = vga_in8 (0x3d5, par);
566 vga_out8 (0x3d4, 0x53); 570 vga_out8 (0x3d4, 0x53, par);
567 par->CR53 = vga_in8 (0x3d5); 571 par->CR53 = vga_in8 (0x3d5, par);
568 vga_out8 (0x3d4, 0x58); 572 vga_out8 (0x3d4, 0x58, par);
569 par->CR58 = vga_in8 (0x3d5); 573 par->CR58 = vga_in8 (0x3d5, par);
570 vga_out8 (0x3d4, 0x60); 574 vga_out8 (0x3d4, 0x60, par);
571 par->CR60 = vga_in8 (0x3d5); 575 par->CR60 = vga_in8 (0x3d5, par);
572 vga_out8 (0x3d4, 0x66); 576 vga_out8 (0x3d4, 0x66, par);
573 par->CR66 = vga_in8 (0x3d5); 577 par->CR66 = vga_in8 (0x3d5, par);
574 vga_out8 (0x3d4, 0x67); 578 vga_out8 (0x3d4, 0x67, par);
575 par->CR67 = vga_in8 (0x3d5); 579 par->CR67 = vga_in8 (0x3d5, par);
576 vga_out8 (0x3d4, 0x68); 580 vga_out8 (0x3d4, 0x68, par);
577 par->CR68 = vga_in8 (0x3d5); 581 par->CR68 = vga_in8 (0x3d5, par);
578 vga_out8 (0x3d4, 0x69); 582 vga_out8 (0x3d4, 0x69, par);
579 par->CR69 = vga_in8 (0x3d5); 583 par->CR69 = vga_in8 (0x3d5, par);
580 vga_out8 (0x3d4, 0x6f); 584 vga_out8 (0x3d4, 0x6f, par);
581 par->CR6F = vga_in8 (0x3d5); 585 par->CR6F = vga_in8 (0x3d5, par);
582 586
583 vga_out8 (0x3d4, 0x33); 587 vga_out8 (0x3d4, 0x33, par);
584 par->CR33 = vga_in8 (0x3d5); 588 par->CR33 = vga_in8 (0x3d5, par);
585 vga_out8 (0x3d4, 0x86); 589 vga_out8 (0x3d4, 0x86, par);
586 par->CR86 = vga_in8 (0x3d5); 590 par->CR86 = vga_in8 (0x3d5, par);
587 vga_out8 (0x3d4, 0x88); 591 vga_out8 (0x3d4, 0x88, par);
588 par->CR88 = vga_in8 (0x3d5); 592 par->CR88 = vga_in8 (0x3d5, par);
589 vga_out8 (0x3d4, 0x90); 593 vga_out8 (0x3d4, 0x90, par);
590 par->CR90 = vga_in8 (0x3d5); 594 par->CR90 = vga_in8 (0x3d5, par);
591 vga_out8 (0x3d4, 0x91); 595 vga_out8 (0x3d4, 0x91, par);
592 par->CR91 = vga_in8 (0x3d5); 596 par->CR91 = vga_in8 (0x3d5, par);
593 vga_out8 (0x3d4, 0xb0); 597 vga_out8 (0x3d4, 0xb0, par);
594 par->CRB0 = vga_in8 (0x3d5) | 0x80; 598 par->CRB0 = vga_in8 (0x3d5, par) | 0x80;
595 599
596 /* extended mode timing regs */ 600 /* extended mode timing regs */
597 vga_out8 (0x3d4, 0x3b); 601 vga_out8 (0x3d4, 0x3b, par);
598 par->CR3B = vga_in8 (0x3d5); 602 par->CR3B = vga_in8 (0x3d5, par);
599 vga_out8 (0x3d4, 0x3c); 603 vga_out8 (0x3d4, 0x3c, par);
600 par->CR3C = vga_in8 (0x3d5); 604 par->CR3C = vga_in8 (0x3d5, par);
601 vga_out8 (0x3d4, 0x43); 605 vga_out8 (0x3d4, 0x43, par);
602 par->CR43 = vga_in8 (0x3d5); 606 par->CR43 = vga_in8 (0x3d5, par);
603 vga_out8 (0x3d4, 0x5d); 607 vga_out8 (0x3d4, 0x5d, par);
604 par->CR5D = vga_in8 (0x3d5); 608 par->CR5D = vga_in8 (0x3d5, par);
605 vga_out8 (0x3d4, 0x5e); 609 vga_out8 (0x3d4, 0x5e, par);
606 par->CR5E = vga_in8 (0x3d5); 610 par->CR5E = vga_in8 (0x3d5, par);
607 vga_out8 (0x3d4, 0x65); 611 vga_out8 (0x3d4, 0x65, par);
608 par->CR65 = vga_in8 (0x3d5); 612 par->CR65 = vga_in8 (0x3d5, par);
609 613
610 /* save seq extended regs for DCLK PLL programming */ 614 /* save seq extended regs for DCLK PLL programming */
611 vga_out8 (0x3c4, 0x0e); 615 vga_out8 (0x3c4, 0x0e, par);
612 par->SR0E = vga_in8 (0x3c5); 616 par->SR0E = vga_in8 (0x3c5, par);
613 vga_out8 (0x3c4, 0x0f); 617 vga_out8 (0x3c4, 0x0f, par);
614 par->SR0F = vga_in8 (0x3c5); 618 par->SR0F = vga_in8 (0x3c5, par);
615 vga_out8 (0x3c4, 0x10); 619 vga_out8 (0x3c4, 0x10, par);
616 par->SR10 = vga_in8 (0x3c5); 620 par->SR10 = vga_in8 (0x3c5, par);
617 vga_out8 (0x3c4, 0x11); 621 vga_out8 (0x3c4, 0x11, par);
618 par->SR11 = vga_in8 (0x3c5); 622 par->SR11 = vga_in8 (0x3c5, par);
619 vga_out8 (0x3c4, 0x12); 623 vga_out8 (0x3c4, 0x12, par);
620 par->SR12 = vga_in8 (0x3c5); 624 par->SR12 = vga_in8 (0x3c5, par);
621 vga_out8 (0x3c4, 0x13); 625 vga_out8 (0x3c4, 0x13, par);
622 par->SR13 = vga_in8 (0x3c5); 626 par->SR13 = vga_in8 (0x3c5, par);
623 vga_out8 (0x3c4, 0x29); 627 vga_out8 (0x3c4, 0x29, par);
624 par->SR29 = vga_in8 (0x3c5); 628 par->SR29 = vga_in8 (0x3c5, par);
625 629
626 vga_out8 (0x3c4, 0x15); 630 vga_out8 (0x3c4, 0x15, par);
627 par->SR15 = vga_in8 (0x3c5); 631 par->SR15 = vga_in8 (0x3c5, par);
628 vga_out8 (0x3c4, 0x30); 632 vga_out8 (0x3c4, 0x30, par);
629 par->SR30 = vga_in8 (0x3c5); 633 par->SR30 = vga_in8 (0x3c5, par);
630 vga_out8 (0x3c4, 0x18); 634 vga_out8 (0x3c4, 0x18, par);
631 par->SR18 = vga_in8 (0x3c5); 635 par->SR18 = vga_in8 (0x3c5, par);
632 636
633 /* Save flat panel expansion regsters. */ 637 /* Save flat panel expansion regsters. */
634 if (par->chip == S3_SAVAGE_MX) { 638 if (par->chip == S3_SAVAGE_MX) {
635 int i; 639 int i;
636 640
637 for (i = 0; i < 8; i++) { 641 for (i = 0; i < 8; i++) {
638 vga_out8 (0x3c4, 0x54+i); 642 vga_out8 (0x3c4, 0x54+i, par);
639 par->SR54[i] = vga_in8 (0x3c5); 643 par->SR54[i] = vga_in8 (0x3c5, par);
640 } 644 }
641 } 645 }
642 646
643 vga_out8 (0x3d4, 0x66); 647 vga_out8 (0x3d4, 0x66, par);
644 cr66 = vga_in8 (0x3d5); 648 cr66 = vga_in8 (0x3d5, par);
645 vga_out8 (0x3d5, cr66 | 0x80); 649 vga_out8 (0x3d5, cr66 | 0x80, par);
646 vga_out8 (0x3d4, 0x3a); 650 vga_out8 (0x3d4, 0x3a, par);
647 cr3a = vga_in8 (0x3d5); 651 cr3a = vga_in8 (0x3d5, par);
648 vga_out8 (0x3d5, cr3a | 0x80); 652 vga_out8 (0x3d5, cr3a | 0x80, par);
649 653
650 /* now save MIU regs */ 654 /* now save MIU regs */
651 if (par->chip != S3_SAVAGE_MX) { 655 if (par->chip != S3_SAVAGE_MX) {
652 par->MMPR0 = savage_in32(FIFO_CONTROL_REG); 656 par->MMPR0 = savage_in32(FIFO_CONTROL_REG, par);
653 par->MMPR1 = savage_in32(MIU_CONTROL_REG); 657 par->MMPR1 = savage_in32(MIU_CONTROL_REG, par);
654 par->MMPR2 = savage_in32(STREAMS_TIMEOUT_REG); 658 par->MMPR2 = savage_in32(STREAMS_TIMEOUT_REG, par);
655 par->MMPR3 = savage_in32(MISC_TIMEOUT_REG); 659 par->MMPR3 = savage_in32(MISC_TIMEOUT_REG, par);
656 } 660 }
657 661
658 vga_out8 (0x3d4, 0x3a); 662 vga_out8 (0x3d4, 0x3a, par);
659 vga_out8 (0x3d5, cr3a); 663 vga_out8 (0x3d5, cr3a, par);
660 vga_out8 (0x3d4, 0x66); 664 vga_out8 (0x3d4, 0x66, par);
661 vga_out8 (0x3d5, cr66); 665 vga_out8 (0x3d5, cr66, par);
662} 666}
663 667
664static void savage_update_var(struct fb_var_screeninfo *var, struct fb_videomode *modedb) 668static void savage_update_var(struct fb_var_screeninfo *var, struct fb_videomode *modedb)
@@ -868,8 +872,8 @@ static int savagefb_decode_var (struct fb_var_screeninfo *var,
868 * match. Fall back to traditional register-crunching. 872 * match. Fall back to traditional register-crunching.
869 */ 873 */
870 874
871 vga_out8 (0x3d4, 0x3a); 875 vga_out8 (0x3d4, 0x3a, par);
872 tmp = vga_in8 (0x3d5); 876 tmp = vga_in8 (0x3d5, par);
873 if (1 /*FIXME:psav->pci_burst*/) 877 if (1 /*FIXME:psav->pci_burst*/)
874 par->CR3A = (tmp & 0x7f) | 0x15; 878 par->CR3A = (tmp & 0x7f) | 0x15;
875 else 879 else
@@ -879,16 +883,16 @@ static int savagefb_decode_var (struct fb_var_screeninfo *var,
879 par->CR31 = 0x8c; 883 par->CR31 = 0x8c;
880 par->CR66 = 0x89; 884 par->CR66 = 0x89;
881 885
882 vga_out8 (0x3d4, 0x58); 886 vga_out8 (0x3d4, 0x58, par);
883 par->CR58 = vga_in8 (0x3d5) & 0x80; 887 par->CR58 = vga_in8 (0x3d5, par) & 0x80;
884 par->CR58 |= 0x13; 888 par->CR58 |= 0x13;
885 889
886 par->SR15 = 0x03 | 0x80; 890 par->SR15 = 0x03 | 0x80;
887 par->SR18 = 0x00; 891 par->SR18 = 0x00;
888 par->CR43 = par->CR45 = par->CR65 = 0x00; 892 par->CR43 = par->CR45 = par->CR65 = 0x00;
889 893
890 vga_out8 (0x3d4, 0x40); 894 vga_out8 (0x3d4, 0x40, par);
891 par->CR40 = vga_in8 (0x3d5) & ~0x01; 895 par->CR40 = vga_in8 (0x3d5, par) & ~0x01;
892 896
893 par->MMPR0 = 0x010400; 897 par->MMPR0 = 0x010400;
894 par->MMPR1 = 0x00; 898 par->MMPR1 = 0x00;
@@ -992,19 +996,19 @@ static int savagefb_decode_var (struct fb_var_screeninfo *var,
992 996
993 par->CR67 |= 1; 997 par->CR67 |= 1;
994 998
995 vga_out8(0x3d4, 0x36); 999 vga_out8(0x3d4, 0x36, par);
996 par->CR36 = vga_in8 (0x3d5); 1000 par->CR36 = vga_in8 (0x3d5, par);
997 vga_out8 (0x3d4, 0x68); 1001 vga_out8 (0x3d4, 0x68, par);
998 par->CR68 = vga_in8 (0x3d5); 1002 par->CR68 = vga_in8 (0x3d5, par);
999 par->CR69 = 0; 1003 par->CR69 = 0;
1000 vga_out8 (0x3d4, 0x6f); 1004 vga_out8 (0x3d4, 0x6f, par);
1001 par->CR6F = vga_in8 (0x3d5); 1005 par->CR6F = vga_in8 (0x3d5, par);
1002 vga_out8 (0x3d4, 0x86); 1006 vga_out8 (0x3d4, 0x86, par);
1003 par->CR86 = vga_in8 (0x3d5); 1007 par->CR86 = vga_in8 (0x3d5, par);
1004 vga_out8 (0x3d4, 0x88); 1008 vga_out8 (0x3d4, 0x88, par);
1005 par->CR88 = vga_in8 (0x3d5) | 0x08; 1009 par->CR88 = vga_in8 (0x3d5, par) | 0x08;
1006 vga_out8 (0x3d4, 0xb0); 1010 vga_out8 (0x3d4, 0xb0, par);
1007 par->CRB0 = vga_in8 (0x3d5) | 0x80; 1011 par->CRB0 = vga_in8 (0x3d5, par) | 0x80;
1008 1012
1009 return 0; 1013 return 0;
1010} 1014}
@@ -1033,11 +1037,11 @@ static int savagefb_setcolreg(unsigned regno,
1033 1037
1034 switch (info->var.bits_per_pixel) { 1038 switch (info->var.bits_per_pixel) {
1035 case 8: 1039 case 8:
1036 vga_out8 (0x3c8, regno); 1040 vga_out8 (0x3c8, regno, par);
1037 1041
1038 vga_out8 (0x3c9, red >> 10); 1042 vga_out8 (0x3c9, red >> 10, par);
1039 vga_out8 (0x3c9, green >> 10); 1043 vga_out8 (0x3c9, green >> 10, par);
1040 vga_out8 (0x3c9, blue >> 10); 1044 vga_out8 (0x3c9, blue >> 10, par);
1041 break; 1045 break;
1042 1046
1043 case 16: 1047 case 16:
@@ -1079,11 +1083,11 @@ static void savagefb_set_par_int (struct savagefb_par *par)
1079 1083
1080 par->SavageWaitIdle (par); 1084 par->SavageWaitIdle (par);
1081 1085
1082 vga_out8 (0x3c2, 0x23); 1086 vga_out8 (0x3c2, 0x23, par);
1083 1087
1084 vga_out16 (0x3d4, 0x4838); 1088 vga_out16 (0x3d4, 0x4838, par);
1085 vga_out16 (0x3d4, 0xa539); 1089 vga_out16 (0x3d4, 0xa539, par);
1086 vga_out16 (0x3c4, 0x0608); 1090 vga_out16 (0x3c4, 0x0608, par);
1087 1091
1088 vgaHWProtect (par, 1); 1092 vgaHWProtect (par, 1);
1089 1093
@@ -1094,197 +1098,197 @@ static void savagefb_set_par_int (struct savagefb_par *par)
1094 * switch to mode 3 here seems to eliminate the issue. 1098 * switch to mode 3 here seems to eliminate the issue.
1095 */ 1099 */
1096 1100
1097 VerticalRetraceWait(); 1101 VerticalRetraceWait(par);
1098 vga_out8 (0x3d4, 0x67); 1102 vga_out8 (0x3d4, 0x67, par);
1099 cr67 = vga_in8 (0x3d5); 1103 cr67 = vga_in8 (0x3d5, par);
1100 vga_out8 (0x3d5, cr67/*par->CR67*/ & ~0x0c); /* no STREAMS yet */ 1104 vga_out8 (0x3d5, cr67/*par->CR67*/ & ~0x0c, par); /* no STREAMS yet */
1101 1105
1102 vga_out8 (0x3d4, 0x23); 1106 vga_out8 (0x3d4, 0x23, par);
1103 vga_out8 (0x3d5, 0x00); 1107 vga_out8 (0x3d5, 0x00, par);
1104 vga_out8 (0x3d4, 0x26); 1108 vga_out8 (0x3d4, 0x26, par);
1105 vga_out8 (0x3d5, 0x00); 1109 vga_out8 (0x3d5, 0x00, par);
1106 1110
1107 /* restore extended regs */ 1111 /* restore extended regs */
1108 vga_out8 (0x3d4, 0x66); 1112 vga_out8 (0x3d4, 0x66, par);
1109 vga_out8 (0x3d5, par->CR66); 1113 vga_out8 (0x3d5, par->CR66, par);
1110 vga_out8 (0x3d4, 0x3a); 1114 vga_out8 (0x3d4, 0x3a, par);
1111 vga_out8 (0x3d5, par->CR3A); 1115 vga_out8 (0x3d5, par->CR3A, par);
1112 vga_out8 (0x3d4, 0x31); 1116 vga_out8 (0x3d4, 0x31, par);
1113 vga_out8 (0x3d5, par->CR31); 1117 vga_out8 (0x3d5, par->CR31, par);
1114 vga_out8 (0x3d4, 0x32); 1118 vga_out8 (0x3d4, 0x32, par);
1115 vga_out8 (0x3d5, par->CR32); 1119 vga_out8 (0x3d5, par->CR32, par);
1116 vga_out8 (0x3d4, 0x58); 1120 vga_out8 (0x3d4, 0x58, par);
1117 vga_out8 (0x3d5, par->CR58); 1121 vga_out8 (0x3d5, par->CR58, par);
1118 vga_out8 (0x3d4, 0x53); 1122 vga_out8 (0x3d4, 0x53, par);
1119 vga_out8 (0x3d5, par->CR53 & 0x7f); 1123 vga_out8 (0x3d5, par->CR53 & 0x7f, par);
1120 1124
1121 vga_out16 (0x3c4, 0x0608); 1125 vga_out16 (0x3c4, 0x0608, par);
1122 1126
1123 /* Restore DCLK registers. */ 1127 /* Restore DCLK registers. */
1124 1128
1125 vga_out8 (0x3c4, 0x0e); 1129 vga_out8 (0x3c4, 0x0e, par);
1126 vga_out8 (0x3c5, par->SR0E); 1130 vga_out8 (0x3c5, par->SR0E, par);
1127 vga_out8 (0x3c4, 0x0f); 1131 vga_out8 (0x3c4, 0x0f, par);
1128 vga_out8 (0x3c5, par->SR0F); 1132 vga_out8 (0x3c5, par->SR0F, par);
1129 vga_out8 (0x3c4, 0x29); 1133 vga_out8 (0x3c4, 0x29, par);
1130 vga_out8 (0x3c5, par->SR29); 1134 vga_out8 (0x3c5, par->SR29, par);
1131 vga_out8 (0x3c4, 0x15); 1135 vga_out8 (0x3c4, 0x15, par);
1132 vga_out8 (0x3c5, par->SR15); 1136 vga_out8 (0x3c5, par->SR15, par);
1133 1137
1134 /* Restore flat panel expansion regsters. */ 1138 /* Restore flat panel expansion regsters. */
1135 if( par->chip == S3_SAVAGE_MX ) { 1139 if( par->chip == S3_SAVAGE_MX ) {
1136 int i; 1140 int i;
1137 1141
1138 for( i = 0; i < 8; i++ ) { 1142 for( i = 0; i < 8; i++ ) {
1139 vga_out8 (0x3c4, 0x54+i); 1143 vga_out8 (0x3c4, 0x54+i, par);
1140 vga_out8 (0x3c5, par->SR54[i]); 1144 vga_out8 (0x3c5, par->SR54[i], par);
1141 } 1145 }
1142 } 1146 }
1143 1147
1144 vgaHWRestore (par); 1148 vgaHWRestore (par);
1145 1149
1146 /* extended mode timing registers */ 1150 /* extended mode timing registers */
1147 vga_out8 (0x3d4, 0x53); 1151 vga_out8 (0x3d4, 0x53, par);
1148 vga_out8 (0x3d5, par->CR53); 1152 vga_out8 (0x3d5, par->CR53, par);
1149 vga_out8 (0x3d4, 0x5d); 1153 vga_out8 (0x3d4, 0x5d, par);
1150 vga_out8 (0x3d5, par->CR5D); 1154 vga_out8 (0x3d5, par->CR5D, par);
1151 vga_out8 (0x3d4, 0x5e); 1155 vga_out8 (0x3d4, 0x5e, par);
1152 vga_out8 (0x3d5, par->CR5E); 1156 vga_out8 (0x3d5, par->CR5E, par);
1153 vga_out8 (0x3d4, 0x3b); 1157 vga_out8 (0x3d4, 0x3b, par);
1154 vga_out8 (0x3d5, par->CR3B); 1158 vga_out8 (0x3d5, par->CR3B, par);
1155 vga_out8 (0x3d4, 0x3c); 1159 vga_out8 (0x3d4, 0x3c, par);
1156 vga_out8 (0x3d5, par->CR3C); 1160 vga_out8 (0x3d5, par->CR3C, par);
1157 vga_out8 (0x3d4, 0x43); 1161 vga_out8 (0x3d4, 0x43, par);
1158 vga_out8 (0x3d5, par->CR43); 1162 vga_out8 (0x3d5, par->CR43, par);
1159 vga_out8 (0x3d4, 0x65); 1163 vga_out8 (0x3d4, 0x65, par);
1160 vga_out8 (0x3d5, par->CR65); 1164 vga_out8 (0x3d5, par->CR65, par);
1161 1165
1162 /* restore the desired video mode with cr67 */ 1166 /* restore the desired video mode with cr67 */
1163 vga_out8 (0x3d4, 0x67); 1167 vga_out8 (0x3d4, 0x67, par);
1164 /* following part not present in X11 driver */ 1168 /* following part not present in X11 driver */
1165 cr67 = vga_in8 (0x3d5) & 0xf; 1169 cr67 = vga_in8 (0x3d5, par) & 0xf;
1166 vga_out8 (0x3d5, 0x50 | cr67); 1170 vga_out8 (0x3d5, 0x50 | cr67, par);
1167 udelay (10000); 1171 udelay (10000);
1168 vga_out8 (0x3d4, 0x67); 1172 vga_out8 (0x3d4, 0x67, par);
1169 /* end of part */ 1173 /* end of part */
1170 vga_out8 (0x3d5, par->CR67 & ~0x0c); 1174 vga_out8 (0x3d5, par->CR67 & ~0x0c, par);
1171 1175
1172 /* other mode timing and extended regs */ 1176 /* other mode timing and extended regs */
1173 vga_out8 (0x3d4, 0x34); 1177 vga_out8 (0x3d4, 0x34, par);
1174 vga_out8 (0x3d5, par->CR34); 1178 vga_out8 (0x3d5, par->CR34, par);
1175 vga_out8 (0x3d4, 0x40); 1179 vga_out8 (0x3d4, 0x40, par);
1176 vga_out8 (0x3d5, par->CR40); 1180 vga_out8 (0x3d5, par->CR40, par);
1177 vga_out8 (0x3d4, 0x42); 1181 vga_out8 (0x3d4, 0x42, par);
1178 vga_out8 (0x3d5, par->CR42); 1182 vga_out8 (0x3d5, par->CR42, par);
1179 vga_out8 (0x3d4, 0x45); 1183 vga_out8 (0x3d4, 0x45, par);
1180 vga_out8 (0x3d5, par->CR45); 1184 vga_out8 (0x3d5, par->CR45, par);
1181 vga_out8 (0x3d4, 0x50); 1185 vga_out8 (0x3d4, 0x50, par);
1182 vga_out8 (0x3d5, par->CR50); 1186 vga_out8 (0x3d5, par->CR50, par);
1183 vga_out8 (0x3d4, 0x51); 1187 vga_out8 (0x3d4, 0x51, par);
1184 vga_out8 (0x3d5, par->CR51); 1188 vga_out8 (0x3d5, par->CR51, par);
1185 1189
1186 /* memory timings */ 1190 /* memory timings */
1187 vga_out8 (0x3d4, 0x36); 1191 vga_out8 (0x3d4, 0x36, par);
1188 vga_out8 (0x3d5, par->CR36); 1192 vga_out8 (0x3d5, par->CR36, par);
1189 vga_out8 (0x3d4, 0x60); 1193 vga_out8 (0x3d4, 0x60, par);
1190 vga_out8 (0x3d5, par->CR60); 1194 vga_out8 (0x3d5, par->CR60, par);
1191 vga_out8 (0x3d4, 0x68); 1195 vga_out8 (0x3d4, 0x68, par);
1192 vga_out8 (0x3d5, par->CR68); 1196 vga_out8 (0x3d5, par->CR68, par);
1193 vga_out8 (0x3d4, 0x69); 1197 vga_out8 (0x3d4, 0x69, par);
1194 vga_out8 (0x3d5, par->CR69); 1198 vga_out8 (0x3d5, par->CR69, par);
1195 vga_out8 (0x3d4, 0x6f); 1199 vga_out8 (0x3d4, 0x6f, par);
1196 vga_out8 (0x3d5, par->CR6F); 1200 vga_out8 (0x3d5, par->CR6F, par);
1197 1201
1198 vga_out8 (0x3d4, 0x33); 1202 vga_out8 (0x3d4, 0x33, par);
1199 vga_out8 (0x3d5, par->CR33); 1203 vga_out8 (0x3d5, par->CR33, par);
1200 vga_out8 (0x3d4, 0x86); 1204 vga_out8 (0x3d4, 0x86, par);
1201 vga_out8 (0x3d5, par->CR86); 1205 vga_out8 (0x3d5, par->CR86, par);
1202 vga_out8 (0x3d4, 0x88); 1206 vga_out8 (0x3d4, 0x88, par);
1203 vga_out8 (0x3d5, par->CR88); 1207 vga_out8 (0x3d5, par->CR88, par);
1204 vga_out8 (0x3d4, 0x90); 1208 vga_out8 (0x3d4, 0x90, par);
1205 vga_out8 (0x3d5, par->CR90); 1209 vga_out8 (0x3d5, par->CR90, par);
1206 vga_out8 (0x3d4, 0x91); 1210 vga_out8 (0x3d4, 0x91, par);
1207 vga_out8 (0x3d5, par->CR91); 1211 vga_out8 (0x3d5, par->CR91, par);
1208 1212
1209 if (par->chip == S3_SAVAGE4) { 1213 if (par->chip == S3_SAVAGE4) {
1210 vga_out8 (0x3d4, 0xb0); 1214 vga_out8 (0x3d4, 0xb0, par);
1211 vga_out8 (0x3d5, par->CRB0); 1215 vga_out8 (0x3d5, par->CRB0, par);
1212 } 1216 }
1213 1217
1214 vga_out8 (0x3d4, 0x32); 1218 vga_out8 (0x3d4, 0x32, par);
1215 vga_out8 (0x3d5, par->CR32); 1219 vga_out8 (0x3d5, par->CR32, par);
1216 1220
1217 /* unlock extended seq regs */ 1221 /* unlock extended seq regs */
1218 vga_out8 (0x3c4, 0x08); 1222 vga_out8 (0x3c4, 0x08, par);
1219 vga_out8 (0x3c5, 0x06); 1223 vga_out8 (0x3c5, 0x06, par);
1220 1224
1221 /* Restore extended sequencer regs for MCLK. SR10 == 255 indicates 1225 /* Restore extended sequencer regs for MCLK. SR10 == 255 indicates
1222 * that we should leave the default SR10 and SR11 values there. 1226 * that we should leave the default SR10 and SR11 values there.
1223 */ 1227 */
1224 if (par->SR10 != 255) { 1228 if (par->SR10 != 255) {
1225 vga_out8 (0x3c4, 0x10); 1229 vga_out8 (0x3c4, 0x10, par);
1226 vga_out8 (0x3c5, par->SR10); 1230 vga_out8 (0x3c5, par->SR10, par);
1227 vga_out8 (0x3c4, 0x11); 1231 vga_out8 (0x3c4, 0x11, par);
1228 vga_out8 (0x3c5, par->SR11); 1232 vga_out8 (0x3c5, par->SR11, par);
1229 } 1233 }
1230 1234
1231 /* restore extended seq regs for dclk */ 1235 /* restore extended seq regs for dclk */
1232 vga_out8 (0x3c4, 0x0e); 1236 vga_out8 (0x3c4, 0x0e, par);
1233 vga_out8 (0x3c5, par->SR0E); 1237 vga_out8 (0x3c5, par->SR0E, par);
1234 vga_out8 (0x3c4, 0x0f); 1238 vga_out8 (0x3c4, 0x0f, par);
1235 vga_out8 (0x3c5, par->SR0F); 1239 vga_out8 (0x3c5, par->SR0F, par);
1236 vga_out8 (0x3c4, 0x12); 1240 vga_out8 (0x3c4, 0x12, par);
1237 vga_out8 (0x3c5, par->SR12); 1241 vga_out8 (0x3c5, par->SR12, par);
1238 vga_out8 (0x3c4, 0x13); 1242 vga_out8 (0x3c4, 0x13, par);
1239 vga_out8 (0x3c5, par->SR13); 1243 vga_out8 (0x3c5, par->SR13, par);
1240 vga_out8 (0x3c4, 0x29); 1244 vga_out8 (0x3c4, 0x29, par);
1241 vga_out8 (0x3c5, par->SR29); 1245 vga_out8 (0x3c5, par->SR29, par);
1242 1246
1243 vga_out8 (0x3c4, 0x18); 1247 vga_out8 (0x3c4, 0x18, par);
1244 vga_out8 (0x3c5, par->SR18); 1248 vga_out8 (0x3c5, par->SR18, par);
1245 1249
1246 /* load new m, n pll values for dclk & mclk */ 1250 /* load new m, n pll values for dclk & mclk */
1247 vga_out8 (0x3c4, 0x15); 1251 vga_out8 (0x3c4, 0x15, par);
1248 tmp = vga_in8 (0x3c5) & ~0x21; 1252 tmp = vga_in8 (0x3c5, par) & ~0x21;
1249 1253
1250 vga_out8 (0x3c5, tmp | 0x03); 1254 vga_out8 (0x3c5, tmp | 0x03, par);
1251 vga_out8 (0x3c5, tmp | 0x23); 1255 vga_out8 (0x3c5, tmp | 0x23, par);
1252 vga_out8 (0x3c5, tmp | 0x03); 1256 vga_out8 (0x3c5, tmp | 0x03, par);
1253 vga_out8 (0x3c5, par->SR15); 1257 vga_out8 (0x3c5, par->SR15, par);
1254 udelay (100); 1258 udelay (100);
1255 1259
1256 vga_out8 (0x3c4, 0x30); 1260 vga_out8 (0x3c4, 0x30, par);
1257 vga_out8 (0x3c5, par->SR30); 1261 vga_out8 (0x3c5, par->SR30, par);
1258 vga_out8 (0x3c4, 0x08); 1262 vga_out8 (0x3c4, 0x08, par);
1259 vga_out8 (0x3c5, par->SR08); 1263 vga_out8 (0x3c5, par->SR08, par);
1260 1264
1261 /* now write out cr67 in full, possibly starting STREAMS */ 1265 /* now write out cr67 in full, possibly starting STREAMS */
1262 VerticalRetraceWait(); 1266 VerticalRetraceWait(par);
1263 vga_out8 (0x3d4, 0x67); 1267 vga_out8 (0x3d4, 0x67, par);
1264 vga_out8 (0x3d5, par->CR67); 1268 vga_out8 (0x3d5, par->CR67, par);
1265 1269
1266 vga_out8 (0x3d4, 0x66); 1270 vga_out8 (0x3d4, 0x66, par);
1267 cr66 = vga_in8 (0x3d5); 1271 cr66 = vga_in8 (0x3d5, par);
1268 vga_out8 (0x3d5, cr66 | 0x80); 1272 vga_out8 (0x3d5, cr66 | 0x80, par);
1269 vga_out8 (0x3d4, 0x3a); 1273 vga_out8 (0x3d4, 0x3a, par);
1270 cr3a = vga_in8 (0x3d5); 1274 cr3a = vga_in8 (0x3d5, par);
1271 vga_out8 (0x3d5, cr3a | 0x80); 1275 vga_out8 (0x3d5, cr3a | 0x80, par);
1272 1276
1273 if (par->chip != S3_SAVAGE_MX) { 1277 if (par->chip != S3_SAVAGE_MX) {
1274 VerticalRetraceWait(); 1278 VerticalRetraceWait(par);
1275 savage_out32 (FIFO_CONTROL_REG, par->MMPR0); 1279 savage_out32 (FIFO_CONTROL_REG, par->MMPR0, par);
1276 par->SavageWaitIdle (par); 1280 par->SavageWaitIdle (par);
1277 savage_out32 (MIU_CONTROL_REG, par->MMPR1); 1281 savage_out32 (MIU_CONTROL_REG, par->MMPR1, par);
1278 par->SavageWaitIdle (par); 1282 par->SavageWaitIdle (par);
1279 savage_out32 (STREAMS_TIMEOUT_REG, par->MMPR2); 1283 savage_out32 (STREAMS_TIMEOUT_REG, par->MMPR2, par);
1280 par->SavageWaitIdle (par); 1284 par->SavageWaitIdle (par);
1281 savage_out32 (MISC_TIMEOUT_REG, par->MMPR3); 1285 savage_out32 (MISC_TIMEOUT_REG, par->MMPR3, par);
1282 } 1286 }
1283 1287
1284 vga_out8 (0x3d4, 0x66); 1288 vga_out8 (0x3d4, 0x66, par);
1285 vga_out8 (0x3d5, cr66); 1289 vga_out8 (0x3d5, cr66, par);
1286 vga_out8 (0x3d4, 0x3a); 1290 vga_out8 (0x3d4, 0x3a, par);
1287 vga_out8 (0x3d5, cr3a); 1291 vga_out8 (0x3d5, cr3a, par);
1288 1292
1289 SavageSetup2DEngine (par); 1293 SavageSetup2DEngine (par);
1290 vgaHWProtect (par, 0); 1294 vgaHWProtect (par, 0);
@@ -1299,10 +1303,10 @@ static void savagefb_update_start (struct savagefb_par *par,
1299 * ((var->bits_per_pixel+7) / 8)) >> 2; 1303 * ((var->bits_per_pixel+7) / 8)) >> 2;
1300 1304
1301 /* now program the start address registers */ 1305 /* now program the start address registers */
1302 vga_out16(0x3d4, (base & 0x00ff00) | 0x0c); 1306 vga_out16(0x3d4, (base & 0x00ff00) | 0x0c, par);
1303 vga_out16(0x3d4, ((base & 0x00ff) << 8) | 0x0d); 1307 vga_out16(0x3d4, ((base & 0x00ff) << 8) | 0x0d, par);
1304 vga_out8 (0x3d4, 0x69); 1308 vga_out8 (0x3d4, 0x69, par);
1305 vga_out8 (0x3d5, (base & 0x7f0000) >> 16); 1309 vga_out8 (0x3d5, (base & 0x7f0000) >> 16, par);
1306} 1310}
1307 1311
1308 1312
@@ -1406,12 +1410,12 @@ static int savagefb_blank(int blank, struct fb_info *info)
1406 u8 sr8 = 0, srd = 0; 1410 u8 sr8 = 0, srd = 0;
1407 1411
1408 if (par->display_type == DISP_CRT) { 1412 if (par->display_type == DISP_CRT) {
1409 vga_out8(0x3c4, 0x08); 1413 vga_out8(0x3c4, 0x08, par);
1410 sr8 = vga_in8(0x3c5); 1414 sr8 = vga_in8(0x3c5, par);
1411 sr8 |= 0x06; 1415 sr8 |= 0x06;
1412 vga_out8(0x3c5, sr8); 1416 vga_out8(0x3c5, sr8, par);
1413 vga_out8(0x3c4, 0x0d); 1417 vga_out8(0x3c4, 0x0d, par);
1414 srd = vga_in8(0x3c5); 1418 srd = vga_in8(0x3c5, par);
1415 srd &= 0x03; 1419 srd &= 0x03;
1416 1420
1417 switch (blank) { 1421 switch (blank) {
@@ -1429,8 +1433,8 @@ static int savagefb_blank(int blank, struct fb_info *info)
1429 break; 1433 break;
1430 } 1434 }
1431 1435
1432 vga_out8(0x3c4, 0x0d); 1436 vga_out8(0x3c4, 0x0d, par);
1433 vga_out8(0x3c5, srd); 1437 vga_out8(0x3c5, srd, par);
1434 } 1438 }
1435 1439
1436 if (par->display_type == DISP_LCD || 1440 if (par->display_type == DISP_LCD ||
@@ -1438,14 +1442,14 @@ static int savagefb_blank(int blank, struct fb_info *info)
1438 switch(blank) { 1442 switch(blank) {
1439 case FB_BLANK_UNBLANK: 1443 case FB_BLANK_UNBLANK:
1440 case FB_BLANK_NORMAL: 1444 case FB_BLANK_NORMAL:
1441 vga_out8(0x3c4, 0x31); /* SR31 bit 4 - FP enable */ 1445 vga_out8(0x3c4, 0x31, par); /* SR31 bit 4 - FP enable */
1442 vga_out8(0x3c5, vga_in8(0x3c5) | 0x10); 1446 vga_out8(0x3c5, vga_in8(0x3c5, par) | 0x10, par);
1443 break; 1447 break;
1444 case FB_BLANK_VSYNC_SUSPEND: 1448 case FB_BLANK_VSYNC_SUSPEND:
1445 case FB_BLANK_HSYNC_SUSPEND: 1449 case FB_BLANK_HSYNC_SUSPEND:
1446 case FB_BLANK_POWERDOWN: 1450 case FB_BLANK_POWERDOWN:
1447 vga_out8(0x3c4, 0x31); /* SR31 bit 4 - FP enable */ 1451 vga_out8(0x3c4, 0x31, par); /* SR31 bit 4 - FP enable */
1448 vga_out8(0x3c5, vga_in8(0x3c5) & ~0x10); 1452 vga_out8(0x3c5, vga_in8(0x3c5, par) & ~0x10, par);
1449 break; 1453 break;
1450 } 1454 }
1451 } 1455 }
@@ -1470,7 +1474,6 @@ static struct fb_ops savagefb_ops = {
1470 .fb_copyarea = cfb_copyarea, 1474 .fb_copyarea = cfb_copyarea,
1471 .fb_imageblit = cfb_imageblit, 1475 .fb_imageblit = cfb_imageblit,
1472#endif 1476#endif
1473 .fb_cursor = soft_cursor,
1474}; 1477};
1475 1478
1476/* --------------------------------------------------------------------- */ 1479/* --------------------------------------------------------------------- */
@@ -1499,15 +1502,15 @@ static void savage_enable_mmio (struct savagefb_par *par)
1499 1502
1500 DBG ("savage_enable_mmio\n"); 1503 DBG ("savage_enable_mmio\n");
1501 1504
1502 val = vga_in8 (0x3c3); 1505 val = vga_in8 (0x3c3, par);
1503 vga_out8 (0x3c3, val | 0x01); 1506 vga_out8 (0x3c3, val | 0x01, par);
1504 val = vga_in8 (0x3cc); 1507 val = vga_in8 (0x3cc, par);
1505 vga_out8 (0x3c2, val | 0x01); 1508 vga_out8 (0x3c2, val | 0x01, par);
1506 1509
1507 if (par->chip >= S3_SAVAGE4) { 1510 if (par->chip >= S3_SAVAGE4) {
1508 vga_out8 (0x3d4, 0x40); 1511 vga_out8 (0x3d4, 0x40, par);
1509 val = vga_in8 (0x3d5); 1512 val = vga_in8 (0x3d5, par);
1510 vga_out8 (0x3d5, val | 1); 1513 vga_out8 (0x3d5, val | 1, par);
1511 } 1514 }
1512} 1515}
1513 1516
@@ -1519,9 +1522,9 @@ static void savage_disable_mmio (struct savagefb_par *par)
1519 DBG ("savage_disable_mmio\n"); 1522 DBG ("savage_disable_mmio\n");
1520 1523
1521 if(par->chip >= S3_SAVAGE4 ) { 1524 if(par->chip >= S3_SAVAGE4 ) {
1522 vga_out8 (0x3d4, 0x40); 1525 vga_out8 (0x3d4, 0x40, par);
1523 val = vga_in8 (0x3d5); 1526 val = vga_in8 (0x3d5, par);
1524 vga_out8 (0x3d5, val | 1); 1527 vga_out8 (0x3d5, val | 1, par);
1525 } 1528 }
1526} 1529}
1527 1530
@@ -1641,30 +1644,30 @@ static int __devinit savage_init_hw (struct savagefb_par *par)
1641 DBG("savage_init_hw"); 1644 DBG("savage_init_hw");
1642 1645
1643 /* unprotect CRTC[0-7] */ 1646 /* unprotect CRTC[0-7] */
1644 vga_out8(0x3d4, 0x11); 1647 vga_out8(0x3d4, 0x11, par);
1645 tmp = vga_in8(0x3d5); 1648 tmp = vga_in8(0x3d5, par);
1646 vga_out8(0x3d5, tmp & 0x7f); 1649 vga_out8(0x3d5, tmp & 0x7f, par);
1647 1650
1648 /* unlock extended regs */ 1651 /* unlock extended regs */
1649 vga_out16(0x3d4, 0x4838); 1652 vga_out16(0x3d4, 0x4838, par);
1650 vga_out16(0x3d4, 0xa039); 1653 vga_out16(0x3d4, 0xa039, par);
1651 vga_out16(0x3c4, 0x0608); 1654 vga_out16(0x3c4, 0x0608, par);
1652 1655
1653 vga_out8(0x3d4, 0x40); 1656 vga_out8(0x3d4, 0x40, par);
1654 tmp = vga_in8(0x3d5); 1657 tmp = vga_in8(0x3d5, par);
1655 vga_out8(0x3d5, tmp & ~0x01); 1658 vga_out8(0x3d5, tmp & ~0x01, par);
1656 1659
1657 /* unlock sys regs */ 1660 /* unlock sys regs */
1658 vga_out8(0x3d4, 0x38); 1661 vga_out8(0x3d4, 0x38, par);
1659 vga_out8(0x3d5, 0x48); 1662 vga_out8(0x3d5, 0x48, par);
1660 1663
1661 /* Unlock system registers. */ 1664 /* Unlock system registers. */
1662 vga_out16(0x3d4, 0x4838); 1665 vga_out16(0x3d4, 0x4838, par);
1663 1666
1664 /* Next go on to detect amount of installed ram */ 1667 /* Next go on to detect amount of installed ram */
1665 1668
1666 vga_out8(0x3d4, 0x36); /* for register CR36 (CONFG_REG1), */ 1669 vga_out8(0x3d4, 0x36, par); /* for register CR36 (CONFG_REG1), */
1667 config1 = vga_in8(0x3d5); /* get amount of vram installed */ 1670 config1 = vga_in8(0x3d5, par); /* get amount of vram installed */
1668 1671
1669 /* Compute the amount of video memory and offscreen memory. */ 1672 /* Compute the amount of video memory and offscreen memory. */
1670 1673
@@ -1680,8 +1683,8 @@ static int __devinit savage_init_hw (struct savagefb_par *par)
1680 * when it really means 8MB. Why do it the same when you 1683 * when it really means 8MB. Why do it the same when you
1681 * can do it different... 1684 * can do it different...
1682 */ 1685 */
1683 vga_out8(0x3d4, 0x68); /* memory control 1 */ 1686 vga_out8(0x3d4, 0x68, par); /* memory control 1 */
1684 if( (vga_in8(0x3d5) & 0xC0) == (0x01 << 6) ) 1687 if( (vga_in8(0x3d5, par) & 0xC0) == (0x01 << 6) )
1685 RamSavage4[1] = 8; 1688 RamSavage4[1] = 8;
1686 1689
1687 /*FALLTHROUGH*/ 1690 /*FALLTHROUGH*/
@@ -1710,13 +1713,13 @@ static int __devinit savage_init_hw (struct savagefb_par *par)
1710 printk (KERN_INFO "savagefb: probed videoram: %dk\n", videoRam); 1713 printk (KERN_INFO "savagefb: probed videoram: %dk\n", videoRam);
1711 1714
1712 /* reset graphics engine to avoid memory corruption */ 1715 /* reset graphics engine to avoid memory corruption */
1713 vga_out8 (0x3d4, 0x66); 1716 vga_out8 (0x3d4, 0x66, par);
1714 cr66 = vga_in8 (0x3d5); 1717 cr66 = vga_in8 (0x3d5, par);
1715 vga_out8 (0x3d5, cr66 | 0x02); 1718 vga_out8 (0x3d5, cr66 | 0x02, par);
1716 udelay (10000); 1719 udelay (10000);
1717 1720
1718 vga_out8 (0x3d4, 0x66); 1721 vga_out8 (0x3d4, 0x66, par);
1719 vga_out8 (0x3d5, cr66 & ~0x02); /* clear reset flag */ 1722 vga_out8 (0x3d5, cr66 & ~0x02, par); /* clear reset flag */
1720 udelay (10000); 1723 udelay (10000);
1721 1724
1722 1725
@@ -1724,13 +1727,13 @@ static int __devinit savage_init_hw (struct savagefb_par *par)
1724 * reset memory interface, 3D engine, AGP master, PCI master, 1727 * reset memory interface, 3D engine, AGP master, PCI master,
1725 * master engine unit, motion compensation/LPB 1728 * master engine unit, motion compensation/LPB
1726 */ 1729 */
1727 vga_out8 (0x3d4, 0x3f); 1730 vga_out8 (0x3d4, 0x3f, par);
1728 cr3f = vga_in8 (0x3d5); 1731 cr3f = vga_in8 (0x3d5, par);
1729 vga_out8 (0x3d5, cr3f | 0x08); 1732 vga_out8 (0x3d5, cr3f | 0x08, par);
1730 udelay (10000); 1733 udelay (10000);
1731 1734
1732 vga_out8 (0x3d4, 0x3f); 1735 vga_out8 (0x3d4, 0x3f, par);
1733 vga_out8 (0x3d5, cr3f & ~0x08); /* clear reset flags */ 1736 vga_out8 (0x3d5, cr3f & ~0x08, par); /* clear reset flags */
1734 udelay (10000); 1737 udelay (10000);
1735 1738
1736 /* Savage ramdac speeds */ 1739 /* Savage ramdac speeds */
@@ -1741,15 +1744,15 @@ static int __devinit savage_init_hw (struct savagefb_par *par)
1741 par->clock[3] = 220000; 1744 par->clock[3] = 220000;
1742 1745
1743 /* detect current mclk */ 1746 /* detect current mclk */
1744 vga_out8(0x3c4, 0x08); 1747 vga_out8(0x3c4, 0x08, par);
1745 sr8 = vga_in8(0x3c5); 1748 sr8 = vga_in8(0x3c5, par);
1746 vga_out8(0x3c5, 0x06); 1749 vga_out8(0x3c5, 0x06, par);
1747 vga_out8(0x3c4, 0x10); 1750 vga_out8(0x3c4, 0x10, par);
1748 n = vga_in8(0x3c5); 1751 n = vga_in8(0x3c5, par);
1749 vga_out8(0x3c4, 0x11); 1752 vga_out8(0x3c4, 0x11, par);
1750 m = vga_in8(0x3c5); 1753 m = vga_in8(0x3c5, par);
1751 vga_out8(0x3c4, 0x08); 1754 vga_out8(0x3c4, 0x08, par);
1752 vga_out8(0x3c5, sr8); 1755 vga_out8(0x3c5, sr8, par);
1753 m &= 0x7f; 1756 m &= 0x7f;
1754 n1 = n & 0x1f; 1757 n1 = n & 0x1f;
1755 n2 = (n >> 5) & 0x03; 1758 n2 = (n >> 5) & 0x03;
@@ -1763,10 +1766,10 @@ static int __devinit savage_init_hw (struct savagefb_par *par)
1763 if (par->chip == S3_SAVAGE4) { 1766 if (par->chip == S3_SAVAGE4) {
1764 unsigned char sr30 = 0x00; 1767 unsigned char sr30 = 0x00;
1765 1768
1766 vga_out8(0x3c4, 0x30); 1769 vga_out8(0x3c4, 0x30, par);
1767 /* clear bit 1 */ 1770 /* clear bit 1 */
1768 vga_out8(0x3c5, vga_in8(0x3c5) & ~0x02); 1771 vga_out8(0x3c5, vga_in8(0x3c5, par) & ~0x02, par);
1769 sr30 = vga_in8(0x3c5); 1772 sr30 = vga_in8(0x3c5, par);
1770 if (sr30 & 0x02 /*0x04 */) { 1773 if (sr30 & 0x02 /*0x04 */) {
1771 dvi = 1; 1774 dvi = 1;
1772 printk("savagefb: Digital Flat Panel Detected\n"); 1775 printk("savagefb: Digital Flat Panel Detected\n");
@@ -1783,12 +1786,12 @@ static int __devinit savage_init_hw (struct savagefb_par *par)
1783 /* Check LCD panel parrmation */ 1786 /* Check LCD panel parrmation */
1784 1787
1785 if (par->display_type == DISP_LCD) { 1788 if (par->display_type == DISP_LCD) {
1786 unsigned char cr6b = VGArCR( 0x6b ); 1789 unsigned char cr6b = VGArCR( 0x6b, par);
1787 1790
1788 int panelX = (VGArSEQ (0x61) + 1791 int panelX = (VGArSEQ (0x61, par) +
1789 ((VGArSEQ (0x66) & 0x02) << 7) + 1) * 8; 1792 ((VGArSEQ (0x66, par) & 0x02) << 7) + 1) * 8;
1790 int panelY = (VGArSEQ (0x69) + 1793 int panelY = (VGArSEQ (0x69, par) +
1791 ((VGArSEQ (0x6e) & 0x70) << 4) + 1); 1794 ((VGArSEQ (0x6e, par) & 0x70) << 4) + 1);
1792 1795
1793 char * sTechnology = "Unknown"; 1796 char * sTechnology = "Unknown";
1794 1797
@@ -1810,9 +1813,9 @@ static int __devinit savage_init_hw (struct savagefb_par *par)
1810 ActiveDUO = 0x80 1813 ActiveDUO = 0x80
1811 }; 1814 };
1812 1815
1813 if ((VGArSEQ (0x39) & 0x03) == 0) { 1816 if ((VGArSEQ (0x39, par) & 0x03) == 0) {
1814 sTechnology = "TFT"; 1817 sTechnology = "TFT";
1815 } else if ((VGArSEQ (0x30) & 0x01) == 0) { 1818 } else if ((VGArSEQ (0x30, par) & 0x01) == 0) {
1816 sTechnology = "DSTN"; 1819 sTechnology = "DSTN";
1817 } else { 1820 } else {
1818 sTechnology = "STN"; 1821 sTechnology = "STN";
@@ -2049,24 +2052,11 @@ static int __devinit savagefb_probe (struct pci_dev* dev,
2049 info->monspecs.modedb, info->monspecs.modedb_len, 2052 info->monspecs.modedb, info->monspecs.modedb_len,
2050 NULL, 8); 2053 NULL, 8);
2051 } else if (info->monspecs.modedb != NULL) { 2054 } else if (info->monspecs.modedb != NULL) {
2052 struct fb_monspecs *specs = &info->monspecs; 2055 struct fb_videomode *modedb;
2053 struct fb_videomode modedb;
2054 2056
2055 if (info->monspecs.misc & FB_MISC_1ST_DETAIL) { 2057 modedb = fb_find_best_display(&info->monspecs,
2056 int i; 2058 &info->modelist);
2057 2059 savage_update_var(&info->var, modedb);
2058 for (i = 0; i < specs->modedb_len; i++) {
2059 if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
2060 modedb = specs->modedb[i];
2061 break;
2062 }
2063 }
2064 } else {
2065 /* otherwise, get first mode in database */
2066 modedb = specs->modedb[0];
2067 }
2068
2069 savage_update_var(&info->var, &modedb);
2070 } 2060 }
2071 2061
2072 /* maximize virtual vertical length */ 2062 /* maximize virtual vertical length */
diff --git a/drivers/video/sgivwfb.c b/drivers/video/sgivwfb.c
index 5ce81f44c769..2e8769dd345a 100644
--- a/drivers/video/sgivwfb.c
+++ b/drivers/video/sgivwfb.c
@@ -126,7 +126,6 @@ static struct fb_ops sgivwfb_ops = {
126 .fb_fillrect = cfb_fillrect, 126 .fb_fillrect = cfb_fillrect,
127 .fb_copyarea = cfb_copyarea, 127 .fb_copyarea = cfb_copyarea,
128 .fb_imageblit = cfb_imageblit, 128 .fb_imageblit = cfb_imageblit,
129 .fb_cursor = soft_cursor,
130 .fb_mmap = sgivwfb_mmap, 129 .fb_mmap = sgivwfb_mmap,
131}; 130};
132 131
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index 42c54b69726e..dea1a46c67c4 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -2002,7 +2002,9 @@ static struct fb_ops sisfb_ops = {
2002 .fb_fillrect = fbcon_sis_fillrect, 2002 .fb_fillrect = fbcon_sis_fillrect,
2003 .fb_copyarea = fbcon_sis_copyarea, 2003 .fb_copyarea = fbcon_sis_copyarea,
2004 .fb_imageblit = cfb_imageblit, 2004 .fb_imageblit = cfb_imageblit,
2005#ifdef CONFIG_FB_SOFT_CURSOR
2005 .fb_cursor = soft_cursor, 2006 .fb_cursor = soft_cursor,
2007#endif
2006 .fb_sync = fbcon_sis_sync, 2008 .fb_sync = fbcon_sis_sync,
2007#ifdef SIS_NEW_CONFIG_COMPAT 2009#ifdef SIS_NEW_CONFIG_COMPAT
2008 .fb_compat_ioctl= sisfb_compat_ioctl, 2010 .fb_compat_ioctl= sisfb_compat_ioctl,
diff --git a/drivers/video/skeletonfb.c b/drivers/video/skeletonfb.c
index 7b43716ab665..a01e7ecc15ed 100644
--- a/drivers/video/skeletonfb.c
+++ b/drivers/video/skeletonfb.c
@@ -457,11 +457,8 @@ void xxxfb_imageblit(struct fb_info *p, const struct fb_image *image)
457} 457}
458 458
459/** 459/**
460 * xxxfb_cursor - REQUIRED function. If your hardware lacks support 460 * xxxfb_cursor - OPTIONAL. If your hardware lacks support
461 * for a cursor you can use the default cursor whose 461 * for a cursor, leave this field NULL.
462 * function is called soft_cursor. It will always
463 * work since it uses xxxfb_imageblit function which
464 * is required.
465 * 462 *
466 * @info: frame buffer structure that represents a single frame buffer 463 * @info: frame buffer structure that represents a single frame buffer
467 * @cursor: structure defining the cursor to draw. 464 * @cursor: structure defining the cursor to draw.
@@ -663,7 +660,7 @@ static struct fb_ops xxxfb_ops = {
663 .fb_fillrect = xxxfb_fillrect, /* Needed !!! */ 660 .fb_fillrect = xxxfb_fillrect, /* Needed !!! */
664 .fb_copyarea = xxxfb_copyarea, /* Needed !!! */ 661 .fb_copyarea = xxxfb_copyarea, /* Needed !!! */
665 .fb_imageblit = xxxfb_imageblit, /* Needed !!! */ 662 .fb_imageblit = xxxfb_imageblit, /* Needed !!! */
666 .fb_cursor = xxxfb_cursor, /* Needed !!! */ 663 .fb_cursor = xxxfb_cursor, /* Optional !!! */
667 .fb_rotate = xxxfb_rotate, 664 .fb_rotate = xxxfb_rotate,
668 .fb_poll = xxxfb_poll, 665 .fb_poll = xxxfb_poll,
669 .fb_sync = xxxfb_sync, 666 .fb_sync = xxxfb_sync,
diff --git a/drivers/video/sstfb.c b/drivers/video/sstfb.c
index 663d53657fa4..e0f14df840d9 100644
--- a/drivers/video/sstfb.c
+++ b/drivers/video/sstfb.c
@@ -1382,7 +1382,6 @@ static struct fb_ops sstfb_ops = {
1382 .fb_fillrect = cfb_fillrect, /* sstfb_fillrect */ 1382 .fb_fillrect = cfb_fillrect, /* sstfb_fillrect */
1383 .fb_copyarea = cfb_copyarea, /* sstfb_copyarea */ 1383 .fb_copyarea = cfb_copyarea, /* sstfb_copyarea */
1384 .fb_imageblit = cfb_imageblit, 1384 .fb_imageblit = cfb_imageblit,
1385 .fb_cursor = soft_cursor,
1386 .fb_ioctl = sstfb_ioctl, 1385 .fb_ioctl = sstfb_ioctl,
1387}; 1386};
1388 1387
diff --git a/drivers/video/stifb.c b/drivers/video/stifb.c
index 9e52794768e6..fbb17332afd7 100644
--- a/drivers/video/stifb.c
+++ b/drivers/video/stifb.c
@@ -1147,7 +1147,6 @@ static struct fb_ops stifb_ops = {
1147 .fb_fillrect = cfb_fillrect, 1147 .fb_fillrect = cfb_fillrect,
1148 .fb_copyarea = cfb_copyarea, 1148 .fb_copyarea = cfb_copyarea,
1149 .fb_imageblit = cfb_imageblit, 1149 .fb_imageblit = cfb_imageblit,
1150 .fb_cursor = soft_cursor,
1151}; 1150};
1152 1151
1153 1152
diff --git a/drivers/video/tcx.c b/drivers/video/tcx.c
index 1986a8b3833c..59fff29bc02e 100644
--- a/drivers/video/tcx.c
+++ b/drivers/video/tcx.c
@@ -52,7 +52,6 @@ static struct fb_ops tcx_ops = {
52 .fb_imageblit = cfb_imageblit, 52 .fb_imageblit = cfb_imageblit,
53 .fb_mmap = tcx_mmap, 53 .fb_mmap = tcx_mmap,
54 .fb_ioctl = tcx_ioctl, 54 .fb_ioctl = tcx_ioctl,
55 .fb_cursor = soft_cursor,
56}; 55};
57 56
58/* THC definitions */ 57/* THC definitions */
diff --git a/drivers/video/tdfxfb.c b/drivers/video/tdfxfb.c
index 7044226c5d4c..9d53387e6a66 100644
--- a/drivers/video/tdfxfb.c
+++ b/drivers/video/tdfxfb.c
@@ -184,7 +184,6 @@ static struct fb_ops tdfxfb_ops = {
184 .fb_copyarea = cfb_copyarea, 184 .fb_copyarea = cfb_copyarea,
185 .fb_imageblit = cfb_imageblit, 185 .fb_imageblit = cfb_imageblit,
186#endif 186#endif
187 .fb_cursor = soft_cursor,
188}; 187};
189 188
190/* 189/*
diff --git a/drivers/video/tgafb.c b/drivers/video/tgafb.c
index 9d9d2009ad8c..7398bd48ba6c 100644
--- a/drivers/video/tgafb.c
+++ b/drivers/video/tgafb.c
@@ -63,7 +63,6 @@ static struct fb_ops tgafb_ops = {
63 .fb_fillrect = tgafb_fillrect, 63 .fb_fillrect = tgafb_fillrect,
64 .fb_copyarea = tgafb_copyarea, 64 .fb_copyarea = tgafb_copyarea,
65 .fb_imageblit = tgafb_imageblit, 65 .fb_imageblit = tgafb_imageblit,
66 .fb_cursor = soft_cursor,
67}; 66};
68 67
69 68
diff --git a/drivers/video/tridentfb.c b/drivers/video/tridentfb.c
index 81a6d9f188cf..9ac2d3171187 100644
--- a/drivers/video/tridentfb.c
+++ b/drivers/video/tridentfb.c
@@ -1293,7 +1293,6 @@ static struct fb_ops tridentfb_ops = {
1293 .fb_fillrect = tridentfb_fillrect, 1293 .fb_fillrect = tridentfb_fillrect,
1294 .fb_copyarea= tridentfb_copyarea, 1294 .fb_copyarea= tridentfb_copyarea,
1295 .fb_imageblit = cfb_imageblit, 1295 .fb_imageblit = cfb_imageblit,
1296 .fb_cursor = soft_cursor,
1297}; 1296};
1298 1297
1299module_init(tridentfb_init); 1298module_init(tridentfb_init);
diff --git a/drivers/video/tx3912fb.c b/drivers/video/tx3912fb.c
index 39d9ca71856b..d904da44e1aa 100644
--- a/drivers/video/tx3912fb.c
+++ b/drivers/video/tx3912fb.c
@@ -89,7 +89,6 @@ static struct fb_ops tx3912fb_ops = {
89 .fb_fillrect = cfb_fillrect, 89 .fb_fillrect = cfb_fillrect,
90 .fb_copyarea = cfb_copyarea, 90 .fb_copyarea = cfb_copyarea,
91 .fb_imageblit = cfb_imageblit, 91 .fb_imageblit = cfb_imageblit,
92 .fb_cursor = soft_cursor,
93}; 92};
94 93
95static int tx3912fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 94static int tx3912fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
diff --git a/drivers/video/valkyriefb.c b/drivers/video/valkyriefb.c
index 31a2bbc53974..ce97ec8eae97 100644
--- a/drivers/video/valkyriefb.c
+++ b/drivers/video/valkyriefb.c
@@ -135,7 +135,6 @@ static struct fb_ops valkyriefb_ops = {
135 .fb_fillrect = cfb_fillrect, 135 .fb_fillrect = cfb_fillrect,
136 .fb_copyarea = cfb_copyarea, 136 .fb_copyarea = cfb_copyarea,
137 .fb_imageblit = cfb_imageblit, 137 .fb_imageblit = cfb_imageblit,
138 .fb_cursor = soft_cursor,
139}; 138};
140 139
141/* Sets the video mode according to info->var */ 140/* Sets the video mode according to info->var */
diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
index 3cc23106641d..e25eae1a78c1 100644
--- a/drivers/video/vesafb.c
+++ b/drivers/video/vesafb.c
@@ -48,7 +48,7 @@ static struct fb_fix_screeninfo vesafb_fix __initdata = {
48}; 48};
49 49
50static int inverse = 0; 50static int inverse = 0;
51static int mtrr = 3; /* default to write-combining */ 51static int mtrr = 0; /* disable mtrr */
52static int vram_remap __initdata = 0; /* Set amount of memory to be used */ 52static int vram_remap __initdata = 0; /* Set amount of memory to be used */
53static int vram_total __initdata = 0; /* Set total amount of memory */ 53static int vram_total __initdata = 0; /* Set total amount of memory */
54static int pmi_setpal = 0; /* pmi for palette changes ??? */ 54static int pmi_setpal = 0; /* pmi for palette changes ??? */
@@ -166,45 +166,39 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
166 if (regno >= info->cmap.len) 166 if (regno >= info->cmap.len)
167 return 1; 167 return 1;
168 168
169 switch (info->var.bits_per_pixel) { 169 if (info->var.bits_per_pixel == 8)
170 case 8:
171 vesa_setpalette(regno,red,green,blue); 170 vesa_setpalette(regno,red,green,blue);
172 break; 171 else if (regno < 16) {
173 case 16: 172 switch (info->var.bits_per_pixel) {
174 if (info->var.red.offset == 10) { 173 case 16:
175 /* 1:5:5:5 */ 174 if (info->var.red.offset == 10) {
176 ((u32*) (info->pseudo_palette))[regno] = 175 /* 1:5:5:5 */
176 ((u32*) (info->pseudo_palette))[regno] =
177 ((red & 0xf800) >> 1) | 177 ((red & 0xf800) >> 1) |
178 ((green & 0xf800) >> 6) | 178 ((green & 0xf800) >> 6) |
179 ((blue & 0xf800) >> 11); 179 ((blue & 0xf800) >> 11);
180 } else { 180 } else {
181 /* 0:5:6:5 */ 181 /* 0:5:6:5 */
182 ((u32*) (info->pseudo_palette))[regno] = 182 ((u32*) (info->pseudo_palette))[regno] =
183 ((red & 0xf800) ) | 183 ((red & 0xf800) ) |
184 ((green & 0xfc00) >> 5) | 184 ((green & 0xfc00) >> 5) |
185 ((blue & 0xf800) >> 11); 185 ((blue & 0xf800) >> 11);
186 }
187 break;
188 case 24:
189 case 32:
190 red >>= 8;
191 green >>= 8;
192 blue >>= 8;
193 ((u32 *)(info->pseudo_palette))[regno] =
194 (red << info->var.red.offset) |
195 (green << info->var.green.offset) |
196 (blue << info->var.blue.offset);
197 break;
186 } 198 }
187 break; 199 }
188 case 24: 200
189 red >>= 8; 201 return 0;
190 green >>= 8;
191 blue >>= 8;
192 ((u32 *)(info->pseudo_palette))[regno] =
193 (red << info->var.red.offset) |
194 (green << info->var.green.offset) |
195 (blue << info->var.blue.offset);
196 break;
197 case 32:
198 red >>= 8;
199 green >>= 8;
200 blue >>= 8;
201 ((u32 *)(info->pseudo_palette))[regno] =
202 (red << info->var.red.offset) |
203 (green << info->var.green.offset) |
204 (blue << info->var.blue.offset);
205 break;
206 }
207 return 0;
208} 202}
209 203
210static struct fb_ops vesafb_ops = { 204static struct fb_ops vesafb_ops = {
@@ -215,7 +209,6 @@ static struct fb_ops vesafb_ops = {
215 .fb_fillrect = cfb_fillrect, 209 .fb_fillrect = cfb_fillrect,
216 .fb_copyarea = cfb_copyarea, 210 .fb_copyarea = cfb_copyarea,
217 .fb_imageblit = cfb_imageblit, 211 .fb_imageblit = cfb_imageblit,
218 .fb_cursor = soft_cursor,
219}; 212};
220 213
221static int __init vesafb_setup(char *options) 214static int __init vesafb_setup(char *options)
diff --git a/drivers/video/vfb.c b/drivers/video/vfb.c
index 92d46555dd86..8794dc5d2466 100644
--- a/drivers/video/vfb.c
+++ b/drivers/video/vfb.c
@@ -92,7 +92,6 @@ static struct fb_ops vfb_ops = {
92 .fb_fillrect = cfb_fillrect, 92 .fb_fillrect = cfb_fillrect,
93 .fb_copyarea = cfb_copyarea, 93 .fb_copyarea = cfb_copyarea,
94 .fb_imageblit = cfb_imageblit, 94 .fb_imageblit = cfb_imageblit,
95 .fb_cursor = soft_cursor,
96 .fb_mmap = vfb_mmap, 95 .fb_mmap = vfb_mmap,
97}; 96};
98 97
diff --git a/drivers/video/vga16fb.c b/drivers/video/vga16fb.c
index b46454c55c91..690bb6fe8281 100644
--- a/drivers/video/vga16fb.c
+++ b/drivers/video/vga16fb.c
@@ -1326,7 +1326,6 @@ static struct fb_ops vga16fb_ops = {
1326 .fb_fillrect = vga16fb_fillrect, 1326 .fb_fillrect = vga16fb_fillrect,
1327 .fb_copyarea = vga16fb_copyarea, 1327 .fb_copyarea = vga16fb_copyarea,
1328 .fb_imageblit = vga16fb_imageblit, 1328 .fb_imageblit = vga16fb_imageblit,
1329 .fb_cursor = soft_cursor,
1330}; 1329};
1331 1330
1332#ifndef MODULE 1331#ifndef MODULE
diff --git a/drivers/video/w100fb.c b/drivers/video/w100fb.c
index cf8cdb108fd9..48e70f153c4b 100644
--- a/drivers/video/w100fb.c
+++ b/drivers/video/w100fb.c
@@ -397,7 +397,6 @@ static struct fb_ops w100fb_ops = {
397 .fb_fillrect = cfb_fillrect, 397 .fb_fillrect = cfb_fillrect,
398 .fb_copyarea = cfb_copyarea, 398 .fb_copyarea = cfb_copyarea,
399 .fb_imageblit = cfb_imageblit, 399 .fb_imageblit = cfb_imageblit,
400 .fb_cursor = soft_cursor,
401}; 400};
402 401
403#ifdef CONFIG_PM 402#ifdef CONFIG_PM
diff --git a/drivers/w1/w1_ds2433.c b/drivers/w1/w1_ds2433.c
index 279e0e0363d6..1e3d98aac12d 100644
--- a/drivers/w1/w1_ds2433.c
+++ b/drivers/w1/w1_ds2433.c
@@ -299,10 +299,8 @@ static int w1_f23_add_slave(struct w1_slave *sl)
299static void w1_f23_remove_slave(struct w1_slave *sl) 299static void w1_f23_remove_slave(struct w1_slave *sl)
300{ 300{
301#ifdef CONFIG_W1_F23_CRC 301#ifdef CONFIG_W1_F23_CRC
302 if (sl->family_data) { 302 kfree(sl->family_data);
303 kfree(sl->family_data); 303 sl->family_data = NULL;
304 sl->family_data = NULL;
305 }
306#endif /* CONFIG_W1_F23_CRC */ 304#endif /* CONFIG_W1_F23_CRC */
307 sysfs_remove_bin_file(&sl->dev.kobj, &w1_f23_bin_attr); 305 sysfs_remove_bin_file(&sl->dev.kobj, &w1_f23_bin_attr);
308} 306}
diff --git a/fs/9p/error.c b/fs/9p/error.c
index fee5d19179c5..834cb179e388 100644
--- a/fs/9p/error.c
+++ b/fs/9p/error.c
@@ -33,6 +33,7 @@
33 33
34#include <linux/list.h> 34#include <linux/list.h>
35#include <linux/jhash.h> 35#include <linux/jhash.h>
36#include <linux/string.h>
36 37
37#include "debug.h" 38#include "debug.h"
38#include "error.h" 39#include "error.h"
diff --git a/fs/9p/trans_sock.c b/fs/9p/trans_sock.c
index 01e26f0013ac..a93c2bf94c33 100644
--- a/fs/9p/trans_sock.c
+++ b/fs/9p/trans_sock.c
@@ -269,8 +269,7 @@ static void v9fs_sock_close(struct v9fs_transport *trans)
269 dprintk(DEBUG_TRANS, "socket closed\n"); 269 dprintk(DEBUG_TRANS, "socket closed\n");
270 } 270 }
271 271
272 if (ts) 272 kfree(ts);
273 kfree(ts);
274 273
275 trans->priv = NULL; 274 trans->priv = NULL;
276} 275}
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index 82303f3bf76f..418c3743fdee 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -266,7 +266,7 @@ v9fs_session_init(struct v9fs_session_info *v9ses,
266 266
267 v9ses->remotename = __getname(); 267 v9ses->remotename = __getname();
268 if (!v9ses->remotename) { 268 if (!v9ses->remotename) {
269 putname(v9ses->name); 269 __putname(v9ses->name);
270 return -ENOMEM; 270 return -ENOMEM;
271 } 271 }
272 272
@@ -411,8 +411,8 @@ void v9fs_session_close(struct v9fs_session_info *v9ses)
411 if (v9ses->transport) 411 if (v9ses->transport)
412 v9ses->transport->close(v9ses->transport); 412 v9ses->transport->close(v9ses->transport);
413 413
414 putname(v9ses->name); 414 __putname(v9ses->name);
415 putname(v9ses->remotename); 415 __putname(v9ses->remotename);
416} 416}
417 417
418/** 418/**
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 2b696ae6655a..be7288184fa9 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -1105,7 +1105,7 @@ static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer,
1105 } 1105 }
1106 } 1106 }
1107 1107
1108 putname(link); 1108 __putname(link);
1109 return retval; 1109 return retval;
1110} 1110}
1111 1111
@@ -1129,7 +1129,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
1129 len = v9fs_readlink(dentry, link, strlen(link)); 1129 len = v9fs_readlink(dentry, link, strlen(link));
1130 1130
1131 if (len < 0) { 1131 if (len < 0) {
1132 putname(link); 1132 __putname(link);
1133 link = ERR_PTR(len); 1133 link = ERR_PTR(len);
1134 } else 1134 } else
1135 link[len] = 0; 1135 link[len] = 0;
@@ -1152,7 +1152,7 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void
1152 1152
1153 dprintk(DEBUG_VFS, " %s %s\n", dentry->d_name.name, s); 1153 dprintk(DEBUG_VFS, " %s %s\n", dentry->d_name.name, s);
1154 if (!IS_ERR(s)) 1154 if (!IS_ERR(s))
1155 putname(s); 1155 __putname(s);
1156} 1156}
1157 1157
1158/** 1158/**
@@ -1228,7 +1228,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1228 FreeMem: 1228 FreeMem:
1229 kfree(mistat); 1229 kfree(mistat);
1230 kfree(fcall); 1230 kfree(fcall);
1231 putname(symname); 1231 __putname(symname);
1232 return retval; 1232 return retval;
1233} 1233}
1234 1234
@@ -1319,7 +1319,7 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1319 FreeMem: 1319 FreeMem:
1320 kfree(mistat); 1320 kfree(mistat);
1321 kfree(fcall); 1321 kfree(fcall);
1322 putname(symname); 1322 __putname(symname);
1323 1323
1324 return retval; 1324 return retval;
1325} 1325}
diff --git a/fs/Kconfig b/fs/Kconfig
index 01a295232f75..7d6ae369ce44 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -898,6 +898,7 @@ config AFFS_FS
898config HFS_FS 898config HFS_FS
899 tristate "Apple Macintosh file system support (EXPERIMENTAL)" 899 tristate "Apple Macintosh file system support (EXPERIMENTAL)"
900 depends on EXPERIMENTAL 900 depends on EXPERIMENTAL
901 select NLS
901 help 902 help
902 If you say Y here, you will be able to mount Macintosh-formatted 903 If you say Y here, you will be able to mount Macintosh-formatted
903 floppy disks and hard drive partitions with full read-write access. 904 floppy disks and hard drive partitions with full read-write access.
@@ -1050,6 +1051,19 @@ config JFFS2_FS_WRITEBUFFER
1050 - NOR flash with transparent ECC 1051 - NOR flash with transparent ECC
1051 - DataFlash 1052 - DataFlash
1052 1053
1054config JFFS2_SUMMARY
1055 bool "JFFS2 summary support (EXPERIMENTAL)"
1056 depends on JFFS2_FS && EXPERIMENTAL
1057 default n
1058 help
1059 This feature makes it possible to use summary information
1060 for faster filesystem mount.
1061
1062 The summary information can be inserted into a filesystem image
1063 by the utility 'sumtool'.
1064
1065 If unsure, say 'N'.
1066
1053config JFFS2_COMPRESSION_OPTIONS 1067config JFFS2_COMPRESSION_OPTIONS
1054 bool "Advanced compression options for JFFS2" 1068 bool "Advanced compression options for JFFS2"
1055 depends on JFFS2_FS 1069 depends on JFFS2_FS
@@ -1071,10 +1085,10 @@ config JFFS2_ZLIB
1071 default y 1085 default y
1072 help 1086 help
1073 Zlib is designed to be a free, general-purpose, legally unencumbered, 1087 Zlib is designed to be a free, general-purpose, legally unencumbered,
1074 lossless data-compression library for use on virtually any computer 1088 lossless data-compression library for use on virtually any computer
1075 hardware and operating system. See <http://www.gzip.org/zlib/> for 1089 hardware and operating system. See <http://www.gzip.org/zlib/> for
1076 further information. 1090 further information.
1077 1091
1078 Say 'Y' if unsure. 1092 Say 'Y' if unsure.
1079 1093
1080config JFFS2_RTIME 1094config JFFS2_RTIME
@@ -1096,7 +1110,7 @@ choice
1096 default JFFS2_CMODE_PRIORITY 1110 default JFFS2_CMODE_PRIORITY
1097 depends on JFFS2_FS 1111 depends on JFFS2_FS
1098 help 1112 help
1099 You can set here the default compression mode of JFFS2 from 1113 You can set here the default compression mode of JFFS2 from
1100 the available compression modes. Don't touch if unsure. 1114 the available compression modes. Don't touch if unsure.
1101 1115
1102config JFFS2_CMODE_NONE 1116config JFFS2_CMODE_NONE
@@ -1107,13 +1121,13 @@ config JFFS2_CMODE_NONE
1107config JFFS2_CMODE_PRIORITY 1121config JFFS2_CMODE_PRIORITY
1108 bool "priority" 1122 bool "priority"
1109 help 1123 help
1110 Tries the compressors in a predefinied order and chooses the first 1124 Tries the compressors in a predefinied order and chooses the first
1111 successful one. 1125 successful one.
1112 1126
1113config JFFS2_CMODE_SIZE 1127config JFFS2_CMODE_SIZE
1114 bool "size (EXPERIMENTAL)" 1128 bool "size (EXPERIMENTAL)"
1115 help 1129 help
1116 Tries all compressors and chooses the one which has the smallest 1130 Tries all compressors and chooses the one which has the smallest
1117 result. 1131 result.
1118 1132
1119endchoice 1133endchoice
diff --git a/fs/Makefile b/fs/Makefile
index 1972da186272..4c2655759078 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -10,7 +10,7 @@ obj-y := open.o read_write.o file_table.o buffer.o bio.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 mpage.o direct-io.o \ 12 seq_file.o xattr.o libfs.o fs-writeback.o mpage.o direct-io.o \
13 ioprio.o 13 ioprio.o pnode.o
14 14
15obj-$(CONFIG_INOTIFY) += inotify.o 15obj-$(CONFIG_INOTIFY) += inotify.o
16obj-$(CONFIG_EPOLL) += eventpoll.o 16obj-$(CONFIG_EPOLL) += eventpoll.o
diff --git a/fs/affs/file.c b/fs/affs/file.c
index 6744924b6905..f72fb776ecdf 100644
--- a/fs/affs/file.c
+++ b/fs/affs/file.c
@@ -22,14 +22,13 @@ static int affs_grow_extcache(struct inode *inode, u32 lc_idx);
22static struct buffer_head *affs_alloc_extblock(struct inode *inode, struct buffer_head *bh, u32 ext); 22static struct buffer_head *affs_alloc_extblock(struct inode *inode, struct buffer_head *bh, u32 ext);
23static inline struct buffer_head *affs_get_extblock(struct inode *inode, u32 ext); 23static inline struct buffer_head *affs_get_extblock(struct inode *inode, u32 ext);
24static struct buffer_head *affs_get_extblock_slow(struct inode *inode, u32 ext); 24static struct buffer_head *affs_get_extblock_slow(struct inode *inode, u32 ext);
25static ssize_t affs_file_write(struct file *filp, const char __user *buf, size_t count, loff_t *ppos);
26static int affs_file_open(struct inode *inode, struct file *filp); 25static int affs_file_open(struct inode *inode, struct file *filp);
27static int affs_file_release(struct inode *inode, struct file *filp); 26static int affs_file_release(struct inode *inode, struct file *filp);
28 27
29struct file_operations affs_file_operations = { 28struct file_operations affs_file_operations = {
30 .llseek = generic_file_llseek, 29 .llseek = generic_file_llseek,
31 .read = generic_file_read, 30 .read = generic_file_read,
32 .write = affs_file_write, 31 .write = generic_file_write,
33 .mmap = generic_file_mmap, 32 .mmap = generic_file_mmap,
34 .open = affs_file_open, 33 .open = affs_file_open,
35 .release = affs_file_release, 34 .release = affs_file_release,
@@ -473,21 +472,6 @@ affs_getemptyblk_ino(struct inode *inode, int block)
473 return ERR_PTR(err); 472 return ERR_PTR(err);
474} 473}
475 474
476static ssize_t
477affs_file_write(struct file *file, const char __user *buf,
478 size_t count, loff_t *ppos)
479{
480 ssize_t retval;
481
482 retval = generic_file_write (file, buf, count, ppos);
483 if (retval >0) {
484 struct inode *inode = file->f_dentry->d_inode;
485 inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
486 mark_inode_dirty(inode);
487 }
488 return retval;
489}
490
491static int 475static int
492affs_do_readpage_ofs(struct file *file, struct page *page, unsigned from, unsigned to) 476affs_do_readpage_ofs(struct file *file, struct page *page, unsigned from, unsigned to)
493{ 477{
diff --git a/fs/affs/super.c b/fs/affs/super.c
index 9c3080716c92..aaec015a16e4 100644
--- a/fs/affs/super.c
+++ b/fs/affs/super.c
@@ -35,8 +35,7 @@ affs_put_super(struct super_block *sb)
35 mark_buffer_dirty(sbi->s_root_bh); 35 mark_buffer_dirty(sbi->s_root_bh);
36 } 36 }
37 37
38 if (sbi->s_prefix) 38 kfree(sbi->s_prefix);
39 kfree(sbi->s_prefix);
40 affs_free_bitmap(sb); 39 affs_free_bitmap(sb);
41 affs_brelse(sbi->s_root_bh); 40 affs_brelse(sbi->s_root_bh);
42 kfree(sbi); 41 kfree(sbi);
@@ -198,10 +197,9 @@ parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s
198 *mount_opts |= SF_MUFS; 197 *mount_opts |= SF_MUFS;
199 break; 198 break;
200 case Opt_prefix: 199 case Opt_prefix:
201 if (*prefix) { /* Free any previous prefix */ 200 /* Free any previous prefix */
202 kfree(*prefix); 201 kfree(*prefix);
203 *prefix = NULL; 202 *prefix = NULL;
204 }
205 *prefix = match_strdup(&args[0]); 203 *prefix = match_strdup(&args[0]);
206 if (!*prefix) 204 if (!*prefix)
207 return 0; 205 return 0;
@@ -462,11 +460,9 @@ got_root:
462out_error: 460out_error:
463 if (root_inode) 461 if (root_inode)
464 iput(root_inode); 462 iput(root_inode);
465 if (sbi->s_bitmap) 463 kfree(sbi->s_bitmap);
466 kfree(sbi->s_bitmap);
467 affs_brelse(root_bh); 464 affs_brelse(root_bh);
468 if (sbi->s_prefix) 465 kfree(sbi->s_prefix);
469 kfree(sbi->s_prefix);
470 kfree(sbi); 466 kfree(sbi);
471 sb->s_fs_info = NULL; 467 sb->s_fs_info = NULL;
472 return -EINVAL; 468 return -EINVAL;
diff --git a/fs/afs/file.c b/fs/afs/file.c
index 4975c9c193dd..150b19227922 100644
--- a/fs/afs/file.c
+++ b/fs/afs/file.c
@@ -31,24 +31,10 @@ static int afs_file_readpage(struct file *file, struct page *page);
31static int afs_file_invalidatepage(struct page *page, unsigned long offset); 31static int afs_file_invalidatepage(struct page *page, unsigned long offset);
32static int afs_file_releasepage(struct page *page, gfp_t gfp_flags); 32static int afs_file_releasepage(struct page *page, gfp_t gfp_flags);
33 33
34static ssize_t afs_file_write(struct file *file, const char __user *buf,
35 size_t size, loff_t *off);
36
37struct inode_operations afs_file_inode_operations = { 34struct inode_operations afs_file_inode_operations = {
38 .getattr = afs_inode_getattr, 35 .getattr = afs_inode_getattr,
39}; 36};
40 37
41struct file_operations afs_file_file_operations = {
42 .read = generic_file_read,
43 .write = afs_file_write,
44 .mmap = generic_file_mmap,
45#if 0
46 .open = afs_file_open,
47 .release = afs_file_release,
48 .fsync = afs_file_fsync,
49#endif
50};
51
52struct address_space_operations afs_fs_aops = { 38struct address_space_operations afs_fs_aops = {
53 .readpage = afs_file_readpage, 39 .readpage = afs_file_readpage,
54 .sync_page = block_sync_page, 40 .sync_page = block_sync_page,
@@ -59,22 +45,6 @@ struct address_space_operations afs_fs_aops = {
59 45
60/*****************************************************************************/ 46/*****************************************************************************/
61/* 47/*
62 * AFS file write
63 */
64static ssize_t afs_file_write(struct file *file, const char __user *buf,
65 size_t size, loff_t *off)
66{
67 struct afs_vnode *vnode;
68
69 vnode = AFS_FS_I(file->f_dentry->d_inode);
70 if (vnode->flags & AFS_VNODE_DELETED)
71 return -ESTALE;
72
73 return -EIO;
74} /* end afs_file_write() */
75
76/*****************************************************************************/
77/*
78 * deal with notification that a page was read from the cache 48 * deal with notification that a page was read from the cache
79 */ 49 */
80#ifdef AFS_CACHING_SUPPORT 50#ifdef AFS_CACHING_SUPPORT
@@ -295,8 +265,7 @@ static int afs_file_releasepage(struct page *page, gfp_t gfp_flags)
295 set_page_private(page, 0); 265 set_page_private(page, 0);
296 ClearPagePrivate(page); 266 ClearPagePrivate(page);
297 267
298 if (pageio) 268 kfree(pageio);
299 kfree(pageio);
300 } 269 }
301 270
302 _leave(" = 0"); 271 _leave(" = 0");
diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index c476fde33fbc..4ebb30a50ed5 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -49,7 +49,7 @@ static int afs_inode_map_status(struct afs_vnode *vnode)
49 case AFS_FTYPE_FILE: 49 case AFS_FTYPE_FILE:
50 inode->i_mode = S_IFREG | vnode->status.mode; 50 inode->i_mode = S_IFREG | vnode->status.mode;
51 inode->i_op = &afs_file_inode_operations; 51 inode->i_op = &afs_file_inode_operations;
52 inode->i_fop = &afs_file_file_operations; 52 inode->i_fop = &generic_ro_fops;
53 break; 53 break;
54 case AFS_FTYPE_DIR: 54 case AFS_FTYPE_DIR:
55 inode->i_mode = S_IFDIR | vnode->status.mode; 55 inode->i_mode = S_IFDIR | vnode->status.mode;
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index f09860b45c1a..ab8f87c66319 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -71,7 +71,6 @@ extern struct file_operations afs_dir_file_operations;
71 */ 71 */
72extern struct address_space_operations afs_fs_aops; 72extern struct address_space_operations afs_fs_aops;
73extern struct inode_operations afs_file_inode_operations; 73extern struct inode_operations afs_file_inode_operations;
74extern struct file_operations afs_file_file_operations;
75 74
76#ifdef AFS_CACHING_SUPPORT 75#ifdef AFS_CACHING_SUPPORT
77extern int afs_cache_get_page_cookie(struct page *page, 76extern int afs_cache_get_page_cookie(struct page *page,
diff --git a/fs/aio.c b/fs/aio.c
index edfca5b75535..20bb919eb195 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -42,8 +42,9 @@
42#endif 42#endif
43 43
44/*------ sysctl variables----*/ 44/*------ sysctl variables----*/
45atomic_t aio_nr = ATOMIC_INIT(0); /* current system wide number of aio requests */ 45static DEFINE_SPINLOCK(aio_nr_lock);
46unsigned aio_max_nr = 0x10000; /* system wide maximum number of aio requests */ 46unsigned long aio_nr; /* current system wide number of aio requests */
47unsigned long aio_max_nr = 0x10000; /* system wide maximum number of aio requests */
47/*----end sysctl variables---*/ 48/*----end sysctl variables---*/
48 49
49static kmem_cache_t *kiocb_cachep; 50static kmem_cache_t *kiocb_cachep;
@@ -208,7 +209,7 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
208 return ERR_PTR(-EINVAL); 209 return ERR_PTR(-EINVAL);
209 } 210 }
210 211
211 if (nr_events > aio_max_nr) 212 if ((unsigned long)nr_events > aio_max_nr)
212 return ERR_PTR(-EAGAIN); 213 return ERR_PTR(-EAGAIN);
213 214
214 ctx = kmem_cache_alloc(kioctx_cachep, GFP_KERNEL); 215 ctx = kmem_cache_alloc(kioctx_cachep, GFP_KERNEL);
@@ -233,8 +234,14 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
233 goto out_freectx; 234 goto out_freectx;
234 235
235 /* limit the number of system wide aios */ 236 /* limit the number of system wide aios */
236 atomic_add(ctx->max_reqs, &aio_nr); /* undone by __put_ioctx */ 237 spin_lock(&aio_nr_lock);
237 if (unlikely(atomic_read(&aio_nr) > aio_max_nr)) 238 if (aio_nr + ctx->max_reqs > aio_max_nr ||
239 aio_nr + ctx->max_reqs < aio_nr)
240 ctx->max_reqs = 0;
241 else
242 aio_nr += ctx->max_reqs;
243 spin_unlock(&aio_nr_lock);
244 if (ctx->max_reqs == 0)
238 goto out_cleanup; 245 goto out_cleanup;
239 246
240 /* now link into global list. kludge. FIXME */ 247 /* now link into global list. kludge. FIXME */
@@ -248,8 +255,6 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
248 return ctx; 255 return ctx;
249 256
250out_cleanup: 257out_cleanup:
251 atomic_sub(ctx->max_reqs, &aio_nr);
252 ctx->max_reqs = 0; /* prevent __put_ioctx from sub'ing aio_nr */
253 __put_ioctx(ctx); 258 __put_ioctx(ctx);
254 return ERR_PTR(-EAGAIN); 259 return ERR_PTR(-EAGAIN);
255 260
@@ -374,7 +379,12 @@ void fastcall __put_ioctx(struct kioctx *ctx)
374 pr_debug("__put_ioctx: freeing %p\n", ctx); 379 pr_debug("__put_ioctx: freeing %p\n", ctx);
375 kmem_cache_free(kioctx_cachep, ctx); 380 kmem_cache_free(kioctx_cachep, ctx);
376 381
377 atomic_sub(nr_events, &aio_nr); 382 if (nr_events) {
383 spin_lock(&aio_nr_lock);
384 BUG_ON(aio_nr - nr_events > aio_nr);
385 aio_nr -= nr_events;
386 spin_unlock(&aio_nr_lock);
387 }
378} 388}
379 389
380/* aio_get_req 390/* aio_get_req
@@ -1258,8 +1268,9 @@ asmlinkage long sys_io_setup(unsigned nr_events, aio_context_t __user *ctxp)
1258 goto out; 1268 goto out;
1259 1269
1260 ret = -EINVAL; 1270 ret = -EINVAL;
1261 if (unlikely(ctx || (int)nr_events <= 0)) { 1271 if (unlikely(ctx || nr_events == 0)) {
1262 pr_debug("EINVAL: io_setup: ctx or nr_events > max\n"); 1272 pr_debug("EINVAL: io_setup: ctx %lu nr_events %u\n",
1273 ctx, nr_events);
1263 goto out; 1274 goto out;
1264 } 1275 }
1265 1276
diff --git a/fs/autofs/waitq.c b/fs/autofs/waitq.c
index 1fcaa1568541..633f628005b4 100644
--- a/fs/autofs/waitq.c
+++ b/fs/autofs/waitq.c
@@ -150,10 +150,8 @@ int autofs_wait(struct autofs_sb_info *sbi, struct qstr *name)
150 if ( sbi->catatonic ) { 150 if ( sbi->catatonic ) {
151 /* We might have slept, so check again for catatonic mode */ 151 /* We might have slept, so check again for catatonic mode */
152 wq->status = -ENOENT; 152 wq->status = -ENOENT;
153 if ( wq->name ) { 153 kfree(wq->name);
154 kfree(wq->name); 154 wq->name = NULL;
155 wq->name = NULL;
156 }
157 } 155 }
158 156
159 if ( wq->name ) { 157 if ( wq->name ) {
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
index 0a3c05d10167..818b37be5153 100644
--- a/fs/autofs4/inode.c
+++ b/fs/autofs4/inode.c
@@ -22,10 +22,8 @@
22 22
23static void ino_lnkfree(struct autofs_info *ino) 23static void ino_lnkfree(struct autofs_info *ino)
24{ 24{
25 if (ino->u.symlink) { 25 kfree(ino->u.symlink);
26 kfree(ino->u.symlink); 26 ino->u.symlink = NULL;
27 ino->u.symlink = NULL;
28 }
29} 27}
30 28
31struct autofs_info *autofs4_init_ino(struct autofs_info *ino, 29struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
index 3df86285a1c7..394ff36ef8f1 100644
--- a/fs/autofs4/waitq.c
+++ b/fs/autofs4/waitq.c
@@ -243,10 +243,8 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
243 if ( sbi->catatonic ) { 243 if ( sbi->catatonic ) {
244 /* We might have slept, so check again for catatonic mode */ 244 /* We might have slept, so check again for catatonic mode */
245 wq->status = -ENOENT; 245 wq->status = -ENOENT;
246 if ( wq->name ) { 246 kfree(wq->name);
247 kfree(wq->name); 247 wq->name = NULL;
248 wq->name = NULL;
249 }
250 } 248 }
251 249
252 if ( wq->name ) { 250 if ( wq->name ) {
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index e0a6025f1d06..2d365cb8eec6 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -73,12 +73,6 @@ static struct inode_operations befs_dir_inode_operations = {
73 .lookup = befs_lookup, 73 .lookup = befs_lookup,
74}; 74};
75 75
76static struct file_operations befs_file_operations = {
77 .llseek = default_llseek,
78 .read = generic_file_read,
79 .mmap = generic_file_readonly_mmap,
80};
81
82static struct address_space_operations befs_aops = { 76static struct address_space_operations befs_aops = {
83 .readpage = befs_readpage, 77 .readpage = befs_readpage,
84 .sync_page = block_sync_page, 78 .sync_page = block_sync_page,
@@ -398,7 +392,7 @@ befs_read_inode(struct inode *inode)
398 inode->i_mapping->a_ops = &befs_aops; 392 inode->i_mapping->a_ops = &befs_aops;
399 393
400 if (S_ISREG(inode->i_mode)) { 394 if (S_ISREG(inode->i_mode)) {
401 inode->i_fop = &befs_file_operations; 395 inode->i_fop = &generic_ro_fops;
402 } else if (S_ISDIR(inode->i_mode)) { 396 } else if (S_ISDIR(inode->i_mode)) {
403 inode->i_op = &befs_dir_inode_operations; 397 inode->i_op = &befs_dir_inode_operations;
404 inode->i_fop = &befs_dir_operations; 398 inode->i_fop = &befs_dir_operations;
@@ -731,20 +725,16 @@ parse_options(char *options, befs_mount_options * opts)
731static void 725static void
732befs_put_super(struct super_block *sb) 726befs_put_super(struct super_block *sb)
733{ 727{
734 if (BEFS_SB(sb)->mount_opts.iocharset) { 728 kfree(BEFS_SB(sb)->mount_opts.iocharset);
735 kfree(BEFS_SB(sb)->mount_opts.iocharset); 729 BEFS_SB(sb)->mount_opts.iocharset = NULL;
736 BEFS_SB(sb)->mount_opts.iocharset = NULL;
737 }
738 730
739 if (BEFS_SB(sb)->nls) { 731 if (BEFS_SB(sb)->nls) {
740 unload_nls(BEFS_SB(sb)->nls); 732 unload_nls(BEFS_SB(sb)->nls);
741 BEFS_SB(sb)->nls = NULL; 733 BEFS_SB(sb)->nls = NULL;
742 } 734 }
743 735
744 if (sb->s_fs_info) { 736 kfree(sb->s_fs_info);
745 kfree(sb->s_fs_info); 737 sb->s_fs_info = NULL;
746 sb->s_fs_info = NULL;
747 }
748 return; 738 return;
749} 739}
750 740
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 6fa6adc40972..f36f2210204f 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1006,8 +1006,7 @@ out_free_dentry:
1006 if (interpreter) 1006 if (interpreter)
1007 fput(interpreter); 1007 fput(interpreter);
1008out_free_interp: 1008out_free_interp:
1009 if (elf_interpreter) 1009 kfree(elf_interpreter);
1010 kfree(elf_interpreter);
1011out_free_file: 1010out_free_file:
1012 sys_close(elf_exec_fileno); 1011 sys_close(elf_exec_fileno);
1013out_free_fh: 1012out_free_fh:
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index dda87c4c82a3..e0344f69c79d 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -411,16 +411,11 @@ error:
411 allow_write_access(interpreter); 411 allow_write_access(interpreter);
412 fput(interpreter); 412 fput(interpreter);
413 } 413 }
414 if (interpreter_name) 414 kfree(interpreter_name);
415 kfree(interpreter_name); 415 kfree(exec_params.phdrs);
416 if (exec_params.phdrs) 416 kfree(exec_params.loadmap);
417 kfree(exec_params.phdrs); 417 kfree(interp_params.phdrs);
418 if (exec_params.loadmap) 418 kfree(interp_params.loadmap);
419 kfree(exec_params.loadmap);
420 if (interp_params.phdrs)
421 kfree(interp_params.phdrs);
422 if (interp_params.loadmap)
423 kfree(interp_params.loadmap);
424 return retval; 419 return retval;
425 420
426 /* unrecoverable error - kill the process */ 421 /* unrecoverable error - kill the process */
diff --git a/fs/buffer.c b/fs/buffer.c
index 35fa34977e81..5287be18633b 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -396,7 +396,7 @@ asmlinkage long sys_fdatasync(unsigned int fd)
396 * private_lock is contended then so is mapping->tree_lock). 396 * private_lock is contended then so is mapping->tree_lock).
397 */ 397 */
398static struct buffer_head * 398static struct buffer_head *
399__find_get_block_slow(struct block_device *bdev, sector_t block, int unused) 399__find_get_block_slow(struct block_device *bdev, sector_t block)
400{ 400{
401 struct inode *bd_inode = bdev->bd_inode; 401 struct inode *bd_inode = bdev->bd_inode;
402 struct address_space *bd_mapping = bd_inode->i_mapping; 402 struct address_space *bd_mapping = bd_inode->i_mapping;
@@ -1438,7 +1438,7 @@ __find_get_block(struct block_device *bdev, sector_t block, int size)
1438 struct buffer_head *bh = lookup_bh_lru(bdev, block, size); 1438 struct buffer_head *bh = lookup_bh_lru(bdev, block, size);
1439 1439
1440 if (bh == NULL) { 1440 if (bh == NULL) {
1441 bh = __find_get_block_slow(bdev, block, size); 1441 bh = __find_get_block_slow(bdev, block);
1442 if (bh) 1442 if (bh)
1443 bh_lru_install(bh); 1443 bh_lru_install(bh);
1444 } 1444 }
@@ -1705,7 +1705,7 @@ void unmap_underlying_metadata(struct block_device *bdev, sector_t block)
1705 1705
1706 might_sleep(); 1706 might_sleep();
1707 1707
1708 old_bh = __find_get_block_slow(bdev, block, 0); 1708 old_bh = __find_get_block_slow(bdev, block);
1709 if (old_bh) { 1709 if (old_bh) {
1710 clear_buffer_dirty(old_bh); 1710 clear_buffer_dirty(old_bh);
1711 wait_on_buffer(old_bh); 1711 wait_on_buffer(old_bh);
diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c
index 98539e2afe81..086ae8f4a207 100644
--- a/fs/cifs/asn1.c
+++ b/fs/cifs/asn1.c
@@ -553,8 +553,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
553 *(oid + 3))); 553 *(oid + 3)));
554 rc = compare_oid(oid, oidlen, NTLMSSP_OID, 554 rc = compare_oid(oid, oidlen, NTLMSSP_OID,
555 NTLMSSP_OID_LEN); 555 NTLMSSP_OID_LEN);
556 if(oid) 556 kfree(oid);
557 kfree(oid);
558 if (rc) 557 if (rc)
559 use_ntlmssp = TRUE; 558 use_ntlmssp = TRUE;
560 } 559 }
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index d74367a08d51..450ab75d6546 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1265,8 +1265,7 @@ connect_to_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
1265 the helper that resolves tcp names, mount to it, try to 1265 the helper that resolves tcp names, mount to it, try to
1266 tcon to it unmount it if fail */ 1266 tcon to it unmount it if fail */
1267 1267
1268 if(referrals) 1268 kfree(referrals);
1269 kfree(referrals);
1270 1269
1271 return rc; 1270 return rc;
1272} 1271}
@@ -1535,10 +1534,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1535 1534
1536 memset(&volume_info,0,sizeof(struct smb_vol)); 1535 memset(&volume_info,0,sizeof(struct smb_vol));
1537 if (cifs_parse_mount_options(mount_data, devname, &volume_info)) { 1536 if (cifs_parse_mount_options(mount_data, devname, &volume_info)) {
1538 if(volume_info.UNC) 1537 kfree(volume_info.UNC);
1539 kfree(volume_info.UNC); 1538 kfree(volume_info.password);
1540 if(volume_info.password)
1541 kfree(volume_info.password);
1542 FreeXid(xid); 1539 FreeXid(xid);
1543 return -EINVAL; 1540 return -EINVAL;
1544 } 1541 }
@@ -1551,10 +1548,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1551 cifserror("No username specified "); 1548 cifserror("No username specified ");
1552 /* In userspace mount helper we can get user name from alternate 1549 /* In userspace mount helper we can get user name from alternate
1553 locations such as env variables and files on disk */ 1550 locations such as env variables and files on disk */
1554 if(volume_info.UNC) 1551 kfree(volume_info.UNC);
1555 kfree(volume_info.UNC); 1552 kfree(volume_info.password);
1556 if(volume_info.password)
1557 kfree(volume_info.password);
1558 FreeXid(xid); 1553 FreeXid(xid);
1559 return -EINVAL; 1554 return -EINVAL;
1560 } 1555 }
@@ -1573,10 +1568,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1573 1568
1574 if(rc <= 0) { 1569 if(rc <= 0) {
1575 /* we failed translating address */ 1570 /* we failed translating address */
1576 if(volume_info.UNC) 1571 kfree(volume_info.UNC);
1577 kfree(volume_info.UNC); 1572 kfree(volume_info.password);
1578 if(volume_info.password)
1579 kfree(volume_info.password);
1580 FreeXid(xid); 1573 FreeXid(xid);
1581 return -EINVAL; 1574 return -EINVAL;
1582 } 1575 }
@@ -1587,19 +1580,15 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1587 } else if (volume_info.UNCip){ 1580 } else if (volume_info.UNCip){
1588 /* BB using ip addr as server name connect to the DFS root below */ 1581 /* BB using ip addr as server name connect to the DFS root below */
1589 cERROR(1,("Connecting to DFS root not implemented yet")); 1582 cERROR(1,("Connecting to DFS root not implemented yet"));
1590 if(volume_info.UNC) 1583 kfree(volume_info.UNC);
1591 kfree(volume_info.UNC); 1584 kfree(volume_info.password);
1592 if(volume_info.password)
1593 kfree(volume_info.password);
1594 FreeXid(xid); 1585 FreeXid(xid);
1595 return -EINVAL; 1586 return -EINVAL;
1596 } else /* which servers DFS root would we conect to */ { 1587 } else /* which servers DFS root would we conect to */ {
1597 cERROR(1, 1588 cERROR(1,
1598 ("CIFS mount error: No UNC path (e.g. -o unc=//192.168.1.100/public) specified ")); 1589 ("CIFS mount error: No UNC path (e.g. -o unc=//192.168.1.100/public) specified "));
1599 if(volume_info.UNC) 1590 kfree(volume_info.UNC);
1600 kfree(volume_info.UNC); 1591 kfree(volume_info.password);
1601 if(volume_info.password)
1602 kfree(volume_info.password);
1603 FreeXid(xid); 1592 FreeXid(xid);
1604 return -EINVAL; 1593 return -EINVAL;
1605 } 1594 }
@@ -1612,10 +1601,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1612 cifs_sb->local_nls = load_nls(volume_info.iocharset); 1601 cifs_sb->local_nls = load_nls(volume_info.iocharset);
1613 if(cifs_sb->local_nls == NULL) { 1602 if(cifs_sb->local_nls == NULL) {
1614 cERROR(1,("CIFS mount error: iocharset %s not found",volume_info.iocharset)); 1603 cERROR(1,("CIFS mount error: iocharset %s not found",volume_info.iocharset));
1615 if(volume_info.UNC) 1604 kfree(volume_info.UNC);
1616 kfree(volume_info.UNC); 1605 kfree(volume_info.password);
1617 if(volume_info.password)
1618 kfree(volume_info.password);
1619 FreeXid(xid); 1606 FreeXid(xid);
1620 return -ELIBACC; 1607 return -ELIBACC;
1621 } 1608 }
@@ -1630,10 +1617,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1630 &sin_server6.sin6_addr, 1617 &sin_server6.sin6_addr,
1631 volume_info.username, &srvTcp); 1618 volume_info.username, &srvTcp);
1632 else { 1619 else {
1633 if(volume_info.UNC) 1620 kfree(volume_info.UNC);
1634 kfree(volume_info.UNC); 1621 kfree(volume_info.password);
1635 if(volume_info.password)
1636 kfree(volume_info.password);
1637 FreeXid(xid); 1622 FreeXid(xid);
1638 return -EINVAL; 1623 return -EINVAL;
1639 } 1624 }
@@ -1654,10 +1639,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1654 ("Error connecting to IPv4 socket. Aborting operation")); 1639 ("Error connecting to IPv4 socket. Aborting operation"));
1655 if(csocket != NULL) 1640 if(csocket != NULL)
1656 sock_release(csocket); 1641 sock_release(csocket);
1657 if(volume_info.UNC) 1642 kfree(volume_info.UNC);
1658 kfree(volume_info.UNC); 1643 kfree(volume_info.password);
1659 if(volume_info.password)
1660 kfree(volume_info.password);
1661 FreeXid(xid); 1644 FreeXid(xid);
1662 return rc; 1645 return rc;
1663 } 1646 }
@@ -1666,10 +1649,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1666 if (srvTcp == NULL) { 1649 if (srvTcp == NULL) {
1667 rc = -ENOMEM; 1650 rc = -ENOMEM;
1668 sock_release(csocket); 1651 sock_release(csocket);
1669 if(volume_info.UNC) 1652 kfree(volume_info.UNC);
1670 kfree(volume_info.UNC); 1653 kfree(volume_info.password);
1671 if(volume_info.password)
1672 kfree(volume_info.password);
1673 FreeXid(xid); 1654 FreeXid(xid);
1674 return rc; 1655 return rc;
1675 } else { 1656 } else {
@@ -1692,10 +1673,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1692 if(rc < 0) { 1673 if(rc < 0) {
1693 rc = -ENOMEM; 1674 rc = -ENOMEM;
1694 sock_release(csocket); 1675 sock_release(csocket);
1695 if(volume_info.UNC) 1676 kfree(volume_info.UNC);
1696 kfree(volume_info.UNC); 1677 kfree(volume_info.password);
1697 if(volume_info.password)
1698 kfree(volume_info.password);
1699 FreeXid(xid); 1678 FreeXid(xid);
1700 return rc; 1679 return rc;
1701 } 1680 }
@@ -1710,8 +1689,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1710 if (existingCifsSes) { 1689 if (existingCifsSes) {
1711 pSesInfo = existingCifsSes; 1690 pSesInfo = existingCifsSes;
1712 cFYI(1, ("Existing smb sess found ")); 1691 cFYI(1, ("Existing smb sess found "));
1713 if(volume_info.password) 1692 kfree(volume_info.password);
1714 kfree(volume_info.password);
1715 /* volume_info.UNC freed at end of function */ 1693 /* volume_info.UNC freed at end of function */
1716 } else if (!rc) { 1694 } else if (!rc) {
1717 cFYI(1, ("Existing smb sess not found ")); 1695 cFYI(1, ("Existing smb sess not found "));
@@ -1741,8 +1719,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1741 if(!rc) 1719 if(!rc)
1742 atomic_inc(&srvTcp->socketUseCount); 1720 atomic_inc(&srvTcp->socketUseCount);
1743 } else 1721 } else
1744 if(volume_info.password) 1722 kfree(volume_info.password);
1745 kfree(volume_info.password);
1746 } 1723 }
1747 1724
1748 /* search for existing tcon to this server share */ 1725 /* search for existing tcon to this server share */
@@ -1821,8 +1798,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1821 "", cifs_sb->local_nls, 1798 "", cifs_sb->local_nls,
1822 cifs_sb->mnt_cifs_flags & 1799 cifs_sb->mnt_cifs_flags &
1823 CIFS_MOUNT_MAP_SPECIAL_CHR); 1800 CIFS_MOUNT_MAP_SPECIAL_CHR);
1824 if(volume_info.UNC) 1801 kfree(volume_info.UNC);
1825 kfree(volume_info.UNC);
1826 FreeXid(xid); 1802 FreeXid(xid);
1827 return -ENODEV; 1803 return -ENODEV;
1828 } else { 1804 } else {
@@ -1925,8 +1901,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1925 (in which case it is not needed anymore) but when new sesion is created 1901 (in which case it is not needed anymore) but when new sesion is created
1926 the password ptr is put in the new session structure (in which case the 1902 the password ptr is put in the new session structure (in which case the
1927 password will be freed at unmount time) */ 1903 password will be freed at unmount time) */
1928 if(volume_info.UNC) 1904 kfree(volume_info.UNC);
1929 kfree(volume_info.UNC);
1930 FreeXid(xid); 1905 FreeXid(xid);
1931 return rc; 1906 return rc;
1932} 1907}
@@ -3283,8 +3258,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3283 if ((bcc_ptr + (2 * length)) - 3258 if ((bcc_ptr + (2 * length)) -
3284 pByteArea(smb_buffer_response) <= 3259 pByteArea(smb_buffer_response) <=
3285 BCC(smb_buffer_response)) { 3260 BCC(smb_buffer_response)) {
3286 if(tcon->nativeFileSystem) 3261 kfree(tcon->nativeFileSystem);
3287 kfree(tcon->nativeFileSystem);
3288 tcon->nativeFileSystem = 3262 tcon->nativeFileSystem =
3289 kzalloc(length + 2, GFP_KERNEL); 3263 kzalloc(length + 2, GFP_KERNEL);
3290 cifs_strfromUCS_le(tcon->nativeFileSystem, 3264 cifs_strfromUCS_le(tcon->nativeFileSystem,
@@ -3301,8 +3275,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3301 if ((bcc_ptr + length) - 3275 if ((bcc_ptr + length) -
3302 pByteArea(smb_buffer_response) <= 3276 pByteArea(smb_buffer_response) <=
3303 BCC(smb_buffer_response)) { 3277 BCC(smb_buffer_response)) {
3304 if(tcon->nativeFileSystem) 3278 kfree(tcon->nativeFileSystem);
3305 kfree(tcon->nativeFileSystem);
3306 tcon->nativeFileSystem = 3279 tcon->nativeFileSystem =
3307 kzalloc(length + 1, GFP_KERNEL); 3280 kzalloc(length + 1, GFP_KERNEL);
3308 strncpy(tcon->nativeFileSystem, bcc_ptr, 3281 strncpy(tcon->nativeFileSystem, bcc_ptr,
diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index b43e071fe110..0f99aae33162 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -84,10 +84,8 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode,
84 cifsInode->time = 0; /* will force revalidate to go get info when needed */ 84 cifsInode->time = 0; /* will force revalidate to go get info when needed */
85 85
86cifs_hl_exit: 86cifs_hl_exit:
87 if (fromName) 87 kfree(fromName);
88 kfree(fromName); 88 kfree(toName);
89 if (toName)
90 kfree(toName);
91 FreeXid(xid); 89 FreeXid(xid);
92 return rc; 90 return rc;
93} 91}
@@ -206,8 +204,7 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
206 } 204 }
207 } 205 }
208 206
209 if (full_path) 207 kfree(full_path);
210 kfree(full_path);
211 FreeXid(xid); 208 FreeXid(xid);
212 return rc; 209 return rc;
213} 210}
@@ -253,8 +250,7 @@ cifs_readlink(struct dentry *direntry, char __user *pBuffer, int buflen)
253 len = buflen; 250 len = buflen;
254 tmpbuffer = kmalloc(len,GFP_KERNEL); 251 tmpbuffer = kmalloc(len,GFP_KERNEL);
255 if(tmpbuffer == NULL) { 252 if(tmpbuffer == NULL) {
256 if (full_path) 253 kfree(full_path);
257 kfree(full_path);
258 FreeXid(xid); 254 FreeXid(xid);
259 return -ENOMEM; 255 return -ENOMEM;
260 } 256 }
@@ -303,8 +299,7 @@ cifs_readlink(struct dentry *direntry, char __user *pBuffer, int buflen)
303 strncpy(tmpbuffer, referrals, len-1); 299 strncpy(tmpbuffer, referrals, len-1);
304 } 300 }
305 } 301 }
306 if(referrals) 302 kfree(referrals);
307 kfree(referrals);
308 kfree(tmp_path); 303 kfree(tmp_path);
309} 304}
310 /* BB add code like else decode referrals then memcpy to 305 /* BB add code like else decode referrals then memcpy to
@@ -323,12 +318,8 @@ cifs_readlink(struct dentry *direntry, char __user *pBuffer, int buflen)
323 rc)); 318 rc));
324 } 319 }
325 320
326 if (tmpbuffer) { 321 kfree(tmpbuffer);
327 kfree(tmpbuffer); 322 kfree(full_path);
328 }
329 if (full_path) {
330 kfree(full_path);
331 }
332 FreeXid(xid); 323 FreeXid(xid);
333 return rc; 324 return rc;
334} 325}
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index eba1de917f2a..34a06692e4fa 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -98,14 +98,10 @@ sesInfoFree(struct cifsSesInfo *buf_to_free)
98 atomic_dec(&sesInfoAllocCount); 98 atomic_dec(&sesInfoAllocCount);
99 list_del(&buf_to_free->cifsSessionList); 99 list_del(&buf_to_free->cifsSessionList);
100 write_unlock(&GlobalSMBSeslock); 100 write_unlock(&GlobalSMBSeslock);
101 if (buf_to_free->serverOS) 101 kfree(buf_to_free->serverOS);
102 kfree(buf_to_free->serverOS); 102 kfree(buf_to_free->serverDomain);
103 if (buf_to_free->serverDomain) 103 kfree(buf_to_free->serverNOS);
104 kfree(buf_to_free->serverDomain); 104 kfree(buf_to_free->password);
105 if (buf_to_free->serverNOS)
106 kfree(buf_to_free->serverNOS);
107 if (buf_to_free->password)
108 kfree(buf_to_free->password);
109 kfree(buf_to_free); 105 kfree(buf_to_free);
110} 106}
111 107
@@ -144,8 +140,7 @@ tconInfoFree(struct cifsTconInfo *buf_to_free)
144 atomic_dec(&tconInfoAllocCount); 140 atomic_dec(&tconInfoAllocCount);
145 list_del(&buf_to_free->cifsConnectionList); 141 list_del(&buf_to_free->cifsConnectionList);
146 write_unlock(&GlobalSMBSeslock); 142 write_unlock(&GlobalSMBSeslock);
147 if (buf_to_free->nativeFileSystem) 143 kfree(buf_to_free->nativeFileSystem);
148 kfree(buf_to_free->nativeFileSystem);
149 kfree(buf_to_free); 144 kfree(buf_to_free);
150} 145}
151 146
diff --git a/fs/cifs/xattr.c b/fs/cifs/xattr.c
index c1e02eff1d25..f375f87c7dbd 100644
--- a/fs/cifs/xattr.c
+++ b/fs/cifs/xattr.c
@@ -87,8 +87,7 @@ int cifs_removexattr(struct dentry * direntry, const char * ea_name)
87 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 87 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
88 } 88 }
89remove_ea_exit: 89remove_ea_exit:
90 if (full_path) 90 kfree(full_path);
91 kfree(full_path);
92 FreeXid(xid); 91 FreeXid(xid);
93#endif 92#endif
94 return rc; 93 return rc;
@@ -132,8 +131,7 @@ int cifs_setxattr(struct dentry * direntry, const char * ea_name,
132 returns as xattrs */ 131 returns as xattrs */
133 if(value_size > MAX_EA_VALUE_SIZE) { 132 if(value_size > MAX_EA_VALUE_SIZE) {
134 cFYI(1,("size of EA value too large")); 133 cFYI(1,("size of EA value too large"));
135 if(full_path) 134 kfree(full_path);
136 kfree(full_path);
137 FreeXid(xid); 135 FreeXid(xid);
138 return -EOPNOTSUPP; 136 return -EOPNOTSUPP;
139 } 137 }
@@ -195,8 +193,7 @@ int cifs_setxattr(struct dentry * direntry, const char * ea_name,
195 } 193 }
196 194
197set_ea_exit: 195set_ea_exit:
198 if (full_path) 196 kfree(full_path);
199 kfree(full_path);
200 FreeXid(xid); 197 FreeXid(xid);
201#endif 198#endif
202 return rc; 199 return rc;
@@ -298,8 +295,7 @@ ssize_t cifs_getxattr(struct dentry * direntry, const char * ea_name,
298 rc = -EOPNOTSUPP; 295 rc = -EOPNOTSUPP;
299 296
300get_ea_exit: 297get_ea_exit:
301 if (full_path) 298 kfree(full_path);
302 kfree(full_path);
303 FreeXid(xid); 299 FreeXid(xid);
304#endif 300#endif
305 return rc; 301 return rc;
@@ -345,8 +341,7 @@ ssize_t cifs_listxattr(struct dentry * direntry, char * data, size_t buf_size)
345 cifs_sb->mnt_cifs_flags & 341 cifs_sb->mnt_cifs_flags &
346 CIFS_MOUNT_MAP_SPECIAL_CHR); 342 CIFS_MOUNT_MAP_SPECIAL_CHR);
347 343
348 if (full_path) 344 kfree(full_path);
349 kfree(full_path);
350 FreeXid(xid); 345 FreeXid(xid);
351#endif 346#endif
352 return rc; 347 return rc;
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 43dbcb0b21eb..4909754ea84a 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -2235,7 +2235,8 @@ static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
2235 if (err) 2235 if (err)
2236 err = -EFAULT; 2236 err = -EFAULT;
2237 2237
2238out: if (karg) kfree(karg); 2238out:
2239 kfree(karg);
2239 return err; 2240 return err;
2240} 2241}
2241 2242
diff --git a/fs/dcache.c b/fs/dcache.c
index e90512ed35a4..17e439138681 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -644,7 +644,7 @@ void shrink_dcache_parent(struct dentry * parent)
644 * 644 *
645 * Prune the dentries that are anonymous 645 * Prune the dentries that are anonymous
646 * 646 *
647 * parsing d_hash list does not hlist_for_each_rcu() as it 647 * parsing d_hash list does not hlist_for_each_entry_rcu() as it
648 * done under dcache_lock. 648 * done under dcache_lock.
649 * 649 *
650 */ 650 */
@@ -1043,15 +1043,13 @@ struct dentry * __d_lookup(struct dentry * parent, struct qstr * name)
1043 struct hlist_head *head = d_hash(parent,hash); 1043 struct hlist_head *head = d_hash(parent,hash);
1044 struct dentry *found = NULL; 1044 struct dentry *found = NULL;
1045 struct hlist_node *node; 1045 struct hlist_node *node;
1046 struct dentry *dentry;
1046 1047
1047 rcu_read_lock(); 1048 rcu_read_lock();
1048 1049
1049 hlist_for_each_rcu(node, head) { 1050 hlist_for_each_entry_rcu(dentry, node, head, d_hash) {
1050 struct dentry *dentry;
1051 struct qstr *qstr; 1051 struct qstr *qstr;
1052 1052
1053 dentry = hlist_entry(node, struct dentry, d_hash);
1054
1055 if (dentry->d_name.hash != hash) 1053 if (dentry->d_name.hash != hash)
1056 continue; 1054 continue;
1057 if (dentry->d_parent != parent) 1055 if (dentry->d_parent != parent)
@@ -1123,7 +1121,7 @@ int d_validate(struct dentry *dentry, struct dentry *dparent)
1123 spin_lock(&dcache_lock); 1121 spin_lock(&dcache_lock);
1124 base = d_hash(dparent, dentry->d_name.hash); 1122 base = d_hash(dparent, dentry->d_name.hash);
1125 hlist_for_each(lhp,base) { 1123 hlist_for_each(lhp,base) {
1126 /* hlist_for_each_rcu() not required for d_hash list 1124 /* hlist_for_each_entry_rcu() not required for d_hash list
1127 * as it is parsed under dcache_lock 1125 * as it is parsed under dcache_lock
1128 */ 1126 */
1129 if (dentry == hlist_entry(lhp, struct dentry, d_hash)) { 1127 if (dentry == hlist_entry(lhp, struct dentry, d_hash)) {
diff --git a/fs/devfs/base.c b/fs/devfs/base.c
index 8b679b67e5e0..1274422a5384 100644
--- a/fs/devfs/base.c
+++ b/fs/devfs/base.c
@@ -2738,10 +2738,8 @@ static int devfsd_close(struct inode *inode, struct file *file)
2738 entry = fs_info->devfsd_first_event; 2738 entry = fs_info->devfsd_first_event;
2739 fs_info->devfsd_first_event = NULL; 2739 fs_info->devfsd_first_event = NULL;
2740 fs_info->devfsd_last_event = NULL; 2740 fs_info->devfsd_last_event = NULL;
2741 if (fs_info->devfsd_info) { 2741 kfree(fs_info->devfsd_info);
2742 kfree(fs_info->devfsd_info); 2742 fs_info->devfsd_info = NULL;
2743 fs_info->devfsd_info = NULL;
2744 }
2745 spin_unlock(&fs_info->devfsd_buffer_lock); 2743 spin_unlock(&fs_info->devfsd_buffer_lock);
2746 fs_info->devfsd_pgrp = 0; 2744 fs_info->devfsd_pgrp = 0;
2747 fs_info->devfsd_task = NULL; 2745 fs_info->devfsd_task = NULL;
diff --git a/fs/dquot.c b/fs/dquot.c
index ea7644227a65..05b60283c9c2 100644
--- a/fs/dquot.c
+++ b/fs/dquot.c
@@ -77,6 +77,7 @@
77#include <linux/kmod.h> 77#include <linux/kmod.h>
78#include <linux/namei.h> 78#include <linux/namei.h>
79#include <linux/buffer_head.h> 79#include <linux/buffer_head.h>
80#include <linux/quotaops.h>
80 81
81#include <asm/uaccess.h> 82#include <asm/uaccess.h>
82 83
@@ -1320,13 +1321,11 @@ int vfs_quota_off(struct super_block *sb, int type)
1320 int cnt; 1321 int cnt;
1321 struct quota_info *dqopt = sb_dqopt(sb); 1322 struct quota_info *dqopt = sb_dqopt(sb);
1322 struct inode *toputinode[MAXQUOTAS]; 1323 struct inode *toputinode[MAXQUOTAS];
1323 struct vfsmount *toputmnt[MAXQUOTAS];
1324 1324
1325 /* We need to serialize quota_off() for device */ 1325 /* We need to serialize quota_off() for device */
1326 down(&dqopt->dqonoff_sem); 1326 down(&dqopt->dqonoff_sem);
1327 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1327 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1328 toputinode[cnt] = NULL; 1328 toputinode[cnt] = NULL;
1329 toputmnt[cnt] = NULL;
1330 if (type != -1 && cnt != type) 1329 if (type != -1 && cnt != type)
1331 continue; 1330 continue;
1332 if (!sb_has_quota_enabled(sb, cnt)) 1331 if (!sb_has_quota_enabled(sb, cnt))
@@ -1347,9 +1346,7 @@ int vfs_quota_off(struct super_block *sb, int type)
1347 put_quota_format(dqopt->info[cnt].dqi_format); 1346 put_quota_format(dqopt->info[cnt].dqi_format);
1348 1347
1349 toputinode[cnt] = dqopt->files[cnt]; 1348 toputinode[cnt] = dqopt->files[cnt];
1350 toputmnt[cnt] = dqopt->mnt[cnt];
1351 dqopt->files[cnt] = NULL; 1349 dqopt->files[cnt] = NULL;
1352 dqopt->mnt[cnt] = NULL;
1353 dqopt->info[cnt].dqi_flags = 0; 1350 dqopt->info[cnt].dqi_flags = 0;
1354 dqopt->info[cnt].dqi_igrace = 0; 1351 dqopt->info[cnt].dqi_igrace = 0;
1355 dqopt->info[cnt].dqi_bgrace = 0; 1352 dqopt->info[cnt].dqi_bgrace = 0;
@@ -1357,10 +1354,7 @@ int vfs_quota_off(struct super_block *sb, int type)
1357 } 1354 }
1358 up(&dqopt->dqonoff_sem); 1355 up(&dqopt->dqonoff_sem);
1359 /* Sync the superblock so that buffers with quota data are written to 1356 /* Sync the superblock so that buffers with quota data are written to
1360 * disk (and so userspace sees correct data afterwards). 1357 * disk (and so userspace sees correct data afterwards). */
1361 * The reference to vfsmnt we are still holding protects us from
1362 * umount (we don't have it only when quotas are turned on/off for
1363 * journal replay but in that case we are guarded by the fs anyway). */
1364 if (sb->s_op->sync_fs) 1358 if (sb->s_op->sync_fs)
1365 sb->s_op->sync_fs(sb, 1); 1359 sb->s_op->sync_fs(sb, 1);
1366 sync_blockdev(sb->s_bdev); 1360 sync_blockdev(sb->s_bdev);
@@ -1384,10 +1378,6 @@ int vfs_quota_off(struct super_block *sb, int type)
1384 iput(toputinode[cnt]); 1378 iput(toputinode[cnt]);
1385 } 1379 }
1386 up(&dqopt->dqonoff_sem); 1380 up(&dqopt->dqonoff_sem);
1387 /* We don't hold the reference when we turned on quotas
1388 * just for the journal replay... */
1389 if (toputmnt[cnt])
1390 mntput(toputmnt[cnt]);
1391 } 1381 }
1392 if (sb->s_bdev) 1382 if (sb->s_bdev)
1393 invalidate_bdev(sb->s_bdev, 0); 1383 invalidate_bdev(sb->s_bdev, 0);
@@ -1502,11 +1492,8 @@ int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path)
1502 /* Quota file not on the same filesystem? */ 1492 /* Quota file not on the same filesystem? */
1503 if (nd.mnt->mnt_sb != sb) 1493 if (nd.mnt->mnt_sb != sb)
1504 error = -EXDEV; 1494 error = -EXDEV;
1505 else { 1495 else
1506 error = vfs_quota_on_inode(nd.dentry->d_inode, type, format_id); 1496 error = vfs_quota_on_inode(nd.dentry->d_inode, type, format_id);
1507 if (!error)
1508 sb_dqopt(sb)->mnt[type] = mntget(nd.mnt);
1509 }
1510out_path: 1497out_path:
1511 path_release(&nd); 1498 path_release(&nd);
1512 return error; 1499 return error;
diff --git a/fs/exec.c b/fs/exec.c
index 10d493fea7ce..cd6c574557dc 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -48,6 +48,7 @@
48#include <linux/syscalls.h> 48#include <linux/syscalls.h>
49#include <linux/rmap.h> 49#include <linux/rmap.h>
50#include <linux/acct.h> 50#include <linux/acct.h>
51#include <linux/cn_proc.h>
51 52
52#include <asm/uaccess.h> 53#include <asm/uaccess.h>
53#include <asm/mmu_context.h> 54#include <asm/mmu_context.h>
@@ -1096,6 +1097,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
1096 fput(bprm->file); 1097 fput(bprm->file);
1097 bprm->file = NULL; 1098 bprm->file = NULL;
1098 current->did_exec = 1; 1099 current->did_exec = 1;
1100 proc_exec_connector(current);
1099 return retval; 1101 return retval;
1100 } 1102 }
1101 read_lock(&binfmt_lock); 1103 read_lock(&binfmt_lock);
@@ -1509,7 +1511,7 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)
1509 goto close_fail; 1511 goto close_fail;
1510 if (!file->f_op->write) 1512 if (!file->f_op->write)
1511 goto close_fail; 1513 goto close_fail;
1512 if (do_truncate(file->f_dentry, 0) != 0) 1514 if (do_truncate(file->f_dentry, 0, file) != 0)
1513 goto close_fail; 1515 goto close_fail;
1514 1516
1515 retval = binfmt->core_dump(signr, regs, file); 1517 retval = binfmt->core_dump(signr, regs, file);
diff --git a/fs/ext2/acl.c b/fs/ext2/acl.c
index 213148c36ebe..6af2f4130290 100644
--- a/fs/ext2/acl.c
+++ b/fs/ext2/acl.c
@@ -194,8 +194,7 @@ ext2_get_acl(struct inode *inode, int type)
194 acl = NULL; 194 acl = NULL;
195 else 195 else
196 acl = ERR_PTR(retval); 196 acl = ERR_PTR(retval);
197 if (value) 197 kfree(value);
198 kfree(value);
199 198
200 if (!IS_ERR(acl)) { 199 if (!IS_ERR(acl)) {
201 switch(type) { 200 switch(type) {
@@ -262,8 +261,7 @@ ext2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
262 261
263 error = ext2_xattr_set(inode, name_index, "", value, size, 0); 262 error = ext2_xattr_set(inode, name_index, "", value, size, 0);
264 263
265 if (value) 264 kfree(value);
266 kfree(value);
267 if (!error) { 265 if (!error) {
268 switch(type) { 266 switch(type) {
269 case ACL_TYPE_ACCESS: 267 case ACL_TYPE_ACCESS:
diff --git a/fs/file_table.c b/fs/file_table.c
index 4dc205546547..c3a5e2fd663b 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -35,7 +35,7 @@ static DEFINE_SPINLOCK(filp_count_lock);
35 * context and must be fully threaded - use a local spinlock 35 * context and must be fully threaded - use a local spinlock
36 * to protect files_stat.nr_files 36 * to protect files_stat.nr_files
37 */ 37 */
38void filp_ctor(void * objp, struct kmem_cache_s *cachep, unsigned long cflags) 38void filp_ctor(void *objp, struct kmem_cache *cachep, unsigned long cflags)
39{ 39{
40 if ((cflags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == 40 if ((cflags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
41 SLAB_CTOR_CONSTRUCTOR) { 41 SLAB_CTOR_CONSTRUCTOR) {
@@ -46,7 +46,7 @@ void filp_ctor(void * objp, struct kmem_cache_s *cachep, unsigned long cflags)
46 } 46 }
47} 47}
48 48
49void filp_dtor(void * objp, struct kmem_cache_s *cachep, unsigned long dflags) 49void filp_dtor(void *objp, struct kmem_cache *cachep, unsigned long dflags)
50{ 50{
51 unsigned long flags; 51 unsigned long flags;
52 spin_lock_irqsave(&filp_count_lock, flags); 52 spin_lock_irqsave(&filp_count_lock, flags);
diff --git a/fs/freevxfs/vxfs_extern.h b/fs/freevxfs/vxfs_extern.h
index d8be917f9797..927acf70c591 100644
--- a/fs/freevxfs/vxfs_extern.h
+++ b/fs/freevxfs/vxfs_extern.h
@@ -38,7 +38,7 @@
38 */ 38 */
39 39
40 40
41struct kmem_cache_s; 41struct kmem_cache;
42struct super_block; 42struct super_block;
43struct vxfs_inode_info; 43struct vxfs_inode_info;
44struct inode; 44struct inode;
@@ -51,7 +51,7 @@ extern daddr_t vxfs_bmap1(struct inode *, long);
51extern int vxfs_read_fshead(struct super_block *); 51extern int vxfs_read_fshead(struct super_block *);
52 52
53/* vxfs_inode.c */ 53/* vxfs_inode.c */
54extern struct kmem_cache_s *vxfs_inode_cachep; 54extern struct kmem_cache *vxfs_inode_cachep;
55extern void vxfs_dumpi(struct vxfs_inode_info *, ino_t); 55extern void vxfs_dumpi(struct vxfs_inode_info *, ino_t);
56extern struct inode * vxfs_get_fake_inode(struct super_block *, 56extern struct inode * vxfs_get_fake_inode(struct super_block *,
57 struct vxfs_inode_info *); 57 struct vxfs_inode_info *);
diff --git a/fs/freevxfs/vxfs_inode.c b/fs/freevxfs/vxfs_inode.c
index 9672d2facffe..f544aae9169f 100644
--- a/fs/freevxfs/vxfs_inode.c
+++ b/fs/freevxfs/vxfs_inode.c
@@ -46,15 +46,6 @@ extern struct address_space_operations vxfs_immed_aops;
46 46
47extern struct inode_operations vxfs_immed_symlink_iops; 47extern struct inode_operations vxfs_immed_symlink_iops;
48 48
49static struct file_operations vxfs_file_operations = {
50 .open = generic_file_open,
51 .llseek = generic_file_llseek,
52 .read = generic_file_read,
53 .mmap = generic_file_mmap,
54 .sendfile = generic_file_sendfile,
55};
56
57
58kmem_cache_t *vxfs_inode_cachep; 49kmem_cache_t *vxfs_inode_cachep;
59 50
60 51
@@ -318,7 +309,7 @@ vxfs_read_inode(struct inode *ip)
318 aops = &vxfs_aops; 309 aops = &vxfs_aops;
319 310
320 if (S_ISREG(ip->i_mode)) { 311 if (S_ISREG(ip->i_mode)) {
321 ip->i_fop = &vxfs_file_operations; 312 ip->i_fop = &generic_ro_fops;
322 ip->i_mapping->a_ops = aops; 313 ip->i_mapping->a_ops = aops;
323 } else if (S_ISDIR(ip->i_mode)) { 314 } else if (S_ISDIR(ip->i_mode)) {
324 ip->i_op = &vxfs_dir_inode_ops; 315 ip->i_op = &vxfs_dir_inode_ops;
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index c27f8d4098be..785c7213a54f 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -562,7 +562,7 @@ int write_inode_now(struct inode *inode, int sync)
562 }; 562 };
563 563
564 if (!mapping_cap_writeback_dirty(inode->i_mapping)) 564 if (!mapping_cap_writeback_dirty(inode->i_mapping))
565 return 0; 565 wbc.nr_to_write = 0;
566 566
567 might_sleep(); 567 might_sleep();
568 spin_lock(&inode_lock); 568 spin_lock(&inode_lock);
@@ -606,7 +606,7 @@ EXPORT_SYMBOL(sync_inode);
606 * O_SYNC flag set, to flush dirty writes to disk. 606 * O_SYNC flag set, to flush dirty writes to disk.
607 * 607 *
608 * @what is a bitmask, specifying which part of the inode's data should be 608 * @what is a bitmask, specifying which part of the inode's data should be
609 * written and waited upon: 609 * written and waited upon.
610 * 610 *
611 * OSYNC_DATA: i_mapping's dirty data 611 * OSYNC_DATA: i_mapping's dirty data
612 * OSYNC_METADATA: the buffers at i_mapping->private_list 612 * OSYNC_METADATA: the buffers at i_mapping->private_list
@@ -672,8 +672,9 @@ int writeback_acquire(struct backing_dev_info *bdi)
672 672
673/** 673/**
674 * writeback_in_progress: determine whether there is writeback in progress 674 * writeback_in_progress: determine whether there is writeback in progress
675 * against a backing device.
676 * @bdi: the device's backing_dev_info structure. 675 * @bdi: the device's backing_dev_info structure.
676 *
677 * Determine whether there is writeback in progress against a backing device.
677 */ 678 */
678int writeback_in_progress(struct backing_dev_info *bdi) 679int writeback_in_progress(struct backing_dev_info *bdi)
679{ 680{
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index a6f90a6c754a..8f873e621f41 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -184,6 +184,13 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
184 fuse_putback_request() */ 184 fuse_putback_request() */
185 for (i = 1; i < FUSE_MAX_OUTSTANDING; i++) 185 for (i = 1; i < FUSE_MAX_OUTSTANDING; i++)
186 up(&fc->outstanding_sem); 186 up(&fc->outstanding_sem);
187 } else if (req->in.h.opcode == FUSE_RELEASE && req->inode == NULL) {
188 /* Special case for failed iget in CREATE */
189 u64 nodeid = req->in.h.nodeid;
190 __fuse_get_request(req);
191 fuse_reset_request(req);
192 fuse_send_forget(fc, req, nodeid, 1);
193 putback = 0;
187 } 194 }
188 if (putback) 195 if (putback)
189 fuse_putback_request(fc, req); 196 fuse_putback_request(fc, req);
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 70dba721acab..c045cc70c749 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -13,6 +13,7 @@
13#include <linux/gfp.h> 13#include <linux/gfp.h>
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/namei.h> 15#include <linux/namei.h>
16#include <linux/mount.h>
16 17
17static inline unsigned long time_to_jiffies(unsigned long sec, 18static inline unsigned long time_to_jiffies(unsigned long sec,
18 unsigned long nsec) 19 unsigned long nsec)
@@ -134,6 +135,101 @@ static void fuse_invalidate_entry(struct dentry *entry)
134 entry->d_time = jiffies - 1; 135 entry->d_time = jiffies - 1;
135} 136}
136 137
138static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
139 struct nameidata *nd)
140{
141 int err;
142 struct inode *inode;
143 struct fuse_conn *fc = get_fuse_conn(dir);
144 struct fuse_req *req;
145 struct fuse_open_in inarg;
146 struct fuse_open_out outopen;
147 struct fuse_entry_out outentry;
148 struct fuse_inode *fi;
149 struct fuse_file *ff;
150 struct file *file;
151 int flags = nd->intent.open.flags - 1;
152
153 err = -ENOSYS;
154 if (fc->no_create)
155 goto out;
156
157 err = -ENAMETOOLONG;
158 if (entry->d_name.len > FUSE_NAME_MAX)
159 goto out;
160
161 err = -EINTR;
162 req = fuse_get_request(fc);
163 if (!req)
164 goto out;
165
166 ff = fuse_file_alloc();
167 if (!ff)
168 goto out_put_request;
169
170 flags &= ~O_NOCTTY;
171 memset(&inarg, 0, sizeof(inarg));
172 inarg.flags = flags;
173 inarg.mode = mode;
174 req->in.h.opcode = FUSE_CREATE;
175 req->in.h.nodeid = get_node_id(dir);
176 req->inode = dir;
177 req->in.numargs = 2;
178 req->in.args[0].size = sizeof(inarg);
179 req->in.args[0].value = &inarg;
180 req->in.args[1].size = entry->d_name.len + 1;
181 req->in.args[1].value = entry->d_name.name;
182 req->out.numargs = 2;
183 req->out.args[0].size = sizeof(outentry);
184 req->out.args[0].value = &outentry;
185 req->out.args[1].size = sizeof(outopen);
186 req->out.args[1].value = &outopen;
187 request_send(fc, req);
188 err = req->out.h.error;
189 if (err) {
190 if (err == -ENOSYS)
191 fc->no_create = 1;
192 goto out_free_ff;
193 }
194
195 err = -EIO;
196 if (!S_ISREG(outentry.attr.mode))
197 goto out_free_ff;
198
199 inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
200 &outentry.attr);
201 err = -ENOMEM;
202 if (!inode) {
203 flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
204 ff->fh = outopen.fh;
205 fuse_send_release(fc, ff, outentry.nodeid, NULL, flags, 0);
206 goto out_put_request;
207 }
208 fuse_put_request(fc, req);
209 entry->d_time = time_to_jiffies(outentry.entry_valid,
210 outentry.entry_valid_nsec);
211 fi = get_fuse_inode(inode);
212 fi->i_time = time_to_jiffies(outentry.attr_valid,
213 outentry.attr_valid_nsec);
214
215 d_instantiate(entry, inode);
216 file = lookup_instantiate_filp(nd, entry, generic_file_open);
217 if (IS_ERR(file)) {
218 ff->fh = outopen.fh;
219 fuse_send_release(fc, ff, outentry.nodeid, inode, flags, 0);
220 return PTR_ERR(file);
221 }
222 fuse_finish_open(inode, file, ff, &outopen);
223 return 0;
224
225 out_free_ff:
226 fuse_file_free(ff);
227 out_put_request:
228 fuse_put_request(fc, req);
229 out:
230 return err;
231}
232
137static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req, 233static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
138 struct inode *dir, struct dentry *entry, 234 struct inode *dir, struct dentry *entry,
139 int mode) 235 int mode)
@@ -208,6 +304,12 @@ static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode,
208static int fuse_create(struct inode *dir, struct dentry *entry, int mode, 304static int fuse_create(struct inode *dir, struct dentry *entry, int mode,
209 struct nameidata *nd) 305 struct nameidata *nd)
210{ 306{
307 if (nd && (nd->flags & LOOKUP_CREATE)) {
308 int err = fuse_create_open(dir, entry, mode, nd);
309 if (err != -ENOSYS)
310 return err;
311 /* Fall back on mknod */
312 }
211 return fuse_mknod(dir, entry, mode, 0); 313 return fuse_mknod(dir, entry, mode, 0);
212} 314}
213 315
@@ -461,6 +563,38 @@ static int fuse_revalidate(struct dentry *entry)
461 return fuse_do_getattr(inode); 563 return fuse_do_getattr(inode);
462} 564}
463 565
566static int fuse_access(struct inode *inode, int mask)
567{
568 struct fuse_conn *fc = get_fuse_conn(inode);
569 struct fuse_req *req;
570 struct fuse_access_in inarg;
571 int err;
572
573 if (fc->no_access)
574 return 0;
575
576 req = fuse_get_request(fc);
577 if (!req)
578 return -EINTR;
579
580 memset(&inarg, 0, sizeof(inarg));
581 inarg.mask = mask;
582 req->in.h.opcode = FUSE_ACCESS;
583 req->in.h.nodeid = get_node_id(inode);
584 req->inode = inode;
585 req->in.numargs = 1;
586 req->in.args[0].size = sizeof(inarg);
587 req->in.args[0].value = &inarg;
588 request_send(fc, req);
589 err = req->out.h.error;
590 fuse_put_request(fc, req);
591 if (err == -ENOSYS) {
592 fc->no_access = 1;
593 err = 0;
594 }
595 return err;
596}
597
464static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd) 598static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd)
465{ 599{
466 struct fuse_conn *fc = get_fuse_conn(inode); 600 struct fuse_conn *fc = get_fuse_conn(inode);
@@ -491,11 +625,11 @@ static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd)
491 return err; 625 return err;
492 } else { 626 } else {
493 int mode = inode->i_mode; 627 int mode = inode->i_mode;
494 if ((mask & MAY_WRITE) && IS_RDONLY(inode) &&
495 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
496 return -EROFS;
497 if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO)) 628 if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO))
498 return -EACCES; 629 return -EACCES;
630
631 if (nd && (nd->flags & LOOKUP_ACCESS))
632 return fuse_access(inode, mask);
499 return 0; 633 return 0;
500 } 634 }
501} 635}
@@ -629,29 +763,29 @@ static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync)
629 return file ? fuse_fsync_common(file, de, datasync, 1) : 0; 763 return file ? fuse_fsync_common(file, de, datasync, 1) : 0;
630} 764}
631 765
632static unsigned iattr_to_fattr(struct iattr *iattr, struct fuse_attr *fattr) 766static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
633{ 767{
634 unsigned ivalid = iattr->ia_valid; 768 unsigned ivalid = iattr->ia_valid;
635 unsigned fvalid = 0;
636
637 memset(fattr, 0, sizeof(*fattr));
638 769
639 if (ivalid & ATTR_MODE) 770 if (ivalid & ATTR_MODE)
640 fvalid |= FATTR_MODE, fattr->mode = iattr->ia_mode; 771 arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode;
641 if (ivalid & ATTR_UID) 772 if (ivalid & ATTR_UID)
642 fvalid |= FATTR_UID, fattr->uid = iattr->ia_uid; 773 arg->valid |= FATTR_UID, arg->uid = iattr->ia_uid;
643 if (ivalid & ATTR_GID) 774 if (ivalid & ATTR_GID)
644 fvalid |= FATTR_GID, fattr->gid = iattr->ia_gid; 775 arg->valid |= FATTR_GID, arg->gid = iattr->ia_gid;
645 if (ivalid & ATTR_SIZE) 776 if (ivalid & ATTR_SIZE)
646 fvalid |= FATTR_SIZE, fattr->size = iattr->ia_size; 777 arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size;
647 /* You can only _set_ these together (they may change by themselves) */ 778 /* You can only _set_ these together (they may change by themselves) */
648 if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) { 779 if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) {
649 fvalid |= FATTR_ATIME | FATTR_MTIME; 780 arg->valid |= FATTR_ATIME | FATTR_MTIME;
650 fattr->atime = iattr->ia_atime.tv_sec; 781 arg->atime = iattr->ia_atime.tv_sec;
651 fattr->mtime = iattr->ia_mtime.tv_sec; 782 arg->mtime = iattr->ia_mtime.tv_sec;
783 }
784 if (ivalid & ATTR_FILE) {
785 struct fuse_file *ff = iattr->ia_file->private_data;
786 arg->valid |= FATTR_FH;
787 arg->fh = ff->fh;
652 } 788 }
653
654 return fvalid;
655} 789}
656 790
657static int fuse_setattr(struct dentry *entry, struct iattr *attr) 791static int fuse_setattr(struct dentry *entry, struct iattr *attr)
@@ -686,7 +820,7 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr)
686 return -EINTR; 820 return -EINTR;
687 821
688 memset(&inarg, 0, sizeof(inarg)); 822 memset(&inarg, 0, sizeof(inarg));
689 inarg.valid = iattr_to_fattr(attr, &inarg.attr); 823 iattr_to_fattr(attr, &inarg);
690 req->in.h.opcode = FUSE_SETATTR; 824 req->in.h.opcode = FUSE_SETATTR;
691 req->in.h.nodeid = get_node_id(inode); 825 req->in.h.nodeid = get_node_id(inode);
692 req->inode = inode; 826 req->inode = inode;
@@ -735,7 +869,9 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
735 struct nameidata *nd) 869 struct nameidata *nd)
736{ 870{
737 struct inode *inode; 871 struct inode *inode;
738 int err = fuse_lookup_iget(dir, entry, &inode); 872 int err;
873
874 err = fuse_lookup_iget(dir, entry, &inode);
739 if (err) 875 if (err)
740 return ERR_PTR(err); 876 return ERR_PTR(err);
741 if (inode && S_ISDIR(inode->i_mode)) { 877 if (inode && S_ISDIR(inode->i_mode)) {
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 657ab11c173b..2ca86141d13a 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -14,11 +14,69 @@
14 14
15static struct file_operations fuse_direct_io_file_operations; 15static struct file_operations fuse_direct_io_file_operations;
16 16
17int fuse_open_common(struct inode *inode, struct file *file, int isdir) 17static int fuse_send_open(struct inode *inode, struct file *file, int isdir,
18 struct fuse_open_out *outargp)
18{ 19{
19 struct fuse_conn *fc = get_fuse_conn(inode); 20 struct fuse_conn *fc = get_fuse_conn(inode);
20 struct fuse_req *req;
21 struct fuse_open_in inarg; 21 struct fuse_open_in inarg;
22 struct fuse_req *req;
23 int err;
24
25 req = fuse_get_request(fc);
26 if (!req)
27 return -EINTR;
28
29 memset(&inarg, 0, sizeof(inarg));
30 inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
31 req->in.h.opcode = isdir ? FUSE_OPENDIR : FUSE_OPEN;
32 req->in.h.nodeid = get_node_id(inode);
33 req->inode = inode;
34 req->in.numargs = 1;
35 req->in.args[0].size = sizeof(inarg);
36 req->in.args[0].value = &inarg;
37 req->out.numargs = 1;
38 req->out.args[0].size = sizeof(*outargp);
39 req->out.args[0].value = outargp;
40 request_send(fc, req);
41 err = req->out.h.error;
42 fuse_put_request(fc, req);
43
44 return err;
45}
46
47struct fuse_file *fuse_file_alloc(void)
48{
49 struct fuse_file *ff;
50 ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL);
51 if (ff) {
52 ff->release_req = fuse_request_alloc();
53 if (!ff->release_req) {
54 kfree(ff);
55 ff = NULL;
56 }
57 }
58 return ff;
59}
60
61void fuse_file_free(struct fuse_file *ff)
62{
63 fuse_request_free(ff->release_req);
64 kfree(ff);
65}
66
67void fuse_finish_open(struct inode *inode, struct file *file,
68 struct fuse_file *ff, struct fuse_open_out *outarg)
69{
70 if (outarg->open_flags & FOPEN_DIRECT_IO)
71 file->f_op = &fuse_direct_io_file_operations;
72 if (!(outarg->open_flags & FOPEN_KEEP_CACHE))
73 invalidate_inode_pages(inode->i_mapping);
74 ff->fh = outarg->fh;
75 file->private_data = ff;
76}
77
78int fuse_open_common(struct inode *inode, struct file *file, int isdir)
79{
22 struct fuse_open_out outarg; 80 struct fuse_open_out outarg;
23 struct fuse_file *ff; 81 struct fuse_file *ff;
24 int err; 82 int err;
@@ -34,73 +92,53 @@ int fuse_open_common(struct inode *inode, struct file *file, int isdir)
34 /* If opening the root node, no lookup has been performed on 92 /* If opening the root node, no lookup has been performed on
35 it, so the attributes must be refreshed */ 93 it, so the attributes must be refreshed */
36 if (get_node_id(inode) == FUSE_ROOT_ID) { 94 if (get_node_id(inode) == FUSE_ROOT_ID) {
37 int err = fuse_do_getattr(inode); 95 err = fuse_do_getattr(inode);
38 if (err) 96 if (err)
39 return err; 97 return err;
40 } 98 }
41 99
42 req = fuse_get_request(fc); 100 ff = fuse_file_alloc();
43 if (!req)
44 return -EINTR;
45
46 err = -ENOMEM;
47 ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL);
48 if (!ff) 101 if (!ff)
49 goto out_put_request; 102 return -ENOMEM;
50 103
51 ff->release_req = fuse_request_alloc(); 104 err = fuse_send_open(inode, file, isdir, &outarg);
52 if (!ff->release_req) { 105 if (err)
53 kfree(ff); 106 fuse_file_free(ff);
54 goto out_put_request; 107 else {
55 } 108 if (isdir)
56 109 outarg.open_flags &= ~FOPEN_DIRECT_IO;
57 memset(&inarg, 0, sizeof(inarg)); 110 fuse_finish_open(inode, file, ff, &outarg);
58 inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
59 req->in.h.opcode = isdir ? FUSE_OPENDIR : FUSE_OPEN;
60 req->in.h.nodeid = get_node_id(inode);
61 req->inode = inode;
62 req->in.numargs = 1;
63 req->in.args[0].size = sizeof(inarg);
64 req->in.args[0].value = &inarg;
65 req->out.numargs = 1;
66 req->out.args[0].size = sizeof(outarg);
67 req->out.args[0].value = &outarg;
68 request_send(fc, req);
69 err = req->out.h.error;
70 if (err) {
71 fuse_request_free(ff->release_req);
72 kfree(ff);
73 } else {
74 if (!isdir && (outarg.open_flags & FOPEN_DIRECT_IO))
75 file->f_op = &fuse_direct_io_file_operations;
76 if (!(outarg.open_flags & FOPEN_KEEP_CACHE))
77 invalidate_inode_pages(inode->i_mapping);
78 ff->fh = outarg.fh;
79 file->private_data = ff;
80 } 111 }
81 112
82 out_put_request:
83 fuse_put_request(fc, req);
84 return err; 113 return err;
85} 114}
86 115
87int fuse_release_common(struct inode *inode, struct file *file, int isdir) 116void fuse_send_release(struct fuse_conn *fc, struct fuse_file *ff,
117 u64 nodeid, struct inode *inode, int flags, int isdir)
88{ 118{
89 struct fuse_conn *fc = get_fuse_conn(inode); 119 struct fuse_req * req = ff->release_req;
90 struct fuse_file *ff = file->private_data;
91 struct fuse_req *req = ff->release_req;
92 struct fuse_release_in *inarg = &req->misc.release_in; 120 struct fuse_release_in *inarg = &req->misc.release_in;
93 121
94 inarg->fh = ff->fh; 122 inarg->fh = ff->fh;
95 inarg->flags = file->f_flags & ~O_EXCL; 123 inarg->flags = flags;
96 req->in.h.opcode = isdir ? FUSE_RELEASEDIR : FUSE_RELEASE; 124 req->in.h.opcode = isdir ? FUSE_RELEASEDIR : FUSE_RELEASE;
97 req->in.h.nodeid = get_node_id(inode); 125 req->in.h.nodeid = nodeid;
98 req->inode = inode; 126 req->inode = inode;
99 req->in.numargs = 1; 127 req->in.numargs = 1;
100 req->in.args[0].size = sizeof(struct fuse_release_in); 128 req->in.args[0].size = sizeof(struct fuse_release_in);
101 req->in.args[0].value = inarg; 129 req->in.args[0].value = inarg;
102 request_send_background(fc, req); 130 request_send_background(fc, req);
103 kfree(ff); 131 kfree(ff);
132}
133
134int fuse_release_common(struct inode *inode, struct file *file, int isdir)
135{
136 struct fuse_file *ff = file->private_data;
137 if (ff) {
138 struct fuse_conn *fc = get_fuse_conn(inode);
139 u64 nodeid = get_node_id(inode);
140 fuse_send_release(fc, ff, nodeid, inode, file->f_flags, isdir);
141 }
104 142
105 /* Return value is ignored by VFS */ 143 /* Return value is ignored by VFS */
106 return 0; 144 return 0;
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 5cb456f572c1..0ea5301f86be 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -266,6 +266,12 @@ struct fuse_conn {
266 /** Is removexattr not implemented by fs? */ 266 /** Is removexattr not implemented by fs? */
267 unsigned no_removexattr : 1; 267 unsigned no_removexattr : 1;
268 268
269 /** Is access not implemented by fs? */
270 unsigned no_access : 1;
271
272 /** Is create not implemented by fs? */
273 unsigned no_create : 1;
274
269 /** Backing dev info */ 275 /** Backing dev info */
270 struct backing_dev_info bdi; 276 struct backing_dev_info bdi;
271}; 277};
@@ -337,6 +343,17 @@ size_t fuse_send_read_common(struct fuse_req *req, struct file *file,
337 */ 343 */
338int fuse_open_common(struct inode *inode, struct file *file, int isdir); 344int fuse_open_common(struct inode *inode, struct file *file, int isdir);
339 345
346struct fuse_file *fuse_file_alloc(void);
347void fuse_file_free(struct fuse_file *ff);
348void fuse_finish_open(struct inode *inode, struct file *file,
349 struct fuse_file *ff, struct fuse_open_out *outarg);
350
351/**
352 * Send a RELEASE request
353 */
354void fuse_send_release(struct fuse_conn *fc, struct fuse_file *ff,
355 u64 nodeid, struct inode *inode, int flags, int isdir);
356
340/** 357/**
341 * Send RELEASE or RELEASEDIR request 358 * Send RELEASE or RELEASEDIR request
342 */ 359 */
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index dd7113106269..a33fb1d91373 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -294,8 +294,7 @@ static void hostfs_delete_inode(struct inode *inode)
294 294
295static void hostfs_destroy_inode(struct inode *inode) 295static void hostfs_destroy_inode(struct inode *inode)
296{ 296{
297 if(HOSTFS_I(inode)->host_filename) 297 kfree(HOSTFS_I(inode)->host_filename);
298 kfree(HOSTFS_I(inode)->host_filename);
299 298
300 /*XXX: This should not happen, probably. The check is here for 299 /*XXX: This should not happen, probably. The check is here for
301 * additional safety.*/ 300 * additional safety.*/
diff --git a/fs/hpfs/dnode.c b/fs/hpfs/dnode.c
index 1d21307730a8..229ff2fb1809 100644
--- a/fs/hpfs/dnode.c
+++ b/fs/hpfs/dnode.c
@@ -244,12 +244,12 @@ static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
244 go_up: 244 go_up:
245 if (namelen >= 256) { 245 if (namelen >= 256) {
246 hpfs_error(i->i_sb, "hpfs_add_to_dnode: namelen == %d", namelen); 246 hpfs_error(i->i_sb, "hpfs_add_to_dnode: namelen == %d", namelen);
247 if (nd) kfree(nd); 247 kfree(nd);
248 kfree(nname); 248 kfree(nname);
249 return 1; 249 return 1;
250 } 250 }
251 if (!(d = hpfs_map_dnode(i->i_sb, dno, &qbh))) { 251 if (!(d = hpfs_map_dnode(i->i_sb, dno, &qbh))) {
252 if (nd) kfree(nd); 252 kfree(nd);
253 kfree(nname); 253 kfree(nname);
254 return 1; 254 return 1;
255 } 255 }
@@ -257,7 +257,7 @@ static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
257 if (hpfs_sb(i->i_sb)->sb_chk) 257 if (hpfs_sb(i->i_sb)->sb_chk)
258 if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "hpfs_add_to_dnode")) { 258 if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "hpfs_add_to_dnode")) {
259 hpfs_brelse4(&qbh); 259 hpfs_brelse4(&qbh);
260 if (nd) kfree(nd); 260 kfree(nd);
261 kfree(nname); 261 kfree(nname);
262 return 1; 262 return 1;
263 } 263 }
@@ -270,7 +270,7 @@ static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
270 for_all_poss(i, hpfs_pos_subst, 5, t + 1); 270 for_all_poss(i, hpfs_pos_subst, 5, t + 1);
271 hpfs_mark_4buffers_dirty(&qbh); 271 hpfs_mark_4buffers_dirty(&qbh);
272 hpfs_brelse4(&qbh); 272 hpfs_brelse4(&qbh);
273 if (nd) kfree(nd); 273 kfree(nd);
274 kfree(nname); 274 kfree(nname);
275 return 0; 275 return 0;
276 } 276 }
diff --git a/fs/hpfs/super.c b/fs/hpfs/super.c
index 8eefa6366db7..63e88d7e2c3b 100644
--- a/fs/hpfs/super.c
+++ b/fs/hpfs/super.c
@@ -75,7 +75,7 @@ void hpfs_error(struct super_block *s, char *m,...)
75 } else if (s->s_flags & MS_RDONLY) printk("; going on - but anything won't be destroyed because it's read-only\n"); 75 } else if (s->s_flags & MS_RDONLY) printk("; going on - but anything won't be destroyed because it's read-only\n");
76 else printk("; corrupted filesystem mounted read/write - your computer will explode within 20 seconds ... but you wanted it so!\n"); 76 else printk("; corrupted filesystem mounted read/write - your computer will explode within 20 seconds ... but you wanted it so!\n");
77 } else printk("\n"); 77 } else printk("\n");
78 if (buf) kfree(buf); 78 kfree(buf);
79 hpfs_sb(s)->sb_was_error = 1; 79 hpfs_sb(s)->sb_was_error = 1;
80} 80}
81 81
@@ -102,8 +102,8 @@ int hpfs_stop_cycles(struct super_block *s, int key, int *c1, int *c2,
102static void hpfs_put_super(struct super_block *s) 102static void hpfs_put_super(struct super_block *s)
103{ 103{
104 struct hpfs_sb_info *sbi = hpfs_sb(s); 104 struct hpfs_sb_info *sbi = hpfs_sb(s);
105 if (sbi->sb_cp_table) kfree(sbi->sb_cp_table); 105 kfree(sbi->sb_cp_table);
106 if (sbi->sb_bmp_dir) kfree(sbi->sb_bmp_dir); 106 kfree(sbi->sb_bmp_dir);
107 unmark_dirty(s); 107 unmark_dirty(s);
108 s->s_fs_info = NULL; 108 s->s_fs_info = NULL;
109 kfree(sbi); 109 kfree(sbi);
@@ -654,8 +654,8 @@ bail3: brelse(bh1);
654bail2: brelse(bh0); 654bail2: brelse(bh0);
655bail1: 655bail1:
656bail0: 656bail0:
657 if (sbi->sb_bmp_dir) kfree(sbi->sb_bmp_dir); 657 kfree(sbi->sb_bmp_dir);
658 if (sbi->sb_cp_table) kfree(sbi->sb_cp_table); 658 kfree(sbi->sb_cp_table);
659 s->s_fs_info = NULL; 659 s->s_fs_info = NULL;
660 kfree(sbi); 660 kfree(sbi);
661 return -EINVAL; 661 return -EINVAL;
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index 1652de1b6cb9..298f08be22d4 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -855,8 +855,7 @@ root_found:
855 if (opt.check == 'r') table++; 855 if (opt.check == 'r') table++;
856 s->s_root->d_op = &isofs_dentry_ops[table]; 856 s->s_root->d_op = &isofs_dentry_ops[table];
857 857
858 if (opt.iocharset) 858 kfree(opt.iocharset);
859 kfree(opt.iocharset);
860 859
861 return 0; 860 return 0;
862 861
@@ -895,8 +894,7 @@ out_unknown_format:
895out_freebh: 894out_freebh:
896 brelse(bh); 895 brelse(bh);
897out_freesbi: 896out_freesbi:
898 if (opt.iocharset) 897 kfree(opt.iocharset);
899 kfree(opt.iocharset);
900 kfree(sbi); 898 kfree(sbi);
901 s->s_fs_info = NULL; 899 s->s_fs_info = NULL;
902 return -EINVAL; 900 return -EINVAL;
@@ -1164,8 +1162,7 @@ out_nomem:
1164 1162
1165out_noread: 1163out_noread:
1166 printk(KERN_INFO "ISOFS: unable to read i-node block %lu\n", block); 1164 printk(KERN_INFO "ISOFS: unable to read i-node block %lu\n", block);
1167 if (tmpde) 1165 kfree(tmpde);
1168 kfree(tmpde);
1169 return -EIO; 1166 return -EIO;
1170 1167
1171out_toomany: 1168out_toomany:
@@ -1334,8 +1331,7 @@ static void isofs_read_inode(struct inode *inode)
1334 init_special_inode(inode, inode->i_mode, inode->i_rdev); 1331 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1335 1332
1336out: 1333out:
1337 if (tmpde) 1334 kfree(tmpde);
1338 kfree(tmpde);
1339 if (bh) 1335 if (bh)
1340 brelse(bh); 1336 brelse(bh);
1341 return; 1337 return;
diff --git a/fs/jbd/commit.c b/fs/jbd/commit.c
index 2a3e310f79ef..002ad2bbc769 100644
--- a/fs/jbd/commit.c
+++ b/fs/jbd/commit.c
@@ -261,10 +261,8 @@ void journal_commit_transaction(journal_t *journal)
261 struct buffer_head *bh = jh2bh(jh); 261 struct buffer_head *bh = jh2bh(jh);
262 262
263 jbd_lock_bh_state(bh); 263 jbd_lock_bh_state(bh);
264 if (jh->b_committed_data) { 264 kfree(jh->b_committed_data);
265 kfree(jh->b_committed_data); 265 jh->b_committed_data = NULL;
266 jh->b_committed_data = NULL;
267 }
268 jbd_unlock_bh_state(bh); 266 jbd_unlock_bh_state(bh);
269 } 267 }
270 journal_refile_buffer(journal, jh); 268 journal_refile_buffer(journal, jh);
diff --git a/fs/jbd/recovery.c b/fs/jbd/recovery.c
index 103c34e4fb28..80d7f53fd0a7 100644
--- a/fs/jbd/recovery.c
+++ b/fs/jbd/recovery.c
@@ -210,7 +210,7 @@ do { \
210} while (0) 210} while (0)
211 211
212/** 212/**
213 * int journal_recover(journal_t *journal) - recovers a on-disk journal 213 * journal_recover - recovers a on-disk journal
214 * @journal: the journal to recover 214 * @journal: the journal to recover
215 * 215 *
216 * The primary function for recovering the log contents when mounting a 216 * The primary function for recovering the log contents when mounting a
@@ -266,7 +266,7 @@ int journal_recover(journal_t *journal)
266} 266}
267 267
268/** 268/**
269 * int journal_skip_recovery() - Start journal and wipe exiting records 269 * journal_skip_recovery - Start journal and wipe exiting records
270 * @journal: journal to startup 270 * @journal: journal to startup
271 * 271 *
272 * Locate any valid recovery information from the journal and set up the 272 * Locate any valid recovery information from the journal and set up the
diff --git a/fs/jbd/transaction.c b/fs/jbd/transaction.c
index 13cb05bf6048..429f4b263cf1 100644
--- a/fs/jbd/transaction.c
+++ b/fs/jbd/transaction.c
@@ -227,8 +227,7 @@ repeat_locked:
227 spin_unlock(&transaction->t_handle_lock); 227 spin_unlock(&transaction->t_handle_lock);
228 spin_unlock(&journal->j_state_lock); 228 spin_unlock(&journal->j_state_lock);
229out: 229out:
230 if (new_transaction) 230 kfree(new_transaction);
231 kfree(new_transaction);
232 return ret; 231 return ret;
233} 232}
234 233
@@ -725,8 +724,7 @@ done:
725 journal_cancel_revoke(handle, jh); 724 journal_cancel_revoke(handle, jh);
726 725
727out: 726out:
728 if (frozen_buffer) 727 kfree(frozen_buffer);
729 kfree(frozen_buffer);
730 728
731 JBUFFER_TRACE(jh, "exit"); 729 JBUFFER_TRACE(jh, "exit");
732 return error; 730 return error;
@@ -905,8 +903,7 @@ repeat:
905 jbd_unlock_bh_state(bh); 903 jbd_unlock_bh_state(bh);
906out: 904out:
907 journal_put_journal_head(jh); 905 journal_put_journal_head(jh);
908 if (committed_data) 906 kfree(committed_data);
909 kfree(committed_data);
910 return err; 907 return err;
911} 908}
912 909
diff --git a/fs/jffs/intrep.c b/fs/jffs/intrep.c
index 27f199e94cfc..b2e95421d932 100644
--- a/fs/jffs/intrep.c
+++ b/fs/jffs/intrep.c
@@ -462,7 +462,7 @@ jffs_checksum_flash(struct mtd_info *mtd, loff_t start, int size, __u32 *result)
462 } 462 }
463 463
464 /* Free read buffer */ 464 /* Free read buffer */
465 kfree (read_buf); 465 kfree(read_buf);
466 466
467 /* Return result */ 467 /* Return result */
468 D3(printk("checksum result: 0x%08x\n", sum)); 468 D3(printk("checksum result: 0x%08x\n", sum));
@@ -1011,12 +1011,12 @@ jffs_scan_flash(struct jffs_control *c)
1011 offset , fmc->sector_size); 1011 offset , fmc->sector_size);
1012 1012
1013 flash_safe_release(fmc->mtd); 1013 flash_safe_release(fmc->mtd);
1014 kfree (read_buf); 1014 kfree(read_buf);
1015 return -1; /* bad, bad, bad! */ 1015 return -1; /* bad, bad, bad! */
1016 1016
1017 } 1017 }
1018 flash_safe_release(fmc->mtd); 1018 flash_safe_release(fmc->mtd);
1019 kfree (read_buf); 1019 kfree(read_buf);
1020 1020
1021 return -EAGAIN; /* erased offending sector. Try mount one more time please. */ 1021 return -EAGAIN; /* erased offending sector. Try mount one more time please. */
1022 } 1022 }
@@ -1112,7 +1112,7 @@ jffs_scan_flash(struct jffs_control *c)
1112 if (!node) { 1112 if (!node) {
1113 if (!(node = jffs_alloc_node())) { 1113 if (!(node = jffs_alloc_node())) {
1114 /* Free read buffer */ 1114 /* Free read buffer */
1115 kfree (read_buf); 1115 kfree(read_buf);
1116 1116
1117 /* Release the flash device */ 1117 /* Release the flash device */
1118 flash_safe_release(fmc->mtd); 1118 flash_safe_release(fmc->mtd);
@@ -1269,7 +1269,7 @@ jffs_scan_flash(struct jffs_control *c)
1269 DJM(no_jffs_node--); 1269 DJM(no_jffs_node--);
1270 1270
1271 /* Free read buffer */ 1271 /* Free read buffer */
1272 kfree (read_buf); 1272 kfree(read_buf);
1273 1273
1274 /* Release the flash device */ 1274 /* Release the flash device */
1275 flash_safe_release(fmc->mtd); 1275 flash_safe_release(fmc->mtd);
@@ -1296,7 +1296,7 @@ jffs_scan_flash(struct jffs_control *c)
1296 flash_safe_release(fmc->flash_part); 1296 flash_safe_release(fmc->flash_part);
1297 1297
1298 /* Free read buffer */ 1298 /* Free read buffer */
1299 kfree (read_buf); 1299 kfree(read_buf);
1300 1300
1301 return -ENOMEM; 1301 return -ENOMEM;
1302 } 1302 }
@@ -1324,7 +1324,7 @@ jffs_scan_flash(struct jffs_control *c)
1324 jffs_build_end(fmc); 1324 jffs_build_end(fmc);
1325 1325
1326 /* Free read buffer */ 1326 /* Free read buffer */
1327 kfree (read_buf); 1327 kfree(read_buf);
1328 1328
1329 if(!num_free_space){ 1329 if(!num_free_space){
1330 printk(KERN_WARNING "jffs_scan_flash(): Did not find even a single " 1330 printk(KERN_WARNING "jffs_scan_flash(): Did not find even a single "
@@ -1747,9 +1747,7 @@ jffs_find_child(struct jffs_file *dir, const char *name, int len)
1747 } 1747 }
1748 printk("jffs_find_child(): Didn't find the file \"%s\".\n", 1748 printk("jffs_find_child(): Didn't find the file \"%s\".\n",
1749 (copy ? copy : "")); 1749 (copy ? copy : ""));
1750 if (copy) { 1750 kfree(copy);
1751 kfree(copy);
1752 }
1753 }); 1751 });
1754 1752
1755 return f; 1753 return f;
diff --git a/fs/jffs2/Makefile b/fs/jffs2/Makefile
index f1afe681ecd6..77dc5561a04e 100644
--- a/fs/jffs2/Makefile
+++ b/fs/jffs2/Makefile
@@ -1,7 +1,7 @@
1# 1#
2# Makefile for the Linux Journalling Flash File System v2 (JFFS2) 2# Makefile for the Linux Journalling Flash File System v2 (JFFS2)
3# 3#
4# $Id: Makefile.common,v 1.9 2005/02/09 09:23:53 pavlov Exp $ 4# $Id: Makefile.common,v 1.11 2005/09/07 08:34:53 havasi Exp $
5# 5#
6 6
7obj-$(CONFIG_JFFS2_FS) += jffs2.o 7obj-$(CONFIG_JFFS2_FS) += jffs2.o
@@ -9,9 +9,10 @@ obj-$(CONFIG_JFFS2_FS) += jffs2.o
9jffs2-y := compr.o dir.o file.o ioctl.o nodelist.o malloc.o 9jffs2-y := compr.o dir.o file.o ioctl.o nodelist.o malloc.o
10jffs2-y += read.o nodemgmt.o readinode.o write.o scan.o gc.o 10jffs2-y += read.o nodemgmt.o readinode.o write.o scan.o gc.o
11jffs2-y += symlink.o build.o erase.o background.o fs.o writev.o 11jffs2-y += symlink.o build.o erase.o background.o fs.o writev.o
12jffs2-y += super.o 12jffs2-y += super.o debug.o
13 13
14jffs2-$(CONFIG_JFFS2_FS_WRITEBUFFER) += wbuf.o 14jffs2-$(CONFIG_JFFS2_FS_WRITEBUFFER) += wbuf.o
15jffs2-$(CONFIG_JFFS2_RUBIN) += compr_rubin.o 15jffs2-$(CONFIG_JFFS2_RUBIN) += compr_rubin.o
16jffs2-$(CONFIG_JFFS2_RTIME) += compr_rtime.o 16jffs2-$(CONFIG_JFFS2_RTIME) += compr_rtime.o
17jffs2-$(CONFIG_JFFS2_ZLIB) += compr_zlib.o 17jffs2-$(CONFIG_JFFS2_ZLIB) += compr_zlib.o
18jffs2-$(CONFIG_JFFS2_SUMMARY) += summary.o
diff --git a/fs/jffs2/TODO b/fs/jffs2/TODO
index 2bff82fd221f..d0e23b26fa50 100644
--- a/fs/jffs2/TODO
+++ b/fs/jffs2/TODO
@@ -1,5 +1,11 @@
1$Id: TODO,v 1.10 2002/09/09 16:31:21 dwmw2 Exp $ 1$Id: TODO,v 1.18 2005/09/22 11:24:56 dedekind Exp $
2 2
3 - support asynchronous operation -- add a per-fs 'reserved_space' count,
4 let each outstanding write reserve the _maximum_ amount of physical
5 space it could take. Let GC flush the outstanding writes because the
6 reservations will necessarily be pessimistic. With this we could even
7 do shared writable mmap, if we can have a fs hook for do_wp_page() to
8 make the reservation.
3 - disable compression in commit_write()? 9 - disable compression in commit_write()?
4 - fine-tune the allocation / GC thresholds 10 - fine-tune the allocation / GC thresholds
5 - chattr support - turning on/off and tuning compression per-inode 11 - chattr support - turning on/off and tuning compression per-inode
@@ -11,26 +17,15 @@ $Id: TODO,v 1.10 2002/09/09 16:31:21 dwmw2 Exp $
11 - test, test, test 17 - test, test, test
12 18
13 - NAND flash support: 19 - NAND flash support:
14 - flush_wbuf using GC to fill it, don't just pad. 20 - almost done :)
15 - Deal with write errors. Data don't get lost - we just have to write 21 - use bad block check instead of the hardwired byte check
16 the affected node(s) out again somewhere else.
17 - make fsync flush only if actually required
18 - make sys_sync() work.
19 - reboot notifier
20 - timed flush of old wbuf
21 - fix magical second arg of jffs2_flush_wbuf(). Split into two or more functions instead.
22
23 22
24 - Optimisations: 23 - Optimisations:
25 - Stop GC from decompressing and immediately recompressing nodes which could 24 - Split writes so they go to two separate blocks rather than just c->nextblock.
26 just be copied intact. (We now keep track of REF_PRISTINE flag. Easy now.) 25 By writing _new_ nodes to one block, and garbage-collected REF_PRISTINE
27 - Furthermore, in the case where it could be copied intact we don't even need 26 nodes to a different one, we can separate clean nodes from those which
28 to call iget() for it -- if we use (raw_node_raw->flash_offset & 2) as a flag 27 are likely to become dirty, and end up with blocks which are each far
29 to show a node can be copied intact and it's _not_ in icache, we could just do 28 closer to 100% or 0% clean, hence speeding up later GC progress dramatically.
30 it, fix up the next_in_ino list and move on. We would need a way to find out
31 _whether_ it's in icache though -- if it's in icache we also need to do the
32 fragment lists, etc. P'raps a flag or pointer in the jffs2_inode_cache could
33 help. (We have half of this now.)
34 - Stop keeping name in-core with struct jffs2_full_dirent. If we keep the hash in 29 - Stop keeping name in-core with struct jffs2_full_dirent. If we keep the hash in
35 the full dirent, we only need to go to the flash in lookup() when we think we've 30 the full dirent, we only need to go to the flash in lookup() when we think we've
36 got a match, and in readdir(). 31 got a match, and in readdir().
@@ -38,3 +33,8 @@ $Id: TODO,v 1.10 2002/09/09 16:31:21 dwmw2 Exp $
38 - Remove totlen from jffs2_raw_node_ref? Need to have totlen passed into 33 - Remove totlen from jffs2_raw_node_ref? Need to have totlen passed into
39 jffs2_mark_node_obsolete(). Can all callers work it out? 34 jffs2_mark_node_obsolete(). Can all callers work it out?
40 - Remove size from jffs2_raw_node_frag. 35 - Remove size from jffs2_raw_node_frag.
36
37dedekind:
381. __jffs2_flush_wbuf() has a strange 'pad' parameter. Eliminate.
392. get_sb()->build_fs()->scan() path... Why get_sb() removes scan()'s crap in
40 case of failure? scan() does not clean everything. Fix.
diff --git a/fs/jffs2/background.c b/fs/jffs2/background.c
index 8210ac16a368..7b77a9541125 100644
--- a/fs/jffs2/background.c
+++ b/fs/jffs2/background.c
@@ -51,7 +51,7 @@ int jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c)
51 D1(printk(KERN_DEBUG "JFFS2: Garbage collect thread is pid %d\n", pid)); 51 D1(printk(KERN_DEBUG "JFFS2: Garbage collect thread is pid %d\n", pid));
52 wait_for_completion(&c->gc_thread_start); 52 wait_for_completion(&c->gc_thread_start);
53 } 53 }
54 54
55 return ret; 55 return ret;
56} 56}
57 57
@@ -101,7 +101,7 @@ static int jffs2_garbage_collect_thread(void *_c)
101 101
102 cond_resched(); 102 cond_resched();
103 103
104 /* Put_super will send a SIGKILL and then wait on the sem. 104 /* Put_super will send a SIGKILL and then wait on the sem.
105 */ 105 */
106 while (signal_pending(current)) { 106 while (signal_pending(current)) {
107 siginfo_t info; 107 siginfo_t info;
diff --git a/fs/jffs2/build.c b/fs/jffs2/build.c
index 97dc39796e2c..fff108bb118b 100644
--- a/fs/jffs2/build.c
+++ b/fs/jffs2/build.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: build.c,v 1.71 2005/07/12 16:37:08 dedekind Exp $ 10 * $Id: build.c,v 1.85 2005/11/07 11:14:38 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -18,7 +18,8 @@
18#include <linux/mtd/mtd.h> 18#include <linux/mtd/mtd.h>
19#include "nodelist.h" 19#include "nodelist.h"
20 20
21static void jffs2_build_remove_unlinked_inode(struct jffs2_sb_info *, struct jffs2_inode_cache *, struct jffs2_full_dirent **); 21static void jffs2_build_remove_unlinked_inode(struct jffs2_sb_info *,
22 struct jffs2_inode_cache *, struct jffs2_full_dirent **);
22 23
23static inline struct jffs2_inode_cache * 24static inline struct jffs2_inode_cache *
24first_inode_chain(int *i, struct jffs2_sb_info *c) 25first_inode_chain(int *i, struct jffs2_sb_info *c)
@@ -46,11 +47,12 @@ next_inode(int *i, struct jffs2_inode_cache *ic, struct jffs2_sb_info *c)
46 ic = next_inode(&i, ic, (c))) 47 ic = next_inode(&i, ic, (c)))
47 48
48 49
49static inline void jffs2_build_inode_pass1(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic) 50static inline void jffs2_build_inode_pass1(struct jffs2_sb_info *c,
51 struct jffs2_inode_cache *ic)
50{ 52{
51 struct jffs2_full_dirent *fd; 53 struct jffs2_full_dirent *fd;
52 54
53 D1(printk(KERN_DEBUG "jffs2_build_inode building directory inode #%u\n", ic->ino)); 55 dbg_fsbuild("building directory inode #%u\n", ic->ino);
54 56
55 /* For each child, increase nlink */ 57 /* For each child, increase nlink */
56 for(fd = ic->scan_dents; fd; fd = fd->next) { 58 for(fd = ic->scan_dents; fd; fd = fd->next) {
@@ -58,26 +60,23 @@ static inline void jffs2_build_inode_pass1(struct jffs2_sb_info *c, struct jffs2
58 if (!fd->ino) 60 if (!fd->ino)
59 continue; 61 continue;
60 62
61 /* XXX: Can get high latency here with huge directories */ 63 /* we can get high latency here with huge directories */
62 64
63 child_ic = jffs2_get_ino_cache(c, fd->ino); 65 child_ic = jffs2_get_ino_cache(c, fd->ino);
64 if (!child_ic) { 66 if (!child_ic) {
65 printk(KERN_NOTICE "Eep. Child \"%s\" (ino #%u) of dir ino #%u doesn't exist!\n", 67 dbg_fsbuild("child \"%s\" (ino #%u) of dir ino #%u doesn't exist!\n",
66 fd->name, fd->ino, ic->ino); 68 fd->name, fd->ino, ic->ino);
67 jffs2_mark_node_obsolete(c, fd->raw); 69 jffs2_mark_node_obsolete(c, fd->raw);
68 continue; 70 continue;
69 } 71 }
70 72
71 if (child_ic->nlink++ && fd->type == DT_DIR) { 73 if (child_ic->nlink++ && fd->type == DT_DIR) {
72 printk(KERN_NOTICE "Child dir \"%s\" (ino #%u) of dir ino #%u appears to be a hard link\n", fd->name, fd->ino, ic->ino); 74 JFFS2_ERROR("child dir \"%s\" (ino #%u) of dir ino #%u appears to be a hard link\n",
73 if (fd->ino == 1 && ic->ino == 1) { 75 fd->name, fd->ino, ic->ino);
74 printk(KERN_NOTICE "This is mostly harmless, and probably caused by creating a JFFS2 image\n"); 76 /* TODO: What do we do about it? */
75 printk(KERN_NOTICE "using a buggy version of mkfs.jffs2. Use at least v1.17.\n");
76 }
77 /* What do we do about it? */
78 } 77 }
79 D1(printk(KERN_DEBUG "Increased nlink for child \"%s\" (ino #%u)\n", fd->name, fd->ino)); 78 dbg_fsbuild("increased nlink for child \"%s\" (ino #%u)\n", fd->name, fd->ino);
80 /* Can't free them. We might need them in pass 2 */ 79 /* Can't free scan_dents so far. We might need them in pass 2 */
81 } 80 }
82} 81}
83 82
@@ -94,6 +93,8 @@ static int jffs2_build_filesystem(struct jffs2_sb_info *c)
94 struct jffs2_full_dirent *fd; 93 struct jffs2_full_dirent *fd;
95 struct jffs2_full_dirent *dead_fds = NULL; 94 struct jffs2_full_dirent *dead_fds = NULL;
96 95
96 dbg_fsbuild("build FS data structures\n");
97
97 /* First, scan the medium and build all the inode caches with 98 /* First, scan the medium and build all the inode caches with
98 lists of physical nodes */ 99 lists of physical nodes */
99 100
@@ -103,60 +104,54 @@ static int jffs2_build_filesystem(struct jffs2_sb_info *c)
103 if (ret) 104 if (ret)
104 goto exit; 105 goto exit;
105 106
106 D1(printk(KERN_DEBUG "Scanned flash completely\n")); 107 dbg_fsbuild("scanned flash completely\n");
107 D2(jffs2_dump_block_lists(c)); 108 jffs2_dbg_dump_block_lists_nolock(c);
108 109
110 dbg_fsbuild("pass 1 starting\n");
109 c->flags |= JFFS2_SB_FLAG_BUILDING; 111 c->flags |= JFFS2_SB_FLAG_BUILDING;
110 /* Now scan the directory tree, increasing nlink according to every dirent found. */ 112 /* Now scan the directory tree, increasing nlink according to every dirent found. */
111 for_each_inode(i, c, ic) { 113 for_each_inode(i, c, ic) {
112 D1(printk(KERN_DEBUG "Pass 1: ino #%u\n", ic->ino));
113
114 D1(BUG_ON(ic->ino > c->highest_ino));
115
116 if (ic->scan_dents) { 114 if (ic->scan_dents) {
117 jffs2_build_inode_pass1(c, ic); 115 jffs2_build_inode_pass1(c, ic);
118 cond_resched(); 116 cond_resched();
119 } 117 }
120 } 118 }
121 119
122 D1(printk(KERN_DEBUG "Pass 1 complete\n")); 120 dbg_fsbuild("pass 1 complete\n");
123 121
124 /* Next, scan for inodes with nlink == 0 and remove them. If 122 /* Next, scan for inodes with nlink == 0 and remove them. If
125 they were directories, then decrement the nlink of their 123 they were directories, then decrement the nlink of their
126 children too, and repeat the scan. As that's going to be 124 children too, and repeat the scan. As that's going to be
127 a fairly uncommon occurrence, it's not so evil to do it this 125 a fairly uncommon occurrence, it's not so evil to do it this
128 way. Recursion bad. */ 126 way. Recursion bad. */
129 D1(printk(KERN_DEBUG "Pass 2 starting\n")); 127 dbg_fsbuild("pass 2 starting\n");
130 128
131 for_each_inode(i, c, ic) { 129 for_each_inode(i, c, ic) {
132 D1(printk(KERN_DEBUG "Pass 2: ino #%u, nlink %d, ic %p, nodes %p\n", ic->ino, ic->nlink, ic, ic->nodes));
133 if (ic->nlink) 130 if (ic->nlink)
134 continue; 131 continue;
135 132
136 jffs2_build_remove_unlinked_inode(c, ic, &dead_fds); 133 jffs2_build_remove_unlinked_inode(c, ic, &dead_fds);
137 cond_resched(); 134 cond_resched();
138 } 135 }
139 136
140 D1(printk(KERN_DEBUG "Pass 2a starting\n")); 137 dbg_fsbuild("pass 2a starting\n");
141 138
142 while (dead_fds) { 139 while (dead_fds) {
143 fd = dead_fds; 140 fd = dead_fds;
144 dead_fds = fd->next; 141 dead_fds = fd->next;
145 142
146 ic = jffs2_get_ino_cache(c, fd->ino); 143 ic = jffs2_get_ino_cache(c, fd->ino);
147 D1(printk(KERN_DEBUG "Removing dead_fd ino #%u (\"%s\"), ic at %p\n", fd->ino, fd->name, ic));
148 144
149 if (ic) 145 if (ic)
150 jffs2_build_remove_unlinked_inode(c, ic, &dead_fds); 146 jffs2_build_remove_unlinked_inode(c, ic, &dead_fds);
151 jffs2_free_full_dirent(fd); 147 jffs2_free_full_dirent(fd);
152 } 148 }
153 149
154 D1(printk(KERN_DEBUG "Pass 2 complete\n")); 150 dbg_fsbuild("pass 2a complete\n");
155 151 dbg_fsbuild("freeing temporary data structures\n");
152
156 /* Finally, we can scan again and free the dirent structs */ 153 /* Finally, we can scan again and free the dirent structs */
157 for_each_inode(i, c, ic) { 154 for_each_inode(i, c, ic) {
158 D1(printk(KERN_DEBUG "Pass 3: ino #%u, ic %p, nodes %p\n", ic->ino, ic, ic->nodes));
159
160 while(ic->scan_dents) { 155 while(ic->scan_dents) {
161 fd = ic->scan_dents; 156 fd = ic->scan_dents;
162 ic->scan_dents = fd->next; 157 ic->scan_dents = fd->next;
@@ -166,9 +161,8 @@ static int jffs2_build_filesystem(struct jffs2_sb_info *c)
166 cond_resched(); 161 cond_resched();
167 } 162 }
168 c->flags &= ~JFFS2_SB_FLAG_BUILDING; 163 c->flags &= ~JFFS2_SB_FLAG_BUILDING;
169 164
170 D1(printk(KERN_DEBUG "Pass 3 complete\n")); 165 dbg_fsbuild("FS build complete\n");
171 D2(jffs2_dump_block_lists(c));
172 166
173 /* Rotate the lists by some number to ensure wear levelling */ 167 /* Rotate the lists by some number to ensure wear levelling */
174 jffs2_rotate_lists(c); 168 jffs2_rotate_lists(c);
@@ -189,24 +183,26 @@ exit:
189 return ret; 183 return ret;
190} 184}
191 185
192static void jffs2_build_remove_unlinked_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, struct jffs2_full_dirent **dead_fds) 186static void jffs2_build_remove_unlinked_inode(struct jffs2_sb_info *c,
187 struct jffs2_inode_cache *ic,
188 struct jffs2_full_dirent **dead_fds)
193{ 189{
194 struct jffs2_raw_node_ref *raw; 190 struct jffs2_raw_node_ref *raw;
195 struct jffs2_full_dirent *fd; 191 struct jffs2_full_dirent *fd;
196 192
197 D1(printk(KERN_DEBUG "JFFS2: Removing ino #%u with nlink == zero.\n", ic->ino)); 193 dbg_fsbuild("removing ino #%u with nlink == zero.\n", ic->ino);
198 194
199 raw = ic->nodes; 195 raw = ic->nodes;
200 while (raw != (void *)ic) { 196 while (raw != (void *)ic) {
201 struct jffs2_raw_node_ref *next = raw->next_in_ino; 197 struct jffs2_raw_node_ref *next = raw->next_in_ino;
202 D1(printk(KERN_DEBUG "obsoleting node at 0x%08x\n", ref_offset(raw))); 198 dbg_fsbuild("obsoleting node at 0x%08x\n", ref_offset(raw));
203 jffs2_mark_node_obsolete(c, raw); 199 jffs2_mark_node_obsolete(c, raw);
204 raw = next; 200 raw = next;
205 } 201 }
206 202
207 if (ic->scan_dents) { 203 if (ic->scan_dents) {
208 int whinged = 0; 204 int whinged = 0;
209 D1(printk(KERN_DEBUG "Inode #%u was a directory which may have children...\n", ic->ino)); 205 dbg_fsbuild("inode #%u was a directory which may have children...\n", ic->ino);
210 206
211 while(ic->scan_dents) { 207 while(ic->scan_dents) {
212 struct jffs2_inode_cache *child_ic; 208 struct jffs2_inode_cache *child_ic;
@@ -216,45 +212,43 @@ static void jffs2_build_remove_unlinked_inode(struct jffs2_sb_info *c, struct jf
216 212
217 if (!fd->ino) { 213 if (!fd->ino) {
218 /* It's a deletion dirent. Ignore it */ 214 /* It's a deletion dirent. Ignore it */
219 D1(printk(KERN_DEBUG "Child \"%s\" is a deletion dirent, skipping...\n", fd->name)); 215 dbg_fsbuild("child \"%s\" is a deletion dirent, skipping...\n", fd->name);
220 jffs2_free_full_dirent(fd); 216 jffs2_free_full_dirent(fd);
221 continue; 217 continue;
222 } 218 }
223 if (!whinged) { 219 if (!whinged)
224 whinged = 1; 220 whinged = 1;
225 printk(KERN_NOTICE "Inode #%u was a directory with children - removing those too...\n", ic->ino);
226 }
227 221
228 D1(printk(KERN_DEBUG "Removing child \"%s\", ino #%u\n", 222 dbg_fsbuild("removing child \"%s\", ino #%u\n", fd->name, fd->ino);
229 fd->name, fd->ino)); 223
230
231 child_ic = jffs2_get_ino_cache(c, fd->ino); 224 child_ic = jffs2_get_ino_cache(c, fd->ino);
232 if (!child_ic) { 225 if (!child_ic) {
233 printk(KERN_NOTICE "Cannot remove child \"%s\", ino #%u, because it doesn't exist\n", fd->name, fd->ino); 226 dbg_fsbuild("cannot remove child \"%s\", ino #%u, because it doesn't exist\n",
227 fd->name, fd->ino);
234 jffs2_free_full_dirent(fd); 228 jffs2_free_full_dirent(fd);
235 continue; 229 continue;
236 } 230 }
237 231
238 /* Reduce nlink of the child. If it's now zero, stick it on the 232 /* Reduce nlink of the child. If it's now zero, stick it on the
239 dead_fds list to be cleaned up later. Else just free the fd */ 233 dead_fds list to be cleaned up later. Else just free the fd */
240 234
241 child_ic->nlink--; 235 child_ic->nlink--;
242 236
243 if (!child_ic->nlink) { 237 if (!child_ic->nlink) {
244 D1(printk(KERN_DEBUG "Inode #%u (\"%s\") has now got zero nlink. Adding to dead_fds list.\n", 238 dbg_fsbuild("inode #%u (\"%s\") has now got zero nlink, adding to dead_fds list.\n",
245 fd->ino, fd->name)); 239 fd->ino, fd->name);
246 fd->next = *dead_fds; 240 fd->next = *dead_fds;
247 *dead_fds = fd; 241 *dead_fds = fd;
248 } else { 242 } else {
249 D1(printk(KERN_DEBUG "Inode #%u (\"%s\") has now got nlink %d. Ignoring.\n", 243 dbg_fsbuild("inode #%u (\"%s\") has now got nlink %d. Ignoring.\n",
250 fd->ino, fd->name, child_ic->nlink)); 244 fd->ino, fd->name, child_ic->nlink);
251 jffs2_free_full_dirent(fd); 245 jffs2_free_full_dirent(fd);
252 } 246 }
253 } 247 }
254 } 248 }
255 249
256 /* 250 /*
257 We don't delete the inocache from the hash list and free it yet. 251 We don't delete the inocache from the hash list and free it yet.
258 The erase code will do that, when all the nodes are completely gone. 252 The erase code will do that, when all the nodes are completely gone.
259 */ 253 */
260} 254}
@@ -268,7 +262,7 @@ static void jffs2_calc_trigger_levels(struct jffs2_sb_info *c)
268 because there's not enough free space... */ 262 because there's not enough free space... */
269 c->resv_blocks_deletion = 2; 263 c->resv_blocks_deletion = 2;
270 264
271 /* Be conservative about how much space we need before we allow writes. 265 /* Be conservative about how much space we need before we allow writes.
272 On top of that which is required for deletia, require an extra 2% 266 On top of that which is required for deletia, require an extra 2%
273 of the medium to be available, for overhead caused by nodes being 267 of the medium to be available, for overhead caused by nodes being
274 split across blocks, etc. */ 268 split across blocks, etc. */
@@ -283,7 +277,7 @@ static void jffs2_calc_trigger_levels(struct jffs2_sb_info *c)
283 277
284 c->resv_blocks_gctrigger = c->resv_blocks_write + 1; 278 c->resv_blocks_gctrigger = c->resv_blocks_write + 1;
285 279
286 /* When do we allow garbage collection to merge nodes to make 280 /* When do we allow garbage collection to merge nodes to make
287 long-term progress at the expense of short-term space exhaustion? */ 281 long-term progress at the expense of short-term space exhaustion? */
288 c->resv_blocks_gcmerge = c->resv_blocks_deletion + 1; 282 c->resv_blocks_gcmerge = c->resv_blocks_deletion + 1;
289 283
@@ -295,45 +289,45 @@ static void jffs2_calc_trigger_levels(struct jffs2_sb_info *c)
295 trying to GC to make more space. It'll be a fruitless task */ 289 trying to GC to make more space. It'll be a fruitless task */
296 c->nospc_dirty_size = c->sector_size + (c->flash_size / 100); 290 c->nospc_dirty_size = c->sector_size + (c->flash_size / 100);
297 291
298 D1(printk(KERN_DEBUG "JFFS2 trigger levels (size %d KiB, block size %d KiB, %d blocks)\n", 292 dbg_fsbuild("JFFS2 trigger levels (size %d KiB, block size %d KiB, %d blocks)\n",
299 c->flash_size / 1024, c->sector_size / 1024, c->nr_blocks)); 293 c->flash_size / 1024, c->sector_size / 1024, c->nr_blocks);
300 D1(printk(KERN_DEBUG "Blocks required to allow deletion: %d (%d KiB)\n", 294 dbg_fsbuild("Blocks required to allow deletion: %d (%d KiB)\n",
301 c->resv_blocks_deletion, c->resv_blocks_deletion*c->sector_size/1024)); 295 c->resv_blocks_deletion, c->resv_blocks_deletion*c->sector_size/1024);
302 D1(printk(KERN_DEBUG "Blocks required to allow writes: %d (%d KiB)\n", 296 dbg_fsbuild("Blocks required to allow writes: %d (%d KiB)\n",
303 c->resv_blocks_write, c->resv_blocks_write*c->sector_size/1024)); 297 c->resv_blocks_write, c->resv_blocks_write*c->sector_size/1024);
304 D1(printk(KERN_DEBUG "Blocks required to quiesce GC thread: %d (%d KiB)\n", 298 dbg_fsbuild("Blocks required to quiesce GC thread: %d (%d KiB)\n",
305 c->resv_blocks_gctrigger, c->resv_blocks_gctrigger*c->sector_size/1024)); 299 c->resv_blocks_gctrigger, c->resv_blocks_gctrigger*c->sector_size/1024);
306 D1(printk(KERN_DEBUG "Blocks required to allow GC merges: %d (%d KiB)\n", 300 dbg_fsbuild("Blocks required to allow GC merges: %d (%d KiB)\n",
307 c->resv_blocks_gcmerge, c->resv_blocks_gcmerge*c->sector_size/1024)); 301 c->resv_blocks_gcmerge, c->resv_blocks_gcmerge*c->sector_size/1024);
308 D1(printk(KERN_DEBUG "Blocks required to GC bad blocks: %d (%d KiB)\n", 302 dbg_fsbuild("Blocks required to GC bad blocks: %d (%d KiB)\n",
309 c->resv_blocks_gcbad, c->resv_blocks_gcbad*c->sector_size/1024)); 303 c->resv_blocks_gcbad, c->resv_blocks_gcbad*c->sector_size/1024);
310 D1(printk(KERN_DEBUG "Amount of dirty space required to GC: %d bytes\n", 304 dbg_fsbuild("Amount of dirty space required to GC: %d bytes\n",
311 c->nospc_dirty_size)); 305 c->nospc_dirty_size);
312} 306}
313 307
314int jffs2_do_mount_fs(struct jffs2_sb_info *c) 308int jffs2_do_mount_fs(struct jffs2_sb_info *c)
315{ 309{
310 int ret;
316 int i; 311 int i;
312 int size;
317 313
318 c->free_size = c->flash_size; 314 c->free_size = c->flash_size;
319 c->nr_blocks = c->flash_size / c->sector_size; 315 c->nr_blocks = c->flash_size / c->sector_size;
320 if (c->mtd->flags & MTD_NO_VIRTBLOCKS) 316 size = sizeof(struct jffs2_eraseblock) * c->nr_blocks;
321 c->blocks = vmalloc(sizeof(struct jffs2_eraseblock) * c->nr_blocks); 317#ifndef __ECOS
318 if (jffs2_blocks_use_vmalloc(c))
319 c->blocks = vmalloc(size);
322 else 320 else
323 c->blocks = kmalloc(sizeof(struct jffs2_eraseblock) * c->nr_blocks, GFP_KERNEL); 321#endif
322 c->blocks = kmalloc(size, GFP_KERNEL);
324 if (!c->blocks) 323 if (!c->blocks)
325 return -ENOMEM; 324 return -ENOMEM;
325
326 memset(c->blocks, 0, size);
326 for (i=0; i<c->nr_blocks; i++) { 327 for (i=0; i<c->nr_blocks; i++) {
327 INIT_LIST_HEAD(&c->blocks[i].list); 328 INIT_LIST_HEAD(&c->blocks[i].list);
328 c->blocks[i].offset = i * c->sector_size; 329 c->blocks[i].offset = i * c->sector_size;
329 c->blocks[i].free_size = c->sector_size; 330 c->blocks[i].free_size = c->sector_size;
330 c->blocks[i].dirty_size = 0;
331 c->blocks[i].wasted_size = 0;
332 c->blocks[i].unchecked_size = 0;
333 c->blocks[i].used_size = 0;
334 c->blocks[i].first_node = NULL;
335 c->blocks[i].last_node = NULL;
336 c->blocks[i].bad_count = 0;
337 } 331 }
338 332
339 INIT_LIST_HEAD(&c->clean_list); 333 INIT_LIST_HEAD(&c->clean_list);
@@ -348,16 +342,23 @@ int jffs2_do_mount_fs(struct jffs2_sb_info *c)
348 INIT_LIST_HEAD(&c->bad_list); 342 INIT_LIST_HEAD(&c->bad_list);
349 INIT_LIST_HEAD(&c->bad_used_list); 343 INIT_LIST_HEAD(&c->bad_used_list);
350 c->highest_ino = 1; 344 c->highest_ino = 1;
345 c->summary = NULL;
346
347 ret = jffs2_sum_init(c);
348 if (ret)
349 return ret;
351 350
352 if (jffs2_build_filesystem(c)) { 351 if (jffs2_build_filesystem(c)) {
353 D1(printk(KERN_DEBUG "build_fs failed\n")); 352 dbg_fsbuild("build_fs failed\n");
354 jffs2_free_ino_caches(c); 353 jffs2_free_ino_caches(c);
355 jffs2_free_raw_node_refs(c); 354 jffs2_free_raw_node_refs(c);
356 if (c->mtd->flags & MTD_NO_VIRTBLOCKS) { 355#ifndef __ECOS
356 if (jffs2_blocks_use_vmalloc(c))
357 vfree(c->blocks); 357 vfree(c->blocks);
358 } else { 358 else
359#endif
359 kfree(c->blocks); 360 kfree(c->blocks);
360 } 361
361 return -EIO; 362 return -EIO;
362 } 363 }
363 364
diff --git a/fs/jffs2/compr.c b/fs/jffs2/compr.c
index af922a9618ac..e7944e665b9f 100644
--- a/fs/jffs2/compr.c
+++ b/fs/jffs2/compr.c
@@ -9,7 +9,7 @@
9 * 9 *
10 * For licensing information, see the file 'LICENCE' in this directory. 10 * For licensing information, see the file 'LICENCE' in this directory.
11 * 11 *
12 * $Id: compr.c,v 1.42 2004/08/07 21:56:08 dwmw2 Exp $ 12 * $Id: compr.c,v 1.46 2005/11/07 11:14:38 gleixner Exp $
13 * 13 *
14 */ 14 */
15 15
@@ -36,16 +36,16 @@ static uint32_t none_stat_compr_blocks=0,none_stat_decompr_blocks=0,none_stat_co
36 * data. 36 * data.
37 * 37 *
38 * Returns: Lower byte to be stored with data indicating compression type used. 38 * Returns: Lower byte to be stored with data indicating compression type used.
39 * Zero is used to show that the data could not be compressed - the 39 * Zero is used to show that the data could not be compressed - the
40 * compressed version was actually larger than the original. 40 * compressed version was actually larger than the original.
41 * Upper byte will be used later. (soon) 41 * Upper byte will be used later. (soon)
42 * 42 *
43 * If the cdata buffer isn't large enough to hold all the uncompressed data, 43 * If the cdata buffer isn't large enough to hold all the uncompressed data,
44 * jffs2_compress should compress as much as will fit, and should set 44 * jffs2_compress should compress as much as will fit, and should set
45 * *datalen accordingly to show the amount of data which were compressed. 45 * *datalen accordingly to show the amount of data which were compressed.
46 */ 46 */
47uint16_t jffs2_compress(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 47uint16_t jffs2_compress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
48 unsigned char *data_in, unsigned char **cpage_out, 48 unsigned char *data_in, unsigned char **cpage_out,
49 uint32_t *datalen, uint32_t *cdatalen) 49 uint32_t *datalen, uint32_t *cdatalen)
50{ 50{
51 int ret = JFFS2_COMPR_NONE; 51 int ret = JFFS2_COMPR_NONE;
@@ -164,7 +164,7 @@ uint16_t jffs2_compress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
164} 164}
165 165
166int jffs2_decompress(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 166int jffs2_decompress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
167 uint16_t comprtype, unsigned char *cdata_in, 167 uint16_t comprtype, unsigned char *cdata_in,
168 unsigned char *data_out, uint32_t cdatalen, uint32_t datalen) 168 unsigned char *data_out, uint32_t cdatalen, uint32_t datalen)
169{ 169{
170 struct jffs2_compressor *this; 170 struct jffs2_compressor *this;
@@ -298,7 +298,7 @@ char *jffs2_stats(void)
298 298
299 act_buf += sprintf(act_buf,"JFFS2 compressor statistics:\n"); 299 act_buf += sprintf(act_buf,"JFFS2 compressor statistics:\n");
300 act_buf += sprintf(act_buf,"%10s ","none"); 300 act_buf += sprintf(act_buf,"%10s ","none");
301 act_buf += sprintf(act_buf,"compr: %d blocks (%d) decompr: %d blocks\n", none_stat_compr_blocks, 301 act_buf += sprintf(act_buf,"compr: %d blocks (%d) decompr: %d blocks\n", none_stat_compr_blocks,
302 none_stat_compr_size, none_stat_decompr_blocks); 302 none_stat_compr_size, none_stat_decompr_blocks);
303 spin_lock(&jffs2_compressor_list_lock); 303 spin_lock(&jffs2_compressor_list_lock);
304 list_for_each_entry(this, &jffs2_compressor_list, list) { 304 list_for_each_entry(this, &jffs2_compressor_list, list) {
@@ -307,8 +307,8 @@ char *jffs2_stats(void)
307 act_buf += sprintf(act_buf,"- "); 307 act_buf += sprintf(act_buf,"- ");
308 else 308 else
309 act_buf += sprintf(act_buf,"+ "); 309 act_buf += sprintf(act_buf,"+ ");
310 act_buf += sprintf(act_buf,"compr: %d blocks (%d/%d) decompr: %d blocks ", this->stat_compr_blocks, 310 act_buf += sprintf(act_buf,"compr: %d blocks (%d/%d) decompr: %d blocks ", this->stat_compr_blocks,
311 this->stat_compr_new_size, this->stat_compr_orig_size, 311 this->stat_compr_new_size, this->stat_compr_orig_size,
312 this->stat_decompr_blocks); 312 this->stat_decompr_blocks);
313 act_buf += sprintf(act_buf,"\n"); 313 act_buf += sprintf(act_buf,"\n");
314 } 314 }
@@ -317,7 +317,7 @@ char *jffs2_stats(void)
317 return buf; 317 return buf;
318} 318}
319 319
320char *jffs2_get_compression_mode_name(void) 320char *jffs2_get_compression_mode_name(void)
321{ 321{
322 switch (jffs2_compression_mode) { 322 switch (jffs2_compression_mode) {
323 case JFFS2_COMPR_MODE_NONE: 323 case JFFS2_COMPR_MODE_NONE:
@@ -330,7 +330,7 @@ char *jffs2_get_compression_mode_name(void)
330 return "unkown"; 330 return "unkown";
331} 331}
332 332
333int jffs2_set_compression_mode_name(const char *name) 333int jffs2_set_compression_mode_name(const char *name)
334{ 334{
335 if (!strcmp("none",name)) { 335 if (!strcmp("none",name)) {
336 jffs2_compression_mode = JFFS2_COMPR_MODE_NONE; 336 jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
@@ -355,7 +355,7 @@ static int jffs2_compressor_Xable(const char *name, int disabled)
355 if (!strcmp(this->name, name)) { 355 if (!strcmp(this->name, name)) {
356 this->disabled = disabled; 356 this->disabled = disabled;
357 spin_unlock(&jffs2_compressor_list_lock); 357 spin_unlock(&jffs2_compressor_list_lock);
358 return 0; 358 return 0;
359 } 359 }
360 } 360 }
361 spin_unlock(&jffs2_compressor_list_lock); 361 spin_unlock(&jffs2_compressor_list_lock);
@@ -385,7 +385,7 @@ int jffs2_set_compressor_priority(const char *name, int priority)
385 } 385 }
386 } 386 }
387 spin_unlock(&jffs2_compressor_list_lock); 387 spin_unlock(&jffs2_compressor_list_lock);
388 printk(KERN_WARNING "JFFS2: compressor %s not found.\n",name); 388 printk(KERN_WARNING "JFFS2: compressor %s not found.\n",name);
389 return 1; 389 return 1;
390reinsert: 390reinsert:
391 /* list is sorted in the order of priority, so if 391 /* list is sorted in the order of priority, so if
@@ -412,7 +412,7 @@ void jffs2_free_comprbuf(unsigned char *comprbuf, unsigned char *orig)
412 kfree(comprbuf); 412 kfree(comprbuf);
413} 413}
414 414
415int jffs2_compressors_init(void) 415int jffs2_compressors_init(void)
416{ 416{
417/* Registering compressors */ 417/* Registering compressors */
418#ifdef CONFIG_JFFS2_ZLIB 418#ifdef CONFIG_JFFS2_ZLIB
@@ -425,12 +425,6 @@ int jffs2_compressors_init(void)
425 jffs2_rubinmips_init(); 425 jffs2_rubinmips_init();
426 jffs2_dynrubin_init(); 426 jffs2_dynrubin_init();
427#endif 427#endif
428#ifdef CONFIG_JFFS2_LZARI
429 jffs2_lzari_init();
430#endif
431#ifdef CONFIG_JFFS2_LZO
432 jffs2_lzo_init();
433#endif
434/* Setting default compression mode */ 428/* Setting default compression mode */
435#ifdef CONFIG_JFFS2_CMODE_NONE 429#ifdef CONFIG_JFFS2_CMODE_NONE
436 jffs2_compression_mode = JFFS2_COMPR_MODE_NONE; 430 jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
@@ -446,15 +440,9 @@ int jffs2_compressors_init(void)
446 return 0; 440 return 0;
447} 441}
448 442
449int jffs2_compressors_exit(void) 443int jffs2_compressors_exit(void)
450{ 444{
451/* Unregistering compressors */ 445/* Unregistering compressors */
452#ifdef CONFIG_JFFS2_LZO
453 jffs2_lzo_exit();
454#endif
455#ifdef CONFIG_JFFS2_LZARI
456 jffs2_lzari_exit();
457#endif
458#ifdef CONFIG_JFFS2_RUBIN 446#ifdef CONFIG_JFFS2_RUBIN
459 jffs2_dynrubin_exit(); 447 jffs2_dynrubin_exit();
460 jffs2_rubinmips_exit(); 448 jffs2_rubinmips_exit();
diff --git a/fs/jffs2/compr.h b/fs/jffs2/compr.h
index 89ceeed201eb..a77e830d85c5 100644
--- a/fs/jffs2/compr.h
+++ b/fs/jffs2/compr.h
@@ -4,10 +4,10 @@
4 * Copyright (C) 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>, 4 * Copyright (C) 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>,
5 * University of Szeged, Hungary 5 * University of Szeged, Hungary
6 * 6 *
7 * For licensing information, see the file 'LICENCE' in the 7 * For licensing information, see the file 'LICENCE' in the
8 * jffs2 directory. 8 * jffs2 directory.
9 * 9 *
10 * $Id: compr.h,v 1.6 2004/07/16 15:17:57 dwmw2 Exp $ 10 * $Id: compr.h,v 1.9 2005/11/07 11:14:38 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -103,13 +103,5 @@ void jffs2_rtime_exit(void);
103int jffs2_zlib_init(void); 103int jffs2_zlib_init(void);
104void jffs2_zlib_exit(void); 104void jffs2_zlib_exit(void);
105#endif 105#endif
106#ifdef CONFIG_JFFS2_LZARI
107int jffs2_lzari_init(void);
108void jffs2_lzari_exit(void);
109#endif
110#ifdef CONFIG_JFFS2_LZO
111int jffs2_lzo_init(void);
112void jffs2_lzo_exit(void);
113#endif
114 106
115#endif /* __JFFS2_COMPR_H__ */ 107#endif /* __JFFS2_COMPR_H__ */
diff --git a/fs/jffs2/compr_rtime.c b/fs/jffs2/compr_rtime.c
index 393129418666..2eb1b7428d16 100644
--- a/fs/jffs2/compr_rtime.c
+++ b/fs/jffs2/compr_rtime.c
@@ -24,8 +24,8 @@
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/string.h> 27#include <linux/string.h>
28#include <linux/jffs2.h> 28#include <linux/jffs2.h>
29#include "compr.h" 29#include "compr.h"
30 30
31/* _compress returns the compressed size, -1 if bigger */ 31/* _compress returns the compressed size, -1 if bigger */
@@ -38,19 +38,19 @@ static int jffs2_rtime_compress(unsigned char *data_in,
38 int outpos = 0; 38 int outpos = 0;
39 int pos=0; 39 int pos=0;
40 40
41 memset(positions,0,sizeof(positions)); 41 memset(positions,0,sizeof(positions));
42 42
43 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) { 43 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
44 int backpos, runlen=0; 44 int backpos, runlen=0;
45 unsigned char value; 45 unsigned char value;
46 46
47 value = data_in[pos]; 47 value = data_in[pos];
48 48
49 cpage_out[outpos++] = data_in[pos++]; 49 cpage_out[outpos++] = data_in[pos++];
50 50
51 backpos = positions[value]; 51 backpos = positions[value];
52 positions[value]=pos; 52 positions[value]=pos;
53 53
54 while ((backpos < pos) && (pos < (*sourcelen)) && 54 while ((backpos < pos) && (pos < (*sourcelen)) &&
55 (data_in[pos]==data_in[backpos++]) && (runlen<255)) { 55 (data_in[pos]==data_in[backpos++]) && (runlen<255)) {
56 pos++; 56 pos++;
@@ -63,12 +63,12 @@ static int jffs2_rtime_compress(unsigned char *data_in,
63 /* We failed */ 63 /* We failed */
64 return -1; 64 return -1;
65 } 65 }
66 66
67 /* Tell the caller how much we managed to compress, and how much space it took */ 67 /* Tell the caller how much we managed to compress, and how much space it took */
68 *sourcelen = pos; 68 *sourcelen = pos;
69 *dstlen = outpos; 69 *dstlen = outpos;
70 return 0; 70 return 0;
71} 71}
72 72
73 73
74static int jffs2_rtime_decompress(unsigned char *data_in, 74static int jffs2_rtime_decompress(unsigned char *data_in,
@@ -79,19 +79,19 @@ static int jffs2_rtime_decompress(unsigned char *data_in,
79 short positions[256]; 79 short positions[256];
80 int outpos = 0; 80 int outpos = 0;
81 int pos=0; 81 int pos=0;
82 82
83 memset(positions,0,sizeof(positions)); 83 memset(positions,0,sizeof(positions));
84 84
85 while (outpos<destlen) { 85 while (outpos<destlen) {
86 unsigned char value; 86 unsigned char value;
87 int backoffs; 87 int backoffs;
88 int repeat; 88 int repeat;
89 89
90 value = data_in[pos++]; 90 value = data_in[pos++];
91 cpage_out[outpos++] = value; /* first the verbatim copied byte */ 91 cpage_out[outpos++] = value; /* first the verbatim copied byte */
92 repeat = data_in[pos++]; 92 repeat = data_in[pos++];
93 backoffs = positions[value]; 93 backoffs = positions[value];
94 94
95 positions[value]=outpos; 95 positions[value]=outpos;
96 if (repeat) { 96 if (repeat) {
97 if (backoffs + repeat >= outpos) { 97 if (backoffs + repeat >= outpos) {
@@ -101,12 +101,12 @@ static int jffs2_rtime_decompress(unsigned char *data_in,
101 } 101 }
102 } else { 102 } else {
103 memcpy(&cpage_out[outpos],&cpage_out[backoffs],repeat); 103 memcpy(&cpage_out[outpos],&cpage_out[backoffs],repeat);
104 outpos+=repeat; 104 outpos+=repeat;
105 } 105 }
106 } 106 }
107 } 107 }
108 return 0; 108 return 0;
109} 109}
110 110
111static struct jffs2_compressor jffs2_rtime_comp = { 111static struct jffs2_compressor jffs2_rtime_comp = {
112 .priority = JFFS2_RTIME_PRIORITY, 112 .priority = JFFS2_RTIME_PRIORITY,
diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c
index 09422388fb96..e792e675d624 100644
--- a/fs/jffs2/compr_rubin.c
+++ b/fs/jffs2/compr_rubin.c
@@ -11,7 +11,6 @@
11 * 11 *
12 */ 12 */
13 13
14
15#include <linux/string.h> 14#include <linux/string.h>
16#include <linux/types.h> 15#include <linux/types.h>
17#include <linux/jffs2.h> 16#include <linux/jffs2.h>
@@ -20,7 +19,7 @@
20#include "compr.h" 19#include "compr.h"
21 20
22static void init_rubin(struct rubin_state *rs, int div, int *bits) 21static void init_rubin(struct rubin_state *rs, int div, int *bits)
23{ 22{
24 int c; 23 int c;
25 24
26 rs->q = 0; 25 rs->q = 0;
@@ -40,7 +39,7 @@ static int encode(struct rubin_state *rs, long A, long B, int symbol)
40 39
41 while ((rs->q >= UPPER_BIT_RUBIN) || ((rs->p + rs->q) <= UPPER_BIT_RUBIN)) { 40 while ((rs->q >= UPPER_BIT_RUBIN) || ((rs->p + rs->q) <= UPPER_BIT_RUBIN)) {
42 rs->bit_number++; 41 rs->bit_number++;
43 42
44 ret = pushbit(&rs->pp, (rs->q & UPPER_BIT_RUBIN) ? 1 : 0, 0); 43 ret = pushbit(&rs->pp, (rs->q & UPPER_BIT_RUBIN) ? 1 : 0, 0);
45 if (ret) 44 if (ret)
46 return ret; 45 return ret;
@@ -68,7 +67,7 @@ static int encode(struct rubin_state *rs, long A, long B, int symbol)
68 67
69 68
70static void end_rubin(struct rubin_state *rs) 69static void end_rubin(struct rubin_state *rs)
71{ 70{
72 71
73 int i; 72 int i;
74 73
@@ -82,7 +81,7 @@ static void end_rubin(struct rubin_state *rs)
82 81
83static void init_decode(struct rubin_state *rs, int div, int *bits) 82static void init_decode(struct rubin_state *rs, int div, int *bits)
84{ 83{
85 init_rubin(rs, div, bits); 84 init_rubin(rs, div, bits);
86 85
87 /* behalve lower */ 86 /* behalve lower */
88 rs->rec_q = 0; 87 rs->rec_q = 0;
@@ -188,7 +187,7 @@ static int in_byte(struct rubin_state *rs)
188 187
189 188
190 189
191static int rubin_do_compress(int bit_divider, int *bits, unsigned char *data_in, 190static int rubin_do_compress(int bit_divider, int *bits, unsigned char *data_in,
192 unsigned char *cpage_out, uint32_t *sourcelen, uint32_t *dstlen) 191 unsigned char *cpage_out, uint32_t *sourcelen, uint32_t *dstlen)
193 { 192 {
194 int outpos = 0; 193 int outpos = 0;
@@ -198,31 +197,31 @@ static int rubin_do_compress(int bit_divider, int *bits, unsigned char *data_in,
198 init_pushpull(&rs.pp, cpage_out, *dstlen * 8, 0, 32); 197 init_pushpull(&rs.pp, cpage_out, *dstlen * 8, 0, 32);
199 198
200 init_rubin(&rs, bit_divider, bits); 199 init_rubin(&rs, bit_divider, bits);
201 200
202 while (pos < (*sourcelen) && !out_byte(&rs, data_in[pos])) 201 while (pos < (*sourcelen) && !out_byte(&rs, data_in[pos]))
203 pos++; 202 pos++;
204 203
205 end_rubin(&rs); 204 end_rubin(&rs);
206 205
207 if (outpos > pos) { 206 if (outpos > pos) {
208 /* We failed */ 207 /* We failed */
209 return -1; 208 return -1;
210 } 209 }
211 210
212 /* Tell the caller how much we managed to compress, 211 /* Tell the caller how much we managed to compress,
213 * and how much space it took */ 212 * and how much space it took */
214 213
215 outpos = (pushedbits(&rs.pp)+7)/8; 214 outpos = (pushedbits(&rs.pp)+7)/8;
216 215
217 if (outpos >= pos) 216 if (outpos >= pos)
218 return -1; /* We didn't actually compress */ 217 return -1; /* We didn't actually compress */
219 *sourcelen = pos; 218 *sourcelen = pos;
220 *dstlen = outpos; 219 *dstlen = outpos;
221 return 0; 220 return 0;
222} 221}
223#if 0 222#if 0
224/* _compress returns the compressed size, -1 if bigger */ 223/* _compress returns the compressed size, -1 if bigger */
225int jffs2_rubinmips_compress(unsigned char *data_in, unsigned char *cpage_out, 224int jffs2_rubinmips_compress(unsigned char *data_in, unsigned char *cpage_out,
226 uint32_t *sourcelen, uint32_t *dstlen, void *model) 225 uint32_t *sourcelen, uint32_t *dstlen, void *model)
227{ 226{
228 return rubin_do_compress(BIT_DIVIDER_MIPS, bits_mips, data_in, cpage_out, sourcelen, dstlen); 227 return rubin_do_compress(BIT_DIVIDER_MIPS, bits_mips, data_in, cpage_out, sourcelen, dstlen);
@@ -277,7 +276,7 @@ static int jffs2_dynrubin_compress(unsigned char *data_in,
277 } 276 }
278 277
279 ret = rubin_do_compress(256, bits, data_in, cpage_out+8, &mysrclen, &mydstlen); 278 ret = rubin_do_compress(256, bits, data_in, cpage_out+8, &mysrclen, &mydstlen);
280 if (ret) 279 if (ret)
281 return ret; 280 return ret;
282 281
283 /* Add back the 8 bytes we took for the probabilities */ 282 /* Add back the 8 bytes we took for the probabilities */
@@ -293,19 +292,19 @@ static int jffs2_dynrubin_compress(unsigned char *data_in,
293 return 0; 292 return 0;
294} 293}
295 294
296static void rubin_do_decompress(int bit_divider, int *bits, unsigned char *cdata_in, 295static void rubin_do_decompress(int bit_divider, int *bits, unsigned char *cdata_in,
297 unsigned char *page_out, uint32_t srclen, uint32_t destlen) 296 unsigned char *page_out, uint32_t srclen, uint32_t destlen)
298{ 297{
299 int outpos = 0; 298 int outpos = 0;
300 struct rubin_state rs; 299 struct rubin_state rs;
301 300
302 init_pushpull(&rs.pp, cdata_in, srclen, 0, 0); 301 init_pushpull(&rs.pp, cdata_in, srclen, 0, 0);
303 init_decode(&rs, bit_divider, bits); 302 init_decode(&rs, bit_divider, bits);
304 303
305 while (outpos < destlen) { 304 while (outpos < destlen) {
306 page_out[outpos++] = in_byte(&rs); 305 page_out[outpos++] = in_byte(&rs);
307 } 306 }
308} 307}
309 308
310 309
311static int jffs2_rubinmips_decompress(unsigned char *data_in, 310static int jffs2_rubinmips_decompress(unsigned char *data_in,
diff --git a/fs/jffs2/compr_rubin.h b/fs/jffs2/compr_rubin.h
index cf51e34f6574..bf1a93451621 100644
--- a/fs/jffs2/compr_rubin.h
+++ b/fs/jffs2/compr_rubin.h
@@ -1,7 +1,7 @@
1/* Rubin encoder/decoder header */ 1/* Rubin encoder/decoder header */
2/* work started at : aug 3, 1994 */ 2/* work started at : aug 3, 1994 */
3/* last modification : aug 15, 1994 */ 3/* last modification : aug 15, 1994 */
4/* $Id: compr_rubin.h,v 1.6 2002/01/25 01:49:26 dwmw2 Exp $ */ 4/* $Id: compr_rubin.h,v 1.7 2005/11/07 11:14:38 gleixner Exp $ */
5 5
6#include "pushpull.h" 6#include "pushpull.h"
7 7
@@ -11,8 +11,8 @@
11 11
12 12
13struct rubin_state { 13struct rubin_state {
14 unsigned long p; 14 unsigned long p;
15 unsigned long q; 15 unsigned long q;
16 unsigned long rec_q; 16 unsigned long rec_q;
17 long bit_number; 17 long bit_number;
18 struct pushpull pp; 18 struct pushpull pp;
diff --git a/fs/jffs2/compr_zlib.c b/fs/jffs2/compr_zlib.c
index 83f7e0788fd0..4db8be8e90cc 100644
--- a/fs/jffs2/compr_zlib.c
+++ b/fs/jffs2/compr_zlib.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: compr_zlib.c,v 1.31 2005/05/20 19:30:06 gleixner Exp $ 10 * $Id: compr_zlib.c,v 1.32 2005/11/07 11:14:38 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -24,11 +24,11 @@
24#include "nodelist.h" 24#include "nodelist.h"
25#include "compr.h" 25#include "compr.h"
26 26
27 /* Plan: call deflate() with avail_in == *sourcelen, 27 /* Plan: call deflate() with avail_in == *sourcelen,
28 avail_out = *dstlen - 12 and flush == Z_FINISH. 28 avail_out = *dstlen - 12 and flush == Z_FINISH.
29 If it doesn't manage to finish, call it again with 29 If it doesn't manage to finish, call it again with
30 avail_in == 0 and avail_out set to the remaining 12 30 avail_in == 0 and avail_out set to the remaining 12
31 bytes for it to clean up. 31 bytes for it to clean up.
32 Q: Is 12 bytes sufficient? 32 Q: Is 12 bytes sufficient?
33 */ 33 */
34#define STREAM_END_SPACE 12 34#define STREAM_END_SPACE 12
@@ -89,7 +89,7 @@ static int jffs2_zlib_compress(unsigned char *data_in,
89 89
90 def_strm.next_in = data_in; 90 def_strm.next_in = data_in;
91 def_strm.total_in = 0; 91 def_strm.total_in = 0;
92 92
93 def_strm.next_out = cpage_out; 93 def_strm.next_out = cpage_out;
94 def_strm.total_out = 0; 94 def_strm.total_out = 0;
95 95
@@ -99,7 +99,7 @@ static int jffs2_zlib_compress(unsigned char *data_in,
99 D1(printk(KERN_DEBUG "calling deflate with avail_in %d, avail_out %d\n", 99 D1(printk(KERN_DEBUG "calling deflate with avail_in %d, avail_out %d\n",
100 def_strm.avail_in, def_strm.avail_out)); 100 def_strm.avail_in, def_strm.avail_out));
101 ret = zlib_deflate(&def_strm, Z_PARTIAL_FLUSH); 101 ret = zlib_deflate(&def_strm, Z_PARTIAL_FLUSH);
102 D1(printk(KERN_DEBUG "deflate returned with avail_in %d, avail_out %d, total_in %ld, total_out %ld\n", 102 D1(printk(KERN_DEBUG "deflate returned with avail_in %d, avail_out %d, total_in %ld, total_out %ld\n",
103 def_strm.avail_in, def_strm.avail_out, def_strm.total_in, def_strm.total_out)); 103 def_strm.avail_in, def_strm.avail_out, def_strm.total_in, def_strm.total_out));
104 if (ret != Z_OK) { 104 if (ret != Z_OK) {
105 D1(printk(KERN_DEBUG "deflate in loop returned %d\n", ret)); 105 D1(printk(KERN_DEBUG "deflate in loop returned %d\n", ret));
@@ -150,7 +150,7 @@ static int jffs2_zlib_decompress(unsigned char *data_in,
150 inf_strm.next_in = data_in; 150 inf_strm.next_in = data_in;
151 inf_strm.avail_in = srclen; 151 inf_strm.avail_in = srclen;
152 inf_strm.total_in = 0; 152 inf_strm.total_in = 0;
153 153
154 inf_strm.next_out = cpage_out; 154 inf_strm.next_out = cpage_out;
155 inf_strm.avail_out = destlen; 155 inf_strm.avail_out = destlen;
156 inf_strm.total_out = 0; 156 inf_strm.total_out = 0;
diff --git a/fs/jffs2/comprtest.c b/fs/jffs2/comprtest.c
index cf51f091d0e7..f0fb8be7740c 100644
--- a/fs/jffs2/comprtest.c
+++ b/fs/jffs2/comprtest.c
@@ -1,4 +1,4 @@
1/* $Id: comprtest.c,v 1.5 2002/01/03 15:20:44 dwmw2 Exp $ */ 1/* $Id: comprtest.c,v 1.6 2005/11/07 11:14:38 gleixner Exp $ */
2 2
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/string.h> 4#include <linux/string.h>
@@ -265,9 +265,9 @@ static unsigned char testdata[TESTDATA_LEN] = {
265static unsigned char comprbuf[TESTDATA_LEN]; 265static unsigned char comprbuf[TESTDATA_LEN];
266static unsigned char decomprbuf[TESTDATA_LEN]; 266static unsigned char decomprbuf[TESTDATA_LEN];
267 267
268int jffs2_decompress(unsigned char comprtype, unsigned char *cdata_in, 268int jffs2_decompress(unsigned char comprtype, unsigned char *cdata_in,
269 unsigned char *data_out, uint32_t cdatalen, uint32_t datalen); 269 unsigned char *data_out, uint32_t cdatalen, uint32_t datalen);
270unsigned char jffs2_compress(unsigned char *data_in, unsigned char *cpage_out, 270unsigned char jffs2_compress(unsigned char *data_in, unsigned char *cpage_out,
271 uint32_t *datalen, uint32_t *cdatalen); 271 uint32_t *datalen, uint32_t *cdatalen);
272 272
273int init_module(void ) { 273int init_module(void ) {
@@ -276,10 +276,10 @@ int init_module(void ) {
276 int ret; 276 int ret;
277 277
278 printk("Original data: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", 278 printk("Original data: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
279 testdata[0],testdata[1],testdata[2],testdata[3], 279 testdata[0],testdata[1],testdata[2],testdata[3],
280 testdata[4],testdata[5],testdata[6],testdata[7], 280 testdata[4],testdata[5],testdata[6],testdata[7],
281 testdata[8],testdata[9],testdata[10],testdata[11], 281 testdata[8],testdata[9],testdata[10],testdata[11],
282 testdata[12],testdata[13],testdata[14],testdata[15]); 282 testdata[12],testdata[13],testdata[14],testdata[15]);
283 d = TESTDATA_LEN; 283 d = TESTDATA_LEN;
284 c = TESTDATA_LEN; 284 c = TESTDATA_LEN;
285 comprtype = jffs2_compress(testdata, comprbuf, &d, &c); 285 comprtype = jffs2_compress(testdata, comprbuf, &d, &c);
@@ -287,18 +287,18 @@ int init_module(void ) {
287 printk("jffs2_compress used compression type %d. Compressed size %d, uncompressed size %d\n", 287 printk("jffs2_compress used compression type %d. Compressed size %d, uncompressed size %d\n",
288 comprtype, c, d); 288 comprtype, c, d);
289 printk("Compressed data: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", 289 printk("Compressed data: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
290 comprbuf[0],comprbuf[1],comprbuf[2],comprbuf[3], 290 comprbuf[0],comprbuf[1],comprbuf[2],comprbuf[3],
291 comprbuf[4],comprbuf[5],comprbuf[6],comprbuf[7], 291 comprbuf[4],comprbuf[5],comprbuf[6],comprbuf[7],
292 comprbuf[8],comprbuf[9],comprbuf[10],comprbuf[11], 292 comprbuf[8],comprbuf[9],comprbuf[10],comprbuf[11],
293 comprbuf[12],comprbuf[13],comprbuf[14],comprbuf[15]); 293 comprbuf[12],comprbuf[13],comprbuf[14],comprbuf[15]);
294 294
295 ret = jffs2_decompress(comprtype, comprbuf, decomprbuf, c, d); 295 ret = jffs2_decompress(comprtype, comprbuf, decomprbuf, c, d);
296 printk("jffs2_decompress returned %d\n", ret); 296 printk("jffs2_decompress returned %d\n", ret);
297 printk("Decompressed data: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", 297 printk("Decompressed data: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
298 decomprbuf[0],decomprbuf[1],decomprbuf[2],decomprbuf[3], 298 decomprbuf[0],decomprbuf[1],decomprbuf[2],decomprbuf[3],
299 decomprbuf[4],decomprbuf[5],decomprbuf[6],decomprbuf[7], 299 decomprbuf[4],decomprbuf[5],decomprbuf[6],decomprbuf[7],
300 decomprbuf[8],decomprbuf[9],decomprbuf[10],decomprbuf[11], 300 decomprbuf[8],decomprbuf[9],decomprbuf[10],decomprbuf[11],
301 decomprbuf[12],decomprbuf[13],decomprbuf[14],decomprbuf[15]); 301 decomprbuf[12],decomprbuf[13],decomprbuf[14],decomprbuf[15]);
302 if (memcmp(decomprbuf, testdata, d)) 302 if (memcmp(decomprbuf, testdata, d))
303 printk("Compression and decompression corrupted data\n"); 303 printk("Compression and decompression corrupted data\n");
304 else 304 else
diff --git a/fs/jffs2/debug.c b/fs/jffs2/debug.c
new file mode 100644
index 000000000000..1fe17de713e8
--- /dev/null
+++ b/fs/jffs2/debug.c
@@ -0,0 +1,705 @@
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 *
6 * Created by David Woodhouse <dwmw2@infradead.org>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
10 * $Id: debug.c,v 1.12 2005/11/07 11:14:39 gleixner Exp $
11 *
12 */
13#include <linux/kernel.h>
14#include <linux/types.h>
15#include <linux/pagemap.h>
16#include <linux/crc32.h>
17#include <linux/jffs2.h>
18#include <linux/mtd/mtd.h>
19#include "nodelist.h"
20#include "debug.h"
21
22#ifdef JFFS2_DBG_SANITY_CHECKS
23
24void
25__jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info *c,
26 struct jffs2_eraseblock *jeb)
27{
28 if (unlikely(jeb && jeb->used_size + jeb->dirty_size +
29 jeb->free_size + jeb->wasted_size +
30 jeb->unchecked_size != c->sector_size)) {
31 JFFS2_ERROR("eeep, space accounting for block at 0x%08x is screwed.\n", jeb->offset);
32 JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + wasted %#08x + unchecked %#08x != total %#08x.\n",
33 jeb->free_size, jeb->dirty_size, jeb->used_size,
34 jeb->wasted_size, jeb->unchecked_size, c->sector_size);
35 BUG();
36 }
37
38 if (unlikely(c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size
39 + c->wasted_size + c->unchecked_size != c->flash_size)) {
40 JFFS2_ERROR("eeep, space accounting superblock info is screwed.\n");
41 JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + erasing %#08x + bad %#08x + wasted %#08x + unchecked %#08x != total %#08x.\n",
42 c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size,
43 c->wasted_size, c->unchecked_size, c->flash_size);
44 BUG();
45 }
46}
47
48void
49__jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
50 struct jffs2_eraseblock *jeb)
51{
52 spin_lock(&c->erase_completion_lock);
53 jffs2_dbg_acct_sanity_check_nolock(c, jeb);
54 spin_unlock(&c->erase_completion_lock);
55}
56
57#endif /* JFFS2_DBG_SANITY_CHECKS */
58
59#ifdef JFFS2_DBG_PARANOIA_CHECKS
60/*
61 * Check the fragtree.
62 */
63void
64__jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f)
65{
66 down(&f->sem);
67 __jffs2_dbg_fragtree_paranoia_check_nolock(f);
68 up(&f->sem);
69}
70
71void
72__jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f)
73{
74 struct jffs2_node_frag *frag;
75 int bitched = 0;
76
77 for (frag = frag_first(&f->fragtree); frag; frag = frag_next(frag)) {
78 struct jffs2_full_dnode *fn = frag->node;
79
80 if (!fn || !fn->raw)
81 continue;
82
83 if (ref_flags(fn->raw) == REF_PRISTINE) {
84 if (fn->frags > 1) {
85 JFFS2_ERROR("REF_PRISTINE node at 0x%08x had %d frags. Tell dwmw2.\n",
86 ref_offset(fn->raw), fn->frags);
87 bitched = 1;
88 }
89
90 /* A hole node which isn't multi-page should be garbage-collected
91 and merged anyway, so we just check for the frag size here,
92 rather than mucking around with actually reading the node
93 and checking the compression type, which is the real way
94 to tell a hole node. */
95 if (frag->ofs & (PAGE_CACHE_SIZE-1) && frag_prev(frag)
96 && frag_prev(frag)->size < PAGE_CACHE_SIZE && frag_prev(frag)->node) {
97 JFFS2_ERROR("REF_PRISTINE node at 0x%08x had a previous non-hole frag in the same page. Tell dwmw2.\n",
98 ref_offset(fn->raw));
99 bitched = 1;
100 }
101
102 if ((frag->ofs+frag->size) & (PAGE_CACHE_SIZE-1) && frag_next(frag)
103 && frag_next(frag)->size < PAGE_CACHE_SIZE && frag_next(frag)->node) {
104 JFFS2_ERROR("REF_PRISTINE node at 0x%08x (%08x-%08x) had a following non-hole frag in the same page. Tell dwmw2.\n",
105 ref_offset(fn->raw), frag->ofs, frag->ofs+frag->size);
106 bitched = 1;
107 }
108 }
109 }
110
111 if (bitched) {
112 JFFS2_ERROR("fragtree is corrupted.\n");
113 __jffs2_dbg_dump_fragtree_nolock(f);
114 BUG();
115 }
116}
117
118/*
119 * Check if the flash contains all 0xFF before we start writing.
120 */
121void
122__jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
123 uint32_t ofs, int len)
124{
125 size_t retlen;
126 int ret, i;
127 unsigned char *buf;
128
129 buf = kmalloc(len, GFP_KERNEL);
130 if (!buf)
131 return;
132
133 ret = jffs2_flash_read(c, ofs, len, &retlen, buf);
134 if (ret || (retlen != len)) {
135 JFFS2_WARNING("read %d bytes failed or short. ret %d, retlen %zd.\n",
136 len, ret, retlen);
137 kfree(buf);
138 return;
139 }
140
141 ret = 0;
142 for (i = 0; i < len; i++)
143 if (buf[i] != 0xff)
144 ret = 1;
145
146 if (ret) {
147 JFFS2_ERROR("argh, about to write node to %#08x on flash, but there are data already there. The first corrupted byte is at %#08x offset.\n",
148 ofs, ofs + i);
149 __jffs2_dbg_dump_buffer(buf, len, ofs);
150 kfree(buf);
151 BUG();
152 }
153
154 kfree(buf);
155}
156
157/*
158 * Check the space accounting and node_ref list correctness for the JFFS2 erasable block 'jeb'.
159 */
160void
161__jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
162 struct jffs2_eraseblock *jeb)
163{
164 spin_lock(&c->erase_completion_lock);
165 __jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
166 spin_unlock(&c->erase_completion_lock);
167}
168
169void
170__jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
171 struct jffs2_eraseblock *jeb)
172{
173 uint32_t my_used_size = 0;
174 uint32_t my_unchecked_size = 0;
175 uint32_t my_dirty_size = 0;
176 struct jffs2_raw_node_ref *ref2 = jeb->first_node;
177
178 while (ref2) {
179 uint32_t totlen = ref_totlen(c, jeb, ref2);
180
181 if (ref2->flash_offset < jeb->offset ||
182 ref2->flash_offset > jeb->offset + c->sector_size) {
183 JFFS2_ERROR("node_ref %#08x shouldn't be in block at %#08x.\n",
184 ref_offset(ref2), jeb->offset);
185 goto error;
186
187 }
188 if (ref_flags(ref2) == REF_UNCHECKED)
189 my_unchecked_size += totlen;
190 else if (!ref_obsolete(ref2))
191 my_used_size += totlen;
192 else
193 my_dirty_size += totlen;
194
195 if ((!ref2->next_phys) != (ref2 == jeb->last_node)) {
196 JFFS2_ERROR("node_ref for node at %#08x (mem %p) has next_phys at %#08x (mem %p), last_node is at %#08x (mem %p).\n",
197 ref_offset(ref2), ref2, ref_offset(ref2->next_phys), ref2->next_phys,
198 ref_offset(jeb->last_node), jeb->last_node);
199 goto error;
200 }
201 ref2 = ref2->next_phys;
202 }
203
204 if (my_used_size != jeb->used_size) {
205 JFFS2_ERROR("Calculated used size %#08x != stored used size %#08x.\n",
206 my_used_size, jeb->used_size);
207 goto error;
208 }
209
210 if (my_unchecked_size != jeb->unchecked_size) {
211 JFFS2_ERROR("Calculated unchecked size %#08x != stored unchecked size %#08x.\n",
212 my_unchecked_size, jeb->unchecked_size);
213 goto error;
214 }
215
216#if 0
217 /* This should work when we implement ref->__totlen elemination */
218 if (my_dirty_size != jeb->dirty_size + jeb->wasted_size) {
219 JFFS2_ERROR("Calculated dirty+wasted size %#08x != stored dirty + wasted size %#08x\n",
220 my_dirty_size, jeb->dirty_size + jeb->wasted_size);
221 goto error;
222 }
223
224 if (jeb->free_size == 0
225 && my_used_size + my_unchecked_size + my_dirty_size != c->sector_size) {
226 JFFS2_ERROR("The sum of all nodes in block (%#x) != size of block (%#x)\n",
227 my_used_size + my_unchecked_size + my_dirty_size,
228 c->sector_size);
229 goto error;
230 }
231#endif
232
233 return;
234
235error:
236 __jffs2_dbg_dump_node_refs_nolock(c, jeb);
237 __jffs2_dbg_dump_jeb_nolock(jeb);
238 __jffs2_dbg_dump_block_lists_nolock(c);
239 BUG();
240
241}
242#endif /* JFFS2_DBG_PARANOIA_CHECKS */
243
244#if defined(JFFS2_DBG_DUMPS) || defined(JFFS2_DBG_PARANOIA_CHECKS)
245/*
246 * Dump the node_refs of the 'jeb' JFFS2 eraseblock.
247 */
248void
249__jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c,
250 struct jffs2_eraseblock *jeb)
251{
252 spin_lock(&c->erase_completion_lock);
253 __jffs2_dbg_dump_node_refs_nolock(c, jeb);
254 spin_unlock(&c->erase_completion_lock);
255}
256
257void
258__jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
259 struct jffs2_eraseblock *jeb)
260{
261 struct jffs2_raw_node_ref *ref;
262 int i = 0;
263
264 printk(JFFS2_DBG_MSG_PREFIX " Dump node_refs of the eraseblock %#08x\n", jeb->offset);
265 if (!jeb->first_node) {
266 printk(JFFS2_DBG_MSG_PREFIX " no nodes in the eraseblock %#08x\n", jeb->offset);
267 return;
268 }
269
270 printk(JFFS2_DBG);
271 for (ref = jeb->first_node; ; ref = ref->next_phys) {
272 printk("%#08x(%#x)", ref_offset(ref), ref->__totlen);
273 if (ref->next_phys)
274 printk("->");
275 else
276 break;
277 if (++i == 4) {
278 i = 0;
279 printk("\n" JFFS2_DBG);
280 }
281 }
282 printk("\n");
283}
284
285/*
286 * Dump an eraseblock's space accounting.
287 */
288void
289__jffs2_dbg_dump_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
290{
291 spin_lock(&c->erase_completion_lock);
292 __jffs2_dbg_dump_jeb_nolock(jeb);
293 spin_unlock(&c->erase_completion_lock);
294}
295
296void
297__jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb)
298{
299 if (!jeb)
300 return;
301
302 printk(JFFS2_DBG_MSG_PREFIX " dump space accounting for the eraseblock at %#08x:\n",
303 jeb->offset);
304
305 printk(JFFS2_DBG "used_size: %#08x\n", jeb->used_size);
306 printk(JFFS2_DBG "dirty_size: %#08x\n", jeb->dirty_size);
307 printk(JFFS2_DBG "wasted_size: %#08x\n", jeb->wasted_size);
308 printk(JFFS2_DBG "unchecked_size: %#08x\n", jeb->unchecked_size);
309 printk(JFFS2_DBG "free_size: %#08x\n", jeb->free_size);
310}
311
312void
313__jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c)
314{
315 spin_lock(&c->erase_completion_lock);
316 __jffs2_dbg_dump_block_lists_nolock(c);
317 spin_unlock(&c->erase_completion_lock);
318}
319
320void
321__jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c)
322{
323 printk(JFFS2_DBG_MSG_PREFIX " dump JFFS2 blocks lists:\n");
324
325 printk(JFFS2_DBG "flash_size: %#08x\n", c->flash_size);
326 printk(JFFS2_DBG "used_size: %#08x\n", c->used_size);
327 printk(JFFS2_DBG "dirty_size: %#08x\n", c->dirty_size);
328 printk(JFFS2_DBG "wasted_size: %#08x\n", c->wasted_size);
329 printk(JFFS2_DBG "unchecked_size: %#08x\n", c->unchecked_size);
330 printk(JFFS2_DBG "free_size: %#08x\n", c->free_size);
331 printk(JFFS2_DBG "erasing_size: %#08x\n", c->erasing_size);
332 printk(JFFS2_DBG "bad_size: %#08x\n", c->bad_size);
333 printk(JFFS2_DBG "sector_size: %#08x\n", c->sector_size);
334 printk(JFFS2_DBG "jffs2_reserved_blocks size: %#08x\n",
335 c->sector_size * c->resv_blocks_write);
336
337 if (c->nextblock)
338 printk(JFFS2_DBG "nextblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
339 c->nextblock->offset, c->nextblock->used_size,
340 c->nextblock->dirty_size, c->nextblock->wasted_size,
341 c->nextblock->unchecked_size, c->nextblock->free_size);
342 else
343 printk(JFFS2_DBG "nextblock: NULL\n");
344
345 if (c->gcblock)
346 printk(JFFS2_DBG "gcblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
347 c->gcblock->offset, c->gcblock->used_size, c->gcblock->dirty_size,
348 c->gcblock->wasted_size, c->gcblock->unchecked_size, c->gcblock->free_size);
349 else
350 printk(JFFS2_DBG "gcblock: NULL\n");
351
352 if (list_empty(&c->clean_list)) {
353 printk(JFFS2_DBG "clean_list: empty\n");
354 } else {
355 struct list_head *this;
356 int numblocks = 0;
357 uint32_t dirty = 0;
358
359 list_for_each(this, &c->clean_list) {
360 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
361 numblocks ++;
362 dirty += jeb->wasted_size;
363 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
364 printk(JFFS2_DBG "clean_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
365 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
366 jeb->unchecked_size, jeb->free_size);
367 }
368 }
369
370 printk (JFFS2_DBG "Contains %d blocks with total wasted size %u, average wasted size: %u\n",
371 numblocks, dirty, dirty / numblocks);
372 }
373
374 if (list_empty(&c->very_dirty_list)) {
375 printk(JFFS2_DBG "very_dirty_list: empty\n");
376 } else {
377 struct list_head *this;
378 int numblocks = 0;
379 uint32_t dirty = 0;
380
381 list_for_each(this, &c->very_dirty_list) {
382 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
383
384 numblocks ++;
385 dirty += jeb->dirty_size;
386 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
387 printk(JFFS2_DBG "very_dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
388 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
389 jeb->unchecked_size, jeb->free_size);
390 }
391 }
392
393 printk (JFFS2_DBG "Contains %d blocks with total dirty size %u, average dirty size: %u\n",
394 numblocks, dirty, dirty / numblocks);
395 }
396
397 if (list_empty(&c->dirty_list)) {
398 printk(JFFS2_DBG "dirty_list: empty\n");
399 } else {
400 struct list_head *this;
401 int numblocks = 0;
402 uint32_t dirty = 0;
403
404 list_for_each(this, &c->dirty_list) {
405 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
406
407 numblocks ++;
408 dirty += jeb->dirty_size;
409 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
410 printk(JFFS2_DBG "dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
411 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
412 jeb->unchecked_size, jeb->free_size);
413 }
414 }
415
416 printk (JFFS2_DBG "contains %d blocks with total dirty size %u, average dirty size: %u\n",
417 numblocks, dirty, dirty / numblocks);
418 }
419
420 if (list_empty(&c->erasable_list)) {
421 printk(JFFS2_DBG "erasable_list: empty\n");
422 } else {
423 struct list_head *this;
424
425 list_for_each(this, &c->erasable_list) {
426 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
427
428 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
429 printk(JFFS2_DBG "erasable_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
430 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
431 jeb->unchecked_size, jeb->free_size);
432 }
433 }
434 }
435
436 if (list_empty(&c->erasing_list)) {
437 printk(JFFS2_DBG "erasing_list: empty\n");
438 } else {
439 struct list_head *this;
440
441 list_for_each(this, &c->erasing_list) {
442 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
443
444 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
445 printk(JFFS2_DBG "erasing_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
446 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
447 jeb->unchecked_size, jeb->free_size);
448 }
449 }
450 }
451
452 if (list_empty(&c->erase_pending_list)) {
453 printk(JFFS2_DBG "erase_pending_list: empty\n");
454 } else {
455 struct list_head *this;
456
457 list_for_each(this, &c->erase_pending_list) {
458 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
459
460 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
461 printk(JFFS2_DBG "erase_pending_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
462 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
463 jeb->unchecked_size, jeb->free_size);
464 }
465 }
466 }
467
468 if (list_empty(&c->erasable_pending_wbuf_list)) {
469 printk(JFFS2_DBG "erasable_pending_wbuf_list: empty\n");
470 } else {
471 struct list_head *this;
472
473 list_for_each(this, &c->erasable_pending_wbuf_list) {
474 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
475
476 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
477 printk(JFFS2_DBG "erasable_pending_wbuf_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
478 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
479 jeb->unchecked_size, jeb->free_size);
480 }
481 }
482 }
483
484 if (list_empty(&c->free_list)) {
485 printk(JFFS2_DBG "free_list: empty\n");
486 } else {
487 struct list_head *this;
488
489 list_for_each(this, &c->free_list) {
490 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
491
492 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
493 printk(JFFS2_DBG "free_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
494 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
495 jeb->unchecked_size, jeb->free_size);
496 }
497 }
498 }
499
500 if (list_empty(&c->bad_list)) {
501 printk(JFFS2_DBG "bad_list: empty\n");
502 } else {
503 struct list_head *this;
504
505 list_for_each(this, &c->bad_list) {
506 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
507
508 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
509 printk(JFFS2_DBG "bad_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
510 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
511 jeb->unchecked_size, jeb->free_size);
512 }
513 }
514 }
515
516 if (list_empty(&c->bad_used_list)) {
517 printk(JFFS2_DBG "bad_used_list: empty\n");
518 } else {
519 struct list_head *this;
520
521 list_for_each(this, &c->bad_used_list) {
522 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
523
524 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
525 printk(JFFS2_DBG "bad_used_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
526 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
527 jeb->unchecked_size, jeb->free_size);
528 }
529 }
530 }
531}
532
533void
534__jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f)
535{
536 down(&f->sem);
537 jffs2_dbg_dump_fragtree_nolock(f);
538 up(&f->sem);
539}
540
541void
542__jffs2_dbg_dump_fragtree_nolock(struct jffs2_inode_info *f)
543{
544 struct jffs2_node_frag *this = frag_first(&f->fragtree);
545 uint32_t lastofs = 0;
546 int buggy = 0;
547
548 printk(JFFS2_DBG_MSG_PREFIX " dump fragtree of ino #%u\n", f->inocache->ino);
549 while(this) {
550 if (this->node)
551 printk(JFFS2_DBG "frag %#04x-%#04x: %#08x(%d) on flash (*%p), left (%p), right (%p), parent (%p)\n",
552 this->ofs, this->ofs+this->size, ref_offset(this->node->raw),
553 ref_flags(this->node->raw), this, frag_left(this), frag_right(this),
554 frag_parent(this));
555 else
556 printk(JFFS2_DBG "frag %#04x-%#04x: hole (*%p). left (%p), right (%p), parent (%p)\n",
557 this->ofs, this->ofs+this->size, this, frag_left(this),
558 frag_right(this), frag_parent(this));
559 if (this->ofs != lastofs)
560 buggy = 1;
561 lastofs = this->ofs + this->size;
562 this = frag_next(this);
563 }
564
565 if (f->metadata)
566 printk(JFFS2_DBG "metadata at 0x%08x\n", ref_offset(f->metadata->raw));
567
568 if (buggy) {
569 JFFS2_ERROR("frag tree got a hole in it.\n");
570 BUG();
571 }
572}
573
574#define JFFS2_BUFDUMP_BYTES_PER_LINE 32
575void
576__jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs)
577{
578 int skip;
579 int i;
580
581 printk(JFFS2_DBG_MSG_PREFIX " dump from offset %#08x to offset %#08x (%x bytes).\n",
582 offs, offs + len, len);
583 i = skip = offs % JFFS2_BUFDUMP_BYTES_PER_LINE;
584 offs = offs & ~(JFFS2_BUFDUMP_BYTES_PER_LINE - 1);
585
586 if (skip != 0)
587 printk(JFFS2_DBG "%#08x: ", offs);
588
589 while (skip--)
590 printk(" ");
591
592 while (i < len) {
593 if ((i % JFFS2_BUFDUMP_BYTES_PER_LINE) == 0 && i != len -1) {
594 if (i != 0)
595 printk("\n");
596 offs += JFFS2_BUFDUMP_BYTES_PER_LINE;
597 printk(JFFS2_DBG "%0#8x: ", offs);
598 }
599
600 printk("%02x ", buf[i]);
601
602 i += 1;
603 }
604
605 printk("\n");
606}
607
608/*
609 * Dump a JFFS2 node.
610 */
611void
612__jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs)
613{
614 union jffs2_node_union node;
615 int len = sizeof(union jffs2_node_union);
616 size_t retlen;
617 uint32_t crc;
618 int ret;
619
620 printk(JFFS2_DBG_MSG_PREFIX " dump node at offset %#08x.\n", ofs);
621
622 ret = jffs2_flash_read(c, ofs, len, &retlen, (unsigned char *)&node);
623 if (ret || (retlen != len)) {
624 JFFS2_ERROR("read %d bytes failed or short. ret %d, retlen %zd.\n",
625 len, ret, retlen);
626 return;
627 }
628
629 printk(JFFS2_DBG "magic:\t%#04x\n", je16_to_cpu(node.u.magic));
630 printk(JFFS2_DBG "nodetype:\t%#04x\n", je16_to_cpu(node.u.nodetype));
631 printk(JFFS2_DBG "totlen:\t%#08x\n", je32_to_cpu(node.u.totlen));
632 printk(JFFS2_DBG "hdr_crc:\t%#08x\n", je32_to_cpu(node.u.hdr_crc));
633
634 crc = crc32(0, &node.u, sizeof(node.u) - 4);
635 if (crc != je32_to_cpu(node.u.hdr_crc)) {
636 JFFS2_ERROR("wrong common header CRC.\n");
637 return;
638 }
639
640 if (je16_to_cpu(node.u.magic) != JFFS2_MAGIC_BITMASK &&
641 je16_to_cpu(node.u.magic) != JFFS2_OLD_MAGIC_BITMASK)
642 {
643 JFFS2_ERROR("wrong node magic: %#04x instead of %#04x.\n",
644 je16_to_cpu(node.u.magic), JFFS2_MAGIC_BITMASK);
645 return;
646 }
647
648 switch(je16_to_cpu(node.u.nodetype)) {
649
650 case JFFS2_NODETYPE_INODE:
651
652 printk(JFFS2_DBG "the node is inode node\n");
653 printk(JFFS2_DBG "ino:\t%#08x\n", je32_to_cpu(node.i.ino));
654 printk(JFFS2_DBG "version:\t%#08x\n", je32_to_cpu(node.i.version));
655 printk(JFFS2_DBG "mode:\t%#08x\n", node.i.mode.m);
656 printk(JFFS2_DBG "uid:\t%#04x\n", je16_to_cpu(node.i.uid));
657 printk(JFFS2_DBG "gid:\t%#04x\n", je16_to_cpu(node.i.gid));
658 printk(JFFS2_DBG "isize:\t%#08x\n", je32_to_cpu(node.i.isize));
659 printk(JFFS2_DBG "atime:\t%#08x\n", je32_to_cpu(node.i.atime));
660 printk(JFFS2_DBG "mtime:\t%#08x\n", je32_to_cpu(node.i.mtime));
661 printk(JFFS2_DBG "ctime:\t%#08x\n", je32_to_cpu(node.i.ctime));
662 printk(JFFS2_DBG "offset:\t%#08x\n", je32_to_cpu(node.i.offset));
663 printk(JFFS2_DBG "csize:\t%#08x\n", je32_to_cpu(node.i.csize));
664 printk(JFFS2_DBG "dsize:\t%#08x\n", je32_to_cpu(node.i.dsize));
665 printk(JFFS2_DBG "compr:\t%#02x\n", node.i.compr);
666 printk(JFFS2_DBG "usercompr:\t%#02x\n", node.i.usercompr);
667 printk(JFFS2_DBG "flags:\t%#04x\n", je16_to_cpu(node.i.flags));
668 printk(JFFS2_DBG "data_crc:\t%#08x\n", je32_to_cpu(node.i.data_crc));
669 printk(JFFS2_DBG "node_crc:\t%#08x\n", je32_to_cpu(node.i.node_crc));
670
671 crc = crc32(0, &node.i, sizeof(node.i) - 8);
672 if (crc != je32_to_cpu(node.i.node_crc)) {
673 JFFS2_ERROR("wrong node header CRC.\n");
674 return;
675 }
676 break;
677
678 case JFFS2_NODETYPE_DIRENT:
679
680 printk(JFFS2_DBG "the node is dirent node\n");
681 printk(JFFS2_DBG "pino:\t%#08x\n", je32_to_cpu(node.d.pino));
682 printk(JFFS2_DBG "version:\t%#08x\n", je32_to_cpu(node.d.version));
683 printk(JFFS2_DBG "ino:\t%#08x\n", je32_to_cpu(node.d.ino));
684 printk(JFFS2_DBG "mctime:\t%#08x\n", je32_to_cpu(node.d.mctime));
685 printk(JFFS2_DBG "nsize:\t%#02x\n", node.d.nsize);
686 printk(JFFS2_DBG "type:\t%#02x\n", node.d.type);
687 printk(JFFS2_DBG "node_crc:\t%#08x\n", je32_to_cpu(node.d.node_crc));
688 printk(JFFS2_DBG "name_crc:\t%#08x\n", je32_to_cpu(node.d.name_crc));
689
690 node.d.name[node.d.nsize] = '\0';
691 printk(JFFS2_DBG "name:\t\"%s\"\n", node.d.name);
692
693 crc = crc32(0, &node.d, sizeof(node.d) - 8);
694 if (crc != je32_to_cpu(node.d.node_crc)) {
695 JFFS2_ERROR("wrong node header CRC.\n");
696 return;
697 }
698 break;
699
700 default:
701 printk(JFFS2_DBG "node type is unknown\n");
702 break;
703 }
704}
705#endif /* JFFS2_DBG_DUMPS || JFFS2_DBG_PARANOIA_CHECKS */
diff --git a/fs/jffs2/debug.h b/fs/jffs2/debug.h
new file mode 100644
index 000000000000..f193d43a8a59
--- /dev/null
+++ b/fs/jffs2/debug.h
@@ -0,0 +1,279 @@
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 *
6 * Created by David Woodhouse <dwmw2@infradead.org>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
10 * $Id: debug.h,v 1.21 2005/11/07 11:14:39 gleixner Exp $
11 *
12 */
13#ifndef _JFFS2_DEBUG_H_
14#define _JFFS2_DEBUG_H_
15
16#include <linux/config.h>
17
18#ifndef CONFIG_JFFS2_FS_DEBUG
19#define CONFIG_JFFS2_FS_DEBUG 0
20#endif
21
22#if CONFIG_JFFS2_FS_DEBUG > 0
23/* Enable "paranoia" checks and dumps */
24#define JFFS2_DBG_PARANOIA_CHECKS
25#define JFFS2_DBG_DUMPS
26
27/*
28 * By defining/undefining the below macros one may select debugging messages
29 * fro specific JFFS2 subsystems.
30 */
31#define JFFS2_DBG_READINODE_MESSAGES
32#define JFFS2_DBG_FRAGTREE_MESSAGES
33#define JFFS2_DBG_DENTLIST_MESSAGES
34#define JFFS2_DBG_NODEREF_MESSAGES
35#define JFFS2_DBG_INOCACHE_MESSAGES
36#define JFFS2_DBG_SUMMARY_MESSAGES
37#define JFFS2_DBG_FSBUILD_MESSAGES
38#endif
39
40#if CONFIG_JFFS2_FS_DEBUG > 1
41#define JFFS2_DBG_FRAGTREE2_MESSAGES
42#define JFFS2_DBG_MEMALLOC_MESSAGES
43#endif
44
45/* Sanity checks are supposed to be light-weight and enabled by default */
46#define JFFS2_DBG_SANITY_CHECKS
47
48/*
49 * Dx() are mainly used for debugging messages, they must go away and be
50 * superseded by nicer dbg_xxx() macros...
51 */
52#if CONFIG_JFFS2_FS_DEBUG > 0
53#define D1(x) x
54#else
55#define D1(x)
56#endif
57
58#if CONFIG_JFFS2_FS_DEBUG > 1
59#define D2(x) x
60#else
61#define D2(x)
62#endif
63
64/* The prefixes of JFFS2 messages */
65#define JFFS2_DBG_PREFIX "[JFFS2 DBG]"
66#define JFFS2_ERR_PREFIX "JFFS2 error:"
67#define JFFS2_WARN_PREFIX "JFFS2 warning:"
68#define JFFS2_NOTICE_PREFIX "JFFS2 notice:"
69
70#define JFFS2_ERR KERN_ERR
71#define JFFS2_WARN KERN_WARNING
72#define JFFS2_NOT KERN_NOTICE
73#define JFFS2_DBG KERN_DEBUG
74
75#define JFFS2_DBG_MSG_PREFIX JFFS2_DBG JFFS2_DBG_PREFIX
76#define JFFS2_ERR_MSG_PREFIX JFFS2_ERR JFFS2_ERR_PREFIX
77#define JFFS2_WARN_MSG_PREFIX JFFS2_WARN JFFS2_WARN_PREFIX
78#define JFFS2_NOTICE_MSG_PREFIX JFFS2_NOT JFFS2_NOTICE_PREFIX
79
80/* JFFS2 message macros */
81#define JFFS2_ERROR(fmt, ...) \
82 do { \
83 printk(JFFS2_ERR_MSG_PREFIX \
84 " (%d) %s: " fmt, current->pid, \
85 __FUNCTION__, ##__VA_ARGS__); \
86 } while(0)
87
88#define JFFS2_WARNING(fmt, ...) \
89 do { \
90 printk(JFFS2_WARN_MSG_PREFIX \
91 " (%d) %s: " fmt, current->pid, \
92 __FUNCTION__, ##__VA_ARGS__); \
93 } while(0)
94
95#define JFFS2_NOTICE(fmt, ...) \
96 do { \
97 printk(JFFS2_NOTICE_MSG_PREFIX \
98 " (%d) %s: " fmt, current->pid, \
99 __FUNCTION__, ##__VA_ARGS__); \
100 } while(0)
101
102#define JFFS2_DEBUG(fmt, ...) \
103 do { \
104 printk(JFFS2_DBG_MSG_PREFIX \
105 " (%d) %s: " fmt, current->pid, \
106 __FUNCTION__, ##__VA_ARGS__); \
107 } while(0)
108
109/*
110 * We split our debugging messages on several parts, depending on the JFFS2
111 * subsystem the message belongs to.
112 */
113/* Read inode debugging messages */
114#ifdef JFFS2_DBG_READINODE_MESSAGES
115#define dbg_readinode(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
116#else
117#define dbg_readinode(fmt, ...)
118#endif
119
120/* Fragtree build debugging messages */
121#ifdef JFFS2_DBG_FRAGTREE_MESSAGES
122#define dbg_fragtree(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
123#else
124#define dbg_fragtree(fmt, ...)
125#endif
126#ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
127#define dbg_fragtree2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
128#else
129#define dbg_fragtree2(fmt, ...)
130#endif
131
132/* Directory entry list manilulation debugging messages */
133#ifdef JFFS2_DBG_DENTLIST_MESSAGES
134#define dbg_dentlist(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
135#else
136#define dbg_dentlist(fmt, ...)
137#endif
138
139/* Print the messages about manipulating node_refs */
140#ifdef JFFS2_DBG_NODEREF_MESSAGES
141#define dbg_noderef(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
142#else
143#define dbg_noderef(fmt, ...)
144#endif
145
146/* Manipulations with the list of inodes (JFFS2 inocache) */
147#ifdef JFFS2_DBG_INOCACHE_MESSAGES
148#define dbg_inocache(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
149#else
150#define dbg_inocache(fmt, ...)
151#endif
152
153/* Summary debugging messages */
154#ifdef JFFS2_DBG_SUMMARY_MESSAGES
155#define dbg_summary(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
156#else
157#define dbg_summary(fmt, ...)
158#endif
159
160/* File system build messages */
161#ifdef JFFS2_DBG_FSBUILD_MESSAGES
162#define dbg_fsbuild(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
163#else
164#define dbg_fsbuild(fmt, ...)
165#endif
166
167/* Watch the object allocations */
168#ifdef JFFS2_DBG_MEMALLOC_MESSAGES
169#define dbg_memalloc(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
170#else
171#define dbg_memalloc(fmt, ...)
172#endif
173
174
175/* "Sanity" checks */
176void
177__jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info *c,
178 struct jffs2_eraseblock *jeb);
179void
180__jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
181 struct jffs2_eraseblock *jeb);
182
183/* "Paranoia" checks */
184void
185__jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f);
186void
187__jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f);
188void
189__jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
190 struct jffs2_eraseblock *jeb);
191void
192__jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
193 struct jffs2_eraseblock *jeb);
194void
195__jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
196 uint32_t ofs, int len);
197
198/* "Dump" functions */
199void
200__jffs2_dbg_dump_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
201void
202__jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb);
203void
204__jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c);
205void
206__jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c);
207void
208__jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c,
209 struct jffs2_eraseblock *jeb);
210void
211__jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
212 struct jffs2_eraseblock *jeb);
213void
214__jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f);
215void
216__jffs2_dbg_dump_fragtree_nolock(struct jffs2_inode_info *f);
217void
218__jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs);
219void
220__jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs);
221
222#ifdef JFFS2_DBG_PARANOIA_CHECKS
223#define jffs2_dbg_fragtree_paranoia_check(f) \
224 __jffs2_dbg_fragtree_paranoia_check(f)
225#define jffs2_dbg_fragtree_paranoia_check_nolock(f) \
226 __jffs2_dbg_fragtree_paranoia_check_nolock(f)
227#define jffs2_dbg_acct_paranoia_check(c, jeb) \
228 __jffs2_dbg_acct_paranoia_check(c,jeb)
229#define jffs2_dbg_acct_paranoia_check_nolock(c, jeb) \
230 __jffs2_dbg_acct_paranoia_check_nolock(c,jeb)
231#define jffs2_dbg_prewrite_paranoia_check(c, ofs, len) \
232 __jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
233#else
234#define jffs2_dbg_fragtree_paranoia_check(f)
235#define jffs2_dbg_fragtree_paranoia_check_nolock(f)
236#define jffs2_dbg_acct_paranoia_check(c, jeb)
237#define jffs2_dbg_acct_paranoia_check_nolock(c, jeb)
238#define jffs2_dbg_prewrite_paranoia_check(c, ofs, len)
239#endif /* !JFFS2_PARANOIA_CHECKS */
240
241#ifdef JFFS2_DBG_DUMPS
242#define jffs2_dbg_dump_jeb(c, jeb) \
243 __jffs2_dbg_dump_jeb(c, jeb);
244#define jffs2_dbg_dump_jeb_nolock(jeb) \
245 __jffs2_dbg_dump_jeb_nolock(jeb);
246#define jffs2_dbg_dump_block_lists(c) \
247 __jffs2_dbg_dump_block_lists(c)
248#define jffs2_dbg_dump_block_lists_nolock(c) \
249 __jffs2_dbg_dump_block_lists_nolock(c)
250#define jffs2_dbg_dump_fragtree(f) \
251 __jffs2_dbg_dump_fragtree(f);
252#define jffs2_dbg_dump_fragtree_nolock(f) \
253 __jffs2_dbg_dump_fragtree_nolock(f);
254#define jffs2_dbg_dump_buffer(buf, len, offs) \
255 __jffs2_dbg_dump_buffer(*buf, len, offs);
256#define jffs2_dbg_dump_node(c, ofs) \
257 __jffs2_dbg_dump_node(c, ofs);
258#else
259#define jffs2_dbg_dump_jeb(c, jeb)
260#define jffs2_dbg_dump_jeb_nolock(jeb)
261#define jffs2_dbg_dump_block_lists(c)
262#define jffs2_dbg_dump_block_lists_nolock(c)
263#define jffs2_dbg_dump_fragtree(f)
264#define jffs2_dbg_dump_fragtree_nolock(f)
265#define jffs2_dbg_dump_buffer(buf, len, offs)
266#define jffs2_dbg_dump_node(c, ofs)
267#endif /* !JFFS2_DBG_DUMPS */
268
269#ifdef JFFS2_DBG_SANITY_CHECKS
270#define jffs2_dbg_acct_sanity_check(c, jeb) \
271 __jffs2_dbg_acct_sanity_check(c, jeb)
272#define jffs2_dbg_acct_sanity_check_nolock(c, jeb) \
273 __jffs2_dbg_acct_sanity_check_nolock(c, jeb)
274#else
275#define jffs2_dbg_acct_sanity_check(c, jeb)
276#define jffs2_dbg_acct_sanity_check_nolock(c, jeb)
277#endif /* !JFFS2_DBG_SANITY_CHECKS */
278
279#endif /* _JFFS2_DEBUG_H_ */
diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c
index 3ca0d25eef1d..a7bf9cb2567f 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: dir.c,v 1.86 2005/07/06 12:13:09 dwmw2 Exp $ 10 * $Id: dir.c,v 1.90 2005/11/07 11:14:39 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -64,7 +64,7 @@ struct inode_operations jffs2_dir_inode_operations =
64 64
65 65
66/* We keep the dirent list sorted in increasing order of name hash, 66/* We keep the dirent list sorted in increasing order of name hash,
67 and we use the same hash function as the dentries. Makes this 67 and we use the same hash function as the dentries. Makes this
68 nice and simple 68 nice and simple
69*/ 69*/
70static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target, 70static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
@@ -85,7 +85,7 @@ static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
85 85
86 /* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */ 86 /* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */
87 for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) { 87 for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) {
88 if (fd_list->nhash == target->d_name.hash && 88 if (fd_list->nhash == target->d_name.hash &&
89 (!fd || fd_list->version > fd->version) && 89 (!fd || fd_list->version > fd->version) &&
90 strlen(fd_list->name) == target->d_name.len && 90 strlen(fd_list->name) == target->d_name.len &&
91 !strncmp(fd_list->name, target->d_name.name, target->d_name.len)) { 91 !strncmp(fd_list->name, target->d_name.name, target->d_name.len)) {
@@ -147,7 +147,7 @@ static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir)
147 curofs++; 147 curofs++;
148 /* First loop: curofs = 2; offset = 2 */ 148 /* First loop: curofs = 2; offset = 2 */
149 if (curofs < offset) { 149 if (curofs < offset) {
150 D2(printk(KERN_DEBUG "Skipping dirent: \"%s\", ino #%u, type %d, because curofs %ld < offset %ld\n", 150 D2(printk(KERN_DEBUG "Skipping dirent: \"%s\", ino #%u, type %d, because curofs %ld < offset %ld\n",
151 fd->name, fd->ino, fd->type, curofs, offset)); 151 fd->name, fd->ino, fd->type, curofs, offset));
152 continue; 152 continue;
153 } 153 }
@@ -182,7 +182,7 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode,
182 ri = jffs2_alloc_raw_inode(); 182 ri = jffs2_alloc_raw_inode();
183 if (!ri) 183 if (!ri)
184 return -ENOMEM; 184 return -ENOMEM;
185 185
186 c = JFFS2_SB_INFO(dir_i->i_sb); 186 c = JFFS2_SB_INFO(dir_i->i_sb);
187 187
188 D1(printk(KERN_DEBUG "jffs2_create()\n")); 188 D1(printk(KERN_DEBUG "jffs2_create()\n"));
@@ -203,7 +203,7 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode,
203 f = JFFS2_INODE_INFO(inode); 203 f = JFFS2_INODE_INFO(inode);
204 dir_f = JFFS2_INODE_INFO(dir_i); 204 dir_f = JFFS2_INODE_INFO(dir_i);
205 205
206 ret = jffs2_do_create(c, dir_f, f, ri, 206 ret = jffs2_do_create(c, dir_f, f, ri,
207 dentry->d_name.name, dentry->d_name.len); 207 dentry->d_name.name, dentry->d_name.len);
208 208
209 if (ret) { 209 if (ret) {
@@ -232,11 +232,14 @@ static int jffs2_unlink(struct inode *dir_i, struct dentry *dentry)
232 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i); 232 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
233 struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(dentry->d_inode); 233 struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(dentry->d_inode);
234 int ret; 234 int ret;
235 uint32_t now = get_seconds();
235 236
236 ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name, 237 ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name,
237 dentry->d_name.len, dead_f); 238 dentry->d_name.len, dead_f, now);
238 if (dead_f->inocache) 239 if (dead_f->inocache)
239 dentry->d_inode->i_nlink = dead_f->inocache->nlink; 240 dentry->d_inode->i_nlink = dead_f->inocache->nlink;
241 if (!ret)
242 dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
240 return ret; 243 return ret;
241} 244}
242/***********************************************************************/ 245/***********************************************************************/
@@ -249,6 +252,7 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de
249 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i); 252 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
250 int ret; 253 int ret;
251 uint8_t type; 254 uint8_t type;
255 uint32_t now;
252 256
253 /* Don't let people make hard links to bad inodes. */ 257 /* Don't let people make hard links to bad inodes. */
254 if (!f->inocache) 258 if (!f->inocache)
@@ -261,13 +265,15 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de
261 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12; 265 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12;
262 if (!type) type = DT_REG; 266 if (!type) type = DT_REG;
263 267
264 ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len); 268 now = get_seconds();
269 ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len, now);
265 270
266 if (!ret) { 271 if (!ret) {
267 down(&f->sem); 272 down(&f->sem);
268 old_dentry->d_inode->i_nlink = ++f->inocache->nlink; 273 old_dentry->d_inode->i_nlink = ++f->inocache->nlink;
269 up(&f->sem); 274 up(&f->sem);
270 d_instantiate(dentry, old_dentry->d_inode); 275 d_instantiate(dentry, old_dentry->d_inode);
276 dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
271 atomic_inc(&old_dentry->d_inode->i_count); 277 atomic_inc(&old_dentry->d_inode->i_count);
272 } 278 }
273 return ret; 279 return ret;
@@ -297,14 +303,15 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
297 303
298 if (!ri) 304 if (!ri)
299 return -ENOMEM; 305 return -ENOMEM;
300 306
301 c = JFFS2_SB_INFO(dir_i->i_sb); 307 c = JFFS2_SB_INFO(dir_i->i_sb);
302 308
303 /* Try to reserve enough space for both node and dirent. 309 /* Try to reserve enough space for both node and dirent.
304 * Just the node will do for now, though 310 * Just the node will do for now, though
305 */ 311 */
306 namelen = dentry->d_name.len; 312 namelen = dentry->d_name.len;
307 ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &phys_ofs, &alloclen, ALLOC_NORMAL); 313 ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &phys_ofs, &alloclen,
314 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
308 315
309 if (ret) { 316 if (ret) {
310 jffs2_free_raw_inode(ri); 317 jffs2_free_raw_inode(ri);
@@ -331,7 +338,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
331 ri->compr = JFFS2_COMPR_NONE; 338 ri->compr = JFFS2_COMPR_NONE;
332 ri->data_crc = cpu_to_je32(crc32(0, target, targetlen)); 339 ri->data_crc = cpu_to_je32(crc32(0, target, targetlen));
333 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 340 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
334 341
335 fn = jffs2_write_dnode(c, f, ri, target, targetlen, phys_ofs, ALLOC_NORMAL); 342 fn = jffs2_write_dnode(c, f, ri, target, targetlen, phys_ofs, ALLOC_NORMAL);
336 343
337 jffs2_free_raw_inode(ri); 344 jffs2_free_raw_inode(ri);
@@ -344,9 +351,9 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
344 return PTR_ERR(fn); 351 return PTR_ERR(fn);
345 } 352 }
346 353
347 /* We use f->dents field to store the target path. */ 354 /* We use f->target field to store the target path. */
348 f->dents = kmalloc(targetlen + 1, GFP_KERNEL); 355 f->target = kmalloc(targetlen + 1, GFP_KERNEL);
349 if (!f->dents) { 356 if (!f->target) {
350 printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1); 357 printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1);
351 up(&f->sem); 358 up(&f->sem);
352 jffs2_complete_reservation(c); 359 jffs2_complete_reservation(c);
@@ -354,17 +361,18 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
354 return -ENOMEM; 361 return -ENOMEM;
355 } 362 }
356 363
357 memcpy(f->dents, target, targetlen + 1); 364 memcpy(f->target, target, targetlen + 1);
358 D1(printk(KERN_DEBUG "jffs2_symlink: symlink's target '%s' cached\n", (char *)f->dents)); 365 D1(printk(KERN_DEBUG "jffs2_symlink: symlink's target '%s' cached\n", (char *)f->target));
359 366
360 /* No data here. Only a metadata node, which will be 367 /* No data here. Only a metadata node, which will be
361 obsoleted by the first data write 368 obsoleted by the first data write
362 */ 369 */
363 f->metadata = fn; 370 f->metadata = fn;
364 up(&f->sem); 371 up(&f->sem);
365 372
366 jffs2_complete_reservation(c); 373 jffs2_complete_reservation(c);
367 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL); 374 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
375 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
368 if (ret) { 376 if (ret) {
369 /* Eep. */ 377 /* Eep. */
370 jffs2_clear_inode(inode); 378 jffs2_clear_inode(inode);
@@ -399,7 +407,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
399 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); 407 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL);
400 408
401 if (IS_ERR(fd)) { 409 if (IS_ERR(fd)) {
402 /* dirent failed to write. Delete the inode normally 410 /* dirent failed to write. Delete the inode normally
403 as if it were the final unlink() */ 411 as if it were the final unlink() */
404 jffs2_complete_reservation(c); 412 jffs2_complete_reservation(c);
405 jffs2_free_raw_dirent(rd); 413 jffs2_free_raw_dirent(rd);
@@ -442,14 +450,15 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
442 ri = jffs2_alloc_raw_inode(); 450 ri = jffs2_alloc_raw_inode();
443 if (!ri) 451 if (!ri)
444 return -ENOMEM; 452 return -ENOMEM;
445 453
446 c = JFFS2_SB_INFO(dir_i->i_sb); 454 c = JFFS2_SB_INFO(dir_i->i_sb);
447 455
448 /* Try to reserve enough space for both node and dirent. 456 /* Try to reserve enough space for both node and dirent.
449 * Just the node will do for now, though 457 * Just the node will do for now, though
450 */ 458 */
451 namelen = dentry->d_name.len; 459 namelen = dentry->d_name.len;
452 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL); 460 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL,
461 JFFS2_SUMMARY_INODE_SIZE);
453 462
454 if (ret) { 463 if (ret) {
455 jffs2_free_raw_inode(ri); 464 jffs2_free_raw_inode(ri);
@@ -473,7 +482,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
473 482
474 ri->data_crc = cpu_to_je32(0); 483 ri->data_crc = cpu_to_je32(0);
475 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 484 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
476 485
477 fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL); 486 fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL);
478 487
479 jffs2_free_raw_inode(ri); 488 jffs2_free_raw_inode(ri);
@@ -485,20 +494,21 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
485 jffs2_clear_inode(inode); 494 jffs2_clear_inode(inode);
486 return PTR_ERR(fn); 495 return PTR_ERR(fn);
487 } 496 }
488 /* No data here. Only a metadata node, which will be 497 /* No data here. Only a metadata node, which will be
489 obsoleted by the first data write 498 obsoleted by the first data write
490 */ 499 */
491 f->metadata = fn; 500 f->metadata = fn;
492 up(&f->sem); 501 up(&f->sem);
493 502
494 jffs2_complete_reservation(c); 503 jffs2_complete_reservation(c);
495 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL); 504 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
505 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
496 if (ret) { 506 if (ret) {
497 /* Eep. */ 507 /* Eep. */
498 jffs2_clear_inode(inode); 508 jffs2_clear_inode(inode);
499 return ret; 509 return ret;
500 } 510 }
501 511
502 rd = jffs2_alloc_raw_dirent(); 512 rd = jffs2_alloc_raw_dirent();
503 if (!rd) { 513 if (!rd) {
504 /* Argh. Now we treat it like a normal delete */ 514 /* Argh. Now we treat it like a normal delete */
@@ -525,9 +535,9 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
525 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); 535 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
526 536
527 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); 537 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL);
528 538
529 if (IS_ERR(fd)) { 539 if (IS_ERR(fd)) {
530 /* dirent failed to write. Delete the inode normally 540 /* dirent failed to write. Delete the inode normally
531 as if it were the final unlink() */ 541 as if it were the final unlink() */
532 jffs2_complete_reservation(c); 542 jffs2_complete_reservation(c);
533 jffs2_free_raw_dirent(rd); 543 jffs2_free_raw_dirent(rd);
@@ -589,19 +599,20 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
589 ri = jffs2_alloc_raw_inode(); 599 ri = jffs2_alloc_raw_inode();
590 if (!ri) 600 if (!ri)
591 return -ENOMEM; 601 return -ENOMEM;
592 602
593 c = JFFS2_SB_INFO(dir_i->i_sb); 603 c = JFFS2_SB_INFO(dir_i->i_sb);
594 604
595 if (S_ISBLK(mode) || S_ISCHR(mode)) { 605 if (S_ISBLK(mode) || S_ISCHR(mode)) {
596 dev = cpu_to_je16(old_encode_dev(rdev)); 606 dev = cpu_to_je16(old_encode_dev(rdev));
597 devlen = sizeof(dev); 607 devlen = sizeof(dev);
598 } 608 }
599 609
600 /* Try to reserve enough space for both node and dirent. 610 /* Try to reserve enough space for both node and dirent.
601 * Just the node will do for now, though 611 * Just the node will do for now, though
602 */ 612 */
603 namelen = dentry->d_name.len; 613 namelen = dentry->d_name.len;
604 ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &phys_ofs, &alloclen, ALLOC_NORMAL); 614 ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &phys_ofs, &alloclen,
615 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
605 616
606 if (ret) { 617 if (ret) {
607 jffs2_free_raw_inode(ri); 618 jffs2_free_raw_inode(ri);
@@ -627,7 +638,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
627 ri->compr = JFFS2_COMPR_NONE; 638 ri->compr = JFFS2_COMPR_NONE;
628 ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen)); 639 ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen));
629 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 640 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
630 641
631 fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, phys_ofs, ALLOC_NORMAL); 642 fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, phys_ofs, ALLOC_NORMAL);
632 643
633 jffs2_free_raw_inode(ri); 644 jffs2_free_raw_inode(ri);
@@ -639,14 +650,15 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
639 jffs2_clear_inode(inode); 650 jffs2_clear_inode(inode);
640 return PTR_ERR(fn); 651 return PTR_ERR(fn);
641 } 652 }
642 /* No data here. Only a metadata node, which will be 653 /* No data here. Only a metadata node, which will be
643 obsoleted by the first data write 654 obsoleted by the first data write
644 */ 655 */
645 f->metadata = fn; 656 f->metadata = fn;
646 up(&f->sem); 657 up(&f->sem);
647 658
648 jffs2_complete_reservation(c); 659 jffs2_complete_reservation(c);
649 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL); 660 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
661 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
650 if (ret) { 662 if (ret) {
651 /* Eep. */ 663 /* Eep. */
652 jffs2_clear_inode(inode); 664 jffs2_clear_inode(inode);
@@ -682,9 +694,9 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
682 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); 694 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
683 695
684 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); 696 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL);
685 697
686 if (IS_ERR(fd)) { 698 if (IS_ERR(fd)) {
687 /* dirent failed to write. Delete the inode normally 699 /* dirent failed to write. Delete the inode normally
688 as if it were the final unlink() */ 700 as if it were the final unlink() */
689 jffs2_complete_reservation(c); 701 jffs2_complete_reservation(c);
690 jffs2_free_raw_dirent(rd); 702 jffs2_free_raw_dirent(rd);
@@ -716,8 +728,9 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
716 struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb); 728 struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb);
717 struct jffs2_inode_info *victim_f = NULL; 729 struct jffs2_inode_info *victim_f = NULL;
718 uint8_t type; 730 uint8_t type;
731 uint32_t now;
719 732
720 /* The VFS will check for us and prevent trying to rename a 733 /* The VFS will check for us and prevent trying to rename a
721 * file over a directory and vice versa, but if it's a directory, 734 * file over a directory and vice versa, but if it's a directory,
722 * the VFS can't check whether the victim is empty. The filesystem 735 * the VFS can't check whether the victim is empty. The filesystem
723 * needs to do that for itself. 736 * needs to do that for itself.
@@ -739,19 +752,20 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
739 } 752 }
740 753
741 /* XXX: We probably ought to alloc enough space for 754 /* XXX: We probably ought to alloc enough space for
742 both nodes at the same time. Writing the new link, 755 both nodes at the same time. Writing the new link,
743 then getting -ENOSPC, is quite bad :) 756 then getting -ENOSPC, is quite bad :)
744 */ 757 */
745 758
746 /* Make a hard link */ 759 /* Make a hard link */
747 760
748 /* XXX: This is ugly */ 761 /* XXX: This is ugly */
749 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12; 762 type = (old_dentry->d_inode->i_mode & S_IFMT) >> 12;
750 if (!type) type = DT_REG; 763 if (!type) type = DT_REG;
751 764
752 ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i), 765 now = get_seconds();
766 ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i),
753 old_dentry->d_inode->i_ino, type, 767 old_dentry->d_inode->i_ino, type,
754 new_dentry->d_name.name, new_dentry->d_name.len); 768 new_dentry->d_name.name, new_dentry->d_name.len, now);
755 769
756 if (ret) 770 if (ret)
757 return ret; 771 return ret;
@@ -768,14 +782,14 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
768 } 782 }
769 } 783 }
770 784
771 /* If it was a directory we moved, and there was no victim, 785 /* If it was a directory we moved, and there was no victim,
772 increase i_nlink on its new parent */ 786 increase i_nlink on its new parent */
773 if (S_ISDIR(old_dentry->d_inode->i_mode) && !victim_f) 787 if (S_ISDIR(old_dentry->d_inode->i_mode) && !victim_f)
774 new_dir_i->i_nlink++; 788 new_dir_i->i_nlink++;
775 789
776 /* Unlink the original */ 790 /* Unlink the original */
777 ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i), 791 ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
778 old_dentry->d_name.name, old_dentry->d_name.len, NULL); 792 old_dentry->d_name.name, old_dentry->d_name.len, NULL, now);
779 793
780 /* We don't touch inode->i_nlink */ 794 /* We don't touch inode->i_nlink */
781 795
@@ -792,12 +806,15 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
792 /* Might as well let the VFS know */ 806 /* Might as well let the VFS know */
793 d_instantiate(new_dentry, old_dentry->d_inode); 807 d_instantiate(new_dentry, old_dentry->d_inode);
794 atomic_inc(&old_dentry->d_inode->i_count); 808 atomic_inc(&old_dentry->d_inode->i_count);
809 new_dir_i->i_mtime = new_dir_i->i_ctime = ITIME(now);
795 return ret; 810 return ret;
796 } 811 }
797 812
798 if (S_ISDIR(old_dentry->d_inode->i_mode)) 813 if (S_ISDIR(old_dentry->d_inode->i_mode))
799 old_dir_i->i_nlink--; 814 old_dir_i->i_nlink--;
800 815
816 new_dir_i->i_mtime = new_dir_i->i_ctime = old_dir_i->i_mtime = old_dir_i->i_ctime = ITIME(now);
817
801 return 0; 818 return 0;
802} 819}
803 820
diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
index 787d84ac2bcd..dad68fdffe9e 100644
--- a/fs/jffs2/erase.c
+++ b/fs/jffs2/erase.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: erase.c,v 1.80 2005/07/14 19:46:24 joern Exp $ 10 * $Id: erase.c,v 1.85 2005/09/20 14:53:15 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -24,7 +24,7 @@ struct erase_priv_struct {
24 struct jffs2_eraseblock *jeb; 24 struct jffs2_eraseblock *jeb;
25 struct jffs2_sb_info *c; 25 struct jffs2_sb_info *c;
26}; 26};
27 27
28#ifndef __ECOS 28#ifndef __ECOS
29static void jffs2_erase_callback(struct erase_info *); 29static void jffs2_erase_callback(struct erase_info *);
30#endif 30#endif
@@ -48,7 +48,8 @@ static void jffs2_erase_block(struct jffs2_sb_info *c,
48#else /* Linux */ 48#else /* Linux */
49 struct erase_info *instr; 49 struct erase_info *instr;
50 50
51 D1(printk(KERN_DEBUG "jffs2_erase_block(): erase block %#x (range %#x-%#x)\n", jeb->offset, jeb->offset, jeb->offset + c->sector_size)); 51 D1(printk(KERN_DEBUG "jffs2_erase_block(): erase block %#08x (range %#08x-%#08x)\n",
52 jeb->offset, jeb->offset, jeb->offset + c->sector_size));
52 instr = kmalloc(sizeof(struct erase_info) + sizeof(struct erase_priv_struct), GFP_KERNEL); 53 instr = kmalloc(sizeof(struct erase_info) + sizeof(struct erase_priv_struct), GFP_KERNEL);
53 if (!instr) { 54 if (!instr) {
54 printk(KERN_WARNING "kmalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n"); 55 printk(KERN_WARNING "kmalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n");
@@ -70,7 +71,7 @@ static void jffs2_erase_block(struct jffs2_sb_info *c,
70 instr->callback = jffs2_erase_callback; 71 instr->callback = jffs2_erase_callback;
71 instr->priv = (unsigned long)(&instr[1]); 72 instr->priv = (unsigned long)(&instr[1]);
72 instr->fail_addr = 0xffffffff; 73 instr->fail_addr = 0xffffffff;
73 74
74 ((struct erase_priv_struct *)instr->priv)->jeb = jeb; 75 ((struct erase_priv_struct *)instr->priv)->jeb = jeb;
75 ((struct erase_priv_struct *)instr->priv)->c = c; 76 ((struct erase_priv_struct *)instr->priv)->c = c;
76 77
@@ -95,7 +96,7 @@ static void jffs2_erase_block(struct jffs2_sb_info *c,
95 return; 96 return;
96 } 97 }
97 98
98 if (ret == -EROFS) 99 if (ret == -EROFS)
99 printk(KERN_WARNING "Erase at 0x%08x failed immediately: -EROFS. Is the sector locked?\n", jeb->offset); 100 printk(KERN_WARNING "Erase at 0x%08x failed immediately: -EROFS. Is the sector locked?\n", jeb->offset);
100 else 101 else
101 printk(KERN_WARNING "Erase at 0x%08x failed immediately: errno %d\n", jeb->offset, ret); 102 printk(KERN_WARNING "Erase at 0x%08x failed immediately: errno %d\n", jeb->offset, ret);
@@ -196,7 +197,7 @@ static void jffs2_erase_failed(struct jffs2_sb_info *c, struct jffs2_eraseblock
196 c->nr_erasing_blocks--; 197 c->nr_erasing_blocks--;
197 spin_unlock(&c->erase_completion_lock); 198 spin_unlock(&c->erase_completion_lock);
198 wake_up(&c->erase_wait); 199 wake_up(&c->erase_wait);
199} 200}
200 201
201#ifndef __ECOS 202#ifndef __ECOS
202static void jffs2_erase_callback(struct erase_info *instr) 203static void jffs2_erase_callback(struct erase_info *instr)
@@ -208,7 +209,7 @@ static void jffs2_erase_callback(struct erase_info *instr)
208 jffs2_erase_failed(priv->c, priv->jeb, instr->fail_addr); 209 jffs2_erase_failed(priv->c, priv->jeb, instr->fail_addr);
209 } else { 210 } else {
210 jffs2_erase_succeeded(priv->c, priv->jeb); 211 jffs2_erase_succeeded(priv->c, priv->jeb);
211 } 212 }
212 kfree(instr); 213 kfree(instr);
213} 214}
214#endif /* !__ECOS */ 215#endif /* !__ECOS */
@@ -226,13 +227,13 @@ static inline void jffs2_remove_node_refs_from_ino_list(struct jffs2_sb_info *c,
226 /* Walk the inode's list once, removing any nodes from this eraseblock */ 227 /* Walk the inode's list once, removing any nodes from this eraseblock */
227 while (1) { 228 while (1) {
228 if (!(*prev)->next_in_ino) { 229 if (!(*prev)->next_in_ino) {
229 /* We're looking at the jffs2_inode_cache, which is 230 /* We're looking at the jffs2_inode_cache, which is
230 at the end of the linked list. Stash it and continue 231 at the end of the linked list. Stash it and continue
231 from the beginning of the list */ 232 from the beginning of the list */
232 ic = (struct jffs2_inode_cache *)(*prev); 233 ic = (struct jffs2_inode_cache *)(*prev);
233 prev = &ic->nodes; 234 prev = &ic->nodes;
234 continue; 235 continue;
235 } 236 }
236 237
237 if (SECTOR_ADDR((*prev)->flash_offset) == jeb->offset) { 238 if (SECTOR_ADDR((*prev)->flash_offset) == jeb->offset) {
238 /* It's in the block we're erasing */ 239 /* It's in the block we're erasing */
@@ -266,7 +267,7 @@ static inline void jffs2_remove_node_refs_from_ino_list(struct jffs2_sb_info *c,
266 printk(KERN_DEBUG "After remove_node_refs_from_ino_list: \n" KERN_DEBUG); 267 printk(KERN_DEBUG "After remove_node_refs_from_ino_list: \n" KERN_DEBUG);
267 268
268 this = ic->nodes; 269 this = ic->nodes;
269 270
270 while(this) { 271 while(this) {
271 printk( "0x%08x(%d)->", ref_offset(this), ref_flags(this)); 272 printk( "0x%08x(%d)->", ref_offset(this), ref_flags(this));
272 if (++i == 5) { 273 if (++i == 5) {
@@ -289,7 +290,7 @@ static void jffs2_free_all_node_refs(struct jffs2_sb_info *c, struct jffs2_erase
289 while(jeb->first_node) { 290 while(jeb->first_node) {
290 ref = jeb->first_node; 291 ref = jeb->first_node;
291 jeb->first_node = ref->next_phys; 292 jeb->first_node = ref->next_phys;
292 293
293 /* Remove from the inode-list */ 294 /* Remove from the inode-list */
294 if (ref->next_in_ino) 295 if (ref->next_in_ino)
295 jffs2_remove_node_refs_from_ino_list(c, ref, jeb); 296 jffs2_remove_node_refs_from_ino_list(c, ref, jeb);
@@ -306,7 +307,7 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl
306 uint32_t ofs; 307 uint32_t ofs;
307 size_t retlen; 308 size_t retlen;
308 int ret = -EIO; 309 int ret = -EIO;
309 310
310 ebuf = kmalloc(PAGE_SIZE, GFP_KERNEL); 311 ebuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
311 if (!ebuf) { 312 if (!ebuf) {
312 printk(KERN_WARNING "Failed to allocate page buffer for verifying erase at 0x%08x. Refiling\n", jeb->offset); 313 printk(KERN_WARNING "Failed to allocate page buffer for verifying erase at 0x%08x. Refiling\n", jeb->offset);
@@ -360,7 +361,7 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
360 case -EIO: goto filebad; 361 case -EIO: goto filebad;
361 } 362 }
362 363
363 /* Write the erase complete marker */ 364 /* Write the erase complete marker */
364 D1(printk(KERN_DEBUG "Writing erased marker to block at 0x%08x\n", jeb->offset)); 365 D1(printk(KERN_DEBUG "Writing erased marker to block at 0x%08x\n", jeb->offset));
365 bad_offset = jeb->offset; 366 bad_offset = jeb->offset;
366 367
@@ -398,7 +399,7 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
398 vecs[0].iov_base = (unsigned char *) &marker; 399 vecs[0].iov_base = (unsigned char *) &marker;
399 vecs[0].iov_len = sizeof(marker); 400 vecs[0].iov_len = sizeof(marker);
400 ret = jffs2_flash_direct_writev(c, vecs, 1, jeb->offset, &retlen); 401 ret = jffs2_flash_direct_writev(c, vecs, 1, jeb->offset, &retlen);
401 402
402 if (ret || retlen != sizeof(marker)) { 403 if (ret || retlen != sizeof(marker)) {
403 if (ret) 404 if (ret)
404 printk(KERN_WARNING "Write clean marker to block at 0x%08x failed: %d\n", 405 printk(KERN_WARNING "Write clean marker to block at 0x%08x failed: %d\n",
@@ -415,9 +416,9 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
415 marker_ref->next_phys = NULL; 416 marker_ref->next_phys = NULL;
416 marker_ref->flash_offset = jeb->offset | REF_NORMAL; 417 marker_ref->flash_offset = jeb->offset | REF_NORMAL;
417 marker_ref->__totlen = c->cleanmarker_size; 418 marker_ref->__totlen = c->cleanmarker_size;
418 419
419 jeb->first_node = jeb->last_node = marker_ref; 420 jeb->first_node = jeb->last_node = marker_ref;
420 421
421 jeb->free_size = c->sector_size - c->cleanmarker_size; 422 jeb->free_size = c->sector_size - c->cleanmarker_size;
422 jeb->used_size = c->cleanmarker_size; 423 jeb->used_size = c->cleanmarker_size;
423 jeb->dirty_size = 0; 424 jeb->dirty_size = 0;
@@ -429,8 +430,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
429 c->free_size += jeb->free_size; 430 c->free_size += jeb->free_size;
430 c->used_size += jeb->used_size; 431 c->used_size += jeb->used_size;
431 432
432 ACCT_SANITY_CHECK(c,jeb); 433 jffs2_dbg_acct_sanity_check_nolock(c,jeb);
433 D1(ACCT_PARANOIA_CHECK(jeb)); 434 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
434 435
435 list_add_tail(&jeb->list, &c->free_list); 436 list_add_tail(&jeb->list, &c->free_list);
436 c->nr_erasing_blocks--; 437 c->nr_erasing_blocks--;
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c
index 8279bf0133ff..935f273dc57b 100644
--- a/fs/jffs2/file.c
+++ b/fs/jffs2/file.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: file.c,v 1.102 2005/07/06 12:13:09 dwmw2 Exp $ 10 * $Id: file.c,v 1.104 2005/10/18 23:29:35 tpoynor Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -34,8 +34,8 @@ int jffs2_fsync(struct file *filp, struct dentry *dentry, int datasync)
34 34
35 /* Trigger GC to flush any pending writes for this inode */ 35 /* Trigger GC to flush any pending writes for this inode */
36 jffs2_flush_wbuf_gc(c, inode->i_ino); 36 jffs2_flush_wbuf_gc(c, inode->i_ino);
37 37
38 return 0; 38 return 0;
39} 39}
40 40
41struct file_operations jffs2_file_operations = 41struct file_operations jffs2_file_operations =
@@ -107,7 +107,7 @@ static int jffs2_readpage (struct file *filp, struct page *pg)
107{ 107{
108 struct jffs2_inode_info *f = JFFS2_INODE_INFO(pg->mapping->host); 108 struct jffs2_inode_info *f = JFFS2_INODE_INFO(pg->mapping->host);
109 int ret; 109 int ret;
110 110
111 down(&f->sem); 111 down(&f->sem);
112 ret = jffs2_do_readpage_unlock(pg->mapping->host, pg); 112 ret = jffs2_do_readpage_unlock(pg->mapping->host, pg);
113 up(&f->sem); 113 up(&f->sem);
@@ -130,11 +130,12 @@ static int jffs2_prepare_write (struct file *filp, struct page *pg,
130 struct jffs2_raw_inode ri; 130 struct jffs2_raw_inode ri;
131 struct jffs2_full_dnode *fn; 131 struct jffs2_full_dnode *fn;
132 uint32_t phys_ofs, alloc_len; 132 uint32_t phys_ofs, alloc_len;
133 133
134 D1(printk(KERN_DEBUG "Writing new hole frag 0x%x-0x%x between current EOF and new page\n", 134 D1(printk(KERN_DEBUG "Writing new hole frag 0x%x-0x%x between current EOF and new page\n",
135 (unsigned int)inode->i_size, pageofs)); 135 (unsigned int)inode->i_size, pageofs));
136 136
137 ret = jffs2_reserve_space(c, sizeof(ri), &phys_ofs, &alloc_len, ALLOC_NORMAL); 137 ret = jffs2_reserve_space(c, sizeof(ri), &phys_ofs, &alloc_len,
138 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
138 if (ret) 139 if (ret)
139 return ret; 140 return ret;
140 141
@@ -159,7 +160,7 @@ static int jffs2_prepare_write (struct file *filp, struct page *pg,
159 ri.compr = JFFS2_COMPR_ZERO; 160 ri.compr = JFFS2_COMPR_ZERO;
160 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8)); 161 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
161 ri.data_crc = cpu_to_je32(0); 162 ri.data_crc = cpu_to_je32(0);
162 163
163 fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, ALLOC_NORMAL); 164 fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, ALLOC_NORMAL);
164 165
165 if (IS_ERR(fn)) { 166 if (IS_ERR(fn)) {
@@ -186,7 +187,7 @@ static int jffs2_prepare_write (struct file *filp, struct page *pg,
186 inode->i_size = pageofs; 187 inode->i_size = pageofs;
187 up(&f->sem); 188 up(&f->sem);
188 } 189 }
189 190
190 /* Read in the page if it wasn't already present, unless it's a whole page */ 191 /* Read in the page if it wasn't already present, unless it's a whole page */
191 if (!PageUptodate(pg) && (start || end < PAGE_CACHE_SIZE)) { 192 if (!PageUptodate(pg) && (start || end < PAGE_CACHE_SIZE)) {
192 down(&f->sem); 193 down(&f->sem);
@@ -217,7 +218,7 @@ static int jffs2_commit_write (struct file *filp, struct page *pg,
217 if (!start && end == PAGE_CACHE_SIZE) { 218 if (!start && end == PAGE_CACHE_SIZE) {
218 /* We need to avoid deadlock with page_cache_read() in 219 /* We need to avoid deadlock with page_cache_read() in
219 jffs2_garbage_collect_pass(). So we have to mark the 220 jffs2_garbage_collect_pass(). So we have to mark the
220 page up to date, to prevent page_cache_read() from 221 page up to date, to prevent page_cache_read() from
221 trying to re-lock it. */ 222 trying to re-lock it. */
222 SetPageUptodate(pg); 223 SetPageUptodate(pg);
223 } 224 }
@@ -251,7 +252,7 @@ static int jffs2_commit_write (struct file *filp, struct page *pg,
251 /* There was an error writing. */ 252 /* There was an error writing. */
252 SetPageError(pg); 253 SetPageError(pg);
253 } 254 }
254 255
255 /* Adjust writtenlen for the padding we did, so we don't confuse our caller */ 256 /* Adjust writtenlen for the padding we did, so we don't confuse our caller */
256 if (writtenlen < (start&3)) 257 if (writtenlen < (start&3))
257 writtenlen = 0; 258 writtenlen = 0;
@@ -262,7 +263,7 @@ static int jffs2_commit_write (struct file *filp, struct page *pg,
262 if (inode->i_size < (pg->index << PAGE_CACHE_SHIFT) + start + writtenlen) { 263 if (inode->i_size < (pg->index << PAGE_CACHE_SHIFT) + start + writtenlen) {
263 inode->i_size = (pg->index << PAGE_CACHE_SHIFT) + start + writtenlen; 264 inode->i_size = (pg->index << PAGE_CACHE_SHIFT) + start + writtenlen;
264 inode->i_blocks = (inode->i_size + 511) >> 9; 265 inode->i_blocks = (inode->i_size + 511) >> 9;
265 266
266 inode->i_ctime = inode->i_mtime = ITIME(je32_to_cpu(ri->ctime)); 267 inode->i_ctime = inode->i_mtime = ITIME(je32_to_cpu(ri->ctime));
267 } 268 }
268 } 269 }
@@ -271,13 +272,13 @@ static int jffs2_commit_write (struct file *filp, struct page *pg,
271 272
272 if (start+writtenlen < end) { 273 if (start+writtenlen < end) {
273 /* generic_file_write has written more to the page cache than we've 274 /* generic_file_write has written more to the page cache than we've
274 actually written to the medium. Mark the page !Uptodate so that 275 actually written to the medium. Mark the page !Uptodate so that
275 it gets reread */ 276 it gets reread */
276 D1(printk(KERN_DEBUG "jffs2_commit_write(): Not all bytes written. Marking page !uptodate\n")); 277 D1(printk(KERN_DEBUG "jffs2_commit_write(): Not all bytes written. Marking page !uptodate\n"));
277 SetPageError(pg); 278 SetPageError(pg);
278 ClearPageUptodate(pg); 279 ClearPageUptodate(pg);
279 } 280 }
280 281
281 D1(printk(KERN_DEBUG "jffs2_commit_write() returning %d\n",writtenlen?writtenlen:ret)); 282 D1(printk(KERN_DEBUG "jffs2_commit_write() returning %d\n",start+writtenlen==end?0:ret));
282 return writtenlen?writtenlen:ret; 283 return start+writtenlen==end?0:ret;
283} 284}
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 5687c3f42002..543420665c5b 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: fs.c,v 1.56 2005/07/06 12:13:09 dwmw2 Exp $ 10 * $Id: fs.c,v 1.66 2005/09/27 13:17:29 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -40,7 +40,7 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
40 int ret; 40 int ret;
41 D1(printk(KERN_DEBUG "jffs2_setattr(): ino #%lu\n", inode->i_ino)); 41 D1(printk(KERN_DEBUG "jffs2_setattr(): ino #%lu\n", inode->i_ino));
42 ret = inode_change_ok(inode, iattr); 42 ret = inode_change_ok(inode, iattr);
43 if (ret) 43 if (ret)
44 return ret; 44 return ret;
45 45
46 /* Special cases - we don't want more than one data node 46 /* Special cases - we don't want more than one data node
@@ -73,8 +73,9 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
73 kfree(mdata); 73 kfree(mdata);
74 return -ENOMEM; 74 return -ENOMEM;
75 } 75 }
76 76
77 ret = jffs2_reserve_space(c, sizeof(*ri) + mdatalen, &phys_ofs, &alloclen, ALLOC_NORMAL); 77 ret = jffs2_reserve_space(c, sizeof(*ri) + mdatalen, &phys_ofs, &alloclen,
78 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
78 if (ret) { 79 if (ret) {
79 jffs2_free_raw_inode(ri); 80 jffs2_free_raw_inode(ri);
80 if (S_ISLNK(inode->i_mode & S_IFMT)) 81 if (S_ISLNK(inode->i_mode & S_IFMT))
@@ -83,7 +84,7 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
83 } 84 }
84 down(&f->sem); 85 down(&f->sem);
85 ivalid = iattr->ia_valid; 86 ivalid = iattr->ia_valid;
86 87
87 ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 88 ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
88 ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE); 89 ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
89 ri->totlen = cpu_to_je32(sizeof(*ri) + mdatalen); 90 ri->totlen = cpu_to_je32(sizeof(*ri) + mdatalen);
@@ -99,7 +100,7 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
99 if (iattr->ia_mode & S_ISGID && 100 if (iattr->ia_mode & S_ISGID &&
100 !in_group_p(je16_to_cpu(ri->gid)) && !capable(CAP_FSETID)) 101 !in_group_p(je16_to_cpu(ri->gid)) && !capable(CAP_FSETID))
101 ri->mode = cpu_to_jemode(iattr->ia_mode & ~S_ISGID); 102 ri->mode = cpu_to_jemode(iattr->ia_mode & ~S_ISGID);
102 else 103 else
103 ri->mode = cpu_to_jemode(iattr->ia_mode); 104 ri->mode = cpu_to_jemode(iattr->ia_mode);
104 else 105 else
105 ri->mode = cpu_to_jemode(inode->i_mode); 106 ri->mode = cpu_to_jemode(inode->i_mode);
@@ -128,7 +129,7 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
128 new_metadata = jffs2_write_dnode(c, f, ri, mdata, mdatalen, phys_ofs, ALLOC_NORMAL); 129 new_metadata = jffs2_write_dnode(c, f, ri, mdata, mdatalen, phys_ofs, ALLOC_NORMAL);
129 if (S_ISLNK(inode->i_mode)) 130 if (S_ISLNK(inode->i_mode))
130 kfree(mdata); 131 kfree(mdata);
131 132
132 if (IS_ERR(new_metadata)) { 133 if (IS_ERR(new_metadata)) {
133 jffs2_complete_reservation(c); 134 jffs2_complete_reservation(c);
134 jffs2_free_raw_inode(ri); 135 jffs2_free_raw_inode(ri);
@@ -147,7 +148,7 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
147 old_metadata = f->metadata; 148 old_metadata = f->metadata;
148 149
149 if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) 150 if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size)
150 jffs2_truncate_fraglist (c, &f->fragtree, iattr->ia_size); 151 jffs2_truncate_fragtree (c, &f->fragtree, iattr->ia_size);
151 152
152 if (ivalid & ATTR_SIZE && inode->i_size < iattr->ia_size) { 153 if (ivalid & ATTR_SIZE && inode->i_size < iattr->ia_size) {
153 jffs2_add_full_dnode_to_inode(c, f, new_metadata); 154 jffs2_add_full_dnode_to_inode(c, f, new_metadata);
@@ -166,7 +167,7 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
166 jffs2_complete_reservation(c); 167 jffs2_complete_reservation(c);
167 168
168 /* We have to do the vmtruncate() without f->sem held, since 169 /* We have to do the vmtruncate() without f->sem held, since
169 some pages may be locked and waiting for it in readpage(). 170 some pages may be locked and waiting for it in readpage().
170 We are protected from a simultaneous write() extending i_size 171 We are protected from a simultaneous write() extending i_size
171 back past iattr->ia_size, because do_truncate() holds the 172 back past iattr->ia_size, because do_truncate() holds the
172 generic inode semaphore. */ 173 generic inode semaphore. */
@@ -194,31 +195,27 @@ int jffs2_statfs(struct super_block *sb, struct kstatfs *buf)
194 buf->f_namelen = JFFS2_MAX_NAME_LEN; 195 buf->f_namelen = JFFS2_MAX_NAME_LEN;
195 196
196 spin_lock(&c->erase_completion_lock); 197 spin_lock(&c->erase_completion_lock);
197
198 avail = c->dirty_size + c->free_size; 198 avail = c->dirty_size + c->free_size;
199 if (avail > c->sector_size * c->resv_blocks_write) 199 if (avail > c->sector_size * c->resv_blocks_write)
200 avail -= c->sector_size * c->resv_blocks_write; 200 avail -= c->sector_size * c->resv_blocks_write;
201 else 201 else
202 avail = 0; 202 avail = 0;
203 spin_unlock(&c->erase_completion_lock);
203 204
204 buf->f_bavail = buf->f_bfree = avail >> PAGE_SHIFT; 205 buf->f_bavail = buf->f_bfree = avail >> PAGE_SHIFT;
205 206
206 D2(jffs2_dump_block_lists(c));
207
208 spin_unlock(&c->erase_completion_lock);
209
210 return 0; 207 return 0;
211} 208}
212 209
213 210
214void jffs2_clear_inode (struct inode *inode) 211void jffs2_clear_inode (struct inode *inode)
215{ 212{
216 /* We can forget about this inode for now - drop all 213 /* We can forget about this inode for now - drop all
217 * the nodelists associated with it, etc. 214 * the nodelists associated with it, etc.
218 */ 215 */
219 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); 216 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
220 struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); 217 struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
221 218
222 D1(printk(KERN_DEBUG "jffs2_clear_inode(): ino #%lu mode %o\n", inode->i_ino, inode->i_mode)); 219 D1(printk(KERN_DEBUG "jffs2_clear_inode(): ino #%lu mode %o\n", inode->i_ino, inode->i_mode));
223 220
224 jffs2_do_clear_inode(c, f); 221 jffs2_do_clear_inode(c, f);
@@ -237,7 +234,7 @@ void jffs2_read_inode (struct inode *inode)
237 c = JFFS2_SB_INFO(inode->i_sb); 234 c = JFFS2_SB_INFO(inode->i_sb);
238 235
239 jffs2_init_inode_info(f); 236 jffs2_init_inode_info(f);
240 237
241 ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node); 238 ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node);
242 239
243 if (ret) { 240 if (ret) {
@@ -257,14 +254,14 @@ void jffs2_read_inode (struct inode *inode)
257 254
258 inode->i_blksize = PAGE_SIZE; 255 inode->i_blksize = PAGE_SIZE;
259 inode->i_blocks = (inode->i_size + 511) >> 9; 256 inode->i_blocks = (inode->i_size + 511) >> 9;
260 257
261 switch (inode->i_mode & S_IFMT) { 258 switch (inode->i_mode & S_IFMT) {
262 jint16_t rdev; 259 jint16_t rdev;
263 260
264 case S_IFLNK: 261 case S_IFLNK:
265 inode->i_op = &jffs2_symlink_inode_operations; 262 inode->i_op = &jffs2_symlink_inode_operations;
266 break; 263 break;
267 264
268 case S_IFDIR: 265 case S_IFDIR:
269 { 266 {
270 struct jffs2_full_dirent *fd; 267 struct jffs2_full_dirent *fd;
@@ -301,7 +298,7 @@ void jffs2_read_inode (struct inode *inode)
301 jffs2_do_clear_inode(c, f); 298 jffs2_do_clear_inode(c, f);
302 make_bad_inode(inode); 299 make_bad_inode(inode);
303 return; 300 return;
304 } 301 }
305 302
306 case S_IFSOCK: 303 case S_IFSOCK:
307 case S_IFIFO: 304 case S_IFIFO:
@@ -357,11 +354,11 @@ int jffs2_remount_fs (struct super_block *sb, int *flags, char *data)
357 down(&c->alloc_sem); 354 down(&c->alloc_sem);
358 jffs2_flush_wbuf_pad(c); 355 jffs2_flush_wbuf_pad(c);
359 up(&c->alloc_sem); 356 up(&c->alloc_sem);
360 } 357 }
361 358
362 if (!(*flags & MS_RDONLY)) 359 if (!(*flags & MS_RDONLY))
363 jffs2_start_garbage_collect_thread(c); 360 jffs2_start_garbage_collect_thread(c);
364 361
365 *flags |= MS_NOATIME; 362 *flags |= MS_NOATIME;
366 363
367 return 0; 364 return 0;
@@ -395,9 +392,9 @@ struct inode *jffs2_new_inode (struct inode *dir_i, int mode, struct jffs2_raw_i
395 D1(printk(KERN_DEBUG "jffs2_new_inode(): dir_i %ld, mode 0x%x\n", dir_i->i_ino, mode)); 392 D1(printk(KERN_DEBUG "jffs2_new_inode(): dir_i %ld, mode 0x%x\n", dir_i->i_ino, mode));
396 393
397 c = JFFS2_SB_INFO(sb); 394 c = JFFS2_SB_INFO(sb);
398 395
399 inode = new_inode(sb); 396 inode = new_inode(sb);
400 397
401 if (!inode) 398 if (!inode)
402 return ERR_PTR(-ENOMEM); 399 return ERR_PTR(-ENOMEM);
403 400
@@ -461,40 +458,24 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
461#endif 458#endif
462 459
463 c->flash_size = c->mtd->size; 460 c->flash_size = c->mtd->size;
464 461 c->sector_size = c->mtd->erasesize;
465 /*
466 * Check, if we have to concatenate physical blocks to larger virtual blocks
467 * to reduce the memorysize for c->blocks. (kmalloc allows max. 128K allocation)
468 */
469 c->sector_size = c->mtd->erasesize;
470 blocks = c->flash_size / c->sector_size; 462 blocks = c->flash_size / c->sector_size;
471 if (!(c->mtd->flags & MTD_NO_VIRTBLOCKS)) {
472 while ((blocks * sizeof (struct jffs2_eraseblock)) > (128 * 1024)) {
473 blocks >>= 1;
474 c->sector_size <<= 1;
475 }
476 }
477 463
478 /* 464 /*
479 * Size alignment check 465 * Size alignment check
480 */ 466 */
481 if ((c->sector_size * blocks) != c->flash_size) { 467 if ((c->sector_size * blocks) != c->flash_size) {
482 c->flash_size = c->sector_size * blocks; 468 c->flash_size = c->sector_size * blocks;
483 printk(KERN_INFO "jffs2: Flash size not aligned to erasesize, reducing to %dKiB\n", 469 printk(KERN_INFO "jffs2: Flash size not aligned to erasesize, reducing to %dKiB\n",
484 c->flash_size / 1024); 470 c->flash_size / 1024);
485 } 471 }
486 472
487 if (c->sector_size != c->mtd->erasesize)
488 printk(KERN_INFO "jffs2: Erase block size too small (%dKiB). Using virtual blocks size (%dKiB) instead\n",
489 c->mtd->erasesize / 1024, c->sector_size / 1024);
490
491 if (c->flash_size < 5*c->sector_size) { 473 if (c->flash_size < 5*c->sector_size) {
492 printk(KERN_ERR "jffs2: Too few erase blocks (%d)\n", c->flash_size / c->sector_size); 474 printk(KERN_ERR "jffs2: Too few erase blocks (%d)\n", c->flash_size / c->sector_size);
493 return -EINVAL; 475 return -EINVAL;
494 } 476 }
495 477
496 c->cleanmarker_size = sizeof(struct jffs2_unknown_node); 478 c->cleanmarker_size = sizeof(struct jffs2_unknown_node);
497 /* Joern -- stick alignment for weird 8-byte-page flash here */
498 479
499 /* NAND (or other bizarre) flash... do setup accordingly */ 480 /* NAND (or other bizarre) flash... do setup accordingly */
500 ret = jffs2_flash_setup(c); 481 ret = jffs2_flash_setup(c);
@@ -517,7 +498,7 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
517 root_i = iget(sb, 1); 498 root_i = iget(sb, 1);
518 if (is_bad_inode(root_i)) { 499 if (is_bad_inode(root_i)) {
519 D1(printk(KERN_WARNING "get root inode failed\n")); 500 D1(printk(KERN_WARNING "get root inode failed\n"));
520 goto out_nodes; 501 goto out_root_i;
521 } 502 }
522 503
523 D1(printk(KERN_DEBUG "jffs2_do_fill_super(): d_alloc_root()\n")); 504 D1(printk(KERN_DEBUG "jffs2_do_fill_super(): d_alloc_root()\n"));
@@ -535,10 +516,9 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
535 516
536 out_root_i: 517 out_root_i:
537 iput(root_i); 518 iput(root_i);
538 out_nodes:
539 jffs2_free_ino_caches(c); 519 jffs2_free_ino_caches(c);
540 jffs2_free_raw_node_refs(c); 520 jffs2_free_raw_node_refs(c);
541 if (c->mtd->flags & MTD_NO_VIRTBLOCKS) 521 if (jffs2_blocks_use_vmalloc(c))
542 vfree(c->blocks); 522 vfree(c->blocks);
543 else 523 else
544 kfree(c->blocks); 524 kfree(c->blocks);
@@ -563,16 +543,16 @@ struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
563 struct jffs2_inode_cache *ic; 543 struct jffs2_inode_cache *ic;
564 if (!nlink) { 544 if (!nlink) {
565 /* The inode has zero nlink but its nodes weren't yet marked 545 /* The inode has zero nlink but its nodes weren't yet marked
566 obsolete. This has to be because we're still waiting for 546 obsolete. This has to be because we're still waiting for
567 the final (close() and) iput() to happen. 547 the final (close() and) iput() to happen.
568 548
569 There's a possibility that the final iput() could have 549 There's a possibility that the final iput() could have
570 happened while we were contemplating. In order to ensure 550 happened while we were contemplating. In order to ensure
571 that we don't cause a new read_inode() (which would fail) 551 that we don't cause a new read_inode() (which would fail)
572 for the inode in question, we use ilookup() in this case 552 for the inode in question, we use ilookup() in this case
573 instead of iget(). 553 instead of iget().
574 554
575 The nlink can't _become_ zero at this point because we're 555 The nlink can't _become_ zero at this point because we're
576 holding the alloc_sem, and jffs2_do_unlink() would also 556 holding the alloc_sem, and jffs2_do_unlink() would also
577 need that while decrementing nlink on any inode. 557 need that while decrementing nlink on any inode.
578 */ 558 */
@@ -619,19 +599,19 @@ struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
619 return JFFS2_INODE_INFO(inode); 599 return JFFS2_INODE_INFO(inode);
620} 600}
621 601
622unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c, 602unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c,
623 struct jffs2_inode_info *f, 603 struct jffs2_inode_info *f,
624 unsigned long offset, 604 unsigned long offset,
625 unsigned long *priv) 605 unsigned long *priv)
626{ 606{
627 struct inode *inode = OFNI_EDONI_2SFFJ(f); 607 struct inode *inode = OFNI_EDONI_2SFFJ(f);
628 struct page *pg; 608 struct page *pg;
629 609
630 pg = read_cache_page(inode->i_mapping, offset >> PAGE_CACHE_SHIFT, 610 pg = read_cache_page(inode->i_mapping, offset >> PAGE_CACHE_SHIFT,
631 (void *)jffs2_do_readpage_unlock, inode); 611 (void *)jffs2_do_readpage_unlock, inode);
632 if (IS_ERR(pg)) 612 if (IS_ERR(pg))
633 return (void *)pg; 613 return (void *)pg;
634 614
635 *priv = (unsigned long)pg; 615 *priv = (unsigned long)pg;
636 return kmap(pg); 616 return kmap(pg);
637} 617}
@@ -648,7 +628,7 @@ void jffs2_gc_release_page(struct jffs2_sb_info *c,
648 628
649static int jffs2_flash_setup(struct jffs2_sb_info *c) { 629static int jffs2_flash_setup(struct jffs2_sb_info *c) {
650 int ret = 0; 630 int ret = 0;
651 631
652 if (jffs2_cleanmarker_oob(c)) { 632 if (jffs2_cleanmarker_oob(c)) {
653 /* NAND flash... do setup accordingly */ 633 /* NAND flash... do setup accordingly */
654 ret = jffs2_nand_flash_setup(c); 634 ret = jffs2_nand_flash_setup(c);
@@ -662,14 +642,21 @@ static int jffs2_flash_setup(struct jffs2_sb_info *c) {
662 if (ret) 642 if (ret)
663 return ret; 643 return ret;
664 } 644 }
665 645
666 /* and Dataflash */ 646 /* and Dataflash */
667 if (jffs2_dataflash(c)) { 647 if (jffs2_dataflash(c)) {
668 ret = jffs2_dataflash_setup(c); 648 ret = jffs2_dataflash_setup(c);
669 if (ret) 649 if (ret)
670 return ret; 650 return ret;
671 } 651 }
672 652
653 /* and Intel "Sibley" flash */
654 if (jffs2_nor_wbuf_flash(c)) {
655 ret = jffs2_nor_wbuf_flash_setup(c);
656 if (ret)
657 return ret;
658 }
659
673 return ret; 660 return ret;
674} 661}
675 662
@@ -683,9 +670,14 @@ void jffs2_flash_cleanup(struct jffs2_sb_info *c) {
683 if (jffs2_nor_ecc(c)) { 670 if (jffs2_nor_ecc(c)) {
684 jffs2_nor_ecc_flash_cleanup(c); 671 jffs2_nor_ecc_flash_cleanup(c);
685 } 672 }
686 673
687 /* and DataFlash */ 674 /* and DataFlash */
688 if (jffs2_dataflash(c)) { 675 if (jffs2_dataflash(c)) {
689 jffs2_dataflash_cleanup(c); 676 jffs2_dataflash_cleanup(c);
690 } 677 }
678
679 /* and Intel "Sibley" flash */
680 if (jffs2_nor_wbuf_flash(c)) {
681 jffs2_nor_wbuf_flash_cleanup(c);
682 }
691} 683}
diff --git a/fs/jffs2/gc.c b/fs/jffs2/gc.c
index 7086cd634503..f9ffece453a3 100644
--- a/fs/jffs2/gc.c
+++ b/fs/jffs2/gc.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: gc.c,v 1.148 2005/04/09 10:47:00 dedekind Exp $ 10 * $Id: gc.c,v 1.155 2005/11/07 11:14:39 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -21,14 +21,14 @@
21#include "nodelist.h" 21#include "nodelist.h"
22#include "compr.h" 22#include "compr.h"
23 23
24static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c, 24static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
25 struct jffs2_inode_cache *ic, 25 struct jffs2_inode_cache *ic,
26 struct jffs2_raw_node_ref *raw); 26 struct jffs2_raw_node_ref *raw);
27static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 27static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
28 struct jffs2_inode_info *f, struct jffs2_full_dnode *fd); 28 struct jffs2_inode_info *f, struct jffs2_full_dnode *fd);
29static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 29static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
30 struct jffs2_inode_info *f, struct jffs2_full_dirent *fd); 30 struct jffs2_inode_info *f, struct jffs2_full_dirent *fd);
31static int jffs2_garbage_collect_deletion_dirent(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 31static int jffs2_garbage_collect_deletion_dirent(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
32 struct jffs2_inode_info *f, struct jffs2_full_dirent *fd); 32 struct jffs2_inode_info *f, struct jffs2_full_dirent *fd);
33static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 33static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
34 struct jffs2_inode_info *f, struct jffs2_full_dnode *fn, 34 struct jffs2_inode_info *f, struct jffs2_full_dnode *fn,
@@ -55,7 +55,7 @@ again:
55 D1(printk(KERN_DEBUG "Picking block from bad_used_list to GC next\n")); 55 D1(printk(KERN_DEBUG "Picking block from bad_used_list to GC next\n"));
56 nextlist = &c->bad_used_list; 56 nextlist = &c->bad_used_list;
57 } else if (n < 50 && !list_empty(&c->erasable_list)) { 57 } else if (n < 50 && !list_empty(&c->erasable_list)) {
58 /* Note that most of them will have gone directly to be erased. 58 /* Note that most of them will have gone directly to be erased.
59 So don't favour the erasable_list _too_ much. */ 59 So don't favour the erasable_list _too_ much. */
60 D1(printk(KERN_DEBUG "Picking block from erasable_list to GC next\n")); 60 D1(printk(KERN_DEBUG "Picking block from erasable_list to GC next\n"));
61 nextlist = &c->erasable_list; 61 nextlist = &c->erasable_list;
@@ -101,7 +101,7 @@ again:
101 printk(KERN_WARNING "Eep. ret->gc_node for block at 0x%08x is NULL\n", ret->offset); 101 printk(KERN_WARNING "Eep. ret->gc_node for block at 0x%08x is NULL\n", ret->offset);
102 BUG(); 102 BUG();
103 } 103 }
104 104
105 /* Have we accidentally picked a clean block with wasted space ? */ 105 /* Have we accidentally picked a clean block with wasted space ? */
106 if (ret->wasted_size) { 106 if (ret->wasted_size) {
107 D1(printk(KERN_DEBUG "Converting wasted_size %08x to dirty_size\n", ret->wasted_size)); 107 D1(printk(KERN_DEBUG "Converting wasted_size %08x to dirty_size\n", ret->wasted_size));
@@ -111,7 +111,6 @@ again:
111 ret->wasted_size = 0; 111 ret->wasted_size = 0;
112 } 112 }
113 113
114 D2(jffs2_dump_block_lists(c));
115 return ret; 114 return ret;
116} 115}
117 116
@@ -137,12 +136,12 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
137 136
138 /* We can't start doing GC yet. We haven't finished checking 137 /* We can't start doing GC yet. We haven't finished checking
139 the node CRCs etc. Do it now. */ 138 the node CRCs etc. Do it now. */
140 139
141 /* checked_ino is protected by the alloc_sem */ 140 /* checked_ino is protected by the alloc_sem */
142 if (c->checked_ino > c->highest_ino) { 141 if (c->checked_ino > c->highest_ino) {
143 printk(KERN_CRIT "Checked all inodes but still 0x%x bytes of unchecked space?\n", 142 printk(KERN_CRIT "Checked all inodes but still 0x%x bytes of unchecked space?\n",
144 c->unchecked_size); 143 c->unchecked_size);
145 D2(jffs2_dump_block_lists(c)); 144 jffs2_dbg_dump_block_lists_nolock(c);
146 spin_unlock(&c->erase_completion_lock); 145 spin_unlock(&c->erase_completion_lock);
147 BUG(); 146 BUG();
148 } 147 }
@@ -179,7 +178,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
179 178
180 case INO_STATE_READING: 179 case INO_STATE_READING:
181 /* We need to wait for it to finish, lest we move on 180 /* We need to wait for it to finish, lest we move on
182 and trigger the BUG() above while we haven't yet 181 and trigger the BUG() above while we haven't yet
183 finished checking all its nodes */ 182 finished checking all its nodes */
184 D1(printk(KERN_DEBUG "Waiting for ino #%u to finish reading\n", ic->ino)); 183 D1(printk(KERN_DEBUG "Waiting for ino #%u to finish reading\n", ic->ino));
185 up(&c->alloc_sem); 184 up(&c->alloc_sem);
@@ -229,13 +228,13 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
229 } 228 }
230 229
231 raw = jeb->gc_node; 230 raw = jeb->gc_node;
232 231
233 while(ref_obsolete(raw)) { 232 while(ref_obsolete(raw)) {
234 D1(printk(KERN_DEBUG "Node at 0x%08x is obsolete... skipping\n", ref_offset(raw))); 233 D1(printk(KERN_DEBUG "Node at 0x%08x is obsolete... skipping\n", ref_offset(raw)));
235 raw = raw->next_phys; 234 raw = raw->next_phys;
236 if (unlikely(!raw)) { 235 if (unlikely(!raw)) {
237 printk(KERN_WARNING "eep. End of raw list while still supposedly nodes to GC\n"); 236 printk(KERN_WARNING "eep. End of raw list while still supposedly nodes to GC\n");
238 printk(KERN_WARNING "erase block at 0x%08x. free_size 0x%08x, dirty_size 0x%08x, used_size 0x%08x\n", 237 printk(KERN_WARNING "erase block at 0x%08x. free_size 0x%08x, dirty_size 0x%08x, used_size 0x%08x\n",
239 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size); 238 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size);
240 jeb->gc_node = raw; 239 jeb->gc_node = raw;
241 spin_unlock(&c->erase_completion_lock); 240 spin_unlock(&c->erase_completion_lock);
@@ -260,7 +259,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
260 ic = jffs2_raw_ref_to_ic(raw); 259 ic = jffs2_raw_ref_to_ic(raw);
261 260
262 /* We need to hold the inocache. Either the erase_completion_lock or 261 /* We need to hold the inocache. Either the erase_completion_lock or
263 the inocache_lock are sufficient; we trade down since the inocache_lock 262 the inocache_lock are sufficient; we trade down since the inocache_lock
264 causes less contention. */ 263 causes less contention. */
265 spin_lock(&c->inocache_lock); 264 spin_lock(&c->inocache_lock);
266 265
@@ -279,14 +278,14 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
279 278
280 switch(ic->state) { 279 switch(ic->state) {
281 case INO_STATE_CHECKEDABSENT: 280 case INO_STATE_CHECKEDABSENT:
282 /* It's been checked, but it's not currently in-core. 281 /* It's been checked, but it's not currently in-core.
283 We can just copy any pristine nodes, but have 282 We can just copy any pristine nodes, but have
284 to prevent anyone else from doing read_inode() while 283 to prevent anyone else from doing read_inode() while
285 we're at it, so we set the state accordingly */ 284 we're at it, so we set the state accordingly */
286 if (ref_flags(raw) == REF_PRISTINE) 285 if (ref_flags(raw) == REF_PRISTINE)
287 ic->state = INO_STATE_GC; 286 ic->state = INO_STATE_GC;
288 else { 287 else {
289 D1(printk(KERN_DEBUG "Ino #%u is absent but node not REF_PRISTINE. Reading.\n", 288 D1(printk(KERN_DEBUG "Ino #%u is absent but node not REF_PRISTINE. Reading.\n",
290 ic->ino)); 289 ic->ino));
291 } 290 }
292 break; 291 break;
@@ -299,8 +298,8 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
299 case INO_STATE_CHECKING: 298 case INO_STATE_CHECKING:
300 case INO_STATE_GC: 299 case INO_STATE_GC:
301 /* Should never happen. We should have finished checking 300 /* Should never happen. We should have finished checking
302 by the time we actually start doing any GC, and since 301 by the time we actually start doing any GC, and since
303 we're holding the alloc_sem, no other garbage collection 302 we're holding the alloc_sem, no other garbage collection
304 can happen. 303 can happen.
305 */ 304 */
306 printk(KERN_CRIT "Inode #%u already in state %d in jffs2_garbage_collect_pass()!\n", 305 printk(KERN_CRIT "Inode #%u already in state %d in jffs2_garbage_collect_pass()!\n",
@@ -320,21 +319,21 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
320 D1(printk(KERN_DEBUG "jffs2_garbage_collect_pass() waiting for ino #%u in state %d\n", 319 D1(printk(KERN_DEBUG "jffs2_garbage_collect_pass() waiting for ino #%u in state %d\n",
321 ic->ino, ic->state)); 320 ic->ino, ic->state));
322 sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock); 321 sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock);
323 /* And because we dropped the alloc_sem we must start again from the 322 /* And because we dropped the alloc_sem we must start again from the
324 beginning. Ponder chance of livelock here -- we're returning success 323 beginning. Ponder chance of livelock here -- we're returning success
325 without actually making any progress. 324 without actually making any progress.
326 325
327 Q: What are the chances that the inode is back in INO_STATE_READING 326 Q: What are the chances that the inode is back in INO_STATE_READING
328 again by the time we next enter this function? And that this happens 327 again by the time we next enter this function? And that this happens
329 enough times to cause a real delay? 328 enough times to cause a real delay?
330 329
331 A: Small enough that I don't care :) 330 A: Small enough that I don't care :)
332 */ 331 */
333 return 0; 332 return 0;
334 } 333 }
335 334
336 /* OK. Now if the inode is in state INO_STATE_GC, we are going to copy the 335 /* OK. Now if the inode is in state INO_STATE_GC, we are going to copy the
337 node intact, and we don't have to muck about with the fragtree etc. 336 node intact, and we don't have to muck about with the fragtree etc.
338 because we know it's not in-core. If it _was_ in-core, we go through 337 because we know it's not in-core. If it _was_ in-core, we go through
339 all the iget() crap anyway */ 338 all the iget() crap anyway */
340 339
@@ -454,7 +453,7 @@ static int jffs2_garbage_collect_live(struct jffs2_sb_info *c, struct jffs2_era
454 if (!ret) { 453 if (!ret) {
455 /* Urgh. Return it sensibly. */ 454 /* Urgh. Return it sensibly. */
456 frag->node->raw = f->inocache->nodes; 455 frag->node->raw = f->inocache->nodes;
457 } 456 }
458 if (ret != -EBADFD) 457 if (ret != -EBADFD)
459 goto upnout; 458 goto upnout;
460 } 459 }
@@ -468,7 +467,7 @@ static int jffs2_garbage_collect_live(struct jffs2_sb_info *c, struct jffs2_era
468 } 467 }
469 goto upnout; 468 goto upnout;
470 } 469 }
471 470
472 /* Wasn't a dnode. Try dirent */ 471 /* Wasn't a dnode. Try dirent */
473 for (fd = f->dents; fd; fd=fd->next) { 472 for (fd = f->dents; fd; fd=fd->next) {
474 if (fd->raw == raw) 473 if (fd->raw == raw)
@@ -485,7 +484,8 @@ static int jffs2_garbage_collect_live(struct jffs2_sb_info *c, struct jffs2_era
485 if (ref_obsolete(raw)) { 484 if (ref_obsolete(raw)) {
486 printk(KERN_WARNING "But it's obsolete so we don't mind too much\n"); 485 printk(KERN_WARNING "But it's obsolete so we don't mind too much\n");
487 } else { 486 } else {
488 ret = -EIO; 487 jffs2_dbg_dump_node(c, ref_offset(raw));
488 BUG();
489 } 489 }
490 } 490 }
491 upnout: 491 upnout:
@@ -494,7 +494,7 @@ static int jffs2_garbage_collect_live(struct jffs2_sb_info *c, struct jffs2_era
494 return ret; 494 return ret;
495} 495}
496 496
497static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c, 497static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
498 struct jffs2_inode_cache *ic, 498 struct jffs2_inode_cache *ic,
499 struct jffs2_raw_node_ref *raw) 499 struct jffs2_raw_node_ref *raw)
500{ 500{
@@ -513,8 +513,11 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
513 /* Ask for a small amount of space (or the totlen if smaller) because we 513 /* Ask for a small amount of space (or the totlen if smaller) because we
514 don't want to force wastage of the end of a block if splitting would 514 don't want to force wastage of the end of a block if splitting would
515 work. */ 515 work. */
516 ret = jffs2_reserve_space_gc(c, min_t(uint32_t, sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN, 516 ret = jffs2_reserve_space_gc(c, min_t(uint32_t, sizeof(struct jffs2_raw_inode) +
517 rawlen), &phys_ofs, &alloclen); 517 JFFS2_MIN_DATA_LEN, rawlen), &phys_ofs, &alloclen, rawlen);
518 /* this is not the exact summary size of it,
519 it is only an upper estimation */
520
518 if (ret) 521 if (ret)
519 return ret; 522 return ret;
520 523
@@ -577,7 +580,7 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
577 } 580 }
578 break; 581 break;
579 default: 582 default:
580 printk(KERN_WARNING "Unknown node type for REF_PRISTINE node at 0x%08x: 0x%04x\n", 583 printk(KERN_WARNING "Unknown node type for REF_PRISTINE node at 0x%08x: 0x%04x\n",
581 ref_offset(raw), je16_to_cpu(node->u.nodetype)); 584 ref_offset(raw), je16_to_cpu(node->u.nodetype));
582 goto bail; 585 goto bail;
583 } 586 }
@@ -618,17 +621,19 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
618 retried = 1; 621 retried = 1;
619 622
620 D1(printk(KERN_DEBUG "Retrying failed write of REF_PRISTINE node.\n")); 623 D1(printk(KERN_DEBUG "Retrying failed write of REF_PRISTINE node.\n"));
621
622 ACCT_SANITY_CHECK(c,jeb);
623 D1(ACCT_PARANOIA_CHECK(jeb));
624 624
625 ret = jffs2_reserve_space_gc(c, rawlen, &phys_ofs, &dummy); 625 jffs2_dbg_acct_sanity_check(c,jeb);
626 jffs2_dbg_acct_paranoia_check(c, jeb);
627
628 ret = jffs2_reserve_space_gc(c, rawlen, &phys_ofs, &dummy, rawlen);
629 /* this is not the exact summary size of it,
630 it is only an upper estimation */
626 631
627 if (!ret) { 632 if (!ret) {
628 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", phys_ofs)); 633 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", phys_ofs));
629 634
630 ACCT_SANITY_CHECK(c,jeb); 635 jffs2_dbg_acct_sanity_check(c,jeb);
631 D1(ACCT_PARANOIA_CHECK(jeb)); 636 jffs2_dbg_acct_paranoia_check(c, jeb);
632 637
633 goto retry; 638 goto retry;
634 } 639 }
@@ -664,7 +669,7 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
664 goto out_node; 669 goto out_node;
665} 670}
666 671
667static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 672static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
668 struct jffs2_inode_info *f, struct jffs2_full_dnode *fn) 673 struct jffs2_inode_info *f, struct jffs2_full_dnode *fn)
669{ 674{
670 struct jffs2_full_dnode *new_fn; 675 struct jffs2_full_dnode *new_fn;
@@ -679,7 +684,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
679 S_ISCHR(JFFS2_F_I_MODE(f)) ) { 684 S_ISCHR(JFFS2_F_I_MODE(f)) ) {
680 /* For these, we don't actually need to read the old node */ 685 /* For these, we don't actually need to read the old node */
681 /* FIXME: for minor or major > 255. */ 686 /* FIXME: for minor or major > 255. */
682 dev = cpu_to_je16(((JFFS2_F_I_RDEV_MAJ(f) << 8) | 687 dev = cpu_to_je16(((JFFS2_F_I_RDEV_MAJ(f) << 8) |
683 JFFS2_F_I_RDEV_MIN(f))); 688 JFFS2_F_I_RDEV_MIN(f)));
684 mdata = (char *)&dev; 689 mdata = (char *)&dev;
685 mdatalen = sizeof(dev); 690 mdatalen = sizeof(dev);
@@ -700,14 +705,15 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
700 D1(printk(KERN_DEBUG "jffs2_garbage_collect_metadata(): Writing %d bites of symlink target\n", mdatalen)); 705 D1(printk(KERN_DEBUG "jffs2_garbage_collect_metadata(): Writing %d bites of symlink target\n", mdatalen));
701 706
702 } 707 }
703 708
704 ret = jffs2_reserve_space_gc(c, sizeof(ri) + mdatalen, &phys_ofs, &alloclen); 709 ret = jffs2_reserve_space_gc(c, sizeof(ri) + mdatalen, &phys_ofs, &alloclen,
710 JFFS2_SUMMARY_INODE_SIZE);
705 if (ret) { 711 if (ret) {
706 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_metadata failed: %d\n", 712 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_metadata failed: %d\n",
707 sizeof(ri)+ mdatalen, ret); 713 sizeof(ri)+ mdatalen, ret);
708 goto out; 714 goto out;
709 } 715 }
710 716
711 last_frag = frag_last(&f->fragtree); 717 last_frag = frag_last(&f->fragtree);
712 if (last_frag) 718 if (last_frag)
713 /* Fetch the inode length from the fragtree rather then 719 /* Fetch the inode length from the fragtree rather then
@@ -715,7 +721,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
715 ilen = last_frag->ofs + last_frag->size; 721 ilen = last_frag->ofs + last_frag->size;
716 else 722 else
717 ilen = JFFS2_F_I_SIZE(f); 723 ilen = JFFS2_F_I_SIZE(f);
718 724
719 memset(&ri, 0, sizeof(ri)); 725 memset(&ri, 0, sizeof(ri));
720 ri.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 726 ri.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
721 ri.nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE); 727 ri.nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
@@ -754,7 +760,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
754 return ret; 760 return ret;
755} 761}
756 762
757static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 763static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
758 struct jffs2_inode_info *f, struct jffs2_full_dirent *fd) 764 struct jffs2_inode_info *f, struct jffs2_full_dirent *fd)
759{ 765{
760 struct jffs2_full_dirent *new_fd; 766 struct jffs2_full_dirent *new_fd;
@@ -771,12 +777,18 @@ static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_er
771 rd.pino = cpu_to_je32(f->inocache->ino); 777 rd.pino = cpu_to_je32(f->inocache->ino);
772 rd.version = cpu_to_je32(++f->highest_version); 778 rd.version = cpu_to_je32(++f->highest_version);
773 rd.ino = cpu_to_je32(fd->ino); 779 rd.ino = cpu_to_je32(fd->ino);
774 rd.mctime = cpu_to_je32(max(JFFS2_F_I_MTIME(f), JFFS2_F_I_CTIME(f))); 780 /* If the times on this inode were set by explicit utime() they can be different,
781 so refrain from splatting them. */
782 if (JFFS2_F_I_MTIME(f) == JFFS2_F_I_CTIME(f))
783 rd.mctime = cpu_to_je32(JFFS2_F_I_MTIME(f));
784 else
785 rd.mctime = cpu_to_je32(0);
775 rd.type = fd->type; 786 rd.type = fd->type;
776 rd.node_crc = cpu_to_je32(crc32(0, &rd, sizeof(rd)-8)); 787 rd.node_crc = cpu_to_je32(crc32(0, &rd, sizeof(rd)-8));
777 rd.name_crc = cpu_to_je32(crc32(0, fd->name, rd.nsize)); 788 rd.name_crc = cpu_to_je32(crc32(0, fd->name, rd.nsize));
778 789
779 ret = jffs2_reserve_space_gc(c, sizeof(rd)+rd.nsize, &phys_ofs, &alloclen); 790 ret = jffs2_reserve_space_gc(c, sizeof(rd)+rd.nsize, &phys_ofs, &alloclen,
791 JFFS2_SUMMARY_DIRENT_SIZE(rd.nsize));
780 if (ret) { 792 if (ret) {
781 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_dirent failed: %d\n", 793 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_dirent failed: %d\n",
782 sizeof(rd)+rd.nsize, ret); 794 sizeof(rd)+rd.nsize, ret);
@@ -792,7 +804,7 @@ static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_er
792 return 0; 804 return 0;
793} 805}
794 806
795static int jffs2_garbage_collect_deletion_dirent(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 807static int jffs2_garbage_collect_deletion_dirent(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
796 struct jffs2_inode_info *f, struct jffs2_full_dirent *fd) 808 struct jffs2_inode_info *f, struct jffs2_full_dirent *fd)
797{ 809{
798 struct jffs2_full_dirent **fdp = &f->dents; 810 struct jffs2_full_dirent **fdp = &f->dents;
@@ -831,7 +843,7 @@ static int jffs2_garbage_collect_deletion_dirent(struct jffs2_sb_info *c, struct
831 if (ref_totlen(c, NULL, raw) != rawlen) 843 if (ref_totlen(c, NULL, raw) != rawlen)
832 continue; 844 continue;
833 845
834 /* Doesn't matter if there's one in the same erase block. We're going to 846 /* Doesn't matter if there's one in the same erase block. We're going to
835 delete it too at the same time. */ 847 delete it too at the same time. */
836 if (SECTOR_ADDR(raw->flash_offset) == SECTOR_ADDR(fd->raw->flash_offset)) 848 if (SECTOR_ADDR(raw->flash_offset) == SECTOR_ADDR(fd->raw->flash_offset))
837 continue; 849 continue;
@@ -883,6 +895,9 @@ static int jffs2_garbage_collect_deletion_dirent(struct jffs2_sb_info *c, struct
883 kfree(rd); 895 kfree(rd);
884 } 896 }
885 897
898 /* FIXME: If we're deleting a dirent which contains the current mtime and ctime,
899 we should update the metadata node with those times accordingly */
900
886 /* No need for it any more. Just mark it obsolete and remove it from the list */ 901 /* No need for it any more. Just mark it obsolete and remove it from the list */
887 while (*fdp) { 902 while (*fdp) {
888 if ((*fdp) == fd) { 903 if ((*fdp) == fd) {
@@ -912,13 +927,13 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
912 927
913 D1(printk(KERN_DEBUG "Writing replacement hole node for ino #%u from offset 0x%x to 0x%x\n", 928 D1(printk(KERN_DEBUG "Writing replacement hole node for ino #%u from offset 0x%x to 0x%x\n",
914 f->inocache->ino, start, end)); 929 f->inocache->ino, start, end));
915 930
916 memset(&ri, 0, sizeof(ri)); 931 memset(&ri, 0, sizeof(ri));
917 932
918 if(fn->frags > 1) { 933 if(fn->frags > 1) {
919 size_t readlen; 934 size_t readlen;
920 uint32_t crc; 935 uint32_t crc;
921 /* It's partially obsoleted by a later write. So we have to 936 /* It's partially obsoleted by a later write. So we have to
922 write it out again with the _same_ version as before */ 937 write it out again with the _same_ version as before */
923 ret = jffs2_flash_read(c, ref_offset(fn->raw), sizeof(ri), &readlen, (char *)&ri); 938 ret = jffs2_flash_read(c, ref_offset(fn->raw), sizeof(ri), &readlen, (char *)&ri);
924 if (readlen != sizeof(ri) || ret) { 939 if (readlen != sizeof(ri) || ret) {
@@ -940,16 +955,16 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
940 crc = crc32(0, &ri, sizeof(ri)-8); 955 crc = crc32(0, &ri, sizeof(ri)-8);
941 if (crc != je32_to_cpu(ri.node_crc)) { 956 if (crc != je32_to_cpu(ri.node_crc)) {
942 printk(KERN_WARNING "jffs2_garbage_collect_hole: Node at 0x%08x had CRC 0x%08x which doesn't match calculated CRC 0x%08x\n", 957 printk(KERN_WARNING "jffs2_garbage_collect_hole: Node at 0x%08x had CRC 0x%08x which doesn't match calculated CRC 0x%08x\n",
943 ref_offset(fn->raw), 958 ref_offset(fn->raw),
944 je32_to_cpu(ri.node_crc), crc); 959 je32_to_cpu(ri.node_crc), crc);
945 /* FIXME: We could possibly deal with this by writing new holes for each frag */ 960 /* FIXME: We could possibly deal with this by writing new holes for each frag */
946 printk(KERN_WARNING "Data in the range 0x%08x to 0x%08x of inode #%u will be lost\n", 961 printk(KERN_WARNING "Data in the range 0x%08x to 0x%08x of inode #%u will be lost\n",
947 start, end, f->inocache->ino); 962 start, end, f->inocache->ino);
948 goto fill; 963 goto fill;
949 } 964 }
950 if (ri.compr != JFFS2_COMPR_ZERO) { 965 if (ri.compr != JFFS2_COMPR_ZERO) {
951 printk(KERN_WARNING "jffs2_garbage_collect_hole: Node 0x%08x wasn't a hole node!\n", ref_offset(fn->raw)); 966 printk(KERN_WARNING "jffs2_garbage_collect_hole: Node 0x%08x wasn't a hole node!\n", ref_offset(fn->raw));
952 printk(KERN_WARNING "Data in the range 0x%08x to 0x%08x of inode #%u will be lost\n", 967 printk(KERN_WARNING "Data in the range 0x%08x to 0x%08x of inode #%u will be lost\n",
953 start, end, f->inocache->ino); 968 start, end, f->inocache->ino);
954 goto fill; 969 goto fill;
955 } 970 }
@@ -967,7 +982,7 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
967 ri.csize = cpu_to_je32(0); 982 ri.csize = cpu_to_je32(0);
968 ri.compr = JFFS2_COMPR_ZERO; 983 ri.compr = JFFS2_COMPR_ZERO;
969 } 984 }
970 985
971 frag = frag_last(&f->fragtree); 986 frag = frag_last(&f->fragtree);
972 if (frag) 987 if (frag)
973 /* Fetch the inode length from the fragtree rather then 988 /* Fetch the inode length from the fragtree rather then
@@ -986,7 +1001,8 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
986 ri.data_crc = cpu_to_je32(0); 1001 ri.data_crc = cpu_to_je32(0);
987 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8)); 1002 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
988 1003
989 ret = jffs2_reserve_space_gc(c, sizeof(ri), &phys_ofs, &alloclen); 1004 ret = jffs2_reserve_space_gc(c, sizeof(ri), &phys_ofs, &alloclen,
1005 JFFS2_SUMMARY_INODE_SIZE);
990 if (ret) { 1006 if (ret) {
991 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_hole failed: %d\n", 1007 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_hole failed: %d\n",
992 sizeof(ri), ret); 1008 sizeof(ri), ret);
@@ -1008,10 +1024,10 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
1008 return 0; 1024 return 0;
1009 } 1025 }
1010 1026
1011 /* 1027 /*
1012 * We should only get here in the case where the node we are 1028 * We should only get here in the case where the node we are
1013 * replacing had more than one frag, so we kept the same version 1029 * replacing had more than one frag, so we kept the same version
1014 * number as before. (Except in case of error -- see 'goto fill;' 1030 * number as before. (Except in case of error -- see 'goto fill;'
1015 * above.) 1031 * above.)
1016 */ 1032 */
1017 D1(if(unlikely(fn->frags <= 1)) { 1033 D1(if(unlikely(fn->frags <= 1)) {
@@ -1023,7 +1039,7 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
1023 /* This is a partially-overlapped hole node. Mark it REF_NORMAL not REF_PRISTINE */ 1039 /* This is a partially-overlapped hole node. Mark it REF_NORMAL not REF_PRISTINE */
1024 mark_ref_normal(new_fn->raw); 1040 mark_ref_normal(new_fn->raw);
1025 1041
1026 for (frag = jffs2_lookup_node_frag(&f->fragtree, fn->ofs); 1042 for (frag = jffs2_lookup_node_frag(&f->fragtree, fn->ofs);
1027 frag; frag = frag_next(frag)) { 1043 frag; frag = frag_next(frag)) {
1028 if (frag->ofs > fn->size + fn->ofs) 1044 if (frag->ofs > fn->size + fn->ofs)
1029 break; 1045 break;
@@ -1041,10 +1057,10 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
1041 printk(KERN_WARNING "jffs2_garbage_collect_hole: New node has no frags!\n"); 1057 printk(KERN_WARNING "jffs2_garbage_collect_hole: New node has no frags!\n");
1042 BUG(); 1058 BUG();
1043 } 1059 }
1044 1060
1045 jffs2_mark_node_obsolete(c, fn->raw); 1061 jffs2_mark_node_obsolete(c, fn->raw);
1046 jffs2_free_full_dnode(fn); 1062 jffs2_free_full_dnode(fn);
1047 1063
1048 return 0; 1064 return 0;
1049} 1065}
1050 1066
@@ -1054,12 +1070,12 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1054{ 1070{
1055 struct jffs2_full_dnode *new_fn; 1071 struct jffs2_full_dnode *new_fn;
1056 struct jffs2_raw_inode ri; 1072 struct jffs2_raw_inode ri;
1057 uint32_t alloclen, phys_ofs, offset, orig_end, orig_start; 1073 uint32_t alloclen, phys_ofs, offset, orig_end, orig_start;
1058 int ret = 0; 1074 int ret = 0;
1059 unsigned char *comprbuf = NULL, *writebuf; 1075 unsigned char *comprbuf = NULL, *writebuf;
1060 unsigned long pg; 1076 unsigned long pg;
1061 unsigned char *pg_ptr; 1077 unsigned char *pg_ptr;
1062 1078
1063 memset(&ri, 0, sizeof(ri)); 1079 memset(&ri, 0, sizeof(ri));
1064 1080
1065 D1(printk(KERN_DEBUG "Writing replacement dnode for ino #%u from offset 0x%x to 0x%x\n", 1081 D1(printk(KERN_DEBUG "Writing replacement dnode for ino #%u from offset 0x%x to 0x%x\n",
@@ -1071,8 +1087,8 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1071 if (c->nr_free_blocks + c->nr_erasing_blocks > c->resv_blocks_gcmerge) { 1087 if (c->nr_free_blocks + c->nr_erasing_blocks > c->resv_blocks_gcmerge) {
1072 /* Attempt to do some merging. But only expand to cover logically 1088 /* Attempt to do some merging. But only expand to cover logically
1073 adjacent frags if the block containing them is already considered 1089 adjacent frags if the block containing them is already considered
1074 to be dirty. Otherwise we end up with GC just going round in 1090 to be dirty. Otherwise we end up with GC just going round in
1075 circles dirtying the nodes it already wrote out, especially 1091 circles dirtying the nodes it already wrote out, especially
1076 on NAND where we have small eraseblocks and hence a much higher 1092 on NAND where we have small eraseblocks and hence a much higher
1077 chance of nodes having to be split to cross boundaries. */ 1093 chance of nodes having to be split to cross boundaries. */
1078 1094
@@ -1106,7 +1122,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1106 break; 1122 break;
1107 } else { 1123 } else {
1108 1124
1109 /* OK, it's a frag which extends to the beginning of the page. Does it live 1125 /* OK, it's a frag which extends to the beginning of the page. Does it live
1110 in a block which is still considered clean? If so, don't obsolete it. 1126 in a block which is still considered clean? If so, don't obsolete it.
1111 If not, cover it anyway. */ 1127 If not, cover it anyway. */
1112 1128
@@ -1156,7 +1172,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1156 break; 1172 break;
1157 } else { 1173 } else {
1158 1174
1159 /* OK, it's a frag which extends to the beginning of the page. Does it live 1175 /* OK, it's a frag which extends to the beginning of the page. Does it live
1160 in a block which is still considered clean? If so, don't obsolete it. 1176 in a block which is still considered clean? If so, don't obsolete it.
1161 If not, cover it anyway. */ 1177 If not, cover it anyway. */
1162 1178
@@ -1183,14 +1199,14 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1183 break; 1199 break;
1184 } 1200 }
1185 } 1201 }
1186 D1(printk(KERN_DEBUG "Expanded dnode to write from (0x%x-0x%x) to (0x%x-0x%x)\n", 1202 D1(printk(KERN_DEBUG "Expanded dnode to write from (0x%x-0x%x) to (0x%x-0x%x)\n",
1187 orig_start, orig_end, start, end)); 1203 orig_start, orig_end, start, end));
1188 1204
1189 D1(BUG_ON(end > frag_last(&f->fragtree)->ofs + frag_last(&f->fragtree)->size)); 1205 D1(BUG_ON(end > frag_last(&f->fragtree)->ofs + frag_last(&f->fragtree)->size));
1190 BUG_ON(end < orig_end); 1206 BUG_ON(end < orig_end);
1191 BUG_ON(start > orig_start); 1207 BUG_ON(start > orig_start);
1192 } 1208 }
1193 1209
1194 /* First, use readpage() to read the appropriate page into the page cache */ 1210 /* First, use readpage() to read the appropriate page into the page cache */
1195 /* Q: What happens if we actually try to GC the _same_ page for which commit_write() 1211 /* Q: What happens if we actually try to GC the _same_ page for which commit_write()
1196 * triggered garbage collection in the first place? 1212 * triggered garbage collection in the first place?
@@ -1211,7 +1227,8 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1211 uint32_t cdatalen; 1227 uint32_t cdatalen;
1212 uint16_t comprtype = JFFS2_COMPR_NONE; 1228 uint16_t comprtype = JFFS2_COMPR_NONE;
1213 1229
1214 ret = jffs2_reserve_space_gc(c, sizeof(ri) + JFFS2_MIN_DATA_LEN, &phys_ofs, &alloclen); 1230 ret = jffs2_reserve_space_gc(c, sizeof(ri) + JFFS2_MIN_DATA_LEN, &phys_ofs,
1231 &alloclen, JFFS2_SUMMARY_INODE_SIZE);
1215 1232
1216 if (ret) { 1233 if (ret) {
1217 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_dnode failed: %d\n", 1234 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_dnode failed: %d\n",
@@ -1246,7 +1263,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1246 ri.usercompr = (comprtype >> 8) & 0xff; 1263 ri.usercompr = (comprtype >> 8) & 0xff;
1247 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8)); 1264 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
1248 ri.data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen)); 1265 ri.data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
1249 1266
1250 new_fn = jffs2_write_dnode(c, f, &ri, comprbuf, cdatalen, phys_ofs, ALLOC_GC); 1267 new_fn = jffs2_write_dnode(c, f, &ri, comprbuf, cdatalen, phys_ofs, ALLOC_GC);
1251 1268
1252 jffs2_free_comprbuf(comprbuf, writebuf); 1269 jffs2_free_comprbuf(comprbuf, writebuf);
@@ -1268,4 +1285,3 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1268 jffs2_gc_release_page(c, pg_ptr, &pg); 1285 jffs2_gc_release_page(c, pg_ptr, &pg);
1269 return ret; 1286 return ret;
1270} 1287}
1271
diff --git a/fs/jffs2/histo.h b/fs/jffs2/histo.h
index 84f184f0836f..22a93a08210c 100644
--- a/fs/jffs2/histo.h
+++ b/fs/jffs2/histo.h
@@ -1,3 +1,3 @@
1/* This file provides the bit-probabilities for the input file */ 1/* This file provides the bit-probabilities for the input file */
2#define BIT_DIVIDER 629 2#define BIT_DIVIDER 629
3static int bits[9] = { 179,167,183,165,159,198,178,119,}; /* ia32 .so files */ 3static int bits[9] = { 179,167,183,165,159,198,178,119,}; /* ia32 .so files */
diff --git a/fs/jffs2/histo_mips.h b/fs/jffs2/histo_mips.h
index 9a443268d885..fa3dac19a109 100644
--- a/fs/jffs2/histo_mips.h
+++ b/fs/jffs2/histo_mips.h
@@ -1,2 +1,2 @@
1#define BIT_DIVIDER_MIPS 1043 1#define BIT_DIVIDER_MIPS 1043
2static int bits_mips[8] = { 277,249,290,267,229,341,212,241}; /* mips32 */ 2static int bits_mips[8] = { 277,249,290,267,229,341,212,241}; /* mips32 */
diff --git a/fs/jffs2/ioctl.c b/fs/jffs2/ioctl.c
index 238c7992064c..69099835de1c 100644
--- a/fs/jffs2/ioctl.c
+++ b/fs/jffs2/ioctl.c
@@ -7,17 +7,17 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: ioctl.c,v 1.9 2004/11/16 20:36:11 dwmw2 Exp $ 10 * $Id: ioctl.c,v 1.10 2005/11/07 11:14:40 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
14#include <linux/fs.h> 14#include <linux/fs.h>
15 15
16int jffs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, 16int jffs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
17 unsigned long arg) 17 unsigned long arg)
18{ 18{
19 /* Later, this will provide for lsattr.jffs2 and chattr.jffs2, which 19 /* Later, this will provide for lsattr.jffs2 and chattr.jffs2, which
20 will include compression support etc. */ 20 will include compression support etc. */
21 return -ENOTTY; 21 return -ENOTTY;
22} 22}
23 23
diff --git a/fs/jffs2/malloc.c b/fs/jffs2/malloc.c
index 5abb431c2a00..036cbd11c004 100644
--- a/fs/jffs2/malloc.c
+++ b/fs/jffs2/malloc.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: malloc.c,v 1.28 2004/11/16 20:36:11 dwmw2 Exp $ 10 * $Id: malloc.c,v 1.31 2005/11/07 11:14:40 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -17,15 +17,6 @@
17#include <linux/jffs2.h> 17#include <linux/jffs2.h>
18#include "nodelist.h" 18#include "nodelist.h"
19 19
20#if 0
21#define JFFS2_SLAB_POISON SLAB_POISON
22#else
23#define JFFS2_SLAB_POISON 0
24#endif
25
26// replace this by #define D3 (x) x for cache debugging
27#define D3(x)
28
29/* These are initialised to NULL in the kernel startup code. 20/* These are initialised to NULL in the kernel startup code.
30 If you're porting to other operating systems, beware */ 21 If you're porting to other operating systems, beware */
31static kmem_cache_t *full_dnode_slab; 22static kmem_cache_t *full_dnode_slab;
@@ -38,45 +29,45 @@ static kmem_cache_t *inode_cache_slab;
38 29
39int __init jffs2_create_slab_caches(void) 30int __init jffs2_create_slab_caches(void)
40{ 31{
41 full_dnode_slab = kmem_cache_create("jffs2_full_dnode", 32 full_dnode_slab = kmem_cache_create("jffs2_full_dnode",
42 sizeof(struct jffs2_full_dnode), 33 sizeof(struct jffs2_full_dnode),
43 0, JFFS2_SLAB_POISON, NULL, NULL); 34 0, 0, NULL, NULL);
44 if (!full_dnode_slab) 35 if (!full_dnode_slab)
45 goto err; 36 goto err;
46 37
47 raw_dirent_slab = kmem_cache_create("jffs2_raw_dirent", 38 raw_dirent_slab = kmem_cache_create("jffs2_raw_dirent",
48 sizeof(struct jffs2_raw_dirent), 39 sizeof(struct jffs2_raw_dirent),
49 0, JFFS2_SLAB_POISON, NULL, NULL); 40 0, 0, NULL, NULL);
50 if (!raw_dirent_slab) 41 if (!raw_dirent_slab)
51 goto err; 42 goto err;
52 43
53 raw_inode_slab = kmem_cache_create("jffs2_raw_inode", 44 raw_inode_slab = kmem_cache_create("jffs2_raw_inode",
54 sizeof(struct jffs2_raw_inode), 45 sizeof(struct jffs2_raw_inode),
55 0, JFFS2_SLAB_POISON, NULL, NULL); 46 0, 0, NULL, NULL);
56 if (!raw_inode_slab) 47 if (!raw_inode_slab)
57 goto err; 48 goto err;
58 49
59 tmp_dnode_info_slab = kmem_cache_create("jffs2_tmp_dnode", 50 tmp_dnode_info_slab = kmem_cache_create("jffs2_tmp_dnode",
60 sizeof(struct jffs2_tmp_dnode_info), 51 sizeof(struct jffs2_tmp_dnode_info),
61 0, JFFS2_SLAB_POISON, NULL, NULL); 52 0, 0, NULL, NULL);
62 if (!tmp_dnode_info_slab) 53 if (!tmp_dnode_info_slab)
63 goto err; 54 goto err;
64 55
65 raw_node_ref_slab = kmem_cache_create("jffs2_raw_node_ref", 56 raw_node_ref_slab = kmem_cache_create("jffs2_raw_node_ref",
66 sizeof(struct jffs2_raw_node_ref), 57 sizeof(struct jffs2_raw_node_ref),
67 0, JFFS2_SLAB_POISON, NULL, NULL); 58 0, 0, NULL, NULL);
68 if (!raw_node_ref_slab) 59 if (!raw_node_ref_slab)
69 goto err; 60 goto err;
70 61
71 node_frag_slab = kmem_cache_create("jffs2_node_frag", 62 node_frag_slab = kmem_cache_create("jffs2_node_frag",
72 sizeof(struct jffs2_node_frag), 63 sizeof(struct jffs2_node_frag),
73 0, JFFS2_SLAB_POISON, NULL, NULL); 64 0, 0, NULL, NULL);
74 if (!node_frag_slab) 65 if (!node_frag_slab)
75 goto err; 66 goto err;
76 67
77 inode_cache_slab = kmem_cache_create("jffs2_inode_cache", 68 inode_cache_slab = kmem_cache_create("jffs2_inode_cache",
78 sizeof(struct jffs2_inode_cache), 69 sizeof(struct jffs2_inode_cache),
79 0, JFFS2_SLAB_POISON, NULL, NULL); 70 0, 0, NULL, NULL);
80 if (inode_cache_slab) 71 if (inode_cache_slab)
81 return 0; 72 return 0;
82 err: 73 err:
@@ -104,102 +95,113 @@ void jffs2_destroy_slab_caches(void)
104 95
105struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize) 96struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
106{ 97{
107 return kmalloc(sizeof(struct jffs2_full_dirent) + namesize, GFP_KERNEL); 98 struct jffs2_full_dirent *ret;
99 ret = kmalloc(sizeof(struct jffs2_full_dirent) + namesize, GFP_KERNEL);
100 dbg_memalloc("%p\n", ret);
101 return ret;
108} 102}
109 103
110void jffs2_free_full_dirent(struct jffs2_full_dirent *x) 104void jffs2_free_full_dirent(struct jffs2_full_dirent *x)
111{ 105{
106 dbg_memalloc("%p\n", x);
112 kfree(x); 107 kfree(x);
113} 108}
114 109
115struct jffs2_full_dnode *jffs2_alloc_full_dnode(void) 110struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
116{ 111{
117 struct jffs2_full_dnode *ret = kmem_cache_alloc(full_dnode_slab, GFP_KERNEL); 112 struct jffs2_full_dnode *ret;
118 D3 (printk (KERN_DEBUG "alloc_full_dnode at %p\n", ret)); 113 ret = kmem_cache_alloc(full_dnode_slab, GFP_KERNEL);
114 dbg_memalloc("%p\n", ret);
119 return ret; 115 return ret;
120} 116}
121 117
122void jffs2_free_full_dnode(struct jffs2_full_dnode *x) 118void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
123{ 119{
124 D3 (printk (KERN_DEBUG "free full_dnode at %p\n", x)); 120 dbg_memalloc("%p\n", x);
125 kmem_cache_free(full_dnode_slab, x); 121 kmem_cache_free(full_dnode_slab, x);
126} 122}
127 123
128struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void) 124struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
129{ 125{
130 struct jffs2_raw_dirent *ret = kmem_cache_alloc(raw_dirent_slab, GFP_KERNEL); 126 struct jffs2_raw_dirent *ret;
131 D3 (printk (KERN_DEBUG "alloc_raw_dirent\n", ret)); 127 ret = kmem_cache_alloc(raw_dirent_slab, GFP_KERNEL);
128 dbg_memalloc("%p\n", ret);
132 return ret; 129 return ret;
133} 130}
134 131
135void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x) 132void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
136{ 133{
137 D3 (printk (KERN_DEBUG "free_raw_dirent at %p\n", x)); 134 dbg_memalloc("%p\n", x);
138 kmem_cache_free(raw_dirent_slab, x); 135 kmem_cache_free(raw_dirent_slab, x);
139} 136}
140 137
141struct jffs2_raw_inode *jffs2_alloc_raw_inode(void) 138struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
142{ 139{
143 struct jffs2_raw_inode *ret = kmem_cache_alloc(raw_inode_slab, GFP_KERNEL); 140 struct jffs2_raw_inode *ret;
144 D3 (printk (KERN_DEBUG "alloc_raw_inode at %p\n", ret)); 141 ret = kmem_cache_alloc(raw_inode_slab, GFP_KERNEL);
142 dbg_memalloc("%p\n", ret);
145 return ret; 143 return ret;
146} 144}
147 145
148void jffs2_free_raw_inode(struct jffs2_raw_inode *x) 146void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
149{ 147{
150 D3 (printk (KERN_DEBUG "free_raw_inode at %p\n", x)); 148 dbg_memalloc("%p\n", x);
151 kmem_cache_free(raw_inode_slab, x); 149 kmem_cache_free(raw_inode_slab, x);
152} 150}
153 151
154struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void) 152struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
155{ 153{
156 struct jffs2_tmp_dnode_info *ret = kmem_cache_alloc(tmp_dnode_info_slab, GFP_KERNEL); 154 struct jffs2_tmp_dnode_info *ret;
157 D3 (printk (KERN_DEBUG "alloc_tmp_dnode_info at %p\n", ret)); 155 ret = kmem_cache_alloc(tmp_dnode_info_slab, GFP_KERNEL);
156 dbg_memalloc("%p\n",
157 ret);
158 return ret; 158 return ret;
159} 159}
160 160
161void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x) 161void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
162{ 162{
163 D3 (printk (KERN_DEBUG "free_tmp_dnode_info at %p\n", x)); 163 dbg_memalloc("%p\n", x);
164 kmem_cache_free(tmp_dnode_info_slab, x); 164 kmem_cache_free(tmp_dnode_info_slab, x);
165} 165}
166 166
167struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void) 167struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
168{ 168{
169 struct jffs2_raw_node_ref *ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL); 169 struct jffs2_raw_node_ref *ret;
170 D3 (printk (KERN_DEBUG "alloc_raw_node_ref at %p\n", ret)); 170 ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL);
171 dbg_memalloc("%p\n", ret);
171 return ret; 172 return ret;
172} 173}
173 174
174void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x) 175void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
175{ 176{
176 D3 (printk (KERN_DEBUG "free_raw_node_ref at %p\n", x)); 177 dbg_memalloc("%p\n", x);
177 kmem_cache_free(raw_node_ref_slab, x); 178 kmem_cache_free(raw_node_ref_slab, x);
178} 179}
179 180
180struct jffs2_node_frag *jffs2_alloc_node_frag(void) 181struct jffs2_node_frag *jffs2_alloc_node_frag(void)
181{ 182{
182 struct jffs2_node_frag *ret = kmem_cache_alloc(node_frag_slab, GFP_KERNEL); 183 struct jffs2_node_frag *ret;
183 D3 (printk (KERN_DEBUG "alloc_node_frag at %p\n", ret)); 184 ret = kmem_cache_alloc(node_frag_slab, GFP_KERNEL);
185 dbg_memalloc("%p\n", ret);
184 return ret; 186 return ret;
185} 187}
186 188
187void jffs2_free_node_frag(struct jffs2_node_frag *x) 189void jffs2_free_node_frag(struct jffs2_node_frag *x)
188{ 190{
189 D3 (printk (KERN_DEBUG "free_node_frag at %p\n", x)); 191 dbg_memalloc("%p\n", x);
190 kmem_cache_free(node_frag_slab, x); 192 kmem_cache_free(node_frag_slab, x);
191} 193}
192 194
193struct jffs2_inode_cache *jffs2_alloc_inode_cache(void) 195struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
194{ 196{
195 struct jffs2_inode_cache *ret = kmem_cache_alloc(inode_cache_slab, GFP_KERNEL); 197 struct jffs2_inode_cache *ret;
196 D3 (printk(KERN_DEBUG "Allocated inocache at %p\n", ret)); 198 ret = kmem_cache_alloc(inode_cache_slab, GFP_KERNEL);
199 dbg_memalloc("%p\n", ret);
197 return ret; 200 return ret;
198} 201}
199 202
200void jffs2_free_inode_cache(struct jffs2_inode_cache *x) 203void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
201{ 204{
202 D3 (printk(KERN_DEBUG "Freeing inocache at %p\n", x)); 205 dbg_memalloc("%p\n", x);
203 kmem_cache_free(inode_cache_slab, x); 206 kmem_cache_free(inode_cache_slab, x);
204} 207}
205
diff --git a/fs/jffs2/nodelist.c b/fs/jffs2/nodelist.c
index 4991c348f6ec..c79eebb8ab32 100644
--- a/fs/jffs2/nodelist.c
+++ b/fs/jffs2/nodelist.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: nodelist.c,v 1.98 2005/07/10 15:15:32 dedekind Exp $ 10 * $Id: nodelist.c,v 1.115 2005/11/07 11:14:40 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -24,469 +24,832 @@
24void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list) 24void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list)
25{ 25{
26 struct jffs2_full_dirent **prev = list; 26 struct jffs2_full_dirent **prev = list;
27 D1(printk(KERN_DEBUG "jffs2_add_fd_to_list( %p, %p (->%p))\n", new, list, *list)); 27
28 dbg_dentlist("add dirent \"%s\", ino #%u\n", new->name, new->ino);
28 29
29 while ((*prev) && (*prev)->nhash <= new->nhash) { 30 while ((*prev) && (*prev)->nhash <= new->nhash) {
30 if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name)) { 31 if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name)) {
31 /* Duplicate. Free one */ 32 /* Duplicate. Free one */
32 if (new->version < (*prev)->version) { 33 if (new->version < (*prev)->version) {
33 D1(printk(KERN_DEBUG "Eep! Marking new dirent node obsolete\n")); 34 dbg_dentlist("Eep! Marking new dirent node is obsolete, old is \"%s\", ino #%u\n",
34 D1(printk(KERN_DEBUG "New dirent is \"%s\"->ino #%u. Old is \"%s\"->ino #%u\n", new->name, new->ino, (*prev)->name, (*prev)->ino)); 35 (*prev)->name, (*prev)->ino);
35 jffs2_mark_node_obsolete(c, new->raw); 36 jffs2_mark_node_obsolete(c, new->raw);
36 jffs2_free_full_dirent(new); 37 jffs2_free_full_dirent(new);
37 } else { 38 } else {
38 D1(printk(KERN_DEBUG "Marking old dirent node (ino #%u) obsolete\n", (*prev)->ino)); 39 dbg_dentlist("marking old dirent \"%s\", ino #%u bsolete\n",
40 (*prev)->name, (*prev)->ino);
39 new->next = (*prev)->next; 41 new->next = (*prev)->next;
40 jffs2_mark_node_obsolete(c, ((*prev)->raw)); 42 jffs2_mark_node_obsolete(c, ((*prev)->raw));
41 jffs2_free_full_dirent(*prev); 43 jffs2_free_full_dirent(*prev);
42 *prev = new; 44 *prev = new;
43 } 45 }
44 goto out; 46 return;
45 } 47 }
46 prev = &((*prev)->next); 48 prev = &((*prev)->next);
47 } 49 }
48 new->next = *prev; 50 new->next = *prev;
49 *prev = new; 51 *prev = new;
52}
53
54void jffs2_truncate_fragtree(struct jffs2_sb_info *c, struct rb_root *list, uint32_t size)
55{
56 struct jffs2_node_frag *frag = jffs2_lookup_node_frag(list, size);
57
58 dbg_fragtree("truncating fragtree to 0x%08x bytes\n", size);
59
60 /* We know frag->ofs <= size. That's what lookup does for us */
61 if (frag && frag->ofs != size) {
62 if (frag->ofs+frag->size > size) {
63 frag->size = size - frag->ofs;
64 }
65 frag = frag_next(frag);
66 }
67 while (frag && frag->ofs >= size) {
68 struct jffs2_node_frag *next = frag_next(frag);
69
70 frag_erase(frag, list);
71 jffs2_obsolete_node_frag(c, frag);
72 frag = next;
73 }
50 74
51 out: 75 if (size == 0)
52 D2(while(*list) { 76 return;
53 printk(KERN_DEBUG "Dirent \"%s\" (hash 0x%08x, ino #%u\n", (*list)->name, (*list)->nhash, (*list)->ino); 77
54 list = &(*list)->next; 78 /*
55 }); 79 * If the last fragment starts at the RAM page boundary, it is
80 * REF_PRISTINE irrespective of its size.
81 */
82 frag = frag_last(list);
83 if (frag->node && (frag->ofs & (PAGE_CACHE_SIZE - 1)) == 0) {
84 dbg_fragtree2("marking the last fragment 0x%08x-0x%08x REF_PRISTINE.\n",
85 frag->ofs, frag->ofs + frag->size);
86 frag->node->raw->flash_offset = ref_offset(frag->node->raw) | REF_PRISTINE;
87 }
56} 88}
57 89
58/* 90void jffs2_obsolete_node_frag(struct jffs2_sb_info *c, struct jffs2_node_frag *this)
59 * Put a new tmp_dnode_info into the temporaty RB-tree, keeping the list in
60 * order of increasing version.
61 */
62static void jffs2_add_tn_to_tree(struct jffs2_tmp_dnode_info *tn, struct rb_root *list)
63{ 91{
64 struct rb_node **p = &list->rb_node; 92 if (this->node) {
65 struct rb_node * parent = NULL; 93 this->node->frags--;
66 struct jffs2_tmp_dnode_info *this; 94 if (!this->node->frags) {
67 95 /* The node has no valid frags left. It's totally obsoleted */
68 while (*p) { 96 dbg_fragtree2("marking old node @0x%08x (0x%04x-0x%04x) obsolete\n",
69 parent = *p; 97 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size);
70 this = rb_entry(parent, struct jffs2_tmp_dnode_info, rb); 98 jffs2_mark_node_obsolete(c, this->node->raw);
71 99 jffs2_free_full_dnode(this->node);
72 /* There may actually be a collision here, but it doesn't 100 } else {
73 actually matter. As long as the two nodes with the same 101 dbg_fragtree2("marking old node @0x%08x (0x%04x-0x%04x) REF_NORMAL. frags is %d\n",
74 version are together, it's all fine. */ 102 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size, this->node->frags);
75 if (tn->version < this->version) 103 mark_ref_normal(this->node->raw);
76 p = &(*p)->rb_left; 104 }
77 else
78 p = &(*p)->rb_right;
79 }
80 105
81 rb_link_node(&tn->rb, parent, p); 106 }
82 rb_insert_color(&tn->rb, list); 107 jffs2_free_node_frag(this);
83} 108}
84 109
85static void jffs2_free_tmp_dnode_info_list(struct rb_root *list) 110static void jffs2_fragtree_insert(struct jffs2_node_frag *newfrag, struct jffs2_node_frag *base)
86{ 111{
87 struct rb_node *this; 112 struct rb_node *parent = &base->rb;
88 struct jffs2_tmp_dnode_info *tn; 113 struct rb_node **link = &parent;
89 114
90 this = list->rb_node; 115 dbg_fragtree2("insert frag (0x%04x-0x%04x)\n", newfrag->ofs, newfrag->ofs + newfrag->size);
91 116
92 /* Now at bottom of tree */ 117 while (*link) {
93 while (this) { 118 parent = *link;
94 if (this->rb_left) 119 base = rb_entry(parent, struct jffs2_node_frag, rb);
95 this = this->rb_left; 120
96 else if (this->rb_right) 121 if (newfrag->ofs > base->ofs)
97 this = this->rb_right; 122 link = &base->rb.rb_right;
123 else if (newfrag->ofs < base->ofs)
124 link = &base->rb.rb_left;
98 else { 125 else {
99 tn = rb_entry(this, struct jffs2_tmp_dnode_info, rb); 126 JFFS2_ERROR("duplicate frag at %08x (%p,%p)\n", newfrag->ofs, newfrag, base);
100 jffs2_free_full_dnode(tn->fn); 127 BUG();
101 jffs2_free_tmp_dnode_info(tn);
102
103 this = this->rb_parent;
104 if (!this)
105 break;
106
107 if (this->rb_left == &tn->rb)
108 this->rb_left = NULL;
109 else if (this->rb_right == &tn->rb)
110 this->rb_right = NULL;
111 else BUG();
112 } 128 }
113 } 129 }
114 list->rb_node = NULL; 130
131 rb_link_node(&newfrag->rb, &base->rb, link);
115} 132}
116 133
117static void jffs2_free_full_dirent_list(struct jffs2_full_dirent *fd) 134/*
135 * Allocate and initializes a new fragment.
136 */
137static inline struct jffs2_node_frag * new_fragment(struct jffs2_full_dnode *fn, uint32_t ofs, uint32_t size)
118{ 138{
119 struct jffs2_full_dirent *next; 139 struct jffs2_node_frag *newfrag;
120 140
121 while (fd) { 141 newfrag = jffs2_alloc_node_frag();
122 next = fd->next; 142 if (likely(newfrag)) {
123 jffs2_free_full_dirent(fd); 143 newfrag->ofs = ofs;
124 fd = next; 144 newfrag->size = size;
145 newfrag->node = fn;
146 } else {
147 JFFS2_ERROR("cannot allocate a jffs2_node_frag object\n");
125 } 148 }
149
150 return newfrag;
126} 151}
127 152
128/* Returns first valid node after 'ref'. May return 'ref' */ 153/*
129static struct jffs2_raw_node_ref *jffs2_first_valid_node(struct jffs2_raw_node_ref *ref) 154 * Called when there is no overlapping fragment exist. Inserts a hole before the new
155 * fragment and inserts the new fragment to the fragtree.
156 */
157static int no_overlapping_node(struct jffs2_sb_info *c, struct rb_root *root,
158 struct jffs2_node_frag *newfrag,
159 struct jffs2_node_frag *this, uint32_t lastend)
130{ 160{
131 while (ref && ref->next_in_ino) { 161 if (lastend < newfrag->node->ofs) {
132 if (!ref_obsolete(ref)) 162 /* put a hole in before the new fragment */
133 return ref; 163 struct jffs2_node_frag *holefrag;
134 D1(printk(KERN_DEBUG "node at 0x%08x is obsoleted. Ignoring.\n", ref_offset(ref))); 164
135 ref = ref->next_in_ino; 165 holefrag= new_fragment(NULL, lastend, newfrag->node->ofs - lastend);
166 if (unlikely(!holefrag)) {
167 jffs2_free_node_frag(newfrag);
168 return -ENOMEM;
169 }
170
171 if (this) {
172 /* By definition, the 'this' node has no right-hand child,
173 because there are no frags with offset greater than it.
174 So that's where we want to put the hole */
175 dbg_fragtree2("add hole frag %#04x-%#04x on the right of the new frag.\n",
176 holefrag->ofs, holefrag->ofs + holefrag->size);
177 rb_link_node(&holefrag->rb, &this->rb, &this->rb.rb_right);
178 } else {
179 dbg_fragtree2("Add hole frag %#04x-%#04x to the root of the tree.\n",
180 holefrag->ofs, holefrag->ofs + holefrag->size);
181 rb_link_node(&holefrag->rb, NULL, &root->rb_node);
182 }
183 rb_insert_color(&holefrag->rb, root);
184 this = holefrag;
185 }
186
187 if (this) {
188 /* By definition, the 'this' node has no right-hand child,
189 because there are no frags with offset greater than it.
190 So that's where we want to put new fragment */
191 dbg_fragtree2("add the new node at the right\n");
192 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right);
193 } else {
194 dbg_fragtree2("insert the new node at the root of the tree\n");
195 rb_link_node(&newfrag->rb, NULL, &root->rb_node);
136 } 196 }
137 return NULL; 197 rb_insert_color(&newfrag->rb, root);
198
199 return 0;
138} 200}
139 201
140/* Get tmp_dnode_info and full_dirent for all non-obsolete nodes associated 202/* Doesn't set inode->i_size */
141 with this ino, returning the former in order of version */ 203static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *root, struct jffs2_node_frag *newfrag)
204{
205 struct jffs2_node_frag *this;
206 uint32_t lastend;
207
208 /* Skip all the nodes which are completed before this one starts */
209 this = jffs2_lookup_node_frag(root, newfrag->node->ofs);
210
211 if (this) {
212 dbg_fragtree2("lookup gave frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n",
213 this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this);
214 lastend = this->ofs + this->size;
215 } else {
216 dbg_fragtree2("lookup gave no frag\n");
217 lastend = 0;
218 }
219
220 /* See if we ran off the end of the fragtree */
221 if (lastend <= newfrag->ofs) {
222 /* We did */
223
224 /* Check if 'this' node was on the same page as the new node.
225 If so, both 'this' and the new node get marked REF_NORMAL so
226 the GC can take a look.
227 */
228 if (lastend && (lastend-1) >> PAGE_CACHE_SHIFT == newfrag->ofs >> PAGE_CACHE_SHIFT) {
229 if (this->node)
230 mark_ref_normal(this->node->raw);
231 mark_ref_normal(newfrag->node->raw);
232 }
233
234 return no_overlapping_node(c, root, newfrag, this, lastend);
235 }
142 236
143int jffs2_get_inode_nodes(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 237 if (this->node)
144 struct rb_root *tnp, struct jffs2_full_dirent **fdp, 238 dbg_fragtree2("dealing with frag %u-%u, phys %#08x(%d).\n",
145 uint32_t *highest_version, uint32_t *latest_mctime, 239 this->ofs, this->ofs + this->size,
146 uint32_t *mctime_ver) 240 ref_offset(this->node->raw), ref_flags(this->node->raw));
241 else
242 dbg_fragtree2("dealing with hole frag %u-%u.\n",
243 this->ofs, this->ofs + this->size);
244
245 /* OK. 'this' is pointing at the first frag that newfrag->ofs at least partially obsoletes,
246 * - i.e. newfrag->ofs < this->ofs+this->size && newfrag->ofs >= this->ofs
247 */
248 if (newfrag->ofs > this->ofs) {
249 /* This node isn't completely obsoleted. The start of it remains valid */
250
251 /* Mark the new node and the partially covered node REF_NORMAL -- let
252 the GC take a look at them */
253 mark_ref_normal(newfrag->node->raw);
254 if (this->node)
255 mark_ref_normal(this->node->raw);
256
257 if (this->ofs + this->size > newfrag->ofs + newfrag->size) {
258 /* The new node splits 'this' frag into two */
259 struct jffs2_node_frag *newfrag2;
260
261 if (this->node)
262 dbg_fragtree2("split old frag 0x%04x-0x%04x, phys 0x%08x\n",
263 this->ofs, this->ofs+this->size, ref_offset(this->node->raw));
264 else
265 dbg_fragtree2("split old hole frag 0x%04x-0x%04x\n",
266 this->ofs, this->ofs+this->size);
267
268 /* New second frag pointing to this's node */
269 newfrag2 = new_fragment(this->node, newfrag->ofs + newfrag->size,
270 this->ofs + this->size - newfrag->ofs - newfrag->size);
271 if (unlikely(!newfrag2))
272 return -ENOMEM;
273 if (this->node)
274 this->node->frags++;
275
276 /* Adjust size of original 'this' */
277 this->size = newfrag->ofs - this->ofs;
278
279 /* Now, we know there's no node with offset
280 greater than this->ofs but smaller than
281 newfrag2->ofs or newfrag->ofs, for obvious
282 reasons. So we can do a tree insert from
283 'this' to insert newfrag, and a tree insert
284 from newfrag to insert newfrag2. */
285 jffs2_fragtree_insert(newfrag, this);
286 rb_insert_color(&newfrag->rb, root);
287
288 jffs2_fragtree_insert(newfrag2, newfrag);
289 rb_insert_color(&newfrag2->rb, root);
290
291 return 0;
292 }
293 /* New node just reduces 'this' frag in size, doesn't split it */
294 this->size = newfrag->ofs - this->ofs;
295
296 /* Again, we know it lives down here in the tree */
297 jffs2_fragtree_insert(newfrag, this);
298 rb_insert_color(&newfrag->rb, root);
299 } else {
300 /* New frag starts at the same point as 'this' used to. Replace
301 it in the tree without doing a delete and insertion */
302 dbg_fragtree2("inserting newfrag (*%p),%d-%d in before 'this' (*%p),%d-%d\n",
303 newfrag, newfrag->ofs, newfrag->ofs+newfrag->size, this, this->ofs, this->ofs+this->size);
304
305 rb_replace_node(&this->rb, &newfrag->rb, root);
306
307 if (newfrag->ofs + newfrag->size >= this->ofs+this->size) {
308 dbg_fragtree2("obsoleting node frag %p (%x-%x)\n", this, this->ofs, this->ofs+this->size);
309 jffs2_obsolete_node_frag(c, this);
310 } else {
311 this->ofs += newfrag->size;
312 this->size -= newfrag->size;
313
314 jffs2_fragtree_insert(this, newfrag);
315 rb_insert_color(&this->rb, root);
316 return 0;
317 }
318 }
319 /* OK, now we have newfrag added in the correct place in the tree, but
320 frag_next(newfrag) may be a fragment which is overlapped by it
321 */
322 while ((this = frag_next(newfrag)) && newfrag->ofs + newfrag->size >= this->ofs + this->size) {
323 /* 'this' frag is obsoleted completely. */
324 dbg_fragtree2("obsoleting node frag %p (%x-%x) and removing from tree\n",
325 this, this->ofs, this->ofs+this->size);
326 rb_erase(&this->rb, root);
327 jffs2_obsolete_node_frag(c, this);
328 }
329 /* Now we're pointing at the first frag which isn't totally obsoleted by
330 the new frag */
331
332 if (!this || newfrag->ofs + newfrag->size == this->ofs)
333 return 0;
334
335 /* Still some overlap but we don't need to move it in the tree */
336 this->size = (this->ofs + this->size) - (newfrag->ofs + newfrag->size);
337 this->ofs = newfrag->ofs + newfrag->size;
338
339 /* And mark them REF_NORMAL so the GC takes a look at them */
340 if (this->node)
341 mark_ref_normal(this->node->raw);
342 mark_ref_normal(newfrag->node->raw);
343
344 return 0;
345}
346
347/*
348 * Given an inode, probably with existing tree of fragments, add the new node
349 * to the fragment tree.
350 */
351int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn)
147{ 352{
148 struct jffs2_raw_node_ref *ref, *valid_ref; 353 int ret;
149 struct jffs2_tmp_dnode_info *tn; 354 struct jffs2_node_frag *newfrag;
150 struct rb_root ret_tn = RB_ROOT;
151 struct jffs2_full_dirent *fd, *ret_fd = NULL;
152 union jffs2_node_union node;
153 size_t retlen;
154 int err;
155
156 *mctime_ver = 0;
157
158 D1(printk(KERN_DEBUG "jffs2_get_inode_nodes(): ino #%u\n", f->inocache->ino));
159 355
160 spin_lock(&c->erase_completion_lock); 356 if (unlikely(!fn->size))
357 return 0;
161 358
162 valid_ref = jffs2_first_valid_node(f->inocache->nodes); 359 newfrag = new_fragment(fn, fn->ofs, fn->size);
360 if (unlikely(!newfrag))
361 return -ENOMEM;
362 newfrag->node->frags = 1;
163 363
164 if (!valid_ref && (f->inocache->ino != 1)) 364 dbg_fragtree("adding node %#04x-%#04x @0x%08x on flash, newfrag *%p\n",
165 printk(KERN_WARNING "Eep. No valid nodes for ino #%u\n", f->inocache->ino); 365 fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag);
166 366
167 while (valid_ref) { 367 ret = jffs2_add_frag_to_fragtree(c, &f->fragtree, newfrag);
168 /* We can hold a pointer to a non-obsolete node without the spinlock, 368 if (unlikely(ret))
169 but _obsolete_ nodes may disappear at any time, if the block 369 return ret;
170 they're in gets erased. So if we mark 'ref' obsolete while we're
171 not holding the lock, it can go away immediately. For that reason,
172 we find the next valid node first, before processing 'ref'.
173 */
174 ref = valid_ref;
175 valid_ref = jffs2_first_valid_node(ref->next_in_ino);
176 spin_unlock(&c->erase_completion_lock);
177 370
178 cond_resched(); 371 /* If we now share a page with other nodes, mark either previous
372 or next node REF_NORMAL, as appropriate. */
373 if (newfrag->ofs & (PAGE_CACHE_SIZE-1)) {
374 struct jffs2_node_frag *prev = frag_prev(newfrag);
375
376 mark_ref_normal(fn->raw);
377 /* If we don't start at zero there's _always_ a previous */
378 if (prev->node)
379 mark_ref_normal(prev->node->raw);
380 }
381
382 if ((newfrag->ofs+newfrag->size) & (PAGE_CACHE_SIZE-1)) {
383 struct jffs2_node_frag *next = frag_next(newfrag);
384
385 if (next) {
386 mark_ref_normal(fn->raw);
387 if (next->node)
388 mark_ref_normal(next->node->raw);
389 }
390 }
391 jffs2_dbg_fragtree_paranoia_check_nolock(f);
392
393 return 0;
394}
395
396/*
397 * Check the data CRC of the node.
398 *
399 * Returns: 0 if the data CRC is correct;
400 * 1 - if incorrect;
401 * error code if an error occured.
402 */
403static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info *tn)
404{
405 struct jffs2_raw_node_ref *ref = tn->fn->raw;
406 int err = 0, pointed = 0;
407 struct jffs2_eraseblock *jeb;
408 unsigned char *buffer;
409 uint32_t crc, ofs, retlen, len;
410
411 BUG_ON(tn->csize == 0);
412
413 if (!jffs2_is_writebuffered(c))
414 goto adj_acc;
415
416 /* Calculate how many bytes were already checked */
417 ofs = ref_offset(ref) + sizeof(struct jffs2_raw_inode);
418 len = ofs % c->wbuf_pagesize;
419 if (likely(len))
420 len = c->wbuf_pagesize - len;
421
422 if (len >= tn->csize) {
423 dbg_readinode("no need to check node at %#08x, data length %u, data starts at %#08x - it has already been checked.\n",
424 ref_offset(ref), tn->csize, ofs);
425 goto adj_acc;
426 }
427
428 ofs += len;
429 len = tn->csize - len;
430
431 dbg_readinode("check node at %#08x, data length %u, partial CRC %#08x, correct CRC %#08x, data starts at %#08x, start checking from %#08x - %u bytes.\n",
432 ref_offset(ref), tn->csize, tn->partial_crc, tn->data_crc, ofs - len, ofs, len);
433
434#ifndef __ECOS
435 /* TODO: instead, incapsulate point() stuff to jffs2_flash_read(),
436 * adding and jffs2_flash_read_end() interface. */
437 if (c->mtd->point) {
438 err = c->mtd->point(c->mtd, ofs, len, &retlen, &buffer);
439 if (!err && retlen < tn->csize) {
440 JFFS2_WARNING("MTD point returned len too short: %u instead of %u.\n", retlen, tn->csize);
441 c->mtd->unpoint(c->mtd, buffer, ofs, len);
442 } else if (err)
443 JFFS2_WARNING("MTD point failed: error code %d.\n", err);
444 else
445 pointed = 1; /* succefully pointed to device */
446 }
447#endif
448
449 if (!pointed) {
450 buffer = kmalloc(len, GFP_KERNEL);
451 if (unlikely(!buffer))
452 return -ENOMEM;
179 453
180 /* FIXME: point() */ 454 /* TODO: this is very frequent pattern, make it a separate
181 err = jffs2_flash_read(c, (ref_offset(ref)), 455 * routine */
182 min_t(uint32_t, ref_totlen(c, NULL, ref), sizeof(node)), 456 err = jffs2_flash_read(c, ofs, len, &retlen, buffer);
183 &retlen, (void *)&node);
184 if (err) { 457 if (err) {
185 printk(KERN_WARNING "error %d reading node at 0x%08x in get_inode_nodes()\n", err, ref_offset(ref)); 458 JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
186 goto free_out; 459 goto free_out;
187 } 460 }
188
189 461
190 /* Check we've managed to read at least the common node header */ 462 if (retlen != len) {
191 if (retlen < min_t(uint32_t, ref_totlen(c, NULL, ref), sizeof(node.u))) { 463 JFFS2_ERROR("short read at %#08x: %d instead of %d.\n", ofs, retlen, len);
192 printk(KERN_WARNING "short read in get_inode_nodes()\n");
193 err = -EIO; 464 err = -EIO;
194 goto free_out; 465 goto free_out;
195 } 466 }
196 467 }
197 switch (je16_to_cpu(node.u.nodetype)) {
198 case JFFS2_NODETYPE_DIRENT:
199 D1(printk(KERN_DEBUG "Node at %08x (%d) is a dirent node\n", ref_offset(ref), ref_flags(ref)));
200 if (ref_flags(ref) == REF_UNCHECKED) {
201 printk(KERN_WARNING "BUG: Dirent node at 0x%08x never got checked? How?\n", ref_offset(ref));
202 BUG();
203 }
204 if (retlen < sizeof(node.d)) {
205 printk(KERN_WARNING "short read in get_inode_nodes()\n");
206 err = -EIO;
207 goto free_out;
208 }
209 /* sanity check */
210 if (PAD((node.d.nsize + sizeof (node.d))) != PAD(je32_to_cpu (node.d.totlen))) {
211 printk(KERN_NOTICE "jffs2_get_inode_nodes(): Illegal nsize in node at 0x%08x: nsize 0x%02x, totlen %04x\n",
212 ref_offset(ref), node.d.nsize, je32_to_cpu(node.d.totlen));
213 jffs2_mark_node_obsolete(c, ref);
214 spin_lock(&c->erase_completion_lock);
215 continue;
216 }
217 if (je32_to_cpu(node.d.version) > *highest_version)
218 *highest_version = je32_to_cpu(node.d.version);
219 if (ref_obsolete(ref)) {
220 /* Obsoleted. This cannot happen, surely? dwmw2 20020308 */
221 printk(KERN_ERR "Dirent node at 0x%08x became obsolete while we weren't looking\n",
222 ref_offset(ref));
223 BUG();
224 }
225
226 fd = jffs2_alloc_full_dirent(node.d.nsize+1);
227 if (!fd) {
228 err = -ENOMEM;
229 goto free_out;
230 }
231 fd->raw = ref;
232 fd->version = je32_to_cpu(node.d.version);
233 fd->ino = je32_to_cpu(node.d.ino);
234 fd->type = node.d.type;
235
236 /* Pick out the mctime of the latest dirent */
237 if(fd->version > *mctime_ver) {
238 *mctime_ver = fd->version;
239 *latest_mctime = je32_to_cpu(node.d.mctime);
240 }
241 468
242 /* memcpy as much of the name as possible from the raw 469 /* Continue calculating CRC */
243 dirent we've already read from the flash 470 crc = crc32(tn->partial_crc, buffer, len);
244 */ 471 if(!pointed)
245 if (retlen > sizeof(struct jffs2_raw_dirent)) 472 kfree(buffer);
246 memcpy(&fd->name[0], &node.d.name[0], min_t(uint32_t, node.d.nsize, (retlen-sizeof(struct jffs2_raw_dirent)))); 473#ifndef __ECOS
247 474 else
248 /* Do we need to copy any more of the name directly 475 c->mtd->unpoint(c->mtd, buffer, ofs, len);
249 from the flash? 476#endif
250 */
251 if (node.d.nsize + sizeof(struct jffs2_raw_dirent) > retlen) {
252 /* FIXME: point() */
253 int already = retlen - sizeof(struct jffs2_raw_dirent);
254
255 err = jffs2_flash_read(c, (ref_offset(ref)) + retlen,
256 node.d.nsize - already, &retlen, &fd->name[already]);
257 if (!err && retlen != node.d.nsize - already)
258 err = -EIO;
259
260 if (err) {
261 printk(KERN_WARNING "Read remainder of name in jffs2_get_inode_nodes(): error %d\n", err);
262 jffs2_free_full_dirent(fd);
263 goto free_out;
264 }
265 }
266 fd->nhash = full_name_hash(fd->name, node.d.nsize);
267 fd->next = NULL;
268 fd->name[node.d.nsize] = '\0';
269 /* Wheee. We now have a complete jffs2_full_dirent structure, with
270 the name in it and everything. Link it into the list
271 */
272 D1(printk(KERN_DEBUG "Adding fd \"%s\", ino #%u\n", fd->name, fd->ino));
273 jffs2_add_fd_to_list(c, fd, &ret_fd);
274 break;
275
276 case JFFS2_NODETYPE_INODE:
277 D1(printk(KERN_DEBUG "Node at %08x (%d) is a data node\n", ref_offset(ref), ref_flags(ref)));
278 if (retlen < sizeof(node.i)) {
279 printk(KERN_WARNING "read too short for dnode\n");
280 err = -EIO;
281 goto free_out;
282 }
283 if (je32_to_cpu(node.i.version) > *highest_version)
284 *highest_version = je32_to_cpu(node.i.version);
285 D1(printk(KERN_DEBUG "version %d, highest_version now %d\n", je32_to_cpu(node.i.version), *highest_version));
286
287 if (ref_obsolete(ref)) {
288 /* Obsoleted. This cannot happen, surely? dwmw2 20020308 */
289 printk(KERN_ERR "Inode node at 0x%08x became obsolete while we weren't looking\n",
290 ref_offset(ref));
291 BUG();
292 }
293 477
294 /* If we've never checked the CRCs on this node, check them now. */ 478 if (crc != tn->data_crc) {
295 if (ref_flags(ref) == REF_UNCHECKED) { 479 JFFS2_NOTICE("wrong data CRC in data node at 0x%08x: read %#08x, calculated %#08x.\n",
296 uint32_t crc, len; 480 ofs, tn->data_crc, crc);
297 struct jffs2_eraseblock *jeb; 481 return 1;
298 482 }
299 crc = crc32(0, &node, sizeof(node.i)-8);
300 if (crc != je32_to_cpu(node.i.node_crc)) {
301 printk(KERN_NOTICE "jffs2_get_inode_nodes(): CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
302 ref_offset(ref), je32_to_cpu(node.i.node_crc), crc);
303 jffs2_mark_node_obsolete(c, ref);
304 spin_lock(&c->erase_completion_lock);
305 continue;
306 }
307
308 /* sanity checks */
309 if ( je32_to_cpu(node.i.offset) > je32_to_cpu(node.i.isize) ||
310 PAD(je32_to_cpu(node.i.csize) + sizeof (node.i)) != PAD(je32_to_cpu(node.i.totlen))) {
311 printk(KERN_NOTICE "jffs2_get_inode_nodes(): Inode corrupted at 0x%08x, totlen %d, #ino %d, version %d, isize %d, csize %d, dsize %d \n",
312 ref_offset(ref), je32_to_cpu(node.i.totlen), je32_to_cpu(node.i.ino),
313 je32_to_cpu(node.i.version), je32_to_cpu(node.i.isize),
314 je32_to_cpu(node.i.csize), je32_to_cpu(node.i.dsize));
315 jffs2_mark_node_obsolete(c, ref);
316 spin_lock(&c->erase_completion_lock);
317 continue;
318 }
319 483
320 if (node.i.compr != JFFS2_COMPR_ZERO && je32_to_cpu(node.i.csize)) { 484adj_acc:
321 unsigned char *buf=NULL; 485 jeb = &c->blocks[ref->flash_offset / c->sector_size];
322 uint32_t pointed = 0; 486 len = ref_totlen(c, jeb, ref);
323#ifndef __ECOS 487
324 if (c->mtd->point) { 488 /*
325 err = c->mtd->point (c->mtd, ref_offset(ref) + sizeof(node.i), je32_to_cpu(node.i.csize), 489 * Mark the node as having been checked and fix the
326 &retlen, &buf); 490 * accounting accordingly.
327 if (!err && retlen < je32_to_cpu(node.i.csize)) { 491 */
328 D1(printk(KERN_DEBUG "MTD point returned len too short: 0x%zx\n", retlen)); 492 spin_lock(&c->erase_completion_lock);
329 c->mtd->unpoint(c->mtd, buf, ref_offset(ref) + sizeof(node.i), je32_to_cpu(node.i.csize)); 493 jeb->used_size += len;
330 } else if (err){ 494 jeb->unchecked_size -= len;
331 D1(printk(KERN_DEBUG "MTD point failed %d\n", err)); 495 c->used_size += len;
332 } else 496 c->unchecked_size -= len;
333 pointed = 1; /* succefully pointed to device */ 497 spin_unlock(&c->erase_completion_lock);
334 } 498
335#endif 499 return 0;
336 if(!pointed){ 500
337 buf = kmalloc(je32_to_cpu(node.i.csize), GFP_KERNEL); 501free_out:
338 if (!buf) 502 if(!pointed)
339 return -ENOMEM; 503 kfree(buffer);
340
341 err = jffs2_flash_read(c, ref_offset(ref) + sizeof(node.i), je32_to_cpu(node.i.csize),
342 &retlen, buf);
343 if (!err && retlen != je32_to_cpu(node.i.csize))
344 err = -EIO;
345 if (err) {
346 kfree(buf);
347 return err;
348 }
349 }
350 crc = crc32(0, buf, je32_to_cpu(node.i.csize));
351 if(!pointed)
352 kfree(buf);
353#ifndef __ECOS 504#ifndef __ECOS
354 else 505 else
355 c->mtd->unpoint(c->mtd, buf, ref_offset(ref) + sizeof(node.i), je32_to_cpu(node.i.csize)); 506 c->mtd->unpoint(c->mtd, buffer, ofs, len);
356#endif 507#endif
508 return err;
509}
357 510
358 if (crc != je32_to_cpu(node.i.data_crc)) { 511/*
359 printk(KERN_NOTICE "jffs2_get_inode_nodes(): Data CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", 512 * Helper function for jffs2_add_older_frag_to_fragtree().
360 ref_offset(ref), je32_to_cpu(node.i.data_crc), crc); 513 *
361 jffs2_mark_node_obsolete(c, ref); 514 * Checks the node if we are in the checking stage.
362 spin_lock(&c->erase_completion_lock); 515 */
363 continue; 516static inline int check_node(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_tmp_dnode_info *tn)
364 } 517{
365 518 int ret;
366 }
367 519
368 /* Mark the node as having been checked and fix the accounting accordingly */ 520 BUG_ON(ref_obsolete(tn->fn->raw));
369 spin_lock(&c->erase_completion_lock); 521
370 jeb = &c->blocks[ref->flash_offset / c->sector_size]; 522 /* We only check the data CRC of unchecked nodes */
371 len = ref_totlen(c, jeb, ref); 523 if (ref_flags(tn->fn->raw) != REF_UNCHECKED)
372 524 return 0;
373 jeb->used_size += len; 525
374 jeb->unchecked_size -= len; 526 dbg_fragtree2("check node %#04x-%#04x, phys offs %#08x.\n",
375 c->used_size += len; 527 tn->fn->ofs, tn->fn->ofs + tn->fn->size, ref_offset(tn->fn->raw));
376 c->unchecked_size -= len; 528
377 529 ret = check_node_data(c, tn);
378 /* If node covers at least a whole page, or if it starts at the 530 if (unlikely(ret < 0)) {
379 beginning of a page and runs to the end of the file, or if 531 JFFS2_ERROR("check_node_data() returned error: %d.\n",
380 it's a hole node, mark it REF_PRISTINE, else REF_NORMAL. 532 ret);
381 533 } else if (unlikely(ret > 0)) {
382 If it's actually overlapped, it'll get made NORMAL (or OBSOLETE) 534 dbg_fragtree2("CRC error, mark it obsolete.\n");
383 when the overlapping node(s) get added to the tree anyway. 535 jffs2_mark_node_obsolete(c, tn->fn->raw);
384 */ 536 }
385 if ((je32_to_cpu(node.i.dsize) >= PAGE_CACHE_SIZE) || 537
386 ( ((je32_to_cpu(node.i.offset)&(PAGE_CACHE_SIZE-1))==0) && 538 return ret;
387 (je32_to_cpu(node.i.dsize)+je32_to_cpu(node.i.offset) == je32_to_cpu(node.i.isize)))) { 539}
388 D1(printk(KERN_DEBUG "Marking node at 0x%08x REF_PRISTINE\n", ref_offset(ref))); 540
389 ref->flash_offset = ref_offset(ref) | REF_PRISTINE; 541/*
390 } else { 542 * Helper function for jffs2_add_older_frag_to_fragtree().
391 D1(printk(KERN_DEBUG "Marking node at 0x%08x REF_NORMAL\n", ref_offset(ref))); 543 *
392 ref->flash_offset = ref_offset(ref) | REF_NORMAL; 544 * Called when the new fragment that is being inserted
393 } 545 * splits a hole fragment.
394 spin_unlock(&c->erase_completion_lock); 546 */
547static int split_hole(struct jffs2_sb_info *c, struct rb_root *root,
548 struct jffs2_node_frag *newfrag, struct jffs2_node_frag *hole)
549{
550 dbg_fragtree2("fragment %#04x-%#04x splits the hole %#04x-%#04x\n",
551 newfrag->ofs, newfrag->ofs + newfrag->size, hole->ofs, hole->ofs + hole->size);
552
553 if (hole->ofs == newfrag->ofs) {
554 /*
555 * Well, the new fragment actually starts at the same offset as
556 * the hole.
557 */
558 if (hole->ofs + hole->size > newfrag->ofs + newfrag->size) {
559 /*
560 * We replace the overlapped left part of the hole by
561 * the new node.
562 */
563
564 dbg_fragtree2("insert fragment %#04x-%#04x and cut the left part of the hole\n",
565 newfrag->ofs, newfrag->ofs + newfrag->size);
566 rb_replace_node(&hole->rb, &newfrag->rb, root);
567
568 hole->ofs += newfrag->size;
569 hole->size -= newfrag->size;
570
571 /*
572 * We know that 'hole' should be the right hand
573 * fragment.
574 */
575 jffs2_fragtree_insert(hole, newfrag);
576 rb_insert_color(&hole->rb, root);
577 } else {
578 /*
579 * Ah, the new fragment is of the same size as the hole.
580 * Relace the hole by it.
581 */
582 dbg_fragtree2("insert fragment %#04x-%#04x and overwrite hole\n",
583 newfrag->ofs, newfrag->ofs + newfrag->size);
584 rb_replace_node(&hole->rb, &newfrag->rb, root);
585 jffs2_free_node_frag(hole);
586 }
587 } else {
588 /* The new fragment lefts some hole space at the left */
589
590 struct jffs2_node_frag * newfrag2 = NULL;
591
592 if (hole->ofs + hole->size > newfrag->ofs + newfrag->size) {
593 /* The new frag also lefts some space at the right */
594 newfrag2 = new_fragment(NULL, newfrag->ofs +
595 newfrag->size, hole->ofs + hole->size
596 - newfrag->ofs - newfrag->size);
597 if (unlikely(!newfrag2)) {
598 jffs2_free_node_frag(newfrag);
599 return -ENOMEM;
395 } 600 }
601 }
602
603 hole->size = newfrag->ofs - hole->ofs;
604 dbg_fragtree2("left the hole %#04x-%#04x at the left and inserd fragment %#04x-%#04x\n",
605 hole->ofs, hole->ofs + hole->size, newfrag->ofs, newfrag->ofs + newfrag->size);
606
607 jffs2_fragtree_insert(newfrag, hole);
608 rb_insert_color(&newfrag->rb, root);
609
610 if (newfrag2) {
611 dbg_fragtree2("left the hole %#04x-%#04x at the right\n",
612 newfrag2->ofs, newfrag2->ofs + newfrag2->size);
613 jffs2_fragtree_insert(newfrag2, newfrag);
614 rb_insert_color(&newfrag2->rb, root);
615 }
616 }
617
618 return 0;
619}
620
621/*
622 * This function is used when we build inode. It expects the nodes are passed
623 * in the decreasing version order. The whole point of this is to improve the
624 * inodes checking on NAND: we check the nodes' data CRC only when they are not
625 * obsoleted. Previously, add_frag_to_fragtree() function was used and
626 * nodes were passed to it in the increasing version ordes and CRCs of all
627 * nodes were checked.
628 *
629 * Note: tn->fn->size shouldn't be zero.
630 *
631 * Returns 0 if the node was inserted
632 * 1 if it wasn't inserted (since it is obsolete)
633 * < 0 an if error occured
634 */
635int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
636 struct jffs2_tmp_dnode_info *tn)
637{
638 struct jffs2_node_frag *this, *newfrag;
639 uint32_t lastend;
640 struct jffs2_full_dnode *fn = tn->fn;
641 struct rb_root *root = &f->fragtree;
642 uint32_t fn_size = fn->size, fn_ofs = fn->ofs;
643 int err, checked = 0;
644 int ref_flag;
645
646 dbg_fragtree("insert fragment %#04x-%#04x, ver %u\n", fn_ofs, fn_ofs + fn_size, tn->version);
647
648 /* Skip all the nodes which are completed before this one starts */
649 this = jffs2_lookup_node_frag(root, fn_ofs);
650 if (this)
651 dbg_fragtree2("'this' found %#04x-%#04x (%s)\n", this->ofs, this->ofs + this->size, this->node ? "data" : "hole");
652
653 if (this)
654 lastend = this->ofs + this->size;
655 else
656 lastend = 0;
657
658 /* Detect the preliminary type of node */
659 if (fn->size >= PAGE_CACHE_SIZE)
660 ref_flag = REF_PRISTINE;
661 else
662 ref_flag = REF_NORMAL;
663
664 /* See if we ran off the end of the root */
665 if (lastend <= fn_ofs) {
666 /* We did */
667
668 /*
669 * We are going to insert the new node into the
670 * fragment tree, so check it.
671 */
672 err = check_node(c, f, tn);
673 if (err != 0)
674 return err;
675
676 fn->frags = 1;
677
678 newfrag = new_fragment(fn, fn_ofs, fn_size);
679 if (unlikely(!newfrag))
680 return -ENOMEM;
681
682 err = no_overlapping_node(c, root, newfrag, this, lastend);
683 if (unlikely(err != 0)) {
684 jffs2_free_node_frag(newfrag);
685 return err;
686 }
687
688 goto out_ok;
689 }
396 690
397 tn = jffs2_alloc_tmp_dnode_info(); 691 fn->frags = 0;
398 if (!tn) { 692
399 D1(printk(KERN_DEBUG "alloc tn failed\n")); 693 while (1) {
400 err = -ENOMEM; 694 /*
401 goto free_out; 695 * Here we have:
696 * fn_ofs < this->ofs + this->size && fn_ofs >= this->ofs.
697 *
698 * Remember, 'this' has higher version, any non-hole node
699 * which is already in the fragtree is newer then the newly
700 * inserted.
701 */
702 if (!this->node) {
703 /*
704 * 'this' is the hole fragment, so at least the
705 * beginning of the new fragment is valid.
706 */
707
708 /*
709 * We are going to insert the new node into the
710 * fragment tree, so check it.
711 */
712 if (!checked) {
713 err = check_node(c, f, tn);
714 if (unlikely(err != 0))
715 return err;
716 checked = 1;
402 } 717 }
403 718
404 tn->fn = jffs2_alloc_full_dnode(); 719 if (this->ofs + this->size >= fn_ofs + fn_size) {
405 if (!tn->fn) { 720 /* We split the hole on two parts */
406 D1(printk(KERN_DEBUG "alloc fn failed\n")); 721
407 err = -ENOMEM; 722 fn->frags += 1;
408 jffs2_free_tmp_dnode_info(tn); 723 newfrag = new_fragment(fn, fn_ofs, fn_size);
409 goto free_out; 724 if (unlikely(!newfrag))
725 return -ENOMEM;
726
727 err = split_hole(c, root, newfrag, this);
728 if (unlikely(err))
729 return err;
730 goto out_ok;
410 } 731 }
411 tn->version = je32_to_cpu(node.i.version); 732
412 tn->fn->ofs = je32_to_cpu(node.i.offset); 733 /*
413 /* There was a bug where we wrote hole nodes out with 734 * The beginning of the new fragment is valid since it
414 csize/dsize swapped. Deal with it */ 735 * overlaps the hole node.
415 if (node.i.compr == JFFS2_COMPR_ZERO && !je32_to_cpu(node.i.dsize) && je32_to_cpu(node.i.csize)) 736 */
416 tn->fn->size = je32_to_cpu(node.i.csize); 737
417 else // normal case... 738 ref_flag = REF_NORMAL;
418 tn->fn->size = je32_to_cpu(node.i.dsize); 739
419 tn->fn->raw = ref; 740 fn->frags += 1;
420 D1(printk(KERN_DEBUG "dnode @%08x: ver %u, offset %04x, dsize %04x\n", 741 newfrag = new_fragment(fn, fn_ofs,
421 ref_offset(ref), je32_to_cpu(node.i.version), 742 this->ofs + this->size - fn_ofs);
422 je32_to_cpu(node.i.offset), je32_to_cpu(node.i.dsize))); 743 if (unlikely(!newfrag))
423 jffs2_add_tn_to_tree(tn, &ret_tn); 744 return -ENOMEM;
424 break; 745
425 746 if (fn_ofs == this->ofs) {
426 default: 747 /*
427 if (ref_flags(ref) == REF_UNCHECKED) { 748 * The new node starts at the same offset as
428 struct jffs2_eraseblock *jeb; 749 * the hole and supersieds the hole.
429 uint32_t len; 750 */
430 751 dbg_fragtree2("add the new fragment instead of hole %#04x-%#04x, refcnt %d\n",
431 printk(KERN_ERR "Eep. Unknown node type %04x at %08x was marked REF_UNCHECKED\n", 752 fn_ofs, fn_ofs + this->ofs + this->size - fn_ofs, fn->frags);
432 je16_to_cpu(node.u.nodetype), ref_offset(ref)); 753
433 754 rb_replace_node(&this->rb, &newfrag->rb, root);
434 /* Mark the node as having been checked and fix the accounting accordingly */ 755 jffs2_free_node_frag(this);
435 spin_lock(&c->erase_completion_lock); 756 } else {
436 jeb = &c->blocks[ref->flash_offset / c->sector_size]; 757 /*
437 len = ref_totlen(c, jeb, ref); 758 * The hole becomes shorter as its right part
438 759 * is supersieded by the new fragment.
439 jeb->used_size += len; 760 */
440 jeb->unchecked_size -= len; 761 dbg_fragtree2("reduce size of hole %#04x-%#04x to %#04x-%#04x\n",
441 c->used_size += len; 762 this->ofs, this->ofs + this->size, this->ofs, this->ofs + this->size - newfrag->size);
442 c->unchecked_size -= len; 763
443 764 dbg_fragtree2("add new fragment %#04x-%#04x, refcnt %d\n", fn_ofs,
444 mark_ref_normal(ref); 765 fn_ofs + this->ofs + this->size - fn_ofs, fn->frags);
445 spin_unlock(&c->erase_completion_lock); 766
767 this->size -= newfrag->size;
768 jffs2_fragtree_insert(newfrag, this);
769 rb_insert_color(&newfrag->rb, root);
446 } 770 }
447 node.u.nodetype = cpu_to_je16(JFFS2_NODE_ACCURATE | je16_to_cpu(node.u.nodetype)); 771
448 if (crc32(0, &node, sizeof(struct jffs2_unknown_node)-4) != je32_to_cpu(node.u.hdr_crc)) { 772 fn_ofs += newfrag->size;
449 /* Hmmm. This should have been caught at scan time. */ 773 fn_size -= newfrag->size;
450 printk(KERN_ERR "Node header CRC failed at %08x. But it must have been OK earlier.\n", 774 this = rb_entry(rb_next(&newfrag->rb),
451 ref_offset(ref)); 775 struct jffs2_node_frag, rb);
452 printk(KERN_ERR "Node was: { %04x, %04x, %08x, %08x }\n", 776
453 je16_to_cpu(node.u.magic), je16_to_cpu(node.u.nodetype), je32_to_cpu(node.u.totlen), 777 dbg_fragtree2("switch to the next 'this' fragment: %#04x-%#04x %s\n",
454 je32_to_cpu(node.u.hdr_crc)); 778 this->ofs, this->ofs + this->size, this->node ? "(data)" : "(hole)");
455 jffs2_mark_node_obsolete(c, ref); 779 }
456 } else switch(je16_to_cpu(node.u.nodetype) & JFFS2_COMPAT_MASK) { 780
457 case JFFS2_FEATURE_INCOMPAT: 781 /*
458 printk(KERN_NOTICE "Unknown INCOMPAT nodetype %04X at %08x\n", je16_to_cpu(node.u.nodetype), ref_offset(ref)); 782 * 'This' node is not the hole so it obsoletes the new fragment
459 /* EEP */ 783 * either fully or partially.
460 BUG(); 784 */
461 break; 785 if (this->ofs + this->size >= fn_ofs + fn_size) {
462 case JFFS2_FEATURE_ROCOMPAT: 786 /* The new node is obsolete, drop it */
463 printk(KERN_NOTICE "Unknown ROCOMPAT nodetype %04X at %08x\n", je16_to_cpu(node.u.nodetype), ref_offset(ref)); 787 if (fn->frags == 0) {
464 if (!(c->flags & JFFS2_SB_FLAG_RO)) 788 dbg_fragtree2("%#04x-%#04x is obsolete, mark it obsolete\n", fn_ofs, fn_ofs + fn_size);
465 BUG(); 789 ref_flag = REF_OBSOLETE;
466 break;
467 case JFFS2_FEATURE_RWCOMPAT_COPY:
468 printk(KERN_NOTICE "Unknown RWCOMPAT_COPY nodetype %04X at %08x\n", je16_to_cpu(node.u.nodetype), ref_offset(ref));
469 break;
470 case JFFS2_FEATURE_RWCOMPAT_DELETE:
471 printk(KERN_NOTICE "Unknown RWCOMPAT_DELETE nodetype %04X at %08x\n", je16_to_cpu(node.u.nodetype), ref_offset(ref));
472 jffs2_mark_node_obsolete(c, ref);
473 break;
474 } 790 }
791 goto out_ok;
792 } else {
793 struct jffs2_node_frag *new_this;
794
795 /* 'This' node obsoletes the beginning of the new node */
796 dbg_fragtree2("the beginning %#04x-%#04x is obsolete\n", fn_ofs, this->ofs + this->size);
797
798 ref_flag = REF_NORMAL;
799
800 fn_size -= this->ofs + this->size - fn_ofs;
801 fn_ofs = this->ofs + this->size;
802 dbg_fragtree2("now considering %#04x-%#04x\n", fn_ofs, fn_ofs + fn_size);
803
804 new_this = rb_entry(rb_next(&this->rb), struct jffs2_node_frag, rb);
805 if (!new_this) {
806 /*
807 * There is no next fragment. Add the rest of
808 * the new node as the right-hand child.
809 */
810 if (!checked) {
811 err = check_node(c, f, tn);
812 if (unlikely(err != 0))
813 return err;
814 checked = 1;
815 }
475 816
817 fn->frags += 1;
818 newfrag = new_fragment(fn, fn_ofs, fn_size);
819 if (unlikely(!newfrag))
820 return -ENOMEM;
821
822 dbg_fragtree2("there are no more fragments, insert %#04x-%#04x\n",
823 newfrag->ofs, newfrag->ofs + newfrag->size);
824 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right);
825 rb_insert_color(&newfrag->rb, root);
826 goto out_ok;
827 } else {
828 this = new_this;
829 dbg_fragtree2("switch to the next 'this' fragment: %#04x-%#04x %s\n",
830 this->ofs, this->ofs + this->size, this->node ? "(data)" : "(hole)");
831 }
476 } 832 }
477 spin_lock(&c->erase_completion_lock); 833 }
834
835out_ok:
836 BUG_ON(fn->size < PAGE_CACHE_SIZE && ref_flag == REF_PRISTINE);
478 837
838 if (ref_flag == REF_OBSOLETE) {
839 dbg_fragtree2("the node is obsolete now\n");
840 /* jffs2_mark_node_obsolete() will adjust space accounting */
841 jffs2_mark_node_obsolete(c, fn->raw);
842 return 1;
479 } 843 }
844
845 dbg_fragtree2("the node is \"%s\" now\n", ref_flag == REF_NORMAL ? "REF_NORMAL" : "REF_PRISTINE");
846
847 /* Space accounting was adjusted at check_node_data() */
848 spin_lock(&c->erase_completion_lock);
849 fn->raw->flash_offset = ref_offset(fn->raw) | ref_flag;
480 spin_unlock(&c->erase_completion_lock); 850 spin_unlock(&c->erase_completion_lock);
481 *tnp = ret_tn;
482 *fdp = ret_fd;
483 851
484 return 0; 852 return 0;
485
486 free_out:
487 jffs2_free_tmp_dnode_info_list(&ret_tn);
488 jffs2_free_full_dirent_list(ret_fd);
489 return err;
490} 853}
491 854
492void jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, int state) 855void jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, int state)
@@ -499,24 +862,21 @@ void jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache
499 862
500/* During mount, this needs no locking. During normal operation, its 863/* During mount, this needs no locking. During normal operation, its
501 callers want to do other stuff while still holding the inocache_lock. 864 callers want to do other stuff while still holding the inocache_lock.
502 Rather than introducing special case get_ino_cache functions or 865 Rather than introducing special case get_ino_cache functions or
503 callbacks, we just let the caller do the locking itself. */ 866 callbacks, we just let the caller do the locking itself. */
504 867
505struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t ino) 868struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t ino)
506{ 869{
507 struct jffs2_inode_cache *ret; 870 struct jffs2_inode_cache *ret;
508 871
509 D2(printk(KERN_DEBUG "jffs2_get_ino_cache(): ino %u\n", ino));
510
511 ret = c->inocache_list[ino % INOCACHE_HASHSIZE]; 872 ret = c->inocache_list[ino % INOCACHE_HASHSIZE];
512 while (ret && ret->ino < ino) { 873 while (ret && ret->ino < ino) {
513 ret = ret->next; 874 ret = ret->next;
514 } 875 }
515 876
516 if (ret && ret->ino != ino) 877 if (ret && ret->ino != ino)
517 ret = NULL; 878 ret = NULL;
518 879
519 D2(printk(KERN_DEBUG "jffs2_get_ino_cache found %p for ino %u\n", ret, ino));
520 return ret; 880 return ret;
521} 881}
522 882
@@ -528,7 +888,7 @@ void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new
528 if (!new->ino) 888 if (!new->ino)
529 new->ino = ++c->highest_ino; 889 new->ino = ++c->highest_ino;
530 890
531 D2(printk(KERN_DEBUG "jffs2_add_ino_cache: Add %p (ino #%u)\n", new, new->ino)); 891 dbg_inocache("add %p (ino #%u)\n", new, new->ino);
532 892
533 prev = &c->inocache_list[new->ino % INOCACHE_HASHSIZE]; 893 prev = &c->inocache_list[new->ino % INOCACHE_HASHSIZE];
534 894
@@ -544,11 +904,12 @@ void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new
544void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old) 904void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old)
545{ 905{
546 struct jffs2_inode_cache **prev; 906 struct jffs2_inode_cache **prev;
547 D1(printk(KERN_DEBUG "jffs2_del_ino_cache: Del %p (ino #%u)\n", old, old->ino)); 907
908 dbg_inocache("del %p (ino #%u)\n", old, old->ino);
548 spin_lock(&c->inocache_lock); 909 spin_lock(&c->inocache_lock);
549 910
550 prev = &c->inocache_list[old->ino % INOCACHE_HASHSIZE]; 911 prev = &c->inocache_list[old->ino % INOCACHE_HASHSIZE];
551 912
552 while ((*prev) && (*prev)->ino < old->ino) { 913 while ((*prev) && (*prev)->ino < old->ino) {
553 prev = &(*prev)->next; 914 prev = &(*prev)->next;
554 } 915 }
@@ -558,7 +919,7 @@ void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old)
558 919
559 /* Free it now unless it's in READING or CLEARING state, which 920 /* Free it now unless it's in READING or CLEARING state, which
560 are the transitions upon read_inode() and clear_inode(). The 921 are the transitions upon read_inode() and clear_inode(). The
561 rest of the time we know nobody else is looking at it, and 922 rest of the time we know nobody else is looking at it, and
562 if it's held by read_inode() or clear_inode() they'll free it 923 if it's held by read_inode() or clear_inode() they'll free it
563 for themselves. */ 924 for themselves. */
564 if (old->state != INO_STATE_READING && old->state != INO_STATE_CLEARING) 925 if (old->state != INO_STATE_READING && old->state != INO_STATE_CLEARING)
@@ -571,7 +932,7 @@ void jffs2_free_ino_caches(struct jffs2_sb_info *c)
571{ 932{
572 int i; 933 int i;
573 struct jffs2_inode_cache *this, *next; 934 struct jffs2_inode_cache *this, *next;
574 935
575 for (i=0; i<INOCACHE_HASHSIZE; i++) { 936 for (i=0; i<INOCACHE_HASHSIZE; i++) {
576 this = c->inocache_list[i]; 937 this = c->inocache_list[i];
577 while (this) { 938 while (this) {
@@ -598,38 +959,30 @@ void jffs2_free_raw_node_refs(struct jffs2_sb_info *c)
598 c->blocks[i].first_node = c->blocks[i].last_node = NULL; 959 c->blocks[i].first_node = c->blocks[i].last_node = NULL;
599 } 960 }
600} 961}
601 962
602struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_t offset) 963struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_t offset)
603{ 964{
604 /* The common case in lookup is that there will be a node 965 /* The common case in lookup is that there will be a node
605 which precisely matches. So we go looking for that first */ 966 which precisely matches. So we go looking for that first */
606 struct rb_node *next; 967 struct rb_node *next;
607 struct jffs2_node_frag *prev = NULL; 968 struct jffs2_node_frag *prev = NULL;
608 struct jffs2_node_frag *frag = NULL; 969 struct jffs2_node_frag *frag = NULL;
609 970
610 D2(printk(KERN_DEBUG "jffs2_lookup_node_frag(%p, %d)\n", fragtree, offset)); 971 dbg_fragtree2("root %p, offset %d\n", fragtree, offset);
611 972
612 next = fragtree->rb_node; 973 next = fragtree->rb_node;
613 974
614 while(next) { 975 while(next) {
615 frag = rb_entry(next, struct jffs2_node_frag, rb); 976 frag = rb_entry(next, struct jffs2_node_frag, rb);
616 977
617 D2(printk(KERN_DEBUG "Considering frag %d-%d (%p). left %p, right %p\n",
618 frag->ofs, frag->ofs+frag->size, frag, frag->rb.rb_left, frag->rb.rb_right));
619 if (frag->ofs + frag->size <= offset) { 978 if (frag->ofs + frag->size <= offset) {
620 D2(printk(KERN_DEBUG "Going right from frag %d-%d, before the region we care about\n",
621 frag->ofs, frag->ofs+frag->size));
622 /* Remember the closest smaller match on the way down */ 979 /* Remember the closest smaller match on the way down */
623 if (!prev || frag->ofs > prev->ofs) 980 if (!prev || frag->ofs > prev->ofs)
624 prev = frag; 981 prev = frag;
625 next = frag->rb.rb_right; 982 next = frag->rb.rb_right;
626 } else if (frag->ofs > offset) { 983 } else if (frag->ofs > offset) {
627 D2(printk(KERN_DEBUG "Going left from frag %d-%d, after the region we care about\n",
628 frag->ofs, frag->ofs+frag->size));
629 next = frag->rb.rb_left; 984 next = frag->rb.rb_left;
630 } else { 985 } else {
631 D2(printk(KERN_DEBUG "Returning frag %d,%d, matched\n",
632 frag->ofs, frag->ofs+frag->size));
633 return frag; 986 return frag;
634 } 987 }
635 } 988 }
@@ -638,11 +991,11 @@ struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_
638 and return the closest smaller one */ 991 and return the closest smaller one */
639 992
640 if (prev) 993 if (prev)
641 D2(printk(KERN_DEBUG "No match. Returning frag %d,%d, closest previous\n", 994 dbg_fragtree2("no match. Returning frag %#04x-%#04x, closest previous\n",
642 prev->ofs, prev->ofs+prev->size)); 995 prev->ofs, prev->ofs+prev->size);
643 else 996 else
644 D2(printk(KERN_DEBUG "Returning NULL, empty fragtree\n")); 997 dbg_fragtree2("returning NULL, empty fragtree\n");
645 998
646 return prev; 999 return prev;
647} 1000}
648 1001
@@ -656,39 +1009,32 @@ void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
656 if (!root->rb_node) 1009 if (!root->rb_node)
657 return; 1010 return;
658 1011
659 frag = (rb_entry(root->rb_node, struct jffs2_node_frag, rb)); 1012 dbg_fragtree("killing\n");
660 1013
1014 frag = (rb_entry(root->rb_node, struct jffs2_node_frag, rb));
661 while(frag) { 1015 while(frag) {
662 if (frag->rb.rb_left) { 1016 if (frag->rb.rb_left) {
663 D2(printk(KERN_DEBUG "Going left from frag (%p) %d-%d\n",
664 frag, frag->ofs, frag->ofs+frag->size));
665 frag = frag_left(frag); 1017 frag = frag_left(frag);
666 continue; 1018 continue;
667 } 1019 }
668 if (frag->rb.rb_right) { 1020 if (frag->rb.rb_right) {
669 D2(printk(KERN_DEBUG "Going right from frag (%p) %d-%d\n",
670 frag, frag->ofs, frag->ofs+frag->size));
671 frag = frag_right(frag); 1021 frag = frag_right(frag);
672 continue; 1022 continue;
673 } 1023 }
674 1024
675 D2(printk(KERN_DEBUG "jffs2_kill_fragtree: frag at 0x%x-0x%x: node %p, frags %d--\n",
676 frag->ofs, frag->ofs+frag->size, frag->node,
677 frag->node?frag->node->frags:0));
678
679 if (frag->node && !(--frag->node->frags)) { 1025 if (frag->node && !(--frag->node->frags)) {
680 /* Not a hole, and it's the final remaining frag 1026 /* Not a hole, and it's the final remaining frag
681 of this node. Free the node */ 1027 of this node. Free the node */
682 if (c) 1028 if (c)
683 jffs2_mark_node_obsolete(c, frag->node->raw); 1029 jffs2_mark_node_obsolete(c, frag->node->raw);
684 1030
685 jffs2_free_full_dnode(frag->node); 1031 jffs2_free_full_dnode(frag->node);
686 } 1032 }
687 parent = frag_parent(frag); 1033 parent = frag_parent(frag);
688 if (parent) { 1034 if (parent) {
689 if (frag_left(parent) == frag) 1035 if (frag_left(parent) == frag)
690 parent->rb.rb_left = NULL; 1036 parent->rb.rb_left = NULL;
691 else 1037 else
692 parent->rb.rb_right = NULL; 1038 parent->rb.rb_right = NULL;
693 } 1039 }
694 1040
@@ -698,29 +1044,3 @@ void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
698 cond_resched(); 1044 cond_resched();
699 } 1045 }
700} 1046}
701
702void jffs2_fragtree_insert(struct jffs2_node_frag *newfrag, struct jffs2_node_frag *base)
703{
704 struct rb_node *parent = &base->rb;
705 struct rb_node **link = &parent;
706
707 D2(printk(KERN_DEBUG "jffs2_fragtree_insert(%p; %d-%d, %p)\n", newfrag,
708 newfrag->ofs, newfrag->ofs+newfrag->size, base));
709
710 while (*link) {
711 parent = *link;
712 base = rb_entry(parent, struct jffs2_node_frag, rb);
713
714 D2(printk(KERN_DEBUG "fragtree_insert considering frag at 0x%x\n", base->ofs));
715 if (newfrag->ofs > base->ofs)
716 link = &base->rb.rb_right;
717 else if (newfrag->ofs < base->ofs)
718 link = &base->rb.rb_left;
719 else {
720 printk(KERN_CRIT "Duplicate frag at %08x (%p,%p)\n", newfrag->ofs, newfrag, base);
721 BUG();
722 }
723 }
724
725 rb_link_node(&newfrag->rb, &base->rb, link);
726}
diff --git a/fs/jffs2/nodelist.h b/fs/jffs2/nodelist.h
index b34c397909ef..23a67bb3052f 100644
--- a/fs/jffs2/nodelist.h
+++ b/fs/jffs2/nodelist.h
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: nodelist.h,v 1.131 2005/07/05 21:03:07 dwmw2 Exp $ 10 * $Id: nodelist.h,v 1.140 2005/09/07 08:34:54 havasi Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -20,30 +20,15 @@
20#include <linux/jffs2.h> 20#include <linux/jffs2.h>
21#include <linux/jffs2_fs_sb.h> 21#include <linux/jffs2_fs_sb.h>
22#include <linux/jffs2_fs_i.h> 22#include <linux/jffs2_fs_i.h>
23#include "summary.h"
23 24
24#ifdef __ECOS 25#ifdef __ECOS
25#include "os-ecos.h" 26#include "os-ecos.h"
26#else 27#else
27#include <linux/mtd/compatmac.h> /* For min/max in older kernels */ 28#include <linux/mtd/compatmac.h> /* For compatibility with older kernels */
28#include "os-linux.h" 29#include "os-linux.h"
29#endif 30#endif
30 31
31#ifndef CONFIG_JFFS2_FS_DEBUG
32#define CONFIG_JFFS2_FS_DEBUG 1
33#endif
34
35#if CONFIG_JFFS2_FS_DEBUG > 0
36#define D1(x) x
37#else
38#define D1(x)
39#endif
40
41#if CONFIG_JFFS2_FS_DEBUG > 1
42#define D2(x) x
43#else
44#define D2(x)
45#endif
46
47#define JFFS2_NATIVE_ENDIAN 32#define JFFS2_NATIVE_ENDIAN
48 33
49/* Note we handle mode bits conversion from JFFS2 (i.e. Linux) to/from 34/* Note we handle mode bits conversion from JFFS2 (i.e. Linux) to/from
@@ -73,14 +58,17 @@
73#define je16_to_cpu(x) (le16_to_cpu(x.v16)) 58#define je16_to_cpu(x) (le16_to_cpu(x.v16))
74#define je32_to_cpu(x) (le32_to_cpu(x.v32)) 59#define je32_to_cpu(x) (le32_to_cpu(x.v32))
75#define jemode_to_cpu(x) (le32_to_cpu(jffs2_to_os_mode((x).m))) 60#define jemode_to_cpu(x) (le32_to_cpu(jffs2_to_os_mode((x).m)))
76#else 61#else
77#error wibble 62#error wibble
78#endif 63#endif
79 64
65/* The minimal node header size */
66#define JFFS2_MIN_NODE_HEADER sizeof(struct jffs2_raw_dirent)
67
80/* 68/*
81 This is all we need to keep in-core for each raw node during normal 69 This is all we need to keep in-core for each raw node during normal
82 operation. As and when we do read_inode on a particular inode, we can 70 operation. As and when we do read_inode on a particular inode, we can
83 scan the nodes which are listed for it and build up a proper map of 71 scan the nodes which are listed for it and build up a proper map of
84 which nodes are currently valid. JFFSv1 always used to keep that whole 72 which nodes are currently valid. JFFSv1 always used to keep that whole
85 map in core for each inode. 73 map in core for each inode.
86*/ 74*/
@@ -97,7 +85,7 @@ struct jffs2_raw_node_ref
97 85
98 /* flash_offset & 3 always has to be zero, because nodes are 86 /* flash_offset & 3 always has to be zero, because nodes are
99 always aligned at 4 bytes. So we have a couple of extra bits 87 always aligned at 4 bytes. So we have a couple of extra bits
100 to play with, which indicate the node's status; see below: */ 88 to play with, which indicate the node's status; see below: */
101#define REF_UNCHECKED 0 /* We haven't yet checked the CRC or built its inode */ 89#define REF_UNCHECKED 0 /* We haven't yet checked the CRC or built its inode */
102#define REF_OBSOLETE 1 /* Obsolete, can be completely ignored */ 90#define REF_OBSOLETE 1 /* Obsolete, can be completely ignored */
103#define REF_PRISTINE 2 /* Completely clean. GC without looking */ 91#define REF_PRISTINE 2 /* Completely clean. GC without looking */
@@ -110,7 +98,7 @@ struct jffs2_raw_node_ref
110/* For each inode in the filesystem, we need to keep a record of 98/* For each inode in the filesystem, we need to keep a record of
111 nlink, because it would be a PITA to scan the whole directory tree 99 nlink, because it would be a PITA to scan the whole directory tree
112 at read_inode() time to calculate it, and to keep sufficient information 100 at read_inode() time to calculate it, and to keep sufficient information
113 in the raw_node_ref (basically both parent and child inode number for 101 in the raw_node_ref (basically both parent and child inode number for
114 dirent nodes) would take more space than this does. We also keep 102 dirent nodes) would take more space than this does. We also keep
115 a pointer to the first physical node which is part of this inode, too. 103 a pointer to the first physical node which is part of this inode, too.
116*/ 104*/
@@ -140,7 +128,7 @@ struct jffs2_inode_cache {
140#define INOCACHE_HASHSIZE 128 128#define INOCACHE_HASHSIZE 128
141 129
142/* 130/*
143 Larger representation of a raw node, kept in-core only when the 131 Larger representation of a raw node, kept in-core only when the
144 struct inode for this particular ino is instantiated. 132 struct inode for this particular ino is instantiated.
145*/ 133*/
146 134
@@ -150,11 +138,11 @@ struct jffs2_full_dnode
150 uint32_t ofs; /* The offset to which the data of this node belongs */ 138 uint32_t ofs; /* The offset to which the data of this node belongs */
151 uint32_t size; 139 uint32_t size;
152 uint32_t frags; /* Number of fragments which currently refer 140 uint32_t frags; /* Number of fragments which currently refer
153 to this node. When this reaches zero, 141 to this node. When this reaches zero,
154 the node is obsolete. */ 142 the node is obsolete. */
155}; 143};
156 144
157/* 145/*
158 Even larger representation of a raw node, kept in-core only while 146 Even larger representation of a raw node, kept in-core only while
159 we're actually building up the original map of which nodes go where, 147 we're actually building up the original map of which nodes go where,
160 in read_inode() 148 in read_inode()
@@ -164,7 +152,10 @@ struct jffs2_tmp_dnode_info
164 struct rb_node rb; 152 struct rb_node rb;
165 struct jffs2_full_dnode *fn; 153 struct jffs2_full_dnode *fn;
166 uint32_t version; 154 uint32_t version;
167}; 155 uint32_t data_crc;
156 uint32_t partial_crc;
157 uint32_t csize;
158};
168 159
169struct jffs2_full_dirent 160struct jffs2_full_dirent
170{ 161{
@@ -178,7 +169,7 @@ struct jffs2_full_dirent
178}; 169};
179 170
180/* 171/*
181 Fragments - used to build a map of which raw node to obtain 172 Fragments - used to build a map of which raw node to obtain
182 data from for each part of the ino 173 data from for each part of the ino
183*/ 174*/
184struct jffs2_node_frag 175struct jffs2_node_frag
@@ -207,86 +198,18 @@ struct jffs2_eraseblock
207 struct jffs2_raw_node_ref *gc_node; /* Next node to be garbage collected */ 198 struct jffs2_raw_node_ref *gc_node; /* Next node to be garbage collected */
208}; 199};
209 200
210#define ACCT_SANITY_CHECK(c, jeb) do { \ 201static inline int jffs2_blocks_use_vmalloc(struct jffs2_sb_info *c)
211 struct jffs2_eraseblock *___j = jeb; \
212 if ((___j) && ___j->used_size + ___j->dirty_size + ___j->free_size + ___j->wasted_size + ___j->unchecked_size != c->sector_size) { \
213 printk(KERN_NOTICE "Eeep. Space accounting for block at 0x%08x is screwed\n", ___j->offset); \
214 printk(KERN_NOTICE "free 0x%08x + dirty 0x%08x + used %08x + wasted %08x + unchecked %08x != total %08x\n", \
215 ___j->free_size, ___j->dirty_size, ___j->used_size, ___j->wasted_size, ___j->unchecked_size, c->sector_size); \
216 BUG(); \
217 } \
218 if (c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size + c->wasted_size + c->unchecked_size != c->flash_size) { \
219 printk(KERN_NOTICE "Eeep. Space accounting superblock info is screwed\n"); \
220 printk(KERN_NOTICE "free 0x%08x + dirty 0x%08x + used %08x + erasing %08x + bad %08x + wasted %08x + unchecked %08x != total %08x\n", \
221 c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size, c->wasted_size, c->unchecked_size, c->flash_size); \
222 BUG(); \
223 } \
224} while(0)
225
226static inline void paranoia_failed_dump(struct jffs2_eraseblock *jeb)
227{ 202{
228 struct jffs2_raw_node_ref *ref; 203 return ((c->flash_size / c->sector_size) * sizeof (struct jffs2_eraseblock)) > (128 * 1024);
229 int i=0;
230
231 printk(KERN_NOTICE);
232 for (ref = jeb->first_node; ref; ref = ref->next_phys) {
233 printk("%08x->", ref_offset(ref));
234 if (++i == 8) {
235 i = 0;
236 printk("\n" KERN_NOTICE);
237 }
238 }
239 printk("\n");
240} 204}
241 205
242
243#define ACCT_PARANOIA_CHECK(jeb) do { \
244 uint32_t my_used_size = 0; \
245 uint32_t my_unchecked_size = 0; \
246 struct jffs2_raw_node_ref *ref2 = jeb->first_node; \
247 while (ref2) { \
248 if (unlikely(ref2->flash_offset < jeb->offset || \
249 ref2->flash_offset > jeb->offset + c->sector_size)) { \
250 printk(KERN_NOTICE "Node %08x shouldn't be in block at %08x!\n", \
251 ref_offset(ref2), jeb->offset); \
252 paranoia_failed_dump(jeb); \
253 BUG(); \
254 } \
255 if (ref_flags(ref2) == REF_UNCHECKED) \
256 my_unchecked_size += ref_totlen(c, jeb, ref2); \
257 else if (!ref_obsolete(ref2)) \
258 my_used_size += ref_totlen(c, jeb, ref2); \
259 if (unlikely((!ref2->next_phys) != (ref2 == jeb->last_node))) { \
260 if (!ref2->next_phys) \
261 printk("ref for node at %p (phys %08x) has next_phys->%p (----), last_node->%p (phys %08x)\n", \
262 ref2, ref_offset(ref2), ref2->next_phys, \
263 jeb->last_node, ref_offset(jeb->last_node)); \
264 else \
265 printk("ref for node at %p (phys %08x) has next_phys->%p (%08x), last_node->%p (phys %08x)\n", \
266 ref2, ref_offset(ref2), ref2->next_phys, ref_offset(ref2->next_phys), \
267 jeb->last_node, ref_offset(jeb->last_node)); \
268 paranoia_failed_dump(jeb); \
269 BUG(); \
270 } \
271 ref2 = ref2->next_phys; \
272 } \
273 if (my_used_size != jeb->used_size) { \
274 printk(KERN_NOTICE "Calculated used size %08x != stored used size %08x\n", my_used_size, jeb->used_size); \
275 BUG(); \
276 } \
277 if (my_unchecked_size != jeb->unchecked_size) { \
278 printk(KERN_NOTICE "Calculated unchecked size %08x != stored unchecked size %08x\n", my_unchecked_size, jeb->unchecked_size); \
279 BUG(); \
280 } \
281 } while(0)
282
283/* Calculate totlen from surrounding nodes or eraseblock */ 206/* Calculate totlen from surrounding nodes or eraseblock */
284static inline uint32_t __ref_totlen(struct jffs2_sb_info *c, 207static inline uint32_t __ref_totlen(struct jffs2_sb_info *c,
285 struct jffs2_eraseblock *jeb, 208 struct jffs2_eraseblock *jeb,
286 struct jffs2_raw_node_ref *ref) 209 struct jffs2_raw_node_ref *ref)
287{ 210{
288 uint32_t ref_end; 211 uint32_t ref_end;
289 212
290 if (ref->next_phys) 213 if (ref->next_phys)
291 ref_end = ref_offset(ref->next_phys); 214 ref_end = ref_offset(ref->next_phys);
292 else { 215 else {
@@ -306,11 +229,13 @@ static inline uint32_t ref_totlen(struct jffs2_sb_info *c,
306{ 229{
307 uint32_t ret; 230 uint32_t ret;
308 231
309 D1(if (jeb && jeb != &c->blocks[ref->flash_offset / c->sector_size]) { 232#if CONFIG_JFFS2_FS_DEBUG > 0
233 if (jeb && jeb != &c->blocks[ref->flash_offset / c->sector_size]) {
310 printk(KERN_CRIT "ref_totlen called with wrong block -- at 0x%08x instead of 0x%08x; ref 0x%08x\n", 234 printk(KERN_CRIT "ref_totlen called with wrong block -- at 0x%08x instead of 0x%08x; ref 0x%08x\n",
311 jeb->offset, c->blocks[ref->flash_offset / c->sector_size].offset, ref_offset(ref)); 235 jeb->offset, c->blocks[ref->flash_offset / c->sector_size].offset, ref_offset(ref));
312 BUG(); 236 BUG();
313 }) 237 }
238#endif
314 239
315#if 1 240#if 1
316 ret = ref->__totlen; 241 ret = ref->__totlen;
@@ -323,14 +248,13 @@ static inline uint32_t ref_totlen(struct jffs2_sb_info *c,
323 ret, ref->__totlen); 248 ret, ref->__totlen);
324 if (!jeb) 249 if (!jeb)
325 jeb = &c->blocks[ref->flash_offset / c->sector_size]; 250 jeb = &c->blocks[ref->flash_offset / c->sector_size];
326 paranoia_failed_dump(jeb); 251 jffs2_dbg_dump_node_refs_nolock(c, jeb);
327 BUG(); 252 BUG();
328 } 253 }
329#endif 254#endif
330 return ret; 255 return ret;
331} 256}
332 257
333
334#define ALLOC_NORMAL 0 /* Normal allocation */ 258#define ALLOC_NORMAL 0 /* Normal allocation */
335#define ALLOC_DELETION 1 /* Deletion node. Best to allow it */ 259#define ALLOC_DELETION 1 /* Deletion node. Best to allow it */
336#define ALLOC_GC 2 /* Space requested for GC. Give it or die */ 260#define ALLOC_GC 2 /* Space requested for GC. Give it or die */
@@ -340,7 +264,7 @@ static inline uint32_t ref_totlen(struct jffs2_sb_info *c,
340#define VERYDIRTY(c, size) ((size) >= ((c)->sector_size / 2)) 264#define VERYDIRTY(c, size) ((size) >= ((c)->sector_size / 2))
341 265
342/* check if dirty space is more than 255 Byte */ 266/* check if dirty space is more than 255 Byte */
343#define ISDIRTY(size) ((size) > sizeof (struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN) 267#define ISDIRTY(size) ((size) > sizeof (struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN)
344 268
345#define PAD(x) (((x)+3)&~3) 269#define PAD(x) (((x)+3)&~3)
346 270
@@ -384,12 +308,7 @@ static inline struct jffs2_node_frag *frag_last(struct rb_root *root)
384#define frag_erase(frag, list) rb_erase(&frag->rb, list); 308#define frag_erase(frag, list) rb_erase(&frag->rb, list);
385 309
386/* nodelist.c */ 310/* nodelist.c */
387D2(void jffs2_print_frag_list(struct jffs2_inode_info *f));
388void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list); 311void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list);
389int jffs2_get_inode_nodes(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
390 struct rb_root *tnp, struct jffs2_full_dirent **fdp,
391 uint32_t *highest_version, uint32_t *latest_mctime,
392 uint32_t *mctime_ver);
393void jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, int state); 312void jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, int state);
394struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t ino); 313struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t ino);
395void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new); 314void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new);
@@ -398,19 +317,23 @@ void jffs2_free_ino_caches(struct jffs2_sb_info *c);
398void jffs2_free_raw_node_refs(struct jffs2_sb_info *c); 317void jffs2_free_raw_node_refs(struct jffs2_sb_info *c);
399struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_t offset); 318struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_t offset);
400void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c_delete); 319void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c_delete);
401void jffs2_fragtree_insert(struct jffs2_node_frag *newfrag, struct jffs2_node_frag *base);
402struct rb_node *rb_next(struct rb_node *); 320struct rb_node *rb_next(struct rb_node *);
403struct rb_node *rb_prev(struct rb_node *); 321struct rb_node *rb_prev(struct rb_node *);
404void rb_replace_node(struct rb_node *victim, struct rb_node *new, struct rb_root *root); 322void rb_replace_node(struct rb_node *victim, struct rb_node *new, struct rb_root *root);
323void jffs2_obsolete_node_frag(struct jffs2_sb_info *c, struct jffs2_node_frag *this);
324int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn);
325void jffs2_truncate_fragtree (struct jffs2_sb_info *c, struct rb_root *list, uint32_t size);
326int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_tmp_dnode_info *tn);
405 327
406/* nodemgmt.c */ 328/* nodemgmt.c */
407int jffs2_thread_should_wake(struct jffs2_sb_info *c); 329int jffs2_thread_should_wake(struct jffs2_sb_info *c);
408int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len, int prio); 330int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs,
409int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len); 331 uint32_t *len, int prio, uint32_t sumsize);
332int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs,
333 uint32_t *len, uint32_t sumsize);
410int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new); 334int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new);
411void jffs2_complete_reservation(struct jffs2_sb_info *c); 335void jffs2_complete_reservation(struct jffs2_sb_info *c);
412void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *raw); 336void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *raw);
413void jffs2_dump_block_lists(struct jffs2_sb_info *c);
414 337
415/* write.c */ 338/* write.c */
416int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint32_t mode, struct jffs2_raw_inode *ri); 339int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint32_t mode, struct jffs2_raw_inode *ri);
@@ -418,17 +341,15 @@ int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint
418struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs, int alloc_mode); 341struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs, int alloc_mode);
419struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_dirent *rd, const unsigned char *name, uint32_t namelen, uint32_t flash_ofs, int alloc_mode); 342struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_dirent *rd, const unsigned char *name, uint32_t namelen, uint32_t flash_ofs, int alloc_mode);
420int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 343int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
421 struct jffs2_raw_inode *ri, unsigned char *buf, 344 struct jffs2_raw_inode *ri, unsigned char *buf,
422 uint32_t offset, uint32_t writelen, uint32_t *retlen); 345 uint32_t offset, uint32_t writelen, uint32_t *retlen);
423int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const char *name, int namelen); 346int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const char *name, int namelen);
424int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, const char *name, int namelen, struct jffs2_inode_info *dead_f); 347int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, const char *name, int namelen, struct jffs2_inode_info *dead_f, uint32_t time);
425int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, uint8_t type, const char *name, int namelen); 348int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, uint8_t type, const char *name, int namelen, uint32_t time);
426 349
427 350
428/* readinode.c */ 351/* readinode.c */
429void jffs2_truncate_fraglist (struct jffs2_sb_info *c, struct rb_root *list, uint32_t size); 352int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
430int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn);
431int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
432 uint32_t ino, struct jffs2_raw_inode *latest_node); 353 uint32_t ino, struct jffs2_raw_inode *latest_node);
433int jffs2_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic); 354int jffs2_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic);
434void jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f); 355void jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f);
@@ -468,6 +389,10 @@ char *jffs2_getlink(struct jffs2_sb_info *c, struct jffs2_inode_info *f);
468/* scan.c */ 389/* scan.c */
469int jffs2_scan_medium(struct jffs2_sb_info *c); 390int jffs2_scan_medium(struct jffs2_sb_info *c);
470void jffs2_rotate_lists(struct jffs2_sb_info *c); 391void jffs2_rotate_lists(struct jffs2_sb_info *c);
392int jffs2_fill_scan_buf(struct jffs2_sb_info *c, void *buf,
393 uint32_t ofs, uint32_t len);
394struct jffs2_inode_cache *jffs2_scan_make_ino_cache(struct jffs2_sb_info *c, uint32_t ino);
395int jffs2_scan_classify_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
471 396
472/* build.c */ 397/* build.c */
473int jffs2_do_mount_fs(struct jffs2_sb_info *c); 398int jffs2_do_mount_fs(struct jffs2_sb_info *c);
@@ -483,4 +408,6 @@ int jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_erasebloc
483int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); 408int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
484#endif 409#endif
485 410
411#include "debug.h"
412
486#endif /* __JFFS2_NODELIST_H__ */ 413#endif /* __JFFS2_NODELIST_H__ */
diff --git a/fs/jffs2/nodemgmt.c b/fs/jffs2/nodemgmt.c
index c1d8b5ed9ab9..49127a1f0458 100644
--- a/fs/jffs2/nodemgmt.c
+++ b/fs/jffs2/nodemgmt.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: nodemgmt.c,v 1.122 2005/05/06 09:30:27 dedekind Exp $ 10 * $Id: nodemgmt.c,v 1.127 2005/09/20 15:49:12 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -17,6 +17,7 @@
17#include <linux/compiler.h> 17#include <linux/compiler.h>
18#include <linux/sched.h> /* For cond_resched() */ 18#include <linux/sched.h> /* For cond_resched() */
19#include "nodelist.h" 19#include "nodelist.h"
20#include "debug.h"
20 21
21/** 22/**
22 * jffs2_reserve_space - request physical space to write nodes to flash 23 * jffs2_reserve_space - request physical space to write nodes to flash
@@ -38,9 +39,11 @@
38 * for the requested allocation. 39 * for the requested allocation.
39 */ 40 */
40 41
41static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len); 42static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
43 uint32_t *ofs, uint32_t *len, uint32_t sumsize);
42 44
43int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len, int prio) 45int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs,
46 uint32_t *len, int prio, uint32_t sumsize)
44{ 47{
45 int ret = -EAGAIN; 48 int ret = -EAGAIN;
46 int blocksneeded = c->resv_blocks_write; 49 int blocksneeded = c->resv_blocks_write;
@@ -85,12 +88,12 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs
85 up(&c->alloc_sem); 88 up(&c->alloc_sem);
86 return -ENOSPC; 89 return -ENOSPC;
87 } 90 }
88 91
89 /* Calc possibly available space. Possibly available means that we 92 /* Calc possibly available space. Possibly available means that we
90 * don't know, if unchecked size contains obsoleted nodes, which could give us some 93 * don't know, if unchecked size contains obsoleted nodes, which could give us some
91 * more usable space. This will affect the sum only once, as gc first finishes checking 94 * more usable space. This will affect the sum only once, as gc first finishes checking
92 * of nodes. 95 * of nodes.
93 + Return -ENOSPC, if the maximum possibly available space is less or equal than 96 + Return -ENOSPC, if the maximum possibly available space is less or equal than
94 * blocksneeded * sector_size. 97 * blocksneeded * sector_size.
95 * This blocks endless gc looping on a filesystem, which is nearly full, even if 98 * This blocks endless gc looping on a filesystem, which is nearly full, even if
96 * the check above passes. 99 * the check above passes.
@@ -115,7 +118,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs
115 c->nr_free_blocks, c->nr_erasing_blocks, c->free_size, c->dirty_size, c->wasted_size, c->used_size, c->erasing_size, c->bad_size, 118 c->nr_free_blocks, c->nr_erasing_blocks, c->free_size, c->dirty_size, c->wasted_size, c->used_size, c->erasing_size, c->bad_size,
116 c->free_size + c->dirty_size + c->wasted_size + c->used_size + c->erasing_size + c->bad_size, c->flash_size)); 119 c->free_size + c->dirty_size + c->wasted_size + c->used_size + c->erasing_size + c->bad_size, c->flash_size));
117 spin_unlock(&c->erase_completion_lock); 120 spin_unlock(&c->erase_completion_lock);
118 121
119 ret = jffs2_garbage_collect_pass(c); 122 ret = jffs2_garbage_collect_pass(c);
120 if (ret) 123 if (ret)
121 return ret; 124 return ret;
@@ -129,7 +132,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs
129 spin_lock(&c->erase_completion_lock); 132 spin_lock(&c->erase_completion_lock);
130 } 133 }
131 134
132 ret = jffs2_do_reserve_space(c, minsize, ofs, len); 135 ret = jffs2_do_reserve_space(c, minsize, ofs, len, sumsize);
133 if (ret) { 136 if (ret) {
134 D1(printk(KERN_DEBUG "jffs2_reserve_space: ret is %d\n", ret)); 137 D1(printk(KERN_DEBUG "jffs2_reserve_space: ret is %d\n", ret));
135 } 138 }
@@ -140,7 +143,8 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs
140 return ret; 143 return ret;
141} 144}
142 145
143int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len) 146int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs,
147 uint32_t *len, uint32_t sumsize)
144{ 148{
145 int ret = -EAGAIN; 149 int ret = -EAGAIN;
146 minsize = PAD(minsize); 150 minsize = PAD(minsize);
@@ -149,7 +153,7 @@ int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *
149 153
150 spin_lock(&c->erase_completion_lock); 154 spin_lock(&c->erase_completion_lock);
151 while(ret == -EAGAIN) { 155 while(ret == -EAGAIN) {
152 ret = jffs2_do_reserve_space(c, minsize, ofs, len); 156 ret = jffs2_do_reserve_space(c, minsize, ofs, len, sumsize);
153 if (ret) { 157 if (ret) {
154 D1(printk(KERN_DEBUG "jffs2_reserve_space_gc: looping, ret is %d\n", ret)); 158 D1(printk(KERN_DEBUG "jffs2_reserve_space_gc: looping, ret is %d\n", ret));
155 } 159 }
@@ -158,105 +162,185 @@ int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *
158 return ret; 162 return ret;
159} 163}
160 164
161/* Called with alloc sem _and_ erase_completion_lock */ 165
162static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len) 166/* Classify nextblock (clean, dirty of verydirty) and force to select an other one */
167
168static void jffs2_close_nextblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
163{ 169{
164 struct jffs2_eraseblock *jeb = c->nextblock; 170
165 171 /* Check, if we have a dirty block now, or if it was dirty already */
166 restart: 172 if (ISDIRTY (jeb->wasted_size + jeb->dirty_size)) {
167 if (jeb && minsize > jeb->free_size) { 173 c->dirty_size += jeb->wasted_size;
168 /* Skip the end of this block and file it as having some dirty space */ 174 c->wasted_size -= jeb->wasted_size;
169 /* If there's a pending write to it, flush now */ 175 jeb->dirty_size += jeb->wasted_size;
170 if (jffs2_wbuf_dirty(c)) { 176 jeb->wasted_size = 0;
177 if (VERYDIRTY(c, jeb->dirty_size)) {
178 D1(printk(KERN_DEBUG "Adding full erase block at 0x%08x to very_dirty_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n",
179 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size));
180 list_add_tail(&jeb->list, &c->very_dirty_list);
181 } else {
182 D1(printk(KERN_DEBUG "Adding full erase block at 0x%08x to dirty_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n",
183 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size));
184 list_add_tail(&jeb->list, &c->dirty_list);
185 }
186 } else {
187 D1(printk(KERN_DEBUG "Adding full erase block at 0x%08x to clean_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n",
188 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size));
189 list_add_tail(&jeb->list, &c->clean_list);
190 }
191 c->nextblock = NULL;
192
193}
194
195/* Select a new jeb for nextblock */
196
197static int jffs2_find_nextblock(struct jffs2_sb_info *c)
198{
199 struct list_head *next;
200
201 /* Take the next block off the 'free' list */
202
203 if (list_empty(&c->free_list)) {
204
205 if (!c->nr_erasing_blocks &&
206 !list_empty(&c->erasable_list)) {
207 struct jffs2_eraseblock *ejeb;
208
209 ejeb = list_entry(c->erasable_list.next, struct jffs2_eraseblock, list);
210 list_del(&ejeb->list);
211 list_add_tail(&ejeb->list, &c->erase_pending_list);
212 c->nr_erasing_blocks++;
213 jffs2_erase_pending_trigger(c);
214 D1(printk(KERN_DEBUG "jffs2_find_nextblock: Triggering erase of erasable block at 0x%08x\n",
215 ejeb->offset));
216 }
217
218 if (!c->nr_erasing_blocks &&
219 !list_empty(&c->erasable_pending_wbuf_list)) {
220 D1(printk(KERN_DEBUG "jffs2_find_nextblock: Flushing write buffer\n"));
221 /* c->nextblock is NULL, no update to c->nextblock allowed */
171 spin_unlock(&c->erase_completion_lock); 222 spin_unlock(&c->erase_completion_lock);
172 D1(printk(KERN_DEBUG "jffs2_do_reserve_space: Flushing write buffer\n"));
173 jffs2_flush_wbuf_pad(c); 223 jffs2_flush_wbuf_pad(c);
174 spin_lock(&c->erase_completion_lock); 224 spin_lock(&c->erase_completion_lock);
175 jeb = c->nextblock; 225 /* Have another go. It'll be on the erasable_list now */
176 goto restart; 226 return -EAGAIN;
177 } 227 }
178 c->wasted_size += jeb->free_size; 228
179 c->free_size -= jeb->free_size; 229 if (!c->nr_erasing_blocks) {
180 jeb->wasted_size += jeb->free_size; 230 /* Ouch. We're in GC, or we wouldn't have got here.
181 jeb->free_size = 0; 231 And there's no space left. At all. */
182 232 printk(KERN_CRIT "Argh. No free space left for GC. nr_erasing_blocks is %d. nr_free_blocks is %d. (erasableempty: %s, erasingempty: %s, erasependingempty: %s)\n",
183 /* Check, if we have a dirty block now, or if it was dirty already */ 233 c->nr_erasing_blocks, c->nr_free_blocks, list_empty(&c->erasable_list)?"yes":"no",
184 if (ISDIRTY (jeb->wasted_size + jeb->dirty_size)) { 234 list_empty(&c->erasing_list)?"yes":"no", list_empty(&c->erase_pending_list)?"yes":"no");
185 c->dirty_size += jeb->wasted_size; 235 return -ENOSPC;
186 c->wasted_size -= jeb->wasted_size;
187 jeb->dirty_size += jeb->wasted_size;
188 jeb->wasted_size = 0;
189 if (VERYDIRTY(c, jeb->dirty_size)) {
190 D1(printk(KERN_DEBUG "Adding full erase block at 0x%08x to very_dirty_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n",
191 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size));
192 list_add_tail(&jeb->list, &c->very_dirty_list);
193 } else {
194 D1(printk(KERN_DEBUG "Adding full erase block at 0x%08x to dirty_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n",
195 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size));
196 list_add_tail(&jeb->list, &c->dirty_list);
197 }
198 } else {
199 D1(printk(KERN_DEBUG "Adding full erase block at 0x%08x to clean_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n",
200 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size));
201 list_add_tail(&jeb->list, &c->clean_list);
202 } 236 }
203 c->nextblock = jeb = NULL; 237
238 spin_unlock(&c->erase_completion_lock);
239 /* Don't wait for it; just erase one right now */
240 jffs2_erase_pending_blocks(c, 1);
241 spin_lock(&c->erase_completion_lock);
242
243 /* An erase may have failed, decreasing the
244 amount of free space available. So we must
245 restart from the beginning */
246 return -EAGAIN;
204 } 247 }
205
206 if (!jeb) {
207 struct list_head *next;
208 /* Take the next block off the 'free' list */
209 248
210 if (list_empty(&c->free_list)) { 249 next = c->free_list.next;
250 list_del(next);
251 c->nextblock = list_entry(next, struct jffs2_eraseblock, list);
252 c->nr_free_blocks--;
211 253
212 if (!c->nr_erasing_blocks && 254 jffs2_sum_reset_collected(c->summary); /* reset collected summary */
213 !list_empty(&c->erasable_list)) {
214 struct jffs2_eraseblock *ejeb;
215 255
216 ejeb = list_entry(c->erasable_list.next, struct jffs2_eraseblock, list); 256 D1(printk(KERN_DEBUG "jffs2_find_nextblock(): new nextblock = 0x%08x\n", c->nextblock->offset));
217 list_del(&ejeb->list); 257
218 list_add_tail(&ejeb->list, &c->erase_pending_list); 258 return 0;
219 c->nr_erasing_blocks++; 259}
220 jffs2_erase_pending_trigger(c); 260
221 D1(printk(KERN_DEBUG "jffs2_do_reserve_space: Triggering erase of erasable block at 0x%08x\n", 261/* Called with alloc sem _and_ erase_completion_lock */
222 ejeb->offset)); 262static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len, uint32_t sumsize)
263{
264 struct jffs2_eraseblock *jeb = c->nextblock;
265 uint32_t reserved_size; /* for summary information at the end of the jeb */
266 int ret;
267
268 restart:
269 reserved_size = 0;
270
271 if (jffs2_sum_active() && (sumsize != JFFS2_SUMMARY_NOSUM_SIZE)) {
272 /* NOSUM_SIZE means not to generate summary */
273
274 if (jeb) {
275 reserved_size = PAD(sumsize + c->summary->sum_size + JFFS2_SUMMARY_FRAME_SIZE);
276 dbg_summary("minsize=%d , jeb->free=%d ,"
277 "summary->size=%d , sumsize=%d\n",
278 minsize, jeb->free_size,
279 c->summary->sum_size, sumsize);
280 }
281
282 /* Is there enough space for writing out the current node, or we have to
283 write out summary information now, close this jeb and select new nextblock? */
284 if (jeb && (PAD(minsize) + PAD(c->summary->sum_size + sumsize +
285 JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size)) {
286
287 /* Has summary been disabled for this jeb? */
288 if (jffs2_sum_is_disabled(c->summary)) {
289 sumsize = JFFS2_SUMMARY_NOSUM_SIZE;
290 goto restart;
223 } 291 }
224 292
225 if (!c->nr_erasing_blocks && 293 /* Writing out the collected summary information */
226 !list_empty(&c->erasable_pending_wbuf_list)) { 294 dbg_summary("generating summary for 0x%08x.\n", jeb->offset);
227 D1(printk(KERN_DEBUG "jffs2_do_reserve_space: Flushing write buffer\n")); 295 ret = jffs2_sum_write_sumnode(c);
228 /* c->nextblock is NULL, no update to c->nextblock allowed */ 296
297 if (ret)
298 return ret;
299
300 if (jffs2_sum_is_disabled(c->summary)) {
301 /* jffs2_write_sumnode() couldn't write out the summary information
302 diabling summary for this jeb and free the collected information
303 */
304 sumsize = JFFS2_SUMMARY_NOSUM_SIZE;
305 goto restart;
306 }
307
308 jffs2_close_nextblock(c, jeb);
309 jeb = NULL;
310 /* keep always valid value in reserved_size */
311 reserved_size = PAD(sumsize + c->summary->sum_size + JFFS2_SUMMARY_FRAME_SIZE);
312 }
313 } else {
314 if (jeb && minsize > jeb->free_size) {
315 /* Skip the end of this block and file it as having some dirty space */
316 /* If there's a pending write to it, flush now */
317
318 if (jffs2_wbuf_dirty(c)) {
229 spin_unlock(&c->erase_completion_lock); 319 spin_unlock(&c->erase_completion_lock);
320 D1(printk(KERN_DEBUG "jffs2_do_reserve_space: Flushing write buffer\n"));
230 jffs2_flush_wbuf_pad(c); 321 jffs2_flush_wbuf_pad(c);
231 spin_lock(&c->erase_completion_lock); 322 spin_lock(&c->erase_completion_lock);
232 /* Have another go. It'll be on the erasable_list now */ 323 jeb = c->nextblock;
233 return -EAGAIN; 324 goto restart;
234 } 325 }
235 326
236 if (!c->nr_erasing_blocks) { 327 c->wasted_size += jeb->free_size;
237 /* Ouch. We're in GC, or we wouldn't have got here. 328 c->free_size -= jeb->free_size;
238 And there's no space left. At all. */ 329 jeb->wasted_size += jeb->free_size;
239 printk(KERN_CRIT "Argh. No free space left for GC. nr_erasing_blocks is %d. nr_free_blocks is %d. (erasableempty: %s, erasingempty: %s, erasependingempty: %s)\n", 330 jeb->free_size = 0;
240 c->nr_erasing_blocks, c->nr_free_blocks, list_empty(&c->erasable_list)?"yes":"no",
241 list_empty(&c->erasing_list)?"yes":"no", list_empty(&c->erase_pending_list)?"yes":"no");
242 return -ENOSPC;
243 }
244
245 spin_unlock(&c->erase_completion_lock);
246 /* Don't wait for it; just erase one right now */
247 jffs2_erase_pending_blocks(c, 1);
248 spin_lock(&c->erase_completion_lock);
249 331
250 /* An erase may have failed, decreasing the 332 jffs2_close_nextblock(c, jeb);
251 amount of free space available. So we must 333 jeb = NULL;
252 restart from the beginning */
253 return -EAGAIN;
254 } 334 }
335 }
336
337 if (!jeb) {
255 338
256 next = c->free_list.next; 339 ret = jffs2_find_nextblock(c);
257 list_del(next); 340 if (ret)
258 c->nextblock = jeb = list_entry(next, struct jffs2_eraseblock, list); 341 return ret;
259 c->nr_free_blocks--; 342
343 jeb = c->nextblock;
260 344
261 if (jeb->free_size != c->sector_size - c->cleanmarker_size) { 345 if (jeb->free_size != c->sector_size - c->cleanmarker_size) {
262 printk(KERN_WARNING "Eep. Block 0x%08x taken from free_list had free_size of 0x%08x!!\n", jeb->offset, jeb->free_size); 346 printk(KERN_WARNING "Eep. Block 0x%08x taken from free_list had free_size of 0x%08x!!\n", jeb->offset, jeb->free_size);
@@ -266,13 +350,13 @@ static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, ui
266 /* OK, jeb (==c->nextblock) is now pointing at a block which definitely has 350 /* OK, jeb (==c->nextblock) is now pointing at a block which definitely has
267 enough space */ 351 enough space */
268 *ofs = jeb->offset + (c->sector_size - jeb->free_size); 352 *ofs = jeb->offset + (c->sector_size - jeb->free_size);
269 *len = jeb->free_size; 353 *len = jeb->free_size - reserved_size;
270 354
271 if (c->cleanmarker_size && jeb->used_size == c->cleanmarker_size && 355 if (c->cleanmarker_size && jeb->used_size == c->cleanmarker_size &&
272 !jeb->first_node->next_in_ino) { 356 !jeb->first_node->next_in_ino) {
273 /* Only node in it beforehand was a CLEANMARKER node (we think). 357 /* Only node in it beforehand was a CLEANMARKER node (we think).
274 So mark it obsolete now that there's going to be another node 358 So mark it obsolete now that there's going to be another node
275 in the block. This will reduce used_size to zero but We've 359 in the block. This will reduce used_size to zero but We've
276 already set c->nextblock so that jffs2_mark_node_obsolete() 360 already set c->nextblock so that jffs2_mark_node_obsolete()
277 won't try to refile it to the dirty_list. 361 won't try to refile it to the dirty_list.
278 */ 362 */
@@ -292,12 +376,12 @@ static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, ui
292 * @len: length of this physical node 376 * @len: length of this physical node
293 * @dirty: dirty flag for new node 377 * @dirty: dirty flag for new node
294 * 378 *
295 * Should only be used to report nodes for which space has been allocated 379 * Should only be used to report nodes for which space has been allocated
296 * by jffs2_reserve_space. 380 * by jffs2_reserve_space.
297 * 381 *
298 * Must be called with the alloc_sem held. 382 * Must be called with the alloc_sem held.
299 */ 383 */
300 384
301int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new) 385int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new)
302{ 386{
303 struct jffs2_eraseblock *jeb; 387 struct jffs2_eraseblock *jeb;
@@ -349,8 +433,8 @@ int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_r
349 list_add_tail(&jeb->list, &c->clean_list); 433 list_add_tail(&jeb->list, &c->clean_list);
350 c->nextblock = NULL; 434 c->nextblock = NULL;
351 } 435 }
352 ACCT_SANITY_CHECK(c,jeb); 436 jffs2_dbg_acct_sanity_check_nolock(c,jeb);
353 D1(ACCT_PARANOIA_CHECK(jeb)); 437 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
354 438
355 spin_unlock(&c->erase_completion_lock); 439 spin_unlock(&c->erase_completion_lock);
356 440
@@ -404,8 +488,8 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
404 488
405 if (jffs2_can_mark_obsolete(c) && !jffs2_is_readonly(c) && 489 if (jffs2_can_mark_obsolete(c) && !jffs2_is_readonly(c) &&
406 !(c->flags & (JFFS2_SB_FLAG_SCANNING | JFFS2_SB_FLAG_BUILDING))) { 490 !(c->flags & (JFFS2_SB_FLAG_SCANNING | JFFS2_SB_FLAG_BUILDING))) {
407 /* Hm. This may confuse static lock analysis. If any of the above 491 /* Hm. This may confuse static lock analysis. If any of the above
408 three conditions is false, we're going to return from this 492 three conditions is false, we're going to return from this
409 function without actually obliterating any nodes or freeing 493 function without actually obliterating any nodes or freeing
410 any jffs2_raw_node_refs. So we don't need to stop erases from 494 any jffs2_raw_node_refs. So we don't need to stop erases from
411 happening, or protect against people holding an obsolete 495 happening, or protect against people holding an obsolete
@@ -430,7 +514,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
430 ref_totlen(c, jeb, ref), blocknr, ref->flash_offset, jeb->used_size); 514 ref_totlen(c, jeb, ref), blocknr, ref->flash_offset, jeb->used_size);
431 BUG(); 515 BUG();
432 }) 516 })
433 D1(printk(KERN_DEBUG "Obsoleting node at 0x%08x of len %x: ", ref_offset(ref), ref_totlen(c, jeb, ref))); 517 D1(printk(KERN_DEBUG "Obsoleting node at 0x%08x of len %#x: ", ref_offset(ref), ref_totlen(c, jeb, ref)));
434 jeb->used_size -= ref_totlen(c, jeb, ref); 518 jeb->used_size -= ref_totlen(c, jeb, ref);
435 c->used_size -= ref_totlen(c, jeb, ref); 519 c->used_size -= ref_totlen(c, jeb, ref);
436 } 520 }
@@ -462,18 +546,17 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
462 D1(printk(KERN_DEBUG "Wasting\n")); 546 D1(printk(KERN_DEBUG "Wasting\n"));
463 addedsize = 0; 547 addedsize = 0;
464 jeb->wasted_size += ref_totlen(c, jeb, ref); 548 jeb->wasted_size += ref_totlen(c, jeb, ref);
465 c->wasted_size += ref_totlen(c, jeb, ref); 549 c->wasted_size += ref_totlen(c, jeb, ref);
466 } 550 }
467 ref->flash_offset = ref_offset(ref) | REF_OBSOLETE; 551 ref->flash_offset = ref_offset(ref) | REF_OBSOLETE;
468
469 ACCT_SANITY_CHECK(c, jeb);
470 552
471 D1(ACCT_PARANOIA_CHECK(jeb)); 553 jffs2_dbg_acct_sanity_check_nolock(c, jeb);
554 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
472 555
473 if (c->flags & JFFS2_SB_FLAG_SCANNING) { 556 if (c->flags & JFFS2_SB_FLAG_SCANNING) {
474 /* Flash scanning is in progress. Don't muck about with the block 557 /* Flash scanning is in progress. Don't muck about with the block
475 lists because they're not ready yet, and don't actually 558 lists because they're not ready yet, and don't actually
476 obliterate nodes that look obsolete. If they weren't 559 obliterate nodes that look obsolete. If they weren't
477 marked obsolete on the flash at the time they _became_ 560 marked obsolete on the flash at the time they _became_
478 obsolete, there was probably a reason for that. */ 561 obsolete, there was probably a reason for that. */
479 spin_unlock(&c->erase_completion_lock); 562 spin_unlock(&c->erase_completion_lock);
@@ -507,7 +590,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
507 immediately reused, and we spread the load a bit. */ 590 immediately reused, and we spread the load a bit. */
508 D1(printk(KERN_DEBUG "...and adding to erasable_list\n")); 591 D1(printk(KERN_DEBUG "...and adding to erasable_list\n"));
509 list_add_tail(&jeb->list, &c->erasable_list); 592 list_add_tail(&jeb->list, &c->erasable_list);
510 } 593 }
511 } 594 }
512 D1(printk(KERN_DEBUG "Done OK\n")); 595 D1(printk(KERN_DEBUG "Done OK\n"));
513 } else if (jeb == c->gcblock) { 596 } else if (jeb == c->gcblock) {
@@ -525,8 +608,8 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
525 list_add_tail(&jeb->list, &c->very_dirty_list); 608 list_add_tail(&jeb->list, &c->very_dirty_list);
526 } else { 609 } else {
527 D1(printk(KERN_DEBUG "Eraseblock at 0x%08x not moved anywhere. (free 0x%08x, dirty 0x%08x, used 0x%08x)\n", 610 D1(printk(KERN_DEBUG "Eraseblock at 0x%08x not moved anywhere. (free 0x%08x, dirty 0x%08x, used 0x%08x)\n",
528 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size)); 611 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size));
529 } 612 }
530 613
531 spin_unlock(&c->erase_completion_lock); 614 spin_unlock(&c->erase_completion_lock);
532 615
@@ -573,11 +656,11 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
573 656
574 /* Nodes which have been marked obsolete no longer need to be 657 /* Nodes which have been marked obsolete no longer need to be
575 associated with any inode. Remove them from the per-inode list. 658 associated with any inode. Remove them from the per-inode list.
576 659
577 Note we can't do this for NAND at the moment because we need 660 Note we can't do this for NAND at the moment because we need
578 obsolete dirent nodes to stay on the lists, because of the 661 obsolete dirent nodes to stay on the lists, because of the
579 horridness in jffs2_garbage_collect_deletion_dirent(). Also 662 horridness in jffs2_garbage_collect_deletion_dirent(). Also
580 because we delete the inocache, and on NAND we need that to 663 because we delete the inocache, and on NAND we need that to
581 stay around until all the nodes are actually erased, in order 664 stay around until all the nodes are actually erased, in order
582 to stop us from giving the same inode number to another newly 665 to stop us from giving the same inode number to another newly
583 created inode. */ 666 created inode. */
@@ -606,7 +689,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
606 if (ref->next_phys && ref_obsolete(ref->next_phys) && 689 if (ref->next_phys && ref_obsolete(ref->next_phys) &&
607 !ref->next_phys->next_in_ino) { 690 !ref->next_phys->next_in_ino) {
608 struct jffs2_raw_node_ref *n = ref->next_phys; 691 struct jffs2_raw_node_ref *n = ref->next_phys;
609 692
610 spin_lock(&c->erase_completion_lock); 693 spin_lock(&c->erase_completion_lock);
611 694
612 ref->__totlen += n->__totlen; 695 ref->__totlen += n->__totlen;
@@ -620,7 +703,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
620 703
621 jffs2_free_raw_node_ref(n); 704 jffs2_free_raw_node_ref(n);
622 } 705 }
623 706
624 /* Also merge with the previous node in the list, if there is one 707 /* Also merge with the previous node in the list, if there is one
625 and that one is obsolete */ 708 and that one is obsolete */
626 if (ref != jeb->first_node ) { 709 if (ref != jeb->first_node ) {
@@ -630,7 +713,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
630 713
631 while (p->next_phys != ref) 714 while (p->next_phys != ref)
632 p = p->next_phys; 715 p = p->next_phys;
633 716
634 if (ref_obsolete(p) && !ref->next_in_ino) { 717 if (ref_obsolete(p) && !ref->next_in_ino) {
635 p->__totlen += ref->__totlen; 718 p->__totlen += ref->__totlen;
636 if (jeb->last_node == ref) { 719 if (jeb->last_node == ref) {
@@ -649,164 +732,6 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
649 up(&c->erase_free_sem); 732 up(&c->erase_free_sem);
650} 733}
651 734
652#if CONFIG_JFFS2_FS_DEBUG >= 2
653void jffs2_dump_block_lists(struct jffs2_sb_info *c)
654{
655
656
657 printk(KERN_DEBUG "jffs2_dump_block_lists:\n");
658 printk(KERN_DEBUG "flash_size: %08x\n", c->flash_size);
659 printk(KERN_DEBUG "used_size: %08x\n", c->used_size);
660 printk(KERN_DEBUG "dirty_size: %08x\n", c->dirty_size);
661 printk(KERN_DEBUG "wasted_size: %08x\n", c->wasted_size);
662 printk(KERN_DEBUG "unchecked_size: %08x\n", c->unchecked_size);
663 printk(KERN_DEBUG "free_size: %08x\n", c->free_size);
664 printk(KERN_DEBUG "erasing_size: %08x\n", c->erasing_size);
665 printk(KERN_DEBUG "bad_size: %08x\n", c->bad_size);
666 printk(KERN_DEBUG "sector_size: %08x\n", c->sector_size);
667 printk(KERN_DEBUG "jffs2_reserved_blocks size: %08x\n",c->sector_size * c->resv_blocks_write);
668
669 if (c->nextblock) {
670 printk(KERN_DEBUG "nextblock: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
671 c->nextblock->offset, c->nextblock->used_size, c->nextblock->dirty_size, c->nextblock->wasted_size, c->nextblock->unchecked_size, c->nextblock->free_size);
672 } else {
673 printk(KERN_DEBUG "nextblock: NULL\n");
674 }
675 if (c->gcblock) {
676 printk(KERN_DEBUG "gcblock: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
677 c->gcblock->offset, c->gcblock->used_size, c->gcblock->dirty_size, c->gcblock->wasted_size, c->gcblock->unchecked_size, c->gcblock->free_size);
678 } else {
679 printk(KERN_DEBUG "gcblock: NULL\n");
680 }
681 if (list_empty(&c->clean_list)) {
682 printk(KERN_DEBUG "clean_list: empty\n");
683 } else {
684 struct list_head *this;
685 int numblocks = 0;
686 uint32_t dirty = 0;
687
688 list_for_each(this, &c->clean_list) {
689 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
690 numblocks ++;
691 dirty += jeb->wasted_size;
692 printk(KERN_DEBUG "clean_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n", jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size);
693 }
694 printk (KERN_DEBUG "Contains %d blocks with total wasted size %u, average wasted size: %u\n", numblocks, dirty, dirty / numblocks);
695 }
696 if (list_empty(&c->very_dirty_list)) {
697 printk(KERN_DEBUG "very_dirty_list: empty\n");
698 } else {
699 struct list_head *this;
700 int numblocks = 0;
701 uint32_t dirty = 0;
702
703 list_for_each(this, &c->very_dirty_list) {
704 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
705 numblocks ++;
706 dirty += jeb->dirty_size;
707 printk(KERN_DEBUG "very_dirty_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
708 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size);
709 }
710 printk (KERN_DEBUG "Contains %d blocks with total dirty size %u, average dirty size: %u\n",
711 numblocks, dirty, dirty / numblocks);
712 }
713 if (list_empty(&c->dirty_list)) {
714 printk(KERN_DEBUG "dirty_list: empty\n");
715 } else {
716 struct list_head *this;
717 int numblocks = 0;
718 uint32_t dirty = 0;
719
720 list_for_each(this, &c->dirty_list) {
721 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
722 numblocks ++;
723 dirty += jeb->dirty_size;
724 printk(KERN_DEBUG "dirty_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
725 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size);
726 }
727 printk (KERN_DEBUG "Contains %d blocks with total dirty size %u, average dirty size: %u\n",
728 numblocks, dirty, dirty / numblocks);
729 }
730 if (list_empty(&c->erasable_list)) {
731 printk(KERN_DEBUG "erasable_list: empty\n");
732 } else {
733 struct list_head *this;
734
735 list_for_each(this, &c->erasable_list) {
736 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
737 printk(KERN_DEBUG "erasable_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
738 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size);
739 }
740 }
741 if (list_empty(&c->erasing_list)) {
742 printk(KERN_DEBUG "erasing_list: empty\n");
743 } else {
744 struct list_head *this;
745
746 list_for_each(this, &c->erasing_list) {
747 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
748 printk(KERN_DEBUG "erasing_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
749 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size);
750 }
751 }
752 if (list_empty(&c->erase_pending_list)) {
753 printk(KERN_DEBUG "erase_pending_list: empty\n");
754 } else {
755 struct list_head *this;
756
757 list_for_each(this, &c->erase_pending_list) {
758 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
759 printk(KERN_DEBUG "erase_pending_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
760 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size);
761 }
762 }
763 if (list_empty(&c->erasable_pending_wbuf_list)) {
764 printk(KERN_DEBUG "erasable_pending_wbuf_list: empty\n");
765 } else {
766 struct list_head *this;
767
768 list_for_each(this, &c->erasable_pending_wbuf_list) {
769 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
770 printk(KERN_DEBUG "erasable_pending_wbuf_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
771 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size);
772 }
773 }
774 if (list_empty(&c->free_list)) {
775 printk(KERN_DEBUG "free_list: empty\n");
776 } else {
777 struct list_head *this;
778
779 list_for_each(this, &c->free_list) {
780 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
781 printk(KERN_DEBUG "free_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
782 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size);
783 }
784 }
785 if (list_empty(&c->bad_list)) {
786 printk(KERN_DEBUG "bad_list: empty\n");
787 } else {
788 struct list_head *this;
789
790 list_for_each(this, &c->bad_list) {
791 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
792 printk(KERN_DEBUG "bad_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
793 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size);
794 }
795 }
796 if (list_empty(&c->bad_used_list)) {
797 printk(KERN_DEBUG "bad_used_list: empty\n");
798 } else {
799 struct list_head *this;
800
801 list_for_each(this, &c->bad_used_list) {
802 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
803 printk(KERN_DEBUG "bad_used_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
804 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size);
805 }
806 }
807}
808#endif /* CONFIG_JFFS2_FS_DEBUG */
809
810int jffs2_thread_should_wake(struct jffs2_sb_info *c) 735int jffs2_thread_should_wake(struct jffs2_sb_info *c)
811{ 736{
812 int ret = 0; 737 int ret = 0;
@@ -828,11 +753,11 @@ int jffs2_thread_should_wake(struct jffs2_sb_info *c)
828 */ 753 */
829 dirty = c->dirty_size + c->erasing_size - c->nr_erasing_blocks * c->sector_size; 754 dirty = c->dirty_size + c->erasing_size - c->nr_erasing_blocks * c->sector_size;
830 755
831 if (c->nr_free_blocks + c->nr_erasing_blocks < c->resv_blocks_gctrigger && 756 if (c->nr_free_blocks + c->nr_erasing_blocks < c->resv_blocks_gctrigger &&
832 (dirty > c->nospc_dirty_size)) 757 (dirty > c->nospc_dirty_size))
833 ret = 1; 758 ret = 1;
834 759
835 D1(printk(KERN_DEBUG "jffs2_thread_should_wake(): nr_free_blocks %d, nr_erasing_blocks %d, dirty_size 0x%x: %s\n", 760 D1(printk(KERN_DEBUG "jffs2_thread_should_wake(): nr_free_blocks %d, nr_erasing_blocks %d, dirty_size 0x%x: %s\n",
836 c->nr_free_blocks, c->nr_erasing_blocks, c->dirty_size, ret?"yes":"no")); 761 c->nr_free_blocks, c->nr_erasing_blocks, c->dirty_size, ret?"yes":"no"));
837 762
838 return ret; 763 return ret;
diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h
index d900c8929b09..59e7a393200c 100644
--- a/fs/jffs2/os-linux.h
+++ b/fs/jffs2/os-linux.h
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: os-linux.h,v 1.58 2005/07/12 02:34:35 tpoynor Exp $ 10 * $Id: os-linux.h,v 1.64 2005/09/30 13:59:13 dedekind Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -57,6 +57,7 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
57 f->fragtree = RB_ROOT; 57 f->fragtree = RB_ROOT;
58 f->metadata = NULL; 58 f->metadata = NULL;
59 f->dents = NULL; 59 f->dents = NULL;
60 f->target = NULL;
60 f->flags = 0; 61 f->flags = 0;
61 f->usercompr = 0; 62 f->usercompr = 0;
62} 63}
@@ -64,17 +65,24 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
64 65
65#define jffs2_is_readonly(c) (OFNI_BS_2SFFJ(c)->s_flags & MS_RDONLY) 66#define jffs2_is_readonly(c) (OFNI_BS_2SFFJ(c)->s_flags & MS_RDONLY)
66 67
68#define SECTOR_ADDR(x) ( (((unsigned long)(x) / c->sector_size) * c->sector_size) )
67#ifndef CONFIG_JFFS2_FS_WRITEBUFFER 69#ifndef CONFIG_JFFS2_FS_WRITEBUFFER
68#define SECTOR_ADDR(x) ( ((unsigned long)(x) & ~(c->sector_size-1)) ) 70
71
72#ifdef CONFIG_JFFS2_SUMMARY
73#define jffs2_can_mark_obsolete(c) (0)
74#else
69#define jffs2_can_mark_obsolete(c) (1) 75#define jffs2_can_mark_obsolete(c) (1)
76#endif
77
70#define jffs2_is_writebuffered(c) (0) 78#define jffs2_is_writebuffered(c) (0)
71#define jffs2_cleanmarker_oob(c) (0) 79#define jffs2_cleanmarker_oob(c) (0)
72#define jffs2_write_nand_cleanmarker(c,jeb) (-EIO) 80#define jffs2_write_nand_cleanmarker(c,jeb) (-EIO)
73 81
74#define jffs2_flash_write(c, ofs, len, retlen, buf) ((c)->mtd->write((c)->mtd, ofs, len, retlen, buf)) 82#define jffs2_flash_write(c, ofs, len, retlen, buf) jffs2_flash_direct_write(c, ofs, len, retlen, buf)
75#define jffs2_flash_read(c, ofs, len, retlen, buf) ((c)->mtd->read((c)->mtd, ofs, len, retlen, buf)) 83#define jffs2_flash_read(c, ofs, len, retlen, buf) ((c)->mtd->read((c)->mtd, ofs, len, retlen, buf))
76#define jffs2_flush_wbuf_pad(c) ({ (void)(c), 0; }) 84#define jffs2_flush_wbuf_pad(c) ({ do{} while(0); (void)(c), 0; })
77#define jffs2_flush_wbuf_gc(c, i) ({ (void)(c), (void) i, 0; }) 85#define jffs2_flush_wbuf_gc(c, i) ({ do{} while(0); (void)(c), (void) i, 0; })
78#define jffs2_write_nand_badblock(c,jeb,bad_offset) (1) 86#define jffs2_write_nand_badblock(c,jeb,bad_offset) (1)
79#define jffs2_nand_flash_setup(c) (0) 87#define jffs2_nand_flash_setup(c) (0)
80#define jffs2_nand_flash_cleanup(c) do {} while(0) 88#define jffs2_nand_flash_cleanup(c) do {} while(0)
@@ -84,16 +92,26 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
84#define jffs2_wbuf_process NULL 92#define jffs2_wbuf_process NULL
85#define jffs2_nor_ecc(c) (0) 93#define jffs2_nor_ecc(c) (0)
86#define jffs2_dataflash(c) (0) 94#define jffs2_dataflash(c) (0)
95#define jffs2_nor_wbuf_flash(c) (0)
87#define jffs2_nor_ecc_flash_setup(c) (0) 96#define jffs2_nor_ecc_flash_setup(c) (0)
88#define jffs2_nor_ecc_flash_cleanup(c) do {} while (0) 97#define jffs2_nor_ecc_flash_cleanup(c) do {} while (0)
89#define jffs2_dataflash_setup(c) (0) 98#define jffs2_dataflash_setup(c) (0)
90#define jffs2_dataflash_cleanup(c) do {} while (0) 99#define jffs2_dataflash_cleanup(c) do {} while (0)
100#define jffs2_nor_wbuf_flash_setup(c) (0)
101#define jffs2_nor_wbuf_flash_cleanup(c) do {} while (0)
91 102
92#else /* NAND and/or ECC'd NOR support present */ 103#else /* NAND and/or ECC'd NOR support present */
93 104
94#define jffs2_is_writebuffered(c) (c->wbuf != NULL) 105#define jffs2_is_writebuffered(c) (c->wbuf != NULL)
95#define SECTOR_ADDR(x) ( ((unsigned long)(x) / (unsigned long)(c->sector_size)) * c->sector_size ) 106
96#define jffs2_can_mark_obsolete(c) ((c->mtd->type == MTD_NORFLASH && !(c->mtd->flags & MTD_ECC)) || c->mtd->type == MTD_RAM) 107#ifdef CONFIG_JFFS2_SUMMARY
108#define jffs2_can_mark_obsolete(c) (0)
109#else
110#define jffs2_can_mark_obsolete(c) \
111 ((c->mtd->type == MTD_NORFLASH && !(c->mtd->flags & (MTD_ECC|MTD_PROGRAM_REGIONS))) || \
112 c->mtd->type == MTD_RAM)
113#endif
114
97#define jffs2_cleanmarker_oob(c) (c->mtd->type == MTD_NANDFLASH) 115#define jffs2_cleanmarker_oob(c) (c->mtd->type == MTD_NANDFLASH)
98 116
99#define jffs2_flash_write_oob(c, ofs, len, retlen, buf) ((c)->mtd->write_oob((c)->mtd, ofs, len, retlen, buf)) 117#define jffs2_flash_write_oob(c, ofs, len, retlen, buf) ((c)->mtd->write_oob((c)->mtd, ofs, len, retlen, buf))
@@ -123,6 +141,10 @@ void jffs2_nor_ecc_flash_cleanup(struct jffs2_sb_info *c);
123int jffs2_dataflash_setup(struct jffs2_sb_info *c); 141int jffs2_dataflash_setup(struct jffs2_sb_info *c);
124void jffs2_dataflash_cleanup(struct jffs2_sb_info *c); 142void jffs2_dataflash_cleanup(struct jffs2_sb_info *c);
125 143
144#define jffs2_nor_wbuf_flash(c) (c->mtd->type == MTD_NORFLASH && (c->mtd->flags & MTD_PROGRAM_REGIONS))
145int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c);
146void jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c);
147
126#endif /* WRITEBUFFER */ 148#endif /* WRITEBUFFER */
127 149
128/* erase.c */ 150/* erase.c */
@@ -169,20 +191,21 @@ void jffs2_gc_release_inode(struct jffs2_sb_info *c,
169struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c, 191struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
170 int inum, int nlink); 192 int inum, int nlink);
171 193
172unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c, 194unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c,
173 struct jffs2_inode_info *f, 195 struct jffs2_inode_info *f,
174 unsigned long offset, 196 unsigned long offset,
175 unsigned long *priv); 197 unsigned long *priv);
176void jffs2_gc_release_page(struct jffs2_sb_info *c, 198void jffs2_gc_release_page(struct jffs2_sb_info *c,
177 unsigned char *pg, 199 unsigned char *pg,
178 unsigned long *priv); 200 unsigned long *priv);
179void jffs2_flash_cleanup(struct jffs2_sb_info *c); 201void jffs2_flash_cleanup(struct jffs2_sb_info *c);
180 202
181 203
182/* writev.c */ 204/* writev.c */
183int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs, 205int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
184 unsigned long count, loff_t to, size_t *retlen); 206 unsigned long count, loff_t to, size_t *retlen);
185 207int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
208 size_t *retlen, const u_char *buf);
186 209
187#endif /* __JFFS2_OS_LINUX_H__ */ 210#endif /* __JFFS2_OS_LINUX_H__ */
188 211
diff --git a/fs/jffs2/read.c b/fs/jffs2/read.c
index c7f9068907cf..f3b86da833ba 100644
--- a/fs/jffs2/read.c
+++ b/fs/jffs2/read.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: read.c,v 1.39 2005/03/01 10:34:03 dedekind Exp $ 10 * $Id: read.c,v 1.42 2005/11/07 11:14:41 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -43,7 +43,7 @@ int jffs2_read_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
43 } 43 }
44 if (readlen != sizeof(*ri)) { 44 if (readlen != sizeof(*ri)) {
45 jffs2_free_raw_inode(ri); 45 jffs2_free_raw_inode(ri);
46 printk(KERN_WARNING "Short read from 0x%08x: wanted 0x%zx bytes, got 0x%zx\n", 46 printk(KERN_WARNING "Short read from 0x%08x: wanted 0x%zx bytes, got 0x%zx\n",
47 ref_offset(fd->raw), sizeof(*ri), readlen); 47 ref_offset(fd->raw), sizeof(*ri), readlen);
48 return -EIO; 48 return -EIO;
49 } 49 }
@@ -61,7 +61,7 @@ int jffs2_read_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
61 } 61 }
62 /* There was a bug where we wrote hole nodes out with csize/dsize 62 /* There was a bug where we wrote hole nodes out with csize/dsize
63 swapped. Deal with it */ 63 swapped. Deal with it */
64 if (ri->compr == JFFS2_COMPR_ZERO && !je32_to_cpu(ri->dsize) && 64 if (ri->compr == JFFS2_COMPR_ZERO && !je32_to_cpu(ri->dsize) &&
65 je32_to_cpu(ri->csize)) { 65 je32_to_cpu(ri->csize)) {
66 ri->dsize = ri->csize; 66 ri->dsize = ri->csize;
67 ri->csize = cpu_to_je32(0); 67 ri->csize = cpu_to_je32(0);
@@ -74,7 +74,7 @@ int jffs2_read_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
74 goto out_ri; 74 goto out_ri;
75 }); 75 });
76 76
77 77
78 if (ri->compr == JFFS2_COMPR_ZERO) { 78 if (ri->compr == JFFS2_COMPR_ZERO) {
79 memset(buf, 0, len); 79 memset(buf, 0, len);
80 goto out_ri; 80 goto out_ri;
@@ -82,8 +82,8 @@ int jffs2_read_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
82 82
83 /* Cases: 83 /* Cases:
84 Reading whole node and it's uncompressed - read directly to buffer provided, check CRC. 84 Reading whole node and it's uncompressed - read directly to buffer provided, check CRC.
85 Reading whole node and it's compressed - read into comprbuf, check CRC and decompress to buffer provided 85 Reading whole node and it's compressed - read into comprbuf, check CRC and decompress to buffer provided
86 Reading partial node and it's uncompressed - read into readbuf, check CRC, and copy 86 Reading partial node and it's uncompressed - read into readbuf, check CRC, and copy
87 Reading partial node and it's compressed - read into readbuf, check checksum, decompress to decomprbuf and copy 87 Reading partial node and it's compressed - read into readbuf, check checksum, decompress to decomprbuf and copy
88 */ 88 */
89 if (ri->compr == JFFS2_COMPR_NONE && len == je32_to_cpu(ri->dsize)) { 89 if (ri->compr == JFFS2_COMPR_NONE && len == je32_to_cpu(ri->dsize)) {
@@ -129,7 +129,7 @@ int jffs2_read_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
129 D2(printk(KERN_DEBUG "Data CRC matches calculated CRC %08x\n", crc)); 129 D2(printk(KERN_DEBUG "Data CRC matches calculated CRC %08x\n", crc));
130 if (ri->compr != JFFS2_COMPR_NONE) { 130 if (ri->compr != JFFS2_COMPR_NONE) {
131 D2(printk(KERN_DEBUG "Decompress %d bytes from %p to %d bytes at %p\n", 131 D2(printk(KERN_DEBUG "Decompress %d bytes from %p to %d bytes at %p\n",
132 je32_to_cpu(ri->csize), readbuf, je32_to_cpu(ri->dsize), decomprbuf)); 132 je32_to_cpu(ri->csize), readbuf, je32_to_cpu(ri->dsize), decomprbuf));
133 ret = jffs2_decompress(c, f, ri->compr | (ri->usercompr << 8), readbuf, decomprbuf, je32_to_cpu(ri->csize), je32_to_cpu(ri->dsize)); 133 ret = jffs2_decompress(c, f, ri->compr | (ri->usercompr << 8), readbuf, decomprbuf, je32_to_cpu(ri->csize), je32_to_cpu(ri->dsize));
134 if (ret) { 134 if (ret) {
135 printk(KERN_WARNING "Error: jffs2_decompress returned %d\n", ret); 135 printk(KERN_WARNING "Error: jffs2_decompress returned %d\n", ret);
@@ -174,7 +174,6 @@ int jffs2_read_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
174 if (frag) { 174 if (frag) {
175 D1(printk(KERN_NOTICE "Eep. Hole in ino #%u fraglist. frag->ofs = 0x%08x, offset = 0x%08x\n", f->inocache->ino, frag->ofs, offset)); 175 D1(printk(KERN_NOTICE "Eep. Hole in ino #%u fraglist. frag->ofs = 0x%08x, offset = 0x%08x\n", f->inocache->ino, frag->ofs, offset));
176 holesize = min(holesize, frag->ofs - offset); 176 holesize = min(holesize, frag->ofs - offset);
177 D2(jffs2_print_frag_list(f));
178 } 177 }
179 D1(printk(KERN_DEBUG "Filling non-frag hole from %d-%d\n", offset, offset+holesize)); 178 D1(printk(KERN_DEBUG "Filling non-frag hole from %d-%d\n", offset, offset+holesize));
180 memset(buf, 0, holesize); 179 memset(buf, 0, holesize);
@@ -192,7 +191,7 @@ int jffs2_read_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
192 } else { 191 } else {
193 uint32_t readlen; 192 uint32_t readlen;
194 uint32_t fragofs; /* offset within the frag to start reading */ 193 uint32_t fragofs; /* offset within the frag to start reading */
195 194
196 fragofs = offset - frag->ofs; 195 fragofs = offset - frag->ofs;
197 readlen = min(frag->size - fragofs, end - offset); 196 readlen = min(frag->size - fragofs, end - offset);
198 D1(printk(KERN_DEBUG "Reading %d-%d from node at 0x%08x (%d)\n", 197 D1(printk(KERN_DEBUG "Reading %d-%d from node at 0x%08x (%d)\n",
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 5b2a83599d73..5f0652df5d47 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -7,11 +7,12 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: readinode.c,v 1.125 2005/07/10 13:13:55 dedekind Exp $ 10 * $Id: readinode.c,v 1.143 2005/11/07 11:14:41 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/sched.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16#include <linux/fs.h> 17#include <linux/fs.h>
17#include <linux/crc32.h> 18#include <linux/crc32.h>
@@ -20,502 +21,631 @@
20#include <linux/compiler.h> 21#include <linux/compiler.h>
21#include "nodelist.h" 22#include "nodelist.h"
22 23
23static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *list, struct jffs2_node_frag *newfrag); 24/*
24 25 * Put a new tmp_dnode_info into the temporaty RB-tree, keeping the list in
25#if CONFIG_JFFS2_FS_DEBUG >= 2 26 * order of increasing version.
26static void jffs2_print_fragtree(struct rb_root *list, int permitbug) 27 */
28static void jffs2_add_tn_to_tree(struct jffs2_tmp_dnode_info *tn, struct rb_root *list)
27{ 29{
28 struct jffs2_node_frag *this = frag_first(list); 30 struct rb_node **p = &list->rb_node;
29 uint32_t lastofs = 0; 31 struct rb_node * parent = NULL;
30 int buggy = 0; 32 struct jffs2_tmp_dnode_info *this;
31 33
32 while(this) { 34 while (*p) {
33 if (this->node) 35 parent = *p;
34 printk(KERN_DEBUG "frag %04x-%04x: 0x%08x(%d) on flash (*%p). left (%p), right (%p), parent (%p)\n", 36 this = rb_entry(parent, struct jffs2_tmp_dnode_info, rb);
35 this->ofs, this->ofs+this->size, ref_offset(this->node->raw), ref_flags(this->node->raw), 37
36 this, frag_left(this), frag_right(this), frag_parent(this)); 38 /* There may actually be a collision here, but it doesn't
37 else 39 actually matter. As long as the two nodes with the same
38 printk(KERN_DEBUG "frag %04x-%04x: hole (*%p). left (%p} right (%p), parent (%p)\n", this->ofs, 40 version are together, it's all fine. */
39 this->ofs+this->size, this, frag_left(this), frag_right(this), frag_parent(this)); 41 if (tn->version > this->version)
40 if (this->ofs != lastofs) 42 p = &(*p)->rb_left;
41 buggy = 1; 43 else
42 lastofs = this->ofs+this->size; 44 p = &(*p)->rb_right;
43 this = frag_next(this);
44 } 45 }
45 if (buggy && !permitbug) { 46
46 printk(KERN_CRIT "Frag tree got a hole in it\n"); 47 rb_link_node(&tn->rb, parent, p);
47 BUG(); 48 rb_insert_color(&tn->rb, list);
49}
50
51static void jffs2_free_tmp_dnode_info_list(struct rb_root *list)
52{
53 struct rb_node *this;
54 struct jffs2_tmp_dnode_info *tn;
55
56 this = list->rb_node;
57
58 /* Now at bottom of tree */
59 while (this) {
60 if (this->rb_left)
61 this = this->rb_left;
62 else if (this->rb_right)
63 this = this->rb_right;
64 else {
65 tn = rb_entry(this, struct jffs2_tmp_dnode_info, rb);
66 jffs2_free_full_dnode(tn->fn);
67 jffs2_free_tmp_dnode_info(tn);
68
69 this = this->rb_parent;
70 if (!this)
71 break;
72
73 if (this->rb_left == &tn->rb)
74 this->rb_left = NULL;
75 else if (this->rb_right == &tn->rb)
76 this->rb_right = NULL;
77 else BUG();
78 }
48 } 79 }
80 list->rb_node = NULL;
49} 81}
50 82
51void jffs2_print_frag_list(struct jffs2_inode_info *f) 83static void jffs2_free_full_dirent_list(struct jffs2_full_dirent *fd)
52{ 84{
53 jffs2_print_fragtree(&f->fragtree, 0); 85 struct jffs2_full_dirent *next;
54 86
55 if (f->metadata) { 87 while (fd) {
56 printk(KERN_DEBUG "metadata at 0x%08x\n", ref_offset(f->metadata->raw)); 88 next = fd->next;
89 jffs2_free_full_dirent(fd);
90 fd = next;
57 } 91 }
58} 92}
59#endif
60 93
61#if CONFIG_JFFS2_FS_DEBUG >= 1 94/* Returns first valid node after 'ref'. May return 'ref' */
62static int jffs2_sanitycheck_fragtree(struct jffs2_inode_info *f) 95static struct jffs2_raw_node_ref *jffs2_first_valid_node(struct jffs2_raw_node_ref *ref)
63{ 96{
64 struct jffs2_node_frag *frag; 97 while (ref && ref->next_in_ino) {
65 int bitched = 0; 98 if (!ref_obsolete(ref))
66 99 return ref;
67 for (frag = frag_first(&f->fragtree); frag; frag = frag_next(frag)) { 100 dbg_noderef("node at 0x%08x is obsoleted. Ignoring.\n", ref_offset(ref));
101 ref = ref->next_in_ino;
102 }
103 return NULL;
104}
68 105
69 struct jffs2_full_dnode *fn = frag->node; 106/*
70 if (!fn || !fn->raw) 107 * Helper function for jffs2_get_inode_nodes().
71 continue; 108 * It is called every time an directory entry node is found.
109 *
110 * Returns: 0 on succes;
111 * 1 if the node should be marked obsolete;
112 * negative error code on failure.
113 */
114static inline int read_direntry(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref,
115 struct jffs2_raw_dirent *rd, uint32_t read, struct jffs2_full_dirent **fdp,
116 uint32_t *latest_mctime, uint32_t *mctime_ver)
117{
118 struct jffs2_full_dirent *fd;
119
120 /* The direntry nodes are checked during the flash scanning */
121 BUG_ON(ref_flags(ref) == REF_UNCHECKED);
122 /* Obsoleted. This cannot happen, surely? dwmw2 20020308 */
123 BUG_ON(ref_obsolete(ref));
124
125 /* Sanity check */
126 if (unlikely(PAD((rd->nsize + sizeof(*rd))) != PAD(je32_to_cpu(rd->totlen)))) {
127 JFFS2_ERROR("illegal nsize in node at %#08x: nsize %#02x, totlen %#04x\n",
128 ref_offset(ref), rd->nsize, je32_to_cpu(rd->totlen));
129 return 1;
130 }
72 131
73 if (ref_flags(fn->raw) == REF_PRISTINE) { 132 fd = jffs2_alloc_full_dirent(rd->nsize + 1);
133 if (unlikely(!fd))
134 return -ENOMEM;
74 135
75 if (fn->frags > 1) { 136 fd->raw = ref;
76 printk(KERN_WARNING "REF_PRISTINE node at 0x%08x had %d frags. Tell dwmw2\n", ref_offset(fn->raw), fn->frags); 137 fd->version = je32_to_cpu(rd->version);
77 bitched = 1; 138 fd->ino = je32_to_cpu(rd->ino);
78 } 139 fd->type = rd->type;
79 /* A hole node which isn't multi-page should be garbage-collected
80 and merged anyway, so we just check for the frag size here,
81 rather than mucking around with actually reading the node
82 and checking the compression type, which is the real way
83 to tell a hole node. */
84 if (frag->ofs & (PAGE_CACHE_SIZE-1) && frag_prev(frag) && frag_prev(frag)->size < PAGE_CACHE_SIZE && frag_prev(frag)->node) {
85 printk(KERN_WARNING "REF_PRISTINE node at 0x%08x had a previous non-hole frag in the same page. Tell dwmw2\n",
86 ref_offset(fn->raw));
87 bitched = 1;
88 }
89 140
90 if ((frag->ofs+frag->size) & (PAGE_CACHE_SIZE-1) && frag_next(frag) && frag_next(frag)->size < PAGE_CACHE_SIZE && frag_next(frag)->node) { 141 /* Pick out the mctime of the latest dirent */
91 printk(KERN_WARNING "REF_PRISTINE node at 0x%08x (%08x-%08x) had a following non-hole frag in the same page. Tell dwmw2\n", 142 if(fd->version > *mctime_ver && je32_to_cpu(rd->mctime)) {
92 ref_offset(fn->raw), frag->ofs, frag->ofs+frag->size); 143 *mctime_ver = fd->version;
93 bitched = 1; 144 *latest_mctime = je32_to_cpu(rd->mctime);
94 }
95 }
96 } 145 }
97
98 if (bitched) {
99 struct jffs2_node_frag *thisfrag;
100
101 printk(KERN_WARNING "Inode is #%u\n", f->inocache->ino);
102 thisfrag = frag_first(&f->fragtree);
103 while (thisfrag) {
104 if (!thisfrag->node) {
105 printk("Frag @0x%x-0x%x; node-less hole\n",
106 thisfrag->ofs, thisfrag->size + thisfrag->ofs);
107 } else if (!thisfrag->node->raw) {
108 printk("Frag @0x%x-0x%x; raw-less hole\n",
109 thisfrag->ofs, thisfrag->size + thisfrag->ofs);
110 } else {
111 printk("Frag @0x%x-0x%x; raw at 0x%08x(%d) (0x%x-0x%x)\n",
112 thisfrag->ofs, thisfrag->size + thisfrag->ofs,
113 ref_offset(thisfrag->node->raw), ref_flags(thisfrag->node->raw),
114 thisfrag->node->ofs, thisfrag->node->ofs+thisfrag->node->size);
115 }
116 thisfrag = frag_next(thisfrag);
117 }
118 }
119 return bitched;
120}
121#endif /* D1 */
122 146
123static void jffs2_obsolete_node_frag(struct jffs2_sb_info *c, struct jffs2_node_frag *this) 147 /*
124{ 148 * Copy as much of the name as possible from the raw
125 if (this->node) { 149 * dirent we've already read from the flash.
126 this->node->frags--; 150 */
127 if (!this->node->frags) { 151 if (read > sizeof(*rd))
128 /* The node has no valid frags left. It's totally obsoleted */ 152 memcpy(&fd->name[0], &rd->name[0],
129 D2(printk(KERN_DEBUG "Marking old node @0x%08x (0x%04x-0x%04x) obsolete\n", 153 min_t(uint32_t, rd->nsize, (read - sizeof(*rd)) ));
130 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size)); 154
131 jffs2_mark_node_obsolete(c, this->node->raw); 155 /* Do we need to copy any more of the name directly from the flash? */
132 jffs2_free_full_dnode(this->node); 156 if (rd->nsize + sizeof(*rd) > read) {
133 } else { 157 /* FIXME: point() */
134 D2(printk(KERN_DEBUG "Marking old node @0x%08x (0x%04x-0x%04x) REF_NORMAL. frags is %d\n", 158 int err;
135 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size, 159 int already = read - sizeof(*rd);
136 this->node->frags)); 160
137 mark_ref_normal(this->node->raw); 161 err = jffs2_flash_read(c, (ref_offset(ref)) + read,
162 rd->nsize - already, &read, &fd->name[already]);
163 if (unlikely(read != rd->nsize - already) && likely(!err))
164 return -EIO;
165
166 if (unlikely(err)) {
167 JFFS2_ERROR("read remainder of name: error %d\n", err);
168 jffs2_free_full_dirent(fd);
169 return -EIO;
138 } 170 }
139
140 } 171 }
141 jffs2_free_node_frag(this); 172
173 fd->nhash = full_name_hash(fd->name, rd->nsize);
174 fd->next = NULL;
175 fd->name[rd->nsize] = '\0';
176
177 /*
178 * Wheee. We now have a complete jffs2_full_dirent structure, with
179 * the name in it and everything. Link it into the list
180 */
181 jffs2_add_fd_to_list(c, fd, fdp);
182
183 return 0;
142} 184}
143 185
144/* Given an inode, probably with existing list of fragments, add the new node 186/*
145 * to the fragment list. 187 * Helper function for jffs2_get_inode_nodes().
188 * It is called every time an inode node is found.
189 *
190 * Returns: 0 on succes;
191 * 1 if the node should be marked obsolete;
192 * negative error code on failure.
146 */ 193 */
147int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn) 194static inline int read_dnode(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref,
195 struct jffs2_raw_inode *rd, struct rb_root *tnp, int rdlen,
196 uint32_t *latest_mctime, uint32_t *mctime_ver)
148{ 197{
149 int ret; 198 struct jffs2_tmp_dnode_info *tn;
150 struct jffs2_node_frag *newfrag; 199 uint32_t len, csize;
151 200 int ret = 1;
152 D1(printk(KERN_DEBUG "jffs2_add_full_dnode_to_inode(ino #%u, f %p, fn %p)\n", f->inocache->ino, f, fn));
153 201
154 if (unlikely(!fn->size)) 202 /* Obsoleted. This cannot happen, surely? dwmw2 20020308 */
155 return 0; 203 BUG_ON(ref_obsolete(ref));
156 204
157 newfrag = jffs2_alloc_node_frag(); 205 tn = jffs2_alloc_tmp_dnode_info();
158 if (unlikely(!newfrag)) 206 if (!tn) {
207 JFFS2_ERROR("failed to allocate tn (%d bytes).\n", sizeof(*tn));
159 return -ENOMEM; 208 return -ENOMEM;
209 }
160 210
161 D2(printk(KERN_DEBUG "adding node %04x-%04x @0x%08x on flash, newfrag *%p\n", 211 tn->partial_crc = 0;
162 fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag)); 212 csize = je32_to_cpu(rd->csize);
163
164 newfrag->ofs = fn->ofs;
165 newfrag->size = fn->size;
166 newfrag->node = fn;
167 newfrag->node->frags = 1;
168 213
169 ret = jffs2_add_frag_to_fragtree(c, &f->fragtree, newfrag); 214 /* If we've never checked the CRCs on this node, check them now */
170 if (ret) 215 if (ref_flags(ref) == REF_UNCHECKED) {
171 return ret; 216 uint32_t crc;
172 217
173 /* If we now share a page with other nodes, mark either previous 218 crc = crc32(0, rd, sizeof(*rd) - 8);
174 or next node REF_NORMAL, as appropriate. */ 219 if (unlikely(crc != je32_to_cpu(rd->node_crc))) {
175 if (newfrag->ofs & (PAGE_CACHE_SIZE-1)) { 220 JFFS2_NOTICE("header CRC failed on node at %#08x: read %#08x, calculated %#08x\n",
176 struct jffs2_node_frag *prev = frag_prev(newfrag); 221 ref_offset(ref), je32_to_cpu(rd->node_crc), crc);
222 goto free_out;
223 }
177 224
178 mark_ref_normal(fn->raw); 225 /* Sanity checks */
179 /* If we don't start at zero there's _always_ a previous */ 226 if (unlikely(je32_to_cpu(rd->offset) > je32_to_cpu(rd->isize)) ||
180 if (prev->node) 227 unlikely(PAD(je32_to_cpu(rd->csize) + sizeof(*rd)) != PAD(je32_to_cpu(rd->totlen)))) {
181 mark_ref_normal(prev->node->raw); 228 JFFS2_WARNING("inode node header CRC is corrupted at %#08x\n", ref_offset(ref));
182 } 229 jffs2_dbg_dump_node(c, ref_offset(ref));
230 goto free_out;
231 }
183 232
184 if ((newfrag->ofs+newfrag->size) & (PAGE_CACHE_SIZE-1)) { 233 if (jffs2_is_writebuffered(c) && csize != 0) {
185 struct jffs2_node_frag *next = frag_next(newfrag); 234 /* At this point we are supposed to check the data CRC
186 235 * of our unchecked node. But thus far, we do not
187 if (next) { 236 * know whether the node is valid or obsolete. To
188 mark_ref_normal(fn->raw); 237 * figure this out, we need to walk all the nodes of
189 if (next->node) 238 * the inode and build the inode fragtree. We don't
190 mark_ref_normal(next->node->raw); 239 * want to spend time checking data of nodes which may
240 * later be found to be obsolete. So we put off the full
241 * data CRC checking until we have read all the inode
242 * nodes and have started building the fragtree.
243 *
244 * The fragtree is being built starting with nodes
245 * having the highest version number, so we'll be able
246 * to detect whether a node is valid (i.e., it is not
247 * overlapped by a node with higher version) or not.
248 * And we'll be able to check only those nodes, which
249 * are not obsolete.
250 *
251 * Of course, this optimization only makes sense in case
252 * of NAND flashes (or other flashes whith
253 * !jffs2_can_mark_obsolete()), since on NOR flashes
254 * nodes are marked obsolete physically.
255 *
256 * Since NAND flashes (or other flashes with
257 * jffs2_is_writebuffered(c)) are anyway read by
258 * fractions of c->wbuf_pagesize, and we have just read
259 * the node header, it is likely that the starting part
260 * of the node data is also read when we read the
261 * header. So we don't mind to check the CRC of the
262 * starting part of the data of the node now, and check
263 * the second part later (in jffs2_check_node_data()).
264 * Of course, we will not need to re-read and re-check
265 * the NAND page which we have just read. This is why we
266 * read the whole NAND page at jffs2_get_inode_nodes(),
267 * while we needed only the node header.
268 */
269 unsigned char *buf;
270
271 /* 'buf' will point to the start of data */
272 buf = (unsigned char *)rd + sizeof(*rd);
273 /* len will be the read data length */
274 len = min_t(uint32_t, rdlen - sizeof(*rd), csize);
275 tn->partial_crc = crc32(0, buf, len);
276
277 dbg_readinode("Calculates CRC (%#08x) for %d bytes, csize %d\n", tn->partial_crc, len, csize);
278
279 /* If we actually calculated the whole data CRC
280 * and it is wrong, drop the node. */
281 if (len >= csize && unlikely(tn->partial_crc != je32_to_cpu(rd->data_crc))) {
282 JFFS2_NOTICE("wrong data CRC in data node at 0x%08x: read %#08x, calculated %#08x.\n",
283 ref_offset(ref), tn->partial_crc, je32_to_cpu(rd->data_crc));
284 goto free_out;
285 }
286
287 } else if (csize == 0) {
288 /*
289 * We checked the header CRC. If the node has no data, adjust
290 * the space accounting now. For other nodes this will be done
291 * later either when the node is marked obsolete or when its
292 * data is checked.
293 */
294 struct jffs2_eraseblock *jeb;
295
296 dbg_readinode("the node has no data.\n");
297 jeb = &c->blocks[ref->flash_offset / c->sector_size];
298 len = ref_totlen(c, jeb, ref);
299
300 spin_lock(&c->erase_completion_lock);
301 jeb->used_size += len;
302 jeb->unchecked_size -= len;
303 c->used_size += len;
304 c->unchecked_size -= len;
305 ref->flash_offset = ref_offset(ref) | REF_NORMAL;
306 spin_unlock(&c->erase_completion_lock);
191 } 307 }
192 } 308 }
193 D2(if (jffs2_sanitycheck_fragtree(f)) { 309
194 printk(KERN_WARNING "Just added node %04x-%04x @0x%08x on flash, newfrag *%p\n", 310 tn->fn = jffs2_alloc_full_dnode();
195 fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag); 311 if (!tn->fn) {
196 return 0; 312 JFFS2_ERROR("alloc fn failed\n");
197 }) 313 ret = -ENOMEM;
198 D2(jffs2_print_frag_list(f)); 314 goto free_out;
315 }
316
317 tn->version = je32_to_cpu(rd->version);
318 tn->fn->ofs = je32_to_cpu(rd->offset);
319 tn->data_crc = je32_to_cpu(rd->data_crc);
320 tn->csize = csize;
321 tn->fn->raw = ref;
322
323 /* There was a bug where we wrote hole nodes out with
324 csize/dsize swapped. Deal with it */
325 if (rd->compr == JFFS2_COMPR_ZERO && !je32_to_cpu(rd->dsize) && csize)
326 tn->fn->size = csize;
327 else // normal case...
328 tn->fn->size = je32_to_cpu(rd->dsize);
329
330 dbg_readinode("dnode @%08x: ver %u, offset %#04x, dsize %#04x, csize %#04x\n",
331 ref_offset(ref), je32_to_cpu(rd->version), je32_to_cpu(rd->offset), je32_to_cpu(rd->dsize), csize);
332
333 jffs2_add_tn_to_tree(tn, tnp);
334
199 return 0; 335 return 0;
336
337free_out:
338 jffs2_free_tmp_dnode_info(tn);
339 return ret;
200} 340}
201 341
202/* Doesn't set inode->i_size */ 342/*
203static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *list, struct jffs2_node_frag *newfrag) 343 * Helper function for jffs2_get_inode_nodes().
344 * It is called every time an unknown node is found.
345 *
346 * Returns: 0 on succes;
347 * 1 if the node should be marked obsolete;
348 * negative error code on failure.
349 */
350static inline int read_unknown(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref, struct jffs2_unknown_node *un)
204{ 351{
205 struct jffs2_node_frag *this; 352 /* We don't mark unknown nodes as REF_UNCHECKED */
206 uint32_t lastend; 353 BUG_ON(ref_flags(ref) == REF_UNCHECKED);
207 354
208 /* Skip all the nodes which are completed before this one starts */ 355 un->nodetype = cpu_to_je16(JFFS2_NODE_ACCURATE | je16_to_cpu(un->nodetype));
209 this = jffs2_lookup_node_frag(list, newfrag->node->ofs);
210 356
211 if (this) { 357 if (crc32(0, un, sizeof(struct jffs2_unknown_node) - 4) != je32_to_cpu(un->hdr_crc)) {
212 D2(printk(KERN_DEBUG "j_a_f_d_t_f: Lookup gave frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n", 358 /* Hmmm. This should have been caught at scan time. */
213 this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this)); 359 JFFS2_NOTICE("node header CRC failed at %#08x. But it must have been OK earlier.\n", ref_offset(ref));
214 lastend = this->ofs + this->size; 360 jffs2_dbg_dump_node(c, ref_offset(ref));
361 return 1;
215 } else { 362 } else {
216 D2(printk(KERN_DEBUG "j_a_f_d_t_f: Lookup gave no frag\n")); 363 switch(je16_to_cpu(un->nodetype) & JFFS2_COMPAT_MASK) {
217 lastend = 0;
218 }
219
220 /* See if we ran off the end of the list */
221 if (lastend <= newfrag->ofs) {
222 /* We did */
223
224 /* Check if 'this' node was on the same page as the new node.
225 If so, both 'this' and the new node get marked REF_NORMAL so
226 the GC can take a look.
227 */
228 if (lastend && (lastend-1) >> PAGE_CACHE_SHIFT == newfrag->ofs >> PAGE_CACHE_SHIFT) {
229 if (this->node)
230 mark_ref_normal(this->node->raw);
231 mark_ref_normal(newfrag->node->raw);
232 }
233 364
234 if (lastend < newfrag->node->ofs) { 365 case JFFS2_FEATURE_INCOMPAT:
235 /* ... and we need to put a hole in before the new node */ 366 JFFS2_ERROR("unknown INCOMPAT nodetype %#04X at %#08x\n",
236 struct jffs2_node_frag *holefrag = jffs2_alloc_node_frag(); 367 je16_to_cpu(un->nodetype), ref_offset(ref));
237 if (!holefrag) { 368 /* EEP */
238 jffs2_free_node_frag(newfrag); 369 BUG();
239 return -ENOMEM; 370 break;
240 } 371
241 holefrag->ofs = lastend; 372 case JFFS2_FEATURE_ROCOMPAT:
242 holefrag->size = newfrag->node->ofs - lastend; 373 JFFS2_ERROR("unknown ROCOMPAT nodetype %#04X at %#08x\n",
243 holefrag->node = NULL; 374 je16_to_cpu(un->nodetype), ref_offset(ref));
244 if (this) { 375 BUG_ON(!(c->flags & JFFS2_SB_FLAG_RO));
245 /* By definition, the 'this' node has no right-hand child, 376 break;
246 because there are no frags with offset greater than it. 377
247 So that's where we want to put the hole */ 378 case JFFS2_FEATURE_RWCOMPAT_COPY:
248 D2(printk(KERN_DEBUG "Adding hole frag (%p) on right of node at (%p)\n", holefrag, this)); 379 JFFS2_NOTICE("unknown RWCOMPAT_COPY nodetype %#04X at %#08x\n",
249 rb_link_node(&holefrag->rb, &this->rb, &this->rb.rb_right); 380 je16_to_cpu(un->nodetype), ref_offset(ref));
250 } else { 381 break;
251 D2(printk(KERN_DEBUG "Adding hole frag (%p) at root of tree\n", holefrag)); 382
252 rb_link_node(&holefrag->rb, NULL, &list->rb_node); 383 case JFFS2_FEATURE_RWCOMPAT_DELETE:
253 } 384 JFFS2_NOTICE("unknown RWCOMPAT_DELETE nodetype %#04X at %#08x\n",
254 rb_insert_color(&holefrag->rb, list); 385 je16_to_cpu(un->nodetype), ref_offset(ref));
255 this = holefrag; 386 return 1;
256 }
257 if (this) {
258 /* By definition, the 'this' node has no right-hand child,
259 because there are no frags with offset greater than it.
260 So that's where we want to put the hole */
261 D2(printk(KERN_DEBUG "Adding new frag (%p) on right of node at (%p)\n", newfrag, this));
262 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right);
263 } else {
264 D2(printk(KERN_DEBUG "Adding new frag (%p) at root of tree\n", newfrag));
265 rb_link_node(&newfrag->rb, NULL, &list->rb_node);
266 } 387 }
267 rb_insert_color(&newfrag->rb, list);
268 return 0;
269 } 388 }
270 389
271 D2(printk(KERN_DEBUG "j_a_f_d_t_f: dealing with frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n", 390 return 0;
272 this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this)); 391}
273 392
274 /* OK. 'this' is pointing at the first frag that newfrag->ofs at least partially obsoletes, 393/*
275 * - i.e. newfrag->ofs < this->ofs+this->size && newfrag->ofs >= this->ofs 394 * Helper function for jffs2_get_inode_nodes().
276 */ 395 * The function detects whether more data should be read and reads it if yes.
277 if (newfrag->ofs > this->ofs) { 396 *
278 /* This node isn't completely obsoleted. The start of it remains valid */ 397 * Returns: 0 on succes;
279 398 * negative error code on failure.
280 /* Mark the new node and the partially covered node REF_NORMAL -- let 399 */
281 the GC take a look at them */ 400static int read_more(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref,
282 mark_ref_normal(newfrag->node->raw); 401 int right_size, int *rdlen, unsigned char *buf, unsigned char *bufstart)
283 if (this->node) 402{
284 mark_ref_normal(this->node->raw); 403 int right_len, err, len;
285 404 size_t retlen;
286 if (this->ofs + this->size > newfrag->ofs + newfrag->size) { 405 uint32_t offs;
287 /* The new node splits 'this' frag into two */
288 struct jffs2_node_frag *newfrag2 = jffs2_alloc_node_frag();
289 if (!newfrag2) {
290 jffs2_free_node_frag(newfrag);
291 return -ENOMEM;
292 }
293 D2(printk(KERN_DEBUG "split old frag 0x%04x-0x%04x -->", this->ofs, this->ofs+this->size);
294 if (this->node)
295 printk("phys 0x%08x\n", ref_offset(this->node->raw));
296 else
297 printk("hole\n");
298 )
299
300 /* New second frag pointing to this's node */
301 newfrag2->ofs = newfrag->ofs + newfrag->size;
302 newfrag2->size = (this->ofs+this->size) - newfrag2->ofs;
303 newfrag2->node = this->node;
304 if (this->node)
305 this->node->frags++;
306
307 /* Adjust size of original 'this' */
308 this->size = newfrag->ofs - this->ofs;
309
310 /* Now, we know there's no node with offset
311 greater than this->ofs but smaller than
312 newfrag2->ofs or newfrag->ofs, for obvious
313 reasons. So we can do a tree insert from
314 'this' to insert newfrag, and a tree insert
315 from newfrag to insert newfrag2. */
316 jffs2_fragtree_insert(newfrag, this);
317 rb_insert_color(&newfrag->rb, list);
318
319 jffs2_fragtree_insert(newfrag2, newfrag);
320 rb_insert_color(&newfrag2->rb, list);
321
322 return 0;
323 }
324 /* New node just reduces 'this' frag in size, doesn't split it */
325 this->size = newfrag->ofs - this->ofs;
326 406
327 /* Again, we know it lives down here in the tree */ 407 if (jffs2_is_writebuffered(c)) {
328 jffs2_fragtree_insert(newfrag, this); 408 right_len = c->wbuf_pagesize - (bufstart - buf);
329 rb_insert_color(&newfrag->rb, list); 409 if (right_size + (int)(bufstart - buf) > c->wbuf_pagesize)
330 } else { 410 right_len += c->wbuf_pagesize;
331 /* New frag starts at the same point as 'this' used to. Replace 411 } else
332 it in the tree without doing a delete and insertion */ 412 right_len = right_size;
333 D2(printk(KERN_DEBUG "Inserting newfrag (*%p),%d-%d in before 'this' (*%p),%d-%d\n",
334 newfrag, newfrag->ofs, newfrag->ofs+newfrag->size,
335 this, this->ofs, this->ofs+this->size));
336
337 rb_replace_node(&this->rb, &newfrag->rb, list);
338
339 if (newfrag->ofs + newfrag->size >= this->ofs+this->size) {
340 D2(printk(KERN_DEBUG "Obsoleting node frag %p (%x-%x)\n", this, this->ofs, this->ofs+this->size));
341 jffs2_obsolete_node_frag(c, this);
342 } else {
343 this->ofs += newfrag->size;
344 this->size -= newfrag->size;
345 413
346 jffs2_fragtree_insert(this, newfrag); 414 if (*rdlen == right_len)
347 rb_insert_color(&this->rb, list); 415 return 0;
348 return 0; 416
349 } 417 /* We need to read more data */
418 offs = ref_offset(ref) + *rdlen;
419 if (jffs2_is_writebuffered(c)) {
420 bufstart = buf + c->wbuf_pagesize;
421 len = c->wbuf_pagesize;
422 } else {
423 bufstart = buf + *rdlen;
424 len = right_size - *rdlen;
350 } 425 }
351 /* OK, now we have newfrag added in the correct place in the tree, but 426
352 frag_next(newfrag) may be a fragment which is overlapped by it 427 dbg_readinode("read more %d bytes\n", len);
353 */ 428
354 while ((this = frag_next(newfrag)) && newfrag->ofs + newfrag->size >= this->ofs + this->size) { 429 err = jffs2_flash_read(c, offs, len, &retlen, bufstart);
355 /* 'this' frag is obsoleted completely. */ 430 if (err) {
356 D2(printk(KERN_DEBUG "Obsoleting node frag %p (%x-%x) and removing from tree\n", this, this->ofs, this->ofs+this->size)); 431 JFFS2_ERROR("can not read %d bytes from 0x%08x, "
357 rb_erase(&this->rb, list); 432 "error code: %d.\n", len, offs, err);
358 jffs2_obsolete_node_frag(c, this); 433 return err;
359 } 434 }
360 /* Now we're pointing at the first frag which isn't totally obsoleted by
361 the new frag */
362 435
363 if (!this || newfrag->ofs + newfrag->size == this->ofs) { 436 if (retlen < len) {
364 return 0; 437 JFFS2_ERROR("short read at %#08x: %d instead of %d.\n",
438 offs, retlen, len);
439 return -EIO;
365 } 440 }
366 /* Still some overlap but we don't need to move it in the tree */
367 this->size = (this->ofs + this->size) - (newfrag->ofs + newfrag->size);
368 this->ofs = newfrag->ofs + newfrag->size;
369 441
370 /* And mark them REF_NORMAL so the GC takes a look at them */ 442 *rdlen = right_len;
371 if (this->node)
372 mark_ref_normal(this->node->raw);
373 mark_ref_normal(newfrag->node->raw);
374 443
375 return 0; 444 return 0;
376} 445}
377 446
378void jffs2_truncate_fraglist (struct jffs2_sb_info *c, struct rb_root *list, uint32_t size) 447/* Get tmp_dnode_info and full_dirent for all non-obsolete nodes associated
448 with this ino, returning the former in order of version */
449static int jffs2_get_inode_nodes(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
450 struct rb_root *tnp, struct jffs2_full_dirent **fdp,
451 uint32_t *highest_version, uint32_t *latest_mctime,
452 uint32_t *mctime_ver)
379{ 453{
380 struct jffs2_node_frag *frag = jffs2_lookup_node_frag(list, size); 454 struct jffs2_raw_node_ref *ref, *valid_ref;
455 struct rb_root ret_tn = RB_ROOT;
456 struct jffs2_full_dirent *ret_fd = NULL;
457 unsigned char *buf = NULL;
458 union jffs2_node_union *node;
459 size_t retlen;
460 int len, err;
461
462 *mctime_ver = 0;
463
464 dbg_readinode("ino #%u\n", f->inocache->ino);
465
466 if (jffs2_is_writebuffered(c)) {
467 /*
468 * If we have the write buffer, we assume the minimal I/O unit
469 * is c->wbuf_pagesize. We implement some optimizations which in
470 * this case and we need a temporary buffer of size =
471 * 2*c->wbuf_pagesize bytes (see comments in read_dnode()).
472 * Basically, we want to read not only the node header, but the
473 * whole wbuf (NAND page in case of NAND) or 2, if the node
474 * header overlaps the border between the 2 wbufs.
475 */
476 len = 2*c->wbuf_pagesize;
477 } else {
478 /*
479 * When there is no write buffer, the size of the temporary
480 * buffer is the size of the larges node header.
481 */
482 len = sizeof(union jffs2_node_union);
483 }
381 484
382 D1(printk(KERN_DEBUG "Truncating fraglist to 0x%08x bytes\n", size)); 485 /* FIXME: in case of NOR and available ->point() this
486 * needs to be fixed. */
487 buf = kmalloc(len, GFP_KERNEL);
488 if (!buf)
489 return -ENOMEM;
383 490
384 /* We know frag->ofs <= size. That's what lookup does for us */ 491 spin_lock(&c->erase_completion_lock);
385 if (frag && frag->ofs != size) { 492 valid_ref = jffs2_first_valid_node(f->inocache->nodes);
386 if (frag->ofs+frag->size >= size) { 493 if (!valid_ref && f->inocache->ino != 1)
387 D1(printk(KERN_DEBUG "Truncating frag 0x%08x-0x%08x\n", frag->ofs, frag->ofs+frag->size)); 494 JFFS2_WARNING("Eep. No valid nodes for ino #%u.\n", f->inocache->ino);
388 frag->size = size - frag->ofs; 495 while (valid_ref) {
496 unsigned char *bufstart;
497
498 /* We can hold a pointer to a non-obsolete node without the spinlock,
499 but _obsolete_ nodes may disappear at any time, if the block
500 they're in gets erased. So if we mark 'ref' obsolete while we're
501 not holding the lock, it can go away immediately. For that reason,
502 we find the next valid node first, before processing 'ref'.
503 */
504 ref = valid_ref;
505 valid_ref = jffs2_first_valid_node(ref->next_in_ino);
506 spin_unlock(&c->erase_completion_lock);
507
508 cond_resched();
509
510 /*
511 * At this point we don't know the type of the node we're going
512 * to read, so we do not know the size of its header. In order
513 * to minimize the amount of flash IO we assume the node has
514 * size = JFFS2_MIN_NODE_HEADER.
515 */
516 if (jffs2_is_writebuffered(c)) {
517 /*
518 * We treat 'buf' as 2 adjacent wbufs. We want to
519 * adjust bufstart such as it points to the
520 * beginning of the node within this wbuf.
521 */
522 bufstart = buf + (ref_offset(ref) % c->wbuf_pagesize);
523 /* We will read either one wbuf or 2 wbufs. */
524 len = c->wbuf_pagesize - (bufstart - buf);
525 if (JFFS2_MIN_NODE_HEADER + (int)(bufstart - buf) > c->wbuf_pagesize) {
526 /* The header spans the border of the first wbuf */
527 len += c->wbuf_pagesize;
528 }
529 } else {
530 bufstart = buf;
531 len = JFFS2_MIN_NODE_HEADER;
389 } 532 }
390 frag = frag_next(frag);
391 }
392 while (frag && frag->ofs >= size) {
393 struct jffs2_node_frag *next = frag_next(frag);
394 533
395 D1(printk(KERN_DEBUG "Removing frag 0x%08x-0x%08x\n", frag->ofs, frag->ofs+frag->size)); 534 dbg_readinode("read %d bytes at %#08x(%d).\n", len, ref_offset(ref), ref_flags(ref));
396 frag_erase(frag, list);
397 jffs2_obsolete_node_frag(c, frag);
398 frag = next;
399 }
400}
401 535
402/* Scan the list of all nodes present for this ino, build map of versions, etc. */ 536 /* FIXME: point() */
537 err = jffs2_flash_read(c, ref_offset(ref), len,
538 &retlen, bufstart);
539 if (err) {
540 JFFS2_ERROR("can not read %d bytes from 0x%08x, " "error code: %d.\n", len, ref_offset(ref), err);
541 goto free_out;
542 }
403 543
404static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c, 544 if (retlen < len) {
405 struct jffs2_inode_info *f, 545 JFFS2_ERROR("short read at %#08x: %d instead of %d.\n", ref_offset(ref), retlen, len);
406 struct jffs2_raw_inode *latest_node); 546 err = -EIO;
547 goto free_out;
548 }
407 549
408int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 550 node = (union jffs2_node_union *)bufstart;
409 uint32_t ino, struct jffs2_raw_inode *latest_node)
410{
411 D2(printk(KERN_DEBUG "jffs2_do_read_inode(): getting inocache\n"));
412 551
413 retry_inocache: 552 switch (je16_to_cpu(node->u.nodetype)) {
414 spin_lock(&c->inocache_lock);
415 f->inocache = jffs2_get_ino_cache(c, ino);
416 553
417 D2(printk(KERN_DEBUG "jffs2_do_read_inode(): Got inocache at %p\n", f->inocache)); 554 case JFFS2_NODETYPE_DIRENT:
555
556 if (JFFS2_MIN_NODE_HEADER < sizeof(struct jffs2_raw_dirent)) {
557 err = read_more(c, ref, sizeof(struct jffs2_raw_dirent), &len, buf, bufstart);
558 if (unlikely(err))
559 goto free_out;
560 }
561
562 err = read_direntry(c, ref, &node->d, retlen, &ret_fd, latest_mctime, mctime_ver);
563 if (err == 1) {
564 jffs2_mark_node_obsolete(c, ref);
565 break;
566 } else if (unlikely(err))
567 goto free_out;
568
569 if (je32_to_cpu(node->d.version) > *highest_version)
570 *highest_version = je32_to_cpu(node->d.version);
418 571
419 if (f->inocache) {
420 /* Check its state. We may need to wait before we can use it */
421 switch(f->inocache->state) {
422 case INO_STATE_UNCHECKED:
423 case INO_STATE_CHECKEDABSENT:
424 f->inocache->state = INO_STATE_READING;
425 break; 572 break;
426
427 case INO_STATE_CHECKING:
428 case INO_STATE_GC:
429 /* If it's in either of these states, we need
430 to wait for whoever's got it to finish and
431 put it back. */
432 D1(printk(KERN_DEBUG "jffs2_get_ino_cache_read waiting for ino #%u in state %d\n",
433 ino, f->inocache->state));
434 sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock);
435 goto retry_inocache;
436 573
437 case INO_STATE_READING: 574 case JFFS2_NODETYPE_INODE:
438 case INO_STATE_PRESENT: 575
439 /* Eep. This should never happen. It can 576 if (JFFS2_MIN_NODE_HEADER < sizeof(struct jffs2_raw_inode)) {
440 happen if Linux calls read_inode() again 577 err = read_more(c, ref, sizeof(struct jffs2_raw_inode), &len, buf, bufstart);
441 before clear_inode() has finished though. */ 578 if (unlikely(err))
442 printk(KERN_WARNING "Eep. Trying to read_inode #%u when it's already in state %d!\n", ino, f->inocache->state); 579 goto free_out;
443 /* Fail. That's probably better than allowing it to succeed */ 580 }
444 f->inocache = NULL; 581
582 err = read_dnode(c, ref, &node->i, &ret_tn, len, latest_mctime, mctime_ver);
583 if (err == 1) {
584 jffs2_mark_node_obsolete(c, ref);
585 break;
586 } else if (unlikely(err))
587 goto free_out;
588
589 if (je32_to_cpu(node->i.version) > *highest_version)
590 *highest_version = je32_to_cpu(node->i.version);
591
445 break; 592 break;
446 593
447 default: 594 default:
448 BUG(); 595 if (JFFS2_MIN_NODE_HEADER < sizeof(struct jffs2_unknown_node)) {
449 } 596 err = read_more(c, ref, sizeof(struct jffs2_unknown_node), &len, buf, bufstart);
450 } 597 if (unlikely(err))
451 spin_unlock(&c->inocache_lock); 598 goto free_out;
599 }
600
601 err = read_unknown(c, ref, &node->u);
602 if (err == 1) {
603 jffs2_mark_node_obsolete(c, ref);
604 break;
605 } else if (unlikely(err))
606 goto free_out;
452 607
453 if (!f->inocache && ino == 1) {
454 /* Special case - no root inode on medium */
455 f->inocache = jffs2_alloc_inode_cache();
456 if (!f->inocache) {
457 printk(KERN_CRIT "jffs2_do_read_inode(): Cannot allocate inocache for root inode\n");
458 return -ENOMEM;
459 } 608 }
460 D1(printk(KERN_DEBUG "jffs2_do_read_inode(): Creating inocache for root inode\n")); 609 spin_lock(&c->erase_completion_lock);
461 memset(f->inocache, 0, sizeof(struct jffs2_inode_cache));
462 f->inocache->ino = f->inocache->nlink = 1;
463 f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache;
464 f->inocache->state = INO_STATE_READING;
465 jffs2_add_ino_cache(c, f->inocache);
466 }
467 if (!f->inocache) {
468 printk(KERN_WARNING "jffs2_do_read_inode() on nonexistent ino %u\n", ino);
469 return -ENOENT;
470 } 610 }
471 611
472 return jffs2_do_read_inode_internal(c, f, latest_node); 612 spin_unlock(&c->erase_completion_lock);
473} 613 *tnp = ret_tn;
474 614 *fdp = ret_fd;
475int jffs2_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic) 615 kfree(buf);
476{
477 struct jffs2_raw_inode n;
478 struct jffs2_inode_info *f = kmalloc(sizeof(*f), GFP_KERNEL);
479 int ret;
480
481 if (!f)
482 return -ENOMEM;
483 616
484 memset(f, 0, sizeof(*f)); 617 dbg_readinode("nodes of inode #%u were read, the highest version is %u, latest_mctime %u, mctime_ver %u.\n",
485 init_MUTEX_LOCKED(&f->sem); 618 f->inocache->ino, *highest_version, *latest_mctime, *mctime_ver);
486 f->inocache = ic; 619 return 0;
487 620
488 ret = jffs2_do_read_inode_internal(c, f, &n); 621 free_out:
489 if (!ret) { 622 jffs2_free_tmp_dnode_info_list(&ret_tn);
490 up(&f->sem); 623 jffs2_free_full_dirent_list(ret_fd);
491 jffs2_do_clear_inode(c, f); 624 kfree(buf);
492 } 625 return err;
493 kfree (f);
494 return ret;
495} 626}
496 627
497static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c, 628static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
498 struct jffs2_inode_info *f, 629 struct jffs2_inode_info *f,
499 struct jffs2_raw_inode *latest_node) 630 struct jffs2_raw_inode *latest_node)
500{ 631{
501 struct jffs2_tmp_dnode_info *tn = NULL; 632 struct jffs2_tmp_dnode_info *tn;
502 struct rb_root tn_list; 633 struct rb_root tn_list;
503 struct rb_node *rb, *repl_rb; 634 struct rb_node *rb, *repl_rb;
504 struct jffs2_full_dirent *fd_list; 635 struct jffs2_full_dirent *fd_list;
505 struct jffs2_full_dnode *fn = NULL; 636 struct jffs2_full_dnode *fn, *first_fn = NULL;
506 uint32_t crc; 637 uint32_t crc;
507 uint32_t latest_mctime, mctime_ver; 638 uint32_t latest_mctime, mctime_ver;
508 uint32_t mdata_ver = 0;
509 size_t retlen; 639 size_t retlen;
510 int ret; 640 int ret;
511 641
512 D1(printk(KERN_DEBUG "jffs2_do_read_inode_internal(): ino #%u nlink is %d\n", f->inocache->ino, f->inocache->nlink)); 642 dbg_readinode("ino #%u nlink is %d\n", f->inocache->ino, f->inocache->nlink);
513 643
514 /* Grab all nodes relevant to this ino */ 644 /* Grab all nodes relevant to this ino */
515 ret = jffs2_get_inode_nodes(c, f, &tn_list, &fd_list, &f->highest_version, &latest_mctime, &mctime_ver); 645 ret = jffs2_get_inode_nodes(c, f, &tn_list, &fd_list, &f->highest_version, &latest_mctime, &mctime_ver);
516 646
517 if (ret) { 647 if (ret) {
518 printk(KERN_CRIT "jffs2_get_inode_nodes() for ino %u returned %d\n", f->inocache->ino, ret); 648 JFFS2_ERROR("cannot read nodes for ino %u, returned error is %d\n", f->inocache->ino, ret);
519 if (f->inocache->state == INO_STATE_READING) 649 if (f->inocache->state == INO_STATE_READING)
520 jffs2_set_inocache_state(c, f->inocache, INO_STATE_CHECKEDABSENT); 650 jffs2_set_inocache_state(c, f->inocache, INO_STATE_CHECKEDABSENT);
521 return ret; 651 return ret;
@@ -525,42 +655,33 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
525 rb = rb_first(&tn_list); 655 rb = rb_first(&tn_list);
526 656
527 while (rb) { 657 while (rb) {
658 cond_resched();
528 tn = rb_entry(rb, struct jffs2_tmp_dnode_info, rb); 659 tn = rb_entry(rb, struct jffs2_tmp_dnode_info, rb);
529 fn = tn->fn; 660 fn = tn->fn;
530 661 ret = 1;
531 if (f->metadata) { 662 dbg_readinode("consider node ver %u, phys offset "
532 if (likely(tn->version >= mdata_ver)) { 663 "%#08x(%d), range %u-%u.\n", tn->version,
533 D1(printk(KERN_DEBUG "Obsoleting old metadata at 0x%08x\n", ref_offset(f->metadata->raw))); 664 ref_offset(fn->raw), ref_flags(fn->raw),
534 jffs2_mark_node_obsolete(c, f->metadata->raw); 665 fn->ofs, fn->ofs + fn->size);
535 jffs2_free_full_dnode(f->metadata);
536 f->metadata = NULL;
537
538 mdata_ver = 0;
539 } else {
540 /* This should never happen. */
541 printk(KERN_WARNING "Er. New metadata at 0x%08x with ver %d is actually older than previous ver %d at 0x%08x\n",
542 ref_offset(fn->raw), tn->version, mdata_ver, ref_offset(f->metadata->raw));
543 jffs2_mark_node_obsolete(c, fn->raw);
544 jffs2_free_full_dnode(fn);
545 /* Fill in latest_node from the metadata, not this one we're about to free... */
546 fn = f->metadata;
547 goto next_tn;
548 }
549 }
550 666
551 if (fn->size) { 667 if (fn->size) {
552 jffs2_add_full_dnode_to_inode(c, f, fn); 668 ret = jffs2_add_older_frag_to_fragtree(c, f, tn);
553 } else { 669 /* TODO: the error code isn't checked, check it */
554 /* Zero-sized node at end of version list. Just a metadata update */ 670 jffs2_dbg_fragtree_paranoia_check_nolock(f);
555 D1(printk(KERN_DEBUG "metadata @%08x: ver %d\n", ref_offset(fn->raw), tn->version)); 671 BUG_ON(ret < 0);
672 if (!first_fn && ret == 0)
673 first_fn = fn;
674 } else if (!first_fn) {
675 first_fn = fn;
556 f->metadata = fn; 676 f->metadata = fn;
557 mdata_ver = tn->version; 677 ret = 0; /* Prevent freeing the metadata update node */
558 } 678 } else
559 next_tn: 679 jffs2_mark_node_obsolete(c, fn->raw);
680
560 BUG_ON(rb->rb_left); 681 BUG_ON(rb->rb_left);
561 if (rb->rb_parent && rb->rb_parent->rb_left == rb) { 682 if (rb->rb_parent && rb->rb_parent->rb_left == rb) {
562 /* We were then left-hand child of our parent. We need 683 /* We were then left-hand child of our parent. We need
563 to move our own right-hand child into our place. */ 684 * to move our own right-hand child into our place. */
564 repl_rb = rb->rb_right; 685 repl_rb = rb->rb_right;
565 if (repl_rb) 686 if (repl_rb)
566 repl_rb->rb_parent = rb->rb_parent; 687 repl_rb->rb_parent = rb->rb_parent;
@@ -570,7 +691,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
570 rb = rb_next(rb); 691 rb = rb_next(rb);
571 692
572 /* Remove the spent tn from the tree; don't bother rebalancing 693 /* Remove the spent tn from the tree; don't bother rebalancing
573 but put our right-hand child in our own place. */ 694 * but put our right-hand child in our own place. */
574 if (tn->rb.rb_parent) { 695 if (tn->rb.rb_parent) {
575 if (tn->rb.rb_parent->rb_left == &tn->rb) 696 if (tn->rb.rb_parent->rb_left == &tn->rb)
576 tn->rb.rb_parent->rb_left = repl_rb; 697 tn->rb.rb_parent->rb_left = repl_rb;
@@ -581,19 +702,27 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
581 tn->rb.rb_right->rb_parent = NULL; 702 tn->rb.rb_right->rb_parent = NULL;
582 703
583 jffs2_free_tmp_dnode_info(tn); 704 jffs2_free_tmp_dnode_info(tn);
705 if (ret) {
706 dbg_readinode("delete dnode %u-%u.\n",
707 fn->ofs, fn->ofs + fn->size);
708 jffs2_free_full_dnode(fn);
709 }
584 } 710 }
585 D1(jffs2_sanitycheck_fragtree(f)); 711 jffs2_dbg_fragtree_paranoia_check_nolock(f);
586 712
587 if (!fn) { 713 BUG_ON(first_fn && ref_obsolete(first_fn->raw));
714
715 fn = first_fn;
716 if (unlikely(!first_fn)) {
588 /* No data nodes for this inode. */ 717 /* No data nodes for this inode. */
589 if (f->inocache->ino != 1) { 718 if (f->inocache->ino != 1) {
590 printk(KERN_WARNING "jffs2_do_read_inode(): No data nodes found for ino #%u\n", f->inocache->ino); 719 JFFS2_WARNING("no data nodes found for ino #%u\n", f->inocache->ino);
591 if (!fd_list) { 720 if (!fd_list) {
592 if (f->inocache->state == INO_STATE_READING) 721 if (f->inocache->state == INO_STATE_READING)
593 jffs2_set_inocache_state(c, f->inocache, INO_STATE_CHECKEDABSENT); 722 jffs2_set_inocache_state(c, f->inocache, INO_STATE_CHECKEDABSENT);
594 return -EIO; 723 return -EIO;
595 } 724 }
596 printk(KERN_WARNING "jffs2_do_read_inode(): But it has children so we fake some modes for it\n"); 725 JFFS2_NOTICE("but it has children so we fake some modes for it\n");
597 } 726 }
598 latest_node->mode = cpu_to_jemode(S_IFDIR|S_IRUGO|S_IWUSR|S_IXUGO); 727 latest_node->mode = cpu_to_jemode(S_IFDIR|S_IRUGO|S_IWUSR|S_IXUGO);
599 latest_node->version = cpu_to_je32(0); 728 latest_node->version = cpu_to_je32(0);
@@ -608,8 +737,8 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
608 737
609 ret = jffs2_flash_read(c, ref_offset(fn->raw), sizeof(*latest_node), &retlen, (void *)latest_node); 738 ret = jffs2_flash_read(c, ref_offset(fn->raw), sizeof(*latest_node), &retlen, (void *)latest_node);
610 if (ret || retlen != sizeof(*latest_node)) { 739 if (ret || retlen != sizeof(*latest_node)) {
611 printk(KERN_NOTICE "MTD read in jffs2_do_read_inode() failed: Returned %d, %zd of %zd bytes read\n", 740 JFFS2_ERROR("failed to read from flash: error %d, %zd of %zd bytes read\n",
612 ret, retlen, sizeof(*latest_node)); 741 ret, retlen, sizeof(*latest_node));
613 /* FIXME: If this fails, there seems to be a memory leak. Find it. */ 742 /* FIXME: If this fails, there seems to be a memory leak. Find it. */
614 up(&f->sem); 743 up(&f->sem);
615 jffs2_do_clear_inode(c, f); 744 jffs2_do_clear_inode(c, f);
@@ -618,7 +747,8 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
618 747
619 crc = crc32(0, latest_node, sizeof(*latest_node)-8); 748 crc = crc32(0, latest_node, sizeof(*latest_node)-8);
620 if (crc != je32_to_cpu(latest_node->node_crc)) { 749 if (crc != je32_to_cpu(latest_node->node_crc)) {
621 printk(KERN_NOTICE "CRC failed for read_inode of inode %u at physical location 0x%x\n", f->inocache->ino, ref_offset(fn->raw)); 750 JFFS2_ERROR("CRC failed for read_inode of inode %u at physical location 0x%x\n",
751 f->inocache->ino, ref_offset(fn->raw));
622 up(&f->sem); 752 up(&f->sem);
623 jffs2_do_clear_inode(c, f); 753 jffs2_do_clear_inode(c, f);
624 return -EIO; 754 return -EIO;
@@ -633,10 +763,10 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
633 } 763 }
634 break; 764 break;
635 765
636 766
637 case S_IFREG: 767 case S_IFREG:
638 /* If it was a regular file, truncate it to the latest node's isize */ 768 /* If it was a regular file, truncate it to the latest node's isize */
639 jffs2_truncate_fraglist(c, &f->fragtree, je32_to_cpu(latest_node->isize)); 769 jffs2_truncate_fragtree(c, &f->fragtree, je32_to_cpu(latest_node->isize));
640 break; 770 break;
641 771
642 case S_IFLNK: 772 case S_IFLNK:
@@ -649,37 +779,33 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
649 779
650 if (f->inocache->state != INO_STATE_CHECKING) { 780 if (f->inocache->state != INO_STATE_CHECKING) {
651 /* Symlink's inode data is the target path. Read it and 781 /* Symlink's inode data is the target path. Read it and
652 * keep in RAM to facilitate quick follow symlink operation. 782 * keep in RAM to facilitate quick follow symlink
653 * We use f->dents field to store the target path, which 783 * operation. */
654 * is somewhat ugly. */ 784 f->target = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL);
655 f->dents = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL); 785 if (!f->target) {
656 if (!f->dents) { 786 JFFS2_ERROR("can't allocate %d bytes of memory for the symlink target path cache\n", je32_to_cpu(latest_node->csize));
657 printk(KERN_WARNING "Can't allocate %d bytes of memory "
658 "for the symlink target path cache\n",
659 je32_to_cpu(latest_node->csize));
660 up(&f->sem); 787 up(&f->sem);
661 jffs2_do_clear_inode(c, f); 788 jffs2_do_clear_inode(c, f);
662 return -ENOMEM; 789 return -ENOMEM;
663 } 790 }
664 791
665 ret = jffs2_flash_read(c, ref_offset(fn->raw) + sizeof(*latest_node), 792 ret = jffs2_flash_read(c, ref_offset(fn->raw) + sizeof(*latest_node),
666 je32_to_cpu(latest_node->csize), &retlen, (char *)f->dents); 793 je32_to_cpu(latest_node->csize), &retlen, (char *)f->target);
667 794
668 if (ret || retlen != je32_to_cpu(latest_node->csize)) { 795 if (ret || retlen != je32_to_cpu(latest_node->csize)) {
669 if (retlen != je32_to_cpu(latest_node->csize)) 796 if (retlen != je32_to_cpu(latest_node->csize))
670 ret = -EIO; 797 ret = -EIO;
671 kfree(f->dents); 798 kfree(f->target);
672 f->dents = NULL; 799 f->target = NULL;
673 up(&f->sem); 800 up(&f->sem);
674 jffs2_do_clear_inode(c, f); 801 jffs2_do_clear_inode(c, f);
675 return -ret; 802 return -ret;
676 } 803 }
677 804
678 ((char *)f->dents)[je32_to_cpu(latest_node->csize)] = '\0'; 805 f->target[je32_to_cpu(latest_node->csize)] = '\0';
679 D1(printk(KERN_DEBUG "jffs2_do_read_inode(): symlink's target '%s' cached\n", 806 dbg_readinode("symlink's target '%s' cached\n", f->target);
680 (char *)f->dents));
681 } 807 }
682 808
683 /* fall through... */ 809 /* fall through... */
684 810
685 case S_IFBLK: 811 case S_IFBLK:
@@ -687,14 +813,14 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
687 /* Certain inode types should have only one data node, and it's 813 /* Certain inode types should have only one data node, and it's
688 kept as the metadata node */ 814 kept as the metadata node */
689 if (f->metadata) { 815 if (f->metadata) {
690 printk(KERN_WARNING "Argh. Special inode #%u with mode 0%o had metadata node\n", 816 JFFS2_ERROR("Argh. Special inode #%u with mode 0%o had metadata node\n",
691 f->inocache->ino, jemode_to_cpu(latest_node->mode)); 817 f->inocache->ino, jemode_to_cpu(latest_node->mode));
692 up(&f->sem); 818 up(&f->sem);
693 jffs2_do_clear_inode(c, f); 819 jffs2_do_clear_inode(c, f);
694 return -EIO; 820 return -EIO;
695 } 821 }
696 if (!frag_first(&f->fragtree)) { 822 if (!frag_first(&f->fragtree)) {
697 printk(KERN_WARNING "Argh. Special inode #%u with mode 0%o has no fragments\n", 823 JFFS2_ERROR("Argh. Special inode #%u with mode 0%o has no fragments\n",
698 f->inocache->ino, jemode_to_cpu(latest_node->mode)); 824 f->inocache->ino, jemode_to_cpu(latest_node->mode));
699 up(&f->sem); 825 up(&f->sem);
700 jffs2_do_clear_inode(c, f); 826 jffs2_do_clear_inode(c, f);
@@ -702,7 +828,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
702 } 828 }
703 /* ASSERT: f->fraglist != NULL */ 829 /* ASSERT: f->fraglist != NULL */
704 if (frag_next(frag_first(&f->fragtree))) { 830 if (frag_next(frag_first(&f->fragtree))) {
705 printk(KERN_WARNING "Argh. Special inode #%u with mode 0x%x had more than one node\n", 831 JFFS2_ERROR("Argh. Special inode #%u with mode 0x%x had more than one node\n",
706 f->inocache->ino, jemode_to_cpu(latest_node->mode)); 832 f->inocache->ino, jemode_to_cpu(latest_node->mode));
707 /* FIXME: Deal with it - check crc32, check for duplicate node, check times and discard the older one */ 833 /* FIXME: Deal with it - check crc32, check for duplicate node, check times and discard the older one */
708 up(&f->sem); 834 up(&f->sem);
@@ -721,6 +847,93 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
721 return 0; 847 return 0;
722} 848}
723 849
850/* Scan the list of all nodes present for this ino, build map of versions, etc. */
851int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
852 uint32_t ino, struct jffs2_raw_inode *latest_node)
853{
854 dbg_readinode("read inode #%u\n", ino);
855
856 retry_inocache:
857 spin_lock(&c->inocache_lock);
858 f->inocache = jffs2_get_ino_cache(c, ino);
859
860 if (f->inocache) {
861 /* Check its state. We may need to wait before we can use it */
862 switch(f->inocache->state) {
863 case INO_STATE_UNCHECKED:
864 case INO_STATE_CHECKEDABSENT:
865 f->inocache->state = INO_STATE_READING;
866 break;
867
868 case INO_STATE_CHECKING:
869 case INO_STATE_GC:
870 /* If it's in either of these states, we need
871 to wait for whoever's got it to finish and
872 put it back. */
873 dbg_readinode("waiting for ino #%u in state %d\n", ino, f->inocache->state);
874 sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock);
875 goto retry_inocache;
876
877 case INO_STATE_READING:
878 case INO_STATE_PRESENT:
879 /* Eep. This should never happen. It can
880 happen if Linux calls read_inode() again
881 before clear_inode() has finished though. */
882 JFFS2_ERROR("Eep. Trying to read_inode #%u when it's already in state %d!\n", ino, f->inocache->state);
883 /* Fail. That's probably better than allowing it to succeed */
884 f->inocache = NULL;
885 break;
886
887 default:
888 BUG();
889 }
890 }
891 spin_unlock(&c->inocache_lock);
892
893 if (!f->inocache && ino == 1) {
894 /* Special case - no root inode on medium */
895 f->inocache = jffs2_alloc_inode_cache();
896 if (!f->inocache) {
897 JFFS2_ERROR("cannot allocate inocache for root inode\n");
898 return -ENOMEM;
899 }
900 dbg_readinode("creating inocache for root inode\n");
901 memset(f->inocache, 0, sizeof(struct jffs2_inode_cache));
902 f->inocache->ino = f->inocache->nlink = 1;
903 f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache;
904 f->inocache->state = INO_STATE_READING;
905 jffs2_add_ino_cache(c, f->inocache);
906 }
907 if (!f->inocache) {
908 JFFS2_ERROR("requestied to read an nonexistent ino %u\n", ino);
909 return -ENOENT;
910 }
911
912 return jffs2_do_read_inode_internal(c, f, latest_node);
913}
914
915int jffs2_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic)
916{
917 struct jffs2_raw_inode n;
918 struct jffs2_inode_info *f = kmalloc(sizeof(*f), GFP_KERNEL);
919 int ret;
920
921 if (!f)
922 return -ENOMEM;
923
924 memset(f, 0, sizeof(*f));
925 init_MUTEX_LOCKED(&f->sem);
926 f->inocache = ic;
927
928 ret = jffs2_do_read_inode_internal(c, f, &n);
929 if (!ret) {
930 up(&f->sem);
931 jffs2_do_clear_inode(c, f);
932 }
933 kfree (f);
934 return ret;
935}
936
724void jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f) 937void jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f)
725{ 938{
726 struct jffs2_full_dirent *fd, *fds; 939 struct jffs2_full_dirent *fd, *fds;
@@ -740,20 +953,16 @@ void jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f)
740 953
741 jffs2_kill_fragtree(&f->fragtree, deleted?c:NULL); 954 jffs2_kill_fragtree(&f->fragtree, deleted?c:NULL);
742 955
743 /* For symlink inodes we us f->dents to store the target path name */ 956 if (f->target) {
744 if (S_ISLNK(OFNI_EDONI_2SFFJ(f)->i_mode)) { 957 kfree(f->target);
745 if (f->dents) { 958 f->target = NULL;
746 kfree(f->dents); 959 }
747 f->dents = NULL;
748 }
749 } else {
750 fds = f->dents;
751 960
752 while(fds) { 961 fds = f->dents;
753 fd = fds; 962 while(fds) {
754 fds = fd->next; 963 fd = fds;
755 jffs2_free_full_dirent(fd); 964 fds = fd->next;
756 } 965 jffs2_free_full_dirent(fd);
757 } 966 }
758 967
759 if (f->inocache && f->inocache->state != INO_STATE_CHECKING) { 968 if (f->inocache && f->inocache->state != INO_STATE_CHECKING) {
diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c
index b63160f83bab..0e7456ec99fd 100644
--- a/fs/jffs2/scan.c
+++ b/fs/jffs2/scan.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: scan.c,v 1.119 2005/02/17 17:51:13 dedekind Exp $ 10 * $Id: scan.c,v 1.125 2005/09/30 13:59:13 dedekind Exp $
11 * 11 *
12 */ 12 */
13#include <linux/kernel.h> 13#include <linux/kernel.h>
@@ -18,22 +18,11 @@
18#include <linux/crc32.h> 18#include <linux/crc32.h>
19#include <linux/compiler.h> 19#include <linux/compiler.h>
20#include "nodelist.h" 20#include "nodelist.h"
21#include "summary.h"
22#include "debug.h"
21 23
22#define DEFAULT_EMPTY_SCAN_SIZE 1024 24#define DEFAULT_EMPTY_SCAN_SIZE 1024
23 25
24#define DIRTY_SPACE(x) do { typeof(x) _x = (x); \
25 c->free_size -= _x; c->dirty_size += _x; \
26 jeb->free_size -= _x ; jeb->dirty_size += _x; \
27 }while(0)
28#define USED_SPACE(x) do { typeof(x) _x = (x); \
29 c->free_size -= _x; c->used_size += _x; \
30 jeb->free_size -= _x ; jeb->used_size += _x; \
31 }while(0)
32#define UNCHECKED_SPACE(x) do { typeof(x) _x = (x); \
33 c->free_size -= _x; c->unchecked_size += _x; \
34 jeb->free_size -= _x ; jeb->unchecked_size += _x; \
35 }while(0)
36
37#define noisy_printk(noise, args...) do { \ 26#define noisy_printk(noise, args...) do { \
38 if (*(noise)) { \ 27 if (*(noise)) { \
39 printk(KERN_NOTICE args); \ 28 printk(KERN_NOTICE args); \
@@ -47,23 +36,16 @@
47static uint32_t pseudo_random; 36static uint32_t pseudo_random;
48 37
49static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 38static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
50 unsigned char *buf, uint32_t buf_size); 39 unsigned char *buf, uint32_t buf_size, struct jffs2_summary *s);
51 40
52/* These helper functions _must_ increase ofs and also do the dirty/used space accounting. 41/* These helper functions _must_ increase ofs and also do the dirty/used space accounting.
53 * Returning an error will abort the mount - bad checksums etc. should just mark the space 42 * Returning an error will abort the mount - bad checksums etc. should just mark the space
54 * as dirty. 43 * as dirty.
55 */ 44 */
56static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 45static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
57 struct jffs2_raw_inode *ri, uint32_t ofs); 46 struct jffs2_raw_inode *ri, uint32_t ofs, struct jffs2_summary *s);
58static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 47static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
59 struct jffs2_raw_dirent *rd, uint32_t ofs); 48 struct jffs2_raw_dirent *rd, uint32_t ofs, struct jffs2_summary *s);
60
61#define BLK_STATE_ALLFF 0
62#define BLK_STATE_CLEAN 1
63#define BLK_STATE_PARTDIRTY 2
64#define BLK_STATE_CLEANMARKER 3
65#define BLK_STATE_ALLDIRTY 4
66#define BLK_STATE_BADBLOCK 5
67 49
68static inline int min_free(struct jffs2_sb_info *c) 50static inline int min_free(struct jffs2_sb_info *c)
69{ 51{
@@ -89,6 +71,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
89 uint32_t empty_blocks = 0, bad_blocks = 0; 71 uint32_t empty_blocks = 0, bad_blocks = 0;
90 unsigned char *flashbuf = NULL; 72 unsigned char *flashbuf = NULL;
91 uint32_t buf_size = 0; 73 uint32_t buf_size = 0;
74 struct jffs2_summary *s = NULL; /* summary info collected by the scan process */
92#ifndef __ECOS 75#ifndef __ECOS
93 size_t pointlen; 76 size_t pointlen;
94 77
@@ -122,21 +105,34 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
122 return -ENOMEM; 105 return -ENOMEM;
123 } 106 }
124 107
108 if (jffs2_sum_active()) {
109 s = kmalloc(sizeof(struct jffs2_summary), GFP_KERNEL);
110 if (!s) {
111 JFFS2_WARNING("Can't allocate memory for summary\n");
112 return -ENOMEM;
113 }
114 memset(s, 0, sizeof(struct jffs2_summary));
115 }
116
125 for (i=0; i<c->nr_blocks; i++) { 117 for (i=0; i<c->nr_blocks; i++) {
126 struct jffs2_eraseblock *jeb = &c->blocks[i]; 118 struct jffs2_eraseblock *jeb = &c->blocks[i];
127 119
128 ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset), buf_size); 120 /* reset summary info for next eraseblock scan */
121 jffs2_sum_reset_collected(s);
122
123 ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
124 buf_size, s);
129 125
130 if (ret < 0) 126 if (ret < 0)
131 goto out; 127 goto out;
132 128
133 ACCT_PARANOIA_CHECK(jeb); 129 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
134 130
135 /* Now decide which list to put it on */ 131 /* Now decide which list to put it on */
136 switch(ret) { 132 switch(ret) {
137 case BLK_STATE_ALLFF: 133 case BLK_STATE_ALLFF:
138 /* 134 /*
139 * Empty block. Since we can't be sure it 135 * Empty block. Since we can't be sure it
140 * was entirely erased, we just queue it for erase 136 * was entirely erased, we just queue it for erase
141 * again. It will be marked as such when the erase 137 * again. It will be marked as such when the erase
142 * is complete. Meanwhile we still count it as empty 138 * is complete. Meanwhile we still count it as empty
@@ -162,18 +158,18 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
162 break; 158 break;
163 159
164 case BLK_STATE_CLEAN: 160 case BLK_STATE_CLEAN:
165 /* Full (or almost full) of clean data. Clean list */ 161 /* Full (or almost full) of clean data. Clean list */
166 list_add(&jeb->list, &c->clean_list); 162 list_add(&jeb->list, &c->clean_list);
167 break; 163 break;
168 164
169 case BLK_STATE_PARTDIRTY: 165 case BLK_STATE_PARTDIRTY:
170 /* Some data, but not full. Dirty list. */ 166 /* Some data, but not full. Dirty list. */
171 /* We want to remember the block with most free space 167 /* We want to remember the block with most free space
172 and stick it in the 'nextblock' position to start writing to it. */ 168 and stick it in the 'nextblock' position to start writing to it. */
173 if (jeb->free_size > min_free(c) && 169 if (jeb->free_size > min_free(c) &&
174 (!c->nextblock || c->nextblock->free_size < jeb->free_size)) { 170 (!c->nextblock || c->nextblock->free_size < jeb->free_size)) {
175 /* Better candidate for the next writes to go to */ 171 /* Better candidate for the next writes to go to */
176 if (c->nextblock) { 172 if (c->nextblock) {
177 c->nextblock->dirty_size += c->nextblock->free_size + c->nextblock->wasted_size; 173 c->nextblock->dirty_size += c->nextblock->free_size + c->nextblock->wasted_size;
178 c->dirty_size += c->nextblock->free_size + c->nextblock->wasted_size; 174 c->dirty_size += c->nextblock->free_size + c->nextblock->wasted_size;
179 c->free_size -= c->nextblock->free_size; 175 c->free_size -= c->nextblock->free_size;
@@ -184,9 +180,14 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
184 } else { 180 } else {
185 list_add(&c->nextblock->list, &c->dirty_list); 181 list_add(&c->nextblock->list, &c->dirty_list);
186 } 182 }
183 /* deleting summary information of the old nextblock */
184 jffs2_sum_reset_collected(c->summary);
187 } 185 }
188 c->nextblock = jeb; 186 /* update collected summary infromation for the current nextblock */
189 } else { 187 jffs2_sum_move_collected(c, s);
188 D1(printk(KERN_DEBUG "jffs2_scan_medium(): new nextblock = 0x%08x\n", jeb->offset));
189 c->nextblock = jeb;
190 } else {
190 jeb->dirty_size += jeb->free_size + jeb->wasted_size; 191 jeb->dirty_size += jeb->free_size + jeb->wasted_size;
191 c->dirty_size += jeb->free_size + jeb->wasted_size; 192 c->dirty_size += jeb->free_size + jeb->wasted_size;
192 c->free_size -= jeb->free_size; 193 c->free_size -= jeb->free_size;
@@ -197,30 +198,33 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
197 } else { 198 } else {
198 list_add(&jeb->list, &c->dirty_list); 199 list_add(&jeb->list, &c->dirty_list);
199 } 200 }
200 } 201 }
201 break; 202 break;
202 203
203 case BLK_STATE_ALLDIRTY: 204 case BLK_STATE_ALLDIRTY:
204 /* Nothing valid - not even a clean marker. Needs erasing. */ 205 /* Nothing valid - not even a clean marker. Needs erasing. */
205 /* For now we just put it on the erasing list. We'll start the erases later */ 206 /* For now we just put it on the erasing list. We'll start the erases later */
206 D1(printk(KERN_NOTICE "JFFS2: Erase block at 0x%08x is not formatted. It will be erased\n", jeb->offset)); 207 D1(printk(KERN_NOTICE "JFFS2: Erase block at 0x%08x is not formatted. It will be erased\n", jeb->offset));
207 list_add(&jeb->list, &c->erase_pending_list); 208 list_add(&jeb->list, &c->erase_pending_list);
208 c->nr_erasing_blocks++; 209 c->nr_erasing_blocks++;
209 break; 210 break;
210 211
211 case BLK_STATE_BADBLOCK: 212 case BLK_STATE_BADBLOCK:
212 D1(printk(KERN_NOTICE "JFFS2: Block at 0x%08x is bad\n", jeb->offset)); 213 D1(printk(KERN_NOTICE "JFFS2: Block at 0x%08x is bad\n", jeb->offset));
213 list_add(&jeb->list, &c->bad_list); 214 list_add(&jeb->list, &c->bad_list);
214 c->bad_size += c->sector_size; 215 c->bad_size += c->sector_size;
215 c->free_size -= c->sector_size; 216 c->free_size -= c->sector_size;
216 bad_blocks++; 217 bad_blocks++;
217 break; 218 break;
218 default: 219 default:
219 printk(KERN_WARNING "jffs2_scan_medium(): unknown block state\n"); 220 printk(KERN_WARNING "jffs2_scan_medium(): unknown block state\n");
220 BUG(); 221 BUG();
221 } 222 }
222 } 223 }
223 224
225 if (jffs2_sum_active() && s)
226 kfree(s);
227
224 /* Nextblock dirty is always seen as wasted, because we cannot recycle it now */ 228 /* Nextblock dirty is always seen as wasted, because we cannot recycle it now */
225 if (c->nextblock && (c->nextblock->dirty_size)) { 229 if (c->nextblock && (c->nextblock->dirty_size)) {
226 c->nextblock->wasted_size += c->nextblock->dirty_size; 230 c->nextblock->wasted_size += c->nextblock->dirty_size;
@@ -229,12 +233,12 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
229 c->nextblock->dirty_size = 0; 233 c->nextblock->dirty_size = 0;
230 } 234 }
231#ifdef CONFIG_JFFS2_FS_WRITEBUFFER 235#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
232 if (!jffs2_can_mark_obsolete(c) && c->nextblock && (c->nextblock->free_size & (c->wbuf_pagesize-1))) { 236 if (!jffs2_can_mark_obsolete(c) && c->nextblock && (c->nextblock->free_size % c->wbuf_pagesize)) {
233 /* If we're going to start writing into a block which already 237 /* If we're going to start writing into a block which already
234 contains data, and the end of the data isn't page-aligned, 238 contains data, and the end of the data isn't page-aligned,
235 skip a little and align it. */ 239 skip a little and align it. */
236 240
237 uint32_t skip = c->nextblock->free_size & (c->wbuf_pagesize-1); 241 uint32_t skip = c->nextblock->free_size % c->wbuf_pagesize;
238 242
239 D1(printk(KERN_DEBUG "jffs2_scan_medium(): Skipping %d bytes in nextblock to ensure page alignment\n", 243 D1(printk(KERN_DEBUG "jffs2_scan_medium(): Skipping %d bytes in nextblock to ensure page alignment\n",
240 skip)); 244 skip));
@@ -246,7 +250,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
246 } 250 }
247#endif 251#endif
248 if (c->nr_erasing_blocks) { 252 if (c->nr_erasing_blocks) {
249 if ( !c->used_size && ((c->nr_free_blocks+empty_blocks+bad_blocks)!= c->nr_blocks || bad_blocks == c->nr_blocks) ) { 253 if ( !c->used_size && ((c->nr_free_blocks+empty_blocks+bad_blocks)!= c->nr_blocks || bad_blocks == c->nr_blocks) ) {
250 printk(KERN_NOTICE "Cowardly refusing to erase blocks on filesystem with no valid JFFS2 nodes\n"); 254 printk(KERN_NOTICE "Cowardly refusing to erase blocks on filesystem with no valid JFFS2 nodes\n");
251 printk(KERN_NOTICE "empty_blocks %d, bad_blocks %d, c->nr_blocks %d\n",empty_blocks,bad_blocks,c->nr_blocks); 255 printk(KERN_NOTICE "empty_blocks %d, bad_blocks %d, c->nr_blocks %d\n",empty_blocks,bad_blocks,c->nr_blocks);
252 ret = -EIO; 256 ret = -EIO;
@@ -259,13 +263,13 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
259 if (buf_size) 263 if (buf_size)
260 kfree(flashbuf); 264 kfree(flashbuf);
261#ifndef __ECOS 265#ifndef __ECOS
262 else 266 else
263 c->mtd->unpoint(c->mtd, flashbuf, 0, c->mtd->size); 267 c->mtd->unpoint(c->mtd, flashbuf, 0, c->mtd->size);
264#endif 268#endif
265 return ret; 269 return ret;
266} 270}
267 271
268static int jffs2_fill_scan_buf (struct jffs2_sb_info *c, unsigned char *buf, 272int jffs2_fill_scan_buf (struct jffs2_sb_info *c, void *buf,
269 uint32_t ofs, uint32_t len) 273 uint32_t ofs, uint32_t len)
270{ 274{
271 int ret; 275 int ret;
@@ -286,14 +290,36 @@ static int jffs2_fill_scan_buf (struct jffs2_sb_info *c, unsigned char *buf,
286 return 0; 290 return 0;
287} 291}
288 292
293int jffs2_scan_classify_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
294{
295 if ((jeb->used_size + jeb->unchecked_size) == PAD(c->cleanmarker_size) && !jeb->dirty_size
296 && (!jeb->first_node || !jeb->first_node->next_phys) )
297 return BLK_STATE_CLEANMARKER;
298
299 /* move blocks with max 4 byte dirty space to cleanlist */
300 else if (!ISDIRTY(c->sector_size - (jeb->used_size + jeb->unchecked_size))) {
301 c->dirty_size -= jeb->dirty_size;
302 c->wasted_size += jeb->dirty_size;
303 jeb->wasted_size += jeb->dirty_size;
304 jeb->dirty_size = 0;
305 return BLK_STATE_CLEAN;
306 } else if (jeb->used_size || jeb->unchecked_size)
307 return BLK_STATE_PARTDIRTY;
308 else
309 return BLK_STATE_ALLDIRTY;
310}
311
289static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 312static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
290 unsigned char *buf, uint32_t buf_size) { 313 unsigned char *buf, uint32_t buf_size, struct jffs2_summary *s) {
291 struct jffs2_unknown_node *node; 314 struct jffs2_unknown_node *node;
292 struct jffs2_unknown_node crcnode; 315 struct jffs2_unknown_node crcnode;
316 struct jffs2_sum_marker *sm;
293 uint32_t ofs, prevofs; 317 uint32_t ofs, prevofs;
294 uint32_t hdr_crc, buf_ofs, buf_len; 318 uint32_t hdr_crc, buf_ofs, buf_len;
295 int err; 319 int err;
296 int noise = 0; 320 int noise = 0;
321
322
297#ifdef CONFIG_JFFS2_FS_WRITEBUFFER 323#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
298 int cleanmarkerfound = 0; 324 int cleanmarkerfound = 0;
299#endif 325#endif
@@ -319,17 +345,53 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
319 } 345 }
320 } 346 }
321#endif 347#endif
348
349 if (jffs2_sum_active()) {
350 sm = kmalloc(sizeof(struct jffs2_sum_marker), GFP_KERNEL);
351 if (!sm) {
352 return -ENOMEM;
353 }
354
355 err = jffs2_fill_scan_buf(c, (unsigned char *) sm, jeb->offset + c->sector_size -
356 sizeof(struct jffs2_sum_marker), sizeof(struct jffs2_sum_marker));
357 if (err) {
358 kfree(sm);
359 return err;
360 }
361
362 if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC ) {
363 err = jffs2_sum_scan_sumnode(c, jeb, je32_to_cpu(sm->offset), &pseudo_random);
364 if (err) {
365 kfree(sm);
366 return err;
367 }
368 }
369
370 kfree(sm);
371
372 ofs = jeb->offset;
373 prevofs = jeb->offset - 1;
374 }
375
322 buf_ofs = jeb->offset; 376 buf_ofs = jeb->offset;
323 377
324 if (!buf_size) { 378 if (!buf_size) {
325 buf_len = c->sector_size; 379 buf_len = c->sector_size;
380
381 if (jffs2_sum_active()) {
382 /* must reread because of summary test */
383 err = jffs2_fill_scan_buf(c, buf, buf_ofs, buf_len);
384 if (err)
385 return err;
386 }
387
326 } else { 388 } else {
327 buf_len = EMPTY_SCAN_SIZE(c->sector_size); 389 buf_len = EMPTY_SCAN_SIZE(c->sector_size);
328 err = jffs2_fill_scan_buf(c, buf, buf_ofs, buf_len); 390 err = jffs2_fill_scan_buf(c, buf, buf_ofs, buf_len);
329 if (err) 391 if (err)
330 return err; 392 return err;
331 } 393 }
332 394
333 /* We temporarily use 'ofs' as a pointer into the buffer/jeb */ 395 /* We temporarily use 'ofs' as a pointer into the buffer/jeb */
334 ofs = 0; 396 ofs = 0;
335 397
@@ -367,10 +429,12 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
367 429
368 noise = 10; 430 noise = 10;
369 431
370scan_more: 432 dbg_summary("no summary found in jeb 0x%08x. Apply original scan.\n",jeb->offset);
433
434scan_more:
371 while(ofs < jeb->offset + c->sector_size) { 435 while(ofs < jeb->offset + c->sector_size) {
372 436
373 D1(ACCT_PARANOIA_CHECK(jeb)); 437 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
374 438
375 cond_resched(); 439 cond_resched();
376 440
@@ -432,7 +496,7 @@ scan_more:
432 496
433 /* If we're only checking the beginning of a block with a cleanmarker, 497 /* If we're only checking the beginning of a block with a cleanmarker,
434 bail now */ 498 bail now */
435 if (buf_ofs == jeb->offset && jeb->used_size == PAD(c->cleanmarker_size) && 499 if (buf_ofs == jeb->offset && jeb->used_size == PAD(c->cleanmarker_size) &&
436 c->cleanmarker_size && !jeb->dirty_size && !jeb->first_node->next_phys) { 500 c->cleanmarker_size && !jeb->dirty_size && !jeb->first_node->next_phys) {
437 D1(printk(KERN_DEBUG "%d bytes at start of block seems clean... assuming all clean\n", EMPTY_SCAN_SIZE(c->sector_size))); 501 D1(printk(KERN_DEBUG "%d bytes at start of block seems clean... assuming all clean\n", EMPTY_SCAN_SIZE(c->sector_size)));
438 return BLK_STATE_CLEANMARKER; 502 return BLK_STATE_CLEANMARKER;
@@ -441,7 +505,7 @@ scan_more:
441 /* See how much more there is to read in this eraseblock... */ 505 /* See how much more there is to read in this eraseblock... */
442 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); 506 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs);
443 if (!buf_len) { 507 if (!buf_len) {
444 /* No more to read. Break out of main loop without marking 508 /* No more to read. Break out of main loop without marking
445 this range of empty space as dirty (because it's not) */ 509 this range of empty space as dirty (because it's not) */
446 D1(printk(KERN_DEBUG "Empty flash at %08x runs to end of block. Treating as free_space\n", 510 D1(printk(KERN_DEBUG "Empty flash at %08x runs to end of block. Treating as free_space\n",
447 empty_start)); 511 empty_start));
@@ -476,8 +540,8 @@ scan_more:
476 } 540 }
477 if (je16_to_cpu(node->magic) != JFFS2_MAGIC_BITMASK) { 541 if (je16_to_cpu(node->magic) != JFFS2_MAGIC_BITMASK) {
478 /* OK. We're out of possibilities. Whinge and move on */ 542 /* OK. We're out of possibilities. Whinge and move on */
479 noisy_printk(&noise, "jffs2_scan_eraseblock(): Magic bitmask 0x%04x not found at 0x%08x: 0x%04x instead\n", 543 noisy_printk(&noise, "jffs2_scan_eraseblock(): Magic bitmask 0x%04x not found at 0x%08x: 0x%04x instead\n",
480 JFFS2_MAGIC_BITMASK, ofs, 544 JFFS2_MAGIC_BITMASK, ofs,
481 je16_to_cpu(node->magic)); 545 je16_to_cpu(node->magic));
482 DIRTY_SPACE(4); 546 DIRTY_SPACE(4);
483 ofs += 4; 547 ofs += 4;
@@ -492,7 +556,7 @@ scan_more:
492 if (hdr_crc != je32_to_cpu(node->hdr_crc)) { 556 if (hdr_crc != je32_to_cpu(node->hdr_crc)) {
493 noisy_printk(&noise, "jffs2_scan_eraseblock(): Node at 0x%08x {0x%04x, 0x%04x, 0x%08x) has invalid CRC 0x%08x (calculated 0x%08x)\n", 557 noisy_printk(&noise, "jffs2_scan_eraseblock(): Node at 0x%08x {0x%04x, 0x%04x, 0x%08x) has invalid CRC 0x%08x (calculated 0x%08x)\n",
494 ofs, je16_to_cpu(node->magic), 558 ofs, je16_to_cpu(node->magic),
495 je16_to_cpu(node->nodetype), 559 je16_to_cpu(node->nodetype),
496 je32_to_cpu(node->totlen), 560 je32_to_cpu(node->totlen),
497 je32_to_cpu(node->hdr_crc), 561 je32_to_cpu(node->hdr_crc),
498 hdr_crc); 562 hdr_crc);
@@ -501,7 +565,7 @@ scan_more:
501 continue; 565 continue;
502 } 566 }
503 567
504 if (ofs + je32_to_cpu(node->totlen) > 568 if (ofs + je32_to_cpu(node->totlen) >
505 jeb->offset + c->sector_size) { 569 jeb->offset + c->sector_size) {
506 /* Eep. Node goes over the end of the erase block. */ 570 /* Eep. Node goes over the end of the erase block. */
507 printk(KERN_WARNING "Node at 0x%08x with length 0x%08x would run over the end of the erase block\n", 571 printk(KERN_WARNING "Node at 0x%08x with length 0x%08x would run over the end of the erase block\n",
@@ -532,11 +596,11 @@ scan_more:
532 buf_ofs = ofs; 596 buf_ofs = ofs;
533 node = (void *)buf; 597 node = (void *)buf;
534 } 598 }
535 err = jffs2_scan_inode_node(c, jeb, (void *)node, ofs); 599 err = jffs2_scan_inode_node(c, jeb, (void *)node, ofs, s);
536 if (err) return err; 600 if (err) return err;
537 ofs += PAD(je32_to_cpu(node->totlen)); 601 ofs += PAD(je32_to_cpu(node->totlen));
538 break; 602 break;
539 603
540 case JFFS2_NODETYPE_DIRENT: 604 case JFFS2_NODETYPE_DIRENT:
541 if (buf_ofs + buf_len < ofs + je32_to_cpu(node->totlen)) { 605 if (buf_ofs + buf_len < ofs + je32_to_cpu(node->totlen)) {
542 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); 606 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs);
@@ -548,7 +612,7 @@ scan_more:
548 buf_ofs = ofs; 612 buf_ofs = ofs;
549 node = (void *)buf; 613 node = (void *)buf;
550 } 614 }
551 err = jffs2_scan_dirent_node(c, jeb, (void *)node, ofs); 615 err = jffs2_scan_dirent_node(c, jeb, (void *)node, ofs, s);
552 if (err) return err; 616 if (err) return err;
553 ofs += PAD(je32_to_cpu(node->totlen)); 617 ofs += PAD(je32_to_cpu(node->totlen));
554 break; 618 break;
@@ -556,7 +620,7 @@ scan_more:
556 case JFFS2_NODETYPE_CLEANMARKER: 620 case JFFS2_NODETYPE_CLEANMARKER:
557 D1(printk(KERN_DEBUG "CLEANMARKER node found at 0x%08x\n", ofs)); 621 D1(printk(KERN_DEBUG "CLEANMARKER node found at 0x%08x\n", ofs));
558 if (je32_to_cpu(node->totlen) != c->cleanmarker_size) { 622 if (je32_to_cpu(node->totlen) != c->cleanmarker_size) {
559 printk(KERN_NOTICE "CLEANMARKER node found at 0x%08x has totlen 0x%x != normal 0x%x\n", 623 printk(KERN_NOTICE "CLEANMARKER node found at 0x%08x has totlen 0x%x != normal 0x%x\n",
560 ofs, je32_to_cpu(node->totlen), c->cleanmarker_size); 624 ofs, je32_to_cpu(node->totlen), c->cleanmarker_size);
561 DIRTY_SPACE(PAD(sizeof(struct jffs2_unknown_node))); 625 DIRTY_SPACE(PAD(sizeof(struct jffs2_unknown_node)));
562 ofs += PAD(sizeof(struct jffs2_unknown_node)); 626 ofs += PAD(sizeof(struct jffs2_unknown_node));
@@ -575,13 +639,15 @@ scan_more:
575 marker_ref->flash_offset = ofs | REF_NORMAL; 639 marker_ref->flash_offset = ofs | REF_NORMAL;
576 marker_ref->__totlen = c->cleanmarker_size; 640 marker_ref->__totlen = c->cleanmarker_size;
577 jeb->first_node = jeb->last_node = marker_ref; 641 jeb->first_node = jeb->last_node = marker_ref;
578 642
579 USED_SPACE(PAD(c->cleanmarker_size)); 643 USED_SPACE(PAD(c->cleanmarker_size));
580 ofs += PAD(c->cleanmarker_size); 644 ofs += PAD(c->cleanmarker_size);
581 } 645 }
582 break; 646 break;
583 647
584 case JFFS2_NODETYPE_PADDING: 648 case JFFS2_NODETYPE_PADDING:
649 if (jffs2_sum_active())
650 jffs2_sum_add_padding_mem(s, je32_to_cpu(node->totlen));
585 DIRTY_SPACE(PAD(je32_to_cpu(node->totlen))); 651 DIRTY_SPACE(PAD(je32_to_cpu(node->totlen)));
586 ofs += PAD(je32_to_cpu(node->totlen)); 652 ofs += PAD(je32_to_cpu(node->totlen));
587 break; 653 break;
@@ -616,8 +682,15 @@ scan_more:
616 } 682 }
617 } 683 }
618 684
685 if (jffs2_sum_active()) {
686 if (PAD(s->sum_size + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size) {
687 dbg_summary("There is not enough space for "
688 "summary information, disabling for this jeb!\n");
689 jffs2_sum_disable_collecting(s);
690 }
691 }
619 692
620 D1(printk(KERN_DEBUG "Block at 0x%08x: free 0x%08x, dirty 0x%08x, unchecked 0x%08x, used 0x%08x\n", jeb->offset, 693 D1(printk(KERN_DEBUG "Block at 0x%08x: free 0x%08x, dirty 0x%08x, unchecked 0x%08x, used 0x%08x\n", jeb->offset,
621 jeb->free_size, jeb->dirty_size, jeb->unchecked_size, jeb->used_size)); 694 jeb->free_size, jeb->dirty_size, jeb->unchecked_size, jeb->used_size));
622 695
623 /* mark_node_obsolete can add to wasted !! */ 696 /* mark_node_obsolete can add to wasted !! */
@@ -628,24 +701,10 @@ scan_more:
628 jeb->wasted_size = 0; 701 jeb->wasted_size = 0;
629 } 702 }
630 703
631 if ((jeb->used_size + jeb->unchecked_size) == PAD(c->cleanmarker_size) && !jeb->dirty_size 704 return jffs2_scan_classify_jeb(c, jeb);
632 && (!jeb->first_node || !jeb->first_node->next_phys) )
633 return BLK_STATE_CLEANMARKER;
634
635 /* move blocks with max 4 byte dirty space to cleanlist */
636 else if (!ISDIRTY(c->sector_size - (jeb->used_size + jeb->unchecked_size))) {
637 c->dirty_size -= jeb->dirty_size;
638 c->wasted_size += jeb->dirty_size;
639 jeb->wasted_size += jeb->dirty_size;
640 jeb->dirty_size = 0;
641 return BLK_STATE_CLEAN;
642 } else if (jeb->used_size || jeb->unchecked_size)
643 return BLK_STATE_PARTDIRTY;
644 else
645 return BLK_STATE_ALLDIRTY;
646} 705}
647 706
648static struct jffs2_inode_cache *jffs2_scan_make_ino_cache(struct jffs2_sb_info *c, uint32_t ino) 707struct jffs2_inode_cache *jffs2_scan_make_ino_cache(struct jffs2_sb_info *c, uint32_t ino)
649{ 708{
650 struct jffs2_inode_cache *ic; 709 struct jffs2_inode_cache *ic;
651 710
@@ -671,8 +730,8 @@ static struct jffs2_inode_cache *jffs2_scan_make_ino_cache(struct jffs2_sb_info
671 return ic; 730 return ic;
672} 731}
673 732
674static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 733static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
675 struct jffs2_raw_inode *ri, uint32_t ofs) 734 struct jffs2_raw_inode *ri, uint32_t ofs, struct jffs2_summary *s)
676{ 735{
677 struct jffs2_raw_node_ref *raw; 736 struct jffs2_raw_node_ref *raw;
678 struct jffs2_inode_cache *ic; 737 struct jffs2_inode_cache *ic;
@@ -681,11 +740,11 @@ static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
681 D1(printk(KERN_DEBUG "jffs2_scan_inode_node(): Node at 0x%08x\n", ofs)); 740 D1(printk(KERN_DEBUG "jffs2_scan_inode_node(): Node at 0x%08x\n", ofs));
682 741
683 /* We do very little here now. Just check the ino# to which we should attribute 742 /* We do very little here now. Just check the ino# to which we should attribute
684 this node; we can do all the CRC checking etc. later. There's a tradeoff here -- 743 this node; we can do all the CRC checking etc. later. There's a tradeoff here --
685 we used to scan the flash once only, reading everything we want from it into 744 we used to scan the flash once only, reading everything we want from it into
686 memory, then building all our in-core data structures and freeing the extra 745 memory, then building all our in-core data structures and freeing the extra
687 information. Now we allow the first part of the mount to complete a lot quicker, 746 information. Now we allow the first part of the mount to complete a lot quicker,
688 but we have to go _back_ to the flash in order to finish the CRC checking, etc. 747 but we have to go _back_ to the flash in order to finish the CRC checking, etc.
689 Which means that the _full_ amount of time to get to proper write mode with GC 748 Which means that the _full_ amount of time to get to proper write mode with GC
690 operational may actually be _longer_ than before. Sucks to be me. */ 749 operational may actually be _longer_ than before. Sucks to be me. */
691 750
@@ -731,7 +790,7 @@ static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
731 jeb->last_node->next_phys = raw; 790 jeb->last_node->next_phys = raw;
732 jeb->last_node = raw; 791 jeb->last_node = raw;
733 792
734 D1(printk(KERN_DEBUG "Node is ino #%u, version %d. Range 0x%x-0x%x\n", 793 D1(printk(KERN_DEBUG "Node is ino #%u, version %d. Range 0x%x-0x%x\n",
735 je32_to_cpu(ri->ino), je32_to_cpu(ri->version), 794 je32_to_cpu(ri->ino), je32_to_cpu(ri->version),
736 je32_to_cpu(ri->offset), 795 je32_to_cpu(ri->offset),
737 je32_to_cpu(ri->offset)+je32_to_cpu(ri->dsize))); 796 je32_to_cpu(ri->offset)+je32_to_cpu(ri->dsize)));
@@ -739,11 +798,16 @@ static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
739 pseudo_random += je32_to_cpu(ri->version); 798 pseudo_random += je32_to_cpu(ri->version);
740 799
741 UNCHECKED_SPACE(PAD(je32_to_cpu(ri->totlen))); 800 UNCHECKED_SPACE(PAD(je32_to_cpu(ri->totlen)));
801
802 if (jffs2_sum_active()) {
803 jffs2_sum_add_inode_mem(s, ri, ofs - jeb->offset);
804 }
805
742 return 0; 806 return 0;
743} 807}
744 808
745static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 809static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
746 struct jffs2_raw_dirent *rd, uint32_t ofs) 810 struct jffs2_raw_dirent *rd, uint32_t ofs, struct jffs2_summary *s)
747{ 811{
748 struct jffs2_raw_node_ref *raw; 812 struct jffs2_raw_node_ref *raw;
749 struct jffs2_full_dirent *fd; 813 struct jffs2_full_dirent *fd;
@@ -776,7 +840,7 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
776 crc = crc32(0, fd->name, rd->nsize); 840 crc = crc32(0, fd->name, rd->nsize);
777 if (crc != je32_to_cpu(rd->name_crc)) { 841 if (crc != je32_to_cpu(rd->name_crc)) {
778 printk(KERN_NOTICE "jffs2_scan_dirent_node(): Name CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", 842 printk(KERN_NOTICE "jffs2_scan_dirent_node(): Name CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
779 ofs, je32_to_cpu(rd->name_crc), crc); 843 ofs, je32_to_cpu(rd->name_crc), crc);
780 D1(printk(KERN_NOTICE "Name for which CRC failed is (now) '%s', ino #%d\n", fd->name, je32_to_cpu(rd->ino))); 844 D1(printk(KERN_NOTICE "Name for which CRC failed is (now) '%s', ino #%d\n", fd->name, je32_to_cpu(rd->ino)));
781 jffs2_free_full_dirent(fd); 845 jffs2_free_full_dirent(fd);
782 /* FIXME: Why do we believe totlen? */ 846 /* FIXME: Why do we believe totlen? */
@@ -796,7 +860,7 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
796 jffs2_free_raw_node_ref(raw); 860 jffs2_free_raw_node_ref(raw);
797 return -ENOMEM; 861 return -ENOMEM;
798 } 862 }
799 863
800 raw->__totlen = PAD(je32_to_cpu(rd->totlen)); 864 raw->__totlen = PAD(je32_to_cpu(rd->totlen));
801 raw->flash_offset = ofs | REF_PRISTINE; 865 raw->flash_offset = ofs | REF_PRISTINE;
802 raw->next_phys = NULL; 866 raw->next_phys = NULL;
@@ -817,6 +881,10 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
817 USED_SPACE(PAD(je32_to_cpu(rd->totlen))); 881 USED_SPACE(PAD(je32_to_cpu(rd->totlen)));
818 jffs2_add_fd_to_list(c, fd, &ic->scan_dents); 882 jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
819 883
884 if (jffs2_sum_active()) {
885 jffs2_sum_add_dirent_mem(s, rd, ofs - jeb->offset);
886 }
887
820 return 0; 888 return 0;
821} 889}
822 890
@@ -852,76 +920,34 @@ void jffs2_rotate_lists(struct jffs2_sb_info *c)
852 x = count_list(&c->clean_list); 920 x = count_list(&c->clean_list);
853 if (x) { 921 if (x) {
854 rotateby = pseudo_random % x; 922 rotateby = pseudo_random % x;
855 D1(printk(KERN_DEBUG "Rotating clean_list by %d\n", rotateby));
856
857 rotate_list((&c->clean_list), rotateby); 923 rotate_list((&c->clean_list), rotateby);
858
859 D1(printk(KERN_DEBUG "Erase block at front of clean_list is at %08x\n",
860 list_entry(c->clean_list.next, struct jffs2_eraseblock, list)->offset));
861 } else {
862 D1(printk(KERN_DEBUG "Not rotating empty clean_list\n"));
863 } 924 }
864 925
865 x = count_list(&c->very_dirty_list); 926 x = count_list(&c->very_dirty_list);
866 if (x) { 927 if (x) {
867 rotateby = pseudo_random % x; 928 rotateby = pseudo_random % x;
868 D1(printk(KERN_DEBUG "Rotating very_dirty_list by %d\n", rotateby));
869
870 rotate_list((&c->very_dirty_list), rotateby); 929 rotate_list((&c->very_dirty_list), rotateby);
871
872 D1(printk(KERN_DEBUG "Erase block at front of very_dirty_list is at %08x\n",
873 list_entry(c->very_dirty_list.next, struct jffs2_eraseblock, list)->offset));
874 } else {
875 D1(printk(KERN_DEBUG "Not rotating empty very_dirty_list\n"));
876 } 930 }
877 931
878 x = count_list(&c->dirty_list); 932 x = count_list(&c->dirty_list);
879 if (x) { 933 if (x) {
880 rotateby = pseudo_random % x; 934 rotateby = pseudo_random % x;
881 D1(printk(KERN_DEBUG "Rotating dirty_list by %d\n", rotateby));
882
883 rotate_list((&c->dirty_list), rotateby); 935 rotate_list((&c->dirty_list), rotateby);
884
885 D1(printk(KERN_DEBUG "Erase block at front of dirty_list is at %08x\n",
886 list_entry(c->dirty_list.next, struct jffs2_eraseblock, list)->offset));
887 } else {
888 D1(printk(KERN_DEBUG "Not rotating empty dirty_list\n"));
889 } 936 }
890 937
891 x = count_list(&c->erasable_list); 938 x = count_list(&c->erasable_list);
892 if (x) { 939 if (x) {
893 rotateby = pseudo_random % x; 940 rotateby = pseudo_random % x;
894 D1(printk(KERN_DEBUG "Rotating erasable_list by %d\n", rotateby));
895
896 rotate_list((&c->erasable_list), rotateby); 941 rotate_list((&c->erasable_list), rotateby);
897
898 D1(printk(KERN_DEBUG "Erase block at front of erasable_list is at %08x\n",
899 list_entry(c->erasable_list.next, struct jffs2_eraseblock, list)->offset));
900 } else {
901 D1(printk(KERN_DEBUG "Not rotating empty erasable_list\n"));
902 } 942 }
903 943
904 if (c->nr_erasing_blocks) { 944 if (c->nr_erasing_blocks) {
905 rotateby = pseudo_random % c->nr_erasing_blocks; 945 rotateby = pseudo_random % c->nr_erasing_blocks;
906 D1(printk(KERN_DEBUG "Rotating erase_pending_list by %d\n", rotateby));
907
908 rotate_list((&c->erase_pending_list), rotateby); 946 rotate_list((&c->erase_pending_list), rotateby);
909
910 D1(printk(KERN_DEBUG "Erase block at front of erase_pending_list is at %08x\n",
911 list_entry(c->erase_pending_list.next, struct jffs2_eraseblock, list)->offset));
912 } else {
913 D1(printk(KERN_DEBUG "Not rotating empty erase_pending_list\n"));
914 } 947 }
915 948
916 if (c->nr_free_blocks) { 949 if (c->nr_free_blocks) {
917 rotateby = pseudo_random % c->nr_free_blocks; 950 rotateby = pseudo_random % c->nr_free_blocks;
918 D1(printk(KERN_DEBUG "Rotating free_list by %d\n", rotateby));
919
920 rotate_list((&c->free_list), rotateby); 951 rotate_list((&c->free_list), rotateby);
921
922 D1(printk(KERN_DEBUG "Erase block at front of free_list is at %08x\n",
923 list_entry(c->free_list.next, struct jffs2_eraseblock, list)->offset));
924 } else {
925 D1(printk(KERN_DEBUG "Not rotating empty free_list\n"));
926 } 952 }
927} 953}
diff --git a/fs/jffs2/summary.c b/fs/jffs2/summary.c
new file mode 100644
index 000000000000..fb9cec61fcf2
--- /dev/null
+++ b/fs/jffs2/summary.c
@@ -0,0 +1,730 @@
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>,
5 * Zoltan Sogor <weth@inf.u-szeged.hu>,
6 * Patrik Kluba <pajko@halom.u-szeged.hu>,
7 * University of Szeged, Hungary
8 *
9 * For licensing information, see the file 'LICENCE' in this directory.
10 *
11 * $Id: summary.c,v 1.4 2005/09/26 11:37:21 havasi Exp $
12 *
13 */
14
15#include <linux/kernel.h>
16#include <linux/sched.h>
17#include <linux/slab.h>
18#include <linux/mtd/mtd.h>
19#include <linux/pagemap.h>
20#include <linux/crc32.h>
21#include <linux/compiler.h>
22#include <linux/vmalloc.h>
23#include "nodelist.h"
24#include "debug.h"
25
26int jffs2_sum_init(struct jffs2_sb_info *c)
27{
28 c->summary = kmalloc(sizeof(struct jffs2_summary), GFP_KERNEL);
29
30 if (!c->summary) {
31 JFFS2_WARNING("Can't allocate memory for summary information!\n");
32 return -ENOMEM;
33 }
34
35 memset(c->summary, 0, sizeof(struct jffs2_summary));
36
37 c->summary->sum_buf = vmalloc(c->sector_size);
38
39 if (!c->summary->sum_buf) {
40 JFFS2_WARNING("Can't allocate buffer for writing out summary information!\n");
41 kfree(c->summary);
42 return -ENOMEM;
43 }
44
45 dbg_summary("returned succesfully\n");
46
47 return 0;
48}
49
50void jffs2_sum_exit(struct jffs2_sb_info *c)
51{
52 dbg_summary("called\n");
53
54 jffs2_sum_disable_collecting(c->summary);
55
56 vfree(c->summary->sum_buf);
57 c->summary->sum_buf = NULL;
58
59 kfree(c->summary);
60 c->summary = NULL;
61}
62
63static int jffs2_sum_add_mem(struct jffs2_summary *s, union jffs2_sum_mem *item)
64{
65 if (!s->sum_list_head)
66 s->sum_list_head = (union jffs2_sum_mem *) item;
67 if (s->sum_list_tail)
68 s->sum_list_tail->u.next = (union jffs2_sum_mem *) item;
69 s->sum_list_tail = (union jffs2_sum_mem *) item;
70
71 switch (je16_to_cpu(item->u.nodetype)) {
72 case JFFS2_NODETYPE_INODE:
73 s->sum_size += JFFS2_SUMMARY_INODE_SIZE;
74 s->sum_num++;
75 dbg_summary("inode (%u) added to summary\n",
76 je32_to_cpu(item->i.inode));
77 break;
78 case JFFS2_NODETYPE_DIRENT:
79 s->sum_size += JFFS2_SUMMARY_DIRENT_SIZE(item->d.nsize);
80 s->sum_num++;
81 dbg_summary("dirent (%u) added to summary\n",
82 je32_to_cpu(item->d.ino));
83 break;
84 default:
85 JFFS2_WARNING("UNKNOWN node type %u\n",
86 je16_to_cpu(item->u.nodetype));
87 return 1;
88 }
89 return 0;
90}
91
92
93/* The following 3 functions are called from scan.c to collect summary info for not closed jeb */
94
95int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size)
96{
97 dbg_summary("called with %u\n", size);
98 s->sum_padded += size;
99 return 0;
100}
101
102int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri,
103 uint32_t ofs)
104{
105 struct jffs2_sum_inode_mem *temp = kmalloc(sizeof(struct jffs2_sum_inode_mem), GFP_KERNEL);
106
107 if (!temp)
108 return -ENOMEM;
109
110 temp->nodetype = ri->nodetype;
111 temp->inode = ri->ino;
112 temp->version = ri->version;
113 temp->offset = cpu_to_je32(ofs); /* relative offset from the begining of the jeb */
114 temp->totlen = ri->totlen;
115 temp->next = NULL;
116
117 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
118}
119
120int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd,
121 uint32_t ofs)
122{
123 struct jffs2_sum_dirent_mem *temp =
124 kmalloc(sizeof(struct jffs2_sum_dirent_mem) + rd->nsize, GFP_KERNEL);
125
126 if (!temp)
127 return -ENOMEM;
128
129 temp->nodetype = rd->nodetype;
130 temp->totlen = rd->totlen;
131 temp->offset = cpu_to_je32(ofs); /* relative from the begining of the jeb */
132 temp->pino = rd->pino;
133 temp->version = rd->version;
134 temp->ino = rd->ino;
135 temp->nsize = rd->nsize;
136 temp->type = rd->type;
137 temp->next = NULL;
138
139 memcpy(temp->name, rd->name, rd->nsize);
140
141 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
142}
143
144/* Cleanup every collected summary information */
145
146static void jffs2_sum_clean_collected(struct jffs2_summary *s)
147{
148 union jffs2_sum_mem *temp;
149
150 if (!s->sum_list_head) {
151 dbg_summary("already empty\n");
152 }
153 while (s->sum_list_head) {
154 temp = s->sum_list_head;
155 s->sum_list_head = s->sum_list_head->u.next;
156 kfree(temp);
157 }
158 s->sum_list_tail = NULL;
159 s->sum_padded = 0;
160 s->sum_num = 0;
161}
162
163void jffs2_sum_reset_collected(struct jffs2_summary *s)
164{
165 dbg_summary("called\n");
166 jffs2_sum_clean_collected(s);
167 s->sum_size = 0;
168}
169
170void jffs2_sum_disable_collecting(struct jffs2_summary *s)
171{
172 dbg_summary("called\n");
173 jffs2_sum_clean_collected(s);
174 s->sum_size = JFFS2_SUMMARY_NOSUM_SIZE;
175}
176
177int jffs2_sum_is_disabled(struct jffs2_summary *s)
178{
179 return (s->sum_size == JFFS2_SUMMARY_NOSUM_SIZE);
180}
181
182/* Move the collected summary information into sb (called from scan.c) */
183
184void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s)
185{
186 dbg_summary("oldsize=0x%x oldnum=%u => newsize=0x%x newnum=%u\n",
187 c->summary->sum_size, c->summary->sum_num,
188 s->sum_size, s->sum_num);
189
190 c->summary->sum_size = s->sum_size;
191 c->summary->sum_num = s->sum_num;
192 c->summary->sum_padded = s->sum_padded;
193 c->summary->sum_list_head = s->sum_list_head;
194 c->summary->sum_list_tail = s->sum_list_tail;
195
196 s->sum_list_head = s->sum_list_tail = NULL;
197}
198
199/* Called from wbuf.c to collect writed node info */
200
201int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
202 unsigned long count, uint32_t ofs)
203{
204 union jffs2_node_union *node;
205 struct jffs2_eraseblock *jeb;
206
207 node = invecs[0].iov_base;
208 jeb = &c->blocks[ofs / c->sector_size];
209 ofs -= jeb->offset;
210
211 switch (je16_to_cpu(node->u.nodetype)) {
212 case JFFS2_NODETYPE_INODE: {
213 struct jffs2_sum_inode_mem *temp =
214 kmalloc(sizeof(struct jffs2_sum_inode_mem), GFP_KERNEL);
215
216 if (!temp)
217 goto no_mem;
218
219 temp->nodetype = node->i.nodetype;
220 temp->inode = node->i.ino;
221 temp->version = node->i.version;
222 temp->offset = cpu_to_je32(ofs);
223 temp->totlen = node->i.totlen;
224 temp->next = NULL;
225
226 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
227 }
228
229 case JFFS2_NODETYPE_DIRENT: {
230 struct jffs2_sum_dirent_mem *temp =
231 kmalloc(sizeof(struct jffs2_sum_dirent_mem) + node->d.nsize, GFP_KERNEL);
232
233 if (!temp)
234 goto no_mem;
235
236 temp->nodetype = node->d.nodetype;
237 temp->totlen = node->d.totlen;
238 temp->offset = cpu_to_je32(ofs);
239 temp->pino = node->d.pino;
240 temp->version = node->d.version;
241 temp->ino = node->d.ino;
242 temp->nsize = node->d.nsize;
243 temp->type = node->d.type;
244 temp->next = NULL;
245
246 switch (count) {
247 case 1:
248 memcpy(temp->name,node->d.name,node->d.nsize);
249 break;
250
251 case 2:
252 memcpy(temp->name,invecs[1].iov_base,node->d.nsize);
253 break;
254
255 default:
256 BUG(); /* impossible count value */
257 break;
258 }
259
260 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
261 }
262
263 case JFFS2_NODETYPE_PADDING:
264 dbg_summary("node PADDING\n");
265 c->summary->sum_padded += je32_to_cpu(node->u.totlen);
266 break;
267
268 case JFFS2_NODETYPE_CLEANMARKER:
269 dbg_summary("node CLEANMARKER\n");
270 break;
271
272 case JFFS2_NODETYPE_SUMMARY:
273 dbg_summary("node SUMMARY\n");
274 break;
275
276 default:
277 /* If you implement a new node type you should also implement
278 summary support for it or disable summary.
279 */
280 BUG();
281 break;
282 }
283
284 return 0;
285
286no_mem:
287 JFFS2_WARNING("MEMORY ALLOCATION ERROR!");
288 return -ENOMEM;
289}
290
291
292/* Process the stored summary information - helper function for jffs2_sum_scan_sumnode() */
293
294static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
295 struct jffs2_raw_summary *summary, uint32_t *pseudo_random)
296{
297 struct jffs2_raw_node_ref *raw;
298 struct jffs2_inode_cache *ic;
299 struct jffs2_full_dirent *fd;
300 void *sp;
301 int i, ino;
302
303 sp = summary->sum;
304
305 for (i=0; i<je32_to_cpu(summary->sum_num); i++) {
306 dbg_summary("processing summary index %d\n", i);
307
308 switch (je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype)) {
309 case JFFS2_NODETYPE_INODE: {
310 struct jffs2_sum_inode_flash *spi;
311 spi = sp;
312
313 ino = je32_to_cpu(spi->inode);
314
315 dbg_summary("Inode at 0x%08x\n",
316 jeb->offset + je32_to_cpu(spi->offset));
317
318 raw = jffs2_alloc_raw_node_ref();
319 if (!raw) {
320 JFFS2_NOTICE("allocation of node reference failed\n");
321 kfree(summary);
322 return -ENOMEM;
323 }
324
325 ic = jffs2_scan_make_ino_cache(c, ino);
326 if (!ic) {
327 JFFS2_NOTICE("scan_make_ino_cache failed\n");
328 jffs2_free_raw_node_ref(raw);
329 kfree(summary);
330 return -ENOMEM;
331 }
332
333 raw->flash_offset = (jeb->offset + je32_to_cpu(spi->offset)) | REF_UNCHECKED;
334 raw->__totlen = PAD(je32_to_cpu(spi->totlen));
335 raw->next_phys = NULL;
336 raw->next_in_ino = ic->nodes;
337
338 ic->nodes = raw;
339 if (!jeb->first_node)
340 jeb->first_node = raw;
341 if (jeb->last_node)
342 jeb->last_node->next_phys = raw;
343 jeb->last_node = raw;
344 *pseudo_random += je32_to_cpu(spi->version);
345
346 UNCHECKED_SPACE(PAD(je32_to_cpu(spi->totlen)));
347
348 sp += JFFS2_SUMMARY_INODE_SIZE;
349
350 break;
351 }
352
353 case JFFS2_NODETYPE_DIRENT: {
354 struct jffs2_sum_dirent_flash *spd;
355 spd = sp;
356
357 dbg_summary("Dirent at 0x%08x\n",
358 jeb->offset + je32_to_cpu(spd->offset));
359
360 fd = jffs2_alloc_full_dirent(spd->nsize+1);
361 if (!fd) {
362 kfree(summary);
363 return -ENOMEM;
364 }
365
366 memcpy(&fd->name, spd->name, spd->nsize);
367 fd->name[spd->nsize] = 0;
368
369 raw = jffs2_alloc_raw_node_ref();
370 if (!raw) {
371 jffs2_free_full_dirent(fd);
372 JFFS2_NOTICE("allocation of node reference failed\n");
373 kfree(summary);
374 return -ENOMEM;
375 }
376
377 ic = jffs2_scan_make_ino_cache(c, je32_to_cpu(spd->pino));
378 if (!ic) {
379 jffs2_free_full_dirent(fd);
380 jffs2_free_raw_node_ref(raw);
381 kfree(summary);
382 return -ENOMEM;
383 }
384
385 raw->__totlen = PAD(je32_to_cpu(spd->totlen));
386 raw->flash_offset = (jeb->offset + je32_to_cpu(spd->offset)) | REF_PRISTINE;
387 raw->next_phys = NULL;
388 raw->next_in_ino = ic->nodes;
389 ic->nodes = raw;
390 if (!jeb->first_node)
391 jeb->first_node = raw;
392 if (jeb->last_node)
393 jeb->last_node->next_phys = raw;
394 jeb->last_node = raw;
395
396 fd->raw = raw;
397 fd->next = NULL;
398 fd->version = je32_to_cpu(spd->version);
399 fd->ino = je32_to_cpu(spd->ino);
400 fd->nhash = full_name_hash(fd->name, spd->nsize);
401 fd->type = spd->type;
402 USED_SPACE(PAD(je32_to_cpu(spd->totlen)));
403 jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
404
405 *pseudo_random += je32_to_cpu(spd->version);
406
407 sp += JFFS2_SUMMARY_DIRENT_SIZE(spd->nsize);
408
409 break;
410 }
411
412 default : {
413 JFFS2_WARNING("Unsupported node type found in summary! Exiting...");
414 kfree(summary);
415 return -EIO;
416 }
417 }
418 }
419
420 kfree(summary);
421 return 0;
422}
423
424/* Process the summary node - called from jffs2_scan_eraseblock() */
425
426int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
427 uint32_t ofs, uint32_t *pseudo_random)
428{
429 struct jffs2_unknown_node crcnode;
430 struct jffs2_raw_node_ref *cache_ref;
431 struct jffs2_raw_summary *summary;
432 int ret, sumsize;
433 uint32_t crc;
434
435 sumsize = c->sector_size - ofs;
436 ofs += jeb->offset;
437
438 dbg_summary("summary found for 0x%08x at 0x%08x (0x%x bytes)\n",
439 jeb->offset, ofs, sumsize);
440
441 summary = kmalloc(sumsize, GFP_KERNEL);
442
443 if (!summary) {
444 return -ENOMEM;
445 }
446
447 ret = jffs2_fill_scan_buf(c, (unsigned char *)summary, ofs, sumsize);
448
449 if (ret) {
450 kfree(summary);
451 return ret;
452 }
453
454 /* OK, now check for node validity and CRC */
455 crcnode.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
456 crcnode.nodetype = cpu_to_je16(JFFS2_NODETYPE_SUMMARY);
457 crcnode.totlen = summary->totlen;
458 crc = crc32(0, &crcnode, sizeof(crcnode)-4);
459
460 if (je32_to_cpu(summary->hdr_crc) != crc) {
461 dbg_summary("Summary node header is corrupt (bad CRC or "
462 "no summary at all)\n");
463 goto crc_err;
464 }
465
466 if (je32_to_cpu(summary->totlen) != sumsize) {
467 dbg_summary("Summary node is corrupt (wrong erasesize?)\n");
468 goto crc_err;
469 }
470
471 crc = crc32(0, summary, sizeof(struct jffs2_raw_summary)-8);
472
473 if (je32_to_cpu(summary->node_crc) != crc) {
474 dbg_summary("Summary node is corrupt (bad CRC)\n");
475 goto crc_err;
476 }
477
478 crc = crc32(0, summary->sum, sumsize - sizeof(struct jffs2_raw_summary));
479
480 if (je32_to_cpu(summary->sum_crc) != crc) {
481 dbg_summary("Summary node data is corrupt (bad CRC)\n");
482 goto crc_err;
483 }
484
485 if ( je32_to_cpu(summary->cln_mkr) ) {
486
487 dbg_summary("Summary : CLEANMARKER node \n");
488
489 if (je32_to_cpu(summary->cln_mkr) != c->cleanmarker_size) {
490 dbg_summary("CLEANMARKER node has totlen 0x%x != normal 0x%x\n",
491 je32_to_cpu(summary->cln_mkr), c->cleanmarker_size);
492 UNCHECKED_SPACE(PAD(je32_to_cpu(summary->cln_mkr)));
493 } else if (jeb->first_node) {
494 dbg_summary("CLEANMARKER node not first node in block "
495 "(0x%08x)\n", jeb->offset);
496 UNCHECKED_SPACE(PAD(je32_to_cpu(summary->cln_mkr)));
497 } else {
498 struct jffs2_raw_node_ref *marker_ref = jffs2_alloc_raw_node_ref();
499
500 if (!marker_ref) {
501 JFFS2_NOTICE("Failed to allocate node ref for clean marker\n");
502 kfree(summary);
503 return -ENOMEM;
504 }
505
506 marker_ref->next_in_ino = NULL;
507 marker_ref->next_phys = NULL;
508 marker_ref->flash_offset = jeb->offset | REF_NORMAL;
509 marker_ref->__totlen = je32_to_cpu(summary->cln_mkr);
510 jeb->first_node = jeb->last_node = marker_ref;
511
512 USED_SPACE( PAD(je32_to_cpu(summary->cln_mkr)) );
513 }
514 }
515
516 if (je32_to_cpu(summary->padded)) {
517 DIRTY_SPACE(je32_to_cpu(summary->padded));
518 }
519
520 ret = jffs2_sum_process_sum_data(c, jeb, summary, pseudo_random);
521 if (ret)
522 return ret;
523
524 /* for PARANOIA_CHECK */
525 cache_ref = jffs2_alloc_raw_node_ref();
526
527 if (!cache_ref) {
528 JFFS2_NOTICE("Failed to allocate node ref for cache\n");
529 return -ENOMEM;
530 }
531
532 cache_ref->next_in_ino = NULL;
533 cache_ref->next_phys = NULL;
534 cache_ref->flash_offset = ofs | REF_NORMAL;
535 cache_ref->__totlen = sumsize;
536
537 if (!jeb->first_node)
538 jeb->first_node = cache_ref;
539 if (jeb->last_node)
540 jeb->last_node->next_phys = cache_ref;
541 jeb->last_node = cache_ref;
542
543 USED_SPACE(sumsize);
544
545 jeb->wasted_size += jeb->free_size;
546 c->wasted_size += jeb->free_size;
547 c->free_size -= jeb->free_size;
548 jeb->free_size = 0;
549
550 return jffs2_scan_classify_jeb(c, jeb);
551
552crc_err:
553 JFFS2_WARNING("Summary node crc error, skipping summary information.\n");
554
555 return 0;
556}
557
558/* Write summary data to flash - helper function for jffs2_sum_write_sumnode() */
559
560static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
561 uint32_t infosize, uint32_t datasize, int padsize)
562{
563 struct jffs2_raw_summary isum;
564 union jffs2_sum_mem *temp;
565 struct jffs2_sum_marker *sm;
566 struct kvec vecs[2];
567 void *wpage;
568 int ret;
569 size_t retlen;
570
571 memset(c->summary->sum_buf, 0xff, datasize);
572 memset(&isum, 0, sizeof(isum));
573
574 isum.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
575 isum.nodetype = cpu_to_je16(JFFS2_NODETYPE_SUMMARY);
576 isum.totlen = cpu_to_je32(infosize);
577 isum.hdr_crc = cpu_to_je32(crc32(0, &isum, sizeof(struct jffs2_unknown_node) - 4));
578 isum.padded = cpu_to_je32(c->summary->sum_padded);
579 isum.cln_mkr = cpu_to_je32(c->cleanmarker_size);
580 isum.sum_num = cpu_to_je32(c->summary->sum_num);
581 wpage = c->summary->sum_buf;
582
583 while (c->summary->sum_num) {
584
585 switch (je16_to_cpu(c->summary->sum_list_head->u.nodetype)) {
586 case JFFS2_NODETYPE_INODE: {
587 struct jffs2_sum_inode_flash *sino_ptr = wpage;
588
589 sino_ptr->nodetype = c->summary->sum_list_head->i.nodetype;
590 sino_ptr->inode = c->summary->sum_list_head->i.inode;
591 sino_ptr->version = c->summary->sum_list_head->i.version;
592 sino_ptr->offset = c->summary->sum_list_head->i.offset;
593 sino_ptr->totlen = c->summary->sum_list_head->i.totlen;
594
595 wpage += JFFS2_SUMMARY_INODE_SIZE;
596
597 break;
598 }
599
600 case JFFS2_NODETYPE_DIRENT: {
601 struct jffs2_sum_dirent_flash *sdrnt_ptr = wpage;
602
603 sdrnt_ptr->nodetype = c->summary->sum_list_head->d.nodetype;
604 sdrnt_ptr->totlen = c->summary->sum_list_head->d.totlen;
605 sdrnt_ptr->offset = c->summary->sum_list_head->d.offset;
606 sdrnt_ptr->pino = c->summary->sum_list_head->d.pino;
607 sdrnt_ptr->version = c->summary->sum_list_head->d.version;
608 sdrnt_ptr->ino = c->summary->sum_list_head->d.ino;
609 sdrnt_ptr->nsize = c->summary->sum_list_head->d.nsize;
610 sdrnt_ptr->type = c->summary->sum_list_head->d.type;
611
612 memcpy(sdrnt_ptr->name, c->summary->sum_list_head->d.name,
613 c->summary->sum_list_head->d.nsize);
614
615 wpage += JFFS2_SUMMARY_DIRENT_SIZE(c->summary->sum_list_head->d.nsize);
616
617 break;
618 }
619
620 default : {
621 BUG(); /* unknown node in summary information */
622 }
623 }
624
625 temp = c->summary->sum_list_head;
626 c->summary->sum_list_head = c->summary->sum_list_head->u.next;
627 kfree(temp);
628
629 c->summary->sum_num--;
630 }
631
632 jffs2_sum_reset_collected(c->summary);
633
634 wpage += padsize;
635
636 sm = wpage;
637 sm->offset = cpu_to_je32(c->sector_size - jeb->free_size);
638 sm->magic = cpu_to_je32(JFFS2_SUM_MAGIC);
639
640 isum.sum_crc = cpu_to_je32(crc32(0, c->summary->sum_buf, datasize));
641 isum.node_crc = cpu_to_je32(crc32(0, &isum, sizeof(isum) - 8));
642
643 vecs[0].iov_base = &isum;
644 vecs[0].iov_len = sizeof(isum);
645 vecs[1].iov_base = c->summary->sum_buf;
646 vecs[1].iov_len = datasize;
647
648 dbg_summary("JFFS2: writing out data to flash to pos : 0x%08x\n",
649 jeb->offset + c->sector_size - jeb->free_size);
650
651 spin_unlock(&c->erase_completion_lock);
652 ret = jffs2_flash_writev(c, vecs, 2, jeb->offset + c->sector_size -
653 jeb->free_size, &retlen, 0);
654 spin_lock(&c->erase_completion_lock);
655
656
657 if (ret || (retlen != infosize)) {
658 JFFS2_WARNING("Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n",
659 infosize, jeb->offset + c->sector_size - jeb->free_size, ret, retlen);
660
661 c->summary->sum_size = JFFS2_SUMMARY_NOSUM_SIZE;
662 WASTED_SPACE(infosize);
663
664 return 1;
665 }
666
667 return 0;
668}
669
670/* Write out summary information - called from jffs2_do_reserve_space */
671
672int jffs2_sum_write_sumnode(struct jffs2_sb_info *c)
673{
674 struct jffs2_raw_node_ref *summary_ref;
675 int datasize, infosize, padsize, ret;
676 struct jffs2_eraseblock *jeb;
677
678 dbg_summary("called\n");
679
680 jeb = c->nextblock;
681
682 if (!c->summary->sum_num || !c->summary->sum_list_head) {
683 JFFS2_WARNING("Empty summary info!!!\n");
684 BUG();
685 }
686
687 datasize = c->summary->sum_size + sizeof(struct jffs2_sum_marker);
688 infosize = sizeof(struct jffs2_raw_summary) + datasize;
689 padsize = jeb->free_size - infosize;
690 infosize += padsize;
691 datasize += padsize;
692
693 /* Is there enough space for summary? */
694 if (padsize < 0) {
695 /* don't try to write out summary for this jeb */
696 jffs2_sum_disable_collecting(c->summary);
697
698 JFFS2_WARNING("Not enough space for summary, padsize = %d\n", padsize);
699 return 0;
700 }
701
702 ret = jffs2_sum_write_data(c, jeb, infosize, datasize, padsize);
703 if (ret)
704 return 0; /* can't write out summary, block is marked as NOSUM_SIZE */
705
706 /* for ACCT_PARANOIA_CHECK */
707 spin_unlock(&c->erase_completion_lock);
708 summary_ref = jffs2_alloc_raw_node_ref();
709 spin_lock(&c->erase_completion_lock);
710
711 if (!summary_ref) {
712 JFFS2_NOTICE("Failed to allocate node ref for summary\n");
713 return -ENOMEM;
714 }
715
716 summary_ref->next_in_ino = NULL;
717 summary_ref->next_phys = NULL;
718 summary_ref->flash_offset = (jeb->offset + c->sector_size - jeb->free_size) | REF_NORMAL;
719 summary_ref->__totlen = infosize;
720
721 if (!jeb->first_node)
722 jeb->first_node = summary_ref;
723 if (jeb->last_node)
724 jeb->last_node->next_phys = summary_ref;
725 jeb->last_node = summary_ref;
726
727 USED_SPACE(infosize);
728
729 return 0;
730}
diff --git a/fs/jffs2/summary.h b/fs/jffs2/summary.h
new file mode 100644
index 000000000000..b7a678be1709
--- /dev/null
+++ b/fs/jffs2/summary.h
@@ -0,0 +1,183 @@
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>,
5 * Zoltan Sogor <weth@inf.u-szeged.hu>,
6 * Patrik Kluba <pajko@halom.u-szeged.hu>,
7 * University of Szeged, Hungary
8 *
9 * For licensing information, see the file 'LICENCE' in this directory.
10 *
11 * $Id: summary.h,v 1.2 2005/09/26 11:37:21 havasi Exp $
12 *
13 */
14
15#ifndef JFFS2_SUMMARY_H
16#define JFFS2_SUMMARY_H
17
18#include <linux/uio.h>
19#include <linux/jffs2.h>
20
21#define DIRTY_SPACE(x) do { typeof(x) _x = (x); \
22 c->free_size -= _x; c->dirty_size += _x; \
23 jeb->free_size -= _x ; jeb->dirty_size += _x; \
24 }while(0)
25#define USED_SPACE(x) do { typeof(x) _x = (x); \
26 c->free_size -= _x; c->used_size += _x; \
27 jeb->free_size -= _x ; jeb->used_size += _x; \
28 }while(0)
29#define WASTED_SPACE(x) do { typeof(x) _x = (x); \
30 c->free_size -= _x; c->wasted_size += _x; \
31 jeb->free_size -= _x ; jeb->wasted_size += _x; \
32 }while(0)
33#define UNCHECKED_SPACE(x) do { typeof(x) _x = (x); \
34 c->free_size -= _x; c->unchecked_size += _x; \
35 jeb->free_size -= _x ; jeb->unchecked_size += _x; \
36 }while(0)
37
38#define BLK_STATE_ALLFF 0
39#define BLK_STATE_CLEAN 1
40#define BLK_STATE_PARTDIRTY 2
41#define BLK_STATE_CLEANMARKER 3
42#define BLK_STATE_ALLDIRTY 4
43#define BLK_STATE_BADBLOCK 5
44
45#define JFFS2_SUMMARY_NOSUM_SIZE 0xffffffff
46#define JFFS2_SUMMARY_INODE_SIZE (sizeof(struct jffs2_sum_inode_flash))
47#define JFFS2_SUMMARY_DIRENT_SIZE(x) (sizeof(struct jffs2_sum_dirent_flash) + (x))
48
49/* Summary structures used on flash */
50
51struct jffs2_sum_unknown_flash
52{
53 jint16_t nodetype; /* node type */
54};
55
56struct jffs2_sum_inode_flash
57{
58 jint16_t nodetype; /* node type */
59 jint32_t inode; /* inode number */
60 jint32_t version; /* inode version */
61 jint32_t offset; /* offset on jeb */
62 jint32_t totlen; /* record length */
63} __attribute__((packed));
64
65struct jffs2_sum_dirent_flash
66{
67 jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */
68 jint32_t totlen; /* record length */
69 jint32_t offset; /* offset on jeb */
70 jint32_t pino; /* parent inode */
71 jint32_t version; /* dirent version */
72 jint32_t ino; /* == zero for unlink */
73 uint8_t nsize; /* dirent name size */
74 uint8_t type; /* dirent type */
75 uint8_t name[0]; /* dirent name */
76} __attribute__((packed));
77
78union jffs2_sum_flash
79{
80 struct jffs2_sum_unknown_flash u;
81 struct jffs2_sum_inode_flash i;
82 struct jffs2_sum_dirent_flash d;
83};
84
85/* Summary structures used in the memory */
86
87struct jffs2_sum_unknown_mem
88{
89 union jffs2_sum_mem *next;
90 jint16_t nodetype; /* node type */
91};
92
93struct jffs2_sum_inode_mem
94{
95 union jffs2_sum_mem *next;
96 jint16_t nodetype; /* node type */
97 jint32_t inode; /* inode number */
98 jint32_t version; /* inode version */
99 jint32_t offset; /* offset on jeb */
100 jint32_t totlen; /* record length */
101} __attribute__((packed));
102
103struct jffs2_sum_dirent_mem
104{
105 union jffs2_sum_mem *next;
106 jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */
107 jint32_t totlen; /* record length */
108 jint32_t offset; /* ofset on jeb */
109 jint32_t pino; /* parent inode */
110 jint32_t version; /* dirent version */
111 jint32_t ino; /* == zero for unlink */
112 uint8_t nsize; /* dirent name size */
113 uint8_t type; /* dirent type */
114 uint8_t name[0]; /* dirent name */
115} __attribute__((packed));
116
117union jffs2_sum_mem
118{
119 struct jffs2_sum_unknown_mem u;
120 struct jffs2_sum_inode_mem i;
121 struct jffs2_sum_dirent_mem d;
122};
123
124/* Summary related information stored in superblock */
125
126struct jffs2_summary
127{
128 uint32_t sum_size; /* collected summary information for nextblock */
129 uint32_t sum_num;
130 uint32_t sum_padded;
131 union jffs2_sum_mem *sum_list_head;
132 union jffs2_sum_mem *sum_list_tail;
133
134 jint32_t *sum_buf; /* buffer for writing out summary */
135};
136
137/* Summary marker is stored at the end of every sumarized erase block */
138
139struct jffs2_sum_marker
140{
141 jint32_t offset; /* offset of the summary node in the jeb */
142 jint32_t magic; /* == JFFS2_SUM_MAGIC */
143};
144
145#define JFFS2_SUMMARY_FRAME_SIZE (sizeof(struct jffs2_raw_summary) + sizeof(struct jffs2_sum_marker))
146
147#ifdef CONFIG_JFFS2_SUMMARY /* SUMMARY SUPPORT ENABLED */
148
149#define jffs2_sum_active() (1)
150int jffs2_sum_init(struct jffs2_sb_info *c);
151void jffs2_sum_exit(struct jffs2_sb_info *c);
152void jffs2_sum_disable_collecting(struct jffs2_summary *s);
153int jffs2_sum_is_disabled(struct jffs2_summary *s);
154void jffs2_sum_reset_collected(struct jffs2_summary *s);
155void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s);
156int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
157 unsigned long count, uint32_t to);
158int jffs2_sum_write_sumnode(struct jffs2_sb_info *c);
159int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size);
160int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri, uint32_t ofs);
161int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd, uint32_t ofs);
162int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
163 uint32_t ofs, uint32_t *pseudo_random);
164
165#else /* SUMMARY DISABLED */
166
167#define jffs2_sum_active() (0)
168#define jffs2_sum_init(a) (0)
169#define jffs2_sum_exit(a)
170#define jffs2_sum_disable_collecting(a)
171#define jffs2_sum_is_disabled(a) (0)
172#define jffs2_sum_reset_collected(a)
173#define jffs2_sum_add_kvec(a,b,c,d) (0)
174#define jffs2_sum_move_collected(a,b)
175#define jffs2_sum_write_sumnode(a) (0)
176#define jffs2_sum_add_padding_mem(a,b)
177#define jffs2_sum_add_inode_mem(a,b,c)
178#define jffs2_sum_add_dirent_mem(a,b,c)
179#define jffs2_sum_scan_sumnode(a,b,c,d) (0)
180
181#endif /* CONFIG_JFFS2_SUMMARY */
182
183#endif /* JFFS2_SUMMARY_H */
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index aaf9475cfb6a..9e0b5458d9c0 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: super.c,v 1.107 2005/07/12 16:37:08 dedekind Exp $ 10 * $Id: super.c,v 1.110 2005/11/07 11:14:42 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -62,7 +62,7 @@ static int jffs2_sync_fs(struct super_block *sb, int wait)
62 62
63 down(&c->alloc_sem); 63 down(&c->alloc_sem);
64 jffs2_flush_wbuf_pad(c); 64 jffs2_flush_wbuf_pad(c);
65 up(&c->alloc_sem); 65 up(&c->alloc_sem);
66 return 0; 66 return 0;
67} 67}
68 68
@@ -112,7 +112,7 @@ static int jffs2_sb_set(struct super_block *sb, void *data)
112} 112}
113 113
114static struct super_block *jffs2_get_sb_mtd(struct file_system_type *fs_type, 114static struct super_block *jffs2_get_sb_mtd(struct file_system_type *fs_type,
115 int flags, const char *dev_name, 115 int flags, const char *dev_name,
116 void *data, struct mtd_info *mtd) 116 void *data, struct mtd_info *mtd)
117{ 117{
118 struct super_block *sb; 118 struct super_block *sb;
@@ -172,7 +172,7 @@ static struct super_block *jffs2_get_sb_mtd(struct file_system_type *fs_type,
172} 172}
173 173
174static struct super_block *jffs2_get_sb_mtdnr(struct file_system_type *fs_type, 174static struct super_block *jffs2_get_sb_mtdnr(struct file_system_type *fs_type,
175 int flags, const char *dev_name, 175 int flags, const char *dev_name,
176 void *data, int mtdnr) 176 void *data, int mtdnr)
177{ 177{
178 struct mtd_info *mtd; 178 struct mtd_info *mtd;
@@ -201,7 +201,7 @@ static struct super_block *jffs2_get_sb(struct file_system_type *fs_type,
201 201
202 /* The preferred way of mounting in future; especially when 202 /* The preferred way of mounting in future; especially when
203 CONFIG_BLK_DEV is implemented - we specify the underlying 203 CONFIG_BLK_DEV is implemented - we specify the underlying
204 MTD device by number or by name, so that we don't require 204 MTD device by number or by name, so that we don't require
205 block device support to be present in the kernel. */ 205 block device support to be present in the kernel. */
206 206
207 /* FIXME: How to do the root fs this way? */ 207 /* FIXME: How to do the root fs this way? */
@@ -225,7 +225,7 @@ static struct super_block *jffs2_get_sb(struct file_system_type *fs_type,
225 } else if (isdigit(dev_name[3])) { 225 } else if (isdigit(dev_name[3])) {
226 /* Mount by MTD device number name */ 226 /* Mount by MTD device number name */
227 char *endptr; 227 char *endptr;
228 228
229 mtdnr = simple_strtoul(dev_name+3, &endptr, 0); 229 mtdnr = simple_strtoul(dev_name+3, &endptr, 0);
230 if (!*endptr) { 230 if (!*endptr) {
231 /* It was a valid number */ 231 /* It was a valid number */
@@ -235,7 +235,7 @@ static struct super_block *jffs2_get_sb(struct file_system_type *fs_type,
235 } 235 }
236 } 236 }
237 237
238 /* Try the old way - the hack where we allowed users to mount 238 /* Try the old way - the hack where we allowed users to mount
239 /dev/mtdblock$(n) but didn't actually _use_ the blkdev */ 239 /dev/mtdblock$(n) but didn't actually _use_ the blkdev */
240 240
241 err = path_lookup(dev_name, LOOKUP_FOLLOW, &nd); 241 err = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
@@ -282,9 +282,12 @@ static void jffs2_put_super (struct super_block *sb)
282 down(&c->alloc_sem); 282 down(&c->alloc_sem);
283 jffs2_flush_wbuf_pad(c); 283 jffs2_flush_wbuf_pad(c);
284 up(&c->alloc_sem); 284 up(&c->alloc_sem);
285
286 jffs2_sum_exit(c);
287
285 jffs2_free_ino_caches(c); 288 jffs2_free_ino_caches(c);
286 jffs2_free_raw_node_refs(c); 289 jffs2_free_raw_node_refs(c);
287 if (c->mtd->flags & MTD_NO_VIRTBLOCKS) 290 if (jffs2_blocks_use_vmalloc(c))
288 vfree(c->blocks); 291 vfree(c->blocks);
289 else 292 else
290 kfree(c->blocks); 293 kfree(c->blocks);
@@ -321,6 +324,9 @@ static int __init init_jffs2_fs(void)
321#ifdef CONFIG_JFFS2_FS_WRITEBUFFER 324#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
322 " (NAND)" 325 " (NAND)"
323#endif 326#endif
327#ifdef CONFIG_JFFS2_SUMMARY
328 " (SUMMARY) "
329#endif
324 " (C) 2001-2003 Red Hat, Inc.\n"); 330 " (C) 2001-2003 Red Hat, Inc.\n");
325 331
326 jffs2_inode_cachep = kmem_cache_create("jffs2_i", 332 jffs2_inode_cachep = kmem_cache_create("jffs2_i",
@@ -370,5 +376,5 @@ module_exit(exit_jffs2_fs);
370 376
371MODULE_DESCRIPTION("The Journalling Flash File System, v2"); 377MODULE_DESCRIPTION("The Journalling Flash File System, v2");
372MODULE_AUTHOR("Red Hat, Inc."); 378MODULE_AUTHOR("Red Hat, Inc.");
373MODULE_LICENSE("GPL"); // Actually dual-licensed, but it doesn't matter for 379MODULE_LICENSE("GPL"); // Actually dual-licensed, but it doesn't matter for
374 // the sake of this tag. It's Free Software. 380 // the sake of this tag. It's Free Software.
diff --git a/fs/jffs2/symlink.c b/fs/jffs2/symlink.c
index 82ef484f5e12..d55754fe8925 100644
--- a/fs/jffs2/symlink.c
+++ b/fs/jffs2/symlink.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: symlink.c,v 1.16 2005/03/01 10:50:48 dedekind Exp $ 10 * $Id: symlink.c,v 1.19 2005/11/07 11:14:42 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -21,7 +21,7 @@
21static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd); 21static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd);
22 22
23struct inode_operations jffs2_symlink_inode_operations = 23struct inode_operations jffs2_symlink_inode_operations =
24{ 24{
25 .readlink = generic_readlink, 25 .readlink = generic_readlink,
26 .follow_link = jffs2_follow_link, 26 .follow_link = jffs2_follow_link,
27 .setattr = jffs2_setattr 27 .setattr = jffs2_setattr
@@ -30,35 +30,33 @@ struct inode_operations jffs2_symlink_inode_operations =
30static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd) 30static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd)
31{ 31{
32 struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode); 32 struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
33 char *p = (char *)f->dents; 33 char *p = (char *)f->target;
34 34
35 /* 35 /*
36 * We don't acquire the f->sem mutex here since the only data we 36 * We don't acquire the f->sem mutex here since the only data we
37 * use is f->dents which in case of the symlink inode points to the 37 * use is f->target.
38 * symlink's target path.
39 * 38 *
40 * 1. If we are here the inode has already built and f->dents has 39 * 1. If we are here the inode has already built and f->target has
41 * to point to the target path. 40 * to point to the target path.
42 * 2. Nobody uses f->dents (if the inode is symlink's inode). The 41 * 2. Nobody uses f->target (if the inode is symlink's inode). The
43 * exception is inode freeing function which frees f->dents. But 42 * exception is inode freeing function which frees f->target. But
44 * it can't be called while we are here and before VFS has 43 * it can't be called while we are here and before VFS has
45 * stopped using our f->dents string which we provide by means of 44 * stopped using our f->target string which we provide by means of
46 * nd_set_link() call. 45 * nd_set_link() call.
47 */ 46 */
48 47
49 if (!p) { 48 if (!p) {
50 printk(KERN_ERR "jffs2_follow_link(): can't find symlink taerget\n"); 49 printk(KERN_ERR "jffs2_follow_link(): can't find symlink taerget\n");
51 p = ERR_PTR(-EIO); 50 p = ERR_PTR(-EIO);
52 } else {
53 D1(printk(KERN_DEBUG "jffs2_follow_link(): target path is '%s'\n", (char *) f->dents));
54 } 51 }
52 D1(printk(KERN_DEBUG "jffs2_follow_link(): target path is '%s'\n", (char *) f->target));
55 53
56 nd_set_link(nd, p); 54 nd_set_link(nd, p);
57 55
58 /* 56 /*
59 * We unlock the f->sem mutex but VFS will use the f->dents string. This is safe 57 * We will unlock the f->sem mutex but VFS will use the f->target string. This is safe
60 * since the only way that may cause f->dents to be changed is iput() operation. 58 * since the only way that may cause f->target to be changed is iput() operation.
61 * But VFS will not use f->dents after iput() has been called. 59 * But VFS will not use f->target after iput() has been called.
62 */ 60 */
63 return NULL; 61 return NULL;
64} 62}
diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
index 316133c626b7..4cebf0e57c46 100644
--- a/fs/jffs2/wbuf.c
+++ b/fs/jffs2/wbuf.c
@@ -9,7 +9,7 @@
9 * 9 *
10 * For licensing information, see the file 'LICENCE' in this directory. 10 * For licensing information, see the file 'LICENCE' in this directory.
11 * 11 *
12 * $Id: wbuf.c,v 1.92 2005/04/05 12:51:54 dedekind Exp $ 12 * $Id: wbuf.c,v 1.100 2005/09/30 13:59:13 dedekind Exp $
13 * 13 *
14 */ 14 */
15 15
@@ -30,12 +30,12 @@
30static unsigned char *brokenbuf; 30static unsigned char *brokenbuf;
31#endif 31#endif
32 32
33#define PAGE_DIV(x) ( ((unsigned long)(x) / (unsigned long)(c->wbuf_pagesize)) * (unsigned long)(c->wbuf_pagesize) )
34#define PAGE_MOD(x) ( (unsigned long)(x) % (unsigned long)(c->wbuf_pagesize) )
35
33/* max. erase failures before we mark a block bad */ 36/* max. erase failures before we mark a block bad */
34#define MAX_ERASE_FAILURES 2 37#define MAX_ERASE_FAILURES 2
35 38
36/* two seconds timeout for timed wbuf-flushing */
37#define WBUF_FLUSH_TIMEOUT 2 * HZ
38
39struct jffs2_inodirty { 39struct jffs2_inodirty {
40 uint32_t ino; 40 uint32_t ino;
41 struct jffs2_inodirty *next; 41 struct jffs2_inodirty *next;
@@ -139,7 +139,6 @@ static void jffs2_block_refile(struct jffs2_sb_info *c, struct jffs2_eraseblock
139{ 139{
140 D1(printk("About to refile bad block at %08x\n", jeb->offset)); 140 D1(printk("About to refile bad block at %08x\n", jeb->offset));
141 141
142 D2(jffs2_dump_block_lists(c));
143 /* File the existing block on the bad_used_list.... */ 142 /* File the existing block on the bad_used_list.... */
144 if (c->nextblock == jeb) 143 if (c->nextblock == jeb)
145 c->nextblock = NULL; 144 c->nextblock = NULL;
@@ -156,7 +155,6 @@ static void jffs2_block_refile(struct jffs2_sb_info *c, struct jffs2_eraseblock
156 c->nr_erasing_blocks++; 155 c->nr_erasing_blocks++;
157 jffs2_erase_pending_trigger(c); 156 jffs2_erase_pending_trigger(c);
158 } 157 }
159 D2(jffs2_dump_block_lists(c));
160 158
161 /* Adjust its size counts accordingly */ 159 /* Adjust its size counts accordingly */
162 c->wasted_size += jeb->free_size; 160 c->wasted_size += jeb->free_size;
@@ -164,8 +162,9 @@ static void jffs2_block_refile(struct jffs2_sb_info *c, struct jffs2_eraseblock
164 jeb->wasted_size += jeb->free_size; 162 jeb->wasted_size += jeb->free_size;
165 jeb->free_size = 0; 163 jeb->free_size = 0;
166 164
167 ACCT_SANITY_CHECK(c,jeb); 165 jffs2_dbg_dump_block_lists_nolock(c);
168 D1(ACCT_PARANOIA_CHECK(jeb)); 166 jffs2_dbg_acct_sanity_check_nolock(c,jeb);
167 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
169} 168}
170 169
171/* Recover from failure to write wbuf. Recover the nodes up to the 170/* Recover from failure to write wbuf. Recover the nodes up to the
@@ -189,7 +188,7 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
189 /* Find the first node to be recovered, by skipping over every 188 /* Find the first node to be recovered, by skipping over every
190 node which ends before the wbuf starts, or which is obsolete. */ 189 node which ends before the wbuf starts, or which is obsolete. */
191 first_raw = &jeb->first_node; 190 first_raw = &jeb->first_node;
192 while (*first_raw && 191 while (*first_raw &&
193 (ref_obsolete(*first_raw) || 192 (ref_obsolete(*first_raw) ||
194 (ref_offset(*first_raw)+ref_totlen(c, jeb, *first_raw)) < c->wbuf_ofs)) { 193 (ref_offset(*first_raw)+ref_totlen(c, jeb, *first_raw)) < c->wbuf_ofs)) {
195 D1(printk(KERN_DEBUG "Skipping node at 0x%08x(%d)-0x%08x which is either before 0x%08x or obsolete\n", 194 D1(printk(KERN_DEBUG "Skipping node at 0x%08x(%d)-0x%08x which is either before 0x%08x or obsolete\n",
@@ -238,7 +237,7 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
238 ret = c->mtd->read_ecc(c->mtd, start, c->wbuf_ofs - start, &retlen, buf, NULL, c->oobinfo); 237 ret = c->mtd->read_ecc(c->mtd, start, c->wbuf_ofs - start, &retlen, buf, NULL, c->oobinfo);
239 else 238 else
240 ret = c->mtd->read(c->mtd, start, c->wbuf_ofs - start, &retlen, buf); 239 ret = c->mtd->read(c->mtd, start, c->wbuf_ofs - start, &retlen, buf);
241 240
242 if (ret == -EBADMSG && retlen == c->wbuf_ofs - start) { 241 if (ret == -EBADMSG && retlen == c->wbuf_ofs - start) {
243 /* ECC recovered */ 242 /* ECC recovered */
244 ret = 0; 243 ret = 0;
@@ -266,7 +265,7 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
266 265
267 266
268 /* ... and get an allocation of space from a shiny new block instead */ 267 /* ... and get an allocation of space from a shiny new block instead */
269 ret = jffs2_reserve_space_gc(c, end-start, &ofs, &len); 268 ret = jffs2_reserve_space_gc(c, end-start, &ofs, &len, JFFS2_SUMMARY_NOSUM_SIZE);
270 if (ret) { 269 if (ret) {
271 printk(KERN_WARNING "Failed to allocate space for wbuf recovery. Data loss ensues.\n"); 270 printk(KERN_WARNING "Failed to allocate space for wbuf recovery. Data loss ensues.\n");
272 kfree(buf); 271 kfree(buf);
@@ -275,15 +274,15 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
275 if (end-start >= c->wbuf_pagesize) { 274 if (end-start >= c->wbuf_pagesize) {
276 /* Need to do another write immediately, but it's possible 275 /* Need to do another write immediately, but it's possible
277 that this is just because the wbuf itself is completely 276 that this is just because the wbuf itself is completely
278 full, and there's nothing earlier read back from the 277 full, and there's nothing earlier read back from the
279 flash. Hence 'buf' isn't necessarily what we're writing 278 flash. Hence 'buf' isn't necessarily what we're writing
280 from. */ 279 from. */
281 unsigned char *rewrite_buf = buf?:c->wbuf; 280 unsigned char *rewrite_buf = buf?:c->wbuf;
282 uint32_t towrite = (end-start) - ((end-start)%c->wbuf_pagesize); 281 uint32_t towrite = (end-start) - ((end-start)%c->wbuf_pagesize);
283 282
284 D1(printk(KERN_DEBUG "Write 0x%x bytes at 0x%08x in wbuf recover\n", 283 D1(printk(KERN_DEBUG "Write 0x%x bytes at 0x%08x in wbuf recover\n",
285 towrite, ofs)); 284 towrite, ofs));
286 285
287#ifdef BREAKMEHEADER 286#ifdef BREAKMEHEADER
288 static int breakme; 287 static int breakme;
289 if (breakme++ == 20) { 288 if (breakme++ == 20) {
@@ -327,8 +326,7 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
327 c->wbuf_ofs = ofs + towrite; 326 c->wbuf_ofs = ofs + towrite;
328 memmove(c->wbuf, rewrite_buf + towrite, c->wbuf_len); 327 memmove(c->wbuf, rewrite_buf + towrite, c->wbuf_len);
329 /* Don't muck about with c->wbuf_inodes. False positives are harmless. */ 328 /* Don't muck about with c->wbuf_inodes. False positives are harmless. */
330 if (buf) 329 kfree(buf);
331 kfree(buf);
332 } else { 330 } else {
333 /* OK, now we're left with the dregs in whichever buffer we're using */ 331 /* OK, now we're left with the dregs in whichever buffer we're using */
334 if (buf) { 332 if (buf) {
@@ -392,11 +390,11 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
392 else 390 else
393 jeb->last_node = container_of(first_raw, struct jffs2_raw_node_ref, next_phys); 391 jeb->last_node = container_of(first_raw, struct jffs2_raw_node_ref, next_phys);
394 392
395 ACCT_SANITY_CHECK(c,jeb); 393 jffs2_dbg_acct_sanity_check_nolock(c, jeb);
396 D1(ACCT_PARANOIA_CHECK(jeb)); 394 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
397 395
398 ACCT_SANITY_CHECK(c,new_jeb); 396 jffs2_dbg_acct_sanity_check_nolock(c, new_jeb);
399 D1(ACCT_PARANOIA_CHECK(new_jeb)); 397 jffs2_dbg_acct_paranoia_check_nolock(c, new_jeb);
400 398
401 spin_unlock(&c->erase_completion_lock); 399 spin_unlock(&c->erase_completion_lock);
402 400
@@ -435,15 +433,15 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
435 this happens, if we have a change to a new block, 433 this happens, if we have a change to a new block,
436 or if fsync forces us to flush the writebuffer. 434 or if fsync forces us to flush the writebuffer.
437 if we have a switch to next page, we will not have 435 if we have a switch to next page, we will not have
438 enough remaining space for this. 436 enough remaining space for this.
439 */ 437 */
440 if (pad && !jffs2_dataflash(c)) { 438 if (pad ) {
441 c->wbuf_len = PAD(c->wbuf_len); 439 c->wbuf_len = PAD(c->wbuf_len);
442 440
443 /* Pad with JFFS2_DIRTY_BITMASK initially. this helps out ECC'd NOR 441 /* Pad with JFFS2_DIRTY_BITMASK initially. this helps out ECC'd NOR
444 with 8 byte page size */ 442 with 8 byte page size */
445 memset(c->wbuf + c->wbuf_len, 0, c->wbuf_pagesize - c->wbuf_len); 443 memset(c->wbuf + c->wbuf_len, 0, c->wbuf_pagesize - c->wbuf_len);
446 444
447 if ( c->wbuf_len + sizeof(struct jffs2_unknown_node) < c->wbuf_pagesize) { 445 if ( c->wbuf_len + sizeof(struct jffs2_unknown_node) < c->wbuf_pagesize) {
448 struct jffs2_unknown_node *padnode = (void *)(c->wbuf + c->wbuf_len); 446 struct jffs2_unknown_node *padnode = (void *)(c->wbuf + c->wbuf_len);
449 padnode->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 447 padnode->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
@@ -454,7 +452,7 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
454 } 452 }
455 /* else jffs2_flash_writev has actually filled in the rest of the 453 /* else jffs2_flash_writev has actually filled in the rest of the
456 buffer for us, and will deal with the node refs etc. later. */ 454 buffer for us, and will deal with the node refs etc. later. */
457 455
458#ifdef BREAKME 456#ifdef BREAKME
459 static int breakme; 457 static int breakme;
460 if (breakme++ == 20) { 458 if (breakme++ == 20) {
@@ -463,9 +461,9 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
463 c->mtd->write_ecc(c->mtd, c->wbuf_ofs, c->wbuf_pagesize, 461 c->mtd->write_ecc(c->mtd, c->wbuf_ofs, c->wbuf_pagesize,
464 &retlen, brokenbuf, NULL, c->oobinfo); 462 &retlen, brokenbuf, NULL, c->oobinfo);
465 ret = -EIO; 463 ret = -EIO;
466 } else 464 } else
467#endif 465#endif
468 466
469 if (jffs2_cleanmarker_oob(c)) 467 if (jffs2_cleanmarker_oob(c))
470 ret = c->mtd->write_ecc(c->mtd, c->wbuf_ofs, c->wbuf_pagesize, &retlen, c->wbuf, NULL, c->oobinfo); 468 ret = c->mtd->write_ecc(c->mtd, c->wbuf_ofs, c->wbuf_pagesize, &retlen, c->wbuf, NULL, c->oobinfo);
471 else 469 else
@@ -488,7 +486,7 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
488 spin_lock(&c->erase_completion_lock); 486 spin_lock(&c->erase_completion_lock);
489 487
490 /* Adjust free size of the block if we padded. */ 488 /* Adjust free size of the block if we padded. */
491 if (pad && !jffs2_dataflash(c)) { 489 if (pad) {
492 struct jffs2_eraseblock *jeb; 490 struct jffs2_eraseblock *jeb;
493 491
494 jeb = &c->blocks[c->wbuf_ofs / c->sector_size]; 492 jeb = &c->blocks[c->wbuf_ofs / c->sector_size];
@@ -496,7 +494,7 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
496 D1(printk(KERN_DEBUG "jffs2_flush_wbuf() adjusting free_size of %sblock at %08x\n", 494 D1(printk(KERN_DEBUG "jffs2_flush_wbuf() adjusting free_size of %sblock at %08x\n",
497 (jeb==c->nextblock)?"next":"", jeb->offset)); 495 (jeb==c->nextblock)?"next":"", jeb->offset));
498 496
499 /* wbuf_pagesize - wbuf_len is the amount of space that's to be 497 /* wbuf_pagesize - wbuf_len is the amount of space that's to be
500 padded. If there is less free space in the block than that, 498 padded. If there is less free space in the block than that,
501 something screwed up */ 499 something screwed up */
502 if (jeb->free_size < (c->wbuf_pagesize - c->wbuf_len)) { 500 if (jeb->free_size < (c->wbuf_pagesize - c->wbuf_len)) {
@@ -524,9 +522,9 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
524 return 0; 522 return 0;
525} 523}
526 524
527/* Trigger garbage collection to flush the write-buffer. 525/* Trigger garbage collection to flush the write-buffer.
528 If ino arg is zero, do it if _any_ real (i.e. not GC) writes are 526 If ino arg is zero, do it if _any_ real (i.e. not GC) writes are
529 outstanding. If ino arg non-zero, do it only if a write for the 527 outstanding. If ino arg non-zero, do it only if a write for the
530 given inode is outstanding. */ 528 given inode is outstanding. */
531int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino) 529int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino)
532{ 530{
@@ -605,15 +603,6 @@ int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c)
605 603
606 return ret; 604 return ret;
607} 605}
608
609#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
610#define PAGE_DIV(x) ( ((unsigned long)(x) / (unsigned long)(c->wbuf_pagesize)) * (unsigned long)(c->wbuf_pagesize) )
611#define PAGE_MOD(x) ( (unsigned long)(x) % (unsigned long)(c->wbuf_pagesize) )
612#else
613#define PAGE_DIV(x) ( (x) & (~(c->wbuf_pagesize - 1)) )
614#define PAGE_MOD(x) ( (x) & (c->wbuf_pagesize - 1) )
615#endif
616
617int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsigned long count, loff_t to, size_t *retlen, uint32_t ino) 606int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsigned long count, loff_t to, size_t *retlen, uint32_t ino)
618{ 607{
619 struct kvec outvecs[3]; 608 struct kvec outvecs[3];
@@ -630,13 +619,13 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsig
630 /* If not NAND flash, don't bother */ 619 /* If not NAND flash, don't bother */
631 if (!jffs2_is_writebuffered(c)) 620 if (!jffs2_is_writebuffered(c))
632 return jffs2_flash_direct_writev(c, invecs, count, to, retlen); 621 return jffs2_flash_direct_writev(c, invecs, count, to, retlen);
633 622
634 down_write(&c->wbuf_sem); 623 down_write(&c->wbuf_sem);
635 624
636 /* If wbuf_ofs is not initialized, set it to target address */ 625 /* If wbuf_ofs is not initialized, set it to target address */
637 if (c->wbuf_ofs == 0xFFFFFFFF) { 626 if (c->wbuf_ofs == 0xFFFFFFFF) {
638 c->wbuf_ofs = PAGE_DIV(to); 627 c->wbuf_ofs = PAGE_DIV(to);
639 c->wbuf_len = PAGE_MOD(to); 628 c->wbuf_len = PAGE_MOD(to);
640 memset(c->wbuf,0xff,c->wbuf_pagesize); 629 memset(c->wbuf,0xff,c->wbuf_pagesize);
641 } 630 }
642 631
@@ -650,10 +639,10 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsig
650 memset(c->wbuf,0xff,c->wbuf_pagesize); 639 memset(c->wbuf,0xff,c->wbuf_pagesize);
651 } 640 }
652 } 641 }
653 642
654 /* Sanity checks on target address. 643 /* Sanity checks on target address.
655 It's permitted to write at PAD(c->wbuf_len+c->wbuf_ofs), 644 It's permitted to write at PAD(c->wbuf_len+c->wbuf_ofs),
656 and it's permitted to write at the beginning of a new 645 and it's permitted to write at the beginning of a new
657 erase block. Anything else, and you die. 646 erase block. Anything else, and you die.
658 New block starts at xxx000c (0-b = block header) 647 New block starts at xxx000c (0-b = block header)
659 */ 648 */
@@ -671,8 +660,8 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsig
671 } 660 }
672 /* set pointer to new block */ 661 /* set pointer to new block */
673 c->wbuf_ofs = PAGE_DIV(to); 662 c->wbuf_ofs = PAGE_DIV(to);
674 c->wbuf_len = PAGE_MOD(to); 663 c->wbuf_len = PAGE_MOD(to);
675 } 664 }
676 665
677 if (to != PAD(c->wbuf_ofs + c->wbuf_len)) { 666 if (to != PAD(c->wbuf_ofs + c->wbuf_len)) {
678 /* We're not writing immediately after the writebuffer. Bad. */ 667 /* We're not writing immediately after the writebuffer. Bad. */
@@ -692,21 +681,21 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsig
692 invec = 0; 681 invec = 0;
693 outvec = 0; 682 outvec = 0;
694 683
695 /* Fill writebuffer first, if already in use */ 684 /* Fill writebuffer first, if already in use */
696 if (c->wbuf_len) { 685 if (c->wbuf_len) {
697 uint32_t invec_ofs = 0; 686 uint32_t invec_ofs = 0;
698 687
699 /* adjust alignment offset */ 688 /* adjust alignment offset */
700 if (c->wbuf_len != PAGE_MOD(to)) { 689 if (c->wbuf_len != PAGE_MOD(to)) {
701 c->wbuf_len = PAGE_MOD(to); 690 c->wbuf_len = PAGE_MOD(to);
702 /* take care of alignment to next page */ 691 /* take care of alignment to next page */
703 if (!c->wbuf_len) 692 if (!c->wbuf_len)
704 c->wbuf_len = c->wbuf_pagesize; 693 c->wbuf_len = c->wbuf_pagesize;
705 } 694 }
706 695
707 while(c->wbuf_len < c->wbuf_pagesize) { 696 while(c->wbuf_len < c->wbuf_pagesize) {
708 uint32_t thislen; 697 uint32_t thislen;
709 698
710 if (invec == count) 699 if (invec == count)
711 goto alldone; 700 goto alldone;
712 701
@@ -714,17 +703,17 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsig
714 703
715 if (thislen >= invecs[invec].iov_len) 704 if (thislen >= invecs[invec].iov_len)
716 thislen = invecs[invec].iov_len; 705 thislen = invecs[invec].iov_len;
717 706
718 invec_ofs = thislen; 707 invec_ofs = thislen;
719 708
720 memcpy(c->wbuf + c->wbuf_len, invecs[invec].iov_base, thislen); 709 memcpy(c->wbuf + c->wbuf_len, invecs[invec].iov_base, thislen);
721 c->wbuf_len += thislen; 710 c->wbuf_len += thislen;
722 donelen += thislen; 711 donelen += thislen;
723 /* Get next invec, if actual did not fill the buffer */ 712 /* Get next invec, if actual did not fill the buffer */
724 if (c->wbuf_len < c->wbuf_pagesize) 713 if (c->wbuf_len < c->wbuf_pagesize)
725 invec++; 714 invec++;
726 } 715 }
727 716
728 /* write buffer is full, flush buffer */ 717 /* write buffer is full, flush buffer */
729 ret = __jffs2_flush_wbuf(c, NOPAD); 718 ret = __jffs2_flush_wbuf(c, NOPAD);
730 if (ret) { 719 if (ret) {
@@ -783,10 +772,10 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsig
783 772
784 /* We did cross a page boundary, so we write some now */ 773 /* We did cross a page boundary, so we write some now */
785 if (jffs2_cleanmarker_oob(c)) 774 if (jffs2_cleanmarker_oob(c))
786 ret = c->mtd->writev_ecc(c->mtd, outvecs, splitvec+1, outvec_to, &wbuf_retlen, NULL, c->oobinfo); 775 ret = c->mtd->writev_ecc(c->mtd, outvecs, splitvec+1, outvec_to, &wbuf_retlen, NULL, c->oobinfo);
787 else 776 else
788 ret = jffs2_flash_direct_writev(c, outvecs, splitvec+1, outvec_to, &wbuf_retlen); 777 ret = jffs2_flash_direct_writev(c, outvecs, splitvec+1, outvec_to, &wbuf_retlen);
789 778
790 if (ret < 0 || wbuf_retlen != PAGE_DIV(totlen)) { 779 if (ret < 0 || wbuf_retlen != PAGE_DIV(totlen)) {
791 /* At this point we have no problem, 780 /* At this point we have no problem,
792 c->wbuf is empty. However refile nextblock to avoid 781 c->wbuf is empty. However refile nextblock to avoid
@@ -803,7 +792,7 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsig
803 spin_unlock(&c->erase_completion_lock); 792 spin_unlock(&c->erase_completion_lock);
804 goto exit; 793 goto exit;
805 } 794 }
806 795
807 donelen += wbuf_retlen; 796 donelen += wbuf_retlen;
808 c->wbuf_ofs = PAGE_DIV(outvec_to) + PAGE_DIV(totlen); 797 c->wbuf_ofs = PAGE_DIV(outvec_to) + PAGE_DIV(totlen);
809 798
@@ -837,11 +826,17 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsig
837alldone: 826alldone:
838 *retlen = donelen; 827 *retlen = donelen;
839 828
829 if (jffs2_sum_active()) {
830 int res = jffs2_sum_add_kvec(c, invecs, count, (uint32_t) to);
831 if (res)
832 return res;
833 }
834
840 if (c->wbuf_len && ino) 835 if (c->wbuf_len && ino)
841 jffs2_wbuf_dirties_inode(c, ino); 836 jffs2_wbuf_dirties_inode(c, ino);
842 837
843 ret = 0; 838 ret = 0;
844 839
845exit: 840exit:
846 up_write(&c->wbuf_sem); 841 up_write(&c->wbuf_sem);
847 return ret; 842 return ret;
@@ -856,7 +851,7 @@ int jffs2_flash_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *r
856 struct kvec vecs[1]; 851 struct kvec vecs[1];
857 852
858 if (!jffs2_is_writebuffered(c)) 853 if (!jffs2_is_writebuffered(c))
859 return c->mtd->write(c->mtd, ofs, len, retlen, buf); 854 return jffs2_flash_direct_write(c, ofs, len, retlen, buf);
860 855
861 vecs[0].iov_base = (unsigned char *) buf; 856 vecs[0].iov_base = (unsigned char *) buf;
862 vecs[0].iov_len = len; 857 vecs[0].iov_len = len;
@@ -884,18 +879,18 @@ int jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *re
884 if ( (ret == -EBADMSG) && (*retlen == len) ) { 879 if ( (ret == -EBADMSG) && (*retlen == len) ) {
885 printk(KERN_WARNING "mtd->read(0x%zx bytes from 0x%llx) returned ECC error\n", 880 printk(KERN_WARNING "mtd->read(0x%zx bytes from 0x%llx) returned ECC error\n",
886 len, ofs); 881 len, ofs);
887 /* 882 /*
888 * We have the raw data without ECC correction in the buffer, maybe 883 * We have the raw data without ECC correction in the buffer, maybe
889 * we are lucky and all data or parts are correct. We check the node. 884 * we are lucky and all data or parts are correct. We check the node.
890 * If data are corrupted node check will sort it out. 885 * If data are corrupted node check will sort it out.
891 * We keep this block, it will fail on write or erase and the we 886 * We keep this block, it will fail on write or erase and the we
892 * mark it bad. Or should we do that now? But we should give him a chance. 887 * mark it bad. Or should we do that now? But we should give him a chance.
893 * Maybe we had a system crash or power loss before the ecc write or 888 * Maybe we had a system crash or power loss before the ecc write or
894 * a erase was completed. 889 * a erase was completed.
895 * So we return success. :) 890 * So we return success. :)
896 */ 891 */
897 ret = 0; 892 ret = 0;
898 } 893 }
899 894
900 /* if no writebuffer available or write buffer empty, return */ 895 /* if no writebuffer available or write buffer empty, return */
901 if (!c->wbuf_pagesize || !c->wbuf_len) 896 if (!c->wbuf_pagesize || !c->wbuf_len)
@@ -910,16 +905,16 @@ int jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *re
910 if (owbf > c->wbuf_len) /* is read beyond write buffer ? */ 905 if (owbf > c->wbuf_len) /* is read beyond write buffer ? */
911 goto exit; 906 goto exit;
912 lwbf = c->wbuf_len - owbf; /* number of bytes to copy */ 907 lwbf = c->wbuf_len - owbf; /* number of bytes to copy */
913 if (lwbf > len) 908 if (lwbf > len)
914 lwbf = len; 909 lwbf = len;
915 } else { 910 } else {
916 orbf = (c->wbuf_ofs - ofs); /* offset in read buffer */ 911 orbf = (c->wbuf_ofs - ofs); /* offset in read buffer */
917 if (orbf > len) /* is write beyond write buffer ? */ 912 if (orbf > len) /* is write beyond write buffer ? */
918 goto exit; 913 goto exit;
919 lwbf = len - orbf; /* number of bytes to copy */ 914 lwbf = len - orbf; /* number of bytes to copy */
920 if (lwbf > c->wbuf_len) 915 if (lwbf > c->wbuf_len)
921 lwbf = c->wbuf_len; 916 lwbf = c->wbuf_len;
922 } 917 }
923 if (lwbf > 0) 918 if (lwbf > 0)
924 memcpy(buf+orbf,c->wbuf+owbf,lwbf); 919 memcpy(buf+orbf,c->wbuf+owbf,lwbf);
925 920
@@ -947,7 +942,7 @@ int jffs2_check_oob_empty( struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb
947 printk(KERN_NOTICE "jffs2_check_oob_empty(): allocation of temporary data buffer for oob check failed\n"); 942 printk(KERN_NOTICE "jffs2_check_oob_empty(): allocation of temporary data buffer for oob check failed\n");
948 return -ENOMEM; 943 return -ENOMEM;
949 } 944 }
950 /* 945 /*
951 * if mode = 0, we scan for a total empty oob area, else we have 946 * if mode = 0, we scan for a total empty oob area, else we have
952 * to take care of the cleanmarker in the first page of the block 947 * to take care of the cleanmarker in the first page of the block
953 */ 948 */
@@ -956,41 +951,41 @@ int jffs2_check_oob_empty( struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb
956 D1(printk(KERN_WARNING "jffs2_check_oob_empty(): Read OOB failed %d for block at %08x\n", ret, jeb->offset)); 951 D1(printk(KERN_WARNING "jffs2_check_oob_empty(): Read OOB failed %d for block at %08x\n", ret, jeb->offset));
957 goto out; 952 goto out;
958 } 953 }
959 954
960 if (retlen < len) { 955 if (retlen < len) {
961 D1(printk(KERN_WARNING "jffs2_check_oob_empty(): Read OOB return short read " 956 D1(printk(KERN_WARNING "jffs2_check_oob_empty(): Read OOB return short read "
962 "(%zd bytes not %d) for block at %08x\n", retlen, len, jeb->offset)); 957 "(%zd bytes not %d) for block at %08x\n", retlen, len, jeb->offset));
963 ret = -EIO; 958 ret = -EIO;
964 goto out; 959 goto out;
965 } 960 }
966 961
967 /* Special check for first page */ 962 /* Special check for first page */
968 for(i = 0; i < oob_size ; i++) { 963 for(i = 0; i < oob_size ; i++) {
969 /* Yeah, we know about the cleanmarker. */ 964 /* Yeah, we know about the cleanmarker. */
970 if (mode && i >= c->fsdata_pos && 965 if (mode && i >= c->fsdata_pos &&
971 i < c->fsdata_pos + c->fsdata_len) 966 i < c->fsdata_pos + c->fsdata_len)
972 continue; 967 continue;
973 968
974 if (buf[i] != 0xFF) { 969 if (buf[i] != 0xFF) {
975 D2(printk(KERN_DEBUG "Found %02x at %x in OOB for %08x\n", 970 D2(printk(KERN_DEBUG "Found %02x at %x in OOB for %08x\n",
976 buf[page+i], page+i, jeb->offset)); 971 buf[i], i, jeb->offset));
977 ret = 1; 972 ret = 1;
978 goto out; 973 goto out;
979 } 974 }
980 } 975 }
981 976
982 /* we know, we are aligned :) */ 977 /* we know, we are aligned :) */
983 for (page = oob_size; page < len; page += sizeof(long)) { 978 for (page = oob_size; page < len; page += sizeof(long)) {
984 unsigned long dat = *(unsigned long *)(&buf[page]); 979 unsigned long dat = *(unsigned long *)(&buf[page]);
985 if(dat != -1) { 980 if(dat != -1) {
986 ret = 1; 981 ret = 1;
987 goto out; 982 goto out;
988 } 983 }
989 } 984 }
990 985
991out: 986out:
992 kfree(buf); 987 kfree(buf);
993 988
994 return ret; 989 return ret;
995} 990}
996 991
@@ -1072,7 +1067,7 @@ int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_erasebloc
1072 n.totlen = cpu_to_je32(8); 1067 n.totlen = cpu_to_je32(8);
1073 1068
1074 ret = jffs2_flash_write_oob(c, jeb->offset + c->fsdata_pos, c->fsdata_len, &retlen, (unsigned char *)&n); 1069 ret = jffs2_flash_write_oob(c, jeb->offset + c->fsdata_pos, c->fsdata_len, &retlen, (unsigned char *)&n);
1075 1070
1076 if (ret) { 1071 if (ret) {
1077 D1(printk(KERN_WARNING "jffs2_write_nand_cleanmarker(): Write failed for block at %08x: error %d\n", jeb->offset, ret)); 1072 D1(printk(KERN_WARNING "jffs2_write_nand_cleanmarker(): Write failed for block at %08x: error %d\n", jeb->offset, ret));
1078 return ret; 1073 return ret;
@@ -1084,7 +1079,7 @@ int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_erasebloc
1084 return 0; 1079 return 0;
1085} 1080}
1086 1081
1087/* 1082/*
1088 * On NAND we try to mark this block bad. If the block was erased more 1083 * On NAND we try to mark this block bad. If the block was erased more
1089 * than MAX_ERASE_FAILURES we mark it finaly bad. 1084 * than MAX_ERASE_FAILURES we mark it finaly bad.
1090 * Don't care about failures. This block remains on the erase-pending 1085 * Don't care about failures. This block remains on the erase-pending
@@ -1105,7 +1100,7 @@ int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *
1105 1100
1106 D1(printk(KERN_WARNING "jffs2_write_nand_badblock(): Marking bad block at %08x\n", bad_offset)); 1101 D1(printk(KERN_WARNING "jffs2_write_nand_badblock(): Marking bad block at %08x\n", bad_offset));
1107 ret = c->mtd->block_markbad(c->mtd, bad_offset); 1102 ret = c->mtd->block_markbad(c->mtd, bad_offset);
1108 1103
1109 if (ret) { 1104 if (ret) {
1110 D1(printk(KERN_WARNING "jffs2_write_nand_badblock(): Write failed for block at %08x: error %d\n", jeb->offset, ret)); 1105 D1(printk(KERN_WARNING "jffs2_write_nand_badblock(): Write failed for block at %08x: error %d\n", jeb->offset, ret));
1111 return ret; 1106 return ret;
@@ -1129,7 +1124,7 @@ static int jffs2_nand_set_oobinfo(struct jffs2_sb_info *c)
1129 /* Do this only, if we have an oob buffer */ 1124 /* Do this only, if we have an oob buffer */
1130 if (!c->mtd->oobsize) 1125 if (!c->mtd->oobsize)
1131 return 0; 1126 return 0;
1132 1127
1133 /* Cleanmarker is out-of-band, so inline size zero */ 1128 /* Cleanmarker is out-of-band, so inline size zero */
1134 c->cleanmarker_size = 0; 1129 c->cleanmarker_size = 0;
1135 1130
@@ -1155,7 +1150,7 @@ static int jffs2_nand_set_oobinfo(struct jffs2_sb_info *c)
1155 c->fsdata_len = NAND_JFFS2_OOB16_FSDALEN; 1150 c->fsdata_len = NAND_JFFS2_OOB16_FSDALEN;
1156 c->badblock_pos = 15; 1151 c->badblock_pos = 15;
1157 break; 1152 break;
1158 1153
1159 default: 1154 default:
1160 D1(printk(KERN_DEBUG "JFFS2 on NAND. No autoplacment info found\n")); 1155 D1(printk(KERN_DEBUG "JFFS2 on NAND. No autoplacment info found\n"));
1161 return -EINVAL; 1156 return -EINVAL;
@@ -1172,7 +1167,7 @@ int jffs2_nand_flash_setup(struct jffs2_sb_info *c)
1172 init_rwsem(&c->wbuf_sem); 1167 init_rwsem(&c->wbuf_sem);
1173 c->wbuf_pagesize = c->mtd->oobblock; 1168 c->wbuf_pagesize = c->mtd->oobblock;
1174 c->wbuf_ofs = 0xFFFFFFFF; 1169 c->wbuf_ofs = 0xFFFFFFFF;
1175 1170
1176 c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL); 1171 c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
1177 if (!c->wbuf) 1172 if (!c->wbuf)
1178 return -ENOMEM; 1173 return -ENOMEM;
@@ -1198,17 +1193,41 @@ void jffs2_nand_flash_cleanup(struct jffs2_sb_info *c)
1198 1193
1199int jffs2_dataflash_setup(struct jffs2_sb_info *c) { 1194int jffs2_dataflash_setup(struct jffs2_sb_info *c) {
1200 c->cleanmarker_size = 0; /* No cleanmarkers needed */ 1195 c->cleanmarker_size = 0; /* No cleanmarkers needed */
1201 1196
1202 /* Initialize write buffer */ 1197 /* Initialize write buffer */
1203 init_rwsem(&c->wbuf_sem); 1198 init_rwsem(&c->wbuf_sem);
1204 c->wbuf_pagesize = c->sector_size;
1205 c->wbuf_ofs = 0xFFFFFFFF;
1206 1199
1200
1201 c->wbuf_pagesize = c->mtd->erasesize;
1202
1203 /* Find a suitable c->sector_size
1204 * - Not too much sectors
1205 * - Sectors have to be at least 4 K + some bytes
1206 * - All known dataflashes have erase sizes of 528 or 1056
1207 * - we take at least 8 eraseblocks and want to have at least 8K size
1208 * - The concatenation should be a power of 2
1209 */
1210
1211 c->sector_size = 8 * c->mtd->erasesize;
1212
1213 while (c->sector_size < 8192) {
1214 c->sector_size *= 2;
1215 }
1216
1217 /* It may be necessary to adjust the flash size */
1218 c->flash_size = c->mtd->size;
1219
1220 if ((c->flash_size % c->sector_size) != 0) {
1221 c->flash_size = (c->flash_size / c->sector_size) * c->sector_size;
1222 printk(KERN_WARNING "JFFS2 flash size adjusted to %dKiB\n", c->flash_size);
1223 };
1224
1225 c->wbuf_ofs = 0xFFFFFFFF;
1207 c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL); 1226 c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
1208 if (!c->wbuf) 1227 if (!c->wbuf)
1209 return -ENOMEM; 1228 return -ENOMEM;
1210 1229
1211 printk(KERN_INFO "JFFS2 write-buffering enabled (%i)\n", c->wbuf_pagesize); 1230 printk(KERN_INFO "JFFS2 write-buffering enabled buffer (%d) erasesize (%d)\n", c->wbuf_pagesize, c->sector_size);
1212 1231
1213 return 0; 1232 return 0;
1214} 1233}
@@ -1236,3 +1255,23 @@ int jffs2_nor_ecc_flash_setup(struct jffs2_sb_info *c) {
1236void jffs2_nor_ecc_flash_cleanup(struct jffs2_sb_info *c) { 1255void jffs2_nor_ecc_flash_cleanup(struct jffs2_sb_info *c) {
1237 kfree(c->wbuf); 1256 kfree(c->wbuf);
1238} 1257}
1258
1259int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c) {
1260 /* Cleanmarker currently occupies a whole programming region */
1261 c->cleanmarker_size = MTD_PROGREGION_SIZE(c->mtd);
1262
1263 /* Initialize write buffer */
1264 init_rwsem(&c->wbuf_sem);
1265 c->wbuf_pagesize = MTD_PROGREGION_SIZE(c->mtd);
1266 c->wbuf_ofs = 0xFFFFFFFF;
1267
1268 c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
1269 if (!c->wbuf)
1270 return -ENOMEM;
1271
1272 return 0;
1273}
1274
1275void jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c) {
1276 kfree(c->wbuf);
1277}
diff --git a/fs/jffs2/write.c b/fs/jffs2/write.c
index 69100615d9ae..1342f0158e9b 100644
--- a/fs/jffs2/write.c
+++ b/fs/jffs2/write.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: write.c,v 1.92 2005/04/13 13:22:35 dwmw2 Exp $ 10 * $Id: write.c,v 1.97 2005/11/07 11:14:42 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -54,35 +54,7 @@ int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint
54 return 0; 54 return 0;
55} 55}
56 56
57#if CONFIG_JFFS2_FS_DEBUG > 0 57/* jffs2_write_dnode - given a raw_inode, allocate a full_dnode for it,
58static void writecheck(struct jffs2_sb_info *c, uint32_t ofs)
59{
60 unsigned char buf[16];
61 size_t retlen;
62 int ret, i;
63
64 ret = jffs2_flash_read(c, ofs, 16, &retlen, buf);
65 if (ret || (retlen != 16)) {
66 D1(printk(KERN_DEBUG "read failed or short in writecheck(). ret %d, retlen %zd\n", ret, retlen));
67 return;
68 }
69 ret = 0;
70 for (i=0; i<16; i++) {
71 if (buf[i] != 0xff)
72 ret = 1;
73 }
74 if (ret) {
75 printk(KERN_WARNING "ARGH. About to write node to 0x%08x on flash, but there are data already there:\n", ofs);
76 printk(KERN_WARNING "0x%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
77 ofs,
78 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
79 buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]);
80 }
81}
82#endif
83
84
85/* jffs2_write_dnode - given a raw_inode, allocate a full_dnode for it,
86 write it to the flash, link it into the existing inode/fragment list */ 58 write it to the flash, link it into the existing inode/fragment list */
87 59
88struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs, int alloc_mode) 60struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs, int alloc_mode)
@@ -106,7 +78,7 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
106 vecs[1].iov_base = (unsigned char *)data; 78 vecs[1].iov_base = (unsigned char *)data;
107 vecs[1].iov_len = datalen; 79 vecs[1].iov_len = datalen;
108 80
109 D1(writecheck(c, flash_ofs)); 81 jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
110 82
111 if (je32_to_cpu(ri->totlen) != sizeof(*ri) + datalen) { 83 if (je32_to_cpu(ri->totlen) != sizeof(*ri) + datalen) {
112 printk(KERN_WARNING "jffs2_write_dnode: ri->totlen (0x%08x) != sizeof(*ri) (0x%08zx) + datalen (0x%08x)\n", je32_to_cpu(ri->totlen), sizeof(*ri), datalen); 84 printk(KERN_WARNING "jffs2_write_dnode: ri->totlen (0x%08x) != sizeof(*ri) (0x%08zx) + datalen (0x%08x)\n", je32_to_cpu(ri->totlen), sizeof(*ri), datalen);
@@ -114,7 +86,7 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
114 raw = jffs2_alloc_raw_node_ref(); 86 raw = jffs2_alloc_raw_node_ref();
115 if (!raw) 87 if (!raw)
116 return ERR_PTR(-ENOMEM); 88 return ERR_PTR(-ENOMEM);
117 89
118 fn = jffs2_alloc_full_dnode(); 90 fn = jffs2_alloc_full_dnode();
119 if (!fn) { 91 if (!fn) {
120 jffs2_free_raw_node_ref(raw); 92 jffs2_free_raw_node_ref(raw);
@@ -138,7 +110,7 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
138 if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) { 110 if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) {
139 BUG_ON(!retried); 111 BUG_ON(!retried);
140 D1(printk(KERN_DEBUG "jffs2_write_dnode : dnode_version %d, " 112 D1(printk(KERN_DEBUG "jffs2_write_dnode : dnode_version %d, "
141 "highest version %d -> updating dnode\n", 113 "highest version %d -> updating dnode\n",
142 je32_to_cpu(ri->version), f->highest_version)); 114 je32_to_cpu(ri->version), f->highest_version));
143 ri->version = cpu_to_je32(++f->highest_version); 115 ri->version = cpu_to_je32(++f->highest_version);
144 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 116 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
@@ -148,7 +120,7 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
148 (alloc_mode==ALLOC_GC)?0:f->inocache->ino); 120 (alloc_mode==ALLOC_GC)?0:f->inocache->ino);
149 121
150 if (ret || (retlen != sizeof(*ri) + datalen)) { 122 if (ret || (retlen != sizeof(*ri) + datalen)) {
151 printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n", 123 printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n",
152 sizeof(*ri)+datalen, flash_ofs, ret, retlen); 124 sizeof(*ri)+datalen, flash_ofs, ret, retlen);
153 125
154 /* Mark the space as dirtied */ 126 /* Mark the space as dirtied */
@@ -156,10 +128,10 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
156 /* Doesn't belong to any inode */ 128 /* Doesn't belong to any inode */
157 raw->next_in_ino = NULL; 129 raw->next_in_ino = NULL;
158 130
159 /* Don't change raw->size to match retlen. We may have 131 /* Don't change raw->size to match retlen. We may have
160 written the node header already, and only the data will 132 written the node header already, and only the data will
161 seem corrupted, in which case the scan would skip over 133 seem corrupted, in which case the scan would skip over
162 any node we write before the original intended end of 134 any node we write before the original intended end of
163 this node */ 135 this node */
164 raw->flash_offset |= REF_OBSOLETE; 136 raw->flash_offset |= REF_OBSOLETE;
165 jffs2_add_physical_node_ref(c, raw); 137 jffs2_add_physical_node_ref(c, raw);
@@ -176,26 +148,28 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
176 retried = 1; 148 retried = 1;
177 149
178 D1(printk(KERN_DEBUG "Retrying failed write.\n")); 150 D1(printk(KERN_DEBUG "Retrying failed write.\n"));
179 151
180 ACCT_SANITY_CHECK(c,jeb); 152 jffs2_dbg_acct_sanity_check(c,jeb);
181 D1(ACCT_PARANOIA_CHECK(jeb)); 153 jffs2_dbg_acct_paranoia_check(c, jeb);
182 154
183 if (alloc_mode == ALLOC_GC) { 155 if (alloc_mode == ALLOC_GC) {
184 ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &flash_ofs, &dummy); 156 ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &flash_ofs,
157 &dummy, JFFS2_SUMMARY_INODE_SIZE);
185 } else { 158 } else {
186 /* Locking pain */ 159 /* Locking pain */
187 up(&f->sem); 160 up(&f->sem);
188 jffs2_complete_reservation(c); 161 jffs2_complete_reservation(c);
189 162
190 ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &flash_ofs, &dummy, alloc_mode); 163 ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &flash_ofs,
164 &dummy, alloc_mode, JFFS2_SUMMARY_INODE_SIZE);
191 down(&f->sem); 165 down(&f->sem);
192 } 166 }
193 167
194 if (!ret) { 168 if (!ret) {
195 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs)); 169 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs));
196 170
197 ACCT_SANITY_CHECK(c,jeb); 171 jffs2_dbg_acct_sanity_check(c,jeb);
198 D1(ACCT_PARANOIA_CHECK(jeb)); 172 jffs2_dbg_acct_paranoia_check(c, jeb);
199 173
200 goto retry; 174 goto retry;
201 } 175 }
@@ -207,9 +181,9 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
207 return ERR_PTR(ret?ret:-EIO); 181 return ERR_PTR(ret?ret:-EIO);
208 } 182 }
209 /* Mark the space used */ 183 /* Mark the space used */
210 /* If node covers at least a whole page, or if it starts at the 184 /* If node covers at least a whole page, or if it starts at the
211 beginning of a page and runs to the end of the file, or if 185 beginning of a page and runs to the end of the file, or if
212 it's a hole node, mark it REF_PRISTINE, else REF_NORMAL. 186 it's a hole node, mark it REF_PRISTINE, else REF_NORMAL.
213 */ 187 */
214 if ((je32_to_cpu(ri->dsize) >= PAGE_CACHE_SIZE) || 188 if ((je32_to_cpu(ri->dsize) >= PAGE_CACHE_SIZE) ||
215 ( ((je32_to_cpu(ri->offset)&(PAGE_CACHE_SIZE-1))==0) && 189 ( ((je32_to_cpu(ri->offset)&(PAGE_CACHE_SIZE-1))==0) &&
@@ -227,12 +201,12 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
227 spin_unlock(&c->erase_completion_lock); 201 spin_unlock(&c->erase_completion_lock);
228 202
229 D1(printk(KERN_DEBUG "jffs2_write_dnode wrote node at 0x%08x(%d) with dsize 0x%x, csize 0x%x, node_crc 0x%08x, data_crc 0x%08x, totlen 0x%08x\n", 203 D1(printk(KERN_DEBUG "jffs2_write_dnode wrote node at 0x%08x(%d) with dsize 0x%x, csize 0x%x, node_crc 0x%08x, data_crc 0x%08x, totlen 0x%08x\n",
230 flash_ofs, ref_flags(raw), je32_to_cpu(ri->dsize), 204 flash_ofs, ref_flags(raw), je32_to_cpu(ri->dsize),
231 je32_to_cpu(ri->csize), je32_to_cpu(ri->node_crc), 205 je32_to_cpu(ri->csize), je32_to_cpu(ri->node_crc),
232 je32_to_cpu(ri->data_crc), je32_to_cpu(ri->totlen))); 206 je32_to_cpu(ri->data_crc), je32_to_cpu(ri->totlen)));
233 207
234 if (retried) { 208 if (retried) {
235 ACCT_SANITY_CHECK(c,NULL); 209 jffs2_dbg_acct_sanity_check(c,NULL);
236 } 210 }
237 211
238 return fn; 212 return fn;
@@ -247,10 +221,9 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
247 int retried = 0; 221 int retried = 0;
248 int ret; 222 int ret;
249 223
250 D1(printk(KERN_DEBUG "jffs2_write_dirent(ino #%u, name at *0x%p \"%s\"->ino #%u, name_crc 0x%08x)\n", 224 D1(printk(KERN_DEBUG "jffs2_write_dirent(ino #%u, name at *0x%p \"%s\"->ino #%u, name_crc 0x%08x)\n",
251 je32_to_cpu(rd->pino), name, name, je32_to_cpu(rd->ino), 225 je32_to_cpu(rd->pino), name, name, je32_to_cpu(rd->ino),
252 je32_to_cpu(rd->name_crc))); 226 je32_to_cpu(rd->name_crc)));
253 D1(writecheck(c, flash_ofs));
254 227
255 D1(if(je32_to_cpu(rd->hdr_crc) != crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)) { 228 D1(if(je32_to_cpu(rd->hdr_crc) != crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)) {
256 printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dirent()\n"); 229 printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dirent()\n");
@@ -262,7 +235,9 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
262 vecs[0].iov_len = sizeof(*rd); 235 vecs[0].iov_len = sizeof(*rd);
263 vecs[1].iov_base = (unsigned char *)name; 236 vecs[1].iov_base = (unsigned char *)name;
264 vecs[1].iov_len = namelen; 237 vecs[1].iov_len = namelen;
265 238
239 jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
240
266 raw = jffs2_alloc_raw_node_ref(); 241 raw = jffs2_alloc_raw_node_ref();
267 242
268 if (!raw) 243 if (!raw)
@@ -301,7 +276,7 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
301 ret = jffs2_flash_writev(c, vecs, 2, flash_ofs, &retlen, 276 ret = jffs2_flash_writev(c, vecs, 2, flash_ofs, &retlen,
302 (alloc_mode==ALLOC_GC)?0:je32_to_cpu(rd->pino)); 277 (alloc_mode==ALLOC_GC)?0:je32_to_cpu(rd->pino));
303 if (ret || (retlen != sizeof(*rd) + namelen)) { 278 if (ret || (retlen != sizeof(*rd) + namelen)) {
304 printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n", 279 printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n",
305 sizeof(*rd)+namelen, flash_ofs, ret, retlen); 280 sizeof(*rd)+namelen, flash_ofs, ret, retlen);
306 /* Mark the space as dirtied */ 281 /* Mark the space as dirtied */
307 if (retlen) { 282 if (retlen) {
@@ -322,24 +297,26 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
322 297
323 D1(printk(KERN_DEBUG "Retrying failed write.\n")); 298 D1(printk(KERN_DEBUG "Retrying failed write.\n"));
324 299
325 ACCT_SANITY_CHECK(c,jeb); 300 jffs2_dbg_acct_sanity_check(c,jeb);
326 D1(ACCT_PARANOIA_CHECK(jeb)); 301 jffs2_dbg_acct_paranoia_check(c, jeb);
327 302
328 if (alloc_mode == ALLOC_GC) { 303 if (alloc_mode == ALLOC_GC) {
329 ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &flash_ofs, &dummy); 304 ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &flash_ofs,
305 &dummy, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
330 } else { 306 } else {
331 /* Locking pain */ 307 /* Locking pain */
332 up(&f->sem); 308 up(&f->sem);
333 jffs2_complete_reservation(c); 309 jffs2_complete_reservation(c);
334 310
335 ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &flash_ofs, &dummy, alloc_mode); 311 ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &flash_ofs,
312 &dummy, alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
336 down(&f->sem); 313 down(&f->sem);
337 } 314 }
338 315
339 if (!ret) { 316 if (!ret) {
340 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs)); 317 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs));
341 ACCT_SANITY_CHECK(c,jeb); 318 jffs2_dbg_acct_sanity_check(c,jeb);
342 D1(ACCT_PARANOIA_CHECK(jeb)); 319 jffs2_dbg_acct_paranoia_check(c, jeb);
343 goto retry; 320 goto retry;
344 } 321 }
345 D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret)); 322 D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret));
@@ -359,7 +336,7 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
359 spin_unlock(&c->erase_completion_lock); 336 spin_unlock(&c->erase_completion_lock);
360 337
361 if (retried) { 338 if (retried) {
362 ACCT_SANITY_CHECK(c,NULL); 339 jffs2_dbg_acct_sanity_check(c,NULL);
363 } 340 }
364 341
365 return fd; 342 return fd;
@@ -369,7 +346,7 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
369 we don't have to go digging in struct inode or its equivalent. It should set: 346 we don't have to go digging in struct inode or its equivalent. It should set:
370 mode, uid, gid, (starting)isize, atime, ctime, mtime */ 347 mode, uid, gid, (starting)isize, atime, ctime, mtime */
371int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 348int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
372 struct jffs2_raw_inode *ri, unsigned char *buf, 349 struct jffs2_raw_inode *ri, unsigned char *buf,
373 uint32_t offset, uint32_t writelen, uint32_t *retlen) 350 uint32_t offset, uint32_t writelen, uint32_t *retlen)
374{ 351{
375 int ret = 0; 352 int ret = 0;
@@ -377,7 +354,7 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
377 354
378 D1(printk(KERN_DEBUG "jffs2_write_inode_range(): Ino #%u, ofs 0x%x, len 0x%x\n", 355 D1(printk(KERN_DEBUG "jffs2_write_inode_range(): Ino #%u, ofs 0x%x, len 0x%x\n",
379 f->inocache->ino, offset, writelen)); 356 f->inocache->ino, offset, writelen));
380 357
381 while(writelen) { 358 while(writelen) {
382 struct jffs2_full_dnode *fn; 359 struct jffs2_full_dnode *fn;
383 unsigned char *comprbuf = NULL; 360 unsigned char *comprbuf = NULL;
@@ -389,7 +366,8 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
389 retry: 366 retry:
390 D2(printk(KERN_DEBUG "jffs2_commit_write() loop: 0x%x to write to 0x%x\n", writelen, offset)); 367 D2(printk(KERN_DEBUG "jffs2_commit_write() loop: 0x%x to write to 0x%x\n", writelen, offset));
391 368
392 ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN, &phys_ofs, &alloclen, ALLOC_NORMAL); 369 ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN, &phys_ofs,
370 &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
393 if (ret) { 371 if (ret) {
394 D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret)); 372 D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret));
395 break; 373 break;
@@ -473,10 +451,11 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
473 uint32_t alloclen, phys_ofs; 451 uint32_t alloclen, phys_ofs;
474 int ret; 452 int ret;
475 453
476 /* Try to reserve enough space for both node and dirent. 454 /* Try to reserve enough space for both node and dirent.
477 * Just the node will do for now, though 455 * Just the node will do for now, though
478 */ 456 */
479 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL); 457 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL,
458 JFFS2_SUMMARY_INODE_SIZE);
480 D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen)); 459 D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen));
481 if (ret) { 460 if (ret) {
482 up(&f->sem); 461 up(&f->sem);
@@ -498,15 +477,16 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
498 jffs2_complete_reservation(c); 477 jffs2_complete_reservation(c);
499 return PTR_ERR(fn); 478 return PTR_ERR(fn);
500 } 479 }
501 /* No data here. Only a metadata node, which will be 480 /* No data here. Only a metadata node, which will be
502 obsoleted by the first data write 481 obsoleted by the first data write
503 */ 482 */
504 f->metadata = fn; 483 f->metadata = fn;
505 484
506 up(&f->sem); 485 up(&f->sem);
507 jffs2_complete_reservation(c); 486 jffs2_complete_reservation(c);
508 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL); 487 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
509 488 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
489
510 if (ret) { 490 if (ret) {
511 /* Eep. */ 491 /* Eep. */
512 D1(printk(KERN_DEBUG "jffs2_reserve_space() for dirent failed\n")); 492 D1(printk(KERN_DEBUG "jffs2_reserve_space() for dirent failed\n"));
@@ -539,9 +519,9 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
539 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL); 519 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL);
540 520
541 jffs2_free_raw_dirent(rd); 521 jffs2_free_raw_dirent(rd);
542 522
543 if (IS_ERR(fd)) { 523 if (IS_ERR(fd)) {
544 /* dirent failed to write. Delete the inode normally 524 /* dirent failed to write. Delete the inode normally
545 as if it were the final unlink() */ 525 as if it were the final unlink() */
546 jffs2_complete_reservation(c); 526 jffs2_complete_reservation(c);
547 up(&dir_f->sem); 527 up(&dir_f->sem);
@@ -560,14 +540,15 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
560 540
561 541
562int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, 542int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
563 const char *name, int namelen, struct jffs2_inode_info *dead_f) 543 const char *name, int namelen, struct jffs2_inode_info *dead_f,
544 uint32_t time)
564{ 545{
565 struct jffs2_raw_dirent *rd; 546 struct jffs2_raw_dirent *rd;
566 struct jffs2_full_dirent *fd; 547 struct jffs2_full_dirent *fd;
567 uint32_t alloclen, phys_ofs; 548 uint32_t alloclen, phys_ofs;
568 int ret; 549 int ret;
569 550
570 if (1 /* alternative branch needs testing */ || 551 if (1 /* alternative branch needs testing */ ||
571 !jffs2_can_mark_obsolete(c)) { 552 !jffs2_can_mark_obsolete(c)) {
572 /* We can't mark stuff obsolete on the medium. We need to write a deletion dirent */ 553 /* We can't mark stuff obsolete on the medium. We need to write a deletion dirent */
573 554
@@ -575,7 +556,8 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
575 if (!rd) 556 if (!rd)
576 return -ENOMEM; 557 return -ENOMEM;
577 558
578 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_DELETION); 559 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
560 ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
579 if (ret) { 561 if (ret) {
580 jffs2_free_raw_dirent(rd); 562 jffs2_free_raw_dirent(rd);
581 return ret; 563 return ret;
@@ -588,18 +570,18 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
588 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT); 570 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
589 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen); 571 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
590 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)); 572 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
591 573
592 rd->pino = cpu_to_je32(dir_f->inocache->ino); 574 rd->pino = cpu_to_je32(dir_f->inocache->ino);
593 rd->version = cpu_to_je32(++dir_f->highest_version); 575 rd->version = cpu_to_je32(++dir_f->highest_version);
594 rd->ino = cpu_to_je32(0); 576 rd->ino = cpu_to_je32(0);
595 rd->mctime = cpu_to_je32(get_seconds()); 577 rd->mctime = cpu_to_je32(time);
596 rd->nsize = namelen; 578 rd->nsize = namelen;
597 rd->type = DT_UNKNOWN; 579 rd->type = DT_UNKNOWN;
598 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 580 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
599 rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); 581 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
600 582
601 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_DELETION); 583 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_DELETION);
602 584
603 jffs2_free_raw_dirent(rd); 585 jffs2_free_raw_dirent(rd);
604 586
605 if (IS_ERR(fd)) { 587 if (IS_ERR(fd)) {
@@ -618,7 +600,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
618 down(&dir_f->sem); 600 down(&dir_f->sem);
619 601
620 while ((*prev) && (*prev)->nhash <= nhash) { 602 while ((*prev) && (*prev)->nhash <= nhash) {
621 if ((*prev)->nhash == nhash && 603 if ((*prev)->nhash == nhash &&
622 !memcmp((*prev)->name, name, namelen) && 604 !memcmp((*prev)->name, name, namelen) &&
623 !(*prev)->name[namelen]) { 605 !(*prev)->name[namelen]) {
624 struct jffs2_full_dirent *this = *prev; 606 struct jffs2_full_dirent *this = *prev;
@@ -639,7 +621,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
639 /* dead_f is NULL if this was a rename not a real unlink */ 621 /* dead_f is NULL if this was a rename not a real unlink */
640 /* Also catch the !f->inocache case, where there was a dirent 622 /* Also catch the !f->inocache case, where there was a dirent
641 pointing to an inode which didn't exist. */ 623 pointing to an inode which didn't exist. */
642 if (dead_f && dead_f->inocache) { 624 if (dead_f && dead_f->inocache) {
643 625
644 down(&dead_f->sem); 626 down(&dead_f->sem);
645 627
@@ -647,9 +629,9 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
647 while (dead_f->dents) { 629 while (dead_f->dents) {
648 /* There can be only deleted ones */ 630 /* There can be only deleted ones */
649 fd = dead_f->dents; 631 fd = dead_f->dents;
650 632
651 dead_f->dents = fd->next; 633 dead_f->dents = fd->next;
652 634
653 if (fd->ino) { 635 if (fd->ino) {
654 printk(KERN_WARNING "Deleting inode #%u with active dentry \"%s\"->ino #%u\n", 636 printk(KERN_WARNING "Deleting inode #%u with active dentry \"%s\"->ino #%u\n",
655 dead_f->inocache->ino, fd->name, fd->ino); 637 dead_f->inocache->ino, fd->name, fd->ino);
@@ -673,7 +655,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
673} 655}
674 656
675 657
676int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, uint8_t type, const char *name, int namelen) 658int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, uint8_t type, const char *name, int namelen, uint32_t time)
677{ 659{
678 struct jffs2_raw_dirent *rd; 660 struct jffs2_raw_dirent *rd;
679 struct jffs2_full_dirent *fd; 661 struct jffs2_full_dirent *fd;
@@ -684,12 +666,13 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
684 if (!rd) 666 if (!rd)
685 return -ENOMEM; 667 return -ENOMEM;
686 668
687 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL); 669 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
670 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
688 if (ret) { 671 if (ret) {
689 jffs2_free_raw_dirent(rd); 672 jffs2_free_raw_dirent(rd);
690 return ret; 673 return ret;
691 } 674 }
692 675
693 down(&dir_f->sem); 676 down(&dir_f->sem);
694 677
695 /* Build a deletion node */ 678 /* Build a deletion node */
@@ -701,7 +684,7 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
701 rd->pino = cpu_to_je32(dir_f->inocache->ino); 684 rd->pino = cpu_to_je32(dir_f->inocache->ino);
702 rd->version = cpu_to_je32(++dir_f->highest_version); 685 rd->version = cpu_to_je32(++dir_f->highest_version);
703 rd->ino = cpu_to_je32(ino); 686 rd->ino = cpu_to_je32(ino);
704 rd->mctime = cpu_to_je32(get_seconds()); 687 rd->mctime = cpu_to_je32(time);
705 rd->nsize = namelen; 688 rd->nsize = namelen;
706 689
707 rd->type = type; 690 rd->type = type;
@@ -710,7 +693,7 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
710 rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); 693 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
711 694
712 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL); 695 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL);
713 696
714 jffs2_free_raw_dirent(rd); 697 jffs2_free_raw_dirent(rd);
715 698
716 if (IS_ERR(fd)) { 699 if (IS_ERR(fd)) {
diff --git a/fs/jffs2/writev.c b/fs/jffs2/writev.c
index f079f8388566..c638ae1008de 100644
--- a/fs/jffs2/writev.c
+++ b/fs/jffs2/writev.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: writev.c,v 1.6 2004/11/16 20:36:12 dwmw2 Exp $ 10 * $Id: writev.c,v 1.8 2005/09/09 15:11:58 havasi Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -42,9 +42,40 @@ static inline int mtd_fake_writev(struct mtd_info *mtd, const struct kvec *vecs,
42int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs, 42int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
43 unsigned long count, loff_t to, size_t *retlen) 43 unsigned long count, loff_t to, size_t *retlen)
44{ 44{
45 if (!jffs2_is_writebuffered(c)) {
46 if (jffs2_sum_active()) {
47 int res;
48 res = jffs2_sum_add_kvec(c, vecs, count, (uint32_t) to);
49 if (res) {
50 return res;
51 }
52 }
53 }
54
45 if (c->mtd->writev) 55 if (c->mtd->writev)
46 return c->mtd->writev(c->mtd, vecs, count, to, retlen); 56 return c->mtd->writev(c->mtd, vecs, count, to, retlen);
47 else 57 else {
48 return mtd_fake_writev(c->mtd, vecs, count, to, retlen); 58 return mtd_fake_writev(c->mtd, vecs, count, to, retlen);
59 }
49} 60}
50 61
62int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
63 size_t *retlen, const u_char *buf)
64{
65 int ret;
66 ret = c->mtd->write(c->mtd, ofs, len, retlen, buf);
67
68 if (jffs2_sum_active()) {
69 struct kvec vecs[1];
70 int res;
71
72 vecs[0].iov_base = (unsigned char *) buf;
73 vecs[0].iov_len = len;
74
75 res = jffs2_sum_add_kvec(c, vecs, 1, (uint32_t) ofs);
76 if (res) {
77 return res;
78 }
79 }
80 return ret;
81}
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index 87332f30141b..c5a33648e9fd 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -112,8 +112,7 @@ static struct nlm_lockowner *nlm_find_lockowner(struct nlm_host *host, fl_owner_
112 } 112 }
113 } 113 }
114 spin_unlock(&host->h_lock); 114 spin_unlock(&host->h_lock);
115 if (new != NULL) 115 kfree(new);
116 kfree(new);
117 return res; 116 return res;
118} 117}
119 118
diff --git a/fs/mbcache.c b/fs/mbcache.c
index 298997f17475..0f1e4530670f 100644
--- a/fs/mbcache.c
+++ b/fs/mbcache.c
@@ -301,8 +301,7 @@ fail:
301 if (cache) { 301 if (cache) {
302 while (--m >= 0) 302 while (--m >= 0)
303 kfree(cache->c_indexes_hash[m]); 303 kfree(cache->c_indexes_hash[m]);
304 if (cache->c_block_hash) 304 kfree(cache->c_block_hash);
305 kfree(cache->c_block_hash);
306 kfree(cache); 305 kfree(cache);
307 } 306 }
308 return NULL; 307 return NULL;
diff --git a/fs/namei.c b/fs/namei.c
index c5769c4fcab1..b3f8a1966c9c 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1459,7 +1459,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
1459 if (!error) { 1459 if (!error) {
1460 DQUOT_INIT(inode); 1460 DQUOT_INIT(inode);
1461 1461
1462 error = do_truncate(dentry, 0); 1462 error = do_truncate(dentry, 0, NULL);
1463 } 1463 }
1464 put_write_access(inode); 1464 put_write_access(inode);
1465 if (error) 1465 if (error)
diff --git a/fs/namespace.c b/fs/namespace.c
index 2fa9fdf7d6f5..caa9187f67e5 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -24,6 +24,7 @@
24#include <linux/mount.h> 24#include <linux/mount.h>
25#include <asm/uaccess.h> 25#include <asm/uaccess.h>
26#include <asm/unistd.h> 26#include <asm/unistd.h>
27#include "pnode.h"
27 28
28extern int __init init_rootfs(void); 29extern int __init init_rootfs(void);
29 30
@@ -37,33 +38,39 @@ static inline int sysfs_init(void)
37#endif 38#endif
38 39
39/* spinlock for vfsmount related operations, inplace of dcache_lock */ 40/* spinlock for vfsmount related operations, inplace of dcache_lock */
40 __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock); 41__cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
42
43static int event;
41 44
42static struct list_head *mount_hashtable; 45static struct list_head *mount_hashtable;
43static int hash_mask __read_mostly, hash_bits __read_mostly; 46static int hash_mask __read_mostly, hash_bits __read_mostly;
44static kmem_cache_t *mnt_cache; 47static kmem_cache_t *mnt_cache;
48static struct rw_semaphore namespace_sem;
45 49
46static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry) 50static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
47{ 51{
48 unsigned long tmp = ((unsigned long) mnt / L1_CACHE_BYTES); 52 unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES);
49 tmp += ((unsigned long) dentry / L1_CACHE_BYTES); 53 tmp += ((unsigned long)dentry / L1_CACHE_BYTES);
50 tmp = tmp + (tmp >> hash_bits); 54 tmp = tmp + (tmp >> hash_bits);
51 return tmp & hash_mask; 55 return tmp & hash_mask;
52} 56}
53 57
54struct vfsmount *alloc_vfsmnt(const char *name) 58struct vfsmount *alloc_vfsmnt(const char *name)
55{ 59{
56 struct vfsmount *mnt = kmem_cache_alloc(mnt_cache, GFP_KERNEL); 60 struct vfsmount *mnt = kmem_cache_alloc(mnt_cache, GFP_KERNEL);
57 if (mnt) { 61 if (mnt) {
58 memset(mnt, 0, sizeof(struct vfsmount)); 62 memset(mnt, 0, sizeof(struct vfsmount));
59 atomic_set(&mnt->mnt_count,1); 63 atomic_set(&mnt->mnt_count, 1);
60 INIT_LIST_HEAD(&mnt->mnt_hash); 64 INIT_LIST_HEAD(&mnt->mnt_hash);
61 INIT_LIST_HEAD(&mnt->mnt_child); 65 INIT_LIST_HEAD(&mnt->mnt_child);
62 INIT_LIST_HEAD(&mnt->mnt_mounts); 66 INIT_LIST_HEAD(&mnt->mnt_mounts);
63 INIT_LIST_HEAD(&mnt->mnt_list); 67 INIT_LIST_HEAD(&mnt->mnt_list);
64 INIT_LIST_HEAD(&mnt->mnt_expire); 68 INIT_LIST_HEAD(&mnt->mnt_expire);
69 INIT_LIST_HEAD(&mnt->mnt_share);
70 INIT_LIST_HEAD(&mnt->mnt_slave_list);
71 INIT_LIST_HEAD(&mnt->mnt_slave);
65 if (name) { 72 if (name) {
66 int size = strlen(name)+1; 73 int size = strlen(name) + 1;
67 char *newname = kmalloc(size, GFP_KERNEL); 74 char *newname = kmalloc(size, GFP_KERNEL);
68 if (newname) { 75 if (newname) {
69 memcpy(newname, name, size); 76 memcpy(newname, name, size);
@@ -81,36 +88,65 @@ void free_vfsmnt(struct vfsmount *mnt)
81} 88}
82 89
83/* 90/*
84 * Now, lookup_mnt increments the ref count before returning 91 * find the first or last mount at @dentry on vfsmount @mnt depending on
85 * the vfsmount struct. 92 * @dir. If @dir is set return the first mount else return the last mount.
86 */ 93 */
87struct vfsmount *lookup_mnt(struct vfsmount *mnt, struct dentry *dentry) 94struct vfsmount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry,
95 int dir)
88{ 96{
89 struct list_head * head = mount_hashtable + hash(mnt, dentry); 97 struct list_head *head = mount_hashtable + hash(mnt, dentry);
90 struct list_head * tmp = head; 98 struct list_head *tmp = head;
91 struct vfsmount *p, *found = NULL; 99 struct vfsmount *p, *found = NULL;
92 100
93 spin_lock(&vfsmount_lock);
94 for (;;) { 101 for (;;) {
95 tmp = tmp->next; 102 tmp = dir ? tmp->next : tmp->prev;
96 p = NULL; 103 p = NULL;
97 if (tmp == head) 104 if (tmp == head)
98 break; 105 break;
99 p = list_entry(tmp, struct vfsmount, mnt_hash); 106 p = list_entry(tmp, struct vfsmount, mnt_hash);
100 if (p->mnt_parent == mnt && p->mnt_mountpoint == dentry) { 107 if (p->mnt_parent == mnt && p->mnt_mountpoint == dentry) {
101 found = mntget(p); 108 found = p;
102 break; 109 break;
103 } 110 }
104 } 111 }
105 spin_unlock(&vfsmount_lock);
106 return found; 112 return found;
107} 113}
108 114
115/*
116 * lookup_mnt increments the ref count before returning
117 * the vfsmount struct.
118 */
119struct vfsmount *lookup_mnt(struct vfsmount *mnt, struct dentry *dentry)
120{
121 struct vfsmount *child_mnt;
122 spin_lock(&vfsmount_lock);
123 if ((child_mnt = __lookup_mnt(mnt, dentry, 1)))
124 mntget(child_mnt);
125 spin_unlock(&vfsmount_lock);
126 return child_mnt;
127}
128
109static inline int check_mnt(struct vfsmount *mnt) 129static inline int check_mnt(struct vfsmount *mnt)
110{ 130{
111 return mnt->mnt_namespace == current->namespace; 131 return mnt->mnt_namespace == current->namespace;
112} 132}
113 133
134static void touch_namespace(struct namespace *ns)
135{
136 if (ns) {
137 ns->event = ++event;
138 wake_up_interruptible(&ns->poll);
139 }
140}
141
142static void __touch_namespace(struct namespace *ns)
143{
144 if (ns && ns->event != event) {
145 ns->event = event;
146 wake_up_interruptible(&ns->poll);
147 }
148}
149
114static void detach_mnt(struct vfsmount *mnt, struct nameidata *old_nd) 150static void detach_mnt(struct vfsmount *mnt, struct nameidata *old_nd)
115{ 151{
116 old_nd->dentry = mnt->mnt_mountpoint; 152 old_nd->dentry = mnt->mnt_mountpoint;
@@ -122,13 +158,43 @@ static void detach_mnt(struct vfsmount *mnt, struct nameidata *old_nd)
122 old_nd->dentry->d_mounted--; 158 old_nd->dentry->d_mounted--;
123} 159}
124 160
161void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry,
162 struct vfsmount *child_mnt)
163{
164 child_mnt->mnt_parent = mntget(mnt);
165 child_mnt->mnt_mountpoint = dget(dentry);
166 dentry->d_mounted++;
167}
168
125static void attach_mnt(struct vfsmount *mnt, struct nameidata *nd) 169static void attach_mnt(struct vfsmount *mnt, struct nameidata *nd)
126{ 170{
127 mnt->mnt_parent = mntget(nd->mnt); 171 mnt_set_mountpoint(nd->mnt, nd->dentry, mnt);
128 mnt->mnt_mountpoint = dget(nd->dentry); 172 list_add_tail(&mnt->mnt_hash, mount_hashtable +
129 list_add(&mnt->mnt_hash, mount_hashtable+hash(nd->mnt, nd->dentry)); 173 hash(nd->mnt, nd->dentry));
130 list_add_tail(&mnt->mnt_child, &nd->mnt->mnt_mounts); 174 list_add_tail(&mnt->mnt_child, &nd->mnt->mnt_mounts);
131 nd->dentry->d_mounted++; 175}
176
177/*
178 * the caller must hold vfsmount_lock
179 */
180static void commit_tree(struct vfsmount *mnt)
181{
182 struct vfsmount *parent = mnt->mnt_parent;
183 struct vfsmount *m;
184 LIST_HEAD(head);
185 struct namespace *n = parent->mnt_namespace;
186
187 BUG_ON(parent == mnt);
188
189 list_add_tail(&head, &mnt->mnt_list);
190 list_for_each_entry(m, &head, mnt_list)
191 m->mnt_namespace = n;
192 list_splice(&head, n->list.prev);
193
194 list_add_tail(&mnt->mnt_hash, mount_hashtable +
195 hash(parent, mnt->mnt_mountpoint));
196 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts);
197 touch_namespace(n);
132} 198}
133 199
134static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root) 200static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root)
@@ -147,8 +213,18 @@ static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root)
147 return list_entry(next, struct vfsmount, mnt_child); 213 return list_entry(next, struct vfsmount, mnt_child);
148} 214}
149 215
150static struct vfsmount * 216static struct vfsmount *skip_mnt_tree(struct vfsmount *p)
151clone_mnt(struct vfsmount *old, struct dentry *root) 217{
218 struct list_head *prev = p->mnt_mounts.prev;
219 while (prev != &p->mnt_mounts) {
220 p = list_entry(prev, struct vfsmount, mnt_child);
221 prev = p->mnt_mounts.prev;
222 }
223 return p;
224}
225
226static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root,
227 int flag)
152{ 228{
153 struct super_block *sb = old->mnt_sb; 229 struct super_block *sb = old->mnt_sb;
154 struct vfsmount *mnt = alloc_vfsmnt(old->mnt_devname); 230 struct vfsmount *mnt = alloc_vfsmnt(old->mnt_devname);
@@ -160,19 +236,34 @@ clone_mnt(struct vfsmount *old, struct dentry *root)
160 mnt->mnt_root = dget(root); 236 mnt->mnt_root = dget(root);
161 mnt->mnt_mountpoint = mnt->mnt_root; 237 mnt->mnt_mountpoint = mnt->mnt_root;
162 mnt->mnt_parent = mnt; 238 mnt->mnt_parent = mnt;
163 mnt->mnt_namespace = current->namespace; 239
240 if (flag & CL_SLAVE) {
241 list_add(&mnt->mnt_slave, &old->mnt_slave_list);
242 mnt->mnt_master = old;
243 CLEAR_MNT_SHARED(mnt);
244 } else {
245 if ((flag & CL_PROPAGATION) || IS_MNT_SHARED(old))
246 list_add(&mnt->mnt_share, &old->mnt_share);
247 if (IS_MNT_SLAVE(old))
248 list_add(&mnt->mnt_slave, &old->mnt_slave);
249 mnt->mnt_master = old->mnt_master;
250 }
251 if (flag & CL_MAKE_SHARED)
252 set_mnt_shared(mnt);
164 253
165 /* stick the duplicate mount on the same expiry list 254 /* stick the duplicate mount on the same expiry list
166 * as the original if that was on one */ 255 * as the original if that was on one */
167 spin_lock(&vfsmount_lock); 256 if (flag & CL_EXPIRE) {
168 if (!list_empty(&old->mnt_expire)) 257 spin_lock(&vfsmount_lock);
169 list_add(&mnt->mnt_expire, &old->mnt_expire); 258 if (!list_empty(&old->mnt_expire))
170 spin_unlock(&vfsmount_lock); 259 list_add(&mnt->mnt_expire, &old->mnt_expire);
260 spin_unlock(&vfsmount_lock);
261 }
171 } 262 }
172 return mnt; 263 return mnt;
173} 264}
174 265
175void __mntput(struct vfsmount *mnt) 266static inline void __mntput(struct vfsmount *mnt)
176{ 267{
177 struct super_block *sb = mnt->mnt_sb; 268 struct super_block *sb = mnt->mnt_sb;
178 dput(mnt->mnt_root); 269 dput(mnt->mnt_root);
@@ -180,7 +271,46 @@ void __mntput(struct vfsmount *mnt)
180 deactivate_super(sb); 271 deactivate_super(sb);
181} 272}
182 273
183EXPORT_SYMBOL(__mntput); 274void mntput_no_expire(struct vfsmount *mnt)
275{
276repeat:
277 if (atomic_dec_and_lock(&mnt->mnt_count, &vfsmount_lock)) {
278 if (likely(!mnt->mnt_pinned)) {
279 spin_unlock(&vfsmount_lock);
280 __mntput(mnt);
281 return;
282 }
283 atomic_add(mnt->mnt_pinned + 1, &mnt->mnt_count);
284 mnt->mnt_pinned = 0;
285 spin_unlock(&vfsmount_lock);
286 acct_auto_close_mnt(mnt);
287 security_sb_umount_close(mnt);
288 goto repeat;
289 }
290}
291
292EXPORT_SYMBOL(mntput_no_expire);
293
294void mnt_pin(struct vfsmount *mnt)
295{
296 spin_lock(&vfsmount_lock);
297 mnt->mnt_pinned++;
298 spin_unlock(&vfsmount_lock);
299}
300
301EXPORT_SYMBOL(mnt_pin);
302
303void mnt_unpin(struct vfsmount *mnt)
304{
305 spin_lock(&vfsmount_lock);
306 if (mnt->mnt_pinned) {
307 atomic_inc(&mnt->mnt_count);
308 mnt->mnt_pinned--;
309 }
310 spin_unlock(&vfsmount_lock);
311}
312
313EXPORT_SYMBOL(mnt_unpin);
184 314
185/* iterator */ 315/* iterator */
186static void *m_start(struct seq_file *m, loff_t *pos) 316static void *m_start(struct seq_file *m, loff_t *pos)
@@ -189,7 +319,7 @@ static void *m_start(struct seq_file *m, loff_t *pos)
189 struct list_head *p; 319 struct list_head *p;
190 loff_t l = *pos; 320 loff_t l = *pos;
191 321
192 down_read(&n->sem); 322 down_read(&namespace_sem);
193 list_for_each(p, &n->list) 323 list_for_each(p, &n->list)
194 if (!l--) 324 if (!l--)
195 return list_entry(p, struct vfsmount, mnt_list); 325 return list_entry(p, struct vfsmount, mnt_list);
@@ -201,13 +331,12 @@ static void *m_next(struct seq_file *m, void *v, loff_t *pos)
201 struct namespace *n = m->private; 331 struct namespace *n = m->private;
202 struct list_head *p = ((struct vfsmount *)v)->mnt_list.next; 332 struct list_head *p = ((struct vfsmount *)v)->mnt_list.next;
203 (*pos)++; 333 (*pos)++;
204 return p==&n->list ? NULL : list_entry(p, struct vfsmount, mnt_list); 334 return p == &n->list ? NULL : list_entry(p, struct vfsmount, mnt_list);
205} 335}
206 336
207static void m_stop(struct seq_file *m, void *v) 337static void m_stop(struct seq_file *m, void *v)
208{ 338{
209 struct namespace *n = m->private; 339 up_read(&namespace_sem);
210 up_read(&n->sem);
211} 340}
212 341
213static inline void mangle(struct seq_file *m, const char *s) 342static inline void mangle(struct seq_file *m, const char *s)
@@ -275,35 +404,14 @@ struct seq_operations mounts_op = {
275 */ 404 */
276int may_umount_tree(struct vfsmount *mnt) 405int may_umount_tree(struct vfsmount *mnt)
277{ 406{
278 struct list_head *next; 407 int actual_refs = 0;
279 struct vfsmount *this_parent = mnt; 408 int minimum_refs = 0;
280 int actual_refs; 409 struct vfsmount *p;
281 int minimum_refs;
282 410
283 spin_lock(&vfsmount_lock); 411 spin_lock(&vfsmount_lock);
284 actual_refs = atomic_read(&mnt->mnt_count); 412 for (p = mnt; p; p = next_mnt(p, mnt)) {
285 minimum_refs = 2;
286repeat:
287 next = this_parent->mnt_mounts.next;
288resume:
289 while (next != &this_parent->mnt_mounts) {
290 struct vfsmount *p = list_entry(next, struct vfsmount, mnt_child);
291
292 next = next->next;
293
294 actual_refs += atomic_read(&p->mnt_count); 413 actual_refs += atomic_read(&p->mnt_count);
295 minimum_refs += 2; 414 minimum_refs += 2;
296
297 if (!list_empty(&p->mnt_mounts)) {
298 this_parent = p;
299 goto repeat;
300 }
301 }
302
303 if (this_parent != mnt) {
304 next = this_parent->mnt_child.next;
305 this_parent = this_parent->mnt_parent;
306 goto resume;
307 } 415 }
308 spin_unlock(&vfsmount_lock); 416 spin_unlock(&vfsmount_lock);
309 417
@@ -330,45 +438,67 @@ EXPORT_SYMBOL(may_umount_tree);
330 */ 438 */
331int may_umount(struct vfsmount *mnt) 439int may_umount(struct vfsmount *mnt)
332{ 440{
333 if (atomic_read(&mnt->mnt_count) > 2) 441 int ret = 0;
334 return -EBUSY; 442 spin_lock(&vfsmount_lock);
335 return 0; 443 if (propagate_mount_busy(mnt, 2))
444 ret = -EBUSY;
445 spin_unlock(&vfsmount_lock);
446 return ret;
336} 447}
337 448
338EXPORT_SYMBOL(may_umount); 449EXPORT_SYMBOL(may_umount);
339 450
340static void umount_tree(struct vfsmount *mnt) 451void release_mounts(struct list_head *head)
452{
453 struct vfsmount *mnt;
454 while(!list_empty(head)) {
455 mnt = list_entry(head->next, struct vfsmount, mnt_hash);
456 list_del_init(&mnt->mnt_hash);
457 if (mnt->mnt_parent != mnt) {
458 struct dentry *dentry;
459 struct vfsmount *m;
460 spin_lock(&vfsmount_lock);
461 dentry = mnt->mnt_mountpoint;
462 m = mnt->mnt_parent;
463 mnt->mnt_mountpoint = mnt->mnt_root;
464 mnt->mnt_parent = mnt;
465 spin_unlock(&vfsmount_lock);
466 dput(dentry);
467 mntput(m);
468 }
469 mntput(mnt);
470 }
471}
472
473void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill)
341{ 474{
342 struct vfsmount *p; 475 struct vfsmount *p;
343 LIST_HEAD(kill);
344 476
345 for (p = mnt; p; p = next_mnt(p, mnt)) { 477 for (p = mnt; p; p = next_mnt(p, mnt)) {
346 list_del(&p->mnt_list); 478 list_del(&p->mnt_hash);
347 list_add(&p->mnt_list, &kill); 479 list_add(&p->mnt_hash, kill);
348 p->mnt_namespace = NULL;
349 } 480 }
350 481
351 while (!list_empty(&kill)) { 482 if (propagate)
352 mnt = list_entry(kill.next, struct vfsmount, mnt_list); 483 propagate_umount(kill);
353 list_del_init(&mnt->mnt_list); 484
354 list_del_init(&mnt->mnt_expire); 485 list_for_each_entry(p, kill, mnt_hash) {
355 if (mnt->mnt_parent == mnt) { 486 list_del_init(&p->mnt_expire);
356 spin_unlock(&vfsmount_lock); 487 list_del_init(&p->mnt_list);
357 } else { 488 __touch_namespace(p->mnt_namespace);
358 struct nameidata old_nd; 489 p->mnt_namespace = NULL;
359 detach_mnt(mnt, &old_nd); 490 list_del_init(&p->mnt_child);
360 spin_unlock(&vfsmount_lock); 491 if (p->mnt_parent != p)
361 path_release(&old_nd); 492 mnt->mnt_mountpoint->d_mounted--;
362 } 493 change_mnt_propagation(p, MS_PRIVATE);
363 mntput(mnt);
364 spin_lock(&vfsmount_lock);
365 } 494 }
366} 495}
367 496
368static int do_umount(struct vfsmount *mnt, int flags) 497static int do_umount(struct vfsmount *mnt, int flags)
369{ 498{
370 struct super_block * sb = mnt->mnt_sb; 499 struct super_block *sb = mnt->mnt_sb;
371 int retval; 500 int retval;
501 LIST_HEAD(umount_list);
372 502
373 retval = security_sb_umount(mnt, flags); 503 retval = security_sb_umount(mnt, flags);
374 if (retval) 504 if (retval)
@@ -403,7 +533,7 @@ static int do_umount(struct vfsmount *mnt, int flags)
403 */ 533 */
404 534
405 lock_kernel(); 535 lock_kernel();
406 if( (flags&MNT_FORCE) && sb->s_op->umount_begin) 536 if ((flags & MNT_FORCE) && sb->s_op->umount_begin)
407 sb->s_op->umount_begin(sb); 537 sb->s_op->umount_begin(sb);
408 unlock_kernel(); 538 unlock_kernel();
409 539
@@ -432,29 +562,21 @@ static int do_umount(struct vfsmount *mnt, int flags)
432 return retval; 562 return retval;
433 } 563 }
434 564
435 down_write(&current->namespace->sem); 565 down_write(&namespace_sem);
436 spin_lock(&vfsmount_lock); 566 spin_lock(&vfsmount_lock);
567 event++;
437 568
438 if (atomic_read(&sb->s_active) == 1) {
439 /* last instance - try to be smart */
440 spin_unlock(&vfsmount_lock);
441 lock_kernel();
442 DQUOT_OFF(sb);
443 acct_auto_close(sb);
444 unlock_kernel();
445 security_sb_umount_close(mnt);
446 spin_lock(&vfsmount_lock);
447 }
448 retval = -EBUSY; 569 retval = -EBUSY;
449 if (atomic_read(&mnt->mnt_count) == 2 || flags & MNT_DETACH) { 570 if (flags & MNT_DETACH || !propagate_mount_busy(mnt, 2)) {
450 if (!list_empty(&mnt->mnt_list)) 571 if (!list_empty(&mnt->mnt_list))
451 umount_tree(mnt); 572 umount_tree(mnt, 1, &umount_list);
452 retval = 0; 573 retval = 0;
453 } 574 }
454 spin_unlock(&vfsmount_lock); 575 spin_unlock(&vfsmount_lock);
455 if (retval) 576 if (retval)
456 security_sb_umount_busy(mnt); 577 security_sb_umount_busy(mnt);
457 up_write(&current->namespace->sem); 578 up_write(&namespace_sem);
579 release_mounts(&umount_list);
458 return retval; 580 return retval;
459} 581}
460 582
@@ -494,12 +616,11 @@ out:
494#ifdef __ARCH_WANT_SYS_OLDUMOUNT 616#ifdef __ARCH_WANT_SYS_OLDUMOUNT
495 617
496/* 618/*
497 * The 2.0 compatible umount. No flags. 619 * The 2.0 compatible umount. No flags.
498 */ 620 */
499
500asmlinkage long sys_oldumount(char __user * name) 621asmlinkage long sys_oldumount(char __user * name)
501{ 622{
502 return sys_umount(name,0); 623 return sys_umount(name, 0);
503} 624}
504 625
505#endif 626#endif
@@ -522,8 +643,7 @@ static int mount_is_safe(struct nameidata *nd)
522#endif 643#endif
523} 644}
524 645
525static int 646static int lives_below_in_same_fs(struct dentry *d, struct dentry *dentry)
526lives_below_in_same_fs(struct dentry *d, struct dentry *dentry)
527{ 647{
528 while (1) { 648 while (1) {
529 if (d == dentry) 649 if (d == dentry)
@@ -534,12 +654,16 @@ lives_below_in_same_fs(struct dentry *d, struct dentry *dentry)
534 } 654 }
535} 655}
536 656
537static struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry) 657struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry,
658 int flag)
538{ 659{
539 struct vfsmount *res, *p, *q, *r, *s; 660 struct vfsmount *res, *p, *q, *r, *s;
540 struct nameidata nd; 661 struct nameidata nd;
541 662
542 res = q = clone_mnt(mnt, dentry); 663 if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(mnt))
664 return NULL;
665
666 res = q = clone_mnt(mnt, dentry, flag);
543 if (!q) 667 if (!q)
544 goto Enomem; 668 goto Enomem;
545 q->mnt_mountpoint = mnt->mnt_mountpoint; 669 q->mnt_mountpoint = mnt->mnt_mountpoint;
@@ -550,6 +674,10 @@ static struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry)
550 continue; 674 continue;
551 675
552 for (s = r; s; s = next_mnt(s, r)) { 676 for (s = r; s; s = next_mnt(s, r)) {
677 if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(s)) {
678 s = skip_mnt_tree(s);
679 continue;
680 }
553 while (p != s->mnt_parent) { 681 while (p != s->mnt_parent) {
554 p = p->mnt_parent; 682 p = p->mnt_parent;
555 q = q->mnt_parent; 683 q = q->mnt_parent;
@@ -557,7 +685,7 @@ static struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry)
557 p = s; 685 p = s;
558 nd.mnt = q; 686 nd.mnt = q;
559 nd.dentry = p->mnt_mountpoint; 687 nd.dentry = p->mnt_mountpoint;
560 q = clone_mnt(p, p->mnt_root); 688 q = clone_mnt(p, p->mnt_root, flag);
561 if (!q) 689 if (!q)
562 goto Enomem; 690 goto Enomem;
563 spin_lock(&vfsmount_lock); 691 spin_lock(&vfsmount_lock);
@@ -567,15 +695,114 @@ static struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry)
567 } 695 }
568 } 696 }
569 return res; 697 return res;
570 Enomem: 698Enomem:
571 if (res) { 699 if (res) {
700 LIST_HEAD(umount_list);
572 spin_lock(&vfsmount_lock); 701 spin_lock(&vfsmount_lock);
573 umount_tree(res); 702 umount_tree(res, 0, &umount_list);
574 spin_unlock(&vfsmount_lock); 703 spin_unlock(&vfsmount_lock);
704 release_mounts(&umount_list);
575 } 705 }
576 return NULL; 706 return NULL;
577} 707}
578 708
709/*
710 * @source_mnt : mount tree to be attached
711 * @nd : place the mount tree @source_mnt is attached
712 * @parent_nd : if non-null, detach the source_mnt from its parent and
713 * store the parent mount and mountpoint dentry.
714 * (done when source_mnt is moved)
715 *
716 * NOTE: in the table below explains the semantics when a source mount
717 * of a given type is attached to a destination mount of a given type.
718 * ---------------------------------------------------------------------------
719 * | BIND MOUNT OPERATION |
720 * |**************************************************************************
721 * | source-->| shared | private | slave | unbindable |
722 * | dest | | | | |
723 * | | | | | | |
724 * | v | | | | |
725 * |**************************************************************************
726 * | shared | shared (++) | shared (+) | shared(+++)| invalid |
727 * | | | | | |
728 * |non-shared| shared (+) | private | slave (*) | invalid |
729 * ***************************************************************************
730 * A bind operation clones the source mount and mounts the clone on the
731 * destination mount.
732 *
733 * (++) the cloned mount is propagated to all the mounts in the propagation
734 * tree of the destination mount and the cloned mount is added to
735 * the peer group of the source mount.
736 * (+) the cloned mount is created under the destination mount and is marked
737 * as shared. The cloned mount is added to the peer group of the source
738 * mount.
739 * (+++) the mount is propagated to all the mounts in the propagation tree
740 * of the destination mount and the cloned mount is made slave
741 * of the same master as that of the source mount. The cloned mount
742 * is marked as 'shared and slave'.
743 * (*) the cloned mount is made a slave of the same master as that of the
744 * source mount.
745 *
746 * ---------------------------------------------------------------------------
747 * | MOVE MOUNT OPERATION |
748 * |**************************************************************************
749 * | source-->| shared | private | slave | unbindable |
750 * | dest | | | | |
751 * | | | | | | |
752 * | v | | | | |
753 * |**************************************************************************
754 * | shared | shared (+) | shared (+) | shared(+++) | invalid |
755 * | | | | | |
756 * |non-shared| shared (+*) | private | slave (*) | unbindable |
757 * ***************************************************************************
758 *
759 * (+) the mount is moved to the destination. And is then propagated to
760 * all the mounts in the propagation tree of the destination mount.
761 * (+*) the mount is moved to the destination.
762 * (+++) the mount is moved to the destination and is then propagated to
763 * all the mounts belonging to the destination mount's propagation tree.
764 * the mount is marked as 'shared and slave'.
765 * (*) the mount continues to be a slave at the new location.
766 *
767 * if the source mount is a tree, the operations explained above is
768 * applied to each mount in the tree.
769 * Must be called without spinlocks held, since this function can sleep
770 * in allocations.
771 */
772static int attach_recursive_mnt(struct vfsmount *source_mnt,
773 struct nameidata *nd, struct nameidata *parent_nd)
774{
775 LIST_HEAD(tree_list);
776 struct vfsmount *dest_mnt = nd->mnt;
777 struct dentry *dest_dentry = nd->dentry;
778 struct vfsmount *child, *p;
779
780 if (propagate_mnt(dest_mnt, dest_dentry, source_mnt, &tree_list))
781 return -EINVAL;
782
783 if (IS_MNT_SHARED(dest_mnt)) {
784 for (p = source_mnt; p; p = next_mnt(p, source_mnt))
785 set_mnt_shared(p);
786 }
787
788 spin_lock(&vfsmount_lock);
789 if (parent_nd) {
790 detach_mnt(source_mnt, parent_nd);
791 attach_mnt(source_mnt, nd);
792 touch_namespace(current->namespace);
793 } else {
794 mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt);
795 commit_tree(source_mnt);
796 }
797
798 list_for_each_entry_safe(child, p, &tree_list, mnt_hash) {
799 list_del_init(&child->mnt_hash);
800 commit_tree(child);
801 }
802 spin_unlock(&vfsmount_lock);
803 return 0;
804}
805
579static int graft_tree(struct vfsmount *mnt, struct nameidata *nd) 806static int graft_tree(struct vfsmount *mnt, struct nameidata *nd)
580{ 807{
581 int err; 808 int err;
@@ -596,17 +823,8 @@ static int graft_tree(struct vfsmount *mnt, struct nameidata *nd)
596 goto out_unlock; 823 goto out_unlock;
597 824
598 err = -ENOENT; 825 err = -ENOENT;
599 spin_lock(&vfsmount_lock); 826 if (IS_ROOT(nd->dentry) || !d_unhashed(nd->dentry))
600 if (IS_ROOT(nd->dentry) || !d_unhashed(nd->dentry)) { 827 err = attach_recursive_mnt(mnt, nd, NULL);
601 struct list_head head;
602
603 attach_mnt(mnt, nd);
604 list_add_tail(&head, &mnt->mnt_list);
605 list_splice(&head, current->namespace->list.prev);
606 mntget(mnt);
607 err = 0;
608 }
609 spin_unlock(&vfsmount_lock);
610out_unlock: 828out_unlock:
611 up(&nd->dentry->d_inode->i_sem); 829 up(&nd->dentry->d_inode->i_sem);
612 if (!err) 830 if (!err)
@@ -615,6 +833,27 @@ out_unlock:
615} 833}
616 834
617/* 835/*
836 * recursively change the type of the mountpoint.
837 */
838static int do_change_type(struct nameidata *nd, int flag)
839{
840 struct vfsmount *m, *mnt = nd->mnt;
841 int recurse = flag & MS_REC;
842 int type = flag & ~MS_REC;
843
844 if (nd->dentry != nd->mnt->mnt_root)
845 return -EINVAL;
846
847 down_write(&namespace_sem);
848 spin_lock(&vfsmount_lock);
849 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
850 change_mnt_propagation(m, type);
851 spin_unlock(&vfsmount_lock);
852 up_write(&namespace_sem);
853 return 0;
854}
855
856/*
618 * do loopback mount. 857 * do loopback mount.
619 */ 858 */
620static int do_loopback(struct nameidata *nd, char *old_name, int recurse) 859static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
@@ -630,32 +869,34 @@ static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
630 if (err) 869 if (err)
631 return err; 870 return err;
632 871
633 down_write(&current->namespace->sem); 872 down_write(&namespace_sem);
634 err = -EINVAL; 873 err = -EINVAL;
635 if (check_mnt(nd->mnt) && (!recurse || check_mnt(old_nd.mnt))) { 874 if (IS_MNT_UNBINDABLE(old_nd.mnt))
636 err = -ENOMEM; 875 goto out;
637 if (recurse)
638 mnt = copy_tree(old_nd.mnt, old_nd.dentry);
639 else
640 mnt = clone_mnt(old_nd.mnt, old_nd.dentry);
641 }
642 876
643 if (mnt) { 877 if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
644 /* stop bind mounts from expiring */ 878 goto out;
879
880 err = -ENOMEM;
881 if (recurse)
882 mnt = copy_tree(old_nd.mnt, old_nd.dentry, 0);
883 else
884 mnt = clone_mnt(old_nd.mnt, old_nd.dentry, 0);
885
886 if (!mnt)
887 goto out;
888
889 err = graft_tree(mnt, nd);
890 if (err) {
891 LIST_HEAD(umount_list);
645 spin_lock(&vfsmount_lock); 892 spin_lock(&vfsmount_lock);
646 list_del_init(&mnt->mnt_expire); 893 umount_tree(mnt, 0, &umount_list);
647 spin_unlock(&vfsmount_lock); 894 spin_unlock(&vfsmount_lock);
648 895 release_mounts(&umount_list);
649 err = graft_tree(mnt, nd);
650 if (err) {
651 spin_lock(&vfsmount_lock);
652 umount_tree(mnt);
653 spin_unlock(&vfsmount_lock);
654 } else
655 mntput(mnt);
656 } 896 }
657 897
658 up_write(&current->namespace->sem); 898out:
899 up_write(&namespace_sem);
659 path_release(&old_nd); 900 path_release(&old_nd);
660 return err; 901 return err;
661} 902}
@@ -665,12 +906,11 @@ static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
665 * If you've mounted a non-root directory somewhere and want to do remount 906 * If you've mounted a non-root directory somewhere and want to do remount
666 * on it - tough luck. 907 * on it - tough luck.
667 */ 908 */
668
669static int do_remount(struct nameidata *nd, int flags, int mnt_flags, 909static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
670 void *data) 910 void *data)
671{ 911{
672 int err; 912 int err;
673 struct super_block * sb = nd->mnt->mnt_sb; 913 struct super_block *sb = nd->mnt->mnt_sb;
674 914
675 if (!capable(CAP_SYS_ADMIN)) 915 if (!capable(CAP_SYS_ADMIN))
676 return -EPERM; 916 return -EPERM;
@@ -684,13 +924,23 @@ static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
684 down_write(&sb->s_umount); 924 down_write(&sb->s_umount);
685 err = do_remount_sb(sb, flags, data, 0); 925 err = do_remount_sb(sb, flags, data, 0);
686 if (!err) 926 if (!err)
687 nd->mnt->mnt_flags=mnt_flags; 927 nd->mnt->mnt_flags = mnt_flags;
688 up_write(&sb->s_umount); 928 up_write(&sb->s_umount);
689 if (!err) 929 if (!err)
690 security_sb_post_remount(nd->mnt, flags, data); 930 security_sb_post_remount(nd->mnt, flags, data);
691 return err; 931 return err;
692} 932}
693 933
934static inline int tree_contains_unbindable(struct vfsmount *mnt)
935{
936 struct vfsmount *p;
937 for (p = mnt; p; p = next_mnt(p, mnt)) {
938 if (IS_MNT_UNBINDABLE(p))
939 return 1;
940 }
941 return 0;
942}
943
694static int do_move_mount(struct nameidata *nd, char *old_name) 944static int do_move_mount(struct nameidata *nd, char *old_name)
695{ 945{
696 struct nameidata old_nd, parent_nd; 946 struct nameidata old_nd, parent_nd;
@@ -704,8 +954,8 @@ static int do_move_mount(struct nameidata *nd, char *old_name)
704 if (err) 954 if (err)
705 return err; 955 return err;
706 956
707 down_write(&current->namespace->sem); 957 down_write(&namespace_sem);
708 while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry)) 958 while (d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
709 ; 959 ;
710 err = -EINVAL; 960 err = -EINVAL;
711 if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt)) 961 if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
@@ -716,39 +966,47 @@ static int do_move_mount(struct nameidata *nd, char *old_name)
716 if (IS_DEADDIR(nd->dentry->d_inode)) 966 if (IS_DEADDIR(nd->dentry->d_inode))
717 goto out1; 967 goto out1;
718 968
719 spin_lock(&vfsmount_lock);
720 if (!IS_ROOT(nd->dentry) && d_unhashed(nd->dentry)) 969 if (!IS_ROOT(nd->dentry) && d_unhashed(nd->dentry))
721 goto out2; 970 goto out1;
722 971
723 err = -EINVAL; 972 err = -EINVAL;
724 if (old_nd.dentry != old_nd.mnt->mnt_root) 973 if (old_nd.dentry != old_nd.mnt->mnt_root)
725 goto out2; 974 goto out1;
726 975
727 if (old_nd.mnt == old_nd.mnt->mnt_parent) 976 if (old_nd.mnt == old_nd.mnt->mnt_parent)
728 goto out2; 977 goto out1;
729 978
730 if (S_ISDIR(nd->dentry->d_inode->i_mode) != 979 if (S_ISDIR(nd->dentry->d_inode->i_mode) !=
731 S_ISDIR(old_nd.dentry->d_inode->i_mode)) 980 S_ISDIR(old_nd.dentry->d_inode->i_mode))
732 goto out2; 981 goto out1;
733 982 /*
983 * Don't move a mount residing in a shared parent.
984 */
985 if (old_nd.mnt->mnt_parent && IS_MNT_SHARED(old_nd.mnt->mnt_parent))
986 goto out1;
987 /*
988 * Don't move a mount tree containing unbindable mounts to a destination
989 * mount which is shared.
990 */
991 if (IS_MNT_SHARED(nd->mnt) && tree_contains_unbindable(old_nd.mnt))
992 goto out1;
734 err = -ELOOP; 993 err = -ELOOP;
735 for (p = nd->mnt; p->mnt_parent!=p; p = p->mnt_parent) 994 for (p = nd->mnt; p->mnt_parent != p; p = p->mnt_parent)
736 if (p == old_nd.mnt) 995 if (p == old_nd.mnt)
737 goto out2; 996 goto out1;
738 err = 0;
739 997
740 detach_mnt(old_nd.mnt, &parent_nd); 998 if ((err = attach_recursive_mnt(old_nd.mnt, nd, &parent_nd)))
741 attach_mnt(old_nd.mnt, nd); 999 goto out1;
742 1000
1001 spin_lock(&vfsmount_lock);
743 /* if the mount is moved, it should no longer be expire 1002 /* if the mount is moved, it should no longer be expire
744 * automatically */ 1003 * automatically */
745 list_del_init(&old_nd.mnt->mnt_expire); 1004 list_del_init(&old_nd.mnt->mnt_expire);
746out2:
747 spin_unlock(&vfsmount_lock); 1005 spin_unlock(&vfsmount_lock);
748out1: 1006out1:
749 up(&nd->dentry->d_inode->i_sem); 1007 up(&nd->dentry->d_inode->i_sem);
750out: 1008out:
751 up_write(&current->namespace->sem); 1009 up_write(&namespace_sem);
752 if (!err) 1010 if (!err)
753 path_release(&parent_nd); 1011 path_release(&parent_nd);
754 path_release(&old_nd); 1012 path_release(&old_nd);
@@ -787,9 +1045,9 @@ int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
787{ 1045{
788 int err; 1046 int err;
789 1047
790 down_write(&current->namespace->sem); 1048 down_write(&namespace_sem);
791 /* Something was mounted here while we slept */ 1049 /* Something was mounted here while we slept */
792 while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry)) 1050 while (d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
793 ; 1051 ;
794 err = -EINVAL; 1052 err = -EINVAL;
795 if (!check_mnt(nd->mnt)) 1053 if (!check_mnt(nd->mnt))
@@ -806,25 +1064,28 @@ int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
806 goto unlock; 1064 goto unlock;
807 1065
808 newmnt->mnt_flags = mnt_flags; 1066 newmnt->mnt_flags = mnt_flags;
809 newmnt->mnt_namespace = current->namespace; 1067 if ((err = graft_tree(newmnt, nd)))
810 err = graft_tree(newmnt, nd); 1068 goto unlock;
811 1069
812 if (err == 0 && fslist) { 1070 if (fslist) {
813 /* add to the specified expiration list */ 1071 /* add to the specified expiration list */
814 spin_lock(&vfsmount_lock); 1072 spin_lock(&vfsmount_lock);
815 list_add_tail(&newmnt->mnt_expire, fslist); 1073 list_add_tail(&newmnt->mnt_expire, fslist);
816 spin_unlock(&vfsmount_lock); 1074 spin_unlock(&vfsmount_lock);
817 } 1075 }
1076 up_write(&namespace_sem);
1077 return 0;
818 1078
819unlock: 1079unlock:
820 up_write(&current->namespace->sem); 1080 up_write(&namespace_sem);
821 mntput(newmnt); 1081 mntput(newmnt);
822 return err; 1082 return err;
823} 1083}
824 1084
825EXPORT_SYMBOL_GPL(do_add_mount); 1085EXPORT_SYMBOL_GPL(do_add_mount);
826 1086
827static void expire_mount(struct vfsmount *mnt, struct list_head *mounts) 1087static void expire_mount(struct vfsmount *mnt, struct list_head *mounts,
1088 struct list_head *umounts)
828{ 1089{
829 spin_lock(&vfsmount_lock); 1090 spin_lock(&vfsmount_lock);
830 1091
@@ -841,27 +1102,13 @@ static void expire_mount(struct vfsmount *mnt, struct list_head *mounts)
841 * Check that it is still dead: the count should now be 2 - as 1102 * Check that it is still dead: the count should now be 2 - as
842 * contributed by the vfsmount parent and the mntget above 1103 * contributed by the vfsmount parent and the mntget above
843 */ 1104 */
844 if (atomic_read(&mnt->mnt_count) == 2) { 1105 if (!propagate_mount_busy(mnt, 2)) {
845 struct nameidata old_nd;
846
847 /* delete from the namespace */ 1106 /* delete from the namespace */
1107 touch_namespace(mnt->mnt_namespace);
848 list_del_init(&mnt->mnt_list); 1108 list_del_init(&mnt->mnt_list);
849 mnt->mnt_namespace = NULL; 1109 mnt->mnt_namespace = NULL;
850 detach_mnt(mnt, &old_nd); 1110 umount_tree(mnt, 1, umounts);
851 spin_unlock(&vfsmount_lock); 1111 spin_unlock(&vfsmount_lock);
852 path_release(&old_nd);
853
854 /*
855 * Now lay it to rest if this was the last ref on the superblock
856 */
857 if (atomic_read(&mnt->mnt_sb->s_active) == 1) {
858 /* last instance - try to be smart */
859 lock_kernel();
860 DQUOT_OFF(mnt->mnt_sb);
861 acct_auto_close(mnt->mnt_sb);
862 unlock_kernel();
863 }
864 mntput(mnt);
865 } else { 1112 } else {
866 /* 1113 /*
867 * Someone brought it back to life whilst we didn't have any 1114 * Someone brought it back to life whilst we didn't have any
@@ -910,6 +1157,7 @@ void mark_mounts_for_expiry(struct list_head *mounts)
910 * - dispose of the corpse 1157 * - dispose of the corpse
911 */ 1158 */
912 while (!list_empty(&graveyard)) { 1159 while (!list_empty(&graveyard)) {
1160 LIST_HEAD(umounts);
913 mnt = list_entry(graveyard.next, struct vfsmount, mnt_expire); 1161 mnt = list_entry(graveyard.next, struct vfsmount, mnt_expire);
914 list_del_init(&mnt->mnt_expire); 1162 list_del_init(&mnt->mnt_expire);
915 1163
@@ -921,13 +1169,12 @@ void mark_mounts_for_expiry(struct list_head *mounts)
921 get_namespace(namespace); 1169 get_namespace(namespace);
922 1170
923 spin_unlock(&vfsmount_lock); 1171 spin_unlock(&vfsmount_lock);
924 down_write(&namespace->sem); 1172 down_write(&namespace_sem);
925 expire_mount(mnt, mounts); 1173 expire_mount(mnt, mounts, &umounts);
926 up_write(&namespace->sem); 1174 up_write(&namespace_sem);
927 1175 release_mounts(&umounts);
928 mntput(mnt); 1176 mntput(mnt);
929 put_namespace(namespace); 1177 put_namespace(namespace);
930
931 spin_lock(&vfsmount_lock); 1178 spin_lock(&vfsmount_lock);
932 } 1179 }
933 1180
@@ -942,8 +1189,8 @@ EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);
942 * Note that this function differs from copy_from_user() in that it will oops 1189 * Note that this function differs from copy_from_user() in that it will oops
943 * on bad values of `to', rather than returning a short copy. 1190 * on bad values of `to', rather than returning a short copy.
944 */ 1191 */
945static long 1192static long exact_copy_from_user(void *to, const void __user * from,
946exact_copy_from_user(void *to, const void __user *from, unsigned long n) 1193 unsigned long n)
947{ 1194{
948 char *t = to; 1195 char *t = to;
949 const char __user *f = from; 1196 const char __user *f = from;
@@ -964,12 +1211,12 @@ exact_copy_from_user(void *to, const void __user *from, unsigned long n)
964 return n; 1211 return n;
965} 1212}
966 1213
967int copy_mount_options(const void __user *data, unsigned long *where) 1214int copy_mount_options(const void __user * data, unsigned long *where)
968{ 1215{
969 int i; 1216 int i;
970 unsigned long page; 1217 unsigned long page;
971 unsigned long size; 1218 unsigned long size;
972 1219
973 *where = 0; 1220 *where = 0;
974 if (!data) 1221 if (!data)
975 return 0; 1222 return 0;
@@ -988,7 +1235,7 @@ int copy_mount_options(const void __user *data, unsigned long *where)
988 1235
989 i = size - exact_copy_from_user((void *)page, data, size); 1236 i = size - exact_copy_from_user((void *)page, data, size);
990 if (!i) { 1237 if (!i) {
991 free_page(page); 1238 free_page(page);
992 return -EFAULT; 1239 return -EFAULT;
993 } 1240 }
994 if (i != PAGE_SIZE) 1241 if (i != PAGE_SIZE)
@@ -1011,7 +1258,7 @@ int copy_mount_options(const void __user *data, unsigned long *where)
1011 * Therefore, if this magic number is present, it carries no information 1258 * Therefore, if this magic number is present, it carries no information
1012 * and must be discarded. 1259 * and must be discarded.
1013 */ 1260 */
1014long do_mount(char * dev_name, char * dir_name, char *type_page, 1261long do_mount(char *dev_name, char *dir_name, char *type_page,
1015 unsigned long flags, void *data_page) 1262 unsigned long flags, void *data_page)
1016{ 1263{
1017 struct nameidata nd; 1264 struct nameidata nd;
@@ -1039,7 +1286,7 @@ long do_mount(char * dev_name, char * dir_name, char *type_page,
1039 mnt_flags |= MNT_NODEV; 1286 mnt_flags |= MNT_NODEV;
1040 if (flags & MS_NOEXEC) 1287 if (flags & MS_NOEXEC)
1041 mnt_flags |= MNT_NOEXEC; 1288 mnt_flags |= MNT_NOEXEC;
1042 flags &= ~(MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_ACTIVE); 1289 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE);
1043 1290
1044 /* ... and get the mountpoint */ 1291 /* ... and get the mountpoint */
1045 retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd); 1292 retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd);
@@ -1055,6 +1302,8 @@ long do_mount(char * dev_name, char * dir_name, char *type_page,
1055 data_page); 1302 data_page);
1056 else if (flags & MS_BIND) 1303 else if (flags & MS_BIND)
1057 retval = do_loopback(&nd, dev_name, flags & MS_REC); 1304 retval = do_loopback(&nd, dev_name, flags & MS_REC);
1305 else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
1306 retval = do_change_type(&nd, flags);
1058 else if (flags & MS_MOVE) 1307 else if (flags & MS_MOVE)
1059 retval = do_move_mount(&nd, dev_name); 1308 retval = do_move_mount(&nd, dev_name);
1060 else 1309 else
@@ -1091,14 +1340,16 @@ int copy_namespace(int flags, struct task_struct *tsk)
1091 goto out; 1340 goto out;
1092 1341
1093 atomic_set(&new_ns->count, 1); 1342 atomic_set(&new_ns->count, 1);
1094 init_rwsem(&new_ns->sem);
1095 INIT_LIST_HEAD(&new_ns->list); 1343 INIT_LIST_HEAD(&new_ns->list);
1344 init_waitqueue_head(&new_ns->poll);
1345 new_ns->event = 0;
1096 1346
1097 down_write(&tsk->namespace->sem); 1347 down_write(&namespace_sem);
1098 /* First pass: copy the tree topology */ 1348 /* First pass: copy the tree topology */
1099 new_ns->root = copy_tree(namespace->root, namespace->root->mnt_root); 1349 new_ns->root = copy_tree(namespace->root, namespace->root->mnt_root,
1350 CL_COPY_ALL | CL_EXPIRE);
1100 if (!new_ns->root) { 1351 if (!new_ns->root) {
1101 up_write(&tsk->namespace->sem); 1352 up_write(&namespace_sem);
1102 kfree(new_ns); 1353 kfree(new_ns);
1103 goto out; 1354 goto out;
1104 } 1355 }
@@ -1132,7 +1383,7 @@ int copy_namespace(int flags, struct task_struct *tsk)
1132 p = next_mnt(p, namespace->root); 1383 p = next_mnt(p, namespace->root);
1133 q = next_mnt(q, new_ns->root); 1384 q = next_mnt(q, new_ns->root);
1134 } 1385 }
1135 up_write(&tsk->namespace->sem); 1386 up_write(&namespace_sem);
1136 1387
1137 tsk->namespace = new_ns; 1388 tsk->namespace = new_ns;
1138 1389
@@ -1161,7 +1412,7 @@ asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
1161 unsigned long dev_page; 1412 unsigned long dev_page;
1162 char *dir_page; 1413 char *dir_page;
1163 1414
1164 retval = copy_mount_options (type, &type_page); 1415 retval = copy_mount_options(type, &type_page);
1165 if (retval < 0) 1416 if (retval < 0)
1166 return retval; 1417 return retval;
1167 1418
@@ -1170,17 +1421,17 @@ asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
1170 if (IS_ERR(dir_page)) 1421 if (IS_ERR(dir_page))
1171 goto out1; 1422 goto out1;
1172 1423
1173 retval = copy_mount_options (dev_name, &dev_page); 1424 retval = copy_mount_options(dev_name, &dev_page);
1174 if (retval < 0) 1425 if (retval < 0)
1175 goto out2; 1426 goto out2;
1176 1427
1177 retval = copy_mount_options (data, &data_page); 1428 retval = copy_mount_options(data, &data_page);
1178 if (retval < 0) 1429 if (retval < 0)
1179 goto out3; 1430 goto out3;
1180 1431
1181 lock_kernel(); 1432 lock_kernel();
1182 retval = do_mount((char*)dev_page, dir_page, (char*)type_page, 1433 retval = do_mount((char *)dev_page, dir_page, (char *)type_page,
1183 flags, (void*)data_page); 1434 flags, (void *)data_page);
1184 unlock_kernel(); 1435 unlock_kernel();
1185 free_page(data_page); 1436 free_page(data_page);
1186 1437
@@ -1249,9 +1500,11 @@ static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
1249 if (fs) { 1500 if (fs) {
1250 atomic_inc(&fs->count); 1501 atomic_inc(&fs->count);
1251 task_unlock(p); 1502 task_unlock(p);
1252 if (fs->root==old_nd->dentry&&fs->rootmnt==old_nd->mnt) 1503 if (fs->root == old_nd->dentry
1504 && fs->rootmnt == old_nd->mnt)
1253 set_fs_root(fs, new_nd->mnt, new_nd->dentry); 1505 set_fs_root(fs, new_nd->mnt, new_nd->dentry);
1254 if (fs->pwd==old_nd->dentry&&fs->pwdmnt==old_nd->mnt) 1506 if (fs->pwd == old_nd->dentry
1507 && fs->pwdmnt == old_nd->mnt)
1255 set_fs_pwd(fs, new_nd->mnt, new_nd->dentry); 1508 set_fs_pwd(fs, new_nd->mnt, new_nd->dentry);
1256 put_fs_struct(fs); 1509 put_fs_struct(fs);
1257 } else 1510 } else
@@ -1281,8 +1534,8 @@ static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
1281 * though, so you may need to say mount --bind /nfs/my_root /nfs/my_root 1534 * though, so you may need to say mount --bind /nfs/my_root /nfs/my_root
1282 * first. 1535 * first.
1283 */ 1536 */
1284 1537asmlinkage long sys_pivot_root(const char __user * new_root,
1285asmlinkage long sys_pivot_root(const char __user *new_root, const char __user *put_old) 1538 const char __user * put_old)
1286{ 1539{
1287 struct vfsmount *tmp; 1540 struct vfsmount *tmp;
1288 struct nameidata new_nd, old_nd, parent_nd, root_parent, user_nd; 1541 struct nameidata new_nd, old_nd, parent_nd, root_parent, user_nd;
@@ -1293,14 +1546,15 @@ asmlinkage long sys_pivot_root(const char __user *new_root, const char __user *p
1293 1546
1294 lock_kernel(); 1547 lock_kernel();
1295 1548
1296 error = __user_walk(new_root, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &new_nd); 1549 error = __user_walk(new_root, LOOKUP_FOLLOW | LOOKUP_DIRECTORY,
1550 &new_nd);
1297 if (error) 1551 if (error)
1298 goto out0; 1552 goto out0;
1299 error = -EINVAL; 1553 error = -EINVAL;
1300 if (!check_mnt(new_nd.mnt)) 1554 if (!check_mnt(new_nd.mnt))
1301 goto out1; 1555 goto out1;
1302 1556
1303 error = __user_walk(put_old, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &old_nd); 1557 error = __user_walk(put_old, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &old_nd);
1304 if (error) 1558 if (error)
1305 goto out1; 1559 goto out1;
1306 1560
@@ -1314,9 +1568,13 @@ asmlinkage long sys_pivot_root(const char __user *new_root, const char __user *p
1314 user_nd.mnt = mntget(current->fs->rootmnt); 1568 user_nd.mnt = mntget(current->fs->rootmnt);
1315 user_nd.dentry = dget(current->fs->root); 1569 user_nd.dentry = dget(current->fs->root);
1316 read_unlock(&current->fs->lock); 1570 read_unlock(&current->fs->lock);
1317 down_write(&current->namespace->sem); 1571 down_write(&namespace_sem);
1318 down(&old_nd.dentry->d_inode->i_sem); 1572 down(&old_nd.dentry->d_inode->i_sem);
1319 error = -EINVAL; 1573 error = -EINVAL;
1574 if (IS_MNT_SHARED(old_nd.mnt) ||
1575 IS_MNT_SHARED(new_nd.mnt->mnt_parent) ||
1576 IS_MNT_SHARED(user_nd.mnt->mnt_parent))
1577 goto out2;
1320 if (!check_mnt(user_nd.mnt)) 1578 if (!check_mnt(user_nd.mnt))
1321 goto out2; 1579 goto out2;
1322 error = -ENOENT; 1580 error = -ENOENT;
@@ -1356,6 +1614,7 @@ asmlinkage long sys_pivot_root(const char __user *new_root, const char __user *p
1356 detach_mnt(user_nd.mnt, &root_parent); 1614 detach_mnt(user_nd.mnt, &root_parent);
1357 attach_mnt(user_nd.mnt, &old_nd); /* mount old root on put_old */ 1615 attach_mnt(user_nd.mnt, &old_nd); /* mount old root on put_old */
1358 attach_mnt(new_nd.mnt, &root_parent); /* mount new_root on / */ 1616 attach_mnt(new_nd.mnt, &root_parent); /* mount new_root on / */
1617 touch_namespace(current->namespace);
1359 spin_unlock(&vfsmount_lock); 1618 spin_unlock(&vfsmount_lock);
1360 chroot_fs_refs(&user_nd, &new_nd); 1619 chroot_fs_refs(&user_nd, &new_nd);
1361 security_sb_post_pivotroot(&user_nd, &new_nd); 1620 security_sb_post_pivotroot(&user_nd, &new_nd);
@@ -1364,7 +1623,7 @@ asmlinkage long sys_pivot_root(const char __user *new_root, const char __user *p
1364 path_release(&parent_nd); 1623 path_release(&parent_nd);
1365out2: 1624out2:
1366 up(&old_nd.dentry->d_inode->i_sem); 1625 up(&old_nd.dentry->d_inode->i_sem);
1367 up_write(&current->namespace->sem); 1626 up_write(&namespace_sem);
1368 path_release(&user_nd); 1627 path_release(&user_nd);
1369 path_release(&old_nd); 1628 path_release(&old_nd);
1370out1: 1629out1:
@@ -1391,7 +1650,8 @@ static void __init init_mount_tree(void)
1391 panic("Can't allocate initial namespace"); 1650 panic("Can't allocate initial namespace");
1392 atomic_set(&namespace->count, 1); 1651 atomic_set(&namespace->count, 1);
1393 INIT_LIST_HEAD(&namespace->list); 1652 INIT_LIST_HEAD(&namespace->list);
1394 init_rwsem(&namespace->sem); 1653 init_waitqueue_head(&namespace->poll);
1654 namespace->event = 0;
1395 list_add(&mnt->mnt_list, &namespace->list); 1655 list_add(&mnt->mnt_list, &namespace->list);
1396 namespace->root = mnt; 1656 namespace->root = mnt;
1397 mnt->mnt_namespace = namespace; 1657 mnt->mnt_namespace = namespace;
@@ -1414,11 +1674,12 @@ void __init mnt_init(unsigned long mempages)
1414 unsigned int nr_hash; 1674 unsigned int nr_hash;
1415 int i; 1675 int i;
1416 1676
1677 init_rwsem(&namespace_sem);
1678
1417 mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct vfsmount), 1679 mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct vfsmount),
1418 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL); 1680 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL, NULL);
1419 1681
1420 mount_hashtable = (struct list_head *) 1682 mount_hashtable = (struct list_head *)__get_free_page(GFP_ATOMIC);
1421 __get_free_page(GFP_ATOMIC);
1422 1683
1423 if (!mount_hashtable) 1684 if (!mount_hashtable)
1424 panic("Failed to allocate mount hash table\n"); 1685 panic("Failed to allocate mount hash table\n");
@@ -1440,7 +1701,7 @@ void __init mnt_init(unsigned long mempages)
1440 * from the number of bits we can fit. 1701 * from the number of bits we can fit.
1441 */ 1702 */
1442 nr_hash = 1UL << hash_bits; 1703 nr_hash = 1UL << hash_bits;
1443 hash_mask = nr_hash-1; 1704 hash_mask = nr_hash - 1;
1444 1705
1445 printk("Mount-cache hash table entries: %d\n", nr_hash); 1706 printk("Mount-cache hash table entries: %d\n", nr_hash);
1446 1707
@@ -1460,12 +1721,14 @@ void __init mnt_init(unsigned long mempages)
1460void __put_namespace(struct namespace *namespace) 1721void __put_namespace(struct namespace *namespace)
1461{ 1722{
1462 struct vfsmount *root = namespace->root; 1723 struct vfsmount *root = namespace->root;
1724 LIST_HEAD(umount_list);
1463 namespace->root = NULL; 1725 namespace->root = NULL;
1464 spin_unlock(&vfsmount_lock); 1726 spin_unlock(&vfsmount_lock);
1465 down_write(&namespace->sem); 1727 down_write(&namespace_sem);
1466 spin_lock(&vfsmount_lock); 1728 spin_lock(&vfsmount_lock);
1467 umount_tree(root); 1729 umount_tree(root, 0, &umount_list);
1468 spin_unlock(&vfsmount_lock); 1730 spin_unlock(&vfsmount_lock);
1469 up_write(&namespace->sem); 1731 up_write(&namespace_sem);
1732 release_mounts(&umount_list);
1470 kfree(namespace); 1733 kfree(namespace);
1471} 1734}
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 3976c177a7d0..618a327027b3 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -149,8 +149,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
149 } 149 }
150 } 150 }
151 spin_unlock(&clp->cl_lock); 151 spin_unlock(&clp->cl_lock);
152 if (delegation != NULL) 152 kfree(delegation);
153 kfree(delegation);
154 return status; 153 return status;
155} 154}
156 155
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 24d2fbf549bd..6391d8964214 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -1688,8 +1688,7 @@ static void nfs_kill_super(struct super_block *s)
1688 1688
1689 rpciod_down(); /* release rpciod */ 1689 rpciod_down(); /* release rpciod */
1690 1690
1691 if (server->hostname != NULL) 1691 kfree(server->hostname);
1692 kfree(server->hostname);
1693 kfree(server); 1692 kfree(server);
1694} 1693}
1695 1694
@@ -1908,8 +1907,7 @@ nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen)
1908 return ERR_PTR(-ENOMEM); 1907 return ERR_PTR(-ENOMEM);
1909 } 1908 }
1910 if (copy_from_user(dst, src->data, maxlen)) { 1909 if (copy_from_user(dst, src->data, maxlen)) {
1911 if (p != NULL) 1910 kfree(p);
1912 kfree(p);
1913 return ERR_PTR(-EFAULT); 1911 return ERR_PTR(-EFAULT);
1914 } 1912 }
1915 dst[maxlen] = '\0'; 1913 dst[maxlen] = '\0';
@@ -2000,10 +1998,8 @@ static struct super_block *nfs4_get_sb(struct file_system_type *fs_type,
2000out_err: 1998out_err:
2001 s = (struct super_block *)p; 1999 s = (struct super_block *)p;
2002out_free: 2000out_free:
2003 if (server->mnt_path) 2001 kfree(server->mnt_path);
2004 kfree(server->mnt_path); 2002 kfree(server->hostname);
2005 if (server->hostname)
2006 kfree(server->hostname);
2007 kfree(server); 2003 kfree(server);
2008 return s; 2004 return s;
2009} 2005}
@@ -2023,8 +2019,7 @@ static void nfs4_kill_super(struct super_block *sb)
2023 2019
2024 destroy_nfsv4_state(server); 2020 destroy_nfsv4_state(server);
2025 2021
2026 if (server->hostname != NULL) 2022 kfree(server->hostname);
2027 kfree(server->hostname);
2028 kfree(server); 2023 kfree(server);
2029} 2024}
2030 2025
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 52a26baa114c..0675f3215e0a 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -69,10 +69,8 @@ init_nfsv4_state(struct nfs_server *server)
69void 69void
70destroy_nfsv4_state(struct nfs_server *server) 70destroy_nfsv4_state(struct nfs_server *server)
71{ 71{
72 if (server->mnt_path) { 72 kfree(server->mnt_path);
73 kfree(server->mnt_path); 73 server->mnt_path = NULL;
74 server->mnt_path = NULL;
75 }
76 if (server->nfs4_state) { 74 if (server->nfs4_state) {
77 nfs4_put_client(server->nfs4_state); 75 nfs4_put_client(server->nfs4_state);
78 server->nfs4_state = NULL; 76 server->nfs4_state = NULL;
@@ -311,8 +309,7 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct
311 new = NULL; 309 new = NULL;
312 } 310 }
313 spin_unlock(&clp->cl_lock); 311 spin_unlock(&clp->cl_lock);
314 if (new) 312 kfree(new);
315 kfree(new);
316 if (sp != NULL) 313 if (sp != NULL)
317 return sp; 314 return sp;
318 put_rpccred(cred); 315 put_rpccred(cred);
diff --git a/fs/nfs/unlink.c b/fs/nfs/unlink.c
index f732541a3332..d639d172d568 100644
--- a/fs/nfs/unlink.c
+++ b/fs/nfs/unlink.c
@@ -52,8 +52,7 @@ nfs_put_unlinkdata(struct nfs_unlinkdata *data)
52{ 52{
53 if (--data->count == 0) { 53 if (--data->count == 0) {
54 nfs_detach_unlinkdata(data); 54 nfs_detach_unlinkdata(data);
55 if (data->name.name != NULL) 55 kfree(data->name.name);
56 kfree(data->name.name);
57 kfree(data); 56 kfree(data);
58 } 57 }
59} 58}
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 057aff745506..417ec02df44f 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -190,8 +190,7 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
190 out: 190 out:
191 if (dom) 191 if (dom)
192 auth_domain_put(dom); 192 auth_domain_put(dom);
193 if (buf) 193 kfree(buf);
194 kfree(buf);
195 return err; 194 return err;
196} 195}
197 196
@@ -428,8 +427,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
428 path_release(&nd); 427 path_release(&nd);
429 if (dom) 428 if (dom)
430 auth_domain_put(dom); 429 auth_domain_put(dom);
431 if (buf) 430 kfree(buf);
432 kfree(buf);
433 return err; 431 return err;
434} 432}
435 433
diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index e0e134d6baba..9147b8524d05 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -366,7 +366,8 @@ nfs3svc_decode_writeargs(struct svc_rqst *rqstp, u32 *p,
366 len = args->len = ntohl(*p++); 366 len = args->len = ntohl(*p++);
367 367
368 hdr = (void*)p - rqstp->rq_arg.head[0].iov_base; 368 hdr = (void*)p - rqstp->rq_arg.head[0].iov_base;
369 if (rqstp->rq_arg.len < len + hdr) 369 if (rqstp->rq_arg.len < hdr ||
370 rqstp->rq_arg.len - hdr < len)
370 return 0; 371 return 0;
371 372
372 args->vec[0].iov_base = (void*)p; 373 args->vec[0].iov_base = (void*)p;
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 4c4146350236..dcd673186944 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -151,8 +151,7 @@ static u32 *read_buf(struct nfsd4_compoundargs *argp, int nbytes)
151 if (nbytes <= sizeof(argp->tmp)) 151 if (nbytes <= sizeof(argp->tmp))
152 p = argp->tmp; 152 p = argp->tmp;
153 else { 153 else {
154 if (argp->tmpp) 154 kfree(argp->tmpp);
155 kfree(argp->tmpp);
156 p = argp->tmpp = kmalloc(nbytes, GFP_KERNEL); 155 p = argp->tmpp = kmalloc(nbytes, GFP_KERNEL);
157 if (!p) 156 if (!p)
158 return NULL; 157 return NULL;
@@ -2476,10 +2475,8 @@ void nfsd4_release_compoundargs(struct nfsd4_compoundargs *args)
2476 kfree(args->ops); 2475 kfree(args->ops);
2477 args->ops = args->iops; 2476 args->ops = args->iops;
2478 } 2477 }
2479 if (args->tmpp) { 2478 kfree(args->tmpp);
2480 kfree(args->tmpp); 2479 args->tmpp = NULL;
2481 args->tmpp = NULL;
2482 }
2483 while (args->to_free) { 2480 while (args->to_free) {
2484 struct tmpbuf *tb = args->to_free; 2481 struct tmpbuf *tb = args->to_free;
2485 args->to_free = tb->next; 2482 args->to_free = tb->next;
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index 119e4d4495b8..d852ebb538e3 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -93,8 +93,7 @@ nfsd_cache_shutdown(void)
93 93
94 cache_disabled = 1; 94 cache_disabled = 1;
95 95
96 if (hash_list) 96 kfree (hash_list);
97 kfree (hash_list);
98 hash_list = NULL; 97 hash_list = NULL;
99} 98}
100 99
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 841c562991e8..a0871b3efeb7 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -23,6 +23,7 @@
23#include <linux/seq_file.h> 23#include <linux/seq_file.h>
24#include <linux/pagemap.h> 24#include <linux/pagemap.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/string.h>
26 27
27#include <linux/nfs.h> 28#include <linux/nfs.h>
28#include <linux/nfsd_idmap.h> 29#include <linux/nfsd_idmap.h>
@@ -35,6 +36,8 @@
35 36
36#include <asm/uaccess.h> 37#include <asm/uaccess.h>
37 38
39unsigned int nfsd_versbits = ~0;
40
38/* 41/*
39 * We have a single directory with 9 nodes in it. 42 * We have a single directory with 9 nodes in it.
40 */ 43 */
@@ -50,8 +53,15 @@ enum {
50 NFSD_List, 53 NFSD_List,
51 NFSD_Fh, 54 NFSD_Fh,
52 NFSD_Threads, 55 NFSD_Threads,
56 NFSD_Versions,
57 /*
58 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
59 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
60 */
61#ifdef CONFIG_NFSD_V4
53 NFSD_Leasetime, 62 NFSD_Leasetime,
54 NFSD_RecoveryDir, 63 NFSD_RecoveryDir,
64#endif
55}; 65};
56 66
57/* 67/*
@@ -66,8 +76,11 @@ static ssize_t write_getfd(struct file *file, char *buf, size_t size);
66static ssize_t write_getfs(struct file *file, char *buf, size_t size); 76static ssize_t write_getfs(struct file *file, char *buf, size_t size);
67static ssize_t write_filehandle(struct file *file, char *buf, size_t size); 77static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
68static ssize_t write_threads(struct file *file, char *buf, size_t size); 78static ssize_t write_threads(struct file *file, char *buf, size_t size);
79static ssize_t write_versions(struct file *file, char *buf, size_t size);
80#ifdef CONFIG_NFSD_V4
69static ssize_t write_leasetime(struct file *file, char *buf, size_t size); 81static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
70static ssize_t write_recoverydir(struct file *file, char *buf, size_t size); 82static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
83#endif
71 84
72static ssize_t (*write_op[])(struct file *, char *, size_t) = { 85static ssize_t (*write_op[])(struct file *, char *, size_t) = {
73 [NFSD_Svc] = write_svc, 86 [NFSD_Svc] = write_svc,
@@ -79,8 +92,11 @@ static ssize_t (*write_op[])(struct file *, char *, size_t) = {
79 [NFSD_Getfs] = write_getfs, 92 [NFSD_Getfs] = write_getfs,
80 [NFSD_Fh] = write_filehandle, 93 [NFSD_Fh] = write_filehandle,
81 [NFSD_Threads] = write_threads, 94 [NFSD_Threads] = write_threads,
95 [NFSD_Versions] = write_versions,
96#ifdef CONFIG_NFSD_V4
82 [NFSD_Leasetime] = write_leasetime, 97 [NFSD_Leasetime] = write_leasetime,
83 [NFSD_RecoveryDir] = write_recoverydir, 98 [NFSD_RecoveryDir] = write_recoverydir,
99#endif
84}; 100};
85 101
86static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos) 102static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
@@ -104,9 +120,23 @@ static ssize_t nfsctl_transaction_write(struct file *file, const char __user *bu
104 return rv; 120 return rv;
105} 121}
106 122
123static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
124{
125 if (! file->private_data) {
126 /* An attempt to read a transaction file without writing
127 * causes a 0-byte write so that the file can return
128 * state information
129 */
130 ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
131 if (rv < 0)
132 return rv;
133 }
134 return simple_transaction_read(file, buf, size, pos);
135}
136
107static struct file_operations transaction_ops = { 137static struct file_operations transaction_ops = {
108 .write = nfsctl_transaction_write, 138 .write = nfsctl_transaction_write,
109 .read = simple_transaction_read, 139 .read = nfsctl_transaction_read,
110 .release = simple_transaction_release, 140 .release = simple_transaction_release,
111}; 141};
112 142
@@ -329,6 +359,70 @@ static ssize_t write_threads(struct file *file, char *buf, size_t size)
329 return strlen(buf); 359 return strlen(buf);
330} 360}
331 361
362static ssize_t write_versions(struct file *file, char *buf, size_t size)
363{
364 /*
365 * Format:
366 * [-/+]vers [-/+]vers ...
367 */
368 char *mesg = buf;
369 char *vers, sign;
370 int len, num;
371 ssize_t tlen = 0;
372 char *sep;
373
374 if (size>0) {
375 if (nfsd_serv)
376 return -EBUSY;
377 if (buf[size-1] != '\n')
378 return -EINVAL;
379 buf[size-1] = 0;
380
381 vers = mesg;
382 len = qword_get(&mesg, vers, size);
383 if (len <= 0) return -EINVAL;
384 do {
385 sign = *vers;
386 if (sign == '+' || sign == '-')
387 num = simple_strtol((vers+1), NULL, 0);
388 else
389 num = simple_strtol(vers, NULL, 0);
390 switch(num) {
391 case 2:
392 case 3:
393 case 4:
394 if (sign != '-')
395 NFSCTL_VERSET(nfsd_versbits, num);
396 else
397 NFSCTL_VERUNSET(nfsd_versbits, num);
398 break;
399 default:
400 return -EINVAL;
401 }
402 vers += len + 1;
403 tlen += len;
404 } while ((len = qword_get(&mesg, vers, size)) > 0);
405 /* If all get turned off, turn them back on, as
406 * having no versions is BAD
407 */
408 if ((nfsd_versbits & NFSCTL_VERALL)==0)
409 nfsd_versbits = NFSCTL_VERALL;
410 }
411 /* Now write current state into reply buffer */
412 len = 0;
413 sep = "";
414 for (num=2 ; num <= 4 ; num++)
415 if (NFSCTL_VERISSET(NFSCTL_VERALL, num)) {
416 len += sprintf(buf+len, "%s%c%d", sep,
417 NFSCTL_VERISSET(nfsd_versbits, num)?'+':'-',
418 num);
419 sep = " ";
420 }
421 len += sprintf(buf+len, "\n");
422 return len;
423}
424
425#ifdef CONFIG_NFSD_V4
332extern time_t nfs4_leasetime(void); 426extern time_t nfs4_leasetime(void);
333 427
334static ssize_t write_leasetime(struct file *file, char *buf, size_t size) 428static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
@@ -370,6 +464,7 @@ static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
370 status = nfs4_reset_recoverydir(recdir); 464 status = nfs4_reset_recoverydir(recdir);
371 return strlen(buf); 465 return strlen(buf);
372} 466}
467#endif
373 468
374/*----------------------------------------------------------------------------*/ 469/*----------------------------------------------------------------------------*/
375/* 470/*
@@ -389,6 +484,7 @@ static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
389 [NFSD_List] = {"exports", &exports_operations, S_IRUGO}, 484 [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
390 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR}, 485 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
391 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR}, 486 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
487 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
392#ifdef CONFIG_NFSD_V4 488#ifdef CONFIG_NFSD_V4
393 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR}, 489 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
394 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR}, 490 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index 1697539a7171..89ed04696865 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -30,6 +30,7 @@
30#include <linux/nfsd/nfsd.h> 30#include <linux/nfsd/nfsd.h>
31#include <linux/nfsd/stats.h> 31#include <linux/nfsd/stats.h>
32#include <linux/nfsd/cache.h> 32#include <linux/nfsd/cache.h>
33#include <linux/nfsd/syscall.h>
33#include <linux/lockd/bind.h> 34#include <linux/lockd/bind.h>
34#include <linux/nfsacl.h> 35#include <linux/nfsacl.h>
35 36
@@ -52,7 +53,7 @@
52extern struct svc_program nfsd_program; 53extern struct svc_program nfsd_program;
53static void nfsd(struct svc_rqst *rqstp); 54static void nfsd(struct svc_rqst *rqstp);
54struct timeval nfssvc_boot; 55struct timeval nfssvc_boot;
55static struct svc_serv *nfsd_serv; 56 struct svc_serv *nfsd_serv;
56static atomic_t nfsd_busy; 57static atomic_t nfsd_busy;
57static unsigned long nfsd_last_call; 58static unsigned long nfsd_last_call;
58static DEFINE_SPINLOCK(nfsd_call_lock); 59static DEFINE_SPINLOCK(nfsd_call_lock);
@@ -63,6 +64,31 @@ struct nfsd_list {
63}; 64};
64static struct list_head nfsd_list = LIST_HEAD_INIT(nfsd_list); 65static struct list_head nfsd_list = LIST_HEAD_INIT(nfsd_list);
65 66
67static struct svc_version * nfsd_version[] = {
68 [2] = &nfsd_version2,
69#if defined(CONFIG_NFSD_V3)
70 [3] = &nfsd_version3,
71#endif
72#if defined(CONFIG_NFSD_V4)
73 [4] = &nfsd_version4,
74#endif
75};
76
77#define NFSD_MINVERS 2
78#define NFSD_NRVERS (sizeof(nfsd_version)/sizeof(nfsd_version[0]))
79static struct svc_version *nfsd_versions[NFSD_NRVERS];
80
81struct svc_program nfsd_program = {
82 .pg_prog = NFS_PROGRAM, /* program number */
83 .pg_nvers = NFSD_NRVERS, /* nr of entries in nfsd_version */
84 .pg_vers = nfsd_versions, /* version table */
85 .pg_name = "nfsd", /* program name */
86 .pg_class = "nfsd", /* authentication class */
87 .pg_stats = &nfsd_svcstats, /* version table */
88 .pg_authenticate = &svc_set_client, /* export authentication */
89
90};
91
66/* 92/*
67 * Maximum number of nfsd processes 93 * Maximum number of nfsd processes
68 */ 94 */
@@ -80,11 +106,12 @@ int
80nfsd_svc(unsigned short port, int nrservs) 106nfsd_svc(unsigned short port, int nrservs)
81{ 107{
82 int error; 108 int error;
83 int none_left; 109 int none_left, found_one, i;
84 struct list_head *victim; 110 struct list_head *victim;
85 111
86 lock_kernel(); 112 lock_kernel();
87 dprintk("nfsd: creating service\n"); 113 dprintk("nfsd: creating service: vers 0x%x\n",
114 nfsd_versbits);
88 error = -EINVAL; 115 error = -EINVAL;
89 if (nrservs <= 0) 116 if (nrservs <= 0)
90 nrservs = 0; 117 nrservs = 0;
@@ -99,6 +126,27 @@ nfsd_svc(unsigned short port, int nrservs)
99 if (error<0) 126 if (error<0)
100 goto out; 127 goto out;
101 if (!nfsd_serv) { 128 if (!nfsd_serv) {
129 /*
130 * Use the nfsd_ctlbits to define which
131 * versions that will be advertised.
132 * If nfsd_ctlbits doesn't list any version,
133 * export them all.
134 */
135 found_one = 0;
136
137 for (i = NFSD_MINVERS; i < NFSD_NRVERS; i++) {
138 if (NFSCTL_VERISSET(nfsd_versbits, i)) {
139 nfsd_program.pg_vers[i] = nfsd_version[i];
140 found_one = 1;
141 } else
142 nfsd_program.pg_vers[i] = NULL;
143 }
144
145 if (!found_one) {
146 for (i = NFSD_MINVERS; i < NFSD_NRVERS; i++)
147 nfsd_program.pg_vers[i] = nfsd_version[i];
148 }
149
102 atomic_set(&nfsd_busy, 0); 150 atomic_set(&nfsd_busy, 0);
103 error = -ENOMEM; 151 error = -ENOMEM;
104 nfsd_serv = svc_create(&nfsd_program, NFSD_BUFSIZE); 152 nfsd_serv = svc_create(&nfsd_program, NFSD_BUFSIZE);
@@ -379,6 +427,7 @@ static struct svc_program nfsd_acl_program = {
379 .pg_name = "nfsd", 427 .pg_name = "nfsd",
380 .pg_class = "nfsd", 428 .pg_class = "nfsd",
381 .pg_stats = &nfsd_acl_svcstats, 429 .pg_stats = &nfsd_acl_svcstats,
430 .pg_authenticate = &svc_set_client,
382}; 431};
383 432
384static struct svc_stat nfsd_acl_svcstats = { 433static struct svc_stat nfsd_acl_svcstats = {
@@ -389,28 +438,3 @@ static struct svc_stat nfsd_acl_svcstats = {
389#else 438#else
390#define nfsd_acl_program_p NULL 439#define nfsd_acl_program_p NULL
391#endif /* defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) */ 440#endif /* defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) */
392
393extern struct svc_version nfsd_version2, nfsd_version3, nfsd_version4;
394
395static struct svc_version * nfsd_version[] = {
396 [2] = &nfsd_version2,
397#if defined(CONFIG_NFSD_V3)
398 [3] = &nfsd_version3,
399#endif
400#if defined(CONFIG_NFSD_V4)
401 [4] = &nfsd_version4,
402#endif
403};
404
405#define NFSD_NRVERS (sizeof(nfsd_version)/sizeof(nfsd_version[0]))
406struct svc_program nfsd_program = {
407 .pg_next = nfsd_acl_program_p,
408 .pg_prog = NFS_PROGRAM, /* program number */
409 .pg_nvers = NFSD_NRVERS, /* nr of entries in nfsd_version */
410 .pg_vers = nfsd_version, /* version table */
411 .pg_name = "nfsd", /* program name */
412 .pg_class = "nfsd", /* authentication class */
413 .pg_stats = &nfsd_svcstats, /* version table */
414 .pg_authenticate = &svc_set_client, /* export authentication */
415
416};
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 4f2cd3d27566..af7c3c3074b0 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -254,12 +254,19 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
254 254
255 /* Get inode */ 255 /* Get inode */
256 err = fh_verify(rqstp, fhp, ftype, accmode); 256 err = fh_verify(rqstp, fhp, ftype, accmode);
257 if (err || !iap->ia_valid) 257 if (err)
258 goto out; 258 goto out;
259 259
260 dentry = fhp->fh_dentry; 260 dentry = fhp->fh_dentry;
261 inode = dentry->d_inode; 261 inode = dentry->d_inode;
262 262
263 /* Ignore any mode updates on symlinks */
264 if (S_ISLNK(inode->i_mode))
265 iap->ia_valid &= ~ATTR_MODE;
266
267 if (!iap->ia_valid)
268 goto out;
269
263 /* NFSv2 does not differentiate between "set-[ac]time-to-now" 270 /* NFSv2 does not differentiate between "set-[ac]time-to-now"
264 * which only requires access, and "set-[ac]time-to-X" which 271 * which only requires access, and "set-[ac]time-to-X" which
265 * requires ownership. 272 * requires ownership.
diff --git a/fs/open.c b/fs/open.c
index 8d06ec911fd9..6e8136751e9a 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -194,7 +194,7 @@ out:
194 return error; 194 return error;
195} 195}
196 196
197int do_truncate(struct dentry *dentry, loff_t length) 197int do_truncate(struct dentry *dentry, loff_t length, struct file *filp)
198{ 198{
199 int err; 199 int err;
200 struct iattr newattrs; 200 struct iattr newattrs;
@@ -205,6 +205,10 @@ int do_truncate(struct dentry *dentry, loff_t length)
205 205
206 newattrs.ia_size = length; 206 newattrs.ia_size = length;
207 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; 207 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
208 if (filp) {
209 newattrs.ia_file = filp;
210 newattrs.ia_valid |= ATTR_FILE;
211 }
208 212
209 down(&dentry->d_inode->i_sem); 213 down(&dentry->d_inode->i_sem);
210 err = notify_change(dentry, &newattrs); 214 err = notify_change(dentry, &newattrs);
@@ -262,7 +266,7 @@ static inline long do_sys_truncate(const char __user * path, loff_t length)
262 error = locks_verify_truncate(inode, NULL, length); 266 error = locks_verify_truncate(inode, NULL, length);
263 if (!error) { 267 if (!error) {
264 DQUOT_INIT(inode); 268 DQUOT_INIT(inode);
265 error = do_truncate(nd.dentry, length); 269 error = do_truncate(nd.dentry, length, NULL);
266 } 270 }
267 put_write_access(inode); 271 put_write_access(inode);
268 272
@@ -314,7 +318,7 @@ static inline long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
314 318
315 error = locks_verify_truncate(inode, file, length); 319 error = locks_verify_truncate(inode, file, length);
316 if (!error) 320 if (!error)
317 error = do_truncate(dentry, length); 321 error = do_truncate(dentry, length, file);
318out_putf: 322out_putf:
319 fput(file); 323 fput(file);
320out: 324out:
@@ -887,6 +891,10 @@ struct file *nameidata_to_filp(struct nameidata *nd, int flags)
887 return filp; 891 return filp;
888} 892}
889 893
894/*
895 * dentry_open() will have done dput(dentry) and mntput(mnt) if it returns an
896 * error.
897 */
890struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags) 898struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
891{ 899{
892 int error; 900 int error;
@@ -894,8 +902,11 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
894 902
895 error = -ENFILE; 903 error = -ENFILE;
896 f = get_empty_filp(); 904 f = get_empty_filp();
897 if (f == NULL) 905 if (f == NULL) {
906 dput(dentry);
907 mntput(mnt);
898 return ERR_PTR(error); 908 return ERR_PTR(error);
909 }
899 910
900 return __dentry_open(dentry, mnt, flags, f, NULL); 911 return __dentry_open(dentry, mnt, flags, f, NULL);
901} 912}
diff --git a/fs/openpromfs/inode.c b/fs/openpromfs/inode.c
index 1be11ce96b0f..aeb0106890e4 100644
--- a/fs/openpromfs/inode.c
+++ b/fs/openpromfs/inode.c
@@ -1088,8 +1088,7 @@ static void __exit exit_openprom_fs(void)
1088 unregister_filesystem(&openprom_fs_type); 1088 unregister_filesystem(&openprom_fs_type);
1089 free_pages ((unsigned long)nodes, alloced); 1089 free_pages ((unsigned long)nodes, alloced);
1090 for (i = 0; i < aliases_nodes; i++) 1090 for (i = 0; i < aliases_nodes; i++)
1091 if (alias_names [i]) 1091 kfree (alias_names [i]);
1092 kfree (alias_names [i]);
1093 nodes = NULL; 1092 nodes = NULL;
1094} 1093}
1095 1094
diff --git a/fs/partitions/ibm.c b/fs/partitions/ibm.c
index d59dcbf2bd4a..6327bcb2d73d 100644
--- a/fs/partitions/ibm.c
+++ b/fs/partitions/ibm.c
@@ -29,7 +29,7 @@
29 * cyl-cyl-head-head structure 29 * cyl-cyl-head-head structure
30 */ 30 */
31static inline int 31static inline int
32cchh2blk (cchh_t *ptr, struct hd_geometry *geo) { 32cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) {
33 return ptr->cc * geo->heads * geo->sectors + 33 return ptr->cc * geo->heads * geo->sectors +
34 ptr->hh * geo->sectors; 34 ptr->hh * geo->sectors;
35} 35}
@@ -40,7 +40,7 @@ cchh2blk (cchh_t *ptr, struct hd_geometry *geo) {
40 * cyl-cyl-head-head-block structure 40 * cyl-cyl-head-head-block structure
41 */ 41 */
42static inline int 42static inline int
43cchhb2blk (cchhb_t *ptr, struct hd_geometry *geo) { 43cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) {
44 return ptr->cc * geo->heads * geo->sectors + 44 return ptr->cc * geo->heads * geo->sectors +
45 ptr->hh * geo->sectors + 45 ptr->hh * geo->sectors +
46 ptr->b; 46 ptr->b;
@@ -56,7 +56,7 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
56 struct hd_geometry *geo; 56 struct hd_geometry *geo;
57 char type[5] = {0,}; 57 char type[5] = {0,};
58 char name[7] = {0,}; 58 char name[7] = {0,};
59 volume_label_t *vlabel; 59 struct vtoc_volume_label *vlabel;
60 unsigned char *data; 60 unsigned char *data;
61 Sector sect; 61 Sector sect;
62 62
@@ -64,7 +64,8 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
64 goto out_noinfo; 64 goto out_noinfo;
65 if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL) 65 if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL)
66 goto out_nogeo; 66 goto out_nogeo;
67 if ((vlabel = kmalloc(sizeof(volume_label_t), GFP_KERNEL)) == NULL) 67 if ((vlabel = kmalloc(sizeof(struct vtoc_volume_label),
68 GFP_KERNEL)) == NULL)
68 goto out_novlab; 69 goto out_novlab;
69 70
70 if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 || 71 if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 ||
@@ -86,7 +87,7 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
86 strncpy(name, data + 8, 6); 87 strncpy(name, data + 8, 6);
87 else 88 else
88 strncpy(name, data + 4, 6); 89 strncpy(name, data + 4, 6);
89 memcpy (vlabel, data, sizeof(volume_label_t)); 90 memcpy (vlabel, data, sizeof(struct vtoc_volume_label));
90 put_dev_sector(sect); 91 put_dev_sector(sect);
91 92
92 EBCASC(type, 4); 93 EBCASC(type, 4);
@@ -129,9 +130,9 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
129 counter = 0; 130 counter = 0;
130 while ((data = read_dev_sector(bdev, blk*(blocksize/512), 131 while ((data = read_dev_sector(bdev, blk*(blocksize/512),
131 &sect)) != NULL) { 132 &sect)) != NULL) {
132 format1_label_t f1; 133 struct vtoc_format1_label f1;
133 134
134 memcpy(&f1, data, sizeof(format1_label_t)); 135 memcpy(&f1, data, sizeof(struct vtoc_format1_label));
135 put_dev_sector(sect); 136 put_dev_sector(sect);
136 137
137 /* skip FMT4 / FMT5 / FMT7 labels */ 138 /* skip FMT4 / FMT5 / FMT7 labels */
diff --git a/fs/pnode.c b/fs/pnode.c
new file mode 100644
index 000000000000..aeeec8ba8dd2
--- /dev/null
+++ b/fs/pnode.c
@@ -0,0 +1,305 @@
1/*
2 * linux/fs/pnode.c
3 *
4 * (C) Copyright IBM Corporation 2005.
5 * Released under GPL v2.
6 * Author : Ram Pai (linuxram@us.ibm.com)
7 *
8 */
9#include <linux/namespace.h>
10#include <linux/mount.h>
11#include <linux/fs.h>
12#include "pnode.h"
13
14/* return the next shared peer mount of @p */
15static inline struct vfsmount *next_peer(struct vfsmount *p)
16{
17 return list_entry(p->mnt_share.next, struct vfsmount, mnt_share);
18}
19
20static inline struct vfsmount *first_slave(struct vfsmount *p)
21{
22 return list_entry(p->mnt_slave_list.next, struct vfsmount, mnt_slave);
23}
24
25static inline struct vfsmount *next_slave(struct vfsmount *p)
26{
27 return list_entry(p->mnt_slave.next, struct vfsmount, mnt_slave);
28}
29
30static int do_make_slave(struct vfsmount *mnt)
31{
32 struct vfsmount *peer_mnt = mnt, *master = mnt->mnt_master;
33 struct vfsmount *slave_mnt;
34
35 /*
36 * slave 'mnt' to a peer mount that has the
37 * same root dentry. If none is available than
38 * slave it to anything that is available.
39 */
40 while ((peer_mnt = next_peer(peer_mnt)) != mnt &&
41 peer_mnt->mnt_root != mnt->mnt_root) ;
42
43 if (peer_mnt == mnt) {
44 peer_mnt = next_peer(mnt);
45 if (peer_mnt == mnt)
46 peer_mnt = NULL;
47 }
48 list_del_init(&mnt->mnt_share);
49
50 if (peer_mnt)
51 master = peer_mnt;
52
53 if (master) {
54 list_for_each_entry(slave_mnt, &mnt->mnt_slave_list, mnt_slave)
55 slave_mnt->mnt_master = master;
56 list_del(&mnt->mnt_slave);
57 list_add(&mnt->mnt_slave, &master->mnt_slave_list);
58 list_splice(&mnt->mnt_slave_list, master->mnt_slave_list.prev);
59 INIT_LIST_HEAD(&mnt->mnt_slave_list);
60 } else {
61 struct list_head *p = &mnt->mnt_slave_list;
62 while (!list_empty(p)) {
63 slave_mnt = list_entry(p->next,
64 struct vfsmount, mnt_slave);
65 list_del_init(&slave_mnt->mnt_slave);
66 slave_mnt->mnt_master = NULL;
67 }
68 }
69 mnt->mnt_master = master;
70 CLEAR_MNT_SHARED(mnt);
71 INIT_LIST_HEAD(&mnt->mnt_slave_list);
72 return 0;
73}
74
75void change_mnt_propagation(struct vfsmount *mnt, int type)
76{
77 if (type == MS_SHARED) {
78 set_mnt_shared(mnt);
79 return;
80 }
81 do_make_slave(mnt);
82 if (type != MS_SLAVE) {
83 list_del_init(&mnt->mnt_slave);
84 mnt->mnt_master = NULL;
85 if (type == MS_UNBINDABLE)
86 mnt->mnt_flags |= MNT_UNBINDABLE;
87 }
88}
89
90/*
91 * get the next mount in the propagation tree.
92 * @m: the mount seen last
93 * @origin: the original mount from where the tree walk initiated
94 */
95static struct vfsmount *propagation_next(struct vfsmount *m,
96 struct vfsmount *origin)
97{
98 /* are there any slaves of this mount? */
99 if (!IS_MNT_NEW(m) && !list_empty(&m->mnt_slave_list))
100 return first_slave(m);
101
102 while (1) {
103 struct vfsmount *next;
104 struct vfsmount *master = m->mnt_master;
105
106 if ( master == origin->mnt_master ) {
107 next = next_peer(m);
108 return ((next == origin) ? NULL : next);
109 } else if (m->mnt_slave.next != &master->mnt_slave_list)
110 return next_slave(m);
111
112 /* back at master */
113 m = master;
114 }
115}
116
117/*
118 * return the source mount to be used for cloning
119 *
120 * @dest the current destination mount
121 * @last_dest the last seen destination mount
122 * @last_src the last seen source mount
123 * @type return CL_SLAVE if the new mount has to be
124 * cloned as a slave.
125 */
126static struct vfsmount *get_source(struct vfsmount *dest,
127 struct vfsmount *last_dest,
128 struct vfsmount *last_src,
129 int *type)
130{
131 struct vfsmount *p_last_src = NULL;
132 struct vfsmount *p_last_dest = NULL;
133 *type = CL_PROPAGATION;;
134
135 if (IS_MNT_SHARED(dest))
136 *type |= CL_MAKE_SHARED;
137
138 while (last_dest != dest->mnt_master) {
139 p_last_dest = last_dest;
140 p_last_src = last_src;
141 last_dest = last_dest->mnt_master;
142 last_src = last_src->mnt_master;
143 }
144
145 if (p_last_dest) {
146 do {
147 p_last_dest = next_peer(p_last_dest);
148 } while (IS_MNT_NEW(p_last_dest));
149 }
150
151 if (dest != p_last_dest) {
152 *type |= CL_SLAVE;
153 return last_src;
154 } else
155 return p_last_src;
156}
157
158/*
159 * mount 'source_mnt' under the destination 'dest_mnt' at
160 * dentry 'dest_dentry'. And propagate that mount to
161 * all the peer and slave mounts of 'dest_mnt'.
162 * Link all the new mounts into a propagation tree headed at
163 * source_mnt. Also link all the new mounts using ->mnt_list
164 * headed at source_mnt's ->mnt_list
165 *
166 * @dest_mnt: destination mount.
167 * @dest_dentry: destination dentry.
168 * @source_mnt: source mount.
169 * @tree_list : list of heads of trees to be attached.
170 */
171int propagate_mnt(struct vfsmount *dest_mnt, struct dentry *dest_dentry,
172 struct vfsmount *source_mnt, struct list_head *tree_list)
173{
174 struct vfsmount *m, *child;
175 int ret = 0;
176 struct vfsmount *prev_dest_mnt = dest_mnt;
177 struct vfsmount *prev_src_mnt = source_mnt;
178 LIST_HEAD(tmp_list);
179 LIST_HEAD(umount_list);
180
181 for (m = propagation_next(dest_mnt, dest_mnt); m;
182 m = propagation_next(m, dest_mnt)) {
183 int type;
184 struct vfsmount *source;
185
186 if (IS_MNT_NEW(m))
187 continue;
188
189 source = get_source(m, prev_dest_mnt, prev_src_mnt, &type);
190
191 if (!(child = copy_tree(source, source->mnt_root, type))) {
192 ret = -ENOMEM;
193 list_splice(tree_list, tmp_list.prev);
194 goto out;
195 }
196
197 if (is_subdir(dest_dentry, m->mnt_root)) {
198 mnt_set_mountpoint(m, dest_dentry, child);
199 list_add_tail(&child->mnt_hash, tree_list);
200 } else {
201 /*
202 * This can happen if the parent mount was bind mounted
203 * on some subdirectory of a shared/slave mount.
204 */
205 list_add_tail(&child->mnt_hash, &tmp_list);
206 }
207 prev_dest_mnt = m;
208 prev_src_mnt = child;
209 }
210out:
211 spin_lock(&vfsmount_lock);
212 while (!list_empty(&tmp_list)) {
213 child = list_entry(tmp_list.next, struct vfsmount, mnt_hash);
214 list_del_init(&child->mnt_hash);
215 umount_tree(child, 0, &umount_list);
216 }
217 spin_unlock(&vfsmount_lock);
218 release_mounts(&umount_list);
219 return ret;
220}
221
222/*
223 * return true if the refcount is greater than count
224 */
225static inline int do_refcount_check(struct vfsmount *mnt, int count)
226{
227 int mycount = atomic_read(&mnt->mnt_count);
228 return (mycount > count);
229}
230
231/*
232 * check if the mount 'mnt' can be unmounted successfully.
233 * @mnt: the mount to be checked for unmount
234 * NOTE: unmounting 'mnt' would naturally propagate to all
235 * other mounts its parent propagates to.
236 * Check if any of these mounts that **do not have submounts**
237 * have more references than 'refcnt'. If so return busy.
238 */
239int propagate_mount_busy(struct vfsmount *mnt, int refcnt)
240{
241 struct vfsmount *m, *child;
242 struct vfsmount *parent = mnt->mnt_parent;
243 int ret = 0;
244
245 if (mnt == parent)
246 return do_refcount_check(mnt, refcnt);
247
248 /*
249 * quickly check if the current mount can be unmounted.
250 * If not, we don't have to go checking for all other
251 * mounts
252 */
253 if (!list_empty(&mnt->mnt_mounts) || do_refcount_check(mnt, refcnt))
254 return 1;
255
256 for (m = propagation_next(parent, parent); m;
257 m = propagation_next(m, parent)) {
258 child = __lookup_mnt(m, mnt->mnt_mountpoint, 0);
259 if (child && list_empty(&child->mnt_mounts) &&
260 (ret = do_refcount_check(child, 1)))
261 break;
262 }
263 return ret;
264}
265
266/*
267 * NOTE: unmounting 'mnt' naturally propagates to all other mounts its
268 * parent propagates to.
269 */
270static void __propagate_umount(struct vfsmount *mnt)
271{
272 struct vfsmount *parent = mnt->mnt_parent;
273 struct vfsmount *m;
274
275 BUG_ON(parent == mnt);
276
277 for (m = propagation_next(parent, parent); m;
278 m = propagation_next(m, parent)) {
279
280 struct vfsmount *child = __lookup_mnt(m,
281 mnt->mnt_mountpoint, 0);
282 /*
283 * umount the child only if the child has no
284 * other children
285 */
286 if (child && list_empty(&child->mnt_mounts)) {
287 list_del(&child->mnt_hash);
288 list_add_tail(&child->mnt_hash, &mnt->mnt_hash);
289 }
290 }
291}
292
293/*
294 * collect all mounts that receive propagation from the mount in @list,
295 * and return these additional mounts in the same list.
296 * @list: the list of mounts to be unmounted.
297 */
298int propagate_umount(struct list_head *list)
299{
300 struct vfsmount *mnt;
301
302 list_for_each_entry(mnt, list, mnt_hash)
303 __propagate_umount(mnt);
304 return 0;
305}
diff --git a/fs/pnode.h b/fs/pnode.h
new file mode 100644
index 000000000000..020e1bb60fdb
--- /dev/null
+++ b/fs/pnode.h
@@ -0,0 +1,37 @@
1/*
2 * linux/fs/pnode.h
3 *
4 * (C) Copyright IBM Corporation 2005.
5 * Released under GPL v2.
6 *
7 */
8#ifndef _LINUX_PNODE_H
9#define _LINUX_PNODE_H
10
11#include <linux/list.h>
12#include <linux/mount.h>
13
14#define IS_MNT_SHARED(mnt) (mnt->mnt_flags & MNT_SHARED)
15#define IS_MNT_SLAVE(mnt) (mnt->mnt_master)
16#define IS_MNT_NEW(mnt) (!mnt->mnt_namespace)
17#define CLEAR_MNT_SHARED(mnt) (mnt->mnt_flags &= ~MNT_SHARED)
18#define IS_MNT_UNBINDABLE(mnt) (mnt->mnt_flags & MNT_UNBINDABLE)
19
20#define CL_EXPIRE 0x01
21#define CL_SLAVE 0x02
22#define CL_COPY_ALL 0x04
23#define CL_MAKE_SHARED 0x08
24#define CL_PROPAGATION 0x10
25
26static inline void set_mnt_shared(struct vfsmount *mnt)
27{
28 mnt->mnt_flags &= ~MNT_PNODE_MASK;
29 mnt->mnt_flags |= MNT_SHARED;
30}
31
32void change_mnt_propagation(struct vfsmount *, int);
33int propagate_mnt(struct vfsmount *, struct dentry *, struct vfsmount *,
34 struct list_head *);
35int propagate_umount(struct list_head *);
36int propagate_mount_busy(struct vfsmount *, int);
37#endif /* _LINUX_PNODE_H */
diff --git a/fs/proc/base.c b/fs/proc/base.c
index a170450aadb1..634355e16986 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -70,6 +70,7 @@
70#include <linux/seccomp.h> 70#include <linux/seccomp.h>
71#include <linux/cpuset.h> 71#include <linux/cpuset.h>
72#include <linux/audit.h> 72#include <linux/audit.h>
73#include <linux/poll.h>
73#include "internal.h" 74#include "internal.h"
74 75
75/* 76/*
@@ -660,26 +661,38 @@ static struct file_operations proc_smaps_operations = {
660#endif 661#endif
661 662
662extern struct seq_operations mounts_op; 663extern struct seq_operations mounts_op;
664struct proc_mounts {
665 struct seq_file m;
666 int event;
667};
668
663static int mounts_open(struct inode *inode, struct file *file) 669static int mounts_open(struct inode *inode, struct file *file)
664{ 670{
665 struct task_struct *task = proc_task(inode); 671 struct task_struct *task = proc_task(inode);
666 int ret = seq_open(file, &mounts_op); 672 struct namespace *namespace;
673 struct proc_mounts *p;
674 int ret = -EINVAL;
667 675
668 if (!ret) { 676 task_lock(task);
669 struct seq_file *m = file->private_data; 677 namespace = task->namespace;
670 struct namespace *namespace; 678 if (namespace)
671 task_lock(task); 679 get_namespace(namespace);
672 namespace = task->namespace; 680 task_unlock(task);
673 if (namespace) 681
674 get_namespace(namespace); 682 if (namespace) {
675 task_unlock(task); 683 ret = -ENOMEM;
676 684 p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);
677 if (namespace) 685 if (p) {
678 m->private = namespace; 686 file->private_data = &p->m;
679 else { 687 ret = seq_open(file, &mounts_op);
680 seq_release(inode, file); 688 if (!ret) {
681 ret = -EINVAL; 689 p->m.private = namespace;
690 p->event = namespace->event;
691 return 0;
692 }
693 kfree(p);
682 } 694 }
695 put_namespace(namespace);
683 } 696 }
684 return ret; 697 return ret;
685} 698}
@@ -692,11 +705,30 @@ static int mounts_release(struct inode *inode, struct file *file)
692 return seq_release(inode, file); 705 return seq_release(inode, file);
693} 706}
694 707
708static unsigned mounts_poll(struct file *file, poll_table *wait)
709{
710 struct proc_mounts *p = file->private_data;
711 struct namespace *ns = p->m.private;
712 unsigned res = 0;
713
714 poll_wait(file, &ns->poll, wait);
715
716 spin_lock(&vfsmount_lock);
717 if (p->event != ns->event) {
718 p->event = ns->event;
719 res = POLLERR;
720 }
721 spin_unlock(&vfsmount_lock);
722
723 return res;
724}
725
695static struct file_operations proc_mounts_operations = { 726static struct file_operations proc_mounts_operations = {
696 .open = mounts_open, 727 .open = mounts_open,
697 .read = seq_read, 728 .read = seq_read,
698 .llseek = seq_lseek, 729 .llseek = seq_lseek,
699 .release = mounts_release, 730 .release = mounts_release,
731 .poll = mounts_poll,
700}; 732};
701 733
702#define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */ 734#define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */
diff --git a/fs/quota.c b/fs/quota.c
index 1df7832b4e08..612e04db4b93 100644
--- a/fs/quota.c
+++ b/fs/quota.c
@@ -15,6 +15,7 @@
15#include <linux/security.h> 15#include <linux/security.h>
16#include <linux/syscalls.h> 16#include <linux/syscalls.h>
17#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
18#include <linux/quotaops.h>
18 19
19/* Check validity of generic quotactl commands */ 20/* Check validity of generic quotactl commands */
20static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id) 21static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 38ef913767ff..7c40570b71dc 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -28,13 +28,17 @@
28 */ 28 */
29int seq_open(struct file *file, struct seq_operations *op) 29int seq_open(struct file *file, struct seq_operations *op)
30{ 30{
31 struct seq_file *p = kmalloc(sizeof(*p), GFP_KERNEL); 31 struct seq_file *p = file->private_data;
32 if (!p) 32
33 return -ENOMEM; 33 if (!p) {
34 p = kmalloc(sizeof(*p), GFP_KERNEL);
35 if (!p)
36 return -ENOMEM;
37 file->private_data = p;
38 }
34 memset(p, 0, sizeof(*p)); 39 memset(p, 0, sizeof(*p));
35 sema_init(&p->sem, 1); 40 sema_init(&p->sem, 1);
36 p->op = op; 41 p->op = op;
37 file->private_data = p;
38 42
39 /* 43 /*
40 * Wrappers around seq_open(e.g. swaps_open) need to be 44 * Wrappers around seq_open(e.g. swaps_open) need to be
diff --git a/fs/smbfs/request.c b/fs/smbfs/request.c
index 2d85dd7415bb..a0f296d9928a 100644
--- a/fs/smbfs/request.c
+++ b/fs/smbfs/request.c
@@ -786,8 +786,7 @@ int smb_request_recv(struct smb_sb_info *server)
786 /* We should never be called with any of these states */ 786 /* We should never be called with any of these states */
787 case SMB_RECV_END: 787 case SMB_RECV_END:
788 case SMB_RECV_REQUEST: 788 case SMB_RECV_REQUEST:
789 server->rstate = SMB_RECV_END; 789 BUG();
790 break;
791 } 790 }
792 791
793 if (result < 0) { 792 if (result < 0) {
diff --git a/fs/smbfs/symlink.c b/fs/smbfs/symlink.c
index 0c64bc3a0127..cdc53c4fb381 100644
--- a/fs/smbfs/symlink.c
+++ b/fs/smbfs/symlink.c
@@ -45,7 +45,7 @@ static void *smb_follow_link(struct dentry *dentry, struct nameidata *nd)
45 int len = smb_proc_read_link(server_from_dentry(dentry), 45 int len = smb_proc_read_link(server_from_dentry(dentry),
46 dentry, link, PATH_MAX - 1); 46 dentry, link, PATH_MAX - 1);
47 if (len < 0) { 47 if (len < 0) {
48 putname(link); 48 __putname(link);
49 link = ERR_PTR(len); 49 link = ERR_PTR(len);
50 } else { 50 } else {
51 link[len] = 0; 51 link[len] = 0;
@@ -59,7 +59,7 @@ static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
59{ 59{
60 char *s = nd_get_link(nd); 60 char *s = nd_get_link(nd);
61 if (!IS_ERR(s)) 61 if (!IS_ERR(s))
62 putname(s); 62 __putname(s);
63} 63}
64 64
65struct inode_operations smb_link_inode_operations = 65struct inode_operations smb_link_inode_operations =
diff --git a/fs/super.c b/fs/super.c
index f60155ec7780..6689dded3c84 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -171,6 +171,7 @@ void deactivate_super(struct super_block *s)
171 if (atomic_dec_and_lock(&s->s_active, &sb_lock)) { 171 if (atomic_dec_and_lock(&s->s_active, &sb_lock)) {
172 s->s_count -= S_BIAS-1; 172 s->s_count -= S_BIAS-1;
173 spin_unlock(&sb_lock); 173 spin_unlock(&sb_lock);
174 DQUOT_OFF(s);
174 down_write(&s->s_umount); 175 down_write(&s->s_umount);
175 fs->kill_sb(s); 176 fs->kill_sb(s);
176 put_filesystem(fs); 177 put_filesystem(fs);
@@ -474,8 +475,6 @@ rescan:
474 return NULL; 475 return NULL;
475} 476}
476 477
477EXPORT_SYMBOL(user_get_super);
478
479asmlinkage long sys_ustat(unsigned dev, struct ustat __user * ubuf) 478asmlinkage long sys_ustat(unsigned dev, struct ustat __user * ubuf)
480{ 479{
481 struct super_block *s; 480 struct super_block *s;
diff --git a/fs/udf/udf_sb.h b/fs/udf/udf_sb.h
index 0e54922daa09..663669810be6 100644
--- a/fs/udf/udf_sb.h
+++ b/fs/udf/udf_sb.h
@@ -39,8 +39,7 @@ static inline struct udf_sb_info *UDF_SB(struct super_block *sb)
39{\ 39{\
40 if (UDF_SB(X))\ 40 if (UDF_SB(X))\
41 {\ 41 {\
42 if (UDF_SB_PARTMAPS(X))\ 42 kfree(UDF_SB_PARTMAPS(X));\
43 kfree(UDF_SB_PARTMAPS(X));\
44 UDF_SB_PARTMAPS(X) = NULL;\ 43 UDF_SB_PARTMAPS(X) = NULL;\
45 }\ 44 }\
46} 45}
diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index f036d694ba5a..54828ebcf1ba 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -472,13 +472,14 @@ static int ufs_read_cylinder_structures (struct super_block *sb) {
472 return 1; 472 return 1;
473 473
474failed: 474failed:
475 if (base) kfree (base); 475 kfree (base);
476 if (sbi->s_ucg) { 476 if (sbi->s_ucg) {
477 for (i = 0; i < uspi->s_ncg; i++) 477 for (i = 0; i < uspi->s_ncg; i++)
478 if (sbi->s_ucg[i]) brelse (sbi->s_ucg[i]); 478 if (sbi->s_ucg[i])
479 brelse (sbi->s_ucg[i]);
479 kfree (sbi->s_ucg); 480 kfree (sbi->s_ucg);
480 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) 481 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
481 if (sbi->s_ucpi[i]) kfree (sbi->s_ucpi[i]); 482 kfree (sbi->s_ucpi[i]);
482 } 483 }
483 UFSD(("EXIT (FAILED)\n")) 484 UFSD(("EXIT (FAILED)\n"))
484 return 0; 485 return 0;
@@ -981,9 +982,10 @@ magic_found:
981dalloc_failed: 982dalloc_failed:
982 iput(inode); 983 iput(inode);
983failed: 984failed:
984 if (ubh) ubh_brelse_uspi (uspi); 985 if (ubh)
985 if (uspi) kfree (uspi); 986 ubh_brelse_uspi (uspi);
986 if (sbi) kfree(sbi); 987 kfree (uspi);
988 kfree(sbi);
987 sb->s_fs_info = NULL; 989 sb->s_fs_info = NULL;
988 UFSD(("EXIT (FAILED)\n")) 990 UFSD(("EXIT (FAILED)\n"))
989 return -EINVAL; 991 return -EINVAL;
diff --git a/fs/xattr.c b/fs/xattr.c
index f6e00c0e114f..a9db22557998 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -74,8 +74,7 @@ setxattr(struct dentry *d, char __user *name, void __user *value,
74 } 74 }
75out: 75out:
76 up(&d->d_inode->i_sem); 76 up(&d->d_inode->i_sem);
77 if (kvalue) 77 kfree(kvalue);
78 kfree(kvalue);
79 return error; 78 return error;
80} 79}
81 80
@@ -173,8 +172,7 @@ getxattr(struct dentry *d, char __user *name, void __user *value, size_t size)
173 error = -E2BIG; 172 error = -E2BIG;
174 } 173 }
175out: 174out:
176 if (kvalue) 175 kfree(kvalue);
177 kfree(kvalue);
178 return error; 176 return error;
179} 177}
180 178
@@ -259,8 +257,7 @@ listxattr(struct dentry *d, char __user *list, size_t size)
259 error = -E2BIG; 257 error = -E2BIG;
260 } 258 }
261out: 259out:
262 if (klist) 260 kfree(klist);
263 kfree(klist);
264 return error; 261 return error;
265} 262}
266 263
diff --git a/fs/xfs/linux-2.6/kmem.h b/fs/xfs/linux-2.6/kmem.h
index 8f82c1a20dc5..c64a29cdfff3 100644
--- a/fs/xfs/linux-2.6/kmem.h
+++ b/fs/xfs/linux-2.6/kmem.h
@@ -30,8 +30,8 @@
30#define KM_NOFS 0x0004u 30#define KM_NOFS 0x0004u
31#define KM_MAYFAIL 0x0008u 31#define KM_MAYFAIL 0x0008u
32 32
33#define kmem_zone kmem_cache_s 33#define kmem_zone kmem_cache
34#define kmem_zone_t kmem_cache_t 34#define kmem_zone_t struct kmem_cache
35 35
36typedef unsigned long xfs_pflags_t; 36typedef unsigned long xfs_pflags_t;
37 37
diff --git a/include/asm-alpha/pgtable.h b/include/asm-alpha/pgtable.h
index 8393bf374b2b..a985cd29b6db 100644
--- a/include/asm-alpha/pgtable.h
+++ b/include/asm-alpha/pgtable.h
@@ -17,6 +17,9 @@
17#include <asm/processor.h> /* For TASK_SIZE */ 17#include <asm/processor.h> /* For TASK_SIZE */
18#include <asm/machvec.h> 18#include <asm/machvec.h>
19 19
20struct mm_struct;
21struct vm_area_struct;
22
20/* Certain architectures need to do special things when PTEs 23/* Certain architectures need to do special things when PTEs
21 * within a page table are directly modified. Thus, the following 24 * within a page table are directly modified. Thus, the following
22 * hook is made available. 25 * hook is made available.
diff --git a/include/asm-alpha/ptrace.h b/include/asm-alpha/ptrace.h
index d462c5e14c13..072375c135b4 100644
--- a/include/asm-alpha/ptrace.h
+++ b/include/asm-alpha/ptrace.h
@@ -67,6 +67,9 @@ struct switch_stack {
67}; 67};
68 68
69#ifdef __KERNEL__ 69#ifdef __KERNEL__
70
71#define __ARCH_SYS_PTRACE 1
72
70#define user_mode(regs) (((regs)->ps & 8) != 0) 73#define user_mode(regs) (((regs)->ps & 8) != 0)
71#define instruction_pointer(regs) ((regs)->pc) 74#define instruction_pointer(regs) ((regs)->pc)
72#define profile_pc(regs) instruction_pointer(regs) 75#define profile_pc(regs) instruction_pointer(regs)
diff --git a/include/asm-arm/arch-realview/entry-macro.S b/include/asm-arm/arch-realview/entry-macro.S
index 2712ba77bb3a..4df469bf42e2 100644
--- a/include/asm-arm/arch-realview/entry-macro.S
+++ b/include/asm-arm/arch-realview/entry-macro.S
@@ -47,3 +47,17 @@
47 cmpcs \irqnr, \irqnr 47 cmpcs \irqnr, \irqnr
48 48
49 .endm 49 .endm
50
51 /* We assume that irqstat (the raw value of the IRQ acknowledge
52 * register) is preserved from the macro above.
53 * If there is an IPI, we immediately signal end of interrupt on the
54 * controller, since this requires the original irqstat value which
55 * we won't easily be able to recreate later.
56 */
57
58 .macro test_for_ipi, irqnr, irqstat, base, tmp
59 bic \irqnr, \irqstat, #0x1c00
60 cmp \irqnr, #16
61 strcc \irqstat, [\base, #GIC_CPU_EOI]
62 cmpcs \irqnr, \irqnr
63 .endm
diff --git a/include/asm-arm/arch-realview/platform.h b/include/asm-arm/arch-realview/platform.h
index 4b6de13a6b9a..aef9b36b3c37 100644
--- a/include/asm-arm/arch-realview/platform.h
+++ b/include/asm-arm/arch-realview/platform.h
@@ -203,8 +203,14 @@
203 /* Reserved 0x1001A000 - 0x1001FFFF */ 203 /* Reserved 0x1001A000 - 0x1001FFFF */
204#define REALVIEW_CLCD_BASE 0x10020000 /* CLCD */ 204#define REALVIEW_CLCD_BASE 0x10020000 /* CLCD */
205#define REALVIEW_DMAC_BASE 0x10030000 /* DMA controller */ 205#define REALVIEW_DMAC_BASE 0x10030000 /* DMA controller */
206#ifndef CONFIG_REALVIEW_MPCORE
206#define REALVIEW_GIC_CPU_BASE 0x10040000 /* Generic interrupt controller CPU interface */ 207#define REALVIEW_GIC_CPU_BASE 0x10040000 /* Generic interrupt controller CPU interface */
207#define REALVIEW_GIC_DIST_BASE 0x10041000 /* Generic interrupt controller distributor */ 208#define REALVIEW_GIC_DIST_BASE 0x10041000 /* Generic interrupt controller distributor */
209#else
210#define REALVIEW_MPCORE_SCU_BASE 0x10100000 /* SCU registers */
211#define REALVIEW_GIC_CPU_BASE 0x10100100 /* Generic interrupt controller CPU interface */
212#define REALVIEW_GIC_DIST_BASE 0x10101000 /* Generic interrupt controller distributor */
213#endif
208#define REALVIEW_SMC_BASE 0x10080000 /* SMC */ 214#define REALVIEW_SMC_BASE 0x10080000 /* SMC */
209 /* Reserved 0x10090000 - 0x100EFFFF */ 215 /* Reserved 0x10090000 - 0x100EFFFF */
210 216
@@ -265,6 +271,7 @@
265 * Interrupts - bit assignment (primary) 271 * Interrupts - bit assignment (primary)
266 * ------------------------------------------------------------------------ 272 * ------------------------------------------------------------------------
267 */ 273 */
274#ifndef CONFIG_REALVIEW_MPCORE
268#define INT_WDOGINT 0 /* Watchdog timer */ 275#define INT_WDOGINT 0 /* Watchdog timer */
269#define INT_SOFTINT 1 /* Software interrupt */ 276#define INT_SOFTINT 1 /* Software interrupt */
270#define INT_COMMRx 2 /* Debug Comm Rx interrupt */ 277#define INT_COMMRx 2 /* Debug Comm Rx interrupt */
@@ -297,6 +304,55 @@
297#define INT_USB 29 /* USB controller */ 304#define INT_USB 29 /* USB controller */
298#define INT_TSPENINT 30 /* Touchscreen pen */ 305#define INT_TSPENINT 30 /* Touchscreen pen */
299#define INT_TSKPADINT 31 /* Touchscreen keypad */ 306#define INT_TSKPADINT 31 /* Touchscreen keypad */
307#else
308#define INT_LOCALTIMER 29
309#define INT_LOCALWDOG 30
310
311#define INT_AACI 0
312#define INT_TIMERINT0_1 1
313#define INT_TIMERINT2_3 2
314#define INT_USB 3
315#define INT_UARTINT0 4
316#define INT_UARTINT1 5
317#define INT_RTCINT 6
318#define INT_KMI0 7
319#define INT_KMI1 8
320#define INT_ETH 9
321#define INT_EB_IRQ1 10 /* main GIC */
322#define INT_EB_IRQ2 11 /* tile GIC */
323#define INT_EB_FIQ1 12 /* main GIC */
324#define INT_EB_FIQ2 13 /* tile GIC */
325#define INT_MMCI0A 14
326#define INT_MMCI0B 15
327
328#define INT_PMU_CPU0 17
329#define INT_PMU_CPU1 18
330#define INT_PMU_CPU2 19
331#define INT_PMU_CPU3 20
332#define INT_PMU_SCU0 21
333#define INT_PMU_SCU1 22
334#define INT_PMU_SCU2 23
335#define INT_PMU_SCU3 24
336#define INT_PMU_SCU4 25
337#define INT_PMU_SCU5 26
338#define INT_PMU_SCU6 27
339#define INT_PMU_SCU7 28
340
341#define INT_L220_EVENT 29
342#define INT_L220_SLAVE 30
343#define INT_L220_DECODE 31
344
345#define INT_UARTINT2 -1
346#define INT_UARTINT3 -1
347#define INT_CLCDINT -1
348#define INT_DMAINT -1
349#define INT_WDOGINT -1
350#define INT_GPIOINT0 -1
351#define INT_GPIOINT1 -1
352#define INT_GPIOINT2 -1
353#define INT_SCIINT -1
354#define INT_SSPINT -1
355#endif
300 356
301/* 357/*
302 * Interrupt bit positions 358 * Interrupt bit positions
diff --git a/include/asm-arm/arch-realview/smp.h b/include/asm-arm/arch-realview/smp.h
new file mode 100644
index 000000000000..fc87783e8e8b
--- /dev/null
+++ b/include/asm-arm/arch-realview/smp.h
@@ -0,0 +1,31 @@
1#ifndef ASMARM_ARCH_SMP_H
2#define ASMARM_ARCH_SMP_H
3
4#include <linux/config.h>
5
6#include <asm/hardware/gic.h>
7
8#define hard_smp_processor_id() \
9 ({ \
10 unsigned int cpunum; \
11 __asm__("mrc p15, 0, %0, c0, c0, 5" \
12 : "=r" (cpunum)); \
13 cpunum &= 0x0F; \
14 })
15
16/*
17 * We use IRQ1 as the IPI
18 */
19static inline void smp_cross_call(cpumask_t callmap)
20{
21 gic_raise_softirq(callmap, 1);
22}
23
24/*
25 * Do nothing on MPcore.
26 */
27static inline void smp_cross_call_done(cpumask_t callmap)
28{
29}
30
31#endif
diff --git a/include/asm-arm/hardware/arm_scu.h b/include/asm-arm/hardware/arm_scu.h
new file mode 100644
index 000000000000..9903f60c84b7
--- /dev/null
+++ b/include/asm-arm/hardware/arm_scu.h
@@ -0,0 +1,13 @@
1#ifndef ASMARM_HARDWARE_ARM_SCU_H
2#define ASMARM_HARDWARE_ARM_SCU_H
3
4/*
5 * SCU registers
6 */
7#define SCU_CTRL 0x00
8#define SCU_CONFIG 0x04
9#define SCU_CPU_STATUS 0x08
10#define SCU_INVALIDATE 0x0c
11#define SCU_FPGA_REVISION 0x10
12
13#endif
diff --git a/include/asm-cris/arch-v10/byteorder.h b/include/asm-cris/arch-v10/byteorder.h
index e24465d1f40d..255b646b7fa8 100644
--- a/include/asm-cris/arch-v10/byteorder.h
+++ b/include/asm-cris/arch-v10/byteorder.h
@@ -9,14 +9,14 @@
9 * them together into ntohl etc. 9 * them together into ntohl etc.
10 */ 10 */
11 11
12extern __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x) 12static inline __attribute_const__ __u32 ___arch__swab32(__u32 x)
13{ 13{
14 __asm__ ("swapwb %0" : "=r" (x) : "0" (x)); 14 __asm__ ("swapwb %0" : "=r" (x) : "0" (x));
15 15
16 return(x); 16 return(x);
17} 17}
18 18
19extern __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x) 19static inline __attribute_const__ __u16 ___arch__swab16(__u16 x)
20{ 20{
21 __asm__ ("swapb %0" : "=r" (x) : "0" (x)); 21 __asm__ ("swapb %0" : "=r" (x) : "0" (x));
22 22
diff --git a/include/asm-cris/arch-v10/checksum.h b/include/asm-cris/arch-v10/checksum.h
index fde1d00aaa90..633f234f336b 100644
--- a/include/asm-cris/arch-v10/checksum.h
+++ b/include/asm-cris/arch-v10/checksum.h
@@ -8,7 +8,7 @@
8 * to split all of those into 16-bit components, then add. 8 * to split all of those into 16-bit components, then add.
9 */ 9 */
10 10
11extern inline unsigned int 11static inline unsigned int
12csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, unsigned short len, 12csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, unsigned short len,
13 unsigned short proto, unsigned int sum) 13 unsigned short proto, unsigned int sum)
14{ 14{
diff --git a/include/asm-cris/arch-v10/delay.h b/include/asm-cris/arch-v10/delay.h
index cfedae0d2f53..39481f6e0c30 100644
--- a/include/asm-cris/arch-v10/delay.h
+++ b/include/asm-cris/arch-v10/delay.h
@@ -1,7 +1,7 @@
1#ifndef _CRIS_ARCH_DELAY_H 1#ifndef _CRIS_ARCH_DELAY_H
2#define _CRIS_ARCH_DELAY_H 2#define _CRIS_ARCH_DELAY_H
3 3
4extern __inline__ void __delay(int loops) 4static inline void __delay(int loops)
5{ 5{
6 __asm__ __volatile__ ( 6 __asm__ __volatile__ (
7 "move.d %0,$r9\n\t" 7 "move.d %0,$r9\n\t"
diff --git a/include/asm-cris/arch-v10/ide.h b/include/asm-cris/arch-v10/ide.h
index 8cf2d7cb22ac..78b301ed7b12 100644
--- a/include/asm-cris/arch-v10/ide.h
+++ b/include/asm-cris/arch-v10/ide.h
@@ -25,7 +25,7 @@
25 25
26#define MAX_HWIFS 4 26#define MAX_HWIFS 4
27 27
28extern __inline__ int ide_default_irq(unsigned long base) 28static inline int ide_default_irq(unsigned long base)
29{ 29{
30 /* all IDE busses share the same IRQ, number 4. 30 /* all IDE busses share the same IRQ, number 4.
31 * this has the side-effect that ide-probe.c will cluster our 4 interfaces 31 * this has the side-effect that ide-probe.c will cluster our 4 interfaces
@@ -35,7 +35,7 @@ extern __inline__ int ide_default_irq(unsigned long base)
35 return 4; 35 return 4;
36} 36}
37 37
38extern __inline__ unsigned long ide_default_io_base(int index) 38static inline unsigned long ide_default_io_base(int index)
39{ 39{
40 /* we have no real I/O base address per interface, since all go through the 40 /* we have no real I/O base address per interface, since all go through the
41 * same register. but in a bitfield in that register, we have the i/f number. 41 * same register. but in a bitfield in that register, we have the i/f number.
@@ -54,7 +54,7 @@ extern __inline__ unsigned long ide_default_io_base(int index)
54 * of the ide_default_io_base call above. ctrl_port will be 0, but that is don't care for us. 54 * of the ide_default_io_base call above. ctrl_port will be 0, but that is don't care for us.
55 */ 55 */
56 56
57extern __inline__ void ide_init_hwif_ports(hw_regs_t *hw, unsigned long data_port, unsigned long ctrl_port, int *irq) 57static inline void ide_init_hwif_ports(hw_regs_t *hw, unsigned long data_port, unsigned long ctrl_port, int *irq)
58{ 58{
59 int i; 59 int i;
60 60
@@ -77,7 +77,7 @@ extern __inline__ void ide_init_hwif_ports(hw_regs_t *hw, unsigned long data_por
77 hw->io_ports[IDE_IRQ_OFFSET] = 0; 77 hw->io_ports[IDE_IRQ_OFFSET] = 0;
78} 78}
79 79
80extern __inline__ void ide_init_default_hwifs(void) 80static inline void ide_init_default_hwifs(void)
81{ 81{
82 hw_regs_t hw; 82 hw_regs_t hw;
83 int index; 83 int index;
diff --git a/include/asm-cris/arch-v10/system.h b/include/asm-cris/arch-v10/system.h
index 6cc35642b8ab..1ac7b639b1b0 100644
--- a/include/asm-cris/arch-v10/system.h
+++ b/include/asm-cris/arch-v10/system.h
@@ -5,7 +5,7 @@
5 5
6/* read the CPU version register */ 6/* read the CPU version register */
7 7
8extern inline unsigned long rdvr(void) { 8static inline unsigned long rdvr(void) {
9 unsigned char vr; 9 unsigned char vr;
10 __asm__ volatile ("move $vr,%0" : "=rm" (vr)); 10 __asm__ volatile ("move $vr,%0" : "=rm" (vr));
11 return vr; 11 return vr;
@@ -15,7 +15,7 @@ extern inline unsigned long rdvr(void) {
15 15
16/* read/write the user-mode stackpointer */ 16/* read/write the user-mode stackpointer */
17 17
18extern inline unsigned long rdusp(void) { 18static inline unsigned long rdusp(void) {
19 unsigned long usp; 19 unsigned long usp;
20 __asm__ __volatile__("move $usp,%0" : "=rm" (usp)); 20 __asm__ __volatile__("move $usp,%0" : "=rm" (usp));
21 return usp; 21 return usp;
@@ -26,13 +26,13 @@ extern inline unsigned long rdusp(void) {
26 26
27/* read the current stackpointer */ 27/* read the current stackpointer */
28 28
29extern inline unsigned long rdsp(void) { 29static inline unsigned long rdsp(void) {
30 unsigned long sp; 30 unsigned long sp;
31 __asm__ __volatile__("move.d $sp,%0" : "=rm" (sp)); 31 __asm__ __volatile__("move.d $sp,%0" : "=rm" (sp));
32 return sp; 32 return sp;
33} 33}
34 34
35extern inline unsigned long _get_base(char * addr) 35static inline unsigned long _get_base(char * addr)
36{ 36{
37 return 0; 37 return 0;
38} 38}
diff --git a/include/asm-cris/arch-v10/thread_info.h b/include/asm-cris/arch-v10/thread_info.h
index 357f5df0c907..218f4152d3e5 100644
--- a/include/asm-cris/arch-v10/thread_info.h
+++ b/include/asm-cris/arch-v10/thread_info.h
@@ -2,7 +2,7 @@
2#define _ASM_ARCH_THREAD_INFO_H 2#define _ASM_ARCH_THREAD_INFO_H
3 3
4/* how to get the thread information struct from C */ 4/* how to get the thread information struct from C */
5extern inline struct thread_info *current_thread_info(void) 5static inline struct thread_info *current_thread_info(void)
6{ 6{
7 struct thread_info *ti; 7 struct thread_info *ti;
8 __asm__("and.d $sp,%0; ":"=r" (ti) : "0" (~8191UL)); 8 __asm__("and.d $sp,%0; ":"=r" (ti) : "0" (~8191UL));
diff --git a/include/asm-cris/arch-v10/timex.h b/include/asm-cris/arch-v10/timex.h
index ecfc553c06a5..e48447d94faf 100644
--- a/include/asm-cris/arch-v10/timex.h
+++ b/include/asm-cris/arch-v10/timex.h
@@ -22,7 +22,7 @@
22 22
23unsigned long get_ns_in_jiffie(void); 23unsigned long get_ns_in_jiffie(void);
24 24
25extern inline unsigned long get_us_in_jiffie_highres(void) 25static inline unsigned long get_us_in_jiffie_highres(void)
26{ 26{
27 return get_ns_in_jiffie()/1000; 27 return get_ns_in_jiffie()/1000;
28} 28}
diff --git a/include/asm-cris/arch-v10/uaccess.h b/include/asm-cris/arch-v10/uaccess.h
index 787d2e60c83c..65b02d9b605a 100644
--- a/include/asm-cris/arch-v10/uaccess.h
+++ b/include/asm-cris/arch-v10/uaccess.h
@@ -87,7 +87,7 @@
87 * bytes copied if we hit a null byte 87 * bytes copied if we hit a null byte
88 * (without the null byte) 88 * (without the null byte)
89 */ 89 */
90extern inline long 90static inline long
91__do_strncpy_from_user(char *dst, const char *src, long count) 91__do_strncpy_from_user(char *dst, const char *src, long count)
92{ 92{
93 long res; 93 long res;
@@ -602,7 +602,7 @@ __do_strncpy_from_user(char *dst, const char *src, long count)
602 * or 0 for error. Return a value greater than N if too long. 602 * or 0 for error. Return a value greater than N if too long.
603 */ 603 */
604 604
605extern inline long 605static inline long
606strnlen_user(const char *s, long n) 606strnlen_user(const char *s, long n)
607{ 607{
608 long res, tmp1; 608 long res, tmp1;
diff --git a/include/asm-cris/arch-v32/bitops.h b/include/asm-cris/arch-v32/bitops.h
index e40a58d3b862..147689d6b624 100644
--- a/include/asm-cris/arch-v32/bitops.h
+++ b/include/asm-cris/arch-v32/bitops.h
@@ -8,7 +8,7 @@
8 * inverts all bits in the input. 8 * inverts all bits in the input.
9 */ 9 */
10 10
11extern inline unsigned long 11static inline unsigned long
12cris_swapnwbrlz(unsigned long w) 12cris_swapnwbrlz(unsigned long w)
13{ 13{
14 unsigned long res; 14 unsigned long res;
@@ -20,7 +20,7 @@ cris_swapnwbrlz(unsigned long w)
20 return res; 20 return res;
21} 21}
22 22
23extern inline unsigned long 23static inline unsigned long
24cris_swapwbrlz(unsigned long w) 24cris_swapwbrlz(unsigned long w)
25{ 25{
26 unsigned long res; 26 unsigned long res;
@@ -36,7 +36,7 @@ cris_swapwbrlz(unsigned long w)
36 * Find First Zero in word. Undefined if no zero exist, so the caller should 36 * Find First Zero in word. Undefined if no zero exist, so the caller should
37 * check against ~0 first. 37 * check against ~0 first.
38 */ 38 */
39extern inline unsigned long 39static inline unsigned long
40ffz(unsigned long w) 40ffz(unsigned long w)
41{ 41{
42 return cris_swapnwbrlz(w); 42 return cris_swapnwbrlz(w);
@@ -46,7 +46,7 @@ ffz(unsigned long w)
46 * Find First Set bit in word. Undefined if no 1 exist, so the caller 46 * Find First Set bit in word. Undefined if no 1 exist, so the caller
47 * should check against 0 first. 47 * should check against 0 first.
48 */ 48 */
49extern inline unsigned long 49static inline unsigned long
50__ffs(unsigned long w) 50__ffs(unsigned long w)
51{ 51{
52 return cris_swapnwbrlz(~w); 52 return cris_swapnwbrlz(~w);
@@ -55,7 +55,7 @@ __ffs(unsigned long w)
55/* 55/*
56 * Find First Bit that is set. 56 * Find First Bit that is set.
57 */ 57 */
58extern inline unsigned long 58static inline unsigned long
59kernel_ffs(unsigned long w) 59kernel_ffs(unsigned long w)
60{ 60{
61 return w ? cris_swapwbrlz (w) + 1 : 0; 61 return w ? cris_swapwbrlz (w) + 1 : 0;
diff --git a/include/asm-cris/arch-v32/byteorder.h b/include/asm-cris/arch-v32/byteorder.h
index 74846ee6cf99..6ef8fb4a35f2 100644
--- a/include/asm-cris/arch-v32/byteorder.h
+++ b/include/asm-cris/arch-v32/byteorder.h
@@ -3,14 +3,14 @@
3 3
4#include <asm/types.h> 4#include <asm/types.h>
5 5
6extern __inline__ __const__ __u32 6static inline __const__ __u32
7___arch__swab32(__u32 x) 7___arch__swab32(__u32 x)
8{ 8{
9 __asm__ __volatile__ ("swapwb %0" : "=r" (x) : "0" (x)); 9 __asm__ __volatile__ ("swapwb %0" : "=r" (x) : "0" (x));
10 return (x); 10 return (x);
11} 11}
12 12
13extern __inline__ __const__ __u16 13static inline __const__ __u16
14___arch__swab16(__u16 x) 14___arch__swab16(__u16 x)
15{ 15{
16 __asm__ __volatile__ ("swapb %0" : "=r" (x) : "0" (x)); 16 __asm__ __volatile__ ("swapb %0" : "=r" (x) : "0" (x));
diff --git a/include/asm-cris/arch-v32/checksum.h b/include/asm-cris/arch-v32/checksum.h
index a1d6b2a6cc44..97ef89efea62 100644
--- a/include/asm-cris/arch-v32/checksum.h
+++ b/include/asm-cris/arch-v32/checksum.h
@@ -9,7 +9,7 @@
9 * checksum. Which means it would be necessary to split all those into 9 * checksum. Which means it would be necessary to split all those into
10 * 16-bit components and then add. 10 * 16-bit components and then add.
11 */ 11 */
12extern inline unsigned int 12static inline unsigned int
13csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr, 13csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr,
14 unsigned short len, unsigned short proto, unsigned int sum) 14 unsigned short len, unsigned short proto, unsigned int sum)
15{ 15{
diff --git a/include/asm-cris/arch-v32/delay.h b/include/asm-cris/arch-v32/delay.h
index f36f7f760e89..b6e941e637de 100644
--- a/include/asm-cris/arch-v32/delay.h
+++ b/include/asm-cris/arch-v32/delay.h
@@ -1,7 +1,7 @@
1#ifndef _ASM_CRIS_ARCH_DELAY_H 1#ifndef _ASM_CRIS_ARCH_DELAY_H
2#define _ASM_CRIS_ARCH_DELAY_H 2#define _ASM_CRIS_ARCH_DELAY_H
3 3
4extern __inline__ void 4static inline void
5__delay(int loops) 5__delay(int loops)
6{ 6{
7 __asm__ __volatile__ ( 7 __asm__ __volatile__ (
diff --git a/include/asm-cris/arch-v32/ide.h b/include/asm-cris/arch-v32/ide.h
index 24f5604f566a..6590f657500d 100644
--- a/include/asm-cris/arch-v32/ide.h
+++ b/include/asm-cris/arch-v32/ide.h
@@ -26,7 +26,7 @@
26 26
27#define MAX_HWIFS 4 27#define MAX_HWIFS 4
28 28
29extern __inline__ int ide_default_irq(unsigned long base) 29static inline int ide_default_irq(unsigned long base)
30{ 30{
31 /* all IDE busses share the same IRQ, 31 /* all IDE busses share the same IRQ,
32 * this has the side-effect that ide-probe.c will cluster our 4 interfaces 32 * this has the side-effect that ide-probe.c will cluster our 4 interfaces
@@ -36,7 +36,7 @@ extern __inline__ int ide_default_irq(unsigned long base)
36 return ATA_INTR_VECT; 36 return ATA_INTR_VECT;
37} 37}
38 38
39extern __inline__ unsigned long ide_default_io_base(int index) 39static inline unsigned long ide_default_io_base(int index)
40{ 40{
41 reg_ata_rw_ctrl2 ctrl2 = {.sel = index}; 41 reg_ata_rw_ctrl2 ctrl2 = {.sel = index};
42 /* we have no real I/O base address per interface, since all go through the 42 /* we have no real I/O base address per interface, since all go through the
diff --git a/include/asm-cris/arch-v32/io.h b/include/asm-cris/arch-v32/io.h
index 4c80263ec634..043c9ce5294e 100644
--- a/include/asm-cris/arch-v32/io.h
+++ b/include/asm-cris/arch-v32/io.h
@@ -35,7 +35,7 @@ extern struct crisv32_iopin crisv32_led2_red;
35extern struct crisv32_iopin crisv32_led3_green; 35extern struct crisv32_iopin crisv32_led3_green;
36extern struct crisv32_iopin crisv32_led3_red; 36extern struct crisv32_iopin crisv32_led3_red;
37 37
38extern inline void crisv32_io_set(struct crisv32_iopin* iopin, 38static inline void crisv32_io_set(struct crisv32_iopin* iopin,
39 int val) 39 int val)
40{ 40{
41 if (val) 41 if (val)
@@ -44,7 +44,7 @@ extern inline void crisv32_io_set(struct crisv32_iopin* iopin,
44 *iopin->port->data &= ~iopin->bit; 44 *iopin->port->data &= ~iopin->bit;
45} 45}
46 46
47extern inline void crisv32_io_set_dir(struct crisv32_iopin* iopin, 47static inline void crisv32_io_set_dir(struct crisv32_iopin* iopin,
48 enum crisv32_io_dir dir) 48 enum crisv32_io_dir dir)
49{ 49{
50 if (dir == crisv32_io_dir_in) 50 if (dir == crisv32_io_dir_in)
@@ -53,7 +53,7 @@ extern inline void crisv32_io_set_dir(struct crisv32_iopin* iopin,
53 *iopin->port->oe |= iopin->bit; 53 *iopin->port->oe |= iopin->bit;
54} 54}
55 55
56extern inline int crisv32_io_rd(struct crisv32_iopin* iopin) 56static inline int crisv32_io_rd(struct crisv32_iopin* iopin)
57{ 57{
58 return ((*iopin->port->data_in & iopin->bit) ? 1 : 0); 58 return ((*iopin->port->data_in & iopin->bit) ? 1 : 0);
59} 59}
diff --git a/include/asm-cris/arch-v32/system.h b/include/asm-cris/arch-v32/system.h
index b9afbb95e0bb..a3d75d581e2f 100644
--- a/include/asm-cris/arch-v32/system.h
+++ b/include/asm-cris/arch-v32/system.h
@@ -4,7 +4,7 @@
4#include <linux/config.h> 4#include <linux/config.h>
5 5
6/* Read the CPU version register. */ 6/* Read the CPU version register. */
7extern inline unsigned long rdvr(void) 7static inline unsigned long rdvr(void)
8{ 8{
9 unsigned char vr; 9 unsigned char vr;
10 10
@@ -15,7 +15,7 @@ extern inline unsigned long rdvr(void)
15#define cris_machine_name "crisv32" 15#define cris_machine_name "crisv32"
16 16
17/* Read the user-mode stack pointer. */ 17/* Read the user-mode stack pointer. */
18extern inline unsigned long rdusp(void) 18static inline unsigned long rdusp(void)
19{ 19{
20 unsigned long usp; 20 unsigned long usp;
21 21
@@ -24,7 +24,7 @@ extern inline unsigned long rdusp(void)
24} 24}
25 25
26/* Read the current stack pointer. */ 26/* Read the current stack pointer. */
27extern inline unsigned long rdsp(void) 27static inline unsigned long rdsp(void)
28{ 28{
29 unsigned long sp; 29 unsigned long sp;
30 30
diff --git a/include/asm-cris/arch-v32/thread_info.h b/include/asm-cris/arch-v32/thread_info.h
index a7a182307da0..d6936956a3c6 100644
--- a/include/asm-cris/arch-v32/thread_info.h
+++ b/include/asm-cris/arch-v32/thread_info.h
@@ -2,7 +2,7 @@
2#define _ASM_CRIS_ARCH_THREAD_INFO_H 2#define _ASM_CRIS_ARCH_THREAD_INFO_H
3 3
4/* Return a thread_info struct. */ 4/* Return a thread_info struct. */
5extern inline struct thread_info *current_thread_info(void) 5static inline struct thread_info *current_thread_info(void)
6{ 6{
7 struct thread_info *ti; 7 struct thread_info *ti;
8 8
diff --git a/include/asm-cris/arch-v32/timex.h b/include/asm-cris/arch-v32/timex.h
index 4d0fd23b21e9..5a4aa285d5fd 100644
--- a/include/asm-cris/arch-v32/timex.h
+++ b/include/asm-cris/arch-v32/timex.h
@@ -22,7 +22,7 @@
22 22
23extern unsigned long get_ns_in_jiffie(void); 23extern unsigned long get_ns_in_jiffie(void);
24 24
25extern inline unsigned long get_us_in_jiffie_highres(void) 25static inline unsigned long get_us_in_jiffie_highres(void)
26{ 26{
27 return get_ns_in_jiffie() / 1000; 27 return get_ns_in_jiffie() / 1000;
28} 28}
diff --git a/include/asm-cris/arch-v32/uaccess.h b/include/asm-cris/arch-v32/uaccess.h
index 055a0bdbe835..6b207f1b6622 100644
--- a/include/asm-cris/arch-v32/uaccess.h
+++ b/include/asm-cris/arch-v32/uaccess.h
@@ -93,7 +93,7 @@
93 * bytes copied if we hit a null byte 93 * bytes copied if we hit a null byte
94 * (without the null byte) 94 * (without the null byte)
95 */ 95 */
96extern inline long 96static inline long
97__do_strncpy_from_user(char *dst, const char *src, long count) 97__do_strncpy_from_user(char *dst, const char *src, long count)
98{ 98{
99 long res; 99 long res;
@@ -695,7 +695,7 @@ __do_strncpy_from_user(char *dst, const char *src, long count)
695 * or 0 for error. Return a value greater than N if too long. 695 * or 0 for error. Return a value greater than N if too long.
696 */ 696 */
697 697
698extern inline long 698static inline long
699strnlen_user(const char *s, long n) 699strnlen_user(const char *s, long n)
700{ 700{
701 long res, tmp1; 701 long res, tmp1;
diff --git a/include/asm-cris/atomic.h b/include/asm-cris/atomic.h
index 70605b09e8b7..8c2e78304523 100644
--- a/include/asm-cris/atomic.h
+++ b/include/asm-cris/atomic.h
@@ -20,7 +20,7 @@ typedef struct { volatile int counter; } atomic_t;
20 20
21/* These should be written in asm but we do it in C for now. */ 21/* These should be written in asm but we do it in C for now. */
22 22
23extern __inline__ void atomic_add(int i, volatile atomic_t *v) 23static inline void atomic_add(int i, volatile atomic_t *v)
24{ 24{
25 unsigned long flags; 25 unsigned long flags;
26 cris_atomic_save(v, flags); 26 cris_atomic_save(v, flags);
@@ -28,7 +28,7 @@ extern __inline__ void atomic_add(int i, volatile atomic_t *v)
28 cris_atomic_restore(v, flags); 28 cris_atomic_restore(v, flags);
29} 29}
30 30
31extern __inline__ void atomic_sub(int i, volatile atomic_t *v) 31static inline void atomic_sub(int i, volatile atomic_t *v)
32{ 32{
33 unsigned long flags; 33 unsigned long flags;
34 cris_atomic_save(v, flags); 34 cris_atomic_save(v, flags);
@@ -36,7 +36,7 @@ extern __inline__ void atomic_sub(int i, volatile atomic_t *v)
36 cris_atomic_restore(v, flags); 36 cris_atomic_restore(v, flags);
37} 37}
38 38
39extern __inline__ int atomic_add_return(int i, volatile atomic_t *v) 39static inline int atomic_add_return(int i, volatile atomic_t *v)
40{ 40{
41 unsigned long flags; 41 unsigned long flags;
42 int retval; 42 int retval;
@@ -48,7 +48,7 @@ extern __inline__ int atomic_add_return(int i, volatile atomic_t *v)
48 48
49#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0) 49#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
50 50
51extern __inline__ int atomic_sub_return(int i, volatile atomic_t *v) 51static inline int atomic_sub_return(int i, volatile atomic_t *v)
52{ 52{
53 unsigned long flags; 53 unsigned long flags;
54 int retval; 54 int retval;
@@ -58,7 +58,7 @@ extern __inline__ int atomic_sub_return(int i, volatile atomic_t *v)
58 return retval; 58 return retval;
59} 59}
60 60
61extern __inline__ int atomic_sub_and_test(int i, volatile atomic_t *v) 61static inline int atomic_sub_and_test(int i, volatile atomic_t *v)
62{ 62{
63 int retval; 63 int retval;
64 unsigned long flags; 64 unsigned long flags;
@@ -68,7 +68,7 @@ extern __inline__ int atomic_sub_and_test(int i, volatile atomic_t *v)
68 return retval; 68 return retval;
69} 69}
70 70
71extern __inline__ void atomic_inc(volatile atomic_t *v) 71static inline void atomic_inc(volatile atomic_t *v)
72{ 72{
73 unsigned long flags; 73 unsigned long flags;
74 cris_atomic_save(v, flags); 74 cris_atomic_save(v, flags);
@@ -76,7 +76,7 @@ extern __inline__ void atomic_inc(volatile atomic_t *v)
76 cris_atomic_restore(v, flags); 76 cris_atomic_restore(v, flags);
77} 77}
78 78
79extern __inline__ void atomic_dec(volatile atomic_t *v) 79static inline void atomic_dec(volatile atomic_t *v)
80{ 80{
81 unsigned long flags; 81 unsigned long flags;
82 cris_atomic_save(v, flags); 82 cris_atomic_save(v, flags);
@@ -84,7 +84,7 @@ extern __inline__ void atomic_dec(volatile atomic_t *v)
84 cris_atomic_restore(v, flags); 84 cris_atomic_restore(v, flags);
85} 85}
86 86
87extern __inline__ int atomic_inc_return(volatile atomic_t *v) 87static inline int atomic_inc_return(volatile atomic_t *v)
88{ 88{
89 unsigned long flags; 89 unsigned long flags;
90 int retval; 90 int retval;
@@ -94,7 +94,7 @@ extern __inline__ int atomic_inc_return(volatile atomic_t *v)
94 return retval; 94 return retval;
95} 95}
96 96
97extern __inline__ int atomic_dec_return(volatile atomic_t *v) 97static inline int atomic_dec_return(volatile atomic_t *v)
98{ 98{
99 unsigned long flags; 99 unsigned long flags;
100 int retval; 100 int retval;
@@ -103,7 +103,7 @@ extern __inline__ int atomic_dec_return(volatile atomic_t *v)
103 cris_atomic_restore(v, flags); 103 cris_atomic_restore(v, flags);
104 return retval; 104 return retval;
105} 105}
106extern __inline__ int atomic_dec_and_test(volatile atomic_t *v) 106static inline int atomic_dec_and_test(volatile atomic_t *v)
107{ 107{
108 int retval; 108 int retval;
109 unsigned long flags; 109 unsigned long flags;
@@ -113,7 +113,7 @@ extern __inline__ int atomic_dec_and_test(volatile atomic_t *v)
113 return retval; 113 return retval;
114} 114}
115 115
116extern __inline__ int atomic_inc_and_test(volatile atomic_t *v) 116static inline int atomic_inc_and_test(volatile atomic_t *v)
117{ 117{
118 int retval; 118 int retval;
119 unsigned long flags; 119 unsigned long flags;
diff --git a/include/asm-cris/bitops.h b/include/asm-cris/bitops.h
index e3da57f97964..1bddb3f3a289 100644
--- a/include/asm-cris/bitops.h
+++ b/include/asm-cris/bitops.h
@@ -89,7 +89,7 @@ struct __dummy { unsigned long a[100]; };
89 * It also implies a memory barrier. 89 * It also implies a memory barrier.
90 */ 90 */
91 91
92extern inline int test_and_set_bit(int nr, volatile unsigned long *addr) 92static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
93{ 93{
94 unsigned int mask, retval; 94 unsigned int mask, retval;
95 unsigned long flags; 95 unsigned long flags;
@@ -105,7 +105,7 @@ extern inline int test_and_set_bit(int nr, volatile unsigned long *addr)
105 return retval; 105 return retval;
106} 106}
107 107
108extern inline int __test_and_set_bit(int nr, volatile unsigned long *addr) 108static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
109{ 109{
110 unsigned int mask, retval; 110 unsigned int mask, retval;
111 unsigned int *adr = (unsigned int *)addr; 111 unsigned int *adr = (unsigned int *)addr;
@@ -132,7 +132,7 @@ extern inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
132 * It also implies a memory barrier. 132 * It also implies a memory barrier.
133 */ 133 */
134 134
135extern inline int test_and_clear_bit(int nr, volatile unsigned long *addr) 135static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
136{ 136{
137 unsigned int mask, retval; 137 unsigned int mask, retval;
138 unsigned long flags; 138 unsigned long flags;
@@ -157,7 +157,7 @@ extern inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
157 * but actually fail. You must protect multiple accesses with a lock. 157 * but actually fail. You must protect multiple accesses with a lock.
158 */ 158 */
159 159
160extern inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) 160static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
161{ 161{
162 unsigned int mask, retval; 162 unsigned int mask, retval;
163 unsigned int *adr = (unsigned int *)addr; 163 unsigned int *adr = (unsigned int *)addr;
@@ -177,7 +177,7 @@ extern inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
177 * It also implies a memory barrier. 177 * It also implies a memory barrier.
178 */ 178 */
179 179
180extern inline int test_and_change_bit(int nr, volatile unsigned long *addr) 180static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
181{ 181{
182 unsigned int mask, retval; 182 unsigned int mask, retval;
183 unsigned long flags; 183 unsigned long flags;
@@ -193,7 +193,7 @@ extern inline int test_and_change_bit(int nr, volatile unsigned long *addr)
193 193
194/* WARNING: non atomic and it can be reordered! */ 194/* WARNING: non atomic and it can be reordered! */
195 195
196extern inline int __test_and_change_bit(int nr, volatile unsigned long *addr) 196static inline int __test_and_change_bit(int nr, volatile unsigned long *addr)
197{ 197{
198 unsigned int mask, retval; 198 unsigned int mask, retval;
199 unsigned int *adr = (unsigned int *)addr; 199 unsigned int *adr = (unsigned int *)addr;
@@ -214,7 +214,7 @@ extern inline int __test_and_change_bit(int nr, volatile unsigned long *addr)
214 * This routine doesn't need to be atomic. 214 * This routine doesn't need to be atomic.
215 */ 215 */
216 216
217extern inline int test_bit(int nr, const volatile unsigned long *addr) 217static inline int test_bit(int nr, const volatile unsigned long *addr)
218{ 218{
219 unsigned int mask; 219 unsigned int mask;
220 unsigned int *adr = (unsigned int *)addr; 220 unsigned int *adr = (unsigned int *)addr;
@@ -258,7 +258,7 @@ extern inline int test_bit(int nr, const volatile unsigned long *addr)
258 * @offset: The bitnumber to start searching at 258 * @offset: The bitnumber to start searching at
259 * @size: The maximum size to search 259 * @size: The maximum size to search
260 */ 260 */
261extern inline int find_next_zero_bit (const unsigned long * addr, int size, int offset) 261static inline int find_next_zero_bit (const unsigned long * addr, int size, int offset)
262{ 262{
263 unsigned long *p = ((unsigned long *) addr) + (offset >> 5); 263 unsigned long *p = ((unsigned long *) addr) + (offset >> 5);
264 unsigned long result = offset & ~31UL; 264 unsigned long result = offset & ~31UL;
@@ -366,7 +366,7 @@ found_middle:
366#define minix_test_bit(nr,addr) test_bit(nr,addr) 366#define minix_test_bit(nr,addr) test_bit(nr,addr)
367#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size) 367#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
368 368
369extern inline int sched_find_first_bit(const unsigned long *b) 369static inline int sched_find_first_bit(const unsigned long *b)
370{ 370{
371 if (unlikely(b[0])) 371 if (unlikely(b[0]))
372 return __ffs(b[0]); 372 return __ffs(b[0]);
diff --git a/include/asm-cris/checksum.h b/include/asm-cris/checksum.h
index 15ca8aec5c63..26a7719bbb84 100644
--- a/include/asm-cris/checksum.h
+++ b/include/asm-cris/checksum.h
@@ -34,7 +34,7 @@ unsigned int csum_partial_copy_nocheck(const char *src, char *dst,
34 * Fold a partial checksum into a word 34 * Fold a partial checksum into a word
35 */ 35 */
36 36
37extern inline unsigned int csum_fold(unsigned int sum) 37static inline unsigned int csum_fold(unsigned int sum)
38{ 38{
39 /* the while loop is unnecessary really, it's always enough with two 39 /* the while loop is unnecessary really, it's always enough with two
40 iterations */ 40 iterations */
@@ -55,7 +55,7 @@ extern unsigned int csum_partial_copy_from_user(const char *src, char *dst,
55 * 55 *
56 */ 56 */
57 57
58extern inline unsigned short ip_fast_csum(unsigned char * iph, 58static inline unsigned short ip_fast_csum(unsigned char * iph,
59 unsigned int ihl) 59 unsigned int ihl)
60{ 60{
61 return csum_fold(csum_partial(iph, ihl * 4, 0)); 61 return csum_fold(csum_partial(iph, ihl * 4, 0));
@@ -66,7 +66,7 @@ extern inline unsigned short ip_fast_csum(unsigned char * iph,
66 * returns a 16-bit checksum, already complemented 66 * returns a 16-bit checksum, already complemented
67 */ 67 */
68 68
69extern inline unsigned short int csum_tcpudp_magic(unsigned long saddr, 69static inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
70 unsigned long daddr, 70 unsigned long daddr,
71 unsigned short len, 71 unsigned short len,
72 unsigned short proto, 72 unsigned short proto,
@@ -80,7 +80,7 @@ extern inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
80 * in icmp.c 80 * in icmp.c
81 */ 81 */
82 82
83extern inline unsigned short ip_compute_csum(unsigned char * buff, int len) { 83static inline unsigned short ip_compute_csum(unsigned char * buff, int len) {
84 return csum_fold (csum_partial(buff, len, 0)); 84 return csum_fold (csum_partial(buff, len, 0));
85} 85}
86 86
diff --git a/include/asm-cris/current.h b/include/asm-cris/current.h
index dce69c99da39..5f5c0efd00be 100644
--- a/include/asm-cris/current.h
+++ b/include/asm-cris/current.h
@@ -5,7 +5,7 @@
5 5
6struct task_struct; 6struct task_struct;
7 7
8extern inline struct task_struct * get_current(void) 8static inline struct task_struct * get_current(void)
9{ 9{
10 return current_thread_info()->task; 10 return current_thread_info()->task;
11} 11}
diff --git a/include/asm-cris/delay.h b/include/asm-cris/delay.h
index efc41aad4845..d3a397803719 100644
--- a/include/asm-cris/delay.h
+++ b/include/asm-cris/delay.h
@@ -13,7 +13,7 @@
13 13
14extern unsigned long loops_per_usec; /* arch/cris/mm/init.c */ 14extern unsigned long loops_per_usec; /* arch/cris/mm/init.c */
15 15
16extern __inline__ void udelay(unsigned long usecs) 16static inline void udelay(unsigned long usecs)
17{ 17{
18 __delay(usecs * loops_per_usec); 18 __delay(usecs * loops_per_usec);
19} 19}
diff --git a/include/asm-cris/io.h b/include/asm-cris/io.h
index 16e791b3c721..716c69bc58f8 100644
--- a/include/asm-cris/io.h
+++ b/include/asm-cris/io.h
@@ -23,12 +23,12 @@ extern struct cris_io_operations *cris_iops;
23 * Change virtual addresses to physical addresses and vv. 23 * Change virtual addresses to physical addresses and vv.
24 */ 24 */
25 25
26extern inline unsigned long virt_to_phys(volatile void * address) 26static inline unsigned long virt_to_phys(volatile void * address)
27{ 27{
28 return __pa(address); 28 return __pa(address);
29} 29}
30 30
31extern inline void * phys_to_virt(unsigned long address) 31static inline void * phys_to_virt(unsigned long address)
32{ 32{
33 return __va(address); 33 return __va(address);
34} 34}
@@ -36,7 +36,7 @@ extern inline void * phys_to_virt(unsigned long address)
36extern void __iomem * __ioremap(unsigned long offset, unsigned long size, unsigned long flags); 36extern void __iomem * __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
37extern void __iomem * __ioremap_prot(unsigned long phys_addr, unsigned long size, pgprot_t prot); 37extern void __iomem * __ioremap_prot(unsigned long phys_addr, unsigned long size, pgprot_t prot);
38 38
39extern inline void __iomem * ioremap (unsigned long offset, unsigned long size) 39static inline void __iomem * ioremap (unsigned long offset, unsigned long size)
40{ 40{
41 return __ioremap(offset, size, 0); 41 return __ioremap(offset, size, 0);
42} 42}
diff --git a/include/asm-cris/irq.h b/include/asm-cris/irq.h
index 4fab5c3b2e15..4b338792218b 100644
--- a/include/asm-cris/irq.h
+++ b/include/asm-cris/irq.h
@@ -8,7 +8,7 @@
8 8
9#include <asm/arch/irq.h> 9#include <asm/arch/irq.h>
10 10
11extern __inline__ int irq_canonicalize(int irq) 11static inline int irq_canonicalize(int irq)
12{ 12{
13 return irq; 13 return irq;
14} 14}
diff --git a/include/asm-cris/pgalloc.h b/include/asm-cris/pgalloc.h
index a131776edf41..deaddfe79bbc 100644
--- a/include/asm-cris/pgalloc.h
+++ b/include/asm-cris/pgalloc.h
@@ -11,35 +11,35 @@
11 * Allocate and free page tables. 11 * Allocate and free page tables.
12 */ 12 */
13 13
14extern inline pgd_t *pgd_alloc (struct mm_struct *mm) 14static inline pgd_t *pgd_alloc (struct mm_struct *mm)
15{ 15{
16 return (pgd_t *)get_zeroed_page(GFP_KERNEL); 16 return (pgd_t *)get_zeroed_page(GFP_KERNEL);
17} 17}
18 18
19extern inline void pgd_free (pgd_t *pgd) 19static inline void pgd_free (pgd_t *pgd)
20{ 20{
21 free_page((unsigned long)pgd); 21 free_page((unsigned long)pgd);
22} 22}
23 23
24extern inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address) 24static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
25{ 25{
26 pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO); 26 pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
27 return pte; 27 return pte;
28} 28}
29 29
30extern inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address) 30static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
31{ 31{
32 struct page *pte; 32 struct page *pte;
33 pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0); 33 pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
34 return pte; 34 return pte;
35} 35}
36 36
37extern inline void pte_free_kernel(pte_t *pte) 37static inline void pte_free_kernel(pte_t *pte)
38{ 38{
39 free_page((unsigned long)pte); 39 free_page((unsigned long)pte);
40} 40}
41 41
42extern inline void pte_free(struct page *pte) 42static inline void pte_free(struct page *pte)
43{ 43{
44 __free_page(pte); 44 __free_page(pte);
45} 45}
diff --git a/include/asm-cris/pgtable.h b/include/asm-cris/pgtable.h
index a9143bed99db..70a832514f62 100644
--- a/include/asm-cris/pgtable.h
+++ b/include/asm-cris/pgtable.h
@@ -112,44 +112,44 @@ extern unsigned long empty_zero_page;
112 * Undefined behaviour if not.. 112 * Undefined behaviour if not..
113 */ 113 */
114 114
115extern inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_READ; } 115static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_READ; }
116extern inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; } 116static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; }
117extern inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_READ; } 117static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_READ; }
118extern inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_MODIFIED; } 118static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_MODIFIED; }
119extern inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; } 119static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
120extern inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; } 120static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
121 121
122extern inline pte_t pte_wrprotect(pte_t pte) 122static inline pte_t pte_wrprotect(pte_t pte)
123{ 123{
124 pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE); 124 pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
125 return pte; 125 return pte;
126} 126}
127 127
128extern inline pte_t pte_rdprotect(pte_t pte) 128static inline pte_t pte_rdprotect(pte_t pte)
129{ 129{
130 pte_val(pte) &= ~(_PAGE_READ | _PAGE_SILENT_READ); 130 pte_val(pte) &= ~(_PAGE_READ | _PAGE_SILENT_READ);
131 return pte; 131 return pte;
132} 132}
133 133
134extern inline pte_t pte_exprotect(pte_t pte) 134static inline pte_t pte_exprotect(pte_t pte)
135{ 135{
136 pte_val(pte) &= ~(_PAGE_READ | _PAGE_SILENT_READ); 136 pte_val(pte) &= ~(_PAGE_READ | _PAGE_SILENT_READ);
137 return pte; 137 return pte;
138} 138}
139 139
140extern inline pte_t pte_mkclean(pte_t pte) 140static inline pte_t pte_mkclean(pte_t pte)
141{ 141{
142 pte_val(pte) &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE); 142 pte_val(pte) &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE);
143 return pte; 143 return pte;
144} 144}
145 145
146extern inline pte_t pte_mkold(pte_t pte) 146static inline pte_t pte_mkold(pte_t pte)
147{ 147{
148 pte_val(pte) &= ~(_PAGE_ACCESSED | _PAGE_SILENT_READ); 148 pte_val(pte) &= ~(_PAGE_ACCESSED | _PAGE_SILENT_READ);
149 return pte; 149 return pte;
150} 150}
151 151
152extern inline pte_t pte_mkwrite(pte_t pte) 152static inline pte_t pte_mkwrite(pte_t pte)
153{ 153{
154 pte_val(pte) |= _PAGE_WRITE; 154 pte_val(pte) |= _PAGE_WRITE;
155 if (pte_val(pte) & _PAGE_MODIFIED) 155 if (pte_val(pte) & _PAGE_MODIFIED)
@@ -157,7 +157,7 @@ extern inline pte_t pte_mkwrite(pte_t pte)
157 return pte; 157 return pte;
158} 158}
159 159
160extern inline pte_t pte_mkread(pte_t pte) 160static inline pte_t pte_mkread(pte_t pte)
161{ 161{
162 pte_val(pte) |= _PAGE_READ; 162 pte_val(pte) |= _PAGE_READ;
163 if (pte_val(pte) & _PAGE_ACCESSED) 163 if (pte_val(pte) & _PAGE_ACCESSED)
@@ -165,7 +165,7 @@ extern inline pte_t pte_mkread(pte_t pte)
165 return pte; 165 return pte;
166} 166}
167 167
168extern inline pte_t pte_mkexec(pte_t pte) 168static inline pte_t pte_mkexec(pte_t pte)
169{ 169{
170 pte_val(pte) |= _PAGE_READ; 170 pte_val(pte) |= _PAGE_READ;
171 if (pte_val(pte) & _PAGE_ACCESSED) 171 if (pte_val(pte) & _PAGE_ACCESSED)
@@ -173,7 +173,7 @@ extern inline pte_t pte_mkexec(pte_t pte)
173 return pte; 173 return pte;
174} 174}
175 175
176extern inline pte_t pte_mkdirty(pte_t pte) 176static inline pte_t pte_mkdirty(pte_t pte)
177{ 177{
178 pte_val(pte) |= _PAGE_MODIFIED; 178 pte_val(pte) |= _PAGE_MODIFIED;
179 if (pte_val(pte) & _PAGE_WRITE) 179 if (pte_val(pte) & _PAGE_WRITE)
@@ -181,7 +181,7 @@ extern inline pte_t pte_mkdirty(pte_t pte)
181 return pte; 181 return pte;
182} 182}
183 183
184extern inline pte_t pte_mkyoung(pte_t pte) 184static inline pte_t pte_mkyoung(pte_t pte)
185{ 185{
186 pte_val(pte) |= _PAGE_ACCESSED; 186 pte_val(pte) |= _PAGE_ACCESSED;
187 if (pte_val(pte) & _PAGE_READ) 187 if (pte_val(pte) & _PAGE_READ)
@@ -205,7 +205,7 @@ extern inline pte_t pte_mkyoung(pte_t pte)
205 * addresses (the 0xc0xxxxxx's) goes as void *'s. 205 * addresses (the 0xc0xxxxxx's) goes as void *'s.
206 */ 206 */
207 207
208extern inline pte_t __mk_pte(void * page, pgprot_t pgprot) 208static inline pte_t __mk_pte(void * page, pgprot_t pgprot)
209{ 209{
210 pte_t pte; 210 pte_t pte;
211 /* the PTE needs a physical address */ 211 /* the PTE needs a physical address */
@@ -223,7 +223,7 @@ extern inline pte_t __mk_pte(void * page, pgprot_t pgprot)
223 __pte; \ 223 __pte; \
224}) 224})
225 225
226extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot) 226static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
227{ pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; } 227{ pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
228 228
229 229
@@ -232,7 +232,7 @@ extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
232 * pte_pagenr refers to the page-number counted starting from the virtual DRAM start 232 * pte_pagenr refers to the page-number counted starting from the virtual DRAM start
233 */ 233 */
234 234
235extern inline unsigned long __pte_page(pte_t pte) 235static inline unsigned long __pte_page(pte_t pte)
236{ 236{
237 /* the PTE contains a physical address */ 237 /* the PTE contains a physical address */
238 return (unsigned long)__va(pte_val(pte) & PAGE_MASK); 238 return (unsigned long)__va(pte_val(pte) & PAGE_MASK);
@@ -250,7 +250,7 @@ extern inline unsigned long __pte_page(pte_t pte)
250 * don't need the __pa and __va transformations. 250 * don't need the __pa and __va transformations.
251 */ 251 */
252 252
253extern inline void pmd_set(pmd_t * pmdp, pte_t * ptep) 253static inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
254{ pmd_val(*pmdp) = _PAGE_TABLE | (unsigned long) ptep; } 254{ pmd_val(*pmdp) = _PAGE_TABLE | (unsigned long) ptep; }
255 255
256#define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT)) 256#define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
@@ -260,7 +260,7 @@ extern inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
260#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1)) 260#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
261 261
262/* to find an entry in a page-table-directory */ 262/* to find an entry in a page-table-directory */
263extern inline pgd_t * pgd_offset(struct mm_struct * mm, unsigned long address) 263static inline pgd_t * pgd_offset(struct mm_struct * mm, unsigned long address)
264{ 264{
265 return mm->pgd + pgd_index(address); 265 return mm->pgd + pgd_index(address);
266} 266}
@@ -296,7 +296,7 @@ extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; /* defined in head.S */
296 * 296 *
297 * Actually I am not sure on what this could be used for. 297 * Actually I am not sure on what this could be used for.
298 */ 298 */
299extern inline void update_mmu_cache(struct vm_area_struct * vma, 299static inline void update_mmu_cache(struct vm_area_struct * vma,
300 unsigned long address, pte_t pte) 300 unsigned long address, pte_t pte)
301{ 301{
302} 302}
diff --git a/include/asm-cris/processor.h b/include/asm-cris/processor.h
index 0dc218117bd8..dce41009eeb0 100644
--- a/include/asm-cris/processor.h
+++ b/include/asm-cris/processor.h
@@ -16,6 +16,8 @@
16#include <asm/ptrace.h> 16#include <asm/ptrace.h>
17#include <asm/arch/processor.h> 17#include <asm/arch/processor.h>
18 18
19struct task_struct;
20
19/* This decides where the kernel will search for a free chunk of vm 21/* This decides where the kernel will search for a free chunk of vm
20 * space during mmap's. 22 * space during mmap's.
21 */ 23 */
@@ -45,7 +47,7 @@
45 47
46#define current_regs() user_regs(current->thread_info) 48#define current_regs() user_regs(current->thread_info)
47 49
48extern inline void prepare_to_copy(struct task_struct *tsk) 50static inline void prepare_to_copy(struct task_struct *tsk)
49{ 51{
50} 52}
51 53
@@ -58,7 +60,7 @@ unsigned long get_wchan(struct task_struct *p);
58extern unsigned long thread_saved_pc(struct task_struct *tsk); 60extern unsigned long thread_saved_pc(struct task_struct *tsk);
59 61
60/* Free all resources held by a thread. */ 62/* Free all resources held by a thread. */
61extern inline void release_thread(struct task_struct *dead_task) 63static inline void release_thread(struct task_struct *dead_task)
62{ 64{
63 /* Nothing needs to be done. */ 65 /* Nothing needs to be done. */
64} 66}
diff --git a/include/asm-cris/semaphore.h b/include/asm-cris/semaphore.h
index 39faf69bcf76..53f548b791c1 100644
--- a/include/asm-cris/semaphore.h
+++ b/include/asm-cris/semaphore.h
@@ -18,8 +18,6 @@
18 * CRIS semaphores, implemented in C-only so far. 18 * CRIS semaphores, implemented in C-only so far.
19 */ 19 */
20 20
21int printk(const char *fmt, ...);
22
23struct semaphore { 21struct semaphore {
24 atomic_t count; 22 atomic_t count;
25 atomic_t waking; 23 atomic_t waking;
@@ -39,17 +37,17 @@ struct semaphore {
39#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1) 37#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
40#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0) 38#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
41 39
42extern inline void sema_init(struct semaphore *sem, int val) 40static inline void sema_init(struct semaphore *sem, int val)
43{ 41{
44 *sem = (struct semaphore)__SEMAPHORE_INITIALIZER((*sem),val); 42 *sem = (struct semaphore)__SEMAPHORE_INITIALIZER((*sem),val);
45} 43}
46 44
47extern inline void init_MUTEX (struct semaphore *sem) 45static inline void init_MUTEX (struct semaphore *sem)
48{ 46{
49 sema_init(sem, 1); 47 sema_init(sem, 1);
50} 48}
51 49
52extern inline void init_MUTEX_LOCKED (struct semaphore *sem) 50static inline void init_MUTEX_LOCKED (struct semaphore *sem)
53{ 51{
54 sema_init(sem, 0); 52 sema_init(sem, 0);
55} 53}
@@ -61,7 +59,7 @@ extern void __up(struct semaphore * sem);
61 59
62/* notice - we probably can do cli/sti here instead of saving */ 60/* notice - we probably can do cli/sti here instead of saving */
63 61
64extern inline void down(struct semaphore * sem) 62static inline void down(struct semaphore * sem)
65{ 63{
66 unsigned long flags; 64 unsigned long flags;
67 int failed; 65 int failed;
@@ -83,7 +81,7 @@ extern inline void down(struct semaphore * sem)
83 * returns negative for signalled and zero for semaphore acquired. 81 * returns negative for signalled and zero for semaphore acquired.
84 */ 82 */
85 83
86extern inline int down_interruptible(struct semaphore * sem) 84static inline int down_interruptible(struct semaphore * sem)
87{ 85{
88 unsigned long flags; 86 unsigned long flags;
89 int failed; 87 int failed;
@@ -99,7 +97,7 @@ extern inline int down_interruptible(struct semaphore * sem)
99 return(failed); 97 return(failed);
100} 98}
101 99
102extern inline int down_trylock(struct semaphore * sem) 100static inline int down_trylock(struct semaphore * sem)
103{ 101{
104 unsigned long flags; 102 unsigned long flags;
105 int failed; 103 int failed;
@@ -119,7 +117,7 @@ extern inline int down_trylock(struct semaphore * sem)
119 * The default case (no contention) will result in NO 117 * The default case (no contention) will result in NO
120 * jumps for both down() and up(). 118 * jumps for both down() and up().
121 */ 119 */
122extern inline void up(struct semaphore * sem) 120static inline void up(struct semaphore * sem)
123{ 121{
124 unsigned long flags; 122 unsigned long flags;
125 int wakeup; 123 int wakeup;
diff --git a/include/asm-cris/system.h b/include/asm-cris/system.h
index e06739806d4e..d48670107a85 100644
--- a/include/asm-cris/system.h
+++ b/include/asm-cris/system.h
@@ -41,7 +41,7 @@ extern struct task_struct *resume(struct task_struct *prev, struct task_struct *
41void disable_hlt(void); 41void disable_hlt(void);
42void enable_hlt(void); 42void enable_hlt(void);
43 43
44extern inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size) 44static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
45{ 45{
46 /* since Etrax doesn't have any atomic xchg instructions, we need to disable 46 /* since Etrax doesn't have any atomic xchg instructions, we need to disable
47 irq's (if enabled) and do it with move.d's */ 47 irq's (if enabled) and do it with move.d's */
diff --git a/include/asm-cris/timex.h b/include/asm-cris/timex.h
index 3fb069a37717..b92e0e80fe86 100644
--- a/include/asm-cris/timex.h
+++ b/include/asm-cris/timex.h
@@ -16,7 +16,7 @@
16 16
17typedef unsigned long long cycles_t; 17typedef unsigned long long cycles_t;
18 18
19extern inline cycles_t get_cycles(void) 19static inline cycles_t get_cycles(void)
20{ 20{
21 return 0; 21 return 0;
22} 22}
diff --git a/include/asm-cris/tlbflush.h b/include/asm-cris/tlbflush.h
index 6ed7d9ae90db..c52238005b55 100644
--- a/include/asm-cris/tlbflush.h
+++ b/include/asm-cris/tlbflush.h
@@ -39,14 +39,14 @@ static inline void flush_tlb_range(struct vm_area_struct * vma, unsigned long st
39 flush_tlb_mm(vma->vm_mm); 39 flush_tlb_mm(vma->vm_mm);
40} 40}
41 41
42extern inline void flush_tlb_pgtables(struct mm_struct *mm, 42static inline void flush_tlb_pgtables(struct mm_struct *mm,
43 unsigned long start, unsigned long end) 43 unsigned long start, unsigned long end)
44{ 44{
45 /* CRIS does not keep any page table caches in TLB */ 45 /* CRIS does not keep any page table caches in TLB */
46} 46}
47 47
48 48
49extern inline void flush_tlb(void) 49static inline void flush_tlb(void)
50{ 50{
51 flush_tlb_mm(current->mm); 51 flush_tlb_mm(current->mm);
52} 52}
diff --git a/include/asm-cris/uaccess.h b/include/asm-cris/uaccess.h
index 7d50086eb5ea..69d48a2dc8e1 100644
--- a/include/asm-cris/uaccess.h
+++ b/include/asm-cris/uaccess.h
@@ -213,7 +213,7 @@ extern unsigned long __copy_user(void *to, const void *from, unsigned long n);
213extern unsigned long __copy_user_zeroing(void *to, const void *from, unsigned long n); 213extern unsigned long __copy_user_zeroing(void *to, const void *from, unsigned long n);
214extern unsigned long __do_clear_user(void *to, unsigned long n); 214extern unsigned long __do_clear_user(void *to, unsigned long n);
215 215
216extern inline unsigned long 216static inline unsigned long
217__generic_copy_to_user(void __user *to, const void *from, unsigned long n) 217__generic_copy_to_user(void __user *to, const void *from, unsigned long n)
218{ 218{
219 if (access_ok(VERIFY_WRITE, to, n)) 219 if (access_ok(VERIFY_WRITE, to, n))
@@ -221,7 +221,7 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
221 return n; 221 return n;
222} 222}
223 223
224extern inline unsigned long 224static inline unsigned long
225__generic_copy_from_user(void *to, const void __user *from, unsigned long n) 225__generic_copy_from_user(void *to, const void __user *from, unsigned long n)
226{ 226{
227 if (access_ok(VERIFY_READ, from, n)) 227 if (access_ok(VERIFY_READ, from, n))
@@ -229,7 +229,7 @@ __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
229 return n; 229 return n;
230} 230}
231 231
232extern inline unsigned long 232static inline unsigned long
233__generic_clear_user(void __user *to, unsigned long n) 233__generic_clear_user(void __user *to, unsigned long n)
234{ 234{
235 if (access_ok(VERIFY_WRITE, to, n)) 235 if (access_ok(VERIFY_WRITE, to, n))
@@ -237,13 +237,13 @@ __generic_clear_user(void __user *to, unsigned long n)
237 return n; 237 return n;
238} 238}
239 239
240extern inline long 240static inline long
241__strncpy_from_user(char *dst, const char __user *src, long count) 241__strncpy_from_user(char *dst, const char __user *src, long count)
242{ 242{
243 return __do_strncpy_from_user(dst, src, count); 243 return __do_strncpy_from_user(dst, src, count);
244} 244}
245 245
246extern inline long 246static inline long
247strncpy_from_user(char *dst, const char __user *src, long count) 247strncpy_from_user(char *dst, const char __user *src, long count)
248{ 248{
249 long res = -EFAULT; 249 long res = -EFAULT;
@@ -256,7 +256,7 @@ strncpy_from_user(char *dst, const char __user *src, long count)
256/* Note that if these expand awfully if made into switch constructs, so 256/* Note that if these expand awfully if made into switch constructs, so
257 don't do that. */ 257 don't do that. */
258 258
259extern inline unsigned long 259static inline unsigned long
260__constant_copy_from_user(void *to, const void __user *from, unsigned long n) 260__constant_copy_from_user(void *to, const void __user *from, unsigned long n)
261{ 261{
262 unsigned long ret = 0; 262 unsigned long ret = 0;
@@ -306,7 +306,7 @@ __constant_copy_from_user(void *to, const void __user *from, unsigned long n)
306 306
307/* Ditto, don't make a switch out of this. */ 307/* Ditto, don't make a switch out of this. */
308 308
309extern inline unsigned long 309static inline unsigned long
310__constant_copy_to_user(void __user *to, const void *from, unsigned long n) 310__constant_copy_to_user(void __user *to, const void *from, unsigned long n)
311{ 311{
312 unsigned long ret = 0; 312 unsigned long ret = 0;
@@ -356,7 +356,7 @@ __constant_copy_to_user(void __user *to, const void *from, unsigned long n)
356 356
357/* No switch, please. */ 357/* No switch, please. */
358 358
359extern inline unsigned long 359static inline unsigned long
360__constant_clear_user(void __user *to, unsigned long n) 360__constant_clear_user(void __user *to, unsigned long n)
361{ 361{
362 unsigned long ret = 0; 362 unsigned long ret = 0;
@@ -406,19 +406,19 @@ __constant_clear_user(void __user *to, unsigned long n)
406 * used in fast paths and have only a small space overhead. 406 * used in fast paths and have only a small space overhead.
407 */ 407 */
408 408
409extern inline unsigned long 409static inline unsigned long
410__generic_copy_from_user_nocheck(void *to, const void *from, unsigned long n) 410__generic_copy_from_user_nocheck(void *to, const void *from, unsigned long n)
411{ 411{
412 return __copy_user_zeroing(to,from,n); 412 return __copy_user_zeroing(to,from,n);
413} 413}
414 414
415extern inline unsigned long 415static inline unsigned long
416__generic_copy_to_user_nocheck(void *to, const void *from, unsigned long n) 416__generic_copy_to_user_nocheck(void *to, const void *from, unsigned long n)
417{ 417{
418 return __copy_user(to,from,n); 418 return __copy_user(to,from,n);
419} 419}
420 420
421extern inline unsigned long 421static inline unsigned long
422__generic_clear_user_nocheck(void *to, unsigned long n) 422__generic_clear_user_nocheck(void *to, unsigned long n)
423{ 423{
424 return __do_clear_user(to,n); 424 return __do_clear_user(to,n);
diff --git a/include/asm-cris/unistd.h b/include/asm-cris/unistd.h
index 156a34bfc583..2627bbdf8a11 100644
--- a/include/asm-cris/unistd.h
+++ b/include/asm-cris/unistd.h
@@ -343,14 +343,14 @@
343 * some others too. 343 * some others too.
344 */ 344 */
345#define __NR__exit __NR_exit 345#define __NR__exit __NR_exit
346extern inline _syscall0(pid_t,setsid) 346static inline _syscall0(pid_t,setsid)
347extern inline _syscall3(int,write,int,fd,const char *,buf,off_t,count) 347static inline _syscall3(int,write,int,fd,const char *,buf,off_t,count)
348extern inline _syscall3(int,read,int,fd,char *,buf,off_t,count) 348static inline _syscall3(int,read,int,fd,char *,buf,off_t,count)
349extern inline _syscall3(off_t,lseek,int,fd,off_t,offset,int,count) 349static inline _syscall3(off_t,lseek,int,fd,off_t,offset,int,count)
350extern inline _syscall1(int,dup,int,fd) 350static inline _syscall1(int,dup,int,fd)
351extern inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp) 351static inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
352extern inline _syscall3(int,open,const char *,file,int,flag,int,mode) 352static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
353extern inline _syscall1(int,close,int,fd) 353static inline _syscall1(int,close,int,fd)
354 354
355struct pt_regs; 355struct pt_regs;
356asmlinkage long sys_mmap2( 356asmlinkage long sys_mmap2(
@@ -382,8 +382,8 @@ asmlinkage long sys_rt_sigaction(int sig,
382#ifdef __KERNEL__ 382#ifdef __KERNEL__
383#define _exit kernel_syscall_exit 383#define _exit kernel_syscall_exit
384#endif 384#endif
385extern inline _syscall1(int,_exit,int,exitcode) 385static inline _syscall1(int,_exit,int,exitcode)
386extern inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options) 386static inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
387#endif 387#endif
388 388
389 389
diff --git a/include/asm-frv/pgtable.h b/include/asm-frv/pgtable.h
index b247e99dff49..844666377dcb 100644
--- a/include/asm-frv/pgtable.h
+++ b/include/asm-frv/pgtable.h
@@ -26,6 +26,8 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/list.h> 27#include <linux/list.h>
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29struct mm_struct;
30struct vm_area_struct;
29#endif 31#endif
30 32
31#ifndef __ASSEMBLY__ 33#ifndef __ASSEMBLY__
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index 7dca30a26c53..358e4d309ceb 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -128,6 +128,7 @@ do { \
128#endif 128#endif
129 129
130#ifndef __HAVE_ARCH_PTEP_SET_WRPROTECT 130#ifndef __HAVE_ARCH_PTEP_SET_WRPROTECT
131struct mm_struct;
131static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long address, pte_t *ptep) 132static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long address, pte_t *ptep)
132{ 133{
133 pte_t old_pte = *ptep; 134 pte_t old_pte = *ptep;
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index a9c55490fb82..094d4917c1a9 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -35,6 +35,13 @@
35 VMLINUX_SYMBOL(__end_pci_fixups_enable) = .; \ 35 VMLINUX_SYMBOL(__end_pci_fixups_enable) = .; \
36 } \ 36 } \
37 \ 37 \
38 /* RapidIO route ops */ \
39 .rio_route : AT(ADDR(.rio_route) - LOAD_OFFSET) { \
40 VMLINUX_SYMBOL(__start_rio_route_ops) = .; \
41 *(.rio_route_ops) \
42 VMLINUX_SYMBOL(__end_rio_route_ops) = .; \
43 } \
44 \
38 /* Kernel symbol table: Normal symbols */ \ 45 /* Kernel symbol table: Normal symbols */ \
39 __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \ 46 __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \
40 VMLINUX_SYMBOL(__start___ksymtab) = .; \ 47 VMLINUX_SYMBOL(__start___ksymtab) = .; \
diff --git a/include/asm-i386/elf.h b/include/asm-i386/elf.h
index fa11117d3cfa..4153d80e4d2b 100644
--- a/include/asm-i386/elf.h
+++ b/include/asm-i386/elf.h
@@ -119,6 +119,8 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
119 */ 119 */
120#define elf_read_implies_exec(ex, executable_stack) (executable_stack != EXSTACK_DISABLE_X) 120#define elf_read_implies_exec(ex, executable_stack) (executable_stack != EXSTACK_DISABLE_X)
121 121
122struct task_struct;
123
122extern int dump_task_regs (struct task_struct *, elf_gregset_t *); 124extern int dump_task_regs (struct task_struct *, elf_gregset_t *);
123extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *); 125extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *);
124extern int dump_task_extended_fpu (struct task_struct *, struct user_fxsr_struct *); 126extern int dump_task_extended_fpu (struct task_struct *, struct user_fxsr_struct *);
diff --git a/include/asm-i386/kprobes.h b/include/asm-i386/kprobes.h
index 8b6d3a90cd78..ca916a892877 100644
--- a/include/asm-i386/kprobes.h
+++ b/include/asm-i386/kprobes.h
@@ -49,6 +49,23 @@ struct arch_specific_insn {
49 kprobe_opcode_t insn[MAX_INSN_SIZE]; 49 kprobe_opcode_t insn[MAX_INSN_SIZE];
50}; 50};
51 51
52struct prev_kprobe {
53 struct kprobe *kp;
54 unsigned long status;
55 unsigned long old_eflags;
56 unsigned long saved_eflags;
57};
58
59/* per-cpu kprobe control block */
60struct kprobe_ctlblk {
61 unsigned long kprobe_status;
62 unsigned long kprobe_old_eflags;
63 unsigned long kprobe_saved_eflags;
64 long *jprobe_saved_esp;
65 struct pt_regs jprobe_saved_regs;
66 kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE];
67 struct prev_kprobe prev_kprobe;
68};
52 69
53/* trap3/1 are intr gates for kprobes. So, restore the status of IF, 70/* trap3/1 are intr gates for kprobes. So, restore the status of IF,
54 * if necessary, before executing the original int3/1 (trap) handler. 71 * if necessary, before executing the original int3/1 (trap) handler.
diff --git a/include/asm-i386/pgtable.h b/include/asm-i386/pgtable.h
index 03f3c8ac6383..088a945bf26b 100644
--- a/include/asm-i386/pgtable.h
+++ b/include/asm-i386/pgtable.h
@@ -25,6 +25,9 @@
25#include <linux/list.h> 25#include <linux/list.h>
26#include <linux/spinlock.h> 26#include <linux/spinlock.h>
27 27
28struct mm_struct;
29struct vm_area_struct;
30
28/* 31/*
29 * ZERO_PAGE is a global shared page that is always zero: used 32 * ZERO_PAGE is a global shared page that is always zero: used
30 * for zero-mapped memory areas etc.. 33 * for zero-mapped memory areas etc..
diff --git a/include/asm-i386/processor.h b/include/asm-i386/processor.h
index 0a4ec764377c..8c02b0318703 100644
--- a/include/asm-i386/processor.h
+++ b/include/asm-i386/processor.h
@@ -718,4 +718,10 @@ extern void mtrr_bp_init(void);
718#define mtrr_bp_init() do {} while (0) 718#define mtrr_bp_init() do {} while (0)
719#endif 719#endif
720 720
721#ifdef CONFIG_X86_MCE
722extern void mcheck_init(struct cpuinfo_x86 *c);
723#else
724#define mcheck_init(c) do {} while(0)
725#endif
726
721#endif /* __ASM_I386_PROCESSOR_H */ 727#endif /* __ASM_I386_PROCESSOR_H */
diff --git a/include/asm-ia64/dma-mapping.h b/include/asm-ia64/dma-mapping.h
index 6347c9845642..df67d40801de 100644
--- a/include/asm-ia64/dma-mapping.h
+++ b/include/asm-ia64/dma-mapping.h
@@ -48,12 +48,7 @@ dma_set_mask (struct device *dev, u64 mask)
48 return 0; 48 return 0;
49} 49}
50 50
51static inline int 51extern int dma_get_cache_alignment(void);
52dma_get_cache_alignment (void)
53{
54 extern int ia64_max_cacheline_size;
55 return ia64_max_cacheline_size;
56}
57 52
58static inline void 53static inline void
59dma_cache_sync (void *vaddr, size_t size, enum dma_data_direction dir) 54dma_cache_sync (void *vaddr, size_t size, enum dma_data_direction dir)
diff --git a/include/asm-ia64/kprobes.h b/include/asm-ia64/kprobes.h
index 573a3574a24f..592abb000e29 100644
--- a/include/asm-ia64/kprobes.h
+++ b/include/asm-ia64/kprobes.h
@@ -26,6 +26,7 @@
26 */ 26 */
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/ptrace.h> 28#include <linux/ptrace.h>
29#include <linux/percpu.h>
29#include <asm/break.h> 30#include <asm/break.h>
30 31
31#define MAX_INSN_SIZE 16 32#define MAX_INSN_SIZE 16
@@ -62,6 +63,18 @@ typedef struct _bundle {
62 } quad1; 63 } quad1;
63} __attribute__((__aligned__(16))) bundle_t; 64} __attribute__((__aligned__(16))) bundle_t;
64 65
66struct prev_kprobe {
67 struct kprobe *kp;
68 unsigned long status;
69};
70
71/* per-cpu kprobe control block */
72struct kprobe_ctlblk {
73 unsigned long kprobe_status;
74 struct pt_regs jprobe_saved_regs;
75 struct prev_kprobe prev_kprobe;
76};
77
65#define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)pentry 78#define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)pentry
66 79
67#define ARCH_SUPPORTS_KRETPROBES 80#define ARCH_SUPPORTS_KRETPROBES
diff --git a/include/asm-ia64/page.h b/include/asm-ia64/page.h
index ef436b9d06ad..9d41548b7fef 100644
--- a/include/asm-ia64/page.h
+++ b/include/asm-ia64/page.h
@@ -120,6 +120,7 @@ extern unsigned long max_low_pfn;
120 120
121#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) 121#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
122#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 122#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
123#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
123 124
124typedef union ia64_va { 125typedef union ia64_va {
125 struct { 126 struct {
diff --git a/include/asm-ia64/pgtable.h b/include/asm-ia64/pgtable.h
index 21e32a06bc82..c34ba80c1c31 100644
--- a/include/asm-ia64/pgtable.h
+++ b/include/asm-ia64/pgtable.h
@@ -127,6 +127,7 @@
127 127
128# ifndef __ASSEMBLY__ 128# ifndef __ASSEMBLY__
129 129
130#include <linux/sched.h> /* for mm_struct */
130#include <asm/bitops.h> 131#include <asm/bitops.h>
131#include <asm/cacheflush.h> 132#include <asm/cacheflush.h>
132#include <asm/mmu_context.h> 133#include <asm/mmu_context.h>
diff --git a/include/asm-ia64/ptrace.h b/include/asm-ia64/ptrace.h
index a79d1a7ecc77..2c703d6e0c86 100644
--- a/include/asm-ia64/ptrace.h
+++ b/include/asm-ia64/ptrace.h
@@ -229,6 +229,9 @@ struct switch_stack {
229}; 229};
230 230
231#ifdef __KERNEL__ 231#ifdef __KERNEL__
232
233#define __ARCH_SYS_PTRACE 1
234
232/* 235/*
233 * We use the ia64_psr(regs)->ri to determine which of the three 236 * We use the ia64_psr(regs)->ri to determine which of the three
234 * instructions in bundle (16 bytes) took the sample. Generate 237 * instructions in bundle (16 bytes) took the sample. Generate
diff --git a/include/asm-m32r/pgtable.h b/include/asm-m32r/pgtable.h
index 1cd5fd4a5b2c..75740debcd01 100644
--- a/include/asm-m32r/pgtable.h
+++ b/include/asm-m32r/pgtable.h
@@ -27,6 +27,9 @@
27#include <asm/bitops.h> 27#include <asm/bitops.h>
28#include <asm/page.h> 28#include <asm/page.h>
29 29
30struct mm_struct;
31struct vm_area_struct;
32
30extern pgd_t swapper_pg_dir[1024]; 33extern pgd_t swapper_pg_dir[1024];
31extern void paging_init(void); 34extern void paging_init(void);
32 35
diff --git a/include/asm-m32r/ptrace.h b/include/asm-m32r/ptrace.h
index 976417126b2d..55cd7ecfde43 100644
--- a/include/asm-m32r/ptrace.h
+++ b/include/asm-m32r/ptrace.h
@@ -145,6 +145,9 @@ struct pt_regs {
145#define PTRACE_O_TRACESYSGOOD 0x00000001 145#define PTRACE_O_TRACESYSGOOD 0x00000001
146 146
147#ifdef __KERNEL__ 147#ifdef __KERNEL__
148
149#define __ARCH_SYS_PTRACE 1
150
148#if defined(CONFIG_ISA_M32R2) || defined(CONFIG_CHIP_VDEC2) 151#if defined(CONFIG_ISA_M32R2) || defined(CONFIG_CHIP_VDEC2)
149#define user_mode(regs) ((M32R_PSW_BPM & (regs)->psw) != 0) 152#define user_mode(regs) ((M32R_PSW_BPM & (regs)->psw) != 0)
150#elif defined(CONFIG_ISA_M32R) 153#elif defined(CONFIG_ISA_M32R)
diff --git a/include/asm-m68k/kbio.h b/include/asm-m68k/kbio.h
deleted file mode 100644
index e1fbf8fba3e8..000000000000
--- a/include/asm-m68k/kbio.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-sparc/kbio.h>
diff --git a/include/asm-m68k/vuid_event.h b/include/asm-m68k/vuid_event.h
deleted file mode 100644
index 52ecb521a395..000000000000
--- a/include/asm-m68k/vuid_event.h
+++ /dev/null
@@ -1,4 +0,0 @@
1#ifndef _M68K_VUID_EVENT_H
2#define _M68K_VUID_EVENT_H
3#include <asm-sparc/vuid_event.h>
4#endif
diff --git a/include/asm-m68knommu/cacheflush.h b/include/asm-m68knommu/cacheflush.h
index 026bbc9565b4..49925e91e89c 100644
--- a/include/asm-m68knommu/cacheflush.h
+++ b/include/asm-m68knommu/cacheflush.h
@@ -25,7 +25,7 @@
25#define copy_from_user_page(vma, page, vaddr, dst, src, len) \ 25#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
26 memcpy(dst, src, len) 26 memcpy(dst, src, len)
27 27
28extern inline void __flush_cache_all(void) 28static inline void __flush_cache_all(void)
29{ 29{
30#ifdef CONFIG_M5407 30#ifdef CONFIG_M5407
31 /* 31 /*
@@ -64,7 +64,7 @@ extern inline void __flush_cache_all(void)
64 "nop\n\t" 64 "nop\n\t"
65 : : : "d0" ); 65 : : : "d0" );
66#endif /* CONFIG_M5272 */ 66#endif /* CONFIG_M5272 */
67#if CONFIG_M5249 67#ifdef CONFIG_M5249
68 __asm__ __volatile__ ( 68 __asm__ __volatile__ (
69 "movel #0xa1000200, %%d0\n\t" 69 "movel #0xa1000200, %%d0\n\t"
70 "movec %%d0, %%CACR\n\t" 70 "movec %%d0, %%CACR\n\t"
diff --git a/include/asm-m68knommu/irq.h b/include/asm-m68knommu/irq.h
index 208ccd969e4b..a08fa9b958da 100644
--- a/include/asm-m68knommu/irq.h
+++ b/include/asm-m68knommu/irq.h
@@ -2,7 +2,6 @@
2#define _M68K_IRQ_H_ 2#define _M68K_IRQ_H_
3 3
4#include <linux/config.h> 4#include <linux/config.h>
5#include <linux/interrupt.h>
6#include <asm/ptrace.h> 5#include <asm/ptrace.h>
7 6
8#ifdef CONFIG_COLDFIRE 7#ifdef CONFIG_COLDFIRE
@@ -83,36 +82,6 @@ extern void (*mach_disable_irq)(unsigned int);
83#endif /* CONFIG_M68360 */ 82#endif /* CONFIG_M68360 */
84 83
85/* 84/*
86 * This structure is used to chain together the ISRs for a particular
87 * interrupt source (if it supports chaining).
88 */
89typedef struct irq_node {
90 irqreturn_t (*handler)(int, void *, struct pt_regs *);
91 unsigned long flags;
92 void *dev_id;
93 const char *devname;
94 struct irq_node *next;
95} irq_node_t;
96
97/*
98 * This structure has only 4 elements for speed reasons
99 */
100typedef struct irq_handler {
101 irqreturn_t (*handler)(int, void *, struct pt_regs *);
102 unsigned long flags;
103 void *dev_id;
104 const char *devname;
105} irq_handler_t;
106
107/* count of spurious interrupts */
108extern volatile unsigned int num_spurious;
109
110/*
111 * This function returns a new irq_node_t
112 */
113extern irq_node_t *new_irq_node(void);
114
115/*
116 * Some drivers want these entry points 85 * Some drivers want these entry points
117 */ 86 */
118#define enable_irq(x) (mach_enable_irq ? (*mach_enable_irq)(x) : 0) 87#define enable_irq(x) (mach_enable_irq ? (*mach_enable_irq)(x) : 0)
diff --git a/include/asm-m68knommu/irqnode.h b/include/asm-m68knommu/irqnode.h
new file mode 100644
index 000000000000..a2503dfc554c
--- /dev/null
+++ b/include/asm-m68knommu/irqnode.h
@@ -0,0 +1,36 @@
1#ifndef _M68K_IRQNODE_H_
2#define _M68K_IRQNODE_H_
3
4#include <linux/interrupt.h>
5
6/*
7 * This structure is used to chain together the ISRs for a particular
8 * interrupt source (if it supports chaining).
9 */
10typedef struct irq_node {
11 irqreturn_t (*handler)(int, void *, struct pt_regs *);
12 unsigned long flags;
13 void *dev_id;
14 const char *devname;
15 struct irq_node *next;
16} irq_node_t;
17
18/*
19 * This structure has only 4 elements for speed reasons
20 */
21typedef struct irq_handler {
22 irqreturn_t (*handler)(int, void *, struct pt_regs *);
23 unsigned long flags;
24 void *dev_id;
25 const char *devname;
26} irq_handler_t;
27
28/* count of spurious interrupts */
29extern volatile unsigned int num_spurious;
30
31/*
32 * This function returns a new irq_node_t
33 */
34extern irq_node_t *new_irq_node(void);
35
36#endif /* _M68K_IRQNODE_H_ */
diff --git a/include/asm-mips/.gitignore b/include/asm-mips/.gitignore
new file mode 100644
index 000000000000..4ec57ad5bc3c
--- /dev/null
+++ b/include/asm-mips/.gitignore
@@ -0,0 +1 @@
asm_offsets.h
diff --git a/include/asm-mips/delay.h b/include/asm-mips/delay.h
index 85435a8d4e52..48d00cccdafa 100644
--- a/include/asm-mips/delay.h
+++ b/include/asm-mips/delay.h
@@ -84,4 +84,13 @@ static inline void __udelay(unsigned long usecs, unsigned long lpj)
84 84
85#define udelay(usecs) __udelay((usecs),__udelay_val) 85#define udelay(usecs) __udelay((usecs),__udelay_val)
86 86
87/* make sure "usecs *= ..." in udelay do not overflow. */
88#if HZ >= 1000
89#define MAX_UDELAY_MS 1
90#elif HZ <= 200
91#define MAX_UDELAY_MS 5
92#else
93#define MAX_UDELAY_MS (1000 / HZ)
94#endif
95
87#endif /* _ASM_DELAY_H */ 96#endif /* _ASM_DELAY_H */
diff --git a/include/asm-mips/elf.h b/include/asm-mips/elf.h
index 7420f12742bb..d2c9a25f8459 100644
--- a/include/asm-mips/elf.h
+++ b/include/asm-mips/elf.h
@@ -275,6 +275,8 @@ do { \
275 275
276#endif /* CONFIG_64BIT */ 276#endif /* CONFIG_64BIT */
277 277
278struct task_struct;
279
278extern void dump_regs(elf_greg_t *, struct pt_regs *regs); 280extern void dump_regs(elf_greg_t *, struct pt_regs *regs);
279extern int dump_task_regs (struct task_struct *, elf_gregset_t *); 281extern int dump_task_regs (struct task_struct *, elf_gregset_t *);
280extern int dump_task_fpu(struct task_struct *, elf_fpregset_t *); 282extern int dump_task_fpu(struct task_struct *, elf_fpregset_t *);
diff --git a/include/asm-mips/errno.h b/include/asm-mips/errno.h
index 9d3e6e7cdb92..3c0d840e4577 100644
--- a/include/asm-mips/errno.h
+++ b/include/asm-mips/errno.h
@@ -119,10 +119,6 @@
119#define EOWNERDEAD 165 /* Owner died */ 119#define EOWNERDEAD 165 /* Owner died */
120#define ENOTRECOVERABLE 166 /* State not recoverable */ 120#define ENOTRECOVERABLE 166 /* State not recoverable */
121 121
122/* for robust mutexes */
123#define EOWNERDEAD 165 /* Owner died */
124#define ENOTRECOVERABLE 166 /* State not recoverable */
125
126#define EDQUOT 1133 /* Quota exceeded */ 122#define EDQUOT 1133 /* Quota exceeded */
127 123
128#ifdef __KERNEL__ 124#ifdef __KERNEL__
diff --git a/include/asm-mips/ip32/mace.h b/include/asm-mips/ip32/mace.h
index 432011b16c26..5bdc51d85b6c 100644
--- a/include/asm-mips/ip32/mace.h
+++ b/include/asm-mips/ip32/mace.h
@@ -147,6 +147,29 @@ struct mace_audio {
147 } chan[3]; 147 } chan[3];
148}; 148};
149 149
150
151/* register definitions for parallel port DMA */
152struct mace_parport {
153/* 0 - do nothing, 1 - pulse terminal count to the device after buffer is drained */
154#define MACEPAR_CONTEXT_LASTFLAG BIT(63)
155/* Should not cross 4K page boundary */
156#define MACEPAR_CONTEXT_DATALEN_MASK 0xfff00000000
157/* Can be arbitrarily aligned on any byte boundary on output, 64 byte aligned on input */
158#define MACEPAR_CONTEXT_BASEADDR_MASK 0xffffffff
159 volatile u64 context_a;
160 volatile u64 context_b;
161#define MACEPAR_CTLSTAT_DIRECTION BIT(0) /* 0 - mem->device, 1 - device->mem */
162#define MACEPAR_CTLSTAT_ENABLE BIT(1) /* 0 - channel frozen, 1 - channel enabled */
163#define MACEPAR_CTLSTAT_RESET BIT(2) /* 0 - channel active, 1 - complete channel reset */
164#define MACEPAR_CTLSTAT_CTXB_VALID BIT(3)
165#define MACEPAR_CTLSTAT_CTXA_VALID BIT(4)
166 volatile u64 cntlstat; /* Control/Status register */
167#define MACEPAR_DIAG_CTXINUSE BIT(1)
168#define MACEPAR_DIAG_DMACTIVE BIT(2) /* 1 - Dma engine is enabled and processing something */
169#define MACEPAR_DIAG_CTRMASK 0x3ffc /* Counter of bytes left */
170 volatile u64 diagnostic; /* RO: diagnostic register */
171};
172
150/* ISA Control and DMA registers */ 173/* ISA Control and DMA registers */
151struct mace_isactrl { 174struct mace_isactrl {
152 volatile unsigned long ringbase; 175 volatile unsigned long ringbase;
@@ -199,6 +222,7 @@ struct mace_isactrl {
199 volatile unsigned long _pad[0x2000/8 - 4]; 222 volatile unsigned long _pad[0x2000/8 - 4];
200 223
201 volatile unsigned long dp_ram[0x400]; 224 volatile unsigned long dp_ram[0x400];
225 struct mace_parport parport;
202}; 226};
203 227
204/* Keyboard & Mouse registers 228/* Keyboard & Mouse registers
@@ -277,7 +301,7 @@ struct mace_perif {
277 */ 301 */
278 302
279/* Parallel port */ 303/* Parallel port */
280struct mace_parallel { /* later... */ 304struct mace_parallel {
281}; 305};
282 306
283struct mace_ecp1284 { /* later... */ 307struct mace_ecp1284 { /* later... */
diff --git a/include/asm-mips/mach-generic/ide.h b/include/asm-mips/mach-generic/ide.h
index 961006948c7c..550979a9ea9d 100644
--- a/include/asm-mips/mach-generic/ide.h
+++ b/include/asm-mips/mach-generic/ide.h
@@ -168,8 +168,12 @@ static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
168/* ide_insw calls insw, not __ide_insw. Why? */ 168/* ide_insw calls insw, not __ide_insw. Why? */
169#undef insw 169#undef insw
170#undef insl 170#undef insl
171#undef outsw
172#undef outsl
171#define insw(port, addr, count) __ide_insw(port, addr, count) 173#define insw(port, addr, count) __ide_insw(port, addr, count)
172#define insl(port, addr, count) __ide_insl(port, addr, count) 174#define insl(port, addr, count) __ide_insl(port, addr, count)
175#define outsw(port, addr, count) __ide_outsw(port, addr, count)
176#define outsl(port, addr, count) __ide_outsl(port, addr, count)
173 177
174#endif /* __KERNEL__ */ 178#endif /* __KERNEL__ */
175 179
diff --git a/include/asm-mips/mc146818-time.h b/include/asm-mips/mc146818-time.h
index a2c2d2c24303..47214861093b 100644
--- a/include/asm-mips/mc146818-time.h
+++ b/include/asm-mips/mc146818-time.h
@@ -33,7 +33,9 @@ static inline int mc146818_set_rtc_mmss(unsigned long nowtime)
33 int real_seconds, real_minutes, cmos_minutes; 33 int real_seconds, real_minutes, cmos_minutes;
34 unsigned char save_control, save_freq_select; 34 unsigned char save_control, save_freq_select;
35 int retval = 0; 35 int retval = 0;
36 unsigned long flags;
36 37
38 spin_lock_irqsave(&rtc_lock, flags);
37 save_control = CMOS_READ(RTC_CONTROL); /* tell the clock it's being set */ 39 save_control = CMOS_READ(RTC_CONTROL); /* tell the clock it's being set */
38 CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL); 40 CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL);
39 41
@@ -79,14 +81,30 @@ static inline int mc146818_set_rtc_mmss(unsigned long nowtime)
79 */ 81 */
80 CMOS_WRITE(save_control, RTC_CONTROL); 82 CMOS_WRITE(save_control, RTC_CONTROL);
81 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); 83 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
84 spin_unlock_irqrestore(&rtc_lock, flags);
82 85
83 return retval; 86 return retval;
84} 87}
85 88
89/*
90 * Returns true if a clock update is in progress
91 */
92static inline unsigned char rtc_is_updating(void)
93{
94 unsigned char uip;
95 unsigned long flags;
96
97 spin_lock_irqsave(&rtc_lock, flags);
98 uip = (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP);
99 spin_unlock_irqrestore(&rtc_lock, flags);
100 return uip;
101}
102
86static inline unsigned long mc146818_get_cmos_time(void) 103static inline unsigned long mc146818_get_cmos_time(void)
87{ 104{
88 unsigned int year, mon, day, hour, min, sec; 105 unsigned int year, mon, day, hour, min, sec;
89 int i; 106 int i;
107 unsigned long flags;
90 108
91 /* 109 /*
92 * The Linux interpretation of the CMOS clock register contents: 110 * The Linux interpretation of the CMOS clock register contents:
@@ -97,12 +115,13 @@ static inline unsigned long mc146818_get_cmos_time(void)
97 115
98 /* read RTC exactly on falling edge of update flag */ 116 /* read RTC exactly on falling edge of update flag */
99 for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */ 117 for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */
100 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) 118 if (rtc_is_updating())
101 break; 119 break;
102 for (i = 0 ; i < 1000000 ; i++) /* must try at least 2.228 ms */ 120 for (i = 0 ; i < 1000000 ; i++) /* must try at least 2.228 ms */
103 if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)) 121 if (!rtc_is_updating())
104 break; 122 break;
105 123
124 spin_lock_irqsave(&rtc_lock, flags);
106 do { /* Isn't this overkill ? UIP above should guarantee consistency */ 125 do { /* Isn't this overkill ? UIP above should guarantee consistency */
107 sec = CMOS_READ(RTC_SECONDS); 126 sec = CMOS_READ(RTC_SECONDS);
108 min = CMOS_READ(RTC_MINUTES); 127 min = CMOS_READ(RTC_MINUTES);
@@ -120,6 +139,7 @@ static inline unsigned long mc146818_get_cmos_time(void)
120 BCD_TO_BIN(mon); 139 BCD_TO_BIN(mon);
121 BCD_TO_BIN(year); 140 BCD_TO_BIN(year);
122 } 141 }
142 spin_unlock_irqrestore(&rtc_lock, flags);
123 year = mc146818_decode_year(year); 143 year = mc146818_decode_year(year);
124 144
125 return mktime(year, mon, day, hour, min, sec); 145 return mktime(year, mon, day, hour, min, sec);
diff --git a/include/asm-mips/module.h b/include/asm-mips/module.h
index 2be399311eec..2af496c78c12 100644
--- a/include/asm-mips/module.h
+++ b/include/asm-mips/module.h
@@ -76,43 +76,43 @@ search_module_dbetables(unsigned long addr)
76#endif 76#endif
77 77
78#ifdef CONFIG_CPU_MIPS32_R1 78#ifdef CONFIG_CPU_MIPS32_R1
79#define MODULE_PROC_FAMILY "MIPS32_R1" 79#define MODULE_PROC_FAMILY "MIPS32_R1 "
80#elif defined CONFIG_CPU_MIPS32_R2 80#elif defined CONFIG_CPU_MIPS32_R2
81#define MODULE_PROC_FAMILY "MIPS32_R2" 81#define MODULE_PROC_FAMILY "MIPS32_R2 "
82#elif defined CONFIG_CPU_MIPS64_R1 82#elif defined CONFIG_CPU_MIPS64_R1
83#define MODULE_PROC_FAMILY "MIPS64_R1" 83#define MODULE_PROC_FAMILY "MIPS64_R1 "
84#elif defined CONFIG_CPU_MIPS64_R2 84#elif defined CONFIG_CPU_MIPS64_R2
85#define MODULE_PROC_FAMILY "MIPS64_R2" 85#define MODULE_PROC_FAMILY "MIPS64_R2 "
86#elif defined CONFIG_CPU_R3000 86#elif defined CONFIG_CPU_R3000
87#define MODULE_PROC_FAMILY "R3000" 87#define MODULE_PROC_FAMILY "R3000 "
88#elif defined CONFIG_CPU_TX39XX 88#elif defined CONFIG_CPU_TX39XX
89#define MODULE_PROC_FAMILY "TX39XX" 89#define MODULE_PROC_FAMILY "TX39XX "
90#elif defined CONFIG_CPU_VR41XX 90#elif defined CONFIG_CPU_VR41XX
91#define MODULE_PROC_FAMILY "VR41XX" 91#define MODULE_PROC_FAMILY "VR41XX "
92#elif defined CONFIG_CPU_R4300 92#elif defined CONFIG_CPU_R4300
93#define MODULE_PROC_FAMILY "R4300" 93#define MODULE_PROC_FAMILY "R4300 "
94#elif defined CONFIG_CPU_R4X00 94#elif defined CONFIG_CPU_R4X00
95#define MODULE_PROC_FAMILY "R4X00" 95#define MODULE_PROC_FAMILY "R4X00 "
96#elif defined CONFIG_CPU_TX49XX 96#elif defined CONFIG_CPU_TX49XX
97#define MODULE_PROC_FAMILY "TX49XX" 97#define MODULE_PROC_FAMILY "TX49XX "
98#elif defined CONFIG_CPU_R5000 98#elif defined CONFIG_CPU_R5000
99#define MODULE_PROC_FAMILY "R5000" 99#define MODULE_PROC_FAMILY "R5000 "
100#elif defined CONFIG_CPU_R5432 100#elif defined CONFIG_CPU_R5432
101#define MODULE_PROC_FAMILY "R5432" 101#define MODULE_PROC_FAMILY "R5432 "
102#elif defined CONFIG_CPU_R6000 102#elif defined CONFIG_CPU_R6000
103#define MODULE_PROC_FAMILY "R6000" 103#define MODULE_PROC_FAMILY "R6000 "
104#elif defined CONFIG_CPU_NEVADA 104#elif defined CONFIG_CPU_NEVADA
105#define MODULE_PROC_FAMILY "NEVADA" 105#define MODULE_PROC_FAMILY "NEVADA "
106#elif defined CONFIG_CPU_R8000 106#elif defined CONFIG_CPU_R8000
107#define MODULE_PROC_FAMILY "R8000" 107#define MODULE_PROC_FAMILY "R8000 "
108#elif defined CONFIG_CPU_R10000 108#elif defined CONFIG_CPU_R10000
109#define MODULE_PROC_FAMILY "R10000" 109#define MODULE_PROC_FAMILY "R10000 "
110#elif defined CONFIG_CPU_RM7000 110#elif defined CONFIG_CPU_RM7000
111#define MODULE_PROC_FAMILY "RM7000" 111#define MODULE_PROC_FAMILY "RM7000 "
112#elif defined CONFIG_CPU_RM9000 112#elif defined CONFIG_CPU_RM9000
113#define MODULE_PROC_FAMILY "RM9000" 113#define MODULE_PROC_FAMILY "RM9000 "
114#elif defined CONFIG_CPU_SB1 114#elif defined CONFIG_CPU_SB1
115#define MODULE_PROC_FAMILY "SB1" 115#define MODULE_PROC_FAMILY "SB1 "
116#else 116#else
117#error MODULE_PROC_FAMILY undefined for your processor configuration 117#error MODULE_PROC_FAMILY undefined for your processor configuration
118#endif 118#endif
diff --git a/include/asm-mips/pgtable.h b/include/asm-mips/pgtable.h
index 34facd996503..702a28fa7a34 100644
--- a/include/asm-mips/pgtable.h
+++ b/include/asm-mips/pgtable.h
@@ -19,6 +19,9 @@
19#include <asm/io.h> 19#include <asm/io.h>
20#include <asm/pgtable-bits.h> 20#include <asm/pgtable-bits.h>
21 21
22struct mm_struct;
23struct vm_area_struct;
24
22#define PAGE_NONE __pgprot(_PAGE_PRESENT | _CACHE_CACHABLE_NONCOHERENT) 25#define PAGE_NONE __pgprot(_PAGE_PRESENT | _CACHE_CACHABLE_NONCOHERENT)
23#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \ 26#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
24 PAGE_CACHABLE_DEFAULT) 27 PAGE_CACHABLE_DEFAULT)
diff --git a/include/asm-mips/rtc.h b/include/asm-mips/rtc.h
index a60e0dc7c9b9..a2abc4572b63 100644
--- a/include/asm-mips/rtc.h
+++ b/include/asm-mips/rtc.h
@@ -14,7 +14,6 @@
14 14
15#ifdef __KERNEL__ 15#ifdef __KERNEL__
16 16
17#include <linux/spinlock.h>
18#include <linux/rtc.h> 17#include <linux/rtc.h>
19#include <asm/time.h> 18#include <asm/time.h>
20 19
@@ -29,17 +28,13 @@
29#define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */ 28#define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */
30#define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */ 29#define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */
31 30
32static DEFINE_SPINLOCK(mips_rtc_lock);
33
34static inline unsigned int get_rtc_time(struct rtc_time *time) 31static inline unsigned int get_rtc_time(struct rtc_time *time)
35{ 32{
36 unsigned long nowtime; 33 unsigned long nowtime;
37 34
38 spin_lock(&mips_rtc_lock);
39 nowtime = rtc_get_time(); 35 nowtime = rtc_get_time();
40 to_tm(nowtime, time); 36 to_tm(nowtime, time);
41 time->tm_year -= 1900; 37 time->tm_year -= 1900;
42 spin_unlock(&mips_rtc_lock);
43 38
44 return RTC_24H; 39 return RTC_24H;
45} 40}
@@ -49,12 +44,10 @@ static inline int set_rtc_time(struct rtc_time *time)
49 unsigned long nowtime; 44 unsigned long nowtime;
50 int ret; 45 int ret;
51 46
52 spin_lock(&mips_rtc_lock);
53 nowtime = mktime(time->tm_year+1900, time->tm_mon+1, 47 nowtime = mktime(time->tm_year+1900, time->tm_mon+1,
54 time->tm_mday, time->tm_hour, time->tm_min, 48 time->tm_mday, time->tm_hour, time->tm_min,
55 time->tm_sec); 49 time->tm_sec);
56 ret = rtc_set_time(nowtime); 50 ret = rtc_set_time(nowtime);
57 spin_unlock(&mips_rtc_lock);
58 51
59 return ret; 52 return ret;
60} 53}
diff --git a/include/asm-mips/rtlx.h b/include/asm-mips/rtlx.h
index 83cdf6ab0d1f..1298c3fdf6c9 100644
--- a/include/asm-mips/rtlx.h
+++ b/include/asm-mips/rtlx.h
@@ -16,21 +16,19 @@
16#define RTLX_ID (RTLX_xID | RTLX_VERSION) 16#define RTLX_ID (RTLX_xID | RTLX_VERSION)
17#define RTLX_CHANNELS 8 17#define RTLX_CHANNELS 8
18 18
19enum rtlx_state {
20 RTLX_STATE_UNUSED = 0,
21 RTLX_STATE_INITIALISED,
22 RTLX_STATE_REMOTE_READY,
23 RTLX_STATE_OPENED
24};
25
26#define RTLX_BUFFER_SIZE 1024 19#define RTLX_BUFFER_SIZE 1024
20
21/*
22 * lx_state bits
23 */
24#define RTLX_STATE_OPENED 1UL
25
27/* each channel supports read and write. 26/* each channel supports read and write.
28 linux (vpe0) reads lx_buffer and writes rt_buffer 27 linux (vpe0) reads lx_buffer and writes rt_buffer
29 SP (vpe1) reads rt_buffer and writes lx_buffer 28 SP (vpe1) reads rt_buffer and writes lx_buffer
30*/ 29*/
31typedef struct rtlx_channel { 30struct rtlx_channel {
32 enum rtlx_state rt_state; 31 unsigned long lx_state;
33 enum rtlx_state lx_state;
34 32
35 int buffer_size; 33 int buffer_size;
36 34
@@ -43,14 +41,12 @@ typedef struct rtlx_channel {
43 41
44 void *queues; 42 void *queues;
45 43
46} rtlx_channel_t; 44};
47 45
48typedef struct rtlx_info { 46struct rtlx_info {
49 unsigned long id; 47 unsigned long id;
50 enum rtlx_state state;
51 48
52 struct rtlx_channel channel[RTLX_CHANNELS]; 49 struct rtlx_channel channel[RTLX_CHANNELS];
50};
53 51
54} rtlx_info_t; 52#endif /* _RTLX_H_ */
55
56#endif
diff --git a/include/asm-mips/time.h b/include/asm-mips/time.h
index e22a20665871..9cc3564cc2c9 100644
--- a/include/asm-mips/time.h
+++ b/include/asm-mips/time.h
@@ -20,6 +20,9 @@
20#include <linux/linkage.h> 20#include <linux/linkage.h>
21#include <linux/ptrace.h> 21#include <linux/ptrace.h>
22#include <linux/rtc.h> 22#include <linux/rtc.h>
23#include <linux/spinlock.h>
24
25extern spinlock_t rtc_lock;
23 26
24/* 27/*
25 * RTC ops. By default, they point to no-RTC functions. 28 * RTC ops. By default, they point to no-RTC functions.
diff --git a/include/asm-parisc/pgtable.h b/include/asm-parisc/pgtable.h
index c28fb6f48c6c..b4554711c3e7 100644
--- a/include/asm-parisc/pgtable.h
+++ b/include/asm-parisc/pgtable.h
@@ -12,6 +12,7 @@
12 */ 12 */
13 13
14#include <linux/spinlock.h> 14#include <linux/spinlock.h>
15#include <linux/mm.h> /* for vm_area_struct */
15#include <asm/processor.h> 16#include <asm/processor.h>
16#include <asm/cache.h> 17#include <asm/cache.h>
17#include <asm/bitops.h> 18#include <asm/bitops.h>
@@ -418,7 +419,6 @@ extern void paging_init (void);
418 419
419#define PG_dcache_dirty PG_arch_1 420#define PG_dcache_dirty PG_arch_1
420 421
421struct vm_area_struct; /* forward declaration (include/linux/mm.h) */
422extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t); 422extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t);
423 423
424/* Encode and de-code a swap entry */ 424/* Encode and de-code a swap entry */
@@ -464,6 +464,7 @@ static inline int ptep_test_and_clear_dirty(struct vm_area_struct *vma, unsigned
464 464
465extern spinlock_t pa_dbit_lock; 465extern spinlock_t pa_dbit_lock;
466 466
467struct mm_struct;
467static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) 468static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
468{ 469{
469 pte_t old_pte; 470 pte_t old_pte;
diff --git a/include/asm-powerpc/elf.h b/include/asm-powerpc/elf.h
index d140577d0a05..feac3458d71f 100644
--- a/include/asm-powerpc/elf.h
+++ b/include/asm-powerpc/elf.h
@@ -1,11 +1,13 @@
1#ifndef _ASM_POWERPC_ELF_H 1#ifndef _ASM_POWERPC_ELF_H
2#define _ASM_POWERPC_ELF_H 2#define _ASM_POWERPC_ELF_H
3 3
4#include <linux/sched.h> /* for task_struct */
4#include <asm/types.h> 5#include <asm/types.h>
5#include <asm/ptrace.h> 6#include <asm/ptrace.h>
6#include <asm/cputable.h> 7#include <asm/cputable.h>
7#include <asm/auxvec.h> 8#include <asm/auxvec.h>
8#include <asm/page.h> 9#include <asm/page.h>
10#include <asm/string.h>
9 11
10/* PowerPC relocations defined by the ABIs */ 12/* PowerPC relocations defined by the ABIs */
11#define R_PPC_NONE 0 13#define R_PPC_NONE 0
diff --git a/include/asm-powerpc/kprobes.h b/include/asm-powerpc/kprobes.h
index b2f09f17fbe0..6cd0a3bfa280 100644
--- a/include/asm-powerpc/kprobes.h
+++ b/include/asm-powerpc/kprobes.h
@@ -27,6 +27,7 @@
27 */ 27 */
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/ptrace.h> 29#include <linux/ptrace.h>
30#include <linux/percpu.h>
30 31
31struct pt_regs; 32struct pt_regs;
32 33
@@ -53,6 +54,20 @@ struct arch_specific_insn {
53 kprobe_opcode_t *insn; 54 kprobe_opcode_t *insn;
54}; 55};
55 56
57struct prev_kprobe {
58 struct kprobe *kp;
59 unsigned long status;
60 unsigned long saved_msr;
61};
62
63/* per-cpu kprobe control block */
64struct kprobe_ctlblk {
65 unsigned long kprobe_status;
66 unsigned long kprobe_saved_msr;
67 struct pt_regs jprobe_saved_regs;
68 struct prev_kprobe prev_kprobe;
69};
70
56#ifdef CONFIG_KPROBES 71#ifdef CONFIG_KPROBES
57extern int kprobe_exceptions_notify(struct notifier_block *self, 72extern int kprobe_exceptions_notify(struct notifier_block *self,
58 unsigned long val, void *data); 73 unsigned long val, void *data);
diff --git a/include/asm-ppc/ibm44x.h b/include/asm-ppc/ibm44x.h
index e5374be86aef..f835066fb3ca 100644
--- a/include/asm-ppc/ibm44x.h
+++ b/include/asm-ppc/ibm44x.h
@@ -34,12 +34,20 @@
34/* Lowest TLB slot consumed by the default pinned TLBs */ 34/* Lowest TLB slot consumed by the default pinned TLBs */
35#define PPC44x_LOW_SLOT 63 35#define PPC44x_LOW_SLOT 63
36 36
37/* LS 32-bits of UART0 physical address location for early serial text debug */ 37/*
38 * Least significant 32-bits and extended real page number (ERPN) of
39 * UART0 physical address location for early serial text debug
40 */
38#if defined(CONFIG_440SP) 41#if defined(CONFIG_440SP)
42#define UART0_PHYS_ERPN 1
43#define UART0_PHYS_IO_BASE 0xf0000200
44#elif defined(CONFIG_440SPE)
45#define UART0_PHYS_ERPN 4
39#define UART0_PHYS_IO_BASE 0xf0000200 46#define UART0_PHYS_IO_BASE 0xf0000200
40#elif defined(CONFIG_440EP) 47#elif defined(CONFIG_440EP)
41#define UART0_PHYS_IO_BASE 0xe0000000 48#define UART0_PHYS_IO_BASE 0xe0000000
42#else 49#else
50#define UART0_PHYS_ERPN 1
43#define UART0_PHYS_IO_BASE 0x40000200 51#define UART0_PHYS_IO_BASE 0x40000200
44#endif 52#endif
45 53
@@ -56,6 +64,11 @@
56#define PPC44x_PCICFG_PAGE 0x0000000900000000ULL 64#define PPC44x_PCICFG_PAGE 0x0000000900000000ULL
57#define PPC44x_PCIIO_PAGE PPC44x_PCICFG_PAGE 65#define PPC44x_PCIIO_PAGE PPC44x_PCICFG_PAGE
58#define PPC44x_PCIMEM_PAGE 0x0000000a00000000ULL 66#define PPC44x_PCIMEM_PAGE 0x0000000a00000000ULL
67#elif defined(CONFIG_440SPE)
68#define PPC44x_IO_PAGE 0x0000000400000000ULL
69#define PPC44x_PCICFG_PAGE 0x0000000c00000000ULL
70#define PPC44x_PCIIO_PAGE PPC44x_PCICFG_PAGE
71#define PPC44x_PCIMEM_PAGE 0x0000000d00000000ULL
59#elif defined(CONFIG_440EP) 72#elif defined(CONFIG_440EP)
60#define PPC44x_IO_PAGE 0x0000000000000000ULL 73#define PPC44x_IO_PAGE 0x0000000000000000ULL
61#define PPC44x_PCICFG_PAGE 0x0000000000000000ULL 74#define PPC44x_PCICFG_PAGE 0x0000000000000000ULL
@@ -71,7 +84,7 @@
71/* 84/*
72 * 36-bit trap ranges 85 * 36-bit trap ranges
73 */ 86 */
74#if defined(CONFIG_440SP) 87#if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
75#define PPC44x_IO_LO 0xf0000000UL 88#define PPC44x_IO_LO 0xf0000000UL
76#define PPC44x_IO_HI 0xf0000fffUL 89#define PPC44x_IO_HI 0xf0000fffUL
77#define PPC44x_PCI0CFG_LO 0x0ec00000UL 90#define PPC44x_PCI0CFG_LO 0x0ec00000UL
@@ -109,7 +122,7 @@
109 */ 122 */
110 123
111 124
112/* CPRs (440GX and 440SP) */ 125/* CPRs (440GX and 440SP/440SPe) */
113#define DCRN_CPR_CONFIG_ADDR 0xc 126#define DCRN_CPR_CONFIG_ADDR 0xc
114#define DCRN_CPR_CONFIG_DATA 0xd 127#define DCRN_CPR_CONFIG_DATA 0xd
115 128
@@ -130,7 +143,7 @@
130 mtdcr(DCRN_CPR_CONFIG_ADDR, offset); \ 143 mtdcr(DCRN_CPR_CONFIG_ADDR, offset); \
131 mtdcr(DCRN_CPR_CONFIG_DATA, data);}) 144 mtdcr(DCRN_CPR_CONFIG_DATA, data);})
132 145
133/* SDRs (440GX and 440SP) */ 146/* SDRs (440GX and 440SP/440SPe) */
134#define DCRN_SDR_CONFIG_ADDR 0xe 147#define DCRN_SDR_CONFIG_ADDR 0xe
135#define DCRN_SDR_CONFIG_DATA 0xf 148#define DCRN_SDR_CONFIG_DATA 0xf
136#define DCRN_SDR_PFC0 0x4100 149#define DCRN_SDR_PFC0 0x4100
@@ -180,7 +193,7 @@
180 mtdcr(DCRN_SDR_CONFIG_ADDR, offset); \ 193 mtdcr(DCRN_SDR_CONFIG_ADDR, offset); \
181 mtdcr(DCRN_SDR_CONFIG_DATA,data);}) 194 mtdcr(DCRN_SDR_CONFIG_DATA,data);})
182 195
183/* DMA (excluding 440SP) */ 196/* DMA (excluding 440SP/440SPe) */
184#define DCRN_DMA0_BASE 0x100 197#define DCRN_DMA0_BASE 0x100
185#define DCRN_DMA1_BASE 0x108 198#define DCRN_DMA1_BASE 0x108
186#define DCRN_DMA2_BASE 0x110 199#define DCRN_DMA2_BASE 0x110
@@ -200,12 +213,20 @@
200/* UIC */ 213/* UIC */
201#define DCRN_UIC0_BASE 0xc0 214#define DCRN_UIC0_BASE 0xc0
202#define DCRN_UIC1_BASE 0xd0 215#define DCRN_UIC1_BASE 0xd0
203#define DCRN_UIC2_BASE 0x210
204#define DCRN_UICB_BASE 0x200
205#define UIC0 DCRN_UIC0_BASE 216#define UIC0 DCRN_UIC0_BASE
206#define UIC1 DCRN_UIC1_BASE 217#define UIC1 DCRN_UIC1_BASE
218
219#ifdef CONFIG_440SPE
220#define DCRN_UIC2_BASE 0xe0
221#define DCRN_UIC3_BASE 0xf0
222#define UIC2 DCRN_UIC2_BASE
223#define UIC3 DCRN_UIC3_BASE
224#else
225#define DCRN_UIC2_BASE 0x210
226#define DCRN_UICB_BASE 0x200
207#define UIC2 DCRN_UIC2_BASE 227#define UIC2 DCRN_UIC2_BASE
208#define UICB DCRN_UICB_BASE 228#define UICB DCRN_UICB_BASE
229#endif
209 230
210#define DCRN_UIC_SR(base) (base + 0x0) 231#define DCRN_UIC_SR(base) (base + 0x0)
211#define DCRN_UIC_ER(base) (base + 0x2) 232#define DCRN_UIC_ER(base) (base + 0x2)
@@ -218,6 +239,12 @@
218 239
219#define UIC0_UIC1NC 0x00000002 240#define UIC0_UIC1NC 0x00000002
220 241
242#ifdef CONFIG_440SPE
243#define UIC0_UIC1NC 0x00000002
244#define UIC0_UIC2NC 0x00200000
245#define UIC0_UIC3NC 0x00008000
246#endif
247
221#define UICB_UIC0NC 0x40000000 248#define UICB_UIC0NC 0x40000000
222#define UICB_UIC1NC 0x10000000 249#define UICB_UIC1NC 0x10000000
223#define UICB_UIC2NC 0x04000000 250#define UICB_UIC2NC 0x04000000
@@ -297,6 +324,23 @@
297#define MALOBISR_CH0 0x80000000 /* EOB channel 1 bit */ 324#define MALOBISR_CH0 0x80000000 /* EOB channel 1 bit */
298#define MALOBISR_CH2 0x40000000 /* EOB channel 2 bit */ 325#define MALOBISR_CH2 0x40000000 /* EOB channel 2 bit */
299 326
327#if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
328/* 440SP/440SPe PLB Arbiter DCRs */
329#define DCRN_PLB_REVID 0x080 /* PLB Revision ID */
330#define DCRN_PLB_CCR 0x088 /* PLB Crossbar Control */
331
332#define DCRN_PLB0_ACR 0x081 /* PLB Arbiter Control */
333#define DCRN_PLB0_BESRL 0x082 /* PLB Error Status */
334#define DCRN_PLB0_BESRH 0x083 /* PLB Error Status */
335#define DCRN_PLB0_BEARL 0x084 /* PLB Error Address Low */
336#define DCRN_PLB0_BEARH 0x085 /* PLB Error Address High */
337
338#define DCRN_PLB1_ACR 0x089 /* PLB Arbiter Control */
339#define DCRN_PLB1_BESRL 0x08a /* PLB Error Status */
340#define DCRN_PLB1_BESRH 0x08b /* PLB Error Status */
341#define DCRN_PLB1_BEARL 0x08c /* PLB Error Address Low */
342#define DCRN_PLB1_BEARH 0x08d /* PLB Error Address High */
343#else
300/* 440GP/GX PLB Arbiter DCRs */ 344/* 440GP/GX PLB Arbiter DCRs */
301#define DCRN_PLB0_REVID 0x082 /* PLB Arbiter Revision ID */ 345#define DCRN_PLB0_REVID 0x082 /* PLB Arbiter Revision ID */
302#define DCRN_PLB0_ACR 0x083 /* PLB Arbiter Control */ 346#define DCRN_PLB0_ACR 0x083 /* PLB Arbiter Control */
@@ -304,6 +348,7 @@
304#define DCRN_PLB0_BEARL 0x086 /* PLB Error Address Low */ 348#define DCRN_PLB0_BEARL 0x086 /* PLB Error Address Low */
305#define DCRN_PLB0_BEAR DCRN_PLB0_BEARL /* 40x compatibility */ 349#define DCRN_PLB0_BEAR DCRN_PLB0_BEARL /* 40x compatibility */
306#define DCRN_PLB0_BEARH 0x087 /* PLB Error Address High */ 350#define DCRN_PLB0_BEARH 0x087 /* PLB Error Address High */
351#endif
307 352
308/* 440GP/GX PLB to OPB bridge DCRs */ 353/* 440GP/GX PLB to OPB bridge DCRs */
309#define DCRN_POB0_BESR0 0x090 354#define DCRN_POB0_BESR0 0x090
@@ -407,9 +452,13 @@
407#define PPC44x_MEM_SIZE_1G 0x40000000 452#define PPC44x_MEM_SIZE_1G 0x40000000
408#define PPC44x_MEM_SIZE_2G 0x80000000 453#define PPC44x_MEM_SIZE_2G 0x80000000
409 454
410/* 440SP memory controller DCRs */ 455/* 440SP/440SPe memory controller DCRs */
411#define DCRN_MQ0_BS0BAS 0x40 456#define DCRN_MQ0_BS0BAS 0x40
412#define DCRN_MQ0_BS1BAS 0x41 457#if defined(CONFIG_440SP)
458#define MQ0_NUM_BANKS 2
459#elif defined(CONFIG_440SPE)
460#define MQ0_NUM_BANKS 4
461#endif
413 462
414#define MQ0_CONFIG_SIZE_MASK 0x0000fff0 463#define MQ0_CONFIG_SIZE_MASK 0x0000fff0
415#define MQ0_CONFIG_SIZE_8M 0x0000ffc0 464#define MQ0_CONFIG_SIZE_8M 0x0000ffc0
@@ -421,8 +470,9 @@
421#define MQ0_CONFIG_SIZE_512M 0x0000f000 470#define MQ0_CONFIG_SIZE_512M 0x0000f000
422#define MQ0_CONFIG_SIZE_1G 0x0000e000 471#define MQ0_CONFIG_SIZE_1G 0x0000e000
423#define MQ0_CONFIG_SIZE_2G 0x0000c000 472#define MQ0_CONFIG_SIZE_2G 0x0000c000
473#define MQ0_CONFIG_SIZE_4G 0x00008000
424 474
425/* Internal SRAM Controller 440GX/440SP */ 475/* Internal SRAM Controller 440GX/440SP/440SPe */
426#define DCRN_SRAM0_BASE 0x000 476#define DCRN_SRAM0_BASE 0x000
427 477
428#define DCRN_SRAM0_SB0CR (DCRN_SRAM0_BASE + 0x020) 478#define DCRN_SRAM0_SB0CR (DCRN_SRAM0_BASE + 0x020)
@@ -446,7 +496,7 @@
446#define DCRN_SRAM0_DPC (DCRN_SRAM0_BASE + 0x02a) 496#define DCRN_SRAM0_DPC (DCRN_SRAM0_BASE + 0x02a)
447#define SRAM_DPC_ENABLE 0x80000000 497#define SRAM_DPC_ENABLE 0x80000000
448 498
449/* L2 Cache Controller 440GX/440SP */ 499/* L2 Cache Controller 440GX/440SP/440SPe */
450#define DCRN_L2C0_CFG 0x030 500#define DCRN_L2C0_CFG 0x030
451#define L2C_CFG_L2M 0x80000000 501#define L2C_CFG_L2M 0x80000000
452#define L2C_CFG_ICU 0x40000000 502#define L2C_CFG_ICU 0x40000000
@@ -610,8 +660,10 @@
610#define IIC_CLOCK 50 660#define IIC_CLOCK 50
611 661
612#undef NR_UICS 662#undef NR_UICS
613#ifdef CONFIG_440GX 663#if defined(CONFIG_440GX)
614#define NR_UICS 3 664#define NR_UICS 3
665#elif defined(CONFIG_440SPE)
666#define NR_UICS 4
615#else 667#else
616#define NR_UICS 2 668#define NR_UICS 2
617#endif 669#endif
diff --git a/include/asm-ppc/ibm4xx.h b/include/asm-ppc/ibm4xx.h
index e992369cb8e9..6c28ae7807f4 100644
--- a/include/asm-ppc/ibm4xx.h
+++ b/include/asm-ppc/ibm4xx.h
@@ -97,6 +97,10 @@ void ppc4xx_init(unsigned long r3, unsigned long r4, unsigned long r5,
97#include <platforms/4xx/luan.h> 97#include <platforms/4xx/luan.h>
98#endif 98#endif
99 99
100#if defined(CONFIG_YUCCA)
101#include <platforms/4xx/yucca.h>
102#endif
103
100#if defined(CONFIG_OCOTEA) 104#if defined(CONFIG_OCOTEA)
101#include <platforms/4xx/ocotea.h> 105#include <platforms/4xx/ocotea.h>
102#endif 106#endif
diff --git a/include/asm-ppc/ibm_ocp.h b/include/asm-ppc/ibm_ocp.h
index 6f10a25bd628..9c21de1ff4ed 100644
--- a/include/asm-ppc/ibm_ocp.h
+++ b/include/asm-ppc/ibm_ocp.h
@@ -131,9 +131,22 @@ static inline void ibm_ocp_set_emac(int start, int end)
131 /* Copy MAC addresses to EMAC additions */ 131 /* Copy MAC addresses to EMAC additions */
132 for (i=start; i<=end; i++) { 132 for (i=start; i<=end; i++) {
133 def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, i); 133 def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, i);
134 memcpy(((struct ocp_func_emac_data *)def->additions)->mac_addr, 134 if (i == 0)
135 &__res.bi_enetaddr[i], 135 memcpy(((struct ocp_func_emac_data *)def->additions)->mac_addr,
136 6); 136 __res.bi_enetaddr, 6);
137#if defined(CONFIG_405EP) || defined(CONFIG_44x)
138 else if (i == 1)
139 memcpy(((struct ocp_func_emac_data *)def->additions)->mac_addr,
140 __res.bi_enet1addr, 6);
141#endif
142#if defined(CONFIG_440GX)
143 else if (i == 2)
144 memcpy(((struct ocp_func_emac_data *)def->additions)->mac_addr,
145 __res.bi_enet2addr, 6);
146 else if (i == 3)
147 memcpy(((struct ocp_func_emac_data *)def->additions)->mac_addr,
148 __res.bi_enet3addr, 6);
149#endif
137 } 150 }
138} 151}
139#endif 152#endif
diff --git a/include/asm-ppc/pgtable.h b/include/asm-ppc/pgtable.h
index b28a713ba862..6d1c39e8a6af 100644
--- a/include/asm-ppc/pgtable.h
+++ b/include/asm-ppc/pgtable.h
@@ -12,6 +12,7 @@
12#include <asm/processor.h> /* For TASK_SIZE */ 12#include <asm/processor.h> /* For TASK_SIZE */
13#include <asm/mmu.h> 13#include <asm/mmu.h>
14#include <asm/page.h> 14#include <asm/page.h>
15struct mm_struct;
15 16
16extern unsigned long va_to_phys(unsigned long address); 17extern unsigned long va_to_phys(unsigned long address);
17extern pte_t *va_to_pte(unsigned long address); 18extern pte_t *va_to_pte(unsigned long address);
diff --git a/include/asm-ppc/ppcboot.h b/include/asm-ppc/ppcboot.h
index fe24e4520208..6b7b63f71daa 100644
--- a/include/asm-ppc/ppcboot.h
+++ b/include/asm-ppc/ppcboot.h
@@ -73,8 +73,8 @@ typedef struct bd_info {
73#if defined(CONFIG_HYMOD) 73#if defined(CONFIG_HYMOD)
74 hymod_conf_t bi_hymod_conf; /* hymod configuration information */ 74 hymod_conf_t bi_hymod_conf; /* hymod configuration information */
75#endif 75#endif
76#if defined(CONFIG_EVB64260) || defined(CONFIG_44x) || defined(CONFIG_85xx) ||\ 76#if defined(CONFIG_EVB64260) || defined(CONFIG_405EP) || defined(CONFIG_44x) || \
77 defined(CONFIG_83xx) 77 defined(CONFIG_85xx) || defined(CONFIG_83xx)
78 /* second onboard ethernet port */ 78 /* second onboard ethernet port */
79 unsigned char bi_enet1addr[6]; 79 unsigned char bi_enet1addr[6];
80#endif 80#endif
@@ -96,5 +96,7 @@ typedef struct bd_info {
96#endif 96#endif
97} bd_t; 97} bd_t;
98 98
99#define bi_tbfreq bi_intfreq
100
99#endif /* __ASSEMBLY__ */ 101#endif /* __ASSEMBLY__ */
100#endif /* __ASM_PPCBOOT_H__ */ 102#endif /* __ASM_PPCBOOT_H__ */
diff --git a/include/asm-ppc/rio.h b/include/asm-ppc/rio.h
new file mode 100644
index 000000000000..0018bf80cb25
--- /dev/null
+++ b/include/asm-ppc/rio.h
@@ -0,0 +1,18 @@
1/*
2 * RapidIO architecture support
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#ifndef ASM_PPC_RIO_H
14#define ASM_PPC_RIO_H
15
16extern void platform_rio_init(void);
17
18#endif /* ASM_PPC_RIO_H */
diff --git a/include/asm-ppc64/pgtable-4k.h b/include/asm-ppc64/pgtable-4k.h
index c883a2748558..e9590c06ad92 100644
--- a/include/asm-ppc64/pgtable-4k.h
+++ b/include/asm-ppc64/pgtable-4k.h
@@ -23,6 +23,9 @@
23#define PMD_SIZE (1UL << PMD_SHIFT) 23#define PMD_SIZE (1UL << PMD_SHIFT)
24#define PMD_MASK (~(PMD_SIZE-1)) 24#define PMD_MASK (~(PMD_SIZE-1))
25 25
26/* With 4k base page size, hugepage PTEs go at the PMD level */
27#define MIN_HUGEPTE_SHIFT PMD_SHIFT
28
26/* PUD_SHIFT determines what a third-level page table entry can map */ 29/* PUD_SHIFT determines what a third-level page table entry can map */
27#define PUD_SHIFT (PMD_SHIFT + PMD_INDEX_SIZE) 30#define PUD_SHIFT (PMD_SHIFT + PMD_INDEX_SIZE)
28#define PUD_SIZE (1UL << PUD_SHIFT) 31#define PUD_SIZE (1UL << PUD_SHIFT)
diff --git a/include/asm-ppc64/pgtable-64k.h b/include/asm-ppc64/pgtable-64k.h
index c5f437c86b3c..154f1840ece4 100644
--- a/include/asm-ppc64/pgtable-64k.h
+++ b/include/asm-ppc64/pgtable-64k.h
@@ -14,6 +14,9 @@
14#define PTRS_PER_PMD (1 << PMD_INDEX_SIZE) 14#define PTRS_PER_PMD (1 << PMD_INDEX_SIZE)
15#define PTRS_PER_PGD (1 << PGD_INDEX_SIZE) 15#define PTRS_PER_PGD (1 << PGD_INDEX_SIZE)
16 16
17/* With 4k base page size, hugepage PTEs go at the PMD level */
18#define MIN_HUGEPTE_SHIFT PAGE_SHIFT
19
17/* PMD_SHIFT determines what a second-level page table entry can map */ 20/* PMD_SHIFT determines what a second-level page table entry can map */
18#define PMD_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE) 21#define PMD_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE)
19#define PMD_SIZE (1UL << PMD_SHIFT) 22#define PMD_SIZE (1UL << PMD_SHIFT)
diff --git a/include/asm-ppc64/pgtable.h b/include/asm-ppc64/pgtable.h
index fde93ec36abc..a9783ba7fe98 100644
--- a/include/asm-ppc64/pgtable.h
+++ b/include/asm-ppc64/pgtable.h
@@ -13,6 +13,7 @@
13#include <asm/mmu.h> 13#include <asm/mmu.h>
14#include <asm/page.h> 14#include <asm/page.h>
15#include <asm/tlbflush.h> 15#include <asm/tlbflush.h>
16struct mm_struct;
16#endif /* __ASSEMBLY__ */ 17#endif /* __ASSEMBLY__ */
17 18
18#ifdef CONFIG_PPC_64K_PAGES 19#ifdef CONFIG_PPC_64K_PAGES
diff --git a/include/asm-s390/bitops.h b/include/asm-s390/bitops.h
index 8651524217fd..b07c578b22ea 100644
--- a/include/asm-s390/bitops.h
+++ b/include/asm-s390/bitops.h
@@ -518,8 +518,8 @@ static inline int __test_bit(unsigned long nr, const volatile unsigned long *ptr
518 518
519static inline int 519static inline int
520__constant_test_bit(unsigned long nr, const volatile unsigned long *addr) { 520__constant_test_bit(unsigned long nr, const volatile unsigned long *addr) {
521 return (((volatile char *) addr) 521 return ((((volatile char *) addr)
522 [(nr^(__BITOPS_WORDSIZE-8))>>3] & (1<<(nr&7))); 522 [(nr^(__BITOPS_WORDSIZE-8))>>3] & (1<<(nr&7)))) != 0;
523} 523}
524 524
525#define test_bit(nr,addr) \ 525#define test_bit(nr,addr) \
diff --git a/include/asm-s390/elf.h b/include/asm-s390/elf.h
index 3b8bd46832a1..372d51cccd53 100644
--- a/include/asm-s390/elf.h
+++ b/include/asm-s390/elf.h
@@ -96,6 +96,7 @@
96 * ELF register definitions.. 96 * ELF register definitions..
97 */ 97 */
98 98
99#include <linux/sched.h> /* for task_struct */
99#include <asm/ptrace.h> 100#include <asm/ptrace.h>
100#include <asm/user.h> 101#include <asm/user.h>
101#include <asm/system.h> /* for save_access_regs */ 102#include <asm/system.h> /* for save_access_regs */
diff --git a/include/asm-s390/pgtable.h b/include/asm-s390/pgtable.h
index df94f89038cc..9be741bb1496 100644
--- a/include/asm-s390/pgtable.h
+++ b/include/asm-s390/pgtable.h
@@ -36,6 +36,7 @@
36#include <linux/threads.h> 36#include <linux/threads.h>
37 37
38struct vm_area_struct; /* forward declaration (include/linux/mm.h) */ 38struct vm_area_struct; /* forward declaration (include/linux/mm.h) */
39struct mm_struct;
39 40
40extern pgd_t swapper_pg_dir[] __attribute__ ((aligned (4096))); 41extern pgd_t swapper_pg_dir[] __attribute__ ((aligned (4096)));
41extern void paging_init(void); 42extern void paging_init(void);
diff --git a/include/asm-s390/ptrace.h b/include/asm-s390/ptrace.h
index fc7c96edc697..a949cc077cc7 100644
--- a/include/asm-s390/ptrace.h
+++ b/include/asm-s390/ptrace.h
@@ -468,6 +468,8 @@ struct user_regs_struct
468}; 468};
469 469
470#ifdef __KERNEL__ 470#ifdef __KERNEL__
471#define __ARCH_SYS_PTRACE 1
472
471#define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0) 473#define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0)
472#define instruction_pointer(regs) ((regs)->psw.addr & PSW_ADDR_INSN) 474#define instruction_pointer(regs) ((regs)->psw.addr & PSW_ADDR_INSN)
473#define profile_pc(regs) instruction_pointer(regs) 475#define profile_pc(regs) instruction_pointer(regs)
diff --git a/include/asm-s390/uaccess.h b/include/asm-s390/uaccess.h
index 38a5cf8ab9e3..10a619da4761 100644
--- a/include/asm-s390/uaccess.h
+++ b/include/asm-s390/uaccess.h
@@ -200,21 +200,37 @@ extern int __put_user_bad(void) __attribute__((noreturn));
200 200
201#define __get_user(x, ptr) \ 201#define __get_user(x, ptr) \
202({ \ 202({ \
203 __typeof__(*(ptr)) __x; \
204 int __gu_err; \ 203 int __gu_err; \
205 __chk_user_ptr(ptr); \ 204 __chk_user_ptr(ptr); \
206 switch (sizeof(*(ptr))) { \ 205 switch (sizeof(*(ptr))) { \
207 case 1: \ 206 case 1: { \
208 case 2: \ 207 unsigned char __x; \
209 case 4: \ 208 __get_user_asm(__x, ptr, __gu_err); \
210 case 8: \ 209 (x) = (__typeof__(*(ptr))) __x; \
210 break; \
211 }; \
212 case 2: { \
213 unsigned short __x; \
214 __get_user_asm(__x, ptr, __gu_err); \
215 (x) = (__typeof__(*(ptr))) __x; \
216 break; \
217 }; \
218 case 4: { \
219 unsigned int __x; \
220 __get_user_asm(__x, ptr, __gu_err); \
221 (x) = (__typeof__(*(ptr))) __x; \
222 break; \
223 }; \
224 case 8: { \
225 unsigned long long __x; \
211 __get_user_asm(__x, ptr, __gu_err); \ 226 __get_user_asm(__x, ptr, __gu_err); \
227 (x) = (__typeof__(*(ptr))) __x; \
212 break; \ 228 break; \
229 }; \
213 default: \ 230 default: \
214 __get_user_bad(); \ 231 __get_user_bad(); \
215 break; \ 232 break; \
216 } \ 233 } \
217 (x) = __x; \
218 __gu_err; \ 234 __gu_err; \
219}) 235})
220 236
diff --git a/include/asm-s390/vtoc.h b/include/asm-s390/vtoc.h
index a14e34e80b88..41d369f38b0e 100644
--- a/include/asm-s390/vtoc.h
+++ b/include/asm-s390/vtoc.h
@@ -1,372 +1,179 @@
1#ifndef __KERNEL__ 1/*
2#include <string.h> 2 * include/asm-s390/vtoc.h
3#include <stdlib.h> 3 *
4#include <stdio.h> 4 * This file contains volume label definitions for DASD devices.
5#include <errno.h> 5 *
6#include <ctype.h> 6 * (C) Copyright IBM Corp. 2005
7#include <time.h> 7 *
8#include <fcntl.h> 8 * Author(s): Volker Sameske <sameske@de.ibm.com>
9#include <unistd.h> 9 *
10 */
11
12#ifndef _ASM_S390_VTOC_H
13#define _ASM_S390_VTOC_H
10 14
11#include <sys/stat.h>
12#include <sys/ioctl.h>
13
14#include <linux/fs.h>
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/hdreg.h>
17#include <asm/dasd.h>
18#endif
19
20
21#define LINE_LENGTH 80
22#define VTOC_START_CC 0x0
23#define VTOC_START_HH 0x1
24#define FIRST_USABLE_CYL 1
25#define FIRST_USABLE_TRK 2
26
27#define DASD_3380_TYPE 13148
28#define DASD_3390_TYPE 13200
29#define DASD_9345_TYPE 37701
30
31#define DASD_3380_VALUE 0xbb60
32#define DASD_3390_VALUE 0xe5a2
33#define DASD_9345_VALUE 0xbc98
34
35#define VOLSER_LENGTH 6
36#define BIG_DISK_SIZE 0x10000
37
38#define VTOC_ERROR "VTOC error:"
39
40 16
41typedef struct ttr 17struct vtoc_ttr
42{ 18{
43 __u16 tt; 19 __u16 tt;
44 __u8 r; 20 __u8 r;
45} __attribute__ ((packed)) ttr_t; 21} __attribute__ ((packed));
46 22
47typedef struct cchhb 23struct vtoc_cchhb
48{ 24{
49 __u16 cc; 25 __u16 cc;
50 __u16 hh; 26 __u16 hh;
51 __u8 b; 27 __u8 b;
52} __attribute__ ((packed)) cchhb_t; 28} __attribute__ ((packed));
53 29
54typedef struct cchh 30struct vtoc_cchh
55{ 31{
56 __u16 cc; 32 __u16 cc;
57 __u16 hh; 33 __u16 hh;
58} __attribute__ ((packed)) cchh_t; 34} __attribute__ ((packed));
59 35
60typedef struct labeldate 36struct vtoc_labeldate
61{ 37{
62 __u8 year; 38 __u8 year;
63 __u16 day; 39 __u16 day;
64} __attribute__ ((packed)) labeldate_t; 40} __attribute__ ((packed));
65 41
66 42struct vtoc_volume_label
67typedef struct volume_label
68{ 43{
69 char volkey[4]; /* volume key = volume label */ 44 char volkey[4]; /* volume key = volume label */
70 char vollbl[4]; /* volume label */ 45 char vollbl[4]; /* volume label */
71 char volid[6]; /* volume identifier */ 46 char volid[6]; /* volume identifier */
72 __u8 security; /* security byte */ 47 __u8 security; /* security byte */
73 cchhb_t vtoc; /* VTOC address */ 48 struct vtoc_cchhb vtoc; /* VTOC address */
74 char res1[5]; /* reserved */ 49 char res1[5]; /* reserved */
75 char cisize[4]; /* CI-size for FBA,... */ 50 char cisize[4]; /* CI-size for FBA,... */
76 /* ...blanks for CKD */ 51 /* ...blanks for CKD */
77 char blkperci[4]; /* no of blocks per CI (FBA), blanks for CKD */ 52 char blkperci[4]; /* no of blocks per CI (FBA), blanks for CKD */
78 char labperci[4]; /* no of labels per CI (FBA), blanks for CKD */ 53 char labperci[4]; /* no of labels per CI (FBA), blanks for CKD */
79 char res2[4]; /* reserved */ 54 char res2[4]; /* reserved */
80 char lvtoc[14]; /* owner code for LVTOC */ 55 char lvtoc[14]; /* owner code for LVTOC */
81 char res3[29]; /* reserved */ 56 char res3[29]; /* reserved */
82} __attribute__ ((packed)) volume_label_t; 57} __attribute__ ((packed));
83 58
84 59struct vtoc_extent
85typedef struct extent
86{ 60{
87 __u8 typeind; /* extent type indicator */ 61 __u8 typeind; /* extent type indicator */
88 __u8 seqno; /* extent sequence number */ 62 __u8 seqno; /* extent sequence number */
89 cchh_t llimit; /* starting point of this extent */ 63 struct vtoc_cchh llimit; /* starting point of this extent */
90 cchh_t ulimit; /* ending point of this extent */ 64 struct vtoc_cchh ulimit; /* ending point of this extent */
91} __attribute__ ((packed)) extent_t; 65} __attribute__ ((packed));
92
93 66
94typedef struct dev_const 67struct vtoc_dev_const
95{ 68{
96 __u16 DS4DSCYL; /* number of logical cyls */ 69 __u16 DS4DSCYL; /* number of logical cyls */
97 __u16 DS4DSTRK; /* number of tracks in a logical cylinder */ 70 __u16 DS4DSTRK; /* number of tracks in a logical cylinder */
98 __u16 DS4DEVTK; /* device track length */ 71 __u16 DS4DEVTK; /* device track length */
99 __u8 DS4DEVI; /* non-last keyed record overhead */ 72 __u8 DS4DEVI; /* non-last keyed record overhead */
100 __u8 DS4DEVL; /* last keyed record overhead */ 73 __u8 DS4DEVL; /* last keyed record overhead */
101 __u8 DS4DEVK; /* non-keyed record overhead differential */ 74 __u8 DS4DEVK; /* non-keyed record overhead differential */
102 __u8 DS4DEVFG; /* flag byte */ 75 __u8 DS4DEVFG; /* flag byte */
103 __u16 DS4DEVTL; /* device tolerance */ 76 __u16 DS4DEVTL; /* device tolerance */
104 __u8 DS4DEVDT; /* number of DSCB's per track */ 77 __u8 DS4DEVDT; /* number of DSCB's per track */
105 __u8 DS4DEVDB; /* number of directory blocks per track */ 78 __u8 DS4DEVDB; /* number of directory blocks per track */
106} __attribute__ ((packed)) dev_const_t; 79} __attribute__ ((packed));
107 80
108 81struct vtoc_format1_label
109typedef struct format1_label
110{ 82{
111 char DS1DSNAM[44]; /* data set name */ 83 char DS1DSNAM[44]; /* data set name */
112 __u8 DS1FMTID; /* format identifier */ 84 __u8 DS1FMTID; /* format identifier */
113 char DS1DSSN[6]; /* data set serial number */ 85 char DS1DSSN[6]; /* data set serial number */
114 __u16 DS1VOLSQ; /* volume sequence number */ 86 __u16 DS1VOLSQ; /* volume sequence number */
115 labeldate_t DS1CREDT; /* creation date: ydd */ 87 struct vtoc_labeldate DS1CREDT; /* creation date: ydd */
116 labeldate_t DS1EXPDT; /* expiration date */ 88 struct vtoc_labeldate DS1EXPDT; /* expiration date */
117 __u8 DS1NOEPV; /* number of extents on volume */ 89 __u8 DS1NOEPV; /* number of extents on volume */
118 __u8 DS1NOBDB; /* no. of bytes used in last direction blk */ 90 __u8 DS1NOBDB; /* no. of bytes used in last direction blk */
119 __u8 DS1FLAG1; /* flag 1 */ 91 __u8 DS1FLAG1; /* flag 1 */
120 char DS1SYSCD[13]; /* system code */ 92 char DS1SYSCD[13]; /* system code */
121 labeldate_t DS1REFD; /* date last referenced */ 93 struct vtoc_labeldate DS1REFD; /* date last referenced */
122 __u8 DS1SMSFG; /* system managed storage indicators */ 94 __u8 DS1SMSFG; /* system managed storage indicators */
123 __u8 DS1SCXTF; /* sec. space extension flag byte */ 95 __u8 DS1SCXTF; /* sec. space extension flag byte */
124 __u16 DS1SCXTV; /* secondary space extension value */ 96 __u16 DS1SCXTV; /* secondary space extension value */
125 __u8 DS1DSRG1; /* data set organisation byte 1 */ 97 __u8 DS1DSRG1; /* data set organisation byte 1 */
126 __u8 DS1DSRG2; /* data set organisation byte 2 */ 98 __u8 DS1DSRG2; /* data set organisation byte 2 */
127 __u8 DS1RECFM; /* record format */ 99 __u8 DS1RECFM; /* record format */
128 __u8 DS1OPTCD; /* option code */ 100 __u8 DS1OPTCD; /* option code */
129 __u16 DS1BLKL; /* block length */ 101 __u16 DS1BLKL; /* block length */
130 __u16 DS1LRECL; /* record length */ 102 __u16 DS1LRECL; /* record length */
131 __u8 DS1KEYL; /* key length */ 103 __u8 DS1KEYL; /* key length */
132 __u16 DS1RKP; /* relative key position */ 104 __u16 DS1RKP; /* relative key position */
133 __u8 DS1DSIND; /* data set indicators */ 105 __u8 DS1DSIND; /* data set indicators */
134 __u8 DS1SCAL1; /* secondary allocation flag byte */ 106 __u8 DS1SCAL1; /* secondary allocation flag byte */
135 char DS1SCAL3[3]; /* secondary allocation quantity */ 107 char DS1SCAL3[3]; /* secondary allocation quantity */
136 ttr_t DS1LSTAR; /* last used track and block on track */ 108 struct vtoc_ttr DS1LSTAR; /* last used track and block on track */
137 __u16 DS1TRBAL; /* space remaining on last used track */ 109 __u16 DS1TRBAL; /* space remaining on last used track */
138 __u16 res1; /* reserved */ 110 __u16 res1; /* reserved */
139 extent_t DS1EXT1; /* first extent description */ 111 struct vtoc_extent DS1EXT1; /* first extent description */
140 extent_t DS1EXT2; /* second extent description */ 112 struct vtoc_extent DS1EXT2; /* second extent description */
141 extent_t DS1EXT3; /* third extent description */ 113 struct vtoc_extent DS1EXT3; /* third extent description */
142 cchhb_t DS1PTRDS; /* possible pointer to f2 or f3 DSCB */ 114 struct vtoc_cchhb DS1PTRDS; /* possible pointer to f2 or f3 DSCB */
143} __attribute__ ((packed)) format1_label_t; 115} __attribute__ ((packed));
144 116
145 117struct vtoc_format4_label
146typedef struct format4_label
147{ 118{
148 char DS4KEYCD[44]; /* key code for VTOC labels: 44 times 0x04 */ 119 char DS4KEYCD[44]; /* key code for VTOC labels: 44 times 0x04 */
149 __u8 DS4IDFMT; /* format identifier */ 120 __u8 DS4IDFMT; /* format identifier */
150 cchhb_t DS4HPCHR; /* highest address of a format 1 DSCB */ 121 struct vtoc_cchhb DS4HPCHR; /* highest address of a format 1 DSCB */
151 __u16 DS4DSREC; /* number of available DSCB's */ 122 __u16 DS4DSREC; /* number of available DSCB's */
152 cchh_t DS4HCCHH; /* CCHH of next available alternate track */ 123 struct vtoc_cchh DS4HCCHH; /* CCHH of next available alternate track */
153 __u16 DS4NOATK; /* number of remaining alternate tracks */ 124 __u16 DS4NOATK; /* number of remaining alternate tracks */
154 __u8 DS4VTOCI; /* VTOC indicators */ 125 __u8 DS4VTOCI; /* VTOC indicators */
155 __u8 DS4NOEXT; /* number of extents in VTOC */ 126 __u8 DS4NOEXT; /* number of extents in VTOC */
156 __u8 DS4SMSFG; /* system managed storage indicators */ 127 __u8 DS4SMSFG; /* system managed storage indicators */
157 __u8 DS4DEVAC; /* number of alternate cylinders. 128 __u8 DS4DEVAC; /* number of alternate cylinders.
158 Subtract from first two bytes of 129 * Subtract from first two bytes of
159 DS4DEVSZ to get number of usable 130 * DS4DEVSZ to get number of usable
160 cylinders. can be zero. valid 131 * cylinders. can be zero. valid
161 only if DS4DEVAV on. */ 132 * only if DS4DEVAV on. */
162 dev_const_t DS4DEVCT; /* device constants */ 133 struct vtoc_dev_const DS4DEVCT; /* device constants */
163 char DS4AMTIM[8]; /* VSAM time stamp */ 134 char DS4AMTIM[8]; /* VSAM time stamp */
164 char DS4AMCAT[3]; /* VSAM catalog indicator */ 135 char DS4AMCAT[3]; /* VSAM catalog indicator */
165 char DS4R2TIM[8]; /* VSAM volume/catalog match time stamp */ 136 char DS4R2TIM[8]; /* VSAM volume/catalog match time stamp */
166 char res1[5]; /* reserved */ 137 char res1[5]; /* reserved */
167 char DS4F6PTR[5]; /* pointer to first format 6 DSCB */ 138 char DS4F6PTR[5]; /* pointer to first format 6 DSCB */
168 extent_t DS4VTOCE; /* VTOC extent description */ 139 struct vtoc_extent DS4VTOCE; /* VTOC extent description */
169 char res2[10]; /* reserved */ 140 char res2[10]; /* reserved */
170 __u8 DS4EFLVL; /* extended free-space management level */ 141 __u8 DS4EFLVL; /* extended free-space management level */
171 cchhb_t DS4EFPTR; /* pointer to extended free-space info */ 142 struct vtoc_cchhb DS4EFPTR; /* pointer to extended free-space info */
172 char res3[9]; /* reserved */ 143 char res3[9]; /* reserved */
173} __attribute__ ((packed)) format4_label_t; 144} __attribute__ ((packed));
174 145
175 146struct vtoc_ds5ext
176typedef struct ds5ext
177{ 147{
178 __u16 t; /* RTA of the first track of free extent */ 148 __u16 t; /* RTA of the first track of free extent */
179 __u16 fc; /* number of whole cylinders in free ext. */ 149 __u16 fc; /* number of whole cylinders in free ext. */
180 __u8 ft; /* number of remaining free tracks */ 150 __u8 ft; /* number of remaining free tracks */
181} __attribute__ ((packed)) ds5ext_t; 151} __attribute__ ((packed));
182
183 152
184typedef struct format5_label 153struct vtoc_format5_label
185{ 154{
186 char DS5KEYID[4]; /* key identifier */ 155 char DS5KEYID[4]; /* key identifier */
187 ds5ext_t DS5AVEXT; /* first available (free-space) extent. */ 156 struct vtoc_ds5ext DS5AVEXT; /* first available (free-space) extent. */
188 ds5ext_t DS5EXTAV[7]; /* seven available extents */ 157 struct vtoc_ds5ext DS5EXTAV[7]; /* seven available extents */
189 __u8 DS5FMTID; /* format identifier */ 158 __u8 DS5FMTID; /* format identifier */
190 ds5ext_t DS5MAVET[18]; /* eighteen available extents */ 159 struct vtoc_ds5ext DS5MAVET[18]; /* eighteen available extents */
191 cchhb_t DS5PTRDS; /* pointer to next format5 DSCB */ 160 struct vtoc_cchhb DS5PTRDS; /* pointer to next format5 DSCB */
192} __attribute__ ((packed)) format5_label_t; 161} __attribute__ ((packed));
193 162
194 163struct vtoc_ds7ext
195typedef struct ds7ext
196{ 164{
197 __u32 a; /* starting RTA value */ 165 __u32 a; /* starting RTA value */
198 __u32 b; /* ending RTA value + 1 */ 166 __u32 b; /* ending RTA value + 1 */
199} __attribute__ ((packed)) ds7ext_t; 167} __attribute__ ((packed));
200 168
201 169struct vtoc_format7_label
202typedef struct format7_label
203{ 170{
204 char DS7KEYID[4]; /* key identifier */ 171 char DS7KEYID[4]; /* key identifier */
205 ds7ext_t DS7EXTNT[5]; /* space for 5 extent descriptions */ 172 struct vtoc_ds7ext DS7EXTNT[5]; /* space for 5 extent descriptions */
206 __u8 DS7FMTID; /* format identifier */ 173 __u8 DS7FMTID; /* format identifier */
207 ds7ext_t DS7ADEXT[11]; /* space for 11 extent descriptions */ 174 struct vtoc_ds7ext DS7ADEXT[11]; /* space for 11 extent descriptions */
208 char res1[2]; /* reserved */ 175 char res1[2]; /* reserved */
209 cchhb_t DS7PTRDS; /* pointer to next FMT7 DSCB */ 176 struct vtoc_cchhb DS7PTRDS; /* pointer to next FMT7 DSCB */
210} __attribute__ ((packed)) format7_label_t; 177} __attribute__ ((packed));
211 178
212 179#endif /* _ASM_S390_VTOC_H */
213char * vtoc_ebcdic_enc (
214 unsigned char source[LINE_LENGTH],
215 unsigned char target[LINE_LENGTH],
216 int l);
217char * vtoc_ebcdic_dec (
218 unsigned char source[LINE_LENGTH],
219 unsigned char target[LINE_LENGTH],
220 int l);
221void vtoc_set_extent (
222 extent_t * ext,
223 __u8 typeind,
224 __u8 seqno,
225 cchh_t * lower,
226 cchh_t * upper);
227void vtoc_set_cchh (
228 cchh_t * addr,
229 __u16 cc,
230 __u16 hh);
231void vtoc_set_cchhb (
232 cchhb_t * addr,
233 __u16 cc,
234 __u16 hh,
235 __u8 b);
236void vtoc_set_date (
237 labeldate_t * d,
238 __u8 year,
239 __u16 day);
240
241void vtoc_volume_label_init (
242 volume_label_t *vlabel);
243
244int vtoc_read_volume_label (
245 char * device,
246 unsigned long vlabel_start,
247 volume_label_t * vlabel);
248
249int vtoc_write_volume_label (
250 char *device,
251 unsigned long vlabel_start,
252 volume_label_t *vlabel);
253
254void vtoc_volume_label_set_volser (
255 volume_label_t *vlabel,
256 char *volser);
257
258char *vtoc_volume_label_get_volser (
259 volume_label_t *vlabel,
260 char *volser);
261
262void vtoc_volume_label_set_key (
263 volume_label_t *vlabel,
264 char *key);
265
266void vtoc_volume_label_set_label (
267 volume_label_t *vlabel,
268 char *lbl);
269
270char *vtoc_volume_label_get_label (
271 volume_label_t *vlabel,
272 char *lbl);
273
274void vtoc_read_label (
275 char *device,
276 unsigned long position,
277 format1_label_t *f1,
278 format4_label_t *f4,
279 format5_label_t *f5,
280 format7_label_t *f7);
281
282void vtoc_write_label (
283 char *device,
284 unsigned long position,
285 format1_label_t *f1,
286 format4_label_t *f4,
287 format5_label_t *f5,
288 format7_label_t *f7);
289
290
291void vtoc_init_format1_label (
292 char *volid,
293 unsigned int blksize,
294 extent_t *part_extent,
295 format1_label_t *f1);
296
297
298void vtoc_init_format4_label (
299 format4_label_t *f4lbl,
300 unsigned int usable_partitions,
301 unsigned int cylinders,
302 unsigned int tracks,
303 unsigned int blocks,
304 unsigned int blksize,
305 __u16 dev_type);
306
307void vtoc_update_format4_label (
308 format4_label_t *f4,
309 cchhb_t *highest_f1,
310 __u16 unused_update);
311
312
313void vtoc_init_format5_label (
314 format5_label_t *f5);
315
316void vtoc_update_format5_label_add (
317 format5_label_t *f5,
318 int verbose,
319 int cyl,
320 int trk,
321 __u16 a,
322 __u16 b,
323 __u8 c);
324
325void vtoc_update_format5_label_del (
326 format5_label_t *f5,
327 int verbose,
328 int cyl,
329 int trk,
330 __u16 a,
331 __u16 b,
332 __u8 c);
333
334
335void vtoc_init_format7_label (
336 format7_label_t *f7);
337
338void vtoc_update_format7_label_add (
339 format7_label_t *f7,
340 int verbose,
341 __u32 a,
342 __u32 b);
343
344void vtoc_update_format7_label_del (
345 format7_label_t *f7,
346 int verbose,
347 __u32 a,
348 __u32 b);
349
350
351void vtoc_set_freespace(
352 format4_label_t *f4,
353 format5_label_t *f5,
354 format7_label_t *f7,
355 char ch,
356 int verbose,
357 __u32 start,
358 __u32 stop,
359 int cyl,
360 int trk);
361
362
363
364
365
366
367
368
369
370
371
372
diff --git a/include/asm-sh/elf.h b/include/asm-sh/elf.h
index 8fe00a1981ce..1b63dfeea4f2 100644
--- a/include/asm-sh/elf.h
+++ b/include/asm-sh/elf.h
@@ -111,6 +111,7 @@ typedef struct user_fpu_struct elf_fpregset_t;
111 111
112#ifdef __KERNEL__ 112#ifdef __KERNEL__
113#define SET_PERSONALITY(ex, ibcs2) set_personality(PER_LINUX_32BIT) 113#define SET_PERSONALITY(ex, ibcs2) set_personality(PER_LINUX_32BIT)
114struct task_struct;
114extern int dump_task_regs (struct task_struct *, elf_gregset_t *); 115extern int dump_task_regs (struct task_struct *, elf_gregset_t *);
115extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *); 116extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *);
116 117
diff --git a/include/asm-sh/mmzone.h b/include/asm-sh/mmzone.h
deleted file mode 100644
index 0e7406601fdf..000000000000
--- a/include/asm-sh/mmzone.h
+++ /dev/null
@@ -1,61 +0,0 @@
1/*
2 * linux/include/asm-sh/mmzone.h
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 version 2 as
6 * published by the Free Software Foundation.
7 */
8#ifndef __ASM_SH_MMZONE_H
9#define __ASM_SH_MMZONE_H
10
11#include <linux/config.h>
12
13#ifdef CONFIG_DISCONTIGMEM
14
15/* Currently, just for HP690 */
16#define PHYSADDR_TO_NID(phys) ((((phys) - __MEMORY_START) >= 0x01000000)?1:0)
17
18extern pg_data_t discontig_page_data[MAX_NUMNODES];
19extern bootmem_data_t discontig_node_bdata[MAX_NUMNODES];
20
21/*
22 * Following are macros that each numa implmentation must define.
23 */
24
25/*
26 * Given a kernel address, find the home node of the underlying memory.
27 */
28#define KVADDR_TO_NID(kaddr) PHYSADDR_TO_NID(__pa(kaddr))
29
30/*
31 * Return a pointer to the node data for node n.
32 */
33#define NODE_DATA(nid) (&discontig_page_data[nid])
34
35/*
36 * NODE_MEM_MAP gives the kaddr for the mem_map of the node.
37 */
38#define NODE_MEM_MAP(nid) (NODE_DATA(nid)->node_mem_map)
39
40#define phys_to_page(phys) \
41({ unsigned int node = PHYSADDR_TO_NID(phys); \
42 NODE_MEM_MAP(node) \
43 + (((phys) - NODE_DATA(node)->node_start_paddr) >> PAGE_SHIFT); })
44
45static inline int is_valid_page(struct page *page)
46{
47 unsigned int i;
48
49 for (i = 0; i < MAX_NUMNODES; i++) {
50 if (page >= NODE_MEM_MAP(i) &&
51 page < NODE_MEM_MAP(i) + NODE_DATA(i)->node_size)
52 return 1;
53 }
54 return 0;
55}
56
57#define VALID_PAGE(page) is_valid_page(page)
58#define page_to_phys(page) PHYSADDR(page_address(page))
59
60#endif /* CONFIG_DISCONTIGMEM */
61#endif
diff --git a/include/asm-sh/page.h b/include/asm-sh/page.h
index 324e6cc5ecf7..972c3f655b2a 100644
--- a/include/asm-sh/page.h
+++ b/include/asm-sh/page.h
@@ -93,11 +93,6 @@ typedef struct { unsigned long pgprot; } pgprot_t;
93 93
94#define __MEMORY_START CONFIG_MEMORY_START 94#define __MEMORY_START CONFIG_MEMORY_START
95#define __MEMORY_SIZE CONFIG_MEMORY_SIZE 95#define __MEMORY_SIZE CONFIG_MEMORY_SIZE
96#ifdef CONFIG_DISCONTIGMEM
97/* Just for HP690, for now.. */
98#define __MEMORY_START_2ND (__MEMORY_START+0x02000000)
99#define __MEMORY_SIZE_2ND 0x001000000 /* 16MB */
100#endif
101 96
102#define PAGE_OFFSET (0x80000000UL) 97#define PAGE_OFFSET (0x80000000UL)
103#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) 98#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
@@ -105,10 +100,8 @@ typedef struct { unsigned long pgprot; } pgprot_t;
105 100
106#define MAP_NR(addr) (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT) 101#define MAP_NR(addr) (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT)
107 102
108#ifndef CONFIG_DISCONTIGMEM
109#define phys_to_page(phys) (mem_map + (((phys)-__MEMORY_START) >> PAGE_SHIFT)) 103#define phys_to_page(phys) (mem_map + (((phys)-__MEMORY_START) >> PAGE_SHIFT))
110#define page_to_phys(page) (((page - mem_map) << PAGE_SHIFT) + __MEMORY_START) 104#define page_to_phys(page) (((page - mem_map) << PAGE_SHIFT) + __MEMORY_START)
111#endif
112 105
113/* PFN start number, because of __MEMORY_START */ 106/* PFN start number, because of __MEMORY_START */
114#define PFN_START (__MEMORY_START >> PAGE_SHIFT) 107#define PFN_START (__MEMORY_START >> PAGE_SHIFT)
diff --git a/include/asm-sh/pgtable.h b/include/asm-sh/pgtable.h
index aef8ae43de13..bb0efb31a8cb 100644
--- a/include/asm-sh/pgtable.h
+++ b/include/asm-sh/pgtable.h
@@ -196,7 +196,9 @@ static inline pte_t pte_mkexec(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _
196static inline pte_t pte_mkdirty(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY)); return pte; } 196static inline pte_t pte_mkdirty(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY)); return pte; }
197static inline pte_t pte_mkyoung(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED)); return pte; } 197static inline pte_t pte_mkyoung(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED)); return pte; }
198static inline pte_t pte_mkwrite(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_RW)); return pte; } 198static inline pte_t pte_mkwrite(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_RW)); return pte; }
199#ifdef CONFIG_HUGETLB_PAGE
199static inline pte_t pte_mkhuge(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_SZHUGE)); return pte; } 200static inline pte_t pte_mkhuge(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_SZHUGE)); return pte; }
201#endif
200 202
201/* 203/*
202 * Macro and implementation to make a page protection as uncachable. 204 * Macro and implementation to make a page protection as uncachable.
@@ -282,6 +284,8 @@ typedef pte_t *pte_addr_t;
282#define GET_IOSPACE(pfn) 0 284#define GET_IOSPACE(pfn) 0
283#define GET_PFN(pfn) (pfn) 285#define GET_PFN(pfn) (pfn)
284 286
287struct mm_struct;
288
285/* 289/*
286 * No page table caches to initialise 290 * No page table caches to initialise
287 */ 291 */
diff --git a/include/asm-sh64/pgtable.h b/include/asm-sh64/pgtable.h
index 51b05818e4eb..a1906a772df9 100644
--- a/include/asm-sh64/pgtable.h
+++ b/include/asm-sh64/pgtable.h
@@ -24,6 +24,8 @@
24#include <linux/threads.h> 24#include <linux/threads.h>
25#include <linux/config.h> 25#include <linux/config.h>
26 26
27struct vm_area_struct;
28
27extern void paging_init(void); 29extern void paging_init(void);
28 30
29/* We provide our own get_unmapped_area to avoid cache synonym issue */ 31/* We provide our own get_unmapped_area to avoid cache synonym issue */
diff --git a/include/asm-sparc/audioio.h b/include/asm-sparc/audioio.h
deleted file mode 100644
index cf16173f521b..000000000000
--- a/include/asm-sparc/audioio.h
+++ /dev/null
@@ -1,234 +0,0 @@
1/*
2 * include/asm-sparc/audioio.h
3 *
4 * Sparc Audio Midlayer
5 * Copyright (C) 1996 Thomas K. Dyas (tdyas@noc.rutgers.edu)
6 */
7
8#ifndef _AUDIOIO_H_
9#define _AUDIOIO_H_
10
11/*
12 * SunOS/Solaris /dev/audio interface
13 */
14
15#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
16#include <linux/types.h>
17#include <linux/time.h>
18#include <linux/ioctl.h>
19#endif
20
21/*
22 * This structure contains state information for audio device IO streams.
23 */
24typedef struct audio_prinfo {
25 /*
26 * The following values describe the audio data encoding.
27 */
28 unsigned int sample_rate; /* samples per second */
29 unsigned int channels; /* number of interleaved channels */
30 unsigned int precision; /* bit-width of each sample */
31 unsigned int encoding; /* data encoding method */
32
33 /*
34 * The following values control audio device configuration
35 */
36 unsigned int gain; /* gain level: 0 - 255 */
37 unsigned int port; /* selected I/O port (see below) */
38 unsigned int avail_ports; /* available I/O ports (see below) */
39 unsigned int _xxx[2]; /* Reserved for future use */
40
41 unsigned int buffer_size; /* I/O buffer size */
42
43 /*
44 * The following values describe driver state
45 */
46 unsigned int samples; /* number of samples converted */
47 unsigned int eof; /* End Of File counter (play only) */
48
49 unsigned char pause; /* non-zero for pause, zero to resume */
50 unsigned char error; /* non-zero if overflow/underflow */
51 unsigned char waiting; /* non-zero if a process wants access */
52 unsigned char balance; /* stereo channel balance */
53
54 unsigned short minordev;
55
56 /*
57 * The following values are read-only state flags
58 */
59 unsigned char open; /* non-zero if open access permitted */
60 unsigned char active; /* non-zero if I/O is active */
61} audio_prinfo_t;
62
63
64/*
65 * This structure describes the current state of the audio device.
66 */
67typedef struct audio_info {
68 /*
69 * Per-stream information
70 */
71 audio_prinfo_t play; /* output status information */
72 audio_prinfo_t record; /* input status information */
73
74 /*
75 * Per-unit/channel information
76 */
77 unsigned int monitor_gain; /* input to output mix: 0 - 255 */
78 unsigned char output_muted; /* non-zero if output is muted */
79 unsigned char _xxx[3]; /* Reserved for future use */
80 unsigned int _yyy[3]; /* Reserved for future use */
81} audio_info_t;
82
83
84/*
85 * Audio encoding types
86 */
87#define AUDIO_ENCODING_NONE (0) /* no encoding assigned */
88#define AUDIO_ENCODING_ULAW (1) /* u-law encoding */
89#define AUDIO_ENCODING_ALAW (2) /* A-law encoding */
90#define AUDIO_ENCODING_LINEAR (3) /* Linear PCM encoding */
91#define AUDIO_ENCODING_FLOAT (4) /* IEEE float (-1. <-> +1.) */
92#define AUDIO_ENCODING_DVI (104) /* DVI ADPCM */
93#define AUDIO_ENCODING_LINEAR8 (105) /* 8 bit UNSIGNED */
94#define AUDIO_ENCODING_LINEARLE (106) /* Linear PCM LE encoding */
95
96/*
97 * These ranges apply to record, play, and monitor gain values
98 */
99#define AUDIO_MIN_GAIN (0) /* minimum gain value */
100#define AUDIO_MAX_GAIN (255) /* maximum gain value */
101
102/*
103 * These values apply to the balance field to adjust channel gain values
104 */
105#define AUDIO_LEFT_BALANCE (0) /* left channel only */
106#define AUDIO_MID_BALANCE (32) /* equal left/right channel */
107#define AUDIO_RIGHT_BALANCE (64) /* right channel only */
108#define AUDIO_BALANCE_SHIFT (3)
109
110/*
111 * Generic minimum/maximum limits for number of channels, both modes
112 */
113#define AUDIO_MIN_PLAY_CHANNELS (1)
114#define AUDIO_MAX_PLAY_CHANNELS (4)
115#define AUDIO_MIN_REC_CHANNELS (1)
116#define AUDIO_MAX_REC_CHANNELS (4)
117
118/*
119 * Generic minimum/maximum limits for sample precision
120 */
121#define AUDIO_MIN_PLAY_PRECISION (8)
122#define AUDIO_MAX_PLAY_PRECISION (32)
123#define AUDIO_MIN_REC_PRECISION (8)
124#define AUDIO_MAX_REC_PRECISION (32)
125
126/*
127 * Define some convenient names for typical audio ports
128 */
129/*
130 * output ports (several may be enabled simultaneously)
131 */
132#define AUDIO_SPEAKER 0x01 /* output to built-in speaker */
133#define AUDIO_HEADPHONE 0x02 /* output to headphone jack */
134#define AUDIO_LINE_OUT 0x04 /* output to line out */
135
136/*
137 * input ports (usually only one at a time)
138 */
139#define AUDIO_MICROPHONE 0x01 /* input from microphone */
140#define AUDIO_LINE_IN 0x02 /* input from line in */
141#define AUDIO_CD 0x04 /* input from on-board CD inputs */
142#define AUDIO_INTERNAL_CD_IN AUDIO_CD /* input from internal CDROM */
143#define AUDIO_ANALOG_LOOPBACK 0x40 /* input from output */
144
145
146/*
147 * This macro initializes an audio_info structure to 'harmless' values.
148 * Note that (~0) might not be a harmless value for a flag that was
149 * a signed int.
150 */
151#define AUDIO_INITINFO(i) { \
152 unsigned int *__x__; \
153 for (__x__ = (unsigned int *)(i); \
154 (char *) __x__ < (((char *)(i)) + sizeof (audio_info_t)); \
155 *__x__++ = ~0); \
156}
157
158/*
159 * These allow testing for what the user wants to set
160 */
161#define AUD_INITVALUE (~0)
162#define Modify(X) ((unsigned int)(X) != AUD_INITVALUE)
163#define Modifys(X) ((X) != (unsigned short)AUD_INITVALUE)
164#define Modifyc(X) ((X) != (unsigned char)AUD_INITVALUE)
165
166/*
167 * Parameter for the AUDIO_GETDEV ioctl to determine current
168 * audio devices.
169 */
170#define MAX_AUDIO_DEV_LEN (16)
171typedef struct audio_device {
172 char name[MAX_AUDIO_DEV_LEN];
173 char version[MAX_AUDIO_DEV_LEN];
174 char config[MAX_AUDIO_DEV_LEN];
175} audio_device_t;
176
177
178/*
179 * Ioctl calls for the audio device.
180 */
181
182/*
183 * AUDIO_GETINFO retrieves the current state of the audio device.
184 *
185 * AUDIO_SETINFO copies all fields of the audio_info structure whose
186 * values are not set to the initialized value (-1) to the device state.
187 * It performs an implicit AUDIO_GETINFO to return the new state of the
188 * device. Note that the record.samples and play.samples fields are set
189 * to the last value before the AUDIO_SETINFO took effect. This allows
190 * an application to reset the counters while atomically retrieving the
191 * last value.
192 *
193 * AUDIO_DRAIN suspends the calling process until the write buffers are
194 * empty.
195 *
196 * AUDIO_GETDEV returns a structure of type audio_device_t which contains
197 * three strings. The string "name" is a short identifying string (for
198 * example, the SBus Fcode name string), the string "version" identifies
199 * the current version of the device, and the "config" string identifies
200 * the specific configuration of the audio stream. All fields are
201 * device-dependent -- see the device specific manual pages for details.
202 *
203 * AUDIO_GETDEV_SUNOS returns a number which is an audio device defined
204 * herein (making it not too portable)
205 *
206 * AUDIO_FLUSH stops all playback and recording, clears all queued buffers,
207 * resets error counters, and restarts recording and playback as appropriate
208 * for the current sampling mode.
209 */
210#define AUDIO_GETINFO _IOR('A', 1, audio_info_t)
211#define AUDIO_SETINFO _IOWR('A', 2, audio_info_t)
212#define AUDIO_DRAIN _IO('A', 3)
213#define AUDIO_GETDEV _IOR('A', 4, audio_device_t)
214#define AUDIO_GETDEV_SUNOS _IOR('A', 4, int)
215#define AUDIO_FLUSH _IO('A', 5)
216
217/* Define possible audio hardware configurations for
218 * old SunOS-style AUDIO_GETDEV ioctl */
219#define AUDIO_DEV_UNKNOWN (0) /* not defined */
220#define AUDIO_DEV_AMD (1) /* audioamd device */
221#define AUDIO_DEV_SPEAKERBOX (2) /* dbri device with speakerbox */
222#define AUDIO_DEV_CODEC (3) /* dbri device (internal speaker) */
223#define AUDIO_DEV_CS4231 (5) /* cs4231 device */
224
225/*
226 * The following ioctl sets the audio device into an internal loopback mode,
227 * if the hardware supports this. The argument is TRUE to set loopback,
228 * FALSE to reset to normal operation. If the hardware does not support
229 * internal loopback, the ioctl should fail with EINVAL.
230 * Causes ADC data to be digitally mixed in and sent to the DAC.
231 */
232#define AUDIO_DIAG_LOOPBACK _IOW('A', 101, int)
233
234#endif /* _AUDIOIO_H_ */
diff --git a/include/asm-sparc/kbio.h b/include/asm-sparc/kbio.h
deleted file mode 100644
index 3cf496bdf399..000000000000
--- a/include/asm-sparc/kbio.h
+++ /dev/null
@@ -1,56 +0,0 @@
1#ifndef __LINUX_KBIO_H
2#define __LINUX_KBIO_H
3
4/* Return keyboard type */
5#define KIOCTYPE _IOR('k', 9, int)
6/* Return Keyboard layout */
7#define KIOCLAYOUT _IOR('k', 20, int)
8
9enum {
10 TR_NONE,
11 TR_ASCII, /* keyboard is in regular state */
12 TR_EVENT, /* keystrokes sent as firm events */
13 TR_UNTRANS_EVENT /* EVENT+up and down+no translation */
14};
15
16/* Return the current keyboard translation */
17#define KIOCGTRANS _IOR('k', 5, int)
18/* Set the keyboard translation */
19#define KIOCTRANS _IOW('k', 0, int)
20
21/* Send a keyboard command */
22#define KIOCCMD _IOW('k', 8, int)
23
24/* Return if keystrokes are being sent to /dev/kbd */
25
26/* Set routing of keystrokes to /dev/kbd */
27#define KIOCSDIRECT _IOW('k', 10, int)
28
29/* Set keyboard leds */
30#define KIOCSLED _IOW('k', 14, unsigned char)
31
32/* Get keyboard leds */
33#define KIOCGLED _IOR('k', 15, unsigned char)
34
35/* Used by KIOC[GS]RATE */
36struct kbd_rate {
37 unsigned char delay; /* Delay in Hz before first repeat. */
38 unsigned char rate; /* In characters per second (0..50). */
39};
40
41/* Set keyboard rate */
42#define KIOCSRATE _IOW('k', 40, struct kbd_rate)
43
44/* Get keyboard rate */
45#define KIOCGRATE _IOW('k', 41, struct kbd_rate)
46
47/* Top bit records if the key is up or down */
48#define KBD_UP 0x80
49
50/* Usable information */
51#define KBD_KEYMASK 0x7f
52
53/* All keys up */
54#define KBD_IDLE 0x75
55
56#endif /* __LINUX_KBIO_H */
diff --git a/include/asm-sparc/ptrace.h b/include/asm-sparc/ptrace.h
index a8ecb2d6977a..714497099a42 100644
--- a/include/asm-sparc/ptrace.h
+++ b/include/asm-sparc/ptrace.h
@@ -60,6 +60,9 @@ struct sparc_stackf {
60#define STACKFRAME_SZ sizeof(struct sparc_stackf) 60#define STACKFRAME_SZ sizeof(struct sparc_stackf)
61 61
62#ifdef __KERNEL__ 62#ifdef __KERNEL__
63
64#define __ARCH_SYS_PTRACE 1
65
63#define user_mode(regs) (!((regs)->psr & PSR_PS)) 66#define user_mode(regs) (!((regs)->psr & PSR_PS))
64#define instruction_pointer(regs) ((regs)->pc) 67#define instruction_pointer(regs) ((regs)->pc)
65unsigned long profile_pc(struct pt_regs *); 68unsigned long profile_pc(struct pt_regs *);
diff --git a/include/asm-sparc/termios.h b/include/asm-sparc/termios.h
index 0a8ad4cac125..d05f83c80989 100644
--- a/include/asm-sparc/termios.h
+++ b/include/asm-sparc/termios.h
@@ -38,15 +38,6 @@ struct sunos_ttysize {
38 int st_columns; /* Columns on the terminal */ 38 int st_columns; /* Columns on the terminal */
39}; 39};
40 40
41/* Used for packet mode */
42#define TIOCPKT_DATA 0
43#define TIOCPKT_FLUSHREAD 1
44#define TIOCPKT_FLUSHWRITE 2
45#define TIOCPKT_STOP 4
46#define TIOCPKT_START 8
47#define TIOCPKT_NOSTOP 16
48#define TIOCPKT_DOSTOP 32
49
50struct winsize { 41struct winsize {
51 unsigned short ws_row; 42 unsigned short ws_row;
52 unsigned short ws_col; 43 unsigned short ws_col;
diff --git a/include/asm-sparc/vuid_event.h b/include/asm-sparc/vuid_event.h
deleted file mode 100644
index 7781e9f2fdd3..000000000000
--- a/include/asm-sparc/vuid_event.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/* SunOS Virtual User Input Device (VUID) compatibility */
2
3
4typedef struct firm_event {
5 unsigned short id; /* tag for this event */
6 unsigned char pair_type; /* unused by X11 */
7 unsigned char pair; /* unused by X11 */
8 int value; /* VKEY_UP, VKEY_DOWN or delta */
9 struct timeval time;
10} Firm_event;
11
12enum {
13 FE_PAIR_NONE,
14 FE_PAIR_SET,
15 FE_PAIR_DELTA,
16 FE_PAIR_ABSOLUTE
17};
18
19/* VUID stream formats */
20#define VUID_NATIVE 0 /* Native byte stream format */
21#define VUID_FIRM_EVENT 1 /* send firm_event structures */
22
23/* ioctls */
24 /* Set input device byte stream format (any of VUID_{NATIVE,FIRM_EVENT}) */
25#define VUIDSFORMAT _IOW('v', 1, int)
26 /* Retrieve input device byte stream format */
27#define VUIDGFORMAT _IOR('v', 2, int)
28
29/* Possible tag values */
30/* mouse buttons: */
31#define MS_LEFT 0x7f20
32#define MS_MIDDLE 0x7f21
33#define MS_RIGHT 0x7f22
34/* motion: */
35#define LOC_X_DELTA 0x7f80
36#define LOC_Y_DELTA 0x7f81
37#define LOC_X_ABSOLUTE 0x7f82 /* X compat, unsupported */
38#define LOC_Y_ABSOLUTE 0x7f83 /* X compat, unsupported */
39
40#define VKEY_UP 0
41#define VKEY_DOWN 1
diff --git a/include/asm-sparc64/audioio.h b/include/asm-sparc64/audioio.h
deleted file mode 100644
index cf16173f521b..000000000000
--- a/include/asm-sparc64/audioio.h
+++ /dev/null
@@ -1,234 +0,0 @@
1/*
2 * include/asm-sparc/audioio.h
3 *
4 * Sparc Audio Midlayer
5 * Copyright (C) 1996 Thomas K. Dyas (tdyas@noc.rutgers.edu)
6 */
7
8#ifndef _AUDIOIO_H_
9#define _AUDIOIO_H_
10
11/*
12 * SunOS/Solaris /dev/audio interface
13 */
14
15#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
16#include <linux/types.h>
17#include <linux/time.h>
18#include <linux/ioctl.h>
19#endif
20
21/*
22 * This structure contains state information for audio device IO streams.
23 */
24typedef struct audio_prinfo {
25 /*
26 * The following values describe the audio data encoding.
27 */
28 unsigned int sample_rate; /* samples per second */
29 unsigned int channels; /* number of interleaved channels */
30 unsigned int precision; /* bit-width of each sample */
31 unsigned int encoding; /* data encoding method */
32
33 /*
34 * The following values control audio device configuration
35 */
36 unsigned int gain; /* gain level: 0 - 255 */
37 unsigned int port; /* selected I/O port (see below) */
38 unsigned int avail_ports; /* available I/O ports (see below) */
39 unsigned int _xxx[2]; /* Reserved for future use */
40
41 unsigned int buffer_size; /* I/O buffer size */
42
43 /*
44 * The following values describe driver state
45 */
46 unsigned int samples; /* number of samples converted */
47 unsigned int eof; /* End Of File counter (play only) */
48
49 unsigned char pause; /* non-zero for pause, zero to resume */
50 unsigned char error; /* non-zero if overflow/underflow */
51 unsigned char waiting; /* non-zero if a process wants access */
52 unsigned char balance; /* stereo channel balance */
53
54 unsigned short minordev;
55
56 /*
57 * The following values are read-only state flags
58 */
59 unsigned char open; /* non-zero if open access permitted */
60 unsigned char active; /* non-zero if I/O is active */
61} audio_prinfo_t;
62
63
64/*
65 * This structure describes the current state of the audio device.
66 */
67typedef struct audio_info {
68 /*
69 * Per-stream information
70 */
71 audio_prinfo_t play; /* output status information */
72 audio_prinfo_t record; /* input status information */
73
74 /*
75 * Per-unit/channel information
76 */
77 unsigned int monitor_gain; /* input to output mix: 0 - 255 */
78 unsigned char output_muted; /* non-zero if output is muted */
79 unsigned char _xxx[3]; /* Reserved for future use */
80 unsigned int _yyy[3]; /* Reserved for future use */
81} audio_info_t;
82
83
84/*
85 * Audio encoding types
86 */
87#define AUDIO_ENCODING_NONE (0) /* no encoding assigned */
88#define AUDIO_ENCODING_ULAW (1) /* u-law encoding */
89#define AUDIO_ENCODING_ALAW (2) /* A-law encoding */
90#define AUDIO_ENCODING_LINEAR (3) /* Linear PCM encoding */
91#define AUDIO_ENCODING_FLOAT (4) /* IEEE float (-1. <-> +1.) */
92#define AUDIO_ENCODING_DVI (104) /* DVI ADPCM */
93#define AUDIO_ENCODING_LINEAR8 (105) /* 8 bit UNSIGNED */
94#define AUDIO_ENCODING_LINEARLE (106) /* Linear PCM LE encoding */
95
96/*
97 * These ranges apply to record, play, and monitor gain values
98 */
99#define AUDIO_MIN_GAIN (0) /* minimum gain value */
100#define AUDIO_MAX_GAIN (255) /* maximum gain value */
101
102/*
103 * These values apply to the balance field to adjust channel gain values
104 */
105#define AUDIO_LEFT_BALANCE (0) /* left channel only */
106#define AUDIO_MID_BALANCE (32) /* equal left/right channel */
107#define AUDIO_RIGHT_BALANCE (64) /* right channel only */
108#define AUDIO_BALANCE_SHIFT (3)
109
110/*
111 * Generic minimum/maximum limits for number of channels, both modes
112 */
113#define AUDIO_MIN_PLAY_CHANNELS (1)
114#define AUDIO_MAX_PLAY_CHANNELS (4)
115#define AUDIO_MIN_REC_CHANNELS (1)
116#define AUDIO_MAX_REC_CHANNELS (4)
117
118/*
119 * Generic minimum/maximum limits for sample precision
120 */
121#define AUDIO_MIN_PLAY_PRECISION (8)
122#define AUDIO_MAX_PLAY_PRECISION (32)
123#define AUDIO_MIN_REC_PRECISION (8)
124#define AUDIO_MAX_REC_PRECISION (32)
125
126/*
127 * Define some convenient names for typical audio ports
128 */
129/*
130 * output ports (several may be enabled simultaneously)
131 */
132#define AUDIO_SPEAKER 0x01 /* output to built-in speaker */
133#define AUDIO_HEADPHONE 0x02 /* output to headphone jack */
134#define AUDIO_LINE_OUT 0x04 /* output to line out */
135
136/*
137 * input ports (usually only one at a time)
138 */
139#define AUDIO_MICROPHONE 0x01 /* input from microphone */
140#define AUDIO_LINE_IN 0x02 /* input from line in */
141#define AUDIO_CD 0x04 /* input from on-board CD inputs */
142#define AUDIO_INTERNAL_CD_IN AUDIO_CD /* input from internal CDROM */
143#define AUDIO_ANALOG_LOOPBACK 0x40 /* input from output */
144
145
146/*
147 * This macro initializes an audio_info structure to 'harmless' values.
148 * Note that (~0) might not be a harmless value for a flag that was
149 * a signed int.
150 */
151#define AUDIO_INITINFO(i) { \
152 unsigned int *__x__; \
153 for (__x__ = (unsigned int *)(i); \
154 (char *) __x__ < (((char *)(i)) + sizeof (audio_info_t)); \
155 *__x__++ = ~0); \
156}
157
158/*
159 * These allow testing for what the user wants to set
160 */
161#define AUD_INITVALUE (~0)
162#define Modify(X) ((unsigned int)(X) != AUD_INITVALUE)
163#define Modifys(X) ((X) != (unsigned short)AUD_INITVALUE)
164#define Modifyc(X) ((X) != (unsigned char)AUD_INITVALUE)
165
166/*
167 * Parameter for the AUDIO_GETDEV ioctl to determine current
168 * audio devices.
169 */
170#define MAX_AUDIO_DEV_LEN (16)
171typedef struct audio_device {
172 char name[MAX_AUDIO_DEV_LEN];
173 char version[MAX_AUDIO_DEV_LEN];
174 char config[MAX_AUDIO_DEV_LEN];
175} audio_device_t;
176
177
178/*
179 * Ioctl calls for the audio device.
180 */
181
182/*
183 * AUDIO_GETINFO retrieves the current state of the audio device.
184 *
185 * AUDIO_SETINFO copies all fields of the audio_info structure whose
186 * values are not set to the initialized value (-1) to the device state.
187 * It performs an implicit AUDIO_GETINFO to return the new state of the
188 * device. Note that the record.samples and play.samples fields are set
189 * to the last value before the AUDIO_SETINFO took effect. This allows
190 * an application to reset the counters while atomically retrieving the
191 * last value.
192 *
193 * AUDIO_DRAIN suspends the calling process until the write buffers are
194 * empty.
195 *
196 * AUDIO_GETDEV returns a structure of type audio_device_t which contains
197 * three strings. The string "name" is a short identifying string (for
198 * example, the SBus Fcode name string), the string "version" identifies
199 * the current version of the device, and the "config" string identifies
200 * the specific configuration of the audio stream. All fields are
201 * device-dependent -- see the device specific manual pages for details.
202 *
203 * AUDIO_GETDEV_SUNOS returns a number which is an audio device defined
204 * herein (making it not too portable)
205 *
206 * AUDIO_FLUSH stops all playback and recording, clears all queued buffers,
207 * resets error counters, and restarts recording and playback as appropriate
208 * for the current sampling mode.
209 */
210#define AUDIO_GETINFO _IOR('A', 1, audio_info_t)
211#define AUDIO_SETINFO _IOWR('A', 2, audio_info_t)
212#define AUDIO_DRAIN _IO('A', 3)
213#define AUDIO_GETDEV _IOR('A', 4, audio_device_t)
214#define AUDIO_GETDEV_SUNOS _IOR('A', 4, int)
215#define AUDIO_FLUSH _IO('A', 5)
216
217/* Define possible audio hardware configurations for
218 * old SunOS-style AUDIO_GETDEV ioctl */
219#define AUDIO_DEV_UNKNOWN (0) /* not defined */
220#define AUDIO_DEV_AMD (1) /* audioamd device */
221#define AUDIO_DEV_SPEAKERBOX (2) /* dbri device with speakerbox */
222#define AUDIO_DEV_CODEC (3) /* dbri device (internal speaker) */
223#define AUDIO_DEV_CS4231 (5) /* cs4231 device */
224
225/*
226 * The following ioctl sets the audio device into an internal loopback mode,
227 * if the hardware supports this. The argument is TRUE to set loopback,
228 * FALSE to reset to normal operation. If the hardware does not support
229 * internal loopback, the ioctl should fail with EINVAL.
230 * Causes ADC data to be digitally mixed in and sent to the DAC.
231 */
232#define AUDIO_DIAG_LOOPBACK _IOW('A', 101, int)
233
234#endif /* _AUDIOIO_H_ */
diff --git a/include/asm-sparc64/ebus.h b/include/asm-sparc64/ebus.h
index 543e4e500a72..7a408a030f52 100644
--- a/include/asm-sparc64/ebus.h
+++ b/include/asm-sparc64/ebus.h
@@ -79,6 +79,7 @@ extern int ebus_dma_request(struct ebus_dma_info *p, dma_addr_t bus_addr,
79 size_t len); 79 size_t len);
80extern void ebus_dma_prepare(struct ebus_dma_info *p, int write); 80extern void ebus_dma_prepare(struct ebus_dma_info *p, int write);
81extern unsigned int ebus_dma_residue(struct ebus_dma_info *p); 81extern unsigned int ebus_dma_residue(struct ebus_dma_info *p);
82extern unsigned int ebus_dma_addr(struct ebus_dma_info *p);
82extern void ebus_dma_enable(struct ebus_dma_info *p, int on); 83extern void ebus_dma_enable(struct ebus_dma_info *p, int on);
83 84
84extern struct linux_ebus *ebus_chain; 85extern struct linux_ebus *ebus_chain;
diff --git a/include/asm-sparc64/kbio.h b/include/asm-sparc64/kbio.h
deleted file mode 100644
index 3cf496bdf399..000000000000
--- a/include/asm-sparc64/kbio.h
+++ /dev/null
@@ -1,56 +0,0 @@
1#ifndef __LINUX_KBIO_H
2#define __LINUX_KBIO_H
3
4/* Return keyboard type */
5#define KIOCTYPE _IOR('k', 9, int)
6/* Return Keyboard layout */
7#define KIOCLAYOUT _IOR('k', 20, int)
8
9enum {
10 TR_NONE,
11 TR_ASCII, /* keyboard is in regular state */
12 TR_EVENT, /* keystrokes sent as firm events */
13 TR_UNTRANS_EVENT /* EVENT+up and down+no translation */
14};
15
16/* Return the current keyboard translation */
17#define KIOCGTRANS _IOR('k', 5, int)
18/* Set the keyboard translation */
19#define KIOCTRANS _IOW('k', 0, int)
20
21/* Send a keyboard command */
22#define KIOCCMD _IOW('k', 8, int)
23
24/* Return if keystrokes are being sent to /dev/kbd */
25
26/* Set routing of keystrokes to /dev/kbd */
27#define KIOCSDIRECT _IOW('k', 10, int)
28
29/* Set keyboard leds */
30#define KIOCSLED _IOW('k', 14, unsigned char)
31
32/* Get keyboard leds */
33#define KIOCGLED _IOR('k', 15, unsigned char)
34
35/* Used by KIOC[GS]RATE */
36struct kbd_rate {
37 unsigned char delay; /* Delay in Hz before first repeat. */
38 unsigned char rate; /* In characters per second (0..50). */
39};
40
41/* Set keyboard rate */
42#define KIOCSRATE _IOW('k', 40, struct kbd_rate)
43
44/* Get keyboard rate */
45#define KIOCGRATE _IOW('k', 41, struct kbd_rate)
46
47/* Top bit records if the key is up or down */
48#define KBD_UP 0x80
49
50/* Usable information */
51#define KBD_KEYMASK 0x7f
52
53/* All keys up */
54#define KBD_IDLE 0x75
55
56#endif /* __LINUX_KBIO_H */
diff --git a/include/asm-sparc64/kprobes.h b/include/asm-sparc64/kprobes.h
index a8d326a598f0..7ba845320f5c 100644
--- a/include/asm-sparc64/kprobes.h
+++ b/include/asm-sparc64/kprobes.h
@@ -3,6 +3,7 @@
3 3
4#include <linux/config.h> 4#include <linux/config.h>
5#include <linux/types.h> 5#include <linux/types.h>
6#include <linux/percpu.h>
6 7
7typedef u32 kprobe_opcode_t; 8typedef u32 kprobe_opcode_t;
8 9
@@ -18,6 +19,25 @@ struct arch_specific_insn {
18 kprobe_opcode_t insn[MAX_INSN_SIZE]; 19 kprobe_opcode_t insn[MAX_INSN_SIZE];
19}; 20};
20 21
22struct prev_kprobe {
23 struct kprobe *kp;
24 unsigned int status;
25 unsigned long orig_tnpc;
26 unsigned long orig_tstate_pil;
27};
28
29/* per-cpu kprobe control block */
30struct kprobe_ctlblk {
31 unsigned long kprobe_status;
32 unsigned long kprobe_orig_tnpc;
33 unsigned long kprobe_orig_tstate_pil;
34 long *jprobe_saved_esp;
35 struct pt_regs jprobe_saved_regs;
36 struct pt_regs *jprobe_saved_regs_location;
37 struct sparc_stackf jprobe_saved_stack;
38 struct prev_kprobe prev_kprobe;
39};
40
21#ifdef CONFIG_KPROBES 41#ifdef CONFIG_KPROBES
22extern int kprobe_exceptions_notify(struct notifier_block *self, 42extern int kprobe_exceptions_notify(struct notifier_block *self,
23 unsigned long val, void *data); 43 unsigned long val, void *data);
diff --git a/include/asm-sparc64/mmu_context.h b/include/asm-sparc64/mmu_context.h
index 87c43c67866e..08ba72d7722c 100644
--- a/include/asm-sparc64/mmu_context.h
+++ b/include/asm-sparc64/mmu_context.h
@@ -87,37 +87,35 @@ extern void __flush_tlb_mm(unsigned long, unsigned long);
87static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk) 87static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk)
88{ 88{
89 unsigned long ctx_valid; 89 unsigned long ctx_valid;
90 int cpu;
90 91
92 /* Note: page_table_lock is used here to serialize switch_mm
93 * and activate_mm, and their calls to get_new_mmu_context.
94 * This use of page_table_lock is unrelated to its other uses.
95 */
91 spin_lock(&mm->page_table_lock); 96 spin_lock(&mm->page_table_lock);
92 if (CTX_VALID(mm->context)) 97 ctx_valid = CTX_VALID(mm->context);
93 ctx_valid = 1; 98 if (!ctx_valid)
94 else 99 get_new_mmu_context(mm);
95 ctx_valid = 0; 100 spin_unlock(&mm->page_table_lock);
96 101
97 if (!ctx_valid || (old_mm != mm)) { 102 if (!ctx_valid || (old_mm != mm)) {
98 if (!ctx_valid)
99 get_new_mmu_context(mm);
100
101 load_secondary_context(mm); 103 load_secondary_context(mm);
102 reload_tlbmiss_state(tsk, mm); 104 reload_tlbmiss_state(tsk, mm);
103 } 105 }
104 106
105 { 107 /* Even if (mm == old_mm) we _must_ check
106 int cpu = smp_processor_id(); 108 * the cpu_vm_mask. If we do not we could
107 109 * corrupt the TLB state because of how
108 /* Even if (mm == old_mm) we _must_ check 110 * smp_flush_tlb_{page,range,mm} on sparc64
109 * the cpu_vm_mask. If we do not we could 111 * and lazy tlb switches work. -DaveM
110 * corrupt the TLB state because of how 112 */
111 * smp_flush_tlb_{page,range,mm} on sparc64 113 cpu = smp_processor_id();
112 * and lazy tlb switches work. -DaveM 114 if (!ctx_valid || !cpu_isset(cpu, mm->cpu_vm_mask)) {
113 */ 115 cpu_set(cpu, mm->cpu_vm_mask);
114 if (!ctx_valid || !cpu_isset(cpu, mm->cpu_vm_mask)) { 116 __flush_tlb_mm(CTX_HWBITS(mm->context),
115 cpu_set(cpu, mm->cpu_vm_mask); 117 SECONDARY_CONTEXT);
116 __flush_tlb_mm(CTX_HWBITS(mm->context),
117 SECONDARY_CONTEXT);
118 }
119 } 118 }
120 spin_unlock(&mm->page_table_lock);
121} 119}
122 120
123#define deactivate_mm(tsk,mm) do { } while (0) 121#define deactivate_mm(tsk,mm) do { } while (0)
@@ -127,6 +125,10 @@ static inline void activate_mm(struct mm_struct *active_mm, struct mm_struct *mm
127{ 125{
128 int cpu; 126 int cpu;
129 127
128 /* Note: page_table_lock is used here to serialize switch_mm
129 * and activate_mm, and their calls to get_new_mmu_context.
130 * This use of page_table_lock is unrelated to its other uses.
131 */
130 spin_lock(&mm->page_table_lock); 132 spin_lock(&mm->page_table_lock);
131 if (!CTX_VALID(mm->context)) 133 if (!CTX_VALID(mm->context))
132 get_new_mmu_context(mm); 134 get_new_mmu_context(mm);
diff --git a/include/asm-sparc64/ptrace.h b/include/asm-sparc64/ptrace.h
index 6194f771e9fc..7eba90c6c753 100644
--- a/include/asm-sparc64/ptrace.h
+++ b/include/asm-sparc64/ptrace.h
@@ -94,6 +94,9 @@ struct sparc_trapf {
94#define STACKFRAME32_SZ sizeof(struct sparc_stackf32) 94#define STACKFRAME32_SZ sizeof(struct sparc_stackf32)
95 95
96#ifdef __KERNEL__ 96#ifdef __KERNEL__
97
98#define __ARCH_SYS_PTRACE 1
99
97#define force_successful_syscall_return() \ 100#define force_successful_syscall_return() \
98do { current_thread_info()->syscall_noerror = 1; \ 101do { current_thread_info()->syscall_noerror = 1; \
99} while (0) 102} while (0)
diff --git a/include/asm-sparc64/termios.h b/include/asm-sparc64/termios.h
index 9777a9cca88a..ee26a071c677 100644
--- a/include/asm-sparc64/termios.h
+++ b/include/asm-sparc64/termios.h
@@ -38,15 +38,6 @@ struct sunos_ttysize {
38 int st_columns; /* Columns on the terminal */ 38 int st_columns; /* Columns on the terminal */
39}; 39};
40 40
41/* Used for packet mode */
42#define TIOCPKT_DATA 0
43#define TIOCPKT_FLUSHREAD 1
44#define TIOCPKT_FLUSHWRITE 2
45#define TIOCPKT_STOP 4
46#define TIOCPKT_START 8
47#define TIOCPKT_NOSTOP 16
48#define TIOCPKT_DOSTOP 32
49
50struct winsize { 41struct winsize {
51 unsigned short ws_row; 42 unsigned short ws_row;
52 unsigned short ws_col; 43 unsigned short ws_col;
diff --git a/include/asm-sparc64/tlb.h b/include/asm-sparc64/tlb.h
index 66138d959df5..61c01882b562 100644
--- a/include/asm-sparc64/tlb.h
+++ b/include/asm-sparc64/tlb.h
@@ -58,11 +58,9 @@ static inline struct mmu_gather *tlb_gather_mmu(struct mm_struct *mm, unsigned i
58static inline void tlb_flush_mmu(struct mmu_gather *mp) 58static inline void tlb_flush_mmu(struct mmu_gather *mp)
59{ 59{
60 if (mp->need_flush) { 60 if (mp->need_flush) {
61 free_pages_and_swap_cache(mp->pages, mp->pages_nr);
62 mp->pages_nr = 0;
61 mp->need_flush = 0; 63 mp->need_flush = 0;
62 if (!tlb_fast_mode(mp)) {
63 free_pages_and_swap_cache(mp->pages, mp->pages_nr);
64 mp->pages_nr = 0;
65 }
66 } 64 }
67 65
68} 66}
@@ -78,11 +76,9 @@ static inline void tlb_finish_mmu(struct mmu_gather *mp, unsigned long start, un
78{ 76{
79 tlb_flush_mmu(mp); 77 tlb_flush_mmu(mp);
80 78
81 if (mp->fullmm) { 79 if (mp->fullmm)
82 if (CTX_VALID(mp->mm->context))
83 do_flush_tlb_mm(mp->mm);
84 mp->fullmm = 0; 80 mp->fullmm = 0;
85 } else 81 else
86 flush_tlb_pending(); 82 flush_tlb_pending();
87 83
88 /* keep the page table cache within bounds */ 84 /* keep the page table cache within bounds */
@@ -93,11 +89,11 @@ static inline void tlb_finish_mmu(struct mmu_gather *mp, unsigned long start, un
93 89
94static inline void tlb_remove_page(struct mmu_gather *mp, struct page *page) 90static inline void tlb_remove_page(struct mmu_gather *mp, struct page *page)
95{ 91{
96 mp->need_flush = 1;
97 if (tlb_fast_mode(mp)) { 92 if (tlb_fast_mode(mp)) {
98 free_page_and_swap_cache(page); 93 free_page_and_swap_cache(page);
99 return; 94 return;
100 } 95 }
96 mp->need_flush = 1;
101 mp->pages[mp->pages_nr++] = page; 97 mp->pages[mp->pages_nr++] = page;
102 if (mp->pages_nr >= FREE_PTE_NR) 98 if (mp->pages_nr >= FREE_PTE_NR)
103 tlb_flush_mmu(mp); 99 tlb_flush_mmu(mp);
diff --git a/include/asm-sparc64/vuid_event.h b/include/asm-sparc64/vuid_event.h
deleted file mode 100644
index 9ef4d17ad08f..000000000000
--- a/include/asm-sparc64/vuid_event.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/* SunOS Virtual User Input Device (VUID) compatibility */
2
3typedef struct firm_event {
4 unsigned short id; /* tag for this event */
5 unsigned char pair_type; /* unused by X11 */
6 unsigned char pair; /* unused by X11 */
7 int value; /* VKEY_UP, VKEY_DOWN or delta */
8 struct timeval time;
9} Firm_event;
10
11enum {
12 FE_PAIR_NONE,
13 FE_PAIR_SET,
14 FE_PAIR_DELTA,
15 FE_PAIR_ABSOLUTE
16};
17
18/* VUID stream formats */
19#define VUID_NATIVE 0 /* Native byte stream format */
20#define VUID_FIRM_EVENT 1 /* send firm_event structures */
21
22/* ioctls */
23 /* Set input device byte stream format (any of VUID_{NATIVE,FIRM_EVENT}) */
24#define VUIDSFORMAT _IOW('v', 1, int)
25 /* Retrieve input device byte stream format */
26#define VUIDGFORMAT _IOR('v', 2, int)
27
28/* Possible tag values */
29/* mouse buttons: */
30#define MS_LEFT 0x7f20
31#define MS_MIDDLE 0x7f21
32#define MS_RIGHT 0x7f22
33/* motion: */
34#define LOC_X_DELTA 0x7f80
35#define LOC_Y_DELTA 0x7f81
36#define LOC_X_ABSOLUTE 0x7f82 /* X compat, unsupported */
37#define LOC_Y_ABSOLUTE 0x7f83 /* X compat, unsupported */
38
39#define VKEY_UP 0
40#define VKEY_DOWN 1
diff --git a/include/asm-um/ldt-i386.h b/include/asm-um/ldt-i386.h
new file mode 100644
index 000000000000..b42662929b6c
--- /dev/null
+++ b/include/asm-um/ldt-i386.h
@@ -0,0 +1,69 @@
1/*
2 * Copyright (C) 2004 Fujitsu Siemens Computers GmbH
3 * Licensed under the GPL
4 *
5 * Author: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
6 */
7
8#ifndef __ASM_LDT_I386_H
9#define __ASM_LDT_I386_H
10
11#include "asm/semaphore.h"
12#include "asm/arch/ldt.h"
13
14struct mmu_context_skas;
15extern void ldt_host_info(void);
16extern long init_new_ldt(struct mmu_context_skas * to_mm,
17 struct mmu_context_skas * from_mm);
18extern void free_ldt(struct mmu_context_skas * mm);
19
20#define LDT_PAGES_MAX \
21 ((LDT_ENTRIES * LDT_ENTRY_SIZE)/PAGE_SIZE)
22#define LDT_ENTRIES_PER_PAGE \
23 (PAGE_SIZE/LDT_ENTRY_SIZE)
24#define LDT_DIRECT_ENTRIES \
25 ((LDT_PAGES_MAX*sizeof(void *))/LDT_ENTRY_SIZE)
26
27struct ldt_entry {
28 __u32 a;
29 __u32 b;
30};
31
32typedef struct uml_ldt {
33 int entry_count;
34 struct semaphore semaphore;
35 union {
36 struct ldt_entry * pages[LDT_PAGES_MAX];
37 struct ldt_entry entries[LDT_DIRECT_ENTRIES];
38 };
39} uml_ldt_t;
40
41/*
42 * macros stolen from include/asm-i386/desc.h
43 */
44#define LDT_entry_a(info) \
45 ((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
46
47#define LDT_entry_b(info) \
48 (((info)->base_addr & 0xff000000) | \
49 (((info)->base_addr & 0x00ff0000) >> 16) | \
50 ((info)->limit & 0xf0000) | \
51 (((info)->read_exec_only ^ 1) << 9) | \
52 ((info)->contents << 10) | \
53 (((info)->seg_not_present ^ 1) << 15) | \
54 ((info)->seg_32bit << 22) | \
55 ((info)->limit_in_pages << 23) | \
56 ((info)->useable << 20) | \
57 0x7000)
58
59#define LDT_empty(info) (\
60 (info)->base_addr == 0 && \
61 (info)->limit == 0 && \
62 (info)->contents == 0 && \
63 (info)->read_exec_only == 1 && \
64 (info)->seg_32bit == 0 && \
65 (info)->limit_in_pages == 0 && \
66 (info)->seg_not_present == 1 && \
67 (info)->useable == 0 )
68
69#endif
diff --git a/include/asm-um/ldt.h b/include/asm-um/ldt.h
index e908439d338a..4466ff6de0fd 100644
--- a/include/asm-um/ldt.h
+++ b/include/asm-um/ldt.h
@@ -1,3 +1,72 @@
1/*
2 * Copyright (C) 2004 Fujitsu Siemens Computers GmbH
3 * Licensed under the GPL
4 *
5 * Author: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
6 */
7
8#ifndef __ASM_LDT_I386_H
9#define __ASM_LDT_I386_H
10
11#include "asm/semaphore.h"
12#include "asm/arch/ldt.h"
13
14struct mmu_context_skas;
15extern void ldt_host_info(void);
16extern long init_new_ldt(struct mmu_context_skas * to_mm,
17 struct mmu_context_skas * from_mm);
18extern void free_ldt(struct mmu_context_skas * mm);
19
20#define LDT_PAGES_MAX \
21 ((LDT_ENTRIES * LDT_ENTRY_SIZE)/PAGE_SIZE)
22#define LDT_ENTRIES_PER_PAGE \
23 (PAGE_SIZE/LDT_ENTRY_SIZE)
24#define LDT_DIRECT_ENTRIES \
25 ((LDT_PAGES_MAX*sizeof(void *))/LDT_ENTRY_SIZE)
26
27struct ldt_entry {
28 __u32 a;
29 __u32 b;
30};
31
32typedef struct uml_ldt {
33 int entry_count;
34 struct semaphore semaphore;
35 union {
36 struct ldt_entry * pages[LDT_PAGES_MAX];
37 struct ldt_entry entries[LDT_DIRECT_ENTRIES];
38 };
39} uml_ldt_t;
40
41/*
42 * macros stolen from include/asm-i386/desc.h
43 */
44#define LDT_entry_a(info) \
45 ((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
46
47#define LDT_entry_b(info) \
48 (((info)->base_addr & 0xff000000) | \
49 (((info)->base_addr & 0x00ff0000) >> 16) | \
50 ((info)->limit & 0xf0000) | \
51 (((info)->read_exec_only ^ 1) << 9) | \
52 ((info)->contents << 10) | \
53 (((info)->seg_not_present ^ 1) << 15) | \
54 ((info)->seg_32bit << 22) | \
55 ((info)->limit_in_pages << 23) | \
56 ((info)->useable << 20) | \
57 0x7000)
58
59#define LDT_empty(info) (\
60 (info)->base_addr == 0 && \
61 (info)->limit == 0 && \
62 (info)->contents == 0 && \
63 (info)->read_exec_only == 1 && \
64 (info)->seg_32bit == 0 && \
65 (info)->limit_in_pages == 0 && \
66 (info)->seg_not_present == 1 && \
67 (info)->useable == 0 )
68
69#endif
1#ifndef __UM_LDT_H 70#ifndef __UM_LDT_H
2#define __UM_LDT_H 71#define __UM_LDT_H
3 72
diff --git a/include/asm-um/mmu_context.h b/include/asm-um/mmu_context.h
index 2edb4f1f789c..9a0e48eb542e 100644
--- a/include/asm-um/mmu_context.h
+++ b/include/asm-um/mmu_context.h
@@ -29,7 +29,8 @@ static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)
29 * possible. 29 * possible.
30 */ 30 */
31 if (old != new && (current->flags & PF_BORROWED_MM)) 31 if (old != new && (current->flags & PF_BORROWED_MM))
32 force_flush_all(); 32 CHOOSE_MODE(force_flush_all(),
33 switch_mm_skas(&new->context.skas.id));
33} 34}
34 35
35static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, 36static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
diff --git a/include/asm-v850/atomic.h b/include/asm-v850/atomic.h
index 8284aa7363f2..395268a8c0de 100644
--- a/include/asm-v850/atomic.h
+++ b/include/asm-v850/atomic.h
@@ -31,7 +31,7 @@ typedef struct { int counter; } atomic_t;
31#define atomic_read(v) ((v)->counter) 31#define atomic_read(v) ((v)->counter)
32#define atomic_set(v,i) (((v)->counter) = (i)) 32#define atomic_set(v,i) (((v)->counter) = (i))
33 33
34extern __inline__ int atomic_add_return (int i, volatile atomic_t *v) 34static inline int atomic_add_return (int i, volatile atomic_t *v)
35{ 35{
36 unsigned long flags; 36 unsigned long flags;
37 int res; 37 int res;
diff --git a/include/asm-v850/bitops.h b/include/asm-v850/bitops.h
index 0e5c2f210872..b91e799763fd 100644
--- a/include/asm-v850/bitops.h
+++ b/include/asm-v850/bitops.h
@@ -30,7 +30,7 @@
30 * ffz = Find First Zero in word. Undefined if no zero exists, 30 * ffz = Find First Zero in word. Undefined if no zero exists,
31 * so code should check against ~0UL first.. 31 * so code should check against ~0UL first..
32 */ 32 */
33extern __inline__ unsigned long ffz (unsigned long word) 33static inline unsigned long ffz (unsigned long word)
34{ 34{
35 unsigned long result = 0; 35 unsigned long result = 0;
36 36
@@ -135,7 +135,7 @@ extern __inline__ unsigned long ffz (unsigned long word)
135 "m" (*((const char *)(addr) + ((nr) >> 3)))); \ 135 "m" (*((const char *)(addr) + ((nr) >> 3)))); \
136 __test_bit_res; \ 136 __test_bit_res; \
137 }) 137 })
138extern __inline__ int __test_bit (int nr, const void *addr) 138static inline int __test_bit (int nr, const void *addr)
139{ 139{
140 int res; 140 int res;
141 __asm__ __volatile__ ("tst1 %1, [%2]; setf nz, %0" 141 __asm__ __volatile__ ("tst1 %1, [%2]; setf nz, %0"
@@ -157,7 +157,7 @@ extern __inline__ int __test_bit (int nr, const void *addr)
157#define find_first_zero_bit(addr, size) \ 157#define find_first_zero_bit(addr, size) \
158 find_next_zero_bit ((addr), (size), 0) 158 find_next_zero_bit ((addr), (size), 0)
159 159
160extern __inline__ int find_next_zero_bit(const void *addr, int size, int offset) 160static inline int find_next_zero_bit(const void *addr, int size, int offset)
161{ 161{
162 unsigned long *p = ((unsigned long *) addr) + (offset >> 5); 162 unsigned long *p = ((unsigned long *) addr) + (offset >> 5);
163 unsigned long result = offset & ~31UL; 163 unsigned long result = offset & ~31UL;
diff --git a/include/asm-v850/delay.h b/include/asm-v850/delay.h
index 1ce65d48a7c5..6d028e6b2354 100644
--- a/include/asm-v850/delay.h
+++ b/include/asm-v850/delay.h
@@ -16,7 +16,7 @@
16 16
17#include <asm/param.h> 17#include <asm/param.h>
18 18
19extern __inline__ void __delay(unsigned long loops) 19static inline void __delay(unsigned long loops)
20{ 20{
21 if (loops) 21 if (loops)
22 __asm__ __volatile__ ("1: add -1, %0; bnz 1b" 22 __asm__ __volatile__ ("1: add -1, %0; bnz 1b"
@@ -33,7 +33,7 @@ extern __inline__ void __delay(unsigned long loops)
33 33
34extern unsigned long loops_per_jiffy; 34extern unsigned long loops_per_jiffy;
35 35
36extern __inline__ void udelay(unsigned long usecs) 36static inline void udelay(unsigned long usecs)
37{ 37{
38 register unsigned long full_loops, part_loops; 38 register unsigned long full_loops, part_loops;
39 39
diff --git a/include/asm-v850/hw_irq.h b/include/asm-v850/hw_irq.h
index 4bdc98edb9f8..a8aab4342712 100644
--- a/include/asm-v850/hw_irq.h
+++ b/include/asm-v850/hw_irq.h
@@ -1,7 +1,7 @@
1#ifndef __V850_HW_IRQ_H__ 1#ifndef __V850_HW_IRQ_H__
2#define __V850_HW_IRQ_H__ 2#define __V850_HW_IRQ_H__
3 3
4extern inline void hw_resend_irq (struct hw_interrupt_type *h, unsigned int i) 4static inline void hw_resend_irq (struct hw_interrupt_type *h, unsigned int i)
5{ 5{
6} 6}
7 7
diff --git a/include/asm-v850/processor.h b/include/asm-v850/processor.h
index d41f925f5182..98f929427d3d 100644
--- a/include/asm-v850/processor.h
+++ b/include/asm-v850/processor.h
@@ -59,7 +59,7 @@ struct thread_struct {
59 59
60 60
61/* Do necessary setup to start up a newly executed thread. */ 61/* Do necessary setup to start up a newly executed thread. */
62extern inline void start_thread (struct pt_regs *regs, 62static inline void start_thread (struct pt_regs *regs,
63 unsigned long pc, unsigned long usp) 63 unsigned long pc, unsigned long usp)
64{ 64{
65 regs->pc = pc; 65 regs->pc = pc;
@@ -68,7 +68,7 @@ extern inline void start_thread (struct pt_regs *regs,
68} 68}
69 69
70/* Free all resources held by a thread. */ 70/* Free all resources held by a thread. */
71extern inline void release_thread (struct task_struct *dead_task) 71static inline void release_thread (struct task_struct *dead_task)
72{ 72{
73} 73}
74 74
diff --git a/include/asm-v850/semaphore.h b/include/asm-v850/semaphore.h
index df6cdecf6c1f..735baaf3a16e 100644
--- a/include/asm-v850/semaphore.h
+++ b/include/asm-v850/semaphore.h
@@ -24,7 +24,7 @@ struct semaphore {
24#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC (name,1) 24#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC (name,1)
25#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC (name,0) 25#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC (name,0)
26 26
27extern inline void sema_init (struct semaphore *sem, int val) 27static inline void sema_init (struct semaphore *sem, int val)
28{ 28{
29 *sem = (struct semaphore)__SEMAPHORE_INITIALIZER((*sem),val); 29 *sem = (struct semaphore)__SEMAPHORE_INITIALIZER((*sem),val);
30} 30}
@@ -52,14 +52,14 @@ extern int __down_interruptible (struct semaphore * sem);
52extern int __down_trylock (struct semaphore * sem); 52extern int __down_trylock (struct semaphore * sem);
53extern void __up (struct semaphore * sem); 53extern void __up (struct semaphore * sem);
54 54
55extern inline void down (struct semaphore * sem) 55static inline void down (struct semaphore * sem)
56{ 56{
57 might_sleep(); 57 might_sleep();
58 if (atomic_dec_return (&sem->count) < 0) 58 if (atomic_dec_return (&sem->count) < 0)
59 __down (sem); 59 __down (sem);
60} 60}
61 61
62extern inline int down_interruptible (struct semaphore * sem) 62static inline int down_interruptible (struct semaphore * sem)
63{ 63{
64 int ret = 0; 64 int ret = 0;
65 might_sleep(); 65 might_sleep();
@@ -68,7 +68,7 @@ extern inline int down_interruptible (struct semaphore * sem)
68 return ret; 68 return ret;
69} 69}
70 70
71extern inline int down_trylock (struct semaphore *sem) 71static inline int down_trylock (struct semaphore *sem)
72{ 72{
73 int ret = 0; 73 int ret = 0;
74 if (atomic_dec_return (&sem->count) < 0) 74 if (atomic_dec_return (&sem->count) < 0)
@@ -76,7 +76,7 @@ extern inline int down_trylock (struct semaphore *sem)
76 return ret; 76 return ret;
77} 77}
78 78
79extern inline void up (struct semaphore * sem) 79static inline void up (struct semaphore * sem)
80{ 80{
81 if (atomic_inc_return (&sem->count) <= 0) 81 if (atomic_inc_return (&sem->count) <= 0)
82 __up (sem); 82 __up (sem);
diff --git a/include/asm-v850/system.h b/include/asm-v850/system.h
index 20f4c738c04e..107decbd6e6c 100644
--- a/include/asm-v850/system.h
+++ b/include/asm-v850/system.h
@@ -81,7 +81,7 @@ static inline int irqs_disabled (void)
81 ((__typeof__ (*(ptr)))__xchg ((unsigned long)(with), (ptr), sizeof (*(ptr)))) 81 ((__typeof__ (*(ptr)))__xchg ((unsigned long)(with), (ptr), sizeof (*(ptr))))
82#define tas(ptr) (xchg ((ptr), 1)) 82#define tas(ptr) (xchg ((ptr), 1))
83 83
84extern inline unsigned long __xchg (unsigned long with, 84static inline unsigned long __xchg (unsigned long with,
85 __volatile__ void *ptr, int size) 85 __volatile__ void *ptr, int size)
86{ 86{
87 unsigned long tmp, flags; 87 unsigned long tmp, flags;
diff --git a/include/asm-v850/tlbflush.h b/include/asm-v850/tlbflush.h
index 501e4498172c..5f2f85f636ea 100644
--- a/include/asm-v850/tlbflush.h
+++ b/include/asm-v850/tlbflush.h
@@ -56,12 +56,12 @@ static inline void flush_tlb_range(struct vm_area_struct *vma,
56 BUG (); 56 BUG ();
57} 57}
58 58
59extern inline void flush_tlb_kernel_page(unsigned long addr) 59static inline void flush_tlb_kernel_page(unsigned long addr)
60{ 60{
61 BUG (); 61 BUG ();
62} 62}
63 63
64extern inline void flush_tlb_pgtables(struct mm_struct *mm, 64static inline void flush_tlb_pgtables(struct mm_struct *mm,
65 unsigned long start, unsigned long end) 65 unsigned long start, unsigned long end)
66{ 66{
67 BUG (); 67 BUG ();
diff --git a/include/asm-v850/uaccess.h b/include/asm-v850/uaccess.h
index 188b28597cf1..64563c409bb2 100644
--- a/include/asm-v850/uaccess.h
+++ b/include/asm-v850/uaccess.h
@@ -14,7 +14,7 @@
14#define VERIFY_READ 0 14#define VERIFY_READ 0
15#define VERIFY_WRITE 1 15#define VERIFY_WRITE 1
16 16
17extern inline int access_ok (int type, const void *addr, unsigned long size) 17static inline int access_ok (int type, const void *addr, unsigned long size)
18{ 18{
19 /* XXX I guess we should check against real ram bounds at least, and 19 /* XXX I guess we should check against real ram bounds at least, and
20 possibly make sure ADDR is not within the kernel. 20 possibly make sure ADDR is not within the kernel.
diff --git a/include/asm-v850/unaligned.h b/include/asm-v850/unaligned.h
index 65e38362142b..e30b18653a94 100644
--- a/include/asm-v850/unaligned.h
+++ b/include/asm-v850/unaligned.h
@@ -82,19 +82,19 @@ extern int __bug_unaligned_x(void *ptr);
82 }) 82 })
83 83
84 84
85extern inline void __put_unaligned_2(__u32 __v, register __u8 *__p) 85static inline void __put_unaligned_2(__u32 __v, register __u8 *__p)
86{ 86{
87 *__p++ = __v; 87 *__p++ = __v;
88 *__p++ = __v >> 8; 88 *__p++ = __v >> 8;
89} 89}
90 90
91extern inline void __put_unaligned_4(__u32 __v, register __u8 *__p) 91static inline void __put_unaligned_4(__u32 __v, register __u8 *__p)
92{ 92{
93 __put_unaligned_2(__v >> 16, __p + 2); 93 __put_unaligned_2(__v >> 16, __p + 2);
94 __put_unaligned_2(__v, __p); 94 __put_unaligned_2(__v, __p);
95} 95}
96 96
97extern inline void __put_unaligned_8(const unsigned long long __v, register __u8 *__p) 97static inline void __put_unaligned_8(const unsigned long long __v, register __u8 *__p)
98{ 98{
99 /* 99 /*
100 * tradeoff: 8 bytes of stack for all unaligned puts (2 100 * tradeoff: 8 bytes of stack for all unaligned puts (2
diff --git a/include/asm-x86_64/elf.h b/include/asm-x86_64/elf.h
index a60a35e79222..43862cd6a569 100644
--- a/include/asm-x86_64/elf.h
+++ b/include/asm-x86_64/elf.h
@@ -149,6 +149,8 @@ extern void set_personality_64bit(void);
149 */ 149 */
150#define elf_read_implies_exec(ex, executable_stack) (executable_stack != EXSTACK_DISABLE_X) 150#define elf_read_implies_exec(ex, executable_stack) (executable_stack != EXSTACK_DISABLE_X)
151 151
152struct task_struct;
153
152extern int dump_task_regs (struct task_struct *, elf_gregset_t *); 154extern int dump_task_regs (struct task_struct *, elf_gregset_t *);
153extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *); 155extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *);
154 156
diff --git a/include/asm-x86_64/kprobes.h b/include/asm-x86_64/kprobes.h
index 6d6d883fdf6d..4dd7a7e148d4 100644
--- a/include/asm-x86_64/kprobes.h
+++ b/include/asm-x86_64/kprobes.h
@@ -25,6 +25,7 @@
25 */ 25 */
26#include <linux/types.h> 26#include <linux/types.h>
27#include <linux/ptrace.h> 27#include <linux/ptrace.h>
28#include <linux/percpu.h>
28 29
29struct pt_regs; 30struct pt_regs;
30 31
@@ -48,6 +49,24 @@ struct arch_specific_insn {
48 kprobe_opcode_t *insn; 49 kprobe_opcode_t *insn;
49}; 50};
50 51
52struct prev_kprobe {
53 struct kprobe *kp;
54 unsigned long status;
55 unsigned long old_rflags;
56 unsigned long saved_rflags;
57};
58
59/* per-cpu kprobe control block */
60struct kprobe_ctlblk {
61 unsigned long kprobe_status;
62 unsigned long kprobe_old_rflags;
63 unsigned long kprobe_saved_rflags;
64 long *jprobe_saved_rsp;
65 struct pt_regs jprobe_saved_regs;
66 kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE];
67 struct prev_kprobe prev_kprobe;
68};
69
51/* trap3/1 are intr gates for kprobes. So, restore the status of IF, 70/* trap3/1 are intr gates for kprobes. So, restore the status of IF,
52 * if necessary, before executing the original int3/1 (trap) handler. 71 * if necessary, before executing the original int3/1 (trap) handler.
53 */ 72 */
diff --git a/include/asm-x86_64/pgtable.h b/include/asm-x86_64/pgtable.h
index 7a07196a7202..7309fffeec9a 100644
--- a/include/asm-x86_64/pgtable.h
+++ b/include/asm-x86_64/pgtable.h
@@ -105,6 +105,8 @@ static inline void pgd_clear (pgd_t * pgd)
105 105
106#define ptep_get_and_clear(mm,addr,xp) __pte(xchg(&(xp)->pte, 0)) 106#define ptep_get_and_clear(mm,addr,xp) __pte(xchg(&(xp)->pte, 0))
107 107
108struct mm_struct;
109
108static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, unsigned long addr, pte_t *ptep, int full) 110static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, unsigned long addr, pte_t *ptep, int full)
109{ 111{
110 pte_t pte; 112 pte_t pte;
diff --git a/include/asm-xtensa/elf.h b/include/asm-xtensa/elf.h
index 64f1f53874fe..de0667453b2e 100644
--- a/include/asm-xtensa/elf.h
+++ b/include/asm-xtensa/elf.h
@@ -209,6 +209,8 @@ extern void xtensa_elf_core_copy_regs (xtensa_gregset_t *, struct pt_regs *);
209 209
210#define SET_PERSONALITY(ex, ibcs2) set_personality(PER_LINUX_32BIT) 210#define SET_PERSONALITY(ex, ibcs2) set_personality(PER_LINUX_32BIT)
211 211
212struct task_struct;
213
212extern void do_copy_regs (xtensa_gregset_t*, struct pt_regs*, 214extern void do_copy_regs (xtensa_gregset_t*, struct pt_regs*,
213 struct task_struct*); 215 struct task_struct*);
214extern void do_restore_regs (xtensa_gregset_t*, struct pt_regs*, 216extern void do_restore_regs (xtensa_gregset_t*, struct pt_regs*,
diff --git a/include/asm-xtensa/pgtable.h b/include/asm-xtensa/pgtable.h
index 987e3b802313..7b15afb70c56 100644
--- a/include/asm-xtensa/pgtable.h
+++ b/include/asm-xtensa/pgtable.h
@@ -278,6 +278,8 @@ static inline void update_pte(pte_t *ptep, pte_t pteval)
278#endif 278#endif
279} 279}
280 280
281struct mm_struct;
282
281static inline void 283static inline void
282set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pteval) 284set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pteval)
283{ 285{
@@ -294,6 +296,7 @@ set_pmd(pmd_t *pmdp, pmd_t pmdval)
294#endif 296#endif
295} 297}
296 298
299struct vm_area_struct;
297 300
298static inline int 301static inline int
299ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, 302ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr,
diff --git a/include/asm-xtensa/semaphore.h b/include/asm-xtensa/semaphore.h
index 2a10e193b929..f10c3487cd4c 100644
--- a/include/asm-xtensa/semaphore.h
+++ b/include/asm-xtensa/semaphore.h
@@ -38,6 +38,7 @@ struct semaphore {
38static inline void sema_init (struct semaphore *sem, int val) 38static inline void sema_init (struct semaphore *sem, int val)
39{ 39{
40 atomic_set(&sem->count, val); 40 atomic_set(&sem->count, val);
41 sem->sleepers = 0;
41 init_waitqueue_head(&sem->wait); 42 init_waitqueue_head(&sem->wait);
42} 43}
43 44
diff --git a/include/linux/acct.h b/include/linux/acct.h
index 19f70462b3be..93c5b3cdf951 100644
--- a/include/linux/acct.h
+++ b/include/linux/acct.h
@@ -117,12 +117,15 @@ struct acct_v3
117#include <linux/config.h> 117#include <linux/config.h>
118 118
119#ifdef CONFIG_BSD_PROCESS_ACCT 119#ifdef CONFIG_BSD_PROCESS_ACCT
120struct vfsmount;
120struct super_block; 121struct super_block;
122extern void acct_auto_close_mnt(struct vfsmount *m);
121extern void acct_auto_close(struct super_block *sb); 123extern void acct_auto_close(struct super_block *sb);
122extern void acct_process(long exitcode); 124extern void acct_process(long exitcode);
123extern void acct_update_integrals(struct task_struct *tsk); 125extern void acct_update_integrals(struct task_struct *tsk);
124extern void acct_clear_integrals(struct task_struct *tsk); 126extern void acct_clear_integrals(struct task_struct *tsk);
125#else 127#else
128#define acct_auto_close_mnt(x) do { } while (0)
126#define acct_auto_close(x) do { } while (0) 129#define acct_auto_close(x) do { } while (0)
127#define acct_process(x) do { } while (0) 130#define acct_process(x) do { } while (0)
128#define acct_update_integrals(x) do { } while (0) 131#define acct_update_integrals(x) do { } while (0)
diff --git a/include/linux/aio.h b/include/linux/aio.h
index 0decf66117c1..403d71dcb7c8 100644
--- a/include/linux/aio.h
+++ b/include/linux/aio.h
@@ -183,6 +183,7 @@ struct kioctx {
183 struct list_head active_reqs; /* used for cancellation */ 183 struct list_head active_reqs; /* used for cancellation */
184 struct list_head run_list; /* used for kicked reqs */ 184 struct list_head run_list; /* used for kicked reqs */
185 185
186 /* sys_io_setup currently limits this to an unsigned int */
186 unsigned max_reqs; 187 unsigned max_reqs;
187 188
188 struct aio_ring_info ring_info; 189 struct aio_ring_info ring_info;
@@ -234,7 +235,7 @@ static inline struct kiocb *list_kiocb(struct list_head *h)
234} 235}
235 236
236/* for sysctl: */ 237/* for sysctl: */
237extern atomic_t aio_nr; 238extern unsigned long aio_nr;
238extern unsigned aio_max_nr; 239extern unsigned long aio_max_nr;
239 240
240#endif /* __LINUX__AIO_H */ 241#endif /* __LINUX__AIO_H */
diff --git a/include/linux/cn_proc.h b/include/linux/cn_proc.h
new file mode 100644
index 000000000000..70ab56317380
--- /dev/null
+++ b/include/linux/cn_proc.h
@@ -0,0 +1,127 @@
1/*
2 * cn_proc.h - process events connector
3 *
4 * Copyright (C) Matt Helsley, IBM Corp. 2005
5 * Based on cn_fork.h by Nguyen Anh Quynh and Guillaume Thouvenin
6 * Original copyright notice follows:
7 * Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com>
8 * Copyright (C) 2005 Guillaume Thouvenin <guillaume.thouvenin@bull.net>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#ifndef CN_PROC_H
26#define CN_PROC_H
27
28#include <linux/types.h>
29#include <linux/connector.h>
30
31/*
32 * Userspace sends this enum to register with the kernel that it is listening
33 * for events on the connector.
34 */
35enum proc_cn_mcast_op {
36 PROC_CN_MCAST_LISTEN = 1,
37 PROC_CN_MCAST_IGNORE = 2
38};
39
40/*
41 * From the user's point of view, the process
42 * ID is the thread group ID and thread ID is the internal
43 * kernel "pid". So, fields are assigned as follow:
44 *
45 * In user space - In kernel space
46 *
47 * parent process ID = parent->tgid
48 * parent thread ID = parent->pid
49 * child process ID = child->tgid
50 * child thread ID = child->pid
51 */
52
53struct proc_event {
54 enum what {
55 /* Use successive bits so the enums can be used to record
56 * sets of events as well
57 */
58 PROC_EVENT_NONE = 0x00000000,
59 PROC_EVENT_FORK = 0x00000001,
60 PROC_EVENT_EXEC = 0x00000002,
61 PROC_EVENT_UID = 0x00000004,
62 PROC_EVENT_GID = 0x00000040,
63 /* "next" should be 0x00000400 */
64 /* "last" is the last process event: exit */
65 PROC_EVENT_EXIT = 0x80000000
66 } what;
67 __u32 cpu;
68 union { /* must be last field of proc_event struct */
69 struct {
70 __u32 err;
71 } ack;
72
73 struct fork_proc_event {
74 pid_t parent_pid;
75 pid_t parent_tgid;
76 pid_t child_pid;
77 pid_t child_tgid;
78 } fork;
79
80 struct exec_proc_event {
81 pid_t process_pid;
82 pid_t process_tgid;
83 } exec;
84
85 struct id_proc_event {
86 pid_t process_pid;
87 pid_t process_tgid;
88 union {
89 uid_t ruid; /* current->uid */
90 gid_t rgid; /* current->gid */
91 } r;
92 union {
93 uid_t euid;
94 gid_t egid;
95 } e;
96 } id;
97
98 struct exit_proc_event {
99 pid_t process_pid;
100 pid_t process_tgid;
101 __u32 exit_code, exit_signal;
102 } exit;
103 } event_data;
104};
105
106#ifdef __KERNEL__
107#ifdef CONFIG_PROC_EVENTS
108void proc_fork_connector(struct task_struct *task);
109void proc_exec_connector(struct task_struct *task);
110void proc_id_connector(struct task_struct *task, int which_id);
111void proc_exit_connector(struct task_struct *task);
112#else
113static inline void proc_fork_connector(struct task_struct *task)
114{}
115
116static inline void proc_exec_connector(struct task_struct *task)
117{}
118
119static inline void proc_id_connector(struct task_struct *task,
120 int which_id)
121{}
122
123static inline void proc_exit_connector(struct task_struct *task)
124{}
125#endif /* CONFIG_PROC_EVENTS */
126#endif /* __KERNEL__ */
127#endif /* CN_PROC_H */
diff --git a/include/linux/connector.h b/include/linux/connector.h
index 95952cc1f525..c5769c6585f4 100644
--- a/include/linux/connector.h
+++ b/include/linux/connector.h
@@ -27,6 +27,12 @@
27#define CN_IDX_CONNECTOR 0xffffffff 27#define CN_IDX_CONNECTOR 0xffffffff
28#define CN_VAL_CONNECTOR 0xffffffff 28#define CN_VAL_CONNECTOR 0xffffffff
29 29
30/*
31 * Process Events connector unique ids -- used for message routing
32 */
33#define CN_IDX_PROC 0x1
34#define CN_VAL_PROC 0x1
35
30#define CN_NETLINK_USERS 1 36#define CN_NETLINK_USERS 1
31 37
32/* 38/*
diff --git a/include/linux/console_struct.h b/include/linux/console_struct.h
index 725be90ef55e..f8e5587a0f92 100644
--- a/include/linux/console_struct.h
+++ b/include/linux/console_struct.h
@@ -9,6 +9,8 @@
9 * to achieve effects such as fast scrolling by changing the origin. 9 * to achieve effects such as fast scrolling by changing the origin.
10 */ 10 */
11 11
12#include <linux/vt.h>
13
12struct vt_struct; 14struct vt_struct;
13 15
14#define NPAR 16 16#define NPAR 16
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index ab04b4f9b0db..46a2ba617595 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -329,6 +329,7 @@ static inline int d_mountpoint(struct dentry *dentry)
329} 329}
330 330
331extern struct vfsmount *lookup_mnt(struct vfsmount *, struct dentry *); 331extern struct vfsmount *lookup_mnt(struct vfsmount *, struct dentry *);
332extern struct vfsmount *__lookup_mnt(struct vfsmount *, struct dentry *, int);
332extern struct dentry *lookup_create(struct nameidata *nd, int is_dir); 333extern struct dentry *lookup_create(struct nameidata *nd, int is_dir);
333 334
334extern int sysctl_vfs_cache_pressure; 335extern int sysctl_vfs_cache_pressure;
diff --git a/include/linux/fb.h b/include/linux/fb.h
index c698055266d0..e7ff98e395f6 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -810,7 +810,6 @@ struct fb_info {
810extern int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var); 810extern int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var);
811extern int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var); 811extern int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var);
812extern int fb_blank(struct fb_info *info, int blank); 812extern int fb_blank(struct fb_info *info, int blank);
813extern int soft_cursor(struct fb_info *info, struct fb_cursor *cursor);
814extern void cfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect); 813extern void cfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
815extern void cfb_copyarea(struct fb_info *info, const struct fb_copyarea *area); 814extern void cfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
816extern void cfb_imageblit(struct fb_info *info, const struct fb_image *image); 815extern void cfb_imageblit(struct fb_info *info, const struct fb_image *image);
@@ -898,11 +897,13 @@ extern struct fb_videomode *fb_match_mode(struct fb_var_screeninfo *var,
898 struct list_head *head); 897 struct list_head *head);
899extern struct fb_videomode *fb_find_best_mode(struct fb_var_screeninfo *var, 898extern struct fb_videomode *fb_find_best_mode(struct fb_var_screeninfo *var,
900 struct list_head *head); 899 struct list_head *head);
901extern struct fb_videomode *fb_find_nearest_mode(struct fb_var_screeninfo *var, 900extern struct fb_videomode *fb_find_nearest_mode(struct fb_videomode *mode,
902 struct list_head *head); 901 struct list_head *head);
903extern void fb_destroy_modelist(struct list_head *head); 902extern void fb_destroy_modelist(struct list_head *head);
904extern void fb_videomode_to_modelist(struct fb_videomode *modedb, int num, 903extern void fb_videomode_to_modelist(struct fb_videomode *modedb, int num,
905 struct list_head *head); 904 struct list_head *head);
905extern struct fb_videomode *fb_find_best_display(struct fb_monspecs *specs,
906 struct list_head *head);
906 907
907/* drivers/video/fbcmap.c */ 908/* drivers/video/fbcmap.c */
908extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp); 909extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp);
diff --git a/include/linux/file.h b/include/linux/file.h
index f5bbd4c508b3..d3b1a15d5f21 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -59,9 +59,9 @@ extern void FASTCALL(set_close_on_exec(unsigned int fd, int flag));
59extern void put_filp(struct file *); 59extern void put_filp(struct file *);
60extern int get_unused_fd(void); 60extern int get_unused_fd(void);
61extern void FASTCALL(put_unused_fd(unsigned int fd)); 61extern void FASTCALL(put_unused_fd(unsigned int fd));
62struct kmem_cache_s; 62struct kmem_cache;
63extern void filp_ctor(void * objp, struct kmem_cache_s *cachep, unsigned long cflags); 63extern void filp_ctor(void * objp, struct kmem_cache *cachep, unsigned long cflags);
64extern void filp_dtor(void * objp, struct kmem_cache_s *cachep, unsigned long dflags); 64extern void filp_dtor(void * objp, struct kmem_cache *cachep, unsigned long dflags);
65 65
66extern struct file ** alloc_fd_array(int); 66extern struct file ** alloc_fd_array(int);
67extern void free_fd_array(struct file **, int); 67extern void free_fd_array(struct file **, int);
diff --git a/include/linux/font.h b/include/linux/font.h
index 53b129f07f6f..8aac48c37f3d 100644
--- a/include/linux/font.h
+++ b/include/linux/font.h
@@ -31,6 +31,7 @@ struct font_desc {
31#define SUN12x22_IDX 7 31#define SUN12x22_IDX 7
32#define ACORN8x8_IDX 8 32#define ACORN8x8_IDX 8
33#define MINI4x6_IDX 9 33#define MINI4x6_IDX 9
34#define RL_IDX 10
34 35
35extern const struct font_desc font_vga_8x8, 36extern const struct font_desc font_vga_8x8,
36 font_vga_8x16, 37 font_vga_8x16,
@@ -41,6 +42,7 @@ extern const struct font_desc font_vga_8x8,
41 font_sun_8x16, 42 font_sun_8x16,
42 font_sun_12x22, 43 font_sun_12x22,
43 font_acorn_8x8, 44 font_acorn_8x8,
45 font_rl,
44 font_mini_4x6; 46 font_mini_4x6;
45 47
46/* Find a font with a specific name */ 48/* Find a font with a specific name */
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 6d6226732c93..1b5f502a4b8f 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -104,6 +104,10 @@ extern int dir_notify_enable;
104#define MS_MOVE 8192 104#define MS_MOVE 8192
105#define MS_REC 16384 105#define MS_REC 16384
106#define MS_VERBOSE 32768 106#define MS_VERBOSE 32768
107#define MS_UNBINDABLE (1<<17) /* change to unbindable */
108#define MS_PRIVATE (1<<18) /* change to private */
109#define MS_SLAVE (1<<19) /* change to slave */
110#define MS_SHARED (1<<20) /* change to shared */
107#define MS_POSIXACL (1<<16) /* VFS does not apply the umask */ 111#define MS_POSIXACL (1<<16) /* VFS does not apply the umask */
108#define MS_ACTIVE (1<<30) 112#define MS_ACTIVE (1<<30)
109#define MS_NOUSER (1<<31) 113#define MS_NOUSER (1<<31)
@@ -264,6 +268,7 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
264#define ATTR_ATTR_FLAG 1024 268#define ATTR_ATTR_FLAG 1024
265#define ATTR_KILL_SUID 2048 269#define ATTR_KILL_SUID 2048
266#define ATTR_KILL_SGID 4096 270#define ATTR_KILL_SGID 4096
271#define ATTR_FILE 8192
267 272
268/* 273/*
269 * This is the Inode Attributes structure, used for notify_change(). It 274 * This is the Inode Attributes structure, used for notify_change(). It
@@ -283,6 +288,13 @@ struct iattr {
283 struct timespec ia_atime; 288 struct timespec ia_atime;
284 struct timespec ia_mtime; 289 struct timespec ia_mtime;
285 struct timespec ia_ctime; 290 struct timespec ia_ctime;
291
292 /*
293 * Not an attribute, but an auxilary info for filesystems wanting to
294 * implement an ftruncate() like method. NOTE: filesystem should
295 * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
296 */
297 struct file *ia_file;
286}; 298};
287 299
288/* 300/*
@@ -1088,6 +1100,8 @@ int sync_inode(struct inode *inode, struct writeback_control *wbc);
1088 * @get_name: find the name for a given inode in a given directory 1100 * @get_name: find the name for a given inode in a given directory
1089 * @get_parent: find the parent of a given directory 1101 * @get_parent: find the parent of a given directory
1090 * @get_dentry: find a dentry for the inode given a file handle sub-fragment 1102 * @get_dentry: find a dentry for the inode given a file handle sub-fragment
1103 * @find_exported_dentry:
1104 * set by the exporting module to a standard helper function.
1091 * 1105 *
1092 * Description: 1106 * Description:
1093 * The export_operations structure provides a means for nfsd to communicate 1107 * The export_operations structure provides a means for nfsd to communicate
@@ -1239,7 +1253,12 @@ extern int unregister_filesystem(struct file_system_type *);
1239extern struct vfsmount *kern_mount(struct file_system_type *); 1253extern struct vfsmount *kern_mount(struct file_system_type *);
1240extern int may_umount_tree(struct vfsmount *); 1254extern int may_umount_tree(struct vfsmount *);
1241extern int may_umount(struct vfsmount *); 1255extern int may_umount(struct vfsmount *);
1256extern void umount_tree(struct vfsmount *, int, struct list_head *);
1257extern void release_mounts(struct list_head *);
1242extern long do_mount(char *, char *, char *, unsigned long, void *); 1258extern long do_mount(char *, char *, char *, unsigned long, void *);
1259extern struct vfsmount *copy_tree(struct vfsmount *, struct dentry *, int);
1260extern void mnt_set_mountpoint(struct vfsmount *, struct dentry *,
1261 struct vfsmount *);
1243 1262
1244extern int vfs_statfs(struct super_block *, struct kstatfs *); 1263extern int vfs_statfs(struct super_block *, struct kstatfs *);
1245 1264
@@ -1288,7 +1307,7 @@ static inline int break_lease(struct inode *inode, unsigned int mode)
1288 1307
1289/* fs/open.c */ 1308/* fs/open.c */
1290 1309
1291extern int do_truncate(struct dentry *, loff_t start); 1310extern int do_truncate(struct dentry *, loff_t start, struct file *filp);
1292extern long do_sys_open(const char __user *filename, int flags, int mode); 1311extern long do_sys_open(const char __user *filename, int flags, int mode);
1293extern struct file *filp_open(const char *, int, int); 1312extern struct file *filp_open(const char *, int, int);
1294extern struct file * dentry_open(struct dentry *, struct vfsmount *, int); 1313extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
diff --git a/include/linux/fuse.h b/include/linux/fuse.h
index f98854c2abd7..b76b558b03d4 100644
--- a/include/linux/fuse.h
+++ b/include/linux/fuse.h
@@ -14,7 +14,7 @@
14#define FUSE_KERNEL_VERSION 7 14#define FUSE_KERNEL_VERSION 7
15 15
16/** Minor version number of this interface */ 16/** Minor version number of this interface */
17#define FUSE_KERNEL_MINOR_VERSION 2 17#define FUSE_KERNEL_MINOR_VERSION 3
18 18
19/** The node ID of the root inode */ 19/** The node ID of the root inode */
20#define FUSE_ROOT_ID 1 20#define FUSE_ROOT_ID 1
@@ -61,6 +61,7 @@ struct fuse_kstatfs {
61#define FATTR_SIZE (1 << 3) 61#define FATTR_SIZE (1 << 3)
62#define FATTR_ATIME (1 << 4) 62#define FATTR_ATIME (1 << 4)
63#define FATTR_MTIME (1 << 5) 63#define FATTR_MTIME (1 << 5)
64#define FATTR_FH (1 << 6)
64 65
65/** 66/**
66 * Flags returned by the OPEN request 67 * Flags returned by the OPEN request
@@ -99,7 +100,9 @@ enum fuse_opcode {
99 FUSE_OPENDIR = 27, 100 FUSE_OPENDIR = 27,
100 FUSE_READDIR = 28, 101 FUSE_READDIR = 28,
101 FUSE_RELEASEDIR = 29, 102 FUSE_RELEASEDIR = 29,
102 FUSE_FSYNCDIR = 30 103 FUSE_FSYNCDIR = 30,
104 FUSE_ACCESS = 34,
105 FUSE_CREATE = 35
103}; 106};
104 107
105/* Conservative buffer size for the client */ 108/* Conservative buffer size for the client */
@@ -152,12 +155,25 @@ struct fuse_link_in {
152struct fuse_setattr_in { 155struct fuse_setattr_in {
153 __u32 valid; 156 __u32 valid;
154 __u32 padding; 157 __u32 padding;
155 struct fuse_attr attr; 158 __u64 fh;
159 __u64 size;
160 __u64 unused1;
161 __u64 atime;
162 __u64 mtime;
163 __u64 unused2;
164 __u32 atimensec;
165 __u32 mtimensec;
166 __u32 unused3;
167 __u32 mode;
168 __u32 unused4;
169 __u32 uid;
170 __u32 gid;
171 __u32 unused5;
156}; 172};
157 173
158struct fuse_open_in { 174struct fuse_open_in {
159 __u32 flags; 175 __u32 flags;
160 __u32 padding; 176 __u32 mode;
161}; 177};
162 178
163struct fuse_open_out { 179struct fuse_open_out {
@@ -222,6 +238,11 @@ struct fuse_getxattr_out {
222 __u32 padding; 238 __u32 padding;
223}; 239};
224 240
241struct fuse_access_in {
242 __u32 mask;
243 __u32 padding;
244};
245
225struct fuse_init_in_out { 246struct fuse_init_in_out {
226 __u32 major; 247 __u32 major;
227 __u32 minor; 248 __u32 minor;
diff --git a/include/linux/input.h b/include/linux/input.h
index f623c745c21c..3c5823368ddb 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -1007,7 +1007,7 @@ static inline void input_put_device(struct input_dev *dev)
1007 class_device_put(&dev->cdev); 1007 class_device_put(&dev->cdev);
1008} 1008}
1009 1009
1010void input_register_device(struct input_dev *); 1010int input_register_device(struct input_dev *);
1011void input_unregister_device(struct input_dev *); 1011void input_unregister_device(struct input_dev *);
1012 1012
1013void input_register_handler(struct input_handler *); 1013void input_register_handler(struct input_handler *);
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 18d010bee635..cd6bd001ba4e 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -94,7 +94,7 @@ extern struct resource iomem_resource;
94extern int request_resource(struct resource *root, struct resource *new); 94extern int request_resource(struct resource *root, struct resource *new);
95extern struct resource * ____request_resource(struct resource *root, struct resource *new); 95extern struct resource * ____request_resource(struct resource *root, struct resource *new);
96extern int release_resource(struct resource *new); 96extern int release_resource(struct resource *new);
97extern int insert_resource(struct resource *parent, struct resource *new); 97extern __deprecated_for_modules int insert_resource(struct resource *parent, struct resource *new);
98extern int allocate_resource(struct resource *root, struct resource *new, 98extern int allocate_resource(struct resource *root, struct resource *new,
99 unsigned long size, 99 unsigned long size,
100 unsigned long min, unsigned long max, 100 unsigned long min, unsigned long max,
diff --git a/include/linux/ipmi.h b/include/linux/ipmi.h
index 938d55b813a5..d6276e60b3bf 100644
--- a/include/linux/ipmi.h
+++ b/include/linux/ipmi.h
@@ -256,10 +256,7 @@ struct ipmi_recv_msg
256}; 256};
257 257
258/* Allocate and free the receive message. */ 258/* Allocate and free the receive message. */
259static inline void ipmi_free_recv_msg(struct ipmi_recv_msg *msg) 259void ipmi_free_recv_msg(struct ipmi_recv_msg *msg);
260{
261 msg->done(msg);
262}
263 260
264struct ipmi_user_hndl 261struct ipmi_user_hndl
265{ 262{
diff --git a/include/linux/irq.h b/include/linux/irq.h
index 69681c3b1f05..c516382fbec2 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/config.h> 12#include <linux/config.h>
13#include <asm/smp.h> /* cpu_online_map */
13 14
14#if !defined(CONFIG_ARCH_S390) 15#if !defined(CONFIG_ARCH_S390)
15 16
diff --git a/include/linux/jbd.h b/include/linux/jbd.h
index be197eb90077..aa56172c6fed 100644
--- a/include/linux/jbd.h
+++ b/include/linux/jbd.h
@@ -611,6 +611,9 @@ struct transaction_s
611 * @j_revoke: The revoke table - maintains the list of revoked blocks in the 611 * @j_revoke: The revoke table - maintains the list of revoked blocks in the
612 * current transaction. 612 * current transaction.
613 * @j_revoke_table: alternate revoke tables for j_revoke 613 * @j_revoke_table: alternate revoke tables for j_revoke
614 * @j_wbuf: array of buffer_heads for journal_commit_transaction
615 * @j_wbufsize: maximum number of buffer_heads allowed in j_wbuf, the
616 * number that will fit in j_blocksize
614 * @j_private: An opaque pointer to fs-private information. 617 * @j_private: An opaque pointer to fs-private information.
615 */ 618 */
616 619
diff --git a/include/linux/jffs2.h b/include/linux/jffs2.h
index 419fc953ac16..cf792bb3c726 100644
--- a/include/linux/jffs2.h
+++ b/include/linux/jffs2.h
@@ -5,10 +5,10 @@
5 * 5 *
6 * Created by David Woodhouse <dwmw2@infradead.org> 6 * Created by David Woodhouse <dwmw2@infradead.org>
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in the 8 * For licensing information, see the file 'LICENCE' in the
9 * jffs2 directory. 9 * jffs2 directory.
10 * 10 *
11 * $Id: jffs2.h,v 1.34 2004/11/16 20:36:14 dwmw2 Exp $ 11 * $Id: jffs2.h,v 1.38 2005/09/26 11:37:23 havasi Exp $
12 * 12 *
13 */ 13 */
14 14
@@ -28,6 +28,9 @@
28#define JFFS2_EMPTY_BITMASK 0xffff 28#define JFFS2_EMPTY_BITMASK 0xffff
29#define JFFS2_DIRTY_BITMASK 0x0000 29#define JFFS2_DIRTY_BITMASK 0x0000
30 30
31/* Summary node MAGIC marker */
32#define JFFS2_SUM_MAGIC 0x02851885
33
31/* We only allow a single char for length, and 0xFF is empty flash so 34/* We only allow a single char for length, and 0xFF is empty flash so
32 we don't want it confused with a real length. Hence max 254. 35 we don't want it confused with a real length. Hence max 254.
33*/ 36*/
@@ -43,8 +46,6 @@
43#define JFFS2_COMPR_COPY 0x04 46#define JFFS2_COMPR_COPY 0x04
44#define JFFS2_COMPR_DYNRUBIN 0x05 47#define JFFS2_COMPR_DYNRUBIN 0x05
45#define JFFS2_COMPR_ZLIB 0x06 48#define JFFS2_COMPR_ZLIB 0x06
46#define JFFS2_COMPR_LZO 0x07
47#define JFFS2_COMPR_LZARI 0x08
48/* Compatibility flags. */ 49/* Compatibility flags. */
49#define JFFS2_COMPAT_MASK 0xc000 /* What do to if an unknown nodetype is found */ 50#define JFFS2_COMPAT_MASK 0xc000 /* What do to if an unknown nodetype is found */
50#define JFFS2_NODE_ACCURATE 0x2000 51#define JFFS2_NODE_ACCURATE 0x2000
@@ -62,15 +63,17 @@
62#define JFFS2_NODETYPE_CLEANMARKER (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3) 63#define JFFS2_NODETYPE_CLEANMARKER (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
63#define JFFS2_NODETYPE_PADDING (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 4) 64#define JFFS2_NODETYPE_PADDING (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 4)
64 65
66#define JFFS2_NODETYPE_SUMMARY (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 6)
67
65// Maybe later... 68// Maybe later...
66//#define JFFS2_NODETYPE_CHECKPOINT (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3) 69//#define JFFS2_NODETYPE_CHECKPOINT (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
67//#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4) 70//#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4)
68 71
69 72
70#define JFFS2_INO_FLAG_PREREAD 1 /* Do read_inode() for this one at 73#define JFFS2_INO_FLAG_PREREAD 1 /* Do read_inode() for this one at
71 mount time, don't wait for it to 74 mount time, don't wait for it to
72 happen later */ 75 happen later */
73#define JFFS2_INO_FLAG_USERCOMPR 2 /* User has requested a specific 76#define JFFS2_INO_FLAG_USERCOMPR 2 /* User has requested a specific
74 compression type */ 77 compression type */
75 78
76 79
@@ -101,7 +104,7 @@ struct jffs2_unknown_node
101struct jffs2_raw_dirent 104struct jffs2_raw_dirent
102{ 105{
103 jint16_t magic; 106 jint16_t magic;
104 jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */ 107 jint16_t nodetype; /* == JFFS2_NODETYPE_DIRENT */
105 jint32_t totlen; 108 jint32_t totlen;
106 jint32_t hdr_crc; 109 jint32_t hdr_crc;
107 jint32_t pino; 110 jint32_t pino;
@@ -117,7 +120,7 @@ struct jffs2_raw_dirent
117} __attribute__((packed)); 120} __attribute__((packed));
118 121
119/* The JFFS2 raw inode structure: Used for storage on physical media. */ 122/* The JFFS2 raw inode structure: Used for storage on physical media. */
120/* The uid, gid, atime, mtime and ctime members could be longer, but 123/* The uid, gid, atime, mtime and ctime members could be longer, but
121 are left like this for space efficiency. If and when people decide 124 are left like this for space efficiency. If and when people decide
122 they really need them extended, it's simple enough to add support for 125 they really need them extended, it's simple enough to add support for
123 a new type of raw node. 126 a new type of raw node.
@@ -125,7 +128,7 @@ struct jffs2_raw_dirent
125struct jffs2_raw_inode 128struct jffs2_raw_inode
126{ 129{
127 jint16_t magic; /* A constant magic number. */ 130 jint16_t magic; /* A constant magic number. */
128 jint16_t nodetype; /* == JFFS_NODETYPE_INODE */ 131 jint16_t nodetype; /* == JFFS2_NODETYPE_INODE */
129 jint32_t totlen; /* Total length of this node (inc data, etc.) */ 132 jint32_t totlen; /* Total length of this node (inc data, etc.) */
130 jint32_t hdr_crc; 133 jint32_t hdr_crc;
131 jint32_t ino; /* Inode number. */ 134 jint32_t ino; /* Inode number. */
@@ -148,9 +151,25 @@ struct jffs2_raw_inode
148 uint8_t data[0]; 151 uint8_t data[0];
149} __attribute__((packed)); 152} __attribute__((packed));
150 153
151union jffs2_node_union { 154struct jffs2_raw_summary
155{
156 jint16_t magic;
157 jint16_t nodetype; /* = JFFS2_NODETYPE_SUMMARY */
158 jint32_t totlen;
159 jint32_t hdr_crc;
160 jint32_t sum_num; /* number of sum entries*/
161 jint32_t cln_mkr; /* clean marker size, 0 = no cleanmarker */
162 jint32_t padded; /* sum of the size of padding nodes */
163 jint32_t sum_crc; /* summary information crc */
164 jint32_t node_crc; /* node crc */
165 jint32_t sum[0]; /* inode summary info */
166} __attribute__((packed));
167
168union jffs2_node_union
169{
152 struct jffs2_raw_inode i; 170 struct jffs2_raw_inode i;
153 struct jffs2_raw_dirent d; 171 struct jffs2_raw_dirent d;
172 struct jffs2_raw_summary s;
154 struct jffs2_unknown_node u; 173 struct jffs2_unknown_node u;
155}; 174};
156 175
diff --git a/include/linux/jffs2_fs_i.h b/include/linux/jffs2_fs_i.h
index 6dbb1cce6646..ef85ab56302b 100644
--- a/include/linux/jffs2_fs_i.h
+++ b/include/linux/jffs2_fs_i.h
@@ -1,4 +1,4 @@
1/* $Id: jffs2_fs_i.h,v 1.17 2004/11/11 23:51:27 dwmw2 Exp $ */ 1/* $Id: jffs2_fs_i.h,v 1.19 2005/11/07 11:14:52 gleixner Exp $ */
2 2
3#ifndef _JFFS2_FS_I 3#ifndef _JFFS2_FS_I
4#define _JFFS2_FS_I 4#define _JFFS2_FS_I
@@ -25,13 +25,16 @@ struct jffs2_inode_info {
25 /* There may be one datanode which isn't referenced by any of the 25 /* There may be one datanode which isn't referenced by any of the
26 above fragments, if it contains a metadata update but no actual 26 above fragments, if it contains a metadata update but no actual
27 data - or if this is a directory inode */ 27 data - or if this is a directory inode */
28 /* This also holds the _only_ dnode for symlinks/device nodes, 28 /* This also holds the _only_ dnode for symlinks/device nodes,
29 etc. */ 29 etc. */
30 struct jffs2_full_dnode *metadata; 30 struct jffs2_full_dnode *metadata;
31 31
32 /* Directory entries */ 32 /* Directory entries */
33 struct jffs2_full_dirent *dents; 33 struct jffs2_full_dirent *dents;
34 34
35 /* The target path if this is the inode of a symlink */
36 unsigned char *target;
37
35 /* Some stuff we just have to keep in-core at all times, for each inode. */ 38 /* Some stuff we just have to keep in-core at all times, for each inode. */
36 struct jffs2_inode_cache *inocache; 39 struct jffs2_inode_cache *inocache;
37 40
diff --git a/include/linux/jffs2_fs_sb.h b/include/linux/jffs2_fs_sb.h
index 1e21546622de..4bcfb5570221 100644
--- a/include/linux/jffs2_fs_sb.h
+++ b/include/linux/jffs2_fs_sb.h
@@ -1,4 +1,4 @@
1/* $Id: jffs2_fs_sb.h,v 1.52 2005/05/19 16:12:17 gleixner Exp $ */ 1/* $Id: jffs2_fs_sb.h,v 1.54 2005/09/21 13:37:34 dedekind Exp $ */
2 2
3#ifndef _JFFS2_FS_SB 3#ifndef _JFFS2_FS_SB
4#define _JFFS2_FS_SB 4#define _JFFS2_FS_SB
@@ -20,7 +20,7 @@
20struct jffs2_inodirty; 20struct jffs2_inodirty;
21 21
22/* A struct for the overall file system control. Pointers to 22/* A struct for the overall file system control. Pointers to
23 jffs2_sb_info structs are named `c' in the source code. 23 jffs2_sb_info structs are named `c' in the source code.
24 Nee jffs_control 24 Nee jffs_control
25*/ 25*/
26struct jffs2_sb_info { 26struct jffs2_sb_info {
@@ -35,7 +35,7 @@ struct jffs2_sb_info {
35 struct completion gc_thread_start; /* GC thread start completion */ 35 struct completion gc_thread_start; /* GC thread start completion */
36 struct completion gc_thread_exit; /* GC thread exit completion port */ 36 struct completion gc_thread_exit; /* GC thread exit completion port */
37 37
38 struct semaphore alloc_sem; /* Used to protect all the following 38 struct semaphore alloc_sem; /* Used to protect all the following
39 fields, and also to protect against 39 fields, and also to protect against
40 out-of-order writing of nodes. And GC. */ 40 out-of-order writing of nodes. And GC. */
41 uint32_t cleanmarker_size; /* Size of an _inline_ CLEANMARKER 41 uint32_t cleanmarker_size; /* Size of an _inline_ CLEANMARKER
@@ -64,7 +64,7 @@ struct jffs2_sb_info {
64 uint32_t nospc_dirty_size; 64 uint32_t nospc_dirty_size;
65 65
66 uint32_t nr_blocks; 66 uint32_t nr_blocks;
67 struct jffs2_eraseblock *blocks; /* The whole array of blocks. Used for getting blocks 67 struct jffs2_eraseblock *blocks; /* The whole array of blocks. Used for getting blocks
68 * from the offset (blocks[ofs / sector_size]) */ 68 * from the offset (blocks[ofs / sector_size]) */
69 struct jffs2_eraseblock *nextblock; /* The block we're currently filling */ 69 struct jffs2_eraseblock *nextblock; /* The block we're currently filling */
70 70
@@ -82,25 +82,26 @@ struct jffs2_sb_info {
82 struct list_head bad_list; /* Bad blocks. */ 82 struct list_head bad_list; /* Bad blocks. */
83 struct list_head bad_used_list; /* Bad blocks with valid data in. */ 83 struct list_head bad_used_list; /* Bad blocks with valid data in. */
84 84
85 spinlock_t erase_completion_lock; /* Protect free_list and erasing_list 85 spinlock_t erase_completion_lock; /* Protect free_list and erasing_list
86 against erase completion handler */ 86 against erase completion handler */
87 wait_queue_head_t erase_wait; /* For waiting for erases to complete */ 87 wait_queue_head_t erase_wait; /* For waiting for erases to complete */
88 88
89 wait_queue_head_t inocache_wq; 89 wait_queue_head_t inocache_wq;
90 struct jffs2_inode_cache **inocache_list; 90 struct jffs2_inode_cache **inocache_list;
91 spinlock_t inocache_lock; 91 spinlock_t inocache_lock;
92 92
93 /* Sem to allow jffs2_garbage_collect_deletion_dirent to 93 /* Sem to allow jffs2_garbage_collect_deletion_dirent to
94 drop the erase_completion_lock while it's holding a pointer 94 drop the erase_completion_lock while it's holding a pointer
95 to an obsoleted node. I don't like this. Alternatives welcomed. */ 95 to an obsoleted node. I don't like this. Alternatives welcomed. */
96 struct semaphore erase_free_sem; 96 struct semaphore erase_free_sem;
97 97
98 uint32_t wbuf_pagesize; /* 0 for NOR and other flashes with no wbuf */
99
98#ifdef CONFIG_JFFS2_FS_WRITEBUFFER 100#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
99 /* Write-behind buffer for NAND flash */ 101 /* Write-behind buffer for NAND flash */
100 unsigned char *wbuf; 102 unsigned char *wbuf;
101 uint32_t wbuf_ofs; 103 uint32_t wbuf_ofs;
102 uint32_t wbuf_len; 104 uint32_t wbuf_len;
103 uint32_t wbuf_pagesize;
104 struct jffs2_inodirty *wbuf_inodes; 105 struct jffs2_inodirty *wbuf_inodes;
105 106
106 struct rw_semaphore wbuf_sem; /* Protects the write buffer */ 107 struct rw_semaphore wbuf_sem; /* Protects the write buffer */
@@ -112,6 +113,8 @@ struct jffs2_sb_info {
112 uint32_t fsdata_len; 113 uint32_t fsdata_len;
113#endif 114#endif
114 115
116 struct jffs2_summary *summary; /* Summary information */
117
115 /* OS-private pointer for getting back to master superblock info */ 118 /* OS-private pointer for getting back to master superblock info */
116 void *os_priv; 119 void *os_priv;
117}; 120};
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index f1925ccc9fe1..b1e407a4fbda 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -168,7 +168,7 @@ static inline void console_verbose(void)
168 168
169extern void bust_spinlocks(int yes); 169extern void bust_spinlocks(int yes);
170extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ 170extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
171extern int panic_timeout; 171extern __deprecated_for_modules int panic_timeout;
172extern int panic_on_oops; 172extern int panic_on_oops;
173extern int tainted; 173extern int tainted;
174extern const char *print_tainted(void); 174extern const char *print_tainted(void);
@@ -266,7 +266,6 @@ extern void dump_stack(void);
266 266
267/** 267/**
268 * container_of - cast a member of a structure out to the containing structure 268 * container_of - cast a member of a structure out to the containing structure
269 *
270 * @ptr: the pointer to the member. 269 * @ptr: the pointer to the member.
271 * @type: the type of the container struct this is embedded in. 270 * @type: the type of the container struct this is embedded in.
272 * @member: the name of the member within the struct. 271 * @member: the name of the member within the struct.
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index dba27749b428..a484572c302e 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -6,6 +6,7 @@
6#include <linux/smp.h> 6#include <linux/smp.h>
7#include <linux/threads.h> 7#include <linux/threads.h>
8#include <linux/percpu.h> 8#include <linux/percpu.h>
9#include <linux/cpumask.h>
9#include <asm/cputime.h> 10#include <asm/cputime.h>
10 11
11/* 12/*
@@ -43,11 +44,10 @@ extern unsigned long long nr_context_switches(void);
43 */ 44 */
44static inline int kstat_irqs(int irq) 45static inline int kstat_irqs(int irq)
45{ 46{
46 int i, sum=0; 47 int cpu, sum = 0;
47 48
48 for (i = 0; i < NR_CPUS; i++) 49 for_each_cpu(cpu)
49 if (cpu_possible(i)) 50 sum += kstat_cpu(cpu).irqs[irq];
50 sum += kstat_cpu(i).irqs[irq];
51 51
52 return sum; 52 return sum;
53} 53}
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index e30afdca7917..e373c4a9de53 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -33,6 +33,9 @@
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/notifier.h> 34#include <linux/notifier.h>
35#include <linux/smp.h> 35#include <linux/smp.h>
36#include <linux/percpu.h>
37#include <linux/spinlock.h>
38#include <linux/rcupdate.h>
36 39
37#include <asm/kprobes.h> 40#include <asm/kprobes.h>
38 41
@@ -106,6 +109,9 @@ struct jprobe {
106 kprobe_opcode_t *entry; /* probe handling code to jump to */ 109 kprobe_opcode_t *entry; /* probe handling code to jump to */
107}; 110};
108 111
112DECLARE_PER_CPU(struct kprobe *, current_kprobe);
113DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
114
109#ifdef ARCH_SUPPORTS_KRETPROBES 115#ifdef ARCH_SUPPORTS_KRETPROBES
110extern void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs); 116extern void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs);
111#else /* ARCH_SUPPORTS_KRETPROBES */ 117#else /* ARCH_SUPPORTS_KRETPROBES */
@@ -142,17 +148,7 @@ struct kretprobe_instance {
142}; 148};
143 149
144#ifdef CONFIG_KPROBES 150#ifdef CONFIG_KPROBES
145/* Locks kprobe: irq must be disabled */ 151extern spinlock_t kretprobe_lock;
146void lock_kprobes(void);
147void unlock_kprobes(void);
148
149/* kprobe running now on this CPU? */
150static inline int kprobe_running(void)
151{
152 extern unsigned int kprobe_cpu;
153 return kprobe_cpu == smp_processor_id();
154}
155
156extern int arch_prepare_kprobe(struct kprobe *p); 152extern int arch_prepare_kprobe(struct kprobe *p);
157extern void arch_copy_kprobe(struct kprobe *p); 153extern void arch_copy_kprobe(struct kprobe *p);
158extern void arch_arm_kprobe(struct kprobe *p); 154extern void arch_arm_kprobe(struct kprobe *p);
@@ -163,10 +159,26 @@ extern void show_registers(struct pt_regs *regs);
163extern kprobe_opcode_t *get_insn_slot(void); 159extern kprobe_opcode_t *get_insn_slot(void);
164extern void free_insn_slot(kprobe_opcode_t *slot); 160extern void free_insn_slot(kprobe_opcode_t *slot);
165 161
166/* Get the kprobe at this addr (if any). Must have called lock_kprobes */ 162/* Get the kprobe at this addr (if any) - called with preemption disabled */
167struct kprobe *get_kprobe(void *addr); 163struct kprobe *get_kprobe(void *addr);
168struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk); 164struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk);
169 165
166/* kprobe_running() will just return the current_kprobe on this CPU */
167static inline struct kprobe *kprobe_running(void)
168{
169 return (__get_cpu_var(current_kprobe));
170}
171
172static inline void reset_current_kprobe(void)
173{
174 __get_cpu_var(current_kprobe) = NULL;
175}
176
177static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void)
178{
179 return (&__get_cpu_var(kprobe_ctlblk));
180}
181
170int register_kprobe(struct kprobe *p); 182int register_kprobe(struct kprobe *p);
171void unregister_kprobe(struct kprobe *p); 183void unregister_kprobe(struct kprobe *p);
172int setjmp_pre_handler(struct kprobe *, struct pt_regs *); 184int setjmp_pre_handler(struct kprobe *, struct pt_regs *);
@@ -183,9 +195,9 @@ void add_rp_inst(struct kretprobe_instance *ri);
183void kprobe_flush_task(struct task_struct *tk); 195void kprobe_flush_task(struct task_struct *tk);
184void recycle_rp_inst(struct kretprobe_instance *ri); 196void recycle_rp_inst(struct kretprobe_instance *ri);
185#else /* CONFIG_KPROBES */ 197#else /* CONFIG_KPROBES */
186static inline int kprobe_running(void) 198static inline struct kprobe *kprobe_running(void)
187{ 199{
188 return 0; 200 return NULL;
189} 201}
190static inline int register_kprobe(struct kprobe *p) 202static inline int register_kprobe(struct kprobe *p)
191{ 203{
diff --git a/include/linux/list.h b/include/linux/list.h
index 084971f333fe..fbfca73355a3 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -601,7 +601,7 @@ static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
601 * or hlist_del_rcu(), running on this same list. 601 * or hlist_del_rcu(), running on this same list.
602 * However, it is perfectly legal to run concurrently with 602 * However, it is perfectly legal to run concurrently with
603 * the _rcu list-traversal primitives, such as 603 * the _rcu list-traversal primitives, such as
604 * hlist_for_each_rcu(), used to prevent memory-consistency 604 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
605 * problems on Alpha CPUs. Regardless of the type of CPU, the 605 * problems on Alpha CPUs. Regardless of the type of CPU, the
606 * list-traversal primitive must be guarded by rcu_read_lock(). 606 * list-traversal primitive must be guarded by rcu_read_lock().
607 */ 607 */
@@ -650,7 +650,7 @@ static inline void hlist_add_after(struct hlist_node *n,
650 * or hlist_del_rcu(), running on this same list. 650 * or hlist_del_rcu(), running on this same list.
651 * However, it is perfectly legal to run concurrently with 651 * However, it is perfectly legal to run concurrently with
652 * the _rcu list-traversal primitives, such as 652 * the _rcu list-traversal primitives, such as
653 * hlist_for_each_rcu(), used to prevent memory-consistency 653 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
654 * problems on Alpha CPUs. 654 * problems on Alpha CPUs.
655 */ 655 */
656static inline void hlist_add_before_rcu(struct hlist_node *n, 656static inline void hlist_add_before_rcu(struct hlist_node *n,
@@ -675,7 +675,7 @@ static inline void hlist_add_before_rcu(struct hlist_node *n,
675 * or hlist_del_rcu(), running on this same list. 675 * or hlist_del_rcu(), running on this same list.
676 * However, it is perfectly legal to run concurrently with 676 * However, it is perfectly legal to run concurrently with
677 * the _rcu list-traversal primitives, such as 677 * the _rcu list-traversal primitives, such as
678 * hlist_for_each_rcu(), used to prevent memory-consistency 678 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
679 * problems on Alpha CPUs. 679 * problems on Alpha CPUs.
680 */ 680 */
681static inline void hlist_add_after_rcu(struct hlist_node *prev, 681static inline void hlist_add_after_rcu(struct hlist_node *prev,
@@ -699,11 +699,6 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
699 for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ 699 for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
700 pos = n) 700 pos = n)
701 701
702#define hlist_for_each_rcu(pos, head) \
703 for ((pos) = (head)->first; \
704 rcu_dereference((pos)) && ({ prefetch((pos)->next); 1; }); \
705 (pos) = (pos)->next)
706
707/** 702/**
708 * hlist_for_each_entry - iterate over list of given type 703 * hlist_for_each_entry - iterate over list of given type
709 * @tpos: the type * to use as a loop counter. 704 * @tpos: the type * to use as a loop counter.
@@ -756,7 +751,7 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
756 751
757/** 752/**
758 * hlist_for_each_entry_rcu - iterate over rcu list of given type 753 * hlist_for_each_entry_rcu - iterate over rcu list of given type
759 * @pos: the type * to use as a loop counter. 754 * @tpos: the type * to use as a loop counter.
760 * @pos: the &struct hlist_node to use as a loop counter. 755 * @pos: the &struct hlist_node to use as a loop counter.
761 * @head: the head for your list. 756 * @head: the head for your list.
762 * @member: the name of the hlist_node within the struct. 757 * @member: the name of the hlist_node within the struct.
diff --git a/include/linux/memory.h b/include/linux/memory.h
index 0def328ab5cf..9a424383e6c6 100644
--- a/include/linux/memory.h
+++ b/include/linux/memory.h
@@ -54,6 +54,9 @@ struct memory_block {
54 */ 54 */
55#define MEM_MAPPING_INVALID (1<<3) 55#define MEM_MAPPING_INVALID (1<<3)
56 56
57struct notifier_block;
58struct mem_section;
59
57#ifndef CONFIG_MEMORY_HOTPLUG 60#ifndef CONFIG_MEMORY_HOTPLUG
58static inline int memory_dev_init(void) 61static inline int memory_dev_init(void)
59{ 62{
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 5c1fb0a2e806..7b115feca4df 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -932,13 +932,13 @@ int write_one_page(struct page *page, int wait);
932 * turning readahead off */ 932 * turning readahead off */
933 933
934int do_page_cache_readahead(struct address_space *mapping, struct file *filp, 934int do_page_cache_readahead(struct address_space *mapping, struct file *filp,
935 unsigned long offset, unsigned long nr_to_read); 935 pgoff_t offset, unsigned long nr_to_read);
936int force_page_cache_readahead(struct address_space *mapping, struct file *filp, 936int force_page_cache_readahead(struct address_space *mapping, struct file *filp,
937 unsigned long offset, unsigned long nr_to_read); 937 pgoff_t offset, unsigned long nr_to_read);
938unsigned long page_cache_readahead(struct address_space *mapping, 938unsigned long page_cache_readahead(struct address_space *mapping,
939 struct file_ra_state *ra, 939 struct file_ra_state *ra,
940 struct file *filp, 940 struct file *filp,
941 unsigned long offset, 941 pgoff_t offset,
942 unsigned long size); 942 unsigned long size);
943void handle_ra_miss(struct address_space *mapping, 943void handle_ra_miss(struct address_space *mapping,
944 struct file_ra_state *ra, pgoff_t offset); 944 struct file_ra_state *ra, pgoff_t offset);
diff --git a/include/linux/mount.h b/include/linux/mount.h
index f8f39937e301..dd4e83eba933 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -17,12 +17,14 @@
17#include <linux/spinlock.h> 17#include <linux/spinlock.h>
18#include <asm/atomic.h> 18#include <asm/atomic.h>
19 19
20#define MNT_NOSUID 1 20#define MNT_NOSUID 0x01
21#define MNT_NODEV 2 21#define MNT_NODEV 0x02
22#define MNT_NOEXEC 4 22#define MNT_NOEXEC 0x04
23#define MNT_SHARED 0x10 /* if the vfsmount is a shared mount */
24#define MNT_UNBINDABLE 0x20 /* if the vfsmount is a unbindable mount */
25#define MNT_PNODE_MASK 0x30 /* propogation flag mask */
23 26
24struct vfsmount 27struct vfsmount {
25{
26 struct list_head mnt_hash; 28 struct list_head mnt_hash;
27 struct vfsmount *mnt_parent; /* fs we are mounted on */ 29 struct vfsmount *mnt_parent; /* fs we are mounted on */
28 struct dentry *mnt_mountpoint; /* dentry of mountpoint */ 30 struct dentry *mnt_mountpoint; /* dentry of mountpoint */
@@ -36,7 +38,12 @@ struct vfsmount
36 char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */ 38 char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */
37 struct list_head mnt_list; 39 struct list_head mnt_list;
38 struct list_head mnt_expire; /* link in fs-specific expiry list */ 40 struct list_head mnt_expire; /* link in fs-specific expiry list */
41 struct list_head mnt_share; /* circular list of shared mounts */
42 struct list_head mnt_slave_list;/* list of slave mounts */
43 struct list_head mnt_slave; /* slave list entry */
44 struct vfsmount *mnt_master; /* slave is on master->mnt_slave_list */
39 struct namespace *mnt_namespace; /* containing namespace */ 45 struct namespace *mnt_namespace; /* containing namespace */
46 int mnt_pinned;
40}; 47};
41 48
42static inline struct vfsmount *mntget(struct vfsmount *mnt) 49static inline struct vfsmount *mntget(struct vfsmount *mnt)
@@ -46,15 +53,9 @@ static inline struct vfsmount *mntget(struct vfsmount *mnt)
46 return mnt; 53 return mnt;
47} 54}
48 55
49extern void __mntput(struct vfsmount *mnt); 56extern void mntput_no_expire(struct vfsmount *mnt);
50 57extern void mnt_pin(struct vfsmount *mnt);
51static inline void mntput_no_expire(struct vfsmount *mnt) 58extern void mnt_unpin(struct vfsmount *mnt);
52{
53 if (mnt) {
54 if (atomic_dec_and_test(&mnt->mnt_count))
55 __mntput(mnt);
56 }
57}
58 59
59static inline void mntput(struct vfsmount *mnt) 60static inline void mntput(struct vfsmount *mnt)
60{ 61{
diff --git a/include/linux/mtd/bbm.h b/include/linux/mtd/bbm.h
new file mode 100644
index 000000000000..7a7fbe87fef0
--- /dev/null
+++ b/include/linux/mtd/bbm.h
@@ -0,0 +1,122 @@
1/*
2 * linux/include/linux/mtd/bbm.h
3 *
4 * NAND family Bad Block Management (BBM) header file
5 * - Bad Block Table (BBT) implementation
6 *
7 * Copyright (c) 2005 Samsung Electronics
8 * Kyungmin Park <kyungmin.park@samsung.com>
9 *
10 * Copyright (c) 2000-2005
11 * Thomas Gleixner <tglx@linuxtronix.de>
12 *
13 */
14#ifndef __LINUX_MTD_BBM_H
15#define __LINUX_MTD_BBM_H
16
17/* The maximum number of NAND chips in an array */
18#define NAND_MAX_CHIPS 8
19
20/**
21 * struct nand_bbt_descr - bad block table descriptor
22 * @param options options for this descriptor
23 * @param pages the page(s) where we find the bbt, used with
24 * option BBT_ABSPAGE when bbt is searched,
25 * then we store the found bbts pages here.
26 * Its an array and supports up to 8 chips now
27 * @param offs offset of the pattern in the oob area of the page
28 * @param veroffs offset of the bbt version counter in the oob are of the page
29 * @param version version read from the bbt page during scan
30 * @param len length of the pattern, if 0 no pattern check is performed
31 * @param maxblocks maximum number of blocks to search for a bbt. This number of
32 * blocks is reserved at the end of the device
33 * where the tables are written.
34 * @param reserved_block_code if non-0, this pattern denotes a reserved
35 * (rather than bad) block in the stored bbt
36 * @param pattern pattern to identify bad block table or factory marked
37 * good / bad blocks, can be NULL, if len = 0
38 *
39 * Descriptor for the bad block table marker and the descriptor for the
40 * pattern which identifies good and bad blocks. The assumption is made
41 * that the pattern and the version count are always located in the oob area
42 * of the first block.
43 */
44struct nand_bbt_descr {
45 int options;
46 int pages[NAND_MAX_CHIPS];
47 int offs;
48 int veroffs;
49 uint8_t version[NAND_MAX_CHIPS];
50 int len;
51 int maxblocks;
52 int reserved_block_code;
53 uint8_t *pattern;
54};
55
56/* Options for the bad block table descriptors */
57
58/* The number of bits used per block in the bbt on the device */
59#define NAND_BBT_NRBITS_MSK 0x0000000F
60#define NAND_BBT_1BIT 0x00000001
61#define NAND_BBT_2BIT 0x00000002
62#define NAND_BBT_4BIT 0x00000004
63#define NAND_BBT_8BIT 0x00000008
64/* The bad block table is in the last good block of the device */
65#define NAND_BBT_LASTBLOCK 0x00000010
66/* The bbt is at the given page, else we must scan for the bbt */
67#define NAND_BBT_ABSPAGE 0x00000020
68/* The bbt is at the given page, else we must scan for the bbt */
69#define NAND_BBT_SEARCH 0x00000040
70/* bbt is stored per chip on multichip devices */
71#define NAND_BBT_PERCHIP 0x00000080
72/* bbt has a version counter at offset veroffs */
73#define NAND_BBT_VERSION 0x00000100
74/* Create a bbt if none axists */
75#define NAND_BBT_CREATE 0x00000200
76/* Search good / bad pattern through all pages of a block */
77#define NAND_BBT_SCANALLPAGES 0x00000400
78/* Scan block empty during good / bad block scan */
79#define NAND_BBT_SCANEMPTY 0x00000800
80/* Write bbt if neccecary */
81#define NAND_BBT_WRITE 0x00001000
82/* Read and write back block contents when writing bbt */
83#define NAND_BBT_SAVECONTENT 0x00002000
84/* Search good / bad pattern on the first and the second page */
85#define NAND_BBT_SCAN2NDPAGE 0x00004000
86
87/* The maximum number of blocks to scan for a bbt */
88#define NAND_BBT_SCAN_MAXBLOCKS 4
89
90/*
91 * Constants for oob configuration
92 */
93#define ONENAND_BADBLOCK_POS 0
94
95/**
96 * struct bbt_info - [GENERIC] Bad Block Table data structure
97 * @param bbt_erase_shift [INTERN] number of address bits in a bbt entry
98 * @param badblockpos [INTERN] position of the bad block marker in the oob area
99 * @param bbt [INTERN] bad block table pointer
100 * @param badblock_pattern [REPLACEABLE] bad block scan pattern used for initial bad block scan
101 * @param priv [OPTIONAL] pointer to private bbm date
102 */
103struct bbm_info {
104 int bbt_erase_shift;
105 int badblockpos;
106 int options;
107
108 uint8_t *bbt;
109
110 int (*isbad_bbt)(struct mtd_info *mtd, loff_t ofs, int allowbbt);
111
112 /* TODO Add more NAND specific fileds */
113 struct nand_bbt_descr *badblock_pattern;
114
115 void *priv;
116};
117
118/* OneNAND BBT interface */
119extern int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
120extern int onenand_default_bbt(struct mtd_info *mtd);
121
122#endif /* __LINUX_MTD_BBM_H */
diff --git a/include/linux/mtd/blktrans.h b/include/linux/mtd/blktrans.h
index 4ebc2e5a16e2..f46afec6fbf8 100644
--- a/include/linux/mtd/blktrans.h
+++ b/include/linux/mtd/blktrans.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: blktrans.h,v 1.5 2003/06/23 12:00:08 dwmw2 Exp $ 2 * $Id: blktrans.h,v 1.6 2005/11/07 11:14:54 gleixner Exp $
3 * 3 *
4 * (C) 2003 David Woodhouse <dwmw2@infradead.org> 4 * (C) 2003 David Woodhouse <dwmw2@infradead.org>
5 * 5 *
@@ -67,6 +67,6 @@ extern int register_mtd_blktrans(struct mtd_blktrans_ops *tr);
67extern int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr); 67extern int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr);
68extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev); 68extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
69extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev); 69extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
70 70
71 71
72#endif /* __MTD_TRANS_H__ */ 72#endif /* __MTD_TRANS_H__ */
diff --git a/include/linux/mtd/cfi.h b/include/linux/mtd/cfi.h
index e6b6a1c66bd5..39f1430bd6d5 100644
--- a/include/linux/mtd/cfi.h
+++ b/include/linux/mtd/cfi.h
@@ -1,7 +1,7 @@
1 1
2/* Common Flash Interface structures 2/* Common Flash Interface structures
3 * See http://support.intel.com/design/flash/technote/index.htm 3 * See http://support.intel.com/design/flash/technote/index.htm
4 * $Id: cfi.h,v 1.54 2005/06/06 23:04:36 tpoynor Exp $ 4 * $Id: cfi.h,v 1.56 2005/11/07 11:14:54 gleixner Exp $
5 */ 5 */
6 6
7#ifndef __MTD_CFI_H__ 7#ifndef __MTD_CFI_H__
@@ -82,8 +82,8 @@ static inline int cfi_interleave_supported(int i)
82} 82}
83 83
84 84
85/* NB: these values must represents the number of bytes needed to meet the 85/* NB: these values must represents the number of bytes needed to meet the
86 * device type (x8, x16, x32). Eg. a 32 bit device is 4 x 8 bytes. 86 * device type (x8, x16, x32). Eg. a 32 bit device is 4 x 8 bytes.
87 * These numbers are used in calculations. 87 * These numbers are used in calculations.
88 */ 88 */
89#define CFI_DEVICETYPE_X8 (8 / 8) 89#define CFI_DEVICETYPE_X8 (8 / 8)
@@ -173,6 +173,15 @@ struct cfi_intelext_regioninfo {
173 struct cfi_intelext_blockinfo BlockTypes[1]; 173 struct cfi_intelext_blockinfo BlockTypes[1];
174} __attribute__((packed)); 174} __attribute__((packed));
175 175
176struct cfi_intelext_programming_regioninfo {
177 uint8_t ProgRegShift;
178 uint8_t Reserved1;
179 uint8_t ControlValid;
180 uint8_t Reserved2;
181 uint8_t ControlInvalid;
182 uint8_t Reserved3;
183} __attribute__((packed));
184
176/* Vendor-Specific PRI for AMD/Fujitsu Extended Command Set (0x0002) */ 185/* Vendor-Specific PRI for AMD/Fujitsu Extended Command Set (0x0002) */
177 186
178struct cfi_pri_amdstd { 187struct cfi_pri_amdstd {
@@ -250,7 +259,7 @@ static inline uint32_t cfi_build_cmd_addr(uint32_t cmd_ofs, int interleave, int
250/* 259/*
251 * Transforms the CFI command for the given geometry (bus width & interleave). 260 * Transforms the CFI command for the given geometry (bus width & interleave).
252 * It looks too long to be inline, but in the common case it should almost all 261 * It looks too long to be inline, but in the common case it should almost all
253 * get optimised away. 262 * get optimised away.
254 */ 263 */
255static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cfi_private *cfi) 264static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cfi_private *cfi)
256{ 265{
@@ -259,7 +268,7 @@ static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cf
259 unsigned long onecmd; 268 unsigned long onecmd;
260 int i; 269 int i;
261 270
262 /* We do it this way to give the compiler a fighting chance 271 /* We do it this way to give the compiler a fighting chance
263 of optimising away all the crap for 'bankwidth' larger than 272 of optimising away all the crap for 'bankwidth' larger than
264 an unsigned long, in the common case where that support is 273 an unsigned long, in the common case where that support is
265 disabled */ 274 disabled */
@@ -270,7 +279,7 @@ static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cf
270 wordwidth = map_bankwidth(map); 279 wordwidth = map_bankwidth(map);
271 words_per_bus = 1; 280 words_per_bus = 1;
272 } 281 }
273 282
274 chip_mode = map_bankwidth(map) / cfi_interleave(cfi); 283 chip_mode = map_bankwidth(map) / cfi_interleave(cfi);
275 chips_per_word = wordwidth * cfi_interleave(cfi) / map_bankwidth(map); 284 chips_per_word = wordwidth * cfi_interleave(cfi) / map_bankwidth(map);
276 285
@@ -289,7 +298,7 @@ static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cf
289 break; 298 break;
290 } 299 }
291 300
292 /* Now replicate it across the size of an unsigned long, or 301 /* Now replicate it across the size of an unsigned long, or
293 just to the bus width as appropriate */ 302 just to the bus width as appropriate */
294 switch (chips_per_word) { 303 switch (chips_per_word) {
295 default: BUG(); 304 default: BUG();
@@ -305,7 +314,7 @@ static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cf
305 ; 314 ;
306 } 315 }
307 316
308 /* And finally, for the multi-word case, replicate it 317 /* And finally, for the multi-word case, replicate it
309 in all words in the structure */ 318 in all words in the structure */
310 for (i=0; i < words_per_bus; i++) { 319 for (i=0; i < words_per_bus; i++) {
311 val.x[i] = onecmd; 320 val.x[i] = onecmd;
@@ -316,14 +325,14 @@ static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cf
316#define CMD(x) cfi_build_cmd((x), map, cfi) 325#define CMD(x) cfi_build_cmd((x), map, cfi)
317 326
318 327
319static inline unsigned char cfi_merge_status(map_word val, struct map_info *map, 328static inline unsigned long cfi_merge_status(map_word val, struct map_info *map,
320 struct cfi_private *cfi) 329 struct cfi_private *cfi)
321{ 330{
322 int wordwidth, words_per_bus, chip_mode, chips_per_word; 331 int wordwidth, words_per_bus, chip_mode, chips_per_word;
323 unsigned long onestat, res = 0; 332 unsigned long onestat, res = 0;
324 int i; 333 int i;
325 334
326 /* We do it this way to give the compiler a fighting chance 335 /* We do it this way to give the compiler a fighting chance
327 of optimising away all the crap for 'bankwidth' larger than 336 of optimising away all the crap for 'bankwidth' larger than
328 an unsigned long, in the common case where that support is 337 an unsigned long, in the common case where that support is
329 disabled */ 338 disabled */
@@ -334,7 +343,7 @@ static inline unsigned char cfi_merge_status(map_word val, struct map_info *map,
334 wordwidth = map_bankwidth(map); 343 wordwidth = map_bankwidth(map);
335 words_per_bus = 1; 344 words_per_bus = 1;
336 } 345 }
337 346
338 chip_mode = map_bankwidth(map) / cfi_interleave(cfi); 347 chip_mode = map_bankwidth(map) / cfi_interleave(cfi);
339 chips_per_word = wordwidth * cfi_interleave(cfi) / map_bankwidth(map); 348 chips_per_word = wordwidth * cfi_interleave(cfi) / map_bankwidth(map);
340 349
diff --git a/include/linux/mtd/doc2000.h b/include/linux/mtd/doc2000.h
index 953e64fb8ac5..386a52cf8b1b 100644
--- a/include/linux/mtd/doc2000.h
+++ b/include/linux/mtd/doc2000.h
@@ -1,12 +1,12 @@
1/* 1/*
2 * Linux driver for Disk-On-Chip devices 2 * Linux driver for Disk-On-Chip devices
3 * 3 *
4 * Copyright (C) 1999 Machine Vision Holdings, Inc. 4 * Copyright (C) 1999 Machine Vision Holdings, Inc.
5 * Copyright (C) 2001-2003 David Woodhouse <dwmw2@infradead.org> 5 * Copyright (C) 2001-2003 David Woodhouse <dwmw2@infradead.org>
6 * Copyright (C) 2002-2003 Greg Ungerer <gerg@snapgear.com> 6 * Copyright (C) 2002-2003 Greg Ungerer <gerg@snapgear.com>
7 * Copyright (C) 2002-2003 SnapGear Inc 7 * Copyright (C) 2002-2003 SnapGear Inc
8 * 8 *
9 * $Id: doc2000.h,v 1.24 2005/01/05 12:40:38 dwmw2 Exp $ 9 * $Id: doc2000.h,v 1.25 2005/11/07 11:14:54 gleixner Exp $
10 * 10 *
11 * Released under GPL 11 * Released under GPL
12 */ 12 */
@@ -75,10 +75,10 @@
75#define DoC_Mplus_CtrlConfirm 0x1076 75#define DoC_Mplus_CtrlConfirm 0x1076
76#define DoC_Mplus_Power 0x1fff 76#define DoC_Mplus_Power 0x1fff
77 77
78/* How to access the device? 78/* How to access the device?
79 * On ARM, it'll be mmap'd directly with 32-bit wide accesses. 79 * On ARM, it'll be mmap'd directly with 32-bit wide accesses.
80 * On PPC, it's mmap'd and 16-bit wide. 80 * On PPC, it's mmap'd and 16-bit wide.
81 * Others use readb/writeb 81 * Others use readb/writeb
82 */ 82 */
83#if defined(__arm__) 83#if defined(__arm__)
84#define ReadDOC_(adr, reg) ((unsigned char)(*(volatile __u32 *)(((unsigned long)adr)+((reg)<<2)))) 84#define ReadDOC_(adr, reg) ((unsigned char)(*(volatile __u32 *)(((unsigned long)adr)+((reg)<<2))))
@@ -172,7 +172,7 @@ struct DiskOnChip {
172 unsigned long totlen; 172 unsigned long totlen;
173 unsigned char ChipID; /* Type of DiskOnChip */ 173 unsigned char ChipID; /* Type of DiskOnChip */
174 int ioreg; 174 int ioreg;
175 175
176 unsigned long mfr; /* Flash IDs - only one type of flash per device */ 176 unsigned long mfr; /* Flash IDs - only one type of flash per device */
177 unsigned long id; 177 unsigned long id;
178 int chipshift; 178 int chipshift;
@@ -180,10 +180,10 @@ struct DiskOnChip {
180 char pageadrlen; 180 char pageadrlen;
181 char interleave; /* Internal interleaving - Millennium Plus style */ 181 char interleave; /* Internal interleaving - Millennium Plus style */
182 unsigned long erasesize; 182 unsigned long erasesize;
183 183
184 int curfloor; 184 int curfloor;
185 int curchip; 185 int curchip;
186 186
187 int numchips; 187 int numchips;
188 struct Nand *chips; 188 struct Nand *chips;
189 struct mtd_info *nextdoc; 189 struct mtd_info *nextdoc;
diff --git a/include/linux/mtd/flashchip.h b/include/linux/mtd/flashchip.h
index 675776fa3e27..a293a3b78e05 100644
--- a/include/linux/mtd/flashchip.h
+++ b/include/linux/mtd/flashchip.h
@@ -1,12 +1,12 @@
1 1
2/* 2/*
3 * struct flchip definition 3 * struct flchip definition
4 * 4 *
5 * Contains information about the location and state of a given flash device 5 * Contains information about the location and state of a given flash device
6 * 6 *
7 * (C) 2000 Red Hat. GPLd. 7 * (C) 2000 Red Hat. GPLd.
8 * 8 *
9 * $Id: flashchip.h,v 1.17 2005/03/14 18:27:15 bjd Exp $ 9 * $Id: flashchip.h,v 1.18 2005/11/07 11:14:54 gleixner Exp $
10 * 10 *
11 */ 11 */
12 12
@@ -15,11 +15,11 @@
15 15
16/* For spinlocks. sched.h includes spinlock.h from whichever directory it 16/* For spinlocks. sched.h includes spinlock.h from whichever directory it
17 * happens to be in - so we don't have to care whether we're on 2.2, which 17 * happens to be in - so we don't have to care whether we're on 2.2, which
18 * has asm/spinlock.h, or 2.4, which has linux/spinlock.h 18 * has asm/spinlock.h, or 2.4, which has linux/spinlock.h
19 */ 19 */
20#include <linux/sched.h> 20#include <linux/sched.h>
21 21
22typedef enum { 22typedef enum {
23 FL_READY, 23 FL_READY,
24 FL_STATUS, 24 FL_STATUS,
25 FL_CFI_QUERY, 25 FL_CFI_QUERY,
@@ -45,7 +45,7 @@ typedef enum {
45 45
46 46
47 47
48/* NOTE: confusingly, this can be used to refer to more than one chip at a time, 48/* NOTE: confusingly, this can be used to refer to more than one chip at a time,
49 if they're interleaved. This can even refer to individual partitions on 49 if they're interleaved. This can even refer to individual partitions on
50 the same physical chip when present. */ 50 the same physical chip when present. */
51 51
diff --git a/include/linux/mtd/ftl.h b/include/linux/mtd/ftl.h
index 3678459b4535..d99609113307 100644
--- a/include/linux/mtd/ftl.h
+++ b/include/linux/mtd/ftl.h
@@ -1,6 +1,6 @@
1/* 1/*
2 * $Id: ftl.h,v 1.6 2003/01/24 13:20:04 dwmw2 Exp $ 2 * $Id: ftl.h,v 1.7 2005/11/07 11:14:54 gleixner Exp $
3 * 3 *
4 * Derived from (and probably identical to): 4 * Derived from (and probably identical to):
5 * ftl.h 1.7 1999/10/25 20:23:17 5 * ftl.h 1.7 1999/10/25 20:23:17
6 * 6 *
@@ -12,7 +12,7 @@
12 * Software distributed under the License is distributed on an "AS IS" 12 * Software distributed under the License is distributed on an "AS IS"
13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14 * the License for the specific language governing rights and 14 * the License for the specific language governing rights and
15 * limitations under the License. 15 * limitations under the License.
16 * 16 *
17 * The initial developer of the original code is David A. Hinds 17 * The initial developer of the original code is David A. Hinds
18 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds 18 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
diff --git a/include/linux/mtd/gen_probe.h b/include/linux/mtd/gen_probe.h
index 3d7bdec14f97..256e7342ed1e 100644
--- a/include/linux/mtd/gen_probe.h
+++ b/include/linux/mtd/gen_probe.h
@@ -1,14 +1,14 @@
1/* 1/*
2 * (C) 2001, 2001 Red Hat, Inc. 2 * (C) 2001, 2001 Red Hat, Inc.
3 * GPL'd 3 * GPL'd
4 * $Id: gen_probe.h,v 1.3 2004/10/20 22:10:33 dwmw2 Exp $ 4 * $Id: gen_probe.h,v 1.4 2005/11/07 11:14:54 gleixner Exp $
5 */ 5 */
6 6
7#ifndef __LINUX_MTD_GEN_PROBE_H__ 7#ifndef __LINUX_MTD_GEN_PROBE_H__
8#define __LINUX_MTD_GEN_PROBE_H__ 8#define __LINUX_MTD_GEN_PROBE_H__
9 9
10#include <linux/mtd/flashchip.h> 10#include <linux/mtd/flashchip.h>
11#include <linux/mtd/map.h> 11#include <linux/mtd/map.h>
12#include <linux/mtd/cfi.h> 12#include <linux/mtd/cfi.h>
13#include <linux/bitops.h> 13#include <linux/bitops.h>
14 14
diff --git a/include/linux/mtd/jedec.h b/include/linux/mtd/jedec.h
index 2ba0f700ddbc..9006feb218b9 100644
--- a/include/linux/mtd/jedec.h
+++ b/include/linux/mtd/jedec.h
@@ -1,13 +1,13 @@
1 1
2/* JEDEC Flash Interface. 2/* JEDEC Flash Interface.
3 * This is an older type of interface for self programming flash. It is 3 * This is an older type of interface for self programming flash. It is
4 * commonly use in older AMD chips and is obsolete compared with CFI. 4 * commonly use in older AMD chips and is obsolete compared with CFI.
5 * It is called JEDEC because the JEDEC association distributes the ID codes 5 * It is called JEDEC because the JEDEC association distributes the ID codes
6 * for the chips. 6 * for the chips.
7 * 7 *
8 * See the AMD flash databook for information on how to operate the interface. 8 * See the AMD flash databook for information on how to operate the interface.
9 * 9 *
10 * $Id: jedec.h,v 1.3 2003/05/21 11:51:01 dwmw2 Exp $ 10 * $Id: jedec.h,v 1.4 2005/11/07 11:14:54 gleixner Exp $
11 */ 11 */
12 12
13#ifndef __LINUX_MTD_JEDEC_H__ 13#ifndef __LINUX_MTD_JEDEC_H__
@@ -33,16 +33,16 @@ struct jedec_flash_chip
33 __u16 jedec; 33 __u16 jedec;
34 unsigned long size; 34 unsigned long size;
35 unsigned long sectorsize; 35 unsigned long sectorsize;
36 36
37 // *(__u8*)(base + (adder << addrshift)) = data << datashift 37 // *(__u8*)(base + (adder << addrshift)) = data << datashift
38 // Address size = size << addrshift 38 // Address size = size << addrshift
39 unsigned long base; // Byte 0 of the flash, will be unaligned 39 unsigned long base; // Byte 0 of the flash, will be unaligned
40 unsigned int datashift; // Useful for 32bit/16bit accesses 40 unsigned int datashift; // Useful for 32bit/16bit accesses
41 unsigned int addrshift; 41 unsigned int addrshift;
42 unsigned long offset; // linerized start. base==offset for unbanked, uninterleaved flash 42 unsigned long offset; // linerized start. base==offset for unbanked, uninterleaved flash
43 43
44 __u32 capabilities; 44 __u32 capabilities;
45 45
46 // These markers are filled in by the flash_chip_scan function 46 // These markers are filled in by the flash_chip_scan function
47 unsigned long start; 47 unsigned long start;
48 unsigned long length; 48 unsigned long length;
@@ -51,16 +51,16 @@ struct jedec_flash_chip
51struct jedec_private 51struct jedec_private
52{ 52{
53 unsigned long size; // Total size of all the devices 53 unsigned long size; // Total size of all the devices
54 54
55 /* Bank handling. If sum(bank_fill) == size then this is linear flash. 55 /* Bank handling. If sum(bank_fill) == size then this is linear flash.
56 Otherwise the mapping has holes in it. bank_fill may be used to 56 Otherwise the mapping has holes in it. bank_fill may be used to
57 find the holes, but in the common symetric case 57 find the holes, but in the common symetric case
58 bank_fill[0] == bank_fill[*], thus addresses may be computed 58 bank_fill[0] == bank_fill[*], thus addresses may be computed
59 mathmatically. bank_fill must be powers of two */ 59 mathmatically. bank_fill must be powers of two */
60 unsigned is_banked; 60 unsigned is_banked;
61 unsigned long bank_fill[MAX_JEDEC_CHIPS]; 61 unsigned long bank_fill[MAX_JEDEC_CHIPS];
62 62
63 struct jedec_flash_chip chips[MAX_JEDEC_CHIPS]; 63 struct jedec_flash_chip chips[MAX_JEDEC_CHIPS];
64}; 64};
65 65
66#endif 66#endif
diff --git a/include/linux/mtd/map.h b/include/linux/mtd/map.h
index fc28841f3409..fedfbc8a287f 100644
--- a/include/linux/mtd/map.h
+++ b/include/linux/mtd/map.h
@@ -1,6 +1,6 @@
1 1
2/* Overhauled routines for dealing with different mmap regions of flash */ 2/* Overhauled routines for dealing with different mmap regions of flash */
3/* $Id: map.h,v 1.52 2005/05/25 10:29:41 gleixner Exp $ */ 3/* $Id: map.h,v 1.54 2005/11/07 11:14:54 gleixner Exp $ */
4 4
5#ifndef __LINUX_MTD_MAP_H__ 5#ifndef __LINUX_MTD_MAP_H__
6#define __LINUX_MTD_MAP_H__ 6#define __LINUX_MTD_MAP_H__
@@ -170,14 +170,14 @@ typedef union {
170 to a chip probe routine -- either JEDEC or CFI probe or both -- via 170 to a chip probe routine -- either JEDEC or CFI probe or both -- via
171 do_map_probe(). If a chip is recognised, the probe code will invoke the 171 do_map_probe(). If a chip is recognised, the probe code will invoke the
172 appropriate chip driver (if present) and return a struct mtd_info. 172 appropriate chip driver (if present) and return a struct mtd_info.
173 At which point, you fill in the mtd->module with your own module 173 At which point, you fill in the mtd->module with your own module
174 address, and register it with the MTD core code. Or you could partition 174 address, and register it with the MTD core code. Or you could partition
175 it and register the partitions instead, or keep it for your own private 175 it and register the partitions instead, or keep it for your own private
176 use; whatever. 176 use; whatever.
177 177
178 The mtd->priv field will point to the struct map_info, and any further 178 The mtd->priv field will point to the struct map_info, and any further
179 private data required by the chip driver is linked from the 179 private data required by the chip driver is linked from the
180 mtd->priv->fldrv_priv field. This allows the map driver to get at 180 mtd->priv->fldrv_priv field. This allows the map driver to get at
181 the destructor function map->fldrv_destroy() when it's tired 181 the destructor function map->fldrv_destroy() when it's tired
182 of living. 182 of living.
183*/ 183*/
@@ -214,7 +214,7 @@ struct map_info {
214 If there is no cache to care about this can be set to NULL. */ 214 If there is no cache to care about this can be set to NULL. */
215 void (*inval_cache)(struct map_info *, unsigned long, ssize_t); 215 void (*inval_cache)(struct map_info *, unsigned long, ssize_t);
216 216
217 /* set_vpp() must handle being reentered -- enable, enable, disable 217 /* set_vpp() must handle being reentered -- enable, enable, disable
218 must leave it enabled. */ 218 must leave it enabled. */
219 void (*set_vpp)(struct map_info *, int); 219 void (*set_vpp)(struct map_info *, int);
220 220
@@ -353,7 +353,7 @@ static inline map_word map_word_ff(struct map_info *map)
353{ 353{
354 map_word r; 354 map_word r;
355 int i; 355 int i;
356 356
357 if (map_bankwidth(map) < MAP_FF_LIMIT) { 357 if (map_bankwidth(map) < MAP_FF_LIMIT) {
358 int bw = 8 * map_bankwidth(map); 358 int bw = 8 * map_bankwidth(map);
359 r.x[0] = (1 << bw) - 1; 359 r.x[0] = (1 << bw) - 1;
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index c50c3f3927d9..e95d0463a3e5 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: mtd.h,v 1.59 2005/04/11 10:19:02 gleixner Exp $ 2 * $Id: mtd.h,v 1.61 2005/11/07 11:14:54 gleixner Exp $
3 * 3 *
4 * Copyright (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> et al. 4 * Copyright (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> et al.
5 * 5 *
@@ -72,7 +72,17 @@ struct mtd_info {
72 u_int32_t oobsize; // Amount of OOB data per block (e.g. 16) 72 u_int32_t oobsize; // Amount of OOB data per block (e.g. 16)
73 u_int32_t ecctype; 73 u_int32_t ecctype;
74 u_int32_t eccsize; 74 u_int32_t eccsize;
75 75
76 /*
77 * Reuse some of the above unused fields in the case of NOR flash
78 * with configurable programming regions to avoid modifying the
79 * user visible structure layout/size. Only valid when the
80 * MTD_PROGRAM_REGIONS flag is set.
81 * (Maybe we should have an union for those?)
82 */
83#define MTD_PROGREGION_SIZE(mtd) (mtd)->oobblock
84#define MTD_PROGREGION_CTRLMODE_VALID(mtd) (mtd)->oobsize
85#define MTD_PROGREGION_CTRLMODE_INVALID(mtd) (mtd)->ecctype
76 86
77 // Kernel-only stuff starts here. 87 // Kernel-only stuff starts here.
78 char *name; 88 char *name;
@@ -80,13 +90,13 @@ struct mtd_info {
80 90
81 // oobinfo is a nand_oobinfo structure, which can be set by iotcl (MEMSETOOBINFO) 91 // oobinfo is a nand_oobinfo structure, which can be set by iotcl (MEMSETOOBINFO)
82 struct nand_oobinfo oobinfo; 92 struct nand_oobinfo oobinfo;
83 u_int32_t oobavail; // Number of bytes in OOB area available for fs 93 u_int32_t oobavail; // Number of bytes in OOB area available for fs
84 94
85 /* Data for variable erase regions. If numeraseregions is zero, 95 /* Data for variable erase regions. If numeraseregions is zero,
86 * it means that the whole device has erasesize as given above. 96 * it means that the whole device has erasesize as given above.
87 */ 97 */
88 int numeraseregions; 98 int numeraseregions;
89 struct mtd_erase_region_info *eraseregions; 99 struct mtd_erase_region_info *eraseregions;
90 100
91 /* This really shouldn't be here. It can go away in 2.5 */ 101 /* This really shouldn't be here. It can go away in 2.5 */
92 u_int32_t bank_size; 102 u_int32_t bank_size;
@@ -109,10 +119,10 @@ struct mtd_info {
109 int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 119 int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
110 int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); 120 int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
111 121
112 /* 122 /*
113 * Methods to access the protection register area, present in some 123 * Methods to access the protection register area, present in some
114 * flash devices. The user data is one time programmable but the 124 * flash devices. The user data is one time programmable but the
115 * factory data is read only. 125 * factory data is read only.
116 */ 126 */
117 int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len); 127 int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
118 int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 128 int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
@@ -123,14 +133,14 @@ struct mtd_info {
123 133
124 /* kvec-based read/write methods. We need these especially for NAND flash, 134 /* kvec-based read/write methods. We need these especially for NAND flash,
125 with its limited number of write cycles per erase. 135 with its limited number of write cycles per erase.
126 NB: The 'count' parameter is the number of _vectors_, each of 136 NB: The 'count' parameter is the number of _vectors_, each of
127 which contains an (ofs, len) tuple. 137 which contains an (ofs, len) tuple.
128 */ 138 */
129 int (*readv) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from, size_t *retlen); 139 int (*readv) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from, size_t *retlen);
130 int (*readv_ecc) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from, 140 int (*readv_ecc) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from,
131 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel); 141 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
132 int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen); 142 int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
133 int (*writev_ecc) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, 143 int (*writev_ecc) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to,
134 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel); 144 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
135 145
136 /* Sync */ 146 /* Sync */
@@ -194,7 +204,7 @@ int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
194#define MTD_WRITEECC(mtd, args...) (*(mtd->write_ecc))(mtd, args) 204#define MTD_WRITEECC(mtd, args...) (*(mtd->write_ecc))(mtd, args)
195#define MTD_READOOB(mtd, args...) (*(mtd->read_oob))(mtd, args) 205#define MTD_READOOB(mtd, args...) (*(mtd->read_oob))(mtd, args)
196#define MTD_WRITEOOB(mtd, args...) (*(mtd->write_oob))(mtd, args) 206#define MTD_WRITEOOB(mtd, args...) (*(mtd->write_oob))(mtd, args)
197#define MTD_SYNC(mtd) do { if (mtd->sync) (*(mtd->sync))(mtd); } while (0) 207#define MTD_SYNC(mtd) do { if (mtd->sync) (*(mtd->sync))(mtd); } while (0)
198 208
199 209
200#ifdef CONFIG_MTD_PARTITIONS 210#ifdef CONFIG_MTD_PARTITIONS
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 9b5b76217584..da5e67b3fc70 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -5,7 +5,7 @@
5 * Steven J. Hill <sjhill@realitydiluted.com> 5 * Steven J. Hill <sjhill@realitydiluted.com>
6 * Thomas Gleixner <tglx@linutronix.de> 6 * Thomas Gleixner <tglx@linutronix.de>
7 * 7 *
8 * $Id: nand.h,v 1.73 2005/05/31 19:39:17 gleixner Exp $ 8 * $Id: nand.h,v 1.74 2005/09/15 13:58:50 vwool Exp $
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as 11 * it under the terms of the GNU General Public License version 2 as
@@ -24,7 +24,7 @@
24 * bat later if I did something naughty. 24 * bat later if I did something naughty.
25 * 10-11-2000 SJH Added private NAND flash structure for driver 25 * 10-11-2000 SJH Added private NAND flash structure for driver
26 * 10-24-2000 SJH Added prototype for 'nand_scan' function 26 * 10-24-2000 SJH Added prototype for 'nand_scan' function
27 * 10-29-2001 TG changed nand_chip structure to support 27 * 10-29-2001 TG changed nand_chip structure to support
28 * hardwarespecific function for accessing control lines 28 * hardwarespecific function for accessing control lines
29 * 02-21-2002 TG added support for different read/write adress and 29 * 02-21-2002 TG added support for different read/write adress and
30 * ready/busy line access function 30 * ready/busy line access function
@@ -36,21 +36,21 @@
36 * CONFIG_MTD_NAND_ECC_JFFS2 is not set 36 * CONFIG_MTD_NAND_ECC_JFFS2 is not set
37 * 08-10-2002 TG extensions to nand_chip structure to support HW-ECC 37 * 08-10-2002 TG extensions to nand_chip structure to support HW-ECC
38 * 38 *
39 * 08-29-2002 tglx nand_chip structure: data_poi for selecting 39 * 08-29-2002 tglx nand_chip structure: data_poi for selecting
40 * internal / fs-driver buffer 40 * internal / fs-driver buffer
41 * support for 6byte/512byte hardware ECC 41 * support for 6byte/512byte hardware ECC
42 * read_ecc, write_ecc extended for different oob-layout 42 * read_ecc, write_ecc extended for different oob-layout
43 * oob layout selections: NAND_NONE_OOB, NAND_JFFS2_OOB, 43 * oob layout selections: NAND_NONE_OOB, NAND_JFFS2_OOB,
44 * NAND_YAFFS_OOB 44 * NAND_YAFFS_OOB
45 * 11-25-2002 tglx Added Manufacturer code FUJITSU, NATIONAL 45 * 11-25-2002 tglx Added Manufacturer code FUJITSU, NATIONAL
46 * Split manufacturer and device ID structures 46 * Split manufacturer and device ID structures
47 * 47 *
48 * 02-08-2004 tglx added option field to nand structure for chip anomalities 48 * 02-08-2004 tglx added option field to nand structure for chip anomalities
49 * 05-25-2004 tglx added bad block table support, ST-MICRO manufacturer id 49 * 05-25-2004 tglx added bad block table support, ST-MICRO manufacturer id
50 * update of nand_chip structure description 50 * update of nand_chip structure description
51 * 01-17-2005 dmarlin added extended commands for AG-AND device and added option 51 * 01-17-2005 dmarlin added extended commands for AG-AND device and added option
52 * for BBT_AUTO_REFRESH. 52 * for BBT_AUTO_REFRESH.
53 * 01-20-2005 dmarlin added optional pointer to hardware specific callback for 53 * 01-20-2005 dmarlin added optional pointer to hardware specific callback for
54 * extra error status checks. 54 * extra error status checks.
55 */ 55 */
56#ifndef __LINUX_MTD_NAND_H 56#ifndef __LINUX_MTD_NAND_H
@@ -120,8 +120,8 @@ extern int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_
120#define NAND_CMD_CACHEDPROG 0x15 120#define NAND_CMD_CACHEDPROG 0x15
121 121
122/* Extended commands for AG-AND device */ 122/* Extended commands for AG-AND device */
123/* 123/*
124 * Note: the command for NAND_CMD_DEPLETE1 is really 0x00 but 124 * Note: the command for NAND_CMD_DEPLETE1 is really 0x00 but
125 * there is no way to distinguish that from NAND_CMD_READ0 125 * there is no way to distinguish that from NAND_CMD_READ0
126 * until the remaining sequence of commands has been completed 126 * until the remaining sequence of commands has been completed
127 * so add a high order bit and mask it off in the command. 127 * so add a high order bit and mask it off in the command.
@@ -145,7 +145,7 @@ extern int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_
145#define NAND_STATUS_READY 0x40 145#define NAND_STATUS_READY 0x40
146#define NAND_STATUS_WP 0x80 146#define NAND_STATUS_WP 0x80
147 147
148/* 148/*
149 * Constants for ECC_MODES 149 * Constants for ECC_MODES
150 */ 150 */
151 151
@@ -191,12 +191,12 @@ extern int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_
191#define NAND_CACHEPRG 0x00000008 191#define NAND_CACHEPRG 0x00000008
192/* Chip has copy back function */ 192/* Chip has copy back function */
193#define NAND_COPYBACK 0x00000010 193#define NAND_COPYBACK 0x00000010
194/* AND Chip which has 4 banks and a confusing page / block 194/* AND Chip which has 4 banks and a confusing page / block
195 * assignment. See Renesas datasheet for further information */ 195 * assignment. See Renesas datasheet for further information */
196#define NAND_IS_AND 0x00000020 196#define NAND_IS_AND 0x00000020
197/* Chip has a array of 4 pages which can be read without 197/* Chip has a array of 4 pages which can be read without
198 * additional ready /busy waits */ 198 * additional ready /busy waits */
199#define NAND_4PAGE_ARRAY 0x00000040 199#define NAND_4PAGE_ARRAY 0x00000040
200/* Chip requires that BBT is periodically rewritten to prevent 200/* Chip requires that BBT is periodically rewritten to prevent
201 * bits from adjacent blocks from 'leaking' in altering data. 201 * bits from adjacent blocks from 'leaking' in altering data.
202 * This happens with the Renesas AG-AND chips, possibly others. */ 202 * This happens with the Renesas AG-AND chips, possibly others. */
@@ -219,8 +219,8 @@ extern int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_
219/* Use a flash based bad block table. This option is passed to the 219/* Use a flash based bad block table. This option is passed to the
220 * default bad block table function. */ 220 * default bad block table function. */
221#define NAND_USE_FLASH_BBT 0x00010000 221#define NAND_USE_FLASH_BBT 0x00010000
222/* The hw ecc generator provides a syndrome instead a ecc value on read 222/* The hw ecc generator provides a syndrome instead a ecc value on read
223 * This can only work if we have the ecc bytes directly behind the 223 * This can only work if we have the ecc bytes directly behind the
224 * data bytes. Applies for DOC and AG-AND Renesas HW Reed Solomon generators */ 224 * data bytes. Applies for DOC and AG-AND Renesas HW Reed Solomon generators */
225#define NAND_HWECC_SYNDROME 0x00020000 225#define NAND_HWECC_SYNDROME 0x00020000
226/* This option skips the bbt scan during initialization. */ 226/* This option skips the bbt scan during initialization. */
@@ -244,6 +244,7 @@ typedef enum {
244 FL_ERASING, 244 FL_ERASING,
245 FL_SYNCING, 245 FL_SYNCING,
246 FL_CACHEDPRG, 246 FL_CACHEDPRG,
247 FL_PM_SUSPENDED,
247} nand_state_t; 248} nand_state_t;
248 249
249/* Keep gcc happy */ 250/* Keep gcc happy */
@@ -251,7 +252,7 @@ struct nand_chip;
251 252
252/** 253/**
253 * struct nand_hw_control - Control structure for hardware controller (e.g ECC generator) shared among independend devices 254 * struct nand_hw_control - Control structure for hardware controller (e.g ECC generator) shared among independend devices
254 * @lock: protection lock 255 * @lock: protection lock
255 * @active: the mtd device which holds the controller currently 256 * @active: the mtd device which holds the controller currently
256 * @wq: wait queue to sleep on if a NAND operation is in progress 257 * @wq: wait queue to sleep on if a NAND operation is in progress
257 * used instead of the per chip wait queue when a hw controller is available 258 * used instead of the per chip wait queue when a hw controller is available
@@ -264,8 +265,8 @@ struct nand_hw_control {
264 265
265/** 266/**
266 * struct nand_chip - NAND Private Flash Chip Data 267 * struct nand_chip - NAND Private Flash Chip Data
267 * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the flash device 268 * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the flash device
268 * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the flash device 269 * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the flash device
269 * @read_byte: [REPLACEABLE] read one byte from the chip 270 * @read_byte: [REPLACEABLE] read one byte from the chip
270 * @write_byte: [REPLACEABLE] write one byte to the chip 271 * @write_byte: [REPLACEABLE] write one byte to the chip
271 * @read_word: [REPLACEABLE] read one word from the chip 272 * @read_word: [REPLACEABLE] read one word from the chip
@@ -288,7 +289,7 @@ struct nand_hw_control {
288 * be provided if a hardware ECC is available 289 * be provided if a hardware ECC is available
289 * @erase_cmd: [INTERN] erase command write function, selectable due to AND support 290 * @erase_cmd: [INTERN] erase command write function, selectable due to AND support
290 * @scan_bbt: [REPLACEABLE] function to scan bad block table 291 * @scan_bbt: [REPLACEABLE] function to scan bad block table
291 * @eccmode: [BOARDSPECIFIC] mode of ecc, see defines 292 * @eccmode: [BOARDSPECIFIC] mode of ecc, see defines
292 * @eccsize: [INTERN] databytes used per ecc-calculation 293 * @eccsize: [INTERN] databytes used per ecc-calculation
293 * @eccbytes: [INTERN] number of ecc bytes per ecc-calculation step 294 * @eccbytes: [INTERN] number of ecc bytes per ecc-calculation step
294 * @eccsteps: [INTERN] number of ecc calculation steps per page 295 * @eccsteps: [INTERN] number of ecc calculation steps per page
@@ -300,7 +301,7 @@ struct nand_hw_control {
300 * @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock 301 * @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock
301 * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry 302 * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
302 * @chip_shift: [INTERN] number of address bits in one chip 303 * @chip_shift: [INTERN] number of address bits in one chip
303 * @data_buf: [INTERN] internal buffer for one page + oob 304 * @data_buf: [INTERN] internal buffer for one page + oob
304 * @oob_buf: [INTERN] oob buffer for one eraseblock 305 * @oob_buf: [INTERN] oob buffer for one eraseblock
305 * @oobdirty: [INTERN] indicates that oob_buf must be reinitialized 306 * @oobdirty: [INTERN] indicates that oob_buf must be reinitialized
306 * @data_poi: [INTERN] pointer to a data buffer 307 * @data_poi: [INTERN] pointer to a data buffer
@@ -315,22 +316,22 @@ struct nand_hw_control {
315 * @bbt: [INTERN] bad block table pointer 316 * @bbt: [INTERN] bad block table pointer
316 * @bbt_td: [REPLACEABLE] bad block table descriptor for flash lookup 317 * @bbt_td: [REPLACEABLE] bad block table descriptor for flash lookup
317 * @bbt_md: [REPLACEABLE] bad block table mirror descriptor 318 * @bbt_md: [REPLACEABLE] bad block table mirror descriptor
318 * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial bad block scan 319 * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial bad block scan
319 * @controller: [OPTIONAL] a pointer to a hardware controller structure which is shared among multiple independend devices 320 * @controller: [OPTIONAL] a pointer to a hardware controller structure which is shared among multiple independend devices
320 * @priv: [OPTIONAL] pointer to private chip date 321 * @priv: [OPTIONAL] pointer to private chip date
321 * @errstat: [OPTIONAL] hardware specific function to perform additional error status checks 322 * @errstat: [OPTIONAL] hardware specific function to perform additional error status checks
322 * (determine if errors are correctable) 323 * (determine if errors are correctable)
323 */ 324 */
324 325
325struct nand_chip { 326struct nand_chip {
326 void __iomem *IO_ADDR_R; 327 void __iomem *IO_ADDR_R;
327 void __iomem *IO_ADDR_W; 328 void __iomem *IO_ADDR_W;
328 329
329 u_char (*read_byte)(struct mtd_info *mtd); 330 u_char (*read_byte)(struct mtd_info *mtd);
330 void (*write_byte)(struct mtd_info *mtd, u_char byte); 331 void (*write_byte)(struct mtd_info *mtd, u_char byte);
331 u16 (*read_word)(struct mtd_info *mtd); 332 u16 (*read_word)(struct mtd_info *mtd);
332 void (*write_word)(struct mtd_info *mtd, u16 word); 333 void (*write_word)(struct mtd_info *mtd, u16 word);
333 334
334 void (*write_buf)(struct mtd_info *mtd, const u_char *buf, int len); 335 void (*write_buf)(struct mtd_info *mtd, const u_char *buf, int len);
335 void (*read_buf)(struct mtd_info *mtd, u_char *buf, int len); 336 void (*read_buf)(struct mtd_info *mtd, u_char *buf, int len);
336 int (*verify_buf)(struct mtd_info *mtd, const u_char *buf, int len); 337 int (*verify_buf)(struct mtd_info *mtd, const u_char *buf, int len);
@@ -395,7 +396,7 @@ struct nand_chip {
395 * @name: Identify the device type 396 * @name: Identify the device type
396 * @id: device ID code 397 * @id: device ID code
397 * @pagesize: Pagesize in bytes. Either 256 or 512 or 0 398 * @pagesize: Pagesize in bytes. Either 256 or 512 or 0
398 * If the pagesize is 0, then the real pagesize 399 * If the pagesize is 0, then the real pagesize
399 * and the eraseize are determined from the 400 * and the eraseize are determined from the
400 * extended id bytes in the chip 401 * extended id bytes in the chip
401 * @erasesize: Size of an erase block in the flash device. 402 * @erasesize: Size of an erase block in the flash device.
@@ -424,7 +425,7 @@ struct nand_manufacturers {
424extern struct nand_flash_dev nand_flash_ids[]; 425extern struct nand_flash_dev nand_flash_ids[];
425extern struct nand_manufacturers nand_manuf_ids[]; 426extern struct nand_manufacturers nand_manuf_ids[];
426 427
427/** 428/**
428 * struct nand_bbt_descr - bad block table descriptor 429 * struct nand_bbt_descr - bad block table descriptor
429 * @options: options for this descriptor 430 * @options: options for this descriptor
430 * @pages: the page(s) where we find the bbt, used with option BBT_ABSPAGE 431 * @pages: the page(s) where we find the bbt, used with option BBT_ABSPAGE
@@ -435,14 +436,14 @@ extern struct nand_manufacturers nand_manuf_ids[];
435 * @version: version read from the bbt page during scan 436 * @version: version read from the bbt page during scan
436 * @len: length of the pattern, if 0 no pattern check is performed 437 * @len: length of the pattern, if 0 no pattern check is performed
437 * @maxblocks: maximum number of blocks to search for a bbt. This number of 438 * @maxblocks: maximum number of blocks to search for a bbt. This number of
438 * blocks is reserved at the end of the device where the tables are 439 * blocks is reserved at the end of the device where the tables are
439 * written. 440 * written.
440 * @reserved_block_code: if non-0, this pattern denotes a reserved (rather than 441 * @reserved_block_code: if non-0, this pattern denotes a reserved (rather than
441 * bad) block in the stored bbt 442 * bad) block in the stored bbt
442 * @pattern: pattern to identify bad block table or factory marked good / 443 * @pattern: pattern to identify bad block table or factory marked good /
443 * bad blocks, can be NULL, if len = 0 444 * bad blocks, can be NULL, if len = 0
444 * 445 *
445 * Descriptor for the bad block table marker and the descriptor for the 446 * Descriptor for the bad block table marker and the descriptor for the
446 * pattern which identifies good and bad blocks. The assumption is made 447 * pattern which identifies good and bad blocks. The assumption is made
447 * that the pattern and the version count are always located in the oob area 448 * that the pattern and the version count are always located in the oob area
448 * of the first block. 449 * of the first block.
diff --git a/include/linux/mtd/onenand.h b/include/linux/mtd/onenand.h
new file mode 100644
index 000000000000..f1fd4215686a
--- /dev/null
+++ b/include/linux/mtd/onenand.h
@@ -0,0 +1,155 @@
1/*
2 * linux/include/linux/mtd/onenand.h
3 *
4 * Copyright (C) 2005 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
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
12#ifndef __LINUX_MTD_ONENAND_H
13#define __LINUX_MTD_ONENAND_H
14
15#include <linux/spinlock.h>
16#include <linux/mtd/onenand_regs.h>
17#include <linux/mtd/bbm.h>
18
19#define MAX_BUFFERRAM 2
20#define MAX_ONENAND_PAGESIZE (2048 + 64)
21
22/* Scan and identify a OneNAND device */
23extern int onenand_scan(struct mtd_info *mtd, int max_chips);
24/* Free resources held by the OneNAND device */
25extern void onenand_release(struct mtd_info *mtd);
26
27/**
28 * onenand_state_t - chip states
29 * Enumeration for OneNAND flash chip state
30 */
31typedef enum {
32 FL_READY,
33 FL_READING,
34 FL_WRITING,
35 FL_ERASING,
36 FL_SYNCING,
37 FL_UNLOCKING,
38 FL_LOCKING,
39 FL_PM_SUSPENDED,
40} onenand_state_t;
41
42/**
43 * struct onenand_bufferram - OneNAND BufferRAM Data
44 * @param block block address in BufferRAM
45 * @param page page address in BufferRAM
46 * @param valid valid flag
47 */
48struct onenand_bufferram {
49 int block;
50 int page;
51 int valid;
52};
53
54/**
55 * struct onenand_chip - OneNAND Private Flash Chip Data
56 * @param base [BOARDSPECIFIC] address to access OneNAND
57 * @param chipsize [INTERN] the size of one chip for multichip arrays
58 * @param device_id [INTERN] device ID
59 * @param verstion_id [INTERN] version ID
60 * @param options [BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about
61 * @param erase_shift [INTERN] number of address bits in a block
62 * @param page_shift [INTERN] number of address bits in a page
63 * @param ppb_shift [INTERN] number of address bits in a pages per block
64 * @param page_mask [INTERN] a page per block mask
65 * @param bufferam_index [INTERN] BufferRAM index
66 * @param bufferam [INTERN] BufferRAM info
67 * @param readw [REPLACEABLE] hardware specific function for read short
68 * @param writew [REPLACEABLE] hardware specific function for write short
69 * @param command [REPLACEABLE] hardware specific function for writing commands to the chip
70 * @param wait [REPLACEABLE] hardware specific function for wait on ready
71 * @param read_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
72 * @param write_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
73 * @param read_word [REPLACEABLE] hardware specific function for read register of OneNAND
74 * @param write_word [REPLACEABLE] hardware specific function for write register of OneNAND
75 * @param scan_bbt [REPLACEALBE] hardware specific function for scaning Bad block Table
76 * @param chip_lock [INTERN] spinlock used to protect access to this structure and the chip
77 * @param wq [INTERN] wait queue to sleep on if a OneNAND operation is in progress
78 * @param state [INTERN] the current state of the OneNAND device
79 * @param autooob [REPLACEABLE] the default (auto)placement scheme
80 * @param bbm [REPLACEABLE] pointer to Bad Block Management
81 * @param priv [OPTIONAL] pointer to private chip date
82 */
83struct onenand_chip {
84 void __iomem *base;
85 unsigned int chipsize;
86 unsigned int device_id;
87 unsigned int density_mask;
88 unsigned int options;
89
90 unsigned int erase_shift;
91 unsigned int page_shift;
92 unsigned int ppb_shift; /* Pages per block shift */
93 unsigned int page_mask;
94
95 unsigned int bufferram_index;
96 struct onenand_bufferram bufferram[MAX_BUFFERRAM];
97
98 int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
99 int (*wait)(struct mtd_info *mtd, int state);
100 int (*read_bufferram)(struct mtd_info *mtd, int area,
101 unsigned char *buffer, int offset, size_t count);
102 int (*write_bufferram)(struct mtd_info *mtd, int area,
103 const unsigned char *buffer, int offset, size_t count);
104 unsigned short (*read_word)(void __iomem *addr);
105 void (*write_word)(unsigned short value, void __iomem *addr);
106 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
107 int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
108 int (*scan_bbt)(struct mtd_info *mtd);
109
110 spinlock_t chip_lock;
111 wait_queue_head_t wq;
112 onenand_state_t state;
113
114 struct nand_oobinfo *autooob;
115
116 void *bbm;
117
118 void *priv;
119};
120
121/*
122 * Helper macros
123 */
124#define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
125#define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
126#define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
127
128#define ONENAND_GET_SYS_CFG1(this) \
129 (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
130#define ONENAND_SET_SYS_CFG1(v, this) \
131 (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
132
133/*
134 * Options bits
135 */
136#define ONENAND_CONT_LOCK (0x0001)
137
138
139/*
140 * OneNAND Flash Manufacturer ID Codes
141 */
142#define ONENAND_MFR_SAMSUNG 0xec
143#define ONENAND_MFR_UNKNOWN 0x00
144
145/**
146 * struct nand_manufacturers - NAND Flash Manufacturer ID Structure
147 * @param name: Manufacturer name
148 * @param id: manufacturer ID code of device.
149*/
150struct onenand_manufacturers {
151 int id;
152 char *name;
153};
154
155#endif /* __LINUX_MTD_ONENAND_H */
diff --git a/include/linux/mtd/onenand_regs.h b/include/linux/mtd/onenand_regs.h
new file mode 100644
index 000000000000..d7832ef8ed63
--- /dev/null
+++ b/include/linux/mtd/onenand_regs.h
@@ -0,0 +1,180 @@
1/*
2 * linux/include/linux/mtd/onenand_regs.h
3 *
4 * OneNAND Register header file
5 *
6 * Copyright (C) 2005 Samsung Electronics
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#ifndef __ONENAND_REG_H
14#define __ONENAND_REG_H
15
16/* Memory Address Map Translation (Word order) */
17#define ONENAND_MEMORY_MAP(x) ((x) << 1)
18
19/*
20 * External BufferRAM area
21 */
22#define ONENAND_BOOTRAM ONENAND_MEMORY_MAP(0x0000)
23#define ONENAND_DATARAM ONENAND_MEMORY_MAP(0x0200)
24#define ONENAND_SPARERAM ONENAND_MEMORY_MAP(0x8010)
25
26/*
27 * OneNAND Registers
28 */
29#define ONENAND_REG_MANUFACTURER_ID ONENAND_MEMORY_MAP(0xF000)
30#define ONENAND_REG_DEVICE_ID ONENAND_MEMORY_MAP(0xF001)
31#define ONENAND_REG_VERSION_ID ONENAND_MEMORY_MAP(0xF002)
32#define ONENAND_REG_DATA_BUFFER_SIZE ONENAND_MEMORY_MAP(0xF003)
33#define ONENAND_REG_BOOT_BUFFER_SIZE ONENAND_MEMORY_MAP(0xF004)
34#define ONENAND_REG_NUM_BUFFERS ONENAND_MEMORY_MAP(0xF005)
35#define ONENAND_REG_TECHNOLOGY ONENAND_MEMORY_MAP(0xF006)
36
37#define ONENAND_REG_START_ADDRESS1 ONENAND_MEMORY_MAP(0xF100)
38#define ONENAND_REG_START_ADDRESS2 ONENAND_MEMORY_MAP(0xF101)
39#define ONENAND_REG_START_ADDRESS3 ONENAND_MEMORY_MAP(0xF102)
40#define ONENAND_REG_START_ADDRESS4 ONENAND_MEMORY_MAP(0xF103)
41#define ONENAND_REG_START_ADDRESS5 ONENAND_MEMORY_MAP(0xF104)
42#define ONENAND_REG_START_ADDRESS6 ONENAND_MEMORY_MAP(0xF105)
43#define ONENAND_REG_START_ADDRESS7 ONENAND_MEMORY_MAP(0xF106)
44#define ONENAND_REG_START_ADDRESS8 ONENAND_MEMORY_MAP(0xF107)
45
46#define ONENAND_REG_START_BUFFER ONENAND_MEMORY_MAP(0xF200)
47#define ONENAND_REG_COMMAND ONENAND_MEMORY_MAP(0xF220)
48#define ONENAND_REG_SYS_CFG1 ONENAND_MEMORY_MAP(0xF221)
49#define ONENAND_REG_SYS_CFG2 ONENAND_MEMORY_MAP(0xF222)
50#define ONENAND_REG_CTRL_STATUS ONENAND_MEMORY_MAP(0xF240)
51#define ONENAND_REG_INTERRUPT ONENAND_MEMORY_MAP(0xF241)
52#define ONENAND_REG_START_BLOCK_ADDRESS ONENAND_MEMORY_MAP(0xF24C)
53#define ONENAND_REG_END_BLOCK_ADDRESS ONENAND_MEMORY_MAP(0xF24D)
54#define ONENAND_REG_WP_STATUS ONENAND_MEMORY_MAP(0xF24E)
55
56#define ONENAND_REG_ECC_STATUS ONENAND_MEMORY_MAP(0xFF00)
57#define ONENAND_REG_ECC_M0 ONENAND_MEMORY_MAP(0xFF01)
58#define ONENAND_REG_ECC_S0 ONENAND_MEMORY_MAP(0xFF02)
59#define ONENAND_REG_ECC_M1 ONENAND_MEMORY_MAP(0xFF03)
60#define ONENAND_REG_ECC_S1 ONENAND_MEMORY_MAP(0xFF04)
61#define ONENAND_REG_ECC_M2 ONENAND_MEMORY_MAP(0xFF05)
62#define ONENAND_REG_ECC_S2 ONENAND_MEMORY_MAP(0xFF06)
63#define ONENAND_REG_ECC_M3 ONENAND_MEMORY_MAP(0xFF07)
64#define ONENAND_REG_ECC_S3 ONENAND_MEMORY_MAP(0xFF08)
65
66/*
67 * Device ID Register F001h (R)
68 */
69#define ONENAND_DEVICE_DENSITY_SHIFT (4)
70#define ONENAND_DEVICE_IS_DDP (1 << 3)
71#define ONENAND_DEVICE_IS_DEMUX (1 << 2)
72#define ONENAND_DEVICE_VCC_MASK (0x3)
73
74#define ONENAND_DEVICE_DENSITY_512Mb (0x002)
75
76/*
77 * Version ID Register F002h (R)
78 */
79#define ONENAND_VERSION_PROCESS_SHIFT (8)
80
81/*
82 * Start Address 1 F100h (R/W)
83 */
84#define ONENAND_DDP_SHIFT (15)
85
86/*
87 * Start Address 8 F107h (R/W)
88 */
89#define ONENAND_FPA_MASK (0x3f)
90#define ONENAND_FPA_SHIFT (2)
91#define ONENAND_FSA_MASK (0x03)
92
93/*
94 * Start Buffer Register F200h (R/W)
95 */
96#define ONENAND_BSA_MASK (0x03)
97#define ONENAND_BSA_SHIFT (8)
98#define ONENAND_BSA_BOOTRAM (0 << 2)
99#define ONENAND_BSA_DATARAM0 (2 << 2)
100#define ONENAND_BSA_DATARAM1 (3 << 2)
101#define ONENAND_BSC_MASK (0x03)
102
103/*
104 * Command Register F220h (R/W)
105 */
106#define ONENAND_CMD_READ (0x00)
107#define ONENAND_CMD_READOOB (0x13)
108#define ONENAND_CMD_PROG (0x80)
109#define ONENAND_CMD_PROGOOB (0x1A)
110#define ONENAND_CMD_UNLOCK (0x23)
111#define ONENAND_CMD_LOCK (0x2A)
112#define ONENAND_CMD_LOCK_TIGHT (0x2C)
113#define ONENAND_CMD_ERASE (0x94)
114#define ONENAND_CMD_RESET (0xF0)
115#define ONENAND_CMD_READID (0x90)
116
117/* NOTE: Those are not *REAL* commands */
118#define ONENAND_CMD_BUFFERRAM (0x1978)
119
120/*
121 * System Configuration 1 Register F221h (R, R/W)
122 */
123#define ONENAND_SYS_CFG1_SYNC_READ (1 << 15)
124#define ONENAND_SYS_CFG1_BRL_7 (7 << 12)
125#define ONENAND_SYS_CFG1_BRL_6 (6 << 12)
126#define ONENAND_SYS_CFG1_BRL_5 (5 << 12)
127#define ONENAND_SYS_CFG1_BRL_4 (4 << 12)
128#define ONENAND_SYS_CFG1_BRL_3 (3 << 12)
129#define ONENAND_SYS_CFG1_BRL_10 (2 << 12)
130#define ONENAND_SYS_CFG1_BRL_9 (1 << 12)
131#define ONENAND_SYS_CFG1_BRL_8 (0 << 12)
132#define ONENAND_SYS_CFG1_BRL_SHIFT (12)
133#define ONENAND_SYS_CFG1_BL_32 (4 << 9)
134#define ONENAND_SYS_CFG1_BL_16 (3 << 9)
135#define ONENAND_SYS_CFG1_BL_8 (2 << 9)
136#define ONENAND_SYS_CFG1_BL_4 (1 << 9)
137#define ONENAND_SYS_CFG1_BL_CONT (0 << 9)
138#define ONENAND_SYS_CFG1_BL_SHIFT (9)
139#define ONENAND_SYS_CFG1_NO_ECC (1 << 8)
140#define ONENAND_SYS_CFG1_RDY (1 << 7)
141#define ONENAND_SYS_CFG1_INT (1 << 6)
142#define ONENAND_SYS_CFG1_IOBE (1 << 5)
143#define ONENAND_SYS_CFG1_RDY_CONF (1 << 4)
144
145/*
146 * Controller Status Register F240h (R)
147 */
148#define ONENAND_CTRL_ONGO (1 << 15)
149#define ONENAND_CTRL_LOCK (1 << 14)
150#define ONENAND_CTRL_LOAD (1 << 13)
151#define ONENAND_CTRL_PROGRAM (1 << 12)
152#define ONENAND_CTRL_ERASE (1 << 11)
153#define ONENAND_CTRL_ERROR (1 << 10)
154#define ONENAND_CTRL_RSTB (1 << 7)
155
156/*
157 * Interrupt Status Register F241h (R)
158 */
159#define ONENAND_INT_MASTER (1 << 15)
160#define ONENAND_INT_READ (1 << 7)
161#define ONENAND_INT_WRITE (1 << 6)
162#define ONENAND_INT_ERASE (1 << 5)
163#define ONENAND_INT_RESET (1 << 4)
164#define ONENAND_INT_CLEAR (0 << 0)
165
166/*
167 * NAND Flash Write Protection Status Register F24Eh (R)
168 */
169#define ONENAND_WP_US (1 << 2)
170#define ONENAND_WP_LS (1 << 1)
171#define ONENAND_WP_LTS (1 << 0)
172
173/*
174 * ECC Status Reigser FF00h (R)
175 */
176#define ONENAND_ECC_1BIT (1 << 0)
177#define ONENAND_ECC_2BIT (1 << 1)
178#define ONENAND_ECC_2BIT_ALL (0xAAAA)
179
180#endif /* __ONENAND_REG_H */
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index 50b2edfc8f11..b03f512d51b9 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -5,7 +5,7 @@
5 * 5 *
6 * This code is GPL 6 * This code is GPL
7 * 7 *
8 * $Id: partitions.h,v 1.16 2004/11/16 18:34:40 dwmw2 Exp $ 8 * $Id: partitions.h,v 1.17 2005/11/07 11:14:55 gleixner Exp $
9 */ 9 */
10 10
11#ifndef MTD_PARTITIONS_H 11#ifndef MTD_PARTITIONS_H
@@ -16,25 +16,25 @@
16 16
17/* 17/*
18 * Partition definition structure: 18 * Partition definition structure:
19 * 19 *
20 * An array of struct partition is passed along with a MTD object to 20 * An array of struct partition is passed along with a MTD object to
21 * add_mtd_partitions() to create them. 21 * add_mtd_partitions() to create them.
22 * 22 *
23 * For each partition, these fields are available: 23 * For each partition, these fields are available:
24 * name: string that will be used to label the partition's MTD device. 24 * name: string that will be used to label the partition's MTD device.
25 * size: the partition size; if defined as MTDPART_SIZ_FULL, the partition 25 * size: the partition size; if defined as MTDPART_SIZ_FULL, the partition
26 * will extend to the end of the master MTD device. 26 * will extend to the end of the master MTD device.
27 * offset: absolute starting position within the master MTD device; if 27 * offset: absolute starting position within the master MTD device; if
28 * defined as MTDPART_OFS_APPEND, the partition will start where the 28 * defined as MTDPART_OFS_APPEND, the partition will start where the
29 * previous one ended; if MTDPART_OFS_NXTBLK, at the next erase block. 29 * previous one ended; if MTDPART_OFS_NXTBLK, at the next erase block.
30 * mask_flags: contains flags that have to be masked (removed) from the 30 * mask_flags: contains flags that have to be masked (removed) from the
31 * master MTD flag set for the corresponding MTD partition. 31 * master MTD flag set for the corresponding MTD partition.
32 * For example, to force a read-only partition, simply adding 32 * For example, to force a read-only partition, simply adding
33 * MTD_WRITEABLE to the mask_flags will do the trick. 33 * MTD_WRITEABLE to the mask_flags will do the trick.
34 * 34 *
35 * Note: writeable partitions require their size and offset be 35 * Note: writeable partitions require their size and offset be
36 * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK). 36 * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK).
37 */ 37 */
38 38
39struct mtd_partition { 39struct mtd_partition {
40 char *name; /* identifier string */ 40 char *name; /* identifier string */
@@ -66,7 +66,7 @@ struct mtd_part_parser {
66 66
67extern int register_mtd_parser(struct mtd_part_parser *parser); 67extern int register_mtd_parser(struct mtd_part_parser *parser);
68extern int deregister_mtd_parser(struct mtd_part_parser *parser); 68extern int deregister_mtd_parser(struct mtd_part_parser *parser);
69extern int parse_mtd_partitions(struct mtd_info *master, const char **types, 69extern int parse_mtd_partitions(struct mtd_info *master, const char **types,
70 struct mtd_partition **pparts, unsigned long origin); 70 struct mtd_partition **pparts, unsigned long origin);
71 71
72#define put_partition_parser(p) do { module_put((p)->owner); } while(0) 72#define put_partition_parser(p) do { module_put((p)->owner); } while(0)
diff --git a/include/linux/mtd/physmap.h b/include/linux/mtd/physmap.h
index 05aa4970677f..c7b8bcdef013 100644
--- a/include/linux/mtd/physmap.h
+++ b/include/linux/mtd/physmap.h
@@ -1,8 +1,8 @@
1/* 1/*
2 * For boards with physically mapped flash and using 2 * For boards with physically mapped flash and using
3 * drivers/mtd/maps/physmap.c mapping driver. 3 * drivers/mtd/maps/physmap.c mapping driver.
4 * 4 *
5 * $Id: physmap.h,v 1.3 2004/07/21 00:16:15 jwboyer Exp $ 5 * $Id: physmap.h,v 1.4 2005/11/07 11:14:55 gleixner Exp $
6 * 6 *
7 * Copyright (C) 2003 MontaVista Software Inc. 7 * Copyright (C) 2003 MontaVista Software Inc.
8 * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net 8 * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
@@ -18,7 +18,7 @@
18 18
19#include <linux/config.h> 19#include <linux/config.h>
20 20
21#if defined(CONFIG_MTD_PHYSMAP) 21#if defined(CONFIG_MTD_PHYSMAP)
22 22
23#include <linux/mtd/mtd.h> 23#include <linux/mtd/mtd.h>
24#include <linux/mtd/map.h> 24#include <linux/mtd/map.h>
@@ -44,12 +44,12 @@ static inline void physmap_configure(unsigned long addr, unsigned long size, int
44#if defined(CONFIG_MTD_PARTITIONS) 44#if defined(CONFIG_MTD_PARTITIONS)
45 45
46/* 46/*
47 * Machines that wish to do flash partition may want to call this function in 47 * Machines that wish to do flash partition may want to call this function in
48 * their setup routine. 48 * their setup routine.
49 * 49 *
50 * physmap_set_partitions(mypartitions, num_parts); 50 * physmap_set_partitions(mypartitions, num_parts);
51 * 51 *
52 * Note that one can always override this hard-coded partition with 52 * Note that one can always override this hard-coded partition with
53 * command line partition (you need to enable CONFIG_MTD_CMDLINE_PARTS). 53 * command line partition (you need to enable CONFIG_MTD_CMDLINE_PARTS).
54 */ 54 */
55void physmap_set_partitions(struct mtd_partition *parts, int num_parts); 55void physmap_set_partitions(struct mtd_partition *parts, int num_parts);
diff --git a/include/linux/mtd/pmc551.h b/include/linux/mtd/pmc551.h
index 113e3087f68a..a7f6d20ad407 100644
--- a/include/linux/mtd/pmc551.h
+++ b/include/linux/mtd/pmc551.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: pmc551.h,v 1.5 2003/01/24 16:49:53 dwmw2 Exp $ 2 * $Id: pmc551.h,v 1.6 2005/11/07 11:14:55 gleixner Exp $
3 * 3 *
4 * PMC551 PCI Mezzanine Ram Device 4 * PMC551 PCI Mezzanine Ram Device
5 * 5 *
@@ -7,7 +7,7 @@
7 * Mark Ferrell 7 * Mark Ferrell
8 * Copyright 1999,2000 Nortel Networks 8 * Copyright 1999,2000 Nortel Networks
9 * 9 *
10 * License: 10 * License:
11 * As part of this driver was derrived from the slram.c driver it falls 11 * As part of this driver was derrived from the slram.c driver it falls
12 * under the same license, which is GNU General Public License v2 12 * under the same license, which is GNU General Public License v2
13 */ 13 */
@@ -17,7 +17,7 @@
17 17
18#include <linux/mtd/mtd.h> 18#include <linux/mtd/mtd.h>
19 19
20#define PMC551_VERSION "$Id: pmc551.h,v 1.5 2003/01/24 16:49:53 dwmw2 Exp $\n"\ 20#define PMC551_VERSION "$Id: pmc551.h,v 1.6 2005/11/07 11:14:55 gleixner Exp $\n"\
21 "Ramix PMC551 PCI Mezzanine Ram Driver. (C) 1999,2000 Nortel Networks.\n" 21 "Ramix PMC551 PCI Mezzanine Ram Driver. (C) 1999,2000 Nortel Networks.\n"
22 22
23/* 23/*
@@ -30,7 +30,7 @@ struct mypriv {
30 u32 curr_map0; 30 u32 curr_map0;
31 u32 asize; 31 u32 asize;
32 struct mtd_info *nextpmc551; 32 struct mtd_info *nextpmc551;
33}; 33};
34 34
35/* 35/*
36 * Function Prototypes 36 * Function Prototypes
@@ -39,7 +39,7 @@ static int pmc551_erase(struct mtd_info *, struct erase_info *);
39static void pmc551_unpoint(struct mtd_info *, u_char *, loff_t, size_t); 39static void pmc551_unpoint(struct mtd_info *, u_char *, loff_t, size_t);
40static int pmc551_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf); 40static int pmc551_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf);
41static int pmc551_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *); 41static int pmc551_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);
42static int pmc551_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 42static int pmc551_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
43 43
44 44
45/* 45/*
@@ -50,7 +50,7 @@ static int pmc551_write(struct mtd_info *, loff_t, size_t, size_t *, const u_cha
50#endif 50#endif
51 51
52#ifndef PCI_DEVICE_ID_V3_SEMI_V370PDC 52#ifndef PCI_DEVICE_ID_V3_SEMI_V370PDC
53#define PCI_DEVICE_ID_V3_SEMI_V370PDC 0x0200 53#define PCI_DEVICE_ID_V3_SEMI_V370PDC 0x0200
54#endif 54#endif
55 55
56 56
diff --git a/include/linux/mtd/xip.h b/include/linux/mtd/xip.h
index 7b7deef6b180..220d50bb71cd 100644
--- a/include/linux/mtd/xip.h
+++ b/include/linux/mtd/xip.h
@@ -12,7 +12,7 @@
12 * it under the terms of the GNU General Public License version 2 as 12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
14 * 14 *
15 * $Id: xip.h,v 1.2 2004/12/01 15:49:10 nico Exp $ 15 * $Id: xip.h,v 1.5 2005/11/07 11:14:55 gleixner Exp $
16 */ 16 */
17 17
18#ifndef __LINUX_MTD_XIP_H__ 18#ifndef __LINUX_MTD_XIP_H__
@@ -23,19 +23,19 @@
23#ifdef CONFIG_MTD_XIP 23#ifdef CONFIG_MTD_XIP
24 24
25/* 25/*
26 * Function that are modifying the flash state away from array mode must
27 * obviously not be running from flash. The __xipram is therefore marking
28 * those functions so they get relocated to ram.
29 */
30#define __xipram __attribute__ ((__section__ (".data")))
31
32/*
33 * We really don't want gcc to guess anything. 26 * We really don't want gcc to guess anything.
34 * We absolutely _need_ proper inlining. 27 * We absolutely _need_ proper inlining.
35 */ 28 */
36#include <linux/compiler.h> 29#include <linux/compiler.h>
37 30
38/* 31/*
32 * Function that are modifying the flash state away from array mode must
33 * obviously not be running from flash. The __xipram is therefore marking
34 * those functions so they get relocated to ram.
35 */
36#define __xipram noinline __attribute__ ((__section__ (".data")))
37
38/*
39 * Each architecture has to provide the following macros. They must access 39 * Each architecture has to provide the following macros. They must access
40 * the hardware directly and not rely on any other (XIP) functions since they 40 * the hardware directly and not rely on any other (XIP) functions since they
41 * won't be available when used (flash not in array mode). 41 * won't be available when used (flash not in array mode).
@@ -60,9 +60,9 @@
60 * overflowing. 60 * overflowing.
61 * 61 *
62 * xip_iprefetch() 62 * xip_iprefetch()
63 * 63 *
64 * Macro to fill instruction prefetch 64 * Macro to fill instruction prefetch
65 * e.g. a series of nops: asm volatile (".rep 8; nop; .endr"); 65 * e.g. a series of nops: asm volatile (".rep 8; nop; .endr");
66 */ 66 */
67 67
68#include <asm/mtd-xip.h> 68#include <asm/mtd-xip.h>
diff --git a/include/linux/namespace.h b/include/linux/namespace.h
index 0e5a86f13b2f..6731977c4c13 100644
--- a/include/linux/namespace.h
+++ b/include/linux/namespace.h
@@ -9,7 +9,8 @@ struct namespace {
9 atomic_t count; 9 atomic_t count;
10 struct vfsmount * root; 10 struct vfsmount * root;
11 struct list_head list; 11 struct list_head list;
12 struct rw_semaphore sem; 12 wait_queue_head_t poll;
13 int event;
13}; 14};
14 15
15extern int copy_namespace(int, struct task_struct *); 16extern int copy_namespace(int, struct task_struct *);
diff --git a/include/linux/net.h b/include/linux/net.h
index 4e981585a89a..d6a41e6577f6 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -71,6 +71,7 @@ typedef enum {
71 * @SOCK_RAW: raw socket 71 * @SOCK_RAW: raw socket
72 * @SOCK_RDM: reliably-delivered message 72 * @SOCK_RDM: reliably-delivered message
73 * @SOCK_SEQPACKET: sequential packet socket 73 * @SOCK_SEQPACKET: sequential packet socket
74 * @SOCK_DCCP: Datagram Congestion Control Protocol socket
74 * @SOCK_PACKET: linux specific way of getting packets at the dev level. 75 * @SOCK_PACKET: linux specific way of getting packets at the dev level.
75 * For writing rarp and other similar things on the user level. 76 * For writing rarp and other similar things on the user level.
76 * 77 *
diff --git a/include/linux/nfsd/nfsd.h b/include/linux/nfsd/nfsd.h
index 6d5a24f3fc6d..51c231a1e5a6 100644
--- a/include/linux/nfsd/nfsd.h
+++ b/include/linux/nfsd/nfsd.h
@@ -60,7 +60,7 @@ typedef int (*nfsd_dirop_t)(struct inode *, struct dentry *, int, int);
60extern struct svc_program nfsd_program; 60extern struct svc_program nfsd_program;
61extern struct svc_version nfsd_version2, nfsd_version3, 61extern struct svc_version nfsd_version2, nfsd_version3,
62 nfsd_version4; 62 nfsd_version4;
63 63extern struct svc_serv *nfsd_serv;
64/* 64/*
65 * Function prototypes. 65 * Function prototypes.
66 */ 66 */
diff --git a/include/linux/nfsd/syscall.h b/include/linux/nfsd/syscall.h
index e65c9db6d13f..781efbf94ed3 100644
--- a/include/linux/nfsd/syscall.h
+++ b/include/linux/nfsd/syscall.h
@@ -39,6 +39,21 @@
39#define NFSCTL_GETFD 7 /* get an fh by path (used by mountd) */ 39#define NFSCTL_GETFD 7 /* get an fh by path (used by mountd) */
40#define NFSCTL_GETFS 8 /* get an fh by path with max FH len */ 40#define NFSCTL_GETFS 8 /* get an fh by path with max FH len */
41 41
42/*
43 * Macros used to set version
44 */
45#define NFSCTL_VERSET(_cltbits, _v) ((_cltbits) |= (1 << (_v)))
46#define NFSCTL_VERUNSET(_cltbits, _v) ((_cltbits) &= ~(1 << (_v)))
47#define NFSCTL_VERISSET(_cltbits, _v) ((_cltbits) & (1 << (_v)))
48
49#if defined(CONFIG_NFSD_V4)
50#define NFSCTL_VERALL (0x1c /* 0b011100 */)
51#elif defined(CONFIG_NFSD_V3)
52#define NFSCTL_VERALL (0x0c /* 0b001100 */)
53#else
54#define NFSCTL_VERALL (0x04 /* 0b000100 */)
55#endif
56
42/* SVC */ 57/* SVC */
43struct nfsctl_svc { 58struct nfsctl_svc {
44 unsigned short svc_port; 59 unsigned short svc_port;
@@ -120,6 +135,8 @@ extern int exp_delclient(struct nfsctl_client *ncp);
120extern int exp_export(struct nfsctl_export *nxp); 135extern int exp_export(struct nfsctl_export *nxp);
121extern int exp_unexport(struct nfsctl_export *nxp); 136extern int exp_unexport(struct nfsctl_export *nxp);
122 137
138extern unsigned int nfsd_versbits;
139
123#endif /* __KERNEL__ */ 140#endif /* __KERNEL__ */
124 141
125#endif /* NFSD_SYSCALL_H */ 142#endif /* NFSD_SYSCALL_H */
diff --git a/include/linux/nfsd/xdr3.h b/include/linux/nfsd/xdr3.h
index 21e18ce7ca63..3c2a71b43bac 100644
--- a/include/linux/nfsd/xdr3.h
+++ b/include/linux/nfsd/xdr3.h
@@ -42,7 +42,7 @@ struct nfsd3_writeargs {
42 __u64 offset; 42 __u64 offset;
43 __u32 count; 43 __u32 count;
44 int stable; 44 int stable;
45 int len; 45 __u32 len;
46 struct kvec vec[RPCSVC_MAXPAGES]; 46 struct kvec vec[RPCSVC_MAXPAGES];
47 int vlen; 47 int vlen;
48}; 48};
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 8cadfdeef674..9a96f0588393 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -519,6 +519,7 @@
519#define PCI_DEVICE_ID_MATROX_MIL 0x0519 519#define PCI_DEVICE_ID_MATROX_MIL 0x0519
520#define PCI_DEVICE_ID_MATROX_MYS 0x051A 520#define PCI_DEVICE_ID_MATROX_MYS 0x051A
521#define PCI_DEVICE_ID_MATROX_MIL_2 0x051b 521#define PCI_DEVICE_ID_MATROX_MIL_2 0x051b
522#define PCI_DEVICE_ID_MATROX_MYS_AGP 0x051e
522#define PCI_DEVICE_ID_MATROX_MIL_2_AGP 0x051f 523#define PCI_DEVICE_ID_MATROX_MIL_2_AGP 0x051f
523#define PCI_DEVICE_ID_MATROX_MGA_IMP 0x0d10 524#define PCI_DEVICE_ID_MATROX_MGA_IMP 0x0d10
524#define PCI_DEVICE_ID_MATROX_G100_MM 0x1000 525#define PCI_DEVICE_ID_MATROX_G100_MM 0x1000
diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h
index 60ffcb9c5791..e87b233615b3 100644
--- a/include/linux/pkt_sched.h
+++ b/include/linux/pkt_sched.h
@@ -93,6 +93,7 @@ struct tc_fifo_qopt
93/* PRIO section */ 93/* PRIO section */
94 94
95#define TCQ_PRIO_BANDS 16 95#define TCQ_PRIO_BANDS 16
96#define TCQ_MIN_PRIO_BANDS 2
96 97
97struct tc_prio_qopt 98struct tc_prio_qopt
98{ 99{
@@ -169,6 +170,7 @@ struct tc_red_qopt
169 unsigned char Scell_log; /* cell size for idle damping */ 170 unsigned char Scell_log; /* cell size for idle damping */
170 unsigned char flags; 171 unsigned char flags;
171#define TC_RED_ECN 1 172#define TC_RED_ECN 1
173#define TC_RED_HARDDROP 2
172}; 174};
173 175
174struct tc_red_xstats 176struct tc_red_xstats
@@ -194,38 +196,34 @@ enum
194 196
195#define TCA_GRED_MAX (__TCA_GRED_MAX - 1) 197#define TCA_GRED_MAX (__TCA_GRED_MAX - 1)
196 198
197#define TCA_SET_OFF TCA_GRED_PARMS
198struct tc_gred_qopt 199struct tc_gred_qopt
199{ 200{
200 __u32 limit; /* HARD maximal queue length (bytes) 201 __u32 limit; /* HARD maximal queue length (bytes) */
201*/ 202 __u32 qth_min; /* Min average length threshold (bytes) */
202 __u32 qth_min; /* Min average length threshold (bytes) 203 __u32 qth_max; /* Max average length threshold (bytes) */
203*/ 204 __u32 DP; /* upto 2^32 DPs */
204 __u32 qth_max; /* Max average length threshold (bytes) 205 __u32 backlog;
205*/ 206 __u32 qave;
206 __u32 DP; /* upto 2^32 DPs */ 207 __u32 forced;
207 __u32 backlog; 208 __u32 early;
208 __u32 qave; 209 __u32 other;
209 __u32 forced; 210 __u32 pdrop;
210 __u32 early; 211 __u8 Wlog; /* log(W) */
211 __u32 other; 212 __u8 Plog; /* log(P_max/(qth_max-qth_min)) */
212 __u32 pdrop; 213 __u8 Scell_log; /* cell size for idle damping */
213 214 __u8 prio; /* prio of this VQ */
214 unsigned char Wlog; /* log(W) */ 215 __u32 packets;
215 unsigned char Plog; /* log(P_max/(qth_max-qth_min)) */ 216 __u32 bytesin;
216 unsigned char Scell_log; /* cell size for idle damping */
217 __u8 prio; /* prio of this VQ */
218 __u32 packets;
219 __u32 bytesin;
220}; 217};
218
221/* gred setup */ 219/* gred setup */
222struct tc_gred_sopt 220struct tc_gred_sopt
223{ 221{
224 __u32 DPs; 222 __u32 DPs;
225 __u32 def_DP; 223 __u32 def_DP;
226 __u8 grio; 224 __u8 grio;
227 __u8 pad1; 225 __u8 flags;
228 __u16 pad2; 226 __u16 pad1;
229}; 227};
230 228
231/* HTB section */ 229/* HTB section */
diff --git a/include/linux/pnp.h b/include/linux/pnp.h
index aadbac29103c..584d57cb393a 100644
--- a/include/linux/pnp.h
+++ b/include/linux/pnp.h
@@ -353,7 +353,6 @@ struct pnp_protocol {
353int pnp_register_protocol(struct pnp_protocol *protocol); 353int pnp_register_protocol(struct pnp_protocol *protocol);
354void pnp_unregister_protocol(struct pnp_protocol *protocol); 354void pnp_unregister_protocol(struct pnp_protocol *protocol);
355int pnp_add_device(struct pnp_dev *dev); 355int pnp_add_device(struct pnp_dev *dev);
356void pnp_remove_device(struct pnp_dev *dev);
357int pnp_device_attach(struct pnp_dev *pnp_dev); 356int pnp_device_attach(struct pnp_dev *pnp_dev);
358void pnp_device_detach(struct pnp_dev *pnp_dev); 357void pnp_device_detach(struct pnp_dev *pnp_dev);
359extern struct list_head pnp_global; 358extern struct list_head pnp_global;
@@ -399,7 +398,6 @@ static inline int pnp_register_protocol(struct pnp_protocol *protocol) { return
399static inline void pnp_unregister_protocol(struct pnp_protocol *protocol) { } 398static inline void pnp_unregister_protocol(struct pnp_protocol *protocol) { }
400static inline int pnp_init_device(struct pnp_dev *dev) { return -ENODEV; } 399static inline int pnp_init_device(struct pnp_dev *dev) { return -ENODEV; }
401static inline int pnp_add_device(struct pnp_dev *dev) { return -ENODEV; } 400static inline int pnp_add_device(struct pnp_dev *dev) { return -ENODEV; }
402static inline void pnp_remove_device(struct pnp_dev *dev) { }
403static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; } 401static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; }
404static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { ; } 402static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { ; }
405 403
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
index dc6f3647bfbc..b2b3dba1298d 100644
--- a/include/linux/ptrace.h
+++ b/include/linux/ptrace.h
@@ -78,6 +78,8 @@
78#include <linux/compiler.h> /* For unlikely. */ 78#include <linux/compiler.h> /* For unlikely. */
79#include <linux/sched.h> /* For struct task_struct. */ 79#include <linux/sched.h> /* For struct task_struct. */
80 80
81
82extern long arch_ptrace(struct task_struct *child, long request, long addr, long data);
81extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len); 83extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len);
82extern int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len); 84extern int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len);
83extern int ptrace_attach(struct task_struct *tsk); 85extern int ptrace_attach(struct task_struct *tsk);
diff --git a/include/linux/quota.h b/include/linux/quota.h
index 700ead45084f..f33aeb22c26a 100644
--- a/include/linux/quota.h
+++ b/include/linux/quota.h
@@ -289,7 +289,6 @@ struct quota_info {
289 struct semaphore dqonoff_sem; /* Serialize quotaon & quotaoff */ 289 struct semaphore dqonoff_sem; /* Serialize quotaon & quotaoff */
290 struct rw_semaphore dqptr_sem; /* serialize ops using quota_info struct, pointers from inode to dquots */ 290 struct rw_semaphore dqptr_sem; /* serialize ops using quota_info struct, pointers from inode to dquots */
291 struct inode *files[MAXQUOTAS]; /* inodes of quotafiles */ 291 struct inode *files[MAXQUOTAS]; /* inodes of quotafiles */
292 struct vfsmount *mnt[MAXQUOTAS]; /* mountpoint entries of filesystems with quota files */
293 struct mem_dqinfo info[MAXQUOTAS]; /* Information for each quota type */ 292 struct mem_dqinfo info[MAXQUOTAS]; /* Information for each quota type */
294 struct quota_format_ops *ops[MAXQUOTAS]; /* Operations for each type */ 293 struct quota_format_ops *ops[MAXQUOTAS]; /* Operations for each type */
295}; 294};
diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h
index d211507ab246..4f34d3d60f2e 100644
--- a/include/linux/quotaops.h
+++ b/include/linux/quotaops.h
@@ -198,38 +198,38 @@ static __inline__ int DQUOT_OFF(struct super_block *sb)
198#define DQUOT_SYNC(sb) do { } while(0) 198#define DQUOT_SYNC(sb) do { } while(0)
199#define DQUOT_OFF(sb) do { } while(0) 199#define DQUOT_OFF(sb) do { } while(0)
200#define DQUOT_TRANSFER(inode, iattr) (0) 200#define DQUOT_TRANSFER(inode, iattr) (0)
201extern __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr) 201static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
202{ 202{
203 inode_add_bytes(inode, nr); 203 inode_add_bytes(inode, nr);
204 return 0; 204 return 0;
205} 205}
206 206
207extern __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr) 207static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
208{ 208{
209 DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr); 209 DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr);
210 mark_inode_dirty(inode); 210 mark_inode_dirty(inode);
211 return 0; 211 return 0;
212} 212}
213 213
214extern __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr) 214static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
215{ 215{
216 inode_add_bytes(inode, nr); 216 inode_add_bytes(inode, nr);
217 return 0; 217 return 0;
218} 218}
219 219
220extern __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr) 220static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
221{ 221{
222 DQUOT_ALLOC_SPACE_NODIRTY(inode, nr); 222 DQUOT_ALLOC_SPACE_NODIRTY(inode, nr);
223 mark_inode_dirty(inode); 223 mark_inode_dirty(inode);
224 return 0; 224 return 0;
225} 225}
226 226
227extern __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr) 227static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
228{ 228{
229 inode_sub_bytes(inode, nr); 229 inode_sub_bytes(inode, nr);
230} 230}
231 231
232extern __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr) 232static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
233{ 233{
234 DQUOT_FREE_SPACE_NODIRTY(inode, nr); 234 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
235 mark_inode_dirty(inode); 235 mark_inode_dirty(inode);
diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h
index 9f0f9281f42a..36e5d269612f 100644
--- a/include/linux/radix-tree.h
+++ b/include/linux/radix-tree.h
@@ -46,6 +46,7 @@ do { \
46 46
47int radix_tree_insert(struct radix_tree_root *, unsigned long, void *); 47int radix_tree_insert(struct radix_tree_root *, unsigned long, void *);
48void *radix_tree_lookup(struct radix_tree_root *, unsigned long); 48void *radix_tree_lookup(struct radix_tree_root *, unsigned long);
49void **radix_tree_lookup_slot(struct radix_tree_root *, unsigned long);
49void *radix_tree_delete(struct radix_tree_root *, unsigned long); 50void *radix_tree_delete(struct radix_tree_root *, unsigned long);
50unsigned int 51unsigned int
51radix_tree_gang_lookup(struct radix_tree_root *root, void **results, 52radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
diff --git a/include/linux/rio.h b/include/linux/rio.h
new file mode 100644
index 000000000000..c7e907faae9c
--- /dev/null
+++ b/include/linux/rio.h
@@ -0,0 +1,325 @@
1/*
2 * RapidIO interconnect services
3 * (RapidIO Interconnect Specification, http://www.rapidio.org)
4 *
5 * Copyright 2005 MontaVista Software, Inc.
6 * Matt Porter <mporter@kernel.crashing.org>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#ifndef LINUX_RIO_H
15#define LINUX_RIO_H
16
17#ifdef __KERNEL__
18
19#include <linux/types.h>
20#include <linux/config.h>
21#include <linux/ioport.h>
22#include <linux/list.h>
23#include <linux/errno.h>
24#include <linux/device.h>
25#include <linux/rio_regs.h>
26
27#define RIO_ANY_DESTID 0xff
28#define RIO_NO_HOPCOUNT -1
29
30#define RIO_MAX_MPORT_RESOURCES 16
31#define RIO_MAX_DEV_RESOURCES 16
32
33#define RIO_GLOBAL_TABLE 0xff /* Indicates access of a switch's
34 global routing table if it
35 has multiple (or per port)
36 tables */
37
38#define RIO_INVALID_ROUTE 0xff /* Indicates that a route table
39 entry is invalid (no route
40 exists for the device ID) */
41
42#ifdef CONFIG_RAPIDIO_8_BIT_TRANSPORT
43#define RIO_MAX_ROUTE_ENTRIES (1 << 8)
44#else
45#define RIO_MAX_ROUTE_ENTRIES (1 << 16)
46#endif
47
48#define RIO_MAX_MBOX 4
49#define RIO_MAX_MSG_SIZE 0x1000
50
51/*
52 * Error values that may be returned by RIO functions.
53 */
54#define RIO_SUCCESSFUL 0x00
55#define RIO_BAD_SIZE 0x81
56
57/*
58 * For RIO devices, the region numbers are assigned this way:
59 *
60 * 0 RapidIO outbound doorbells
61 * 1-15 RapidIO memory regions
62 *
63 * For RIO master ports, the region number are assigned this way:
64 *
65 * 0 RapidIO inbound doorbells
66 * 1 RapidIO inbound mailboxes
67 * 1 RapidIO outbound mailboxes
68 */
69#define RIO_DOORBELL_RESOURCE 0
70#define RIO_INB_MBOX_RESOURCE 1
71#define RIO_OUTB_MBOX_RESOURCE 2
72
73extern struct bus_type rio_bus_type;
74extern struct list_head rio_devices; /* list of all devices */
75
76struct rio_mport;
77
78/**
79 * struct rio_dev - RIO device info
80 * @global_list: Node in list of all RIO devices
81 * @net_list: Node in list of RIO devices in a network
82 * @net: Network this device is a part of
83 * @did: Device ID
84 * @vid: Vendor ID
85 * @device_rev: Device revision
86 * @asm_did: Assembly device ID
87 * @asm_vid: Assembly vendor ID
88 * @asm_rev: Assembly revision
89 * @efptr: Extended feature pointer
90 * @pef: Processing element features
91 * @swpinfo: Switch port info
92 * @src_ops: Source operation capabilities
93 * @dst_ops: Destination operation capabilities
94 * @dma_mask: Mask of bits of RIO address this device implements
95 * @rswitch: Pointer to &struct rio_switch if valid for this device
96 * @driver: Driver claiming this device
97 * @dev: Device model device
98 * @riores: RIO resources this device owns
99 * @destid: Network destination ID
100 */
101struct rio_dev {
102 struct list_head global_list; /* node in list of all RIO devices */
103 struct list_head net_list; /* node in per net list */
104 struct rio_net *net; /* RIO net this device resides in */
105 u16 did;
106 u16 vid;
107 u32 device_rev;
108 u16 asm_did;
109 u16 asm_vid;
110 u16 asm_rev;
111 u16 efptr;
112 u32 pef;
113 u32 swpinfo; /* Only used for switches */
114 u32 src_ops;
115 u32 dst_ops;
116 u64 dma_mask;
117 struct rio_switch *rswitch; /* RIO switch info */
118 struct rio_driver *driver; /* RIO driver claiming this device */
119 struct device dev; /* LDM device structure */
120 struct resource riores[RIO_MAX_DEV_RESOURCES];
121 u16 destid;
122};
123
124#define rio_dev_g(n) list_entry(n, struct rio_dev, global_list)
125#define rio_dev_f(n) list_entry(n, struct rio_dev, net_list)
126#define to_rio_dev(n) container_of(n, struct rio_dev, dev)
127
128/**
129 * struct rio_msg - RIO message event
130 * @res: Mailbox resource
131 * @mcback: Message event callback
132 */
133struct rio_msg {
134 struct resource *res;
135 void (*mcback) (struct rio_mport * mport, void *dev_id, int mbox, int slot);
136};
137
138/**
139 * struct rio_dbell - RIO doorbell event
140 * @node: Node in list of doorbell events
141 * @res: Doorbell resource
142 * @dinb: Doorbell event callback
143 * @dev_id: Device specific pointer to pass on event
144 */
145struct rio_dbell {
146 struct list_head node;
147 struct resource *res;
148 void (*dinb) (struct rio_mport *mport, void *dev_id, u16 src, u16 dst, u16 info);
149 void *dev_id;
150};
151
152/**
153 * struct rio_mport - RIO master port info
154 * @dbells: List of doorbell events
155 * @node: Node in global list of master ports
156 * @nnode: Node in network list of master ports
157 * @iores: I/O mem resource that this master port interface owns
158 * @riores: RIO resources that this master port interfaces owns
159 * @inb_msg: RIO inbound message event descriptors
160 * @outb_msg: RIO outbound message event descriptors
161 * @host_deviceid: Host device ID associated with this master port
162 * @ops: configuration space functions
163 * @id: Port ID, unique among all ports
164 * @index: Port index, unique among all port interfaces of the same type
165 * @name: Port name string
166 */
167struct rio_mport {
168 struct list_head dbells; /* list of doorbell events */
169 struct list_head node; /* node in global list of ports */
170 struct list_head nnode; /* node in net list of ports */
171 struct resource iores;
172 struct resource riores[RIO_MAX_MPORT_RESOURCES];
173 struct rio_msg inb_msg[RIO_MAX_MBOX];
174 struct rio_msg outb_msg[RIO_MAX_MBOX];
175 int host_deviceid; /* Host device ID */
176 struct rio_ops *ops; /* maintenance transaction functions */
177 unsigned char id; /* port ID, unique among all ports */
178 unsigned char index; /* port index, unique among all port
179 interfaces of the same type */
180 unsigned char name[40];
181};
182
183/**
184 * struct rio_net - RIO network info
185 * @node: Node in global list of RIO networks
186 * @devices: List of devices in this network
187 * @mports: List of master ports accessing this network
188 * @hport: Default port for accessing this network
189 * @id: RIO network ID
190 */
191struct rio_net {
192 struct list_head node; /* node in list of networks */
193 struct list_head devices; /* list of devices in this net */
194 struct list_head mports; /* list of ports accessing net */
195 struct rio_mport *hport; /* primary port for accessing net */
196 unsigned char id; /* RIO network ID */
197};
198
199/**
200 * struct rio_switch - RIO switch info
201 * @node: Node in global list of switches
202 * @switchid: Switch ID that is unique across a network
203 * @hopcount: Hopcount to this switch
204 * @destid: Associated destid in the path
205 * @route_table: Copy of switch routing table
206 * @add_entry: Callback for switch-specific route add function
207 * @get_entry: Callback for switch-specific route get function
208 */
209struct rio_switch {
210 struct list_head node;
211 u16 switchid;
212 u16 hopcount;
213 u16 destid;
214 u8 route_table[RIO_MAX_ROUTE_ENTRIES];
215 int (*add_entry) (struct rio_mport * mport, u16 destid, u8 hopcount,
216 u16 table, u16 route_destid, u8 route_port);
217 int (*get_entry) (struct rio_mport * mport, u16 destid, u8 hopcount,
218 u16 table, u16 route_destid, u8 * route_port);
219};
220
221/* Low-level architecture-dependent routines */
222
223/**
224 * struct rio_ops - Low-level RIO configuration space operations
225 * @lcread: Callback to perform local (master port) read of config space.
226 * @lcwrite: Callback to perform local (master port) write of config space.
227 * @cread: Callback to perform network read of config space.
228 * @cwrite: Callback to perform network write of config space.
229 * @dsend: Callback to send a doorbell message.
230 */
231struct rio_ops {
232 int (*lcread) (int index, u32 offset, int len, u32 * data);
233 int (*lcwrite) (int index, u32 offset, int len, u32 data);
234 int (*cread) (int index, u16 destid, u8 hopcount, u32 offset, int len,
235 u32 * data);
236 int (*cwrite) (int index, u16 destid, u8 hopcount, u32 offset, int len,
237 u32 data);
238 int (*dsend) (int index, u16 destid, u16 data);
239};
240
241#define RIO_RESOURCE_MEM 0x00000100
242#define RIO_RESOURCE_DOORBELL 0x00000200
243#define RIO_RESOURCE_MAILBOX 0x00000400
244
245#define RIO_RESOURCE_CACHEABLE 0x00010000
246#define RIO_RESOURCE_PCI 0x00020000
247
248#define RIO_RESOURCE_BUSY 0x80000000
249
250/**
251 * struct rio_driver - RIO driver info
252 * @node: Node in list of drivers
253 * @name: RIO driver name
254 * @id_table: RIO device ids to be associated with this driver
255 * @probe: RIO device inserted
256 * @remove: RIO device removed
257 * @suspend: RIO device suspended
258 * @resume: RIO device awakened
259 * @enable_wake: RIO device enable wake event
260 * @driver: LDM driver struct
261 *
262 * Provides info on a RIO device driver for insertion/removal and
263 * power management purposes.
264 */
265struct rio_driver {
266 struct list_head node;
267 char *name;
268 const struct rio_device_id *id_table;
269 int (*probe) (struct rio_dev * dev, const struct rio_device_id * id);
270 void (*remove) (struct rio_dev * dev);
271 int (*suspend) (struct rio_dev * dev, u32 state);
272 int (*resume) (struct rio_dev * dev);
273 int (*enable_wake) (struct rio_dev * dev, u32 state, int enable);
274 struct device_driver driver;
275};
276
277#define to_rio_driver(drv) container_of(drv,struct rio_driver, driver)
278
279/**
280 * struct rio_device_id - RIO device identifier
281 * @did: RIO device ID
282 * @vid: RIO vendor ID
283 * @asm_did: RIO assembly device ID
284 * @asm_vid: RIO assembly vendor ID
285 *
286 * Identifies a RIO device based on both the device/vendor IDs and
287 * the assembly device/vendor IDs.
288 */
289struct rio_device_id {
290 u16 did, vid;
291 u16 asm_did, asm_vid;
292};
293
294/**
295 * struct rio_route_ops - Per-switch route operations
296 * @vid: RIO vendor ID
297 * @did: RIO device ID
298 * @add_hook: Callback that adds a route entry
299 * @get_hook: Callback that gets a route entry
300 *
301 * Defines the operations that are necessary to manipulate the route
302 * tables for a particular RIO switch device.
303 */
304struct rio_route_ops {
305 u16 vid, did;
306 int (*add_hook) (struct rio_mport * mport, u16 destid, u8 hopcount,
307 u16 table, u16 route_destid, u8 route_port);
308 int (*get_hook) (struct rio_mport * mport, u16 destid, u8 hopcount,
309 u16 table, u16 route_destid, u8 * route_port);
310};
311
312/* Architecture and hardware-specific functions */
313extern int rio_init_mports(void);
314extern void rio_register_mport(struct rio_mport *);
315extern int rio_hw_add_outb_message(struct rio_mport *, struct rio_dev *, int,
316 void *, size_t);
317extern int rio_hw_add_inb_buffer(struct rio_mport *, int, void *);
318extern void *rio_hw_get_inb_message(struct rio_mport *, int);
319extern int rio_open_inb_mbox(struct rio_mport *, void *, int, int);
320extern void rio_close_inb_mbox(struct rio_mport *, int);
321extern int rio_open_outb_mbox(struct rio_mport *, void *, int, int);
322extern void rio_close_outb_mbox(struct rio_mport *, int);
323
324#endif /* __KERNEL__ */
325#endif /* LINUX_RIO_H */
diff --git a/include/linux/rio_drv.h b/include/linux/rio_drv.h
new file mode 100644
index 000000000000..3bd7cce19e26
--- /dev/null
+++ b/include/linux/rio_drv.h
@@ -0,0 +1,469 @@
1/*
2 * RapidIO driver services
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#ifndef LINUX_RIO_DRV_H
14#define LINUX_RIO_DRV_H
15
16#ifdef __KERNEL__
17
18#include <linux/types.h>
19#include <linux/config.h>
20#include <linux/ioport.h>
21#include <linux/list.h>
22#include <linux/errno.h>
23#include <linux/device.h>
24#include <linux/rio.h>
25
26extern int __rio_local_read_config_32(struct rio_mport *port, u32 offset,
27 u32 * data);
28extern int __rio_local_write_config_32(struct rio_mport *port, u32 offset,
29 u32 data);
30extern int __rio_local_read_config_16(struct rio_mport *port, u32 offset,
31 u16 * data);
32extern int __rio_local_write_config_16(struct rio_mport *port, u32 offset,
33 u16 data);
34extern int __rio_local_read_config_8(struct rio_mport *port, u32 offset,
35 u8 * data);
36extern int __rio_local_write_config_8(struct rio_mport *port, u32 offset,
37 u8 data);
38
39extern int rio_mport_read_config_32(struct rio_mport *port, u16 destid,
40 u8 hopcount, u32 offset, u32 * data);
41extern int rio_mport_write_config_32(struct rio_mport *port, u16 destid,
42 u8 hopcount, u32 offset, u32 data);
43extern int rio_mport_read_config_16(struct rio_mport *port, u16 destid,
44 u8 hopcount, u32 offset, u16 * data);
45extern int rio_mport_write_config_16(struct rio_mport *port, u16 destid,
46 u8 hopcount, u32 offset, u16 data);
47extern int rio_mport_read_config_8(struct rio_mport *port, u16 destid,
48 u8 hopcount, u32 offset, u8 * data);
49extern int rio_mport_write_config_8(struct rio_mport *port, u16 destid,
50 u8 hopcount, u32 offset, u8 data);
51
52/**
53 * rio_local_read_config_32 - Read 32 bits from local configuration space
54 * @port: Master port
55 * @offset: Offset into local configuration space
56 * @data: Pointer to read data into
57 *
58 * Reads 32 bits of data from the specified offset within the local
59 * device's configuration space.
60 */
61static inline int rio_local_read_config_32(struct rio_mport *port, u32 offset,
62 u32 * data)
63{
64 return __rio_local_read_config_32(port, offset, data);
65}
66
67/**
68 * rio_local_write_config_32 - Write 32 bits to local configuration space
69 * @port: Master port
70 * @offset: Offset into local configuration space
71 * @data: Data to be written
72 *
73 * Writes 32 bits of data to the specified offset within the local
74 * device's configuration space.
75 */
76static inline int rio_local_write_config_32(struct rio_mport *port, u32 offset,
77 u32 data)
78{
79 return __rio_local_write_config_32(port, offset, data);
80}
81
82/**
83 * rio_local_read_config_16 - Read 16 bits from local configuration space
84 * @port: Master port
85 * @offset: Offset into local configuration space
86 * @data: Pointer to read data into
87 *
88 * Reads 16 bits of data from the specified offset within the local
89 * device's configuration space.
90 */
91static inline int rio_local_read_config_16(struct rio_mport *port, u32 offset,
92 u16 * data)
93{
94 return __rio_local_read_config_16(port, offset, data);
95}
96
97/**
98 * rio_local_write_config_16 - Write 16 bits to local configuration space
99 * @port: Master port
100 * @offset: Offset into local configuration space
101 * @data: Data to be written
102 *
103 * Writes 16 bits of data to the specified offset within the local
104 * device's configuration space.
105 */
106
107static inline int rio_local_write_config_16(struct rio_mport *port, u32 offset,
108 u16 data)
109{
110 return __rio_local_write_config_16(port, offset, data);
111}
112
113/**
114 * rio_local_read_config_8 - Read 8 bits from local configuration space
115 * @port: Master port
116 * @offset: Offset into local configuration space
117 * @data: Pointer to read data into
118 *
119 * Reads 8 bits of data from the specified offset within the local
120 * device's configuration space.
121 */
122static inline int rio_local_read_config_8(struct rio_mport *port, u32 offset,
123 u8 * data)
124{
125 return __rio_local_read_config_8(port, offset, data);
126}
127
128/**
129 * rio_local_write_config_8 - Write 8 bits to local configuration space
130 * @port: Master port
131 * @offset: Offset into local configuration space
132 * @data: Data to be written
133 *
134 * Writes 8 bits of data to the specified offset within the local
135 * device's configuration space.
136 */
137static inline int rio_local_write_config_8(struct rio_mport *port, u32 offset,
138 u8 data)
139{
140 return __rio_local_write_config_8(port, offset, data);
141}
142
143/**
144 * rio_read_config_32 - Read 32 bits from configuration space
145 * @rdev: RIO device
146 * @offset: Offset into device configuration space
147 * @data: Pointer to read data into
148 *
149 * Reads 32 bits of data from the specified offset within the
150 * RIO device's configuration space.
151 */
152static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset,
153 u32 * data)
154{
155 u8 hopcount = 0xff;
156 u16 destid = rdev->destid;
157
158 if (rdev->rswitch) {
159 destid = rdev->rswitch->destid;
160 hopcount = rdev->rswitch->hopcount;
161 }
162
163 return rio_mport_read_config_32(rdev->net->hport, destid, hopcount,
164 offset, data);
165};
166
167/**
168 * rio_write_config_32 - Write 32 bits to configuration space
169 * @rdev: RIO device
170 * @offset: Offset into device configuration space
171 * @data: Data to be written
172 *
173 * Writes 32 bits of data to the specified offset within the
174 * RIO device's configuration space.
175 */
176static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset,
177 u32 data)
178{
179 u8 hopcount = 0xff;
180 u16 destid = rdev->destid;
181
182 if (rdev->rswitch) {
183 destid = rdev->rswitch->destid;
184 hopcount = rdev->rswitch->hopcount;
185 }
186
187 return rio_mport_write_config_32(rdev->net->hport, destid, hopcount,
188 offset, data);
189};
190
191/**
192 * rio_read_config_16 - Read 16 bits from configuration space
193 * @rdev: RIO device
194 * @offset: Offset into device configuration space
195 * @data: Pointer to read data into
196 *
197 * Reads 16 bits of data from the specified offset within the
198 * RIO device's configuration space.
199 */
200static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset,
201 u16 * data)
202{
203 u8 hopcount = 0xff;
204 u16 destid = rdev->destid;
205
206 if (rdev->rswitch) {
207 destid = rdev->rswitch->destid;
208 hopcount = rdev->rswitch->hopcount;
209 }
210
211 return rio_mport_read_config_16(rdev->net->hport, destid, hopcount,
212 offset, data);
213};
214
215/**
216 * rio_write_config_16 - Write 16 bits to configuration space
217 * @rdev: RIO device
218 * @offset: Offset into device configuration space
219 * @data: Data to be written
220 *
221 * Writes 16 bits of data to the specified offset within the
222 * RIO device's configuration space.
223 */
224static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset,
225 u16 data)
226{
227 u8 hopcount = 0xff;
228 u16 destid = rdev->destid;
229
230 if (rdev->rswitch) {
231 destid = rdev->rswitch->destid;
232 hopcount = rdev->rswitch->hopcount;
233 }
234
235 return rio_mport_write_config_16(rdev->net->hport, destid, hopcount,
236 offset, data);
237};
238
239/**
240 * rio_read_config_8 - Read 8 bits from configuration space
241 * @rdev: RIO device
242 * @offset: Offset into device configuration space
243 * @data: Pointer to read data into
244 *
245 * Reads 8 bits of data from the specified offset within the
246 * RIO device's configuration space.
247 */
248static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data)
249{
250 u8 hopcount = 0xff;
251 u16 destid = rdev->destid;
252
253 if (rdev->rswitch) {
254 destid = rdev->rswitch->destid;
255 hopcount = rdev->rswitch->hopcount;
256 }
257
258 return rio_mport_read_config_8(rdev->net->hport, destid, hopcount,
259 offset, data);
260};
261
262/**
263 * rio_write_config_8 - Write 8 bits to configuration space
264 * @rdev: RIO device
265 * @offset: Offset into device configuration space
266 * @data: Data to be written
267 *
268 * Writes 8 bits of data to the specified offset within the
269 * RIO device's configuration space.
270 */
271static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data)
272{
273 u8 hopcount = 0xff;
274 u16 destid = rdev->destid;
275
276 if (rdev->rswitch) {
277 destid = rdev->rswitch->destid;
278 hopcount = rdev->rswitch->hopcount;
279 }
280
281 return rio_mport_write_config_8(rdev->net->hport, destid, hopcount,
282 offset, data);
283};
284
285extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid,
286 u16 data);
287
288/**
289 * rio_send_doorbell - Send a doorbell message to a device
290 * @rdev: RIO device
291 * @data: Doorbell message data
292 *
293 * Send a doorbell message to a RIO device. The doorbell message
294 * has a 16-bit info field provided by the @data argument.
295 */
296static inline int rio_send_doorbell(struct rio_dev *rdev, u16 data)
297{
298 return rio_mport_send_doorbell(rdev->net->hport, rdev->destid, data);
299};
300
301/**
302 * rio_init_mbox_res - Initialize a RIO mailbox resource
303 * @res: resource struct
304 * @start: start of mailbox range
305 * @end: end of mailbox range
306 *
307 * This function is used to initialize the fields of a resource
308 * for use as a mailbox resource. It initializes a range of
309 * mailboxes using the start and end arguments.
310 */
311static inline void rio_init_mbox_res(struct resource *res, int start, int end)
312{
313 memset(res, 0, sizeof(struct resource));
314 res->start = start;
315 res->end = end;
316 res->flags = RIO_RESOURCE_MAILBOX;
317}
318
319/**
320 * rio_init_dbell_res - Initialize a RIO doorbell resource
321 * @res: resource struct
322 * @start: start of doorbell range
323 * @end: end of doorbell range
324 *
325 * This function is used to initialize the fields of a resource
326 * for use as a doorbell resource. It initializes a range of
327 * doorbell messages using the start and end arguments.
328 */
329static inline void rio_init_dbell_res(struct resource *res, u16 start, u16 end)
330{
331 memset(res, 0, sizeof(struct resource));
332 res->start = start;
333 res->end = end;
334 res->flags = RIO_RESOURCE_DOORBELL;
335}
336
337/**
338 * RIO_DEVICE - macro used to describe a specific RIO device
339 * @vid: the 16 bit RIO vendor ID
340 * @did: the 16 bit RIO device ID
341 *
342 * This macro is used to create a struct rio_device_id that matches a
343 * specific device. The assembly vendor and assembly device fields
344 * will be set to %RIO_ANY_ID.
345 */
346#define RIO_DEVICE(dev,ven) \
347 .did = (dev), .vid = (ven), \
348 .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID
349
350/* Mailbox management */
351extern int rio_request_outb_mbox(struct rio_mport *, void *, int, int,
352 void (*)(struct rio_mport *, void *,int, int));
353extern int rio_release_outb_mbox(struct rio_mport *, int);
354
355/**
356 * rio_add_outb_message - Add RIO message to an outbound mailbox queue
357 * @mport: RIO master port containing the outbound queue
358 * @rdev: RIO device the message is be sent to
359 * @mbox: The outbound mailbox queue
360 * @buffer: Pointer to the message buffer
361 * @len: Length of the message buffer
362 *
363 * Adds a RIO message buffer to an outbound mailbox queue for
364 * transmission. Returns 0 on success.
365 */
366static inline int rio_add_outb_message(struct rio_mport *mport,
367 struct rio_dev *rdev, int mbox,
368 void *buffer, size_t len)
369{
370 return rio_hw_add_outb_message(mport, rdev, mbox, buffer, len);
371}
372
373extern int rio_request_inb_mbox(struct rio_mport *, void *, int, int,
374 void (*)(struct rio_mport *, void *, int, int));
375extern int rio_release_inb_mbox(struct rio_mport *, int);
376
377/**
378 * rio_add_inb_buffer - Add buffer to an inbound mailbox queue
379 * @mport: Master port containing the inbound mailbox
380 * @mbox: The inbound mailbox number
381 * @buffer: Pointer to the message buffer
382 *
383 * Adds a buffer to an inbound mailbox queue for reception. Returns
384 * 0 on success.
385 */
386static inline int rio_add_inb_buffer(struct rio_mport *mport, int mbox,
387 void *buffer)
388{
389 return rio_hw_add_inb_buffer(mport, mbox, buffer);
390}
391
392/**
393 * rio_get_inb_message - Get A RIO message from an inbound mailbox queue
394 * @mport: Master port containing the inbound mailbox
395 * @mbox: The inbound mailbox number
396 * @buffer: Pointer to the message buffer
397 *
398 * Get a RIO message from an inbound mailbox queue. Returns 0 on success.
399 */
400static inline void *rio_get_inb_message(struct rio_mport *mport, int mbox)
401{
402 return rio_hw_get_inb_message(mport, mbox);
403}
404
405/* Doorbell management */
406extern int rio_request_inb_dbell(struct rio_mport *, void *, u16, u16,
407 void (*)(struct rio_mport *, void *, u16, u16, u16));
408extern int rio_release_inb_dbell(struct rio_mport *, u16, u16);
409extern struct resource *rio_request_outb_dbell(struct rio_dev *, u16, u16);
410extern int rio_release_outb_dbell(struct rio_dev *, struct resource *);
411
412/* Memory region management */
413int rio_claim_resource(struct rio_dev *, int);
414int rio_request_regions(struct rio_dev *, char *);
415void rio_release_regions(struct rio_dev *);
416int rio_request_region(struct rio_dev *, int, char *);
417void rio_release_region(struct rio_dev *, int);
418
419/* LDM support */
420int rio_register_driver(struct rio_driver *);
421void rio_unregister_driver(struct rio_driver *);
422struct rio_dev *rio_dev_get(struct rio_dev *);
423void rio_dev_put(struct rio_dev *);
424
425/**
426 * rio_name - Get the unique RIO device identifier
427 * @rdev: RIO device
428 *
429 * Get the unique RIO device identifier. Returns the device
430 * identifier string.
431 */
432static inline char *rio_name(struct rio_dev *rdev)
433{
434 return rdev->dev.bus_id;
435}
436
437/**
438 * rio_get_drvdata - Get RIO driver specific data
439 * @rdev: RIO device
440 *
441 * Get RIO driver specific data. Returns a pointer to the
442 * driver specific data.
443 */
444static inline void *rio_get_drvdata(struct rio_dev *rdev)
445{
446 return dev_get_drvdata(&rdev->dev);
447}
448
449/**
450 * rio_set_drvdata - Set RIO driver specific data
451 * @rdev: RIO device
452 * @data: Pointer to driver specific data
453 *
454 * Set RIO driver specific data. device struct driver data pointer
455 * is set to the @data argument.
456 */
457static inline void rio_set_drvdata(struct rio_dev *rdev, void *data)
458{
459 dev_set_drvdata(&rdev->dev, data);
460}
461
462/* Misc driver helpers */
463extern u16 rio_local_get_device_id(struct rio_mport *port);
464extern struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from);
465extern struct rio_dev *rio_get_asm(u16 vid, u16 did, u16 asm_vid, u16 asm_did,
466 struct rio_dev *from);
467
468#endif /* __KERNEL__ */
469#endif /* LINUX_RIO_DRV_H */
diff --git a/include/linux/rio_ids.h b/include/linux/rio_ids.h
new file mode 100644
index 000000000000..919d4e07d54e
--- /dev/null
+++ b/include/linux/rio_ids.h
@@ -0,0 +1,24 @@
1/*
2 * RapidIO devices
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#ifndef LINUX_RIO_IDS_H
14#define LINUX_RIO_IDS_H
15
16#define RIO_ANY_ID 0xffff
17
18#define RIO_VID_FREESCALE 0x0002
19#define RIO_DID_MPC8560 0x0003
20
21#define RIO_VID_TUNDRA 0x000d
22#define RIO_DID_TSI500 0x0500
23
24#endif /* LINUX_RIO_IDS_H */
diff --git a/include/linux/rio_regs.h b/include/linux/rio_regs.h
new file mode 100644
index 000000000000..326540f9b54e
--- /dev/null
+++ b/include/linux/rio_regs.h
@@ -0,0 +1,215 @@
1/*
2 * RapidIO register definitions
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#ifndef LINUX_RIO_REGS_H
14#define LINUX_RIO_REGS_H
15
16/*
17 * In RapidIO, each device has a 2MB configuration space that is
18 * accessed via maintenance transactions. Portions of configuration
19 * space are standardized and/or reserved.
20 */
21#define RIO_DEV_ID_CAR 0x00 /* [I] Device Identity CAR */
22#define RIO_DEV_INFO_CAR 0x04 /* [I] Device Information CAR */
23#define RIO_ASM_ID_CAR 0x08 /* [I] Assembly Identity CAR */
24#define RIO_ASM_ID_MASK 0xffff0000 /* [I] Asm ID Mask */
25#define RIO_ASM_VEN_ID_MASK 0x0000ffff /* [I] Asm Vend Mask */
26
27#define RIO_ASM_INFO_CAR 0x0c /* [I] Assembly Information CAR */
28#define RIO_ASM_REV_MASK 0xffff0000 /* [I] Asm Rev Mask */
29#define RIO_EXT_FTR_PTR_MASK 0x0000ffff /* [I] EF_PTR Mask */
30
31#define RIO_PEF_CAR 0x10 /* [I] Processing Element Features CAR */
32#define RIO_PEF_BRIDGE 0x80000000 /* [I] Bridge */
33#define RIO_PEF_MEMORY 0x40000000 /* [I] MMIO */
34#define RIO_PEF_PROCESSOR 0x20000000 /* [I] Processor */
35#define RIO_PEF_SWITCH 0x10000000 /* [I] Switch */
36#define RIO_PEF_INB_MBOX 0x00f00000 /* [II] Mailboxes */
37#define RIO_PEF_INB_MBOX0 0x00800000 /* [II] Mailbox 0 */
38#define RIO_PEF_INB_MBOX1 0x00400000 /* [II] Mailbox 1 */
39#define RIO_PEF_INB_MBOX2 0x00200000 /* [II] Mailbox 2 */
40#define RIO_PEF_INB_MBOX3 0x00100000 /* [II] Mailbox 3 */
41#define RIO_PEF_INB_DOORBELL 0x00080000 /* [II] Doorbells */
42#define RIO_PEF_CTLS 0x00000010 /* [III] CTLS */
43#define RIO_PEF_EXT_FEATURES 0x00000008 /* [I] EFT_PTR valid */
44#define RIO_PEF_ADDR_66 0x00000004 /* [I] 66 bits */
45#define RIO_PEF_ADDR_50 0x00000002 /* [I] 50 bits */
46#define RIO_PEF_ADDR_34 0x00000001 /* [I] 34 bits */
47
48#define RIO_SWP_INFO_CAR 0x14 /* [I] Switch Port Information CAR */
49#define RIO_SWP_INFO_PORT_TOTAL_MASK 0x0000ff00 /* [I] Total number of ports */
50#define RIO_SWP_INFO_PORT_NUM_MASK 0x000000ff /* [I] Maintenance transaction port number */
51#define RIO_GET_TOTAL_PORTS(x) ((x & RIO_SWP_INFO_PORT_TOTAL_MASK) >> 8)
52
53#define RIO_SRC_OPS_CAR 0x18 /* [I] Source Operations CAR */
54#define RIO_SRC_OPS_READ 0x00008000 /* [I] Read op */
55#define RIO_SRC_OPS_WRITE 0x00004000 /* [I] Write op */
56#define RIO_SRC_OPS_STREAM_WRITE 0x00002000 /* [I] Str-write op */
57#define RIO_SRC_OPS_WRITE_RESPONSE 0x00001000 /* [I] Write/resp op */
58#define RIO_SRC_OPS_DATA_MSG 0x00000800 /* [II] Data msg op */
59#define RIO_SRC_OPS_DOORBELL 0x00000400 /* [II] Doorbell op */
60#define RIO_SRC_OPS_ATOMIC_TST_SWP 0x00000100 /* [I] Atomic TAS op */
61#define RIO_SRC_OPS_ATOMIC_INC 0x00000080 /* [I] Atomic inc op */
62#define RIO_SRC_OPS_ATOMIC_DEC 0x00000040 /* [I] Atomic dec op */
63#define RIO_SRC_OPS_ATOMIC_SET 0x00000020 /* [I] Atomic set op */
64#define RIO_SRC_OPS_ATOMIC_CLR 0x00000010 /* [I] Atomic clr op */
65#define RIO_SRC_OPS_PORT_WRITE 0x00000004 /* [I] Port-write op */
66
67#define RIO_DST_OPS_CAR 0x1c /* Destination Operations CAR */
68#define RIO_DST_OPS_READ 0x00008000 /* [I] Read op */
69#define RIO_DST_OPS_WRITE 0x00004000 /* [I] Write op */
70#define RIO_DST_OPS_STREAM_WRITE 0x00002000 /* [I] Str-write op */
71#define RIO_DST_OPS_WRITE_RESPONSE 0x00001000 /* [I] Write/resp op */
72#define RIO_DST_OPS_DATA_MSG 0x00000800 /* [II] Data msg op */
73#define RIO_DST_OPS_DOORBELL 0x00000400 /* [II] Doorbell op */
74#define RIO_DST_OPS_ATOMIC_TST_SWP 0x00000100 /* [I] Atomic TAS op */
75#define RIO_DST_OPS_ATOMIC_INC 0x00000080 /* [I] Atomic inc op */
76#define RIO_DST_OPS_ATOMIC_DEC 0x00000040 /* [I] Atomic dec op */
77#define RIO_DST_OPS_ATOMIC_SET 0x00000020 /* [I] Atomic set op */
78#define RIO_DST_OPS_ATOMIC_CLR 0x00000010 /* [I] Atomic clr op */
79#define RIO_DST_OPS_PORT_WRITE 0x00000004 /* [I] Port-write op */
80
81#define RIO_OPS_READ 0x00008000 /* [I] Read op */
82#define RIO_OPS_WRITE 0x00004000 /* [I] Write op */
83#define RIO_OPS_STREAM_WRITE 0x00002000 /* [I] Str-write op */
84#define RIO_OPS_WRITE_RESPONSE 0x00001000 /* [I] Write/resp op */
85#define RIO_OPS_DATA_MSG 0x00000800 /* [II] Data msg op */
86#define RIO_OPS_DOORBELL 0x00000400 /* [II] Doorbell op */
87#define RIO_OPS_ATOMIC_TST_SWP 0x00000100 /* [I] Atomic TAS op */
88#define RIO_OPS_ATOMIC_INC 0x00000080 /* [I] Atomic inc op */
89#define RIO_OPS_ATOMIC_DEC 0x00000040 /* [I] Atomic dec op */
90#define RIO_OPS_ATOMIC_SET 0x00000020 /* [I] Atomic set op */
91#define RIO_OPS_ATOMIC_CLR 0x00000010 /* [I] Atomic clr op */
92#define RIO_OPS_PORT_WRITE 0x00000004 /* [I] Port-write op */
93
94 /* 0x20-0x3c *//* Reserved */
95
96#define RIO_MBOX_CSR 0x40 /* [II] Mailbox CSR */
97#define RIO_MBOX0_AVAIL 0x80000000 /* [II] Mbox 0 avail */
98#define RIO_MBOX0_FULL 0x40000000 /* [II] Mbox 0 full */
99#define RIO_MBOX0_EMPTY 0x20000000 /* [II] Mbox 0 empty */
100#define RIO_MBOX0_BUSY 0x10000000 /* [II] Mbox 0 busy */
101#define RIO_MBOX0_FAIL 0x08000000 /* [II] Mbox 0 fail */
102#define RIO_MBOX0_ERROR 0x04000000 /* [II] Mbox 0 error */
103#define RIO_MBOX1_AVAIL 0x00800000 /* [II] Mbox 1 avail */
104#define RIO_MBOX1_FULL 0x00200000 /* [II] Mbox 1 full */
105#define RIO_MBOX1_EMPTY 0x00200000 /* [II] Mbox 1 empty */
106#define RIO_MBOX1_BUSY 0x00100000 /* [II] Mbox 1 busy */
107#define RIO_MBOX1_FAIL 0x00080000 /* [II] Mbox 1 fail */
108#define RIO_MBOX1_ERROR 0x00040000 /* [II] Mbox 1 error */
109#define RIO_MBOX2_AVAIL 0x00008000 /* [II] Mbox 2 avail */
110#define RIO_MBOX2_FULL 0x00004000 /* [II] Mbox 2 full */
111#define RIO_MBOX2_EMPTY 0x00002000 /* [II] Mbox 2 empty */
112#define RIO_MBOX2_BUSY 0x00001000 /* [II] Mbox 2 busy */
113#define RIO_MBOX2_FAIL 0x00000800 /* [II] Mbox 2 fail */
114#define RIO_MBOX2_ERROR 0x00000400 /* [II] Mbox 2 error */
115#define RIO_MBOX3_AVAIL 0x00000080 /* [II] Mbox 3 avail */
116#define RIO_MBOX3_FULL 0x00000040 /* [II] Mbox 3 full */
117#define RIO_MBOX3_EMPTY 0x00000020 /* [II] Mbox 3 empty */
118#define RIO_MBOX3_BUSY 0x00000010 /* [II] Mbox 3 busy */
119#define RIO_MBOX3_FAIL 0x00000008 /* [II] Mbox 3 fail */
120#define RIO_MBOX3_ERROR 0x00000004 /* [II] Mbox 3 error */
121
122#define RIO_WRITE_PORT_CSR 0x44 /* [I] Write Port CSR */
123#define RIO_DOORBELL_CSR 0x44 /* [II] Doorbell CSR */
124#define RIO_DOORBELL_AVAIL 0x80000000 /* [II] Doorbell avail */
125#define RIO_DOORBELL_FULL 0x40000000 /* [II] Doorbell full */
126#define RIO_DOORBELL_EMPTY 0x20000000 /* [II] Doorbell empty */
127#define RIO_DOORBELL_BUSY 0x10000000 /* [II] Doorbell busy */
128#define RIO_DOORBELL_FAILED 0x08000000 /* [II] Doorbell failed */
129#define RIO_DOORBELL_ERROR 0x04000000 /* [II] Doorbell error */
130#define RIO_WRITE_PORT_AVAILABLE 0x00000080 /* [I] Write Port Available */
131#define RIO_WRITE_PORT_FULL 0x00000040 /* [I] Write Port Full */
132#define RIO_WRITE_PORT_EMPTY 0x00000020 /* [I] Write Port Empty */
133#define RIO_WRITE_PORT_BUSY 0x00000010 /* [I] Write Port Busy */
134#define RIO_WRITE_PORT_FAILED 0x00000008 /* [I] Write Port Failed */
135#define RIO_WRITE_PORT_ERROR 0x00000004 /* [I] Write Port Error */
136
137 /* 0x48 *//* Reserved */
138
139#define RIO_PELL_CTRL_CSR 0x4c /* [I] PE Logical Layer Control CSR */
140#define RIO_PELL_ADDR_66 0x00000004 /* [I] 66-bit addr */
141#define RIO_PELL_ADDR_50 0x00000002 /* [I] 50-bit addr */
142#define RIO_PELL_ADDR_34 0x00000001 /* [I] 34-bit addr */
143
144 /* 0x50-0x54 *//* Reserved */
145
146#define RIO_LCSH_BA 0x58 /* [I] LCS High Base Address */
147#define RIO_LCSL_BA 0x5c /* [I] LCS Base Address */
148
149#define RIO_DID_CSR 0x60 /* [III] Base Device ID CSR */
150
151 /* 0x64 *//* Reserved */
152
153#define RIO_HOST_DID_LOCK_CSR 0x68 /* [III] Host Base Device ID Lock CSR */
154#define RIO_COMPONENT_TAG_CSR 0x6c /* [III] Component Tag CSR */
155
156 /* 0x70-0xf8 *//* Reserved */
157 /* 0x100-0xfff8 *//* [I] Extended Features Space */
158 /* 0x10000-0xfffff8 *//* [I] Implementation-defined Space */
159
160/*
161 * Extended Features Space is a configuration space area where
162 * functionality is mapped into extended feature blocks via a
163 * singly linked list of extended feature pointers (EFT_PTR).
164 *
165 * Each extended feature block can be identified/located in
166 * Extended Features Space by walking the extended feature
167 * list starting with the Extended Feature Pointer located
168 * in the Assembly Information CAR.
169 *
170 * Extended Feature Blocks (EFBs) are identified with an assigned
171 * EFB ID. Extended feature block offsets in the definitions are
172 * relative to the offset of the EFB within the Extended Features
173 * Space.
174 */
175
176/* Helper macros to parse the Extended Feature Block header */
177#define RIO_EFB_PTR_MASK 0xffff0000
178#define RIO_EFB_ID_MASK 0x0000ffff
179#define RIO_GET_BLOCK_PTR(x) ((x & RIO_EFB_PTR_MASK) >> 16)
180#define RIO_GET_BLOCK_ID(x) (x & RIO_EFB_ID_MASK)
181
182/* Extended Feature Block IDs */
183#define RIO_EFB_PAR_EP_ID 0x0001 /* [IV] LP/LVDS EP Devices */
184#define RIO_EFB_PAR_EP_REC_ID 0x0002 /* [IV] LP/LVDS EP Recovery Devices */
185#define RIO_EFB_PAR_EP_FREE_ID 0x0003 /* [IV] LP/LVDS EP Free Devices */
186#define RIO_EFB_SER_EP_ID 0x0004 /* [VI] LP/Serial EP Devices */
187#define RIO_EFB_SER_EP_REC_ID 0x0005 /* [VI] LP/Serial EP Recovery Devices */
188#define RIO_EFB_SER_EP_FREE_ID 0x0006 /* [VI] LP/Serial EP Free Devices */
189
190/*
191 * Physical 8/16 LP-LVDS
192 * ID=0x0001, Generic End Point Devices
193 * ID=0x0002, Generic End Point Devices, software assisted recovery option
194 * ID=0x0003, Generic End Point Free Devices
195 *
196 * Physical LP-Serial
197 * ID=0x0004, Generic End Point Devices
198 * ID=0x0005, Generic End Point Devices, software assisted recovery option
199 * ID=0x0006, Generic End Point Free Devices
200 */
201#define RIO_PORT_MNT_HEADER 0x0000
202#define RIO_PORT_REQ_CTL_CSR 0x0020
203#define RIO_PORT_RSP_CTL_CSR 0x0024 /* 0x0001/0x0002 */
204#define RIO_PORT_GEN_CTL_CSR 0x003c
205#define RIO_PORT_GEN_HOST 0x80000000
206#define RIO_PORT_GEN_MASTER 0x40000000
207#define RIO_PORT_GEN_DISCOVERED 0x20000000
208#define RIO_PORT_N_MNT_REQ_CSR(x) (0x0040 + x*0x20) /* 0x0002 */
209#define RIO_PORT_N_MNT_RSP_CSR(x) (0x0044 + x*0x20) /* 0x0002 */
210#define RIO_PORT_N_ACK_STS_CSR(x) (0x0048 + x*0x20) /* 0x0002 */
211#define RIO_PORT_N_ERR_STS_CSR(x) (0x58 + x*0x20)
212#define PORT_N_ERR_STS_PORT_OK 0x00000002
213#define RIO_PORT_N_CTL_CSR(x) (0x5c + x*0x20)
214
215#endif /* LINUX_RIO_REGS_H */
diff --git a/include/linux/rslib.h b/include/linux/rslib.h
index 980c8f74d8dc..ace25acfdc97 100644
--- a/include/linux/rslib.h
+++ b/include/linux/rslib.h
@@ -1,15 +1,15 @@
1/* 1/*
2 * include/linux/rslib.h 2 * include/linux/rslib.h
3 * 3 *
4 * Overview: 4 * Overview:
5 * Generic Reed Solomon encoder / decoder library 5 * Generic Reed Solomon encoder / decoder library
6 * 6 *
7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de) 7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)
8 * 8 *
9 * RS code lifted from reed solomon library written by Phil Karn 9 * RS code lifted from reed solomon library written by Phil Karn
10 * Copyright 2002 Phil Karn, KA9Q 10 * Copyright 2002 Phil Karn, KA9Q
11 * 11 *
12 * $Id: rslib.h,v 1.3 2004/10/05 22:08:22 gleixner Exp $ 12 * $Id: rslib.h,v 1.4 2005/11/07 11:14:52 gleixner Exp $
13 * 13 *
14 * This program is free software; you can redistribute it and/or modify 14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as 15 * it under the terms of the GNU General Public License version 2 as
@@ -21,20 +21,20 @@
21 21
22#include <linux/list.h> 22#include <linux/list.h>
23 23
24/** 24/**
25 * struct rs_control - rs control structure 25 * struct rs_control - rs control structure
26 * 26 *
27 * @mm: Bits per symbol 27 * @mm: Bits per symbol
28 * @nn: Symbols per block (= (1<<mm)-1) 28 * @nn: Symbols per block (= (1<<mm)-1)
29 * @alpha_to: log lookup table 29 * @alpha_to: log lookup table
30 * @index_of: Antilog lookup table 30 * @index_of: Antilog lookup table
31 * @genpoly: Generator polynomial 31 * @genpoly: Generator polynomial
32 * @nroots: Number of generator roots = number of parity symbols 32 * @nroots: Number of generator roots = number of parity symbols
33 * @fcr: First consecutive root, index form 33 * @fcr: First consecutive root, index form
34 * @prim: Primitive element, index form 34 * @prim: Primitive element, index form
35 * @iprim: prim-th root of 1, index form 35 * @iprim: prim-th root of 1, index form
36 * @gfpoly: The primitive generator polynominal 36 * @gfpoly: The primitive generator polynominal
37 * @users: Users of this structure 37 * @users: Users of this structure
38 * @list: List entry for the rs control list 38 * @list: List entry for the rs control list
39*/ 39*/
40struct rs_control { 40struct rs_control {
@@ -58,7 +58,7 @@ int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par,
58 uint16_t invmsk); 58 uint16_t invmsk);
59#endif 59#endif
60#ifdef CONFIG_REED_SOLOMON_DEC8 60#ifdef CONFIG_REED_SOLOMON_DEC8
61int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len, 61int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len,
62 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, 62 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,
63 uint16_t *corr); 63 uint16_t *corr);
64#endif 64#endif
@@ -75,7 +75,7 @@ int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len,
75#endif 75#endif
76 76
77/* Create or get a matching rs control structure */ 77/* Create or get a matching rs control structure */
78struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim, 78struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim,
79 int nroots); 79 int nroots);
80 80
81/* Release a rs control structure */ 81/* Release a rs control structure */
@@ -87,9 +87,9 @@ void free_rs(struct rs_control *rs);
87 * @x: the value to reduce 87 * @x: the value to reduce
88 * 88 *
89 * where 89 * where
90 * rs->mm = number of bits per symbol 90 * rs->mm = number of bits per symbol
91 * rs->nn = (2^rs->mm) - 1 91 * rs->nn = (2^rs->mm) - 1
92 * 92 *
93 * Simple arithmetic modulo would return a wrong result for values 93 * Simple arithmetic modulo would return a wrong result for values
94 * >= 3 * rs->nn 94 * >= 3 * rs->nn
95*/ 95*/
diff --git a/include/linux/sem.h b/include/linux/sem.h
index 106f9757339a..3c1f1120fe88 100644
--- a/include/linux/sem.h
+++ b/include/linux/sem.h
@@ -79,6 +79,8 @@ struct seminfo {
79 79
80#ifdef __KERNEL__ 80#ifdef __KERNEL__
81 81
82struct task_struct;
83
82/* One semaphore structure for each semaphore in the system. */ 84/* One semaphore structure for each semaphore in the system. */
83struct sem { 85struct sem {
84 int semval; /* current value */ 86 int semval; /* current value */
diff --git a/include/linux/shm.h b/include/linux/shm.h
index 80113a1f60bc..a2c896ad0bef 100644
--- a/include/linux/shm.h
+++ b/include/linux/shm.h
@@ -92,6 +92,7 @@ struct shmid_kernel /* private to the kernel */
92#define SHM_DEST 01000 /* segment will be destroyed on last detach */ 92#define SHM_DEST 01000 /* segment will be destroyed on last detach */
93#define SHM_LOCKED 02000 /* segment will not be swapped */ 93#define SHM_LOCKED 02000 /* segment will not be swapped */
94#define SHM_HUGETLB 04000 /* segment will use huge TLB pages */ 94#define SHM_HUGETLB 04000 /* segment will use huge TLB pages */
95#define SHM_NORESERVE 010000 /* don't check for reservations */
95 96
96#ifdef CONFIG_SYSVIPC 97#ifdef CONFIG_SYSVIPC
97long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr); 98long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr);
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 4286d832166f..fdfb8fe8c38c 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -603,23 +603,23 @@ static inline void skb_queue_head_init(struct sk_buff_head *list)
603 */ 603 */
604 604
605/** 605/**
606 * __skb_queue_head - queue a buffer at the list head 606 * __skb_queue_after - queue a buffer at the list head
607 * @list: list to use 607 * @list: list to use
608 * @prev: place after this buffer
608 * @newsk: buffer to queue 609 * @newsk: buffer to queue
609 * 610 *
610 * Queue a buffer at the start of a list. This function takes no locks 611 * Queue a buffer int the middle of a list. This function takes no locks
611 * and you must therefore hold required locks before calling it. 612 * and you must therefore hold required locks before calling it.
612 * 613 *
613 * A buffer cannot be placed on two lists at the same time. 614 * A buffer cannot be placed on two lists at the same time.
614 */ 615 */
615extern void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk); 616static inline void __skb_queue_after(struct sk_buff_head *list,
616static inline void __skb_queue_head(struct sk_buff_head *list, 617 struct sk_buff *prev,
617 struct sk_buff *newsk) 618 struct sk_buff *newsk)
618{ 619{
619 struct sk_buff *prev, *next; 620 struct sk_buff *next;
620
621 list->qlen++; 621 list->qlen++;
622 prev = (struct sk_buff *)list; 622
623 next = prev->next; 623 next = prev->next;
624 newsk->next = next; 624 newsk->next = next;
625 newsk->prev = prev; 625 newsk->prev = prev;
@@ -627,6 +627,23 @@ static inline void __skb_queue_head(struct sk_buff_head *list,
627} 627}
628 628
629/** 629/**
630 * __skb_queue_head - queue a buffer at the list head
631 * @list: list to use
632 * @newsk: buffer to queue
633 *
634 * Queue a buffer at the start of a list. This function takes no locks
635 * and you must therefore hold required locks before calling it.
636 *
637 * A buffer cannot be placed on two lists at the same time.
638 */
639extern void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk);
640static inline void __skb_queue_head(struct sk_buff_head *list,
641 struct sk_buff *newsk)
642{
643 __skb_queue_after(list, (struct sk_buff *)list, newsk);
644}
645
646/**
630 * __skb_queue_tail - queue a buffer at the list tail 647 * __skb_queue_tail - queue a buffer at the list tail
631 * @list: list to use 648 * @list: list to use
632 * @newsk: buffer to queue 649 * @newsk: buffer to queue
@@ -1203,6 +1220,11 @@ static inline void kunmap_skb_frag(void *vaddr)
1203 prefetch(skb->next), (skb != (struct sk_buff *)(queue)); \ 1220 prefetch(skb->next), (skb != (struct sk_buff *)(queue)); \
1204 skb = skb->next) 1221 skb = skb->next)
1205 1222
1223#define skb_queue_reverse_walk(queue, skb) \
1224 for (skb = (queue)->prev; \
1225 prefetch(skb->prev), (skb != (struct sk_buff *)(queue)); \
1226 skb = skb->prev)
1227
1206 1228
1207extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, 1229extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
1208 int noblock, int *err); 1230 int noblock, int *err);
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 09b9aa60063d..d1ea4051b996 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -9,7 +9,7 @@
9 9
10#if defined(__KERNEL__) 10#if defined(__KERNEL__)
11 11
12typedef struct kmem_cache_s kmem_cache_t; 12typedef struct kmem_cache kmem_cache_t;
13 13
14#include <linux/config.h> /* kmalloc_sizes.h needs CONFIG_ options */ 14#include <linux/config.h> /* kmalloc_sizes.h needs CONFIG_ options */
15#include <linux/gfp.h> 15#include <linux/gfp.h>
diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
index 5af8800e0ce3..e4086ec8b952 100644
--- a/include/linux/sunrpc/svc.h
+++ b/include/linux/sunrpc/svc.h
@@ -171,7 +171,8 @@ xdr_argsize_check(struct svc_rqst *rqstp, u32 *p)
171{ 171{
172 char *cp = (char *)p; 172 char *cp = (char *)p;
173 struct kvec *vec = &rqstp->rq_arg.head[0]; 173 struct kvec *vec = &rqstp->rq_arg.head[0];
174 return cp - (char*)vec->iov_base <= vec->iov_len; 174 return cp >= (char*)vec->iov_base
175 && cp <= (char*)vec->iov_base + vec->iov_len;
175} 176}
176 177
177static inline int 178static inline int
diff --git a/include/linux/superhyway.h b/include/linux/superhyway.h
index c906c5a0aaef..17ea468fa362 100644
--- a/include/linux/superhyway.h
+++ b/include/linux/superhyway.h
@@ -19,7 +19,7 @@
19 */ 19 */
20#define SUPERHYWAY_DEVICE_ID_SH5_DMAC 0x0183 20#define SUPERHYWAY_DEVICE_ID_SH5_DMAC 0x0183
21 21
22struct vcr_info { 22struct superhyway_vcr_info {
23 u8 perr_flags; /* P-port Error flags */ 23 u8 perr_flags; /* P-port Error flags */
24 u8 merr_flags; /* Module Error flags */ 24 u8 merr_flags; /* Module Error flags */
25 u16 mod_vers; /* Module Version */ 25 u16 mod_vers; /* Module Version */
@@ -28,6 +28,17 @@ struct vcr_info {
28 u8 top_mb; /* Top Memory block */ 28 u8 top_mb; /* Top Memory block */
29}; 29};
30 30
31struct superhyway_ops {
32 int (*read_vcr)(unsigned long base, struct superhyway_vcr_info *vcr);
33 int (*write_vcr)(unsigned long base, struct superhyway_vcr_info vcr);
34};
35
36struct superhyway_bus {
37 struct superhyway_ops *ops;
38};
39
40extern struct superhyway_bus superhyway_channels[];
41
31struct superhyway_device_id { 42struct superhyway_device_id {
32 unsigned int id; 43 unsigned int id;
33 unsigned long driver_data; 44 unsigned long driver_data;
@@ -55,9 +66,11 @@ struct superhyway_device {
55 66
56 struct superhyway_device_id id; 67 struct superhyway_device_id id;
57 struct superhyway_driver *drv; 68 struct superhyway_driver *drv;
69 struct superhyway_bus *bus;
58 70
59 struct resource resource; 71 int num_resources;
60 struct vcr_info vcr; 72 struct resource *resource;
73 struct superhyway_vcr_info vcr;
61}; 74};
62 75
63#define to_superhyway_device(d) container_of((d), struct superhyway_device, dev) 76#define to_superhyway_device(d) container_of((d), struct superhyway_device, dev)
@@ -65,12 +78,27 @@ struct superhyway_device {
65#define superhyway_get_drvdata(d) dev_get_drvdata(&(d)->dev) 78#define superhyway_get_drvdata(d) dev_get_drvdata(&(d)->dev)
66#define superhyway_set_drvdata(d,p) dev_set_drvdata(&(d)->dev, (p)) 79#define superhyway_set_drvdata(d,p) dev_set_drvdata(&(d)->dev, (p))
67 80
68extern int superhyway_scan_bus(void); 81static inline int
82superhyway_read_vcr(struct superhyway_device *dev, unsigned long base,
83 struct superhyway_vcr_info *vcr)
84{
85 return dev->bus->ops->read_vcr(base, vcr);
86}
87
88static inline int
89superhyway_write_vcr(struct superhyway_device *dev, unsigned long base,
90 struct superhyway_vcr_info vcr)
91{
92 return dev->bus->ops->write_vcr(base, vcr);
93}
94
95extern int superhyway_scan_bus(struct superhyway_bus *);
69 96
70/* drivers/sh/superhyway/superhyway.c */ 97/* drivers/sh/superhyway/superhyway.c */
71int superhyway_register_driver(struct superhyway_driver *); 98int superhyway_register_driver(struct superhyway_driver *);
72void superhyway_unregister_driver(struct superhyway_driver *); 99void superhyway_unregister_driver(struct superhyway_driver *);
73int superhyway_add_device(unsigned int, unsigned long, unsigned long long); 100int superhyway_add_device(unsigned long base, struct superhyway_device *, struct superhyway_bus *);
101int superhyway_add_devices(struct superhyway_bus *bus, struct superhyway_device **devices, int nr_devices);
74 102
75/* drivers/sh/superhyway/superhyway-sysfs.c */ 103/* drivers/sh/superhyway/superhyway-sysfs.c */
76extern struct device_attribute superhyway_dev_attrs[]; 104extern struct device_attribute superhyway_dev_attrs[];
diff --git a/include/linux/wait.h b/include/linux/wait.h
index d38c9fecdc36..d28518236b62 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -54,6 +54,7 @@ struct __wait_queue_head {
54}; 54};
55typedef struct __wait_queue_head wait_queue_head_t; 55typedef struct __wait_queue_head wait_queue_head_t;
56 56
57struct task_struct;
57 58
58/* 59/*
59 * Macros for declaration and initialisaton of the datatypes 60 * Macros for declaration and initialisaton of the datatypes
diff --git a/include/mtd/inftl-user.h b/include/mtd/inftl-user.h
index bda4f2c8f728..9b1e2526b45e 100644
--- a/include/mtd/inftl-user.h
+++ b/include/mtd/inftl-user.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * $Id: inftl-user.h,v 1.1 2004/05/05 15:17:00 dwmw2 Exp $ 2 * $Id: inftl-user.h,v 1.2 2005/11/07 11:14:56 gleixner Exp $
3 * 3 *
4 * Parts of INFTL headers shared with userspace 4 * Parts of INFTL headers shared with userspace
5 * 5 *
6 */ 6 */
7 7
diff --git a/include/mtd/mtd-abi.h b/include/mtd/mtd-abi.h
index 428d9122940b..b5994ea56a5a 100644
--- a/include/mtd/mtd-abi.h
+++ b/include/mtd/mtd-abi.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * $Id: mtd-abi.h,v 1.11 2005/05/19 16:08:58 gleixner Exp $ 2 * $Id: mtd-abi.h,v 1.13 2005/11/07 11:14:56 gleixner Exp $
3 * 3 *
4 * Portions of MTD ABI definition which are shared by kernel and user space 4 * Portions of MTD ABI definition which are shared by kernel and user space
5 */ 5 */
6 6
7#ifndef __MTD_ABI_H__ 7#ifndef __MTD_ABI_H__
@@ -42,6 +42,7 @@ struct mtd_oob_buf {
42#define MTD_OOB 64 // Out-of-band data (NAND flash) 42#define MTD_OOB 64 // Out-of-band data (NAND flash)
43#define MTD_ECC 128 // Device capable of automatic ECC 43#define MTD_ECC 128 // Device capable of automatic ECC
44#define MTD_NO_VIRTBLOCKS 256 // Virtual blocks not allowed 44#define MTD_NO_VIRTBLOCKS 256 // Virtual blocks not allowed
45#define MTD_PROGRAM_REGIONS 512 // Configurable Programming Regions
45 46
46// Some common devices / combinations of capabilities 47// Some common devices / combinations of capabilities
47#define MTD_CAP_ROM 0 48#define MTD_CAP_ROM 0
@@ -80,7 +81,7 @@ struct mtd_info_user {
80}; 81};
81 82
82struct region_info_user { 83struct region_info_user {
83 uint32_t offset; /* At which this region starts, 84 uint32_t offset; /* At which this region starts,
84 * from the beginning of the MTD */ 85 * from the beginning of the MTD */
85 uint32_t erasesize; /* For this region */ 86 uint32_t erasesize; /* For this region */
86 uint32_t numblocks; /* Number of blocks in this region */ 87 uint32_t numblocks; /* Number of blocks in this region */
diff --git a/include/mtd/nftl-user.h b/include/mtd/nftl-user.h
index 924ec0459e9c..b2bca18e7311 100644
--- a/include/mtd/nftl-user.h
+++ b/include/mtd/nftl-user.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * $Id: nftl-user.h,v 1.1 2004/05/05 14:44:57 dwmw2 Exp $ 2 * $Id: nftl-user.h,v 1.2 2005/11/07 11:14:56 gleixner Exp $
3 * 3 *
4 * Parts of NFTL headers shared with userspace 4 * Parts of NFTL headers shared with userspace
5 * 5 *
6 */ 6 */
7 7
diff --git a/include/net/inet_ecn.h b/include/net/inet_ecn.h
index f87845e2e965..b0c47e2eccf1 100644
--- a/include/net/inet_ecn.h
+++ b/include/net/inet_ecn.h
@@ -2,6 +2,7 @@
2#define _INET_ECN_H_ 2#define _INET_ECN_H_
3 3
4#include <linux/ip.h> 4#include <linux/ip.h>
5#include <linux/skbuff.h>
5#include <net/dsfield.h> 6#include <net/dsfield.h>
6 7
7enum { 8enum {
@@ -48,7 +49,7 @@ static inline __u8 INET_ECN_encapsulate(__u8 outer, __u8 inner)
48 (label) |= __constant_htons(INET_ECN_ECT_0 << 4); \ 49 (label) |= __constant_htons(INET_ECN_ECT_0 << 4); \
49 } while (0) 50 } while (0)
50 51
51static inline void IP_ECN_set_ce(struct iphdr *iph) 52static inline int IP_ECN_set_ce(struct iphdr *iph)
52{ 53{
53 u32 check = iph->check; 54 u32 check = iph->check;
54 u32 ecn = (iph->tos + 1) & INET_ECN_MASK; 55 u32 ecn = (iph->tos + 1) & INET_ECN_MASK;
@@ -61,7 +62,7 @@ static inline void IP_ECN_set_ce(struct iphdr *iph)
61 * INET_ECN_CE => 00 62 * INET_ECN_CE => 00
62 */ 63 */
63 if (!(ecn & 2)) 64 if (!(ecn & 2))
64 return; 65 return !ecn;
65 66
66 /* 67 /*
67 * The following gives us: 68 * The following gives us:
@@ -72,6 +73,7 @@ static inline void IP_ECN_set_ce(struct iphdr *iph)
72 73
73 iph->check = check + (check>=0xFFFF); 74 iph->check = check + (check>=0xFFFF);
74 iph->tos |= INET_ECN_CE; 75 iph->tos |= INET_ECN_CE;
76 return 1;
75} 77}
76 78
77static inline void IP_ECN_clear(struct iphdr *iph) 79static inline void IP_ECN_clear(struct iphdr *iph)
@@ -87,11 +89,12 @@ static inline void ipv4_copy_dscp(struct iphdr *outer, struct iphdr *inner)
87 89
88struct ipv6hdr; 90struct ipv6hdr;
89 91
90static inline void IP6_ECN_set_ce(struct ipv6hdr *iph) 92static inline int IP6_ECN_set_ce(struct ipv6hdr *iph)
91{ 93{
92 if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph))) 94 if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
93 return; 95 return 0;
94 *(u32*)iph |= htonl(INET_ECN_CE << 20); 96 *(u32*)iph |= htonl(INET_ECN_CE << 20);
97 return 1;
95} 98}
96 99
97static inline void IP6_ECN_clear(struct ipv6hdr *iph) 100static inline void IP6_ECN_clear(struct ipv6hdr *iph)
@@ -105,4 +108,21 @@ static inline void ipv6_copy_dscp(struct ipv6hdr *outer, struct ipv6hdr *inner)
105 ipv6_change_dsfield(inner, INET_ECN_MASK, dscp); 108 ipv6_change_dsfield(inner, INET_ECN_MASK, dscp);
106} 109}
107 110
111static inline int INET_ECN_set_ce(struct sk_buff *skb)
112{
113 switch (skb->protocol) {
114 case __constant_htons(ETH_P_IP):
115 if (skb->nh.raw + sizeof(struct iphdr) <= skb->tail)
116 return IP_ECN_set_ce(skb->nh.iph);
117 break;
118
119 case __constant_htons(ETH_P_IPV6):
120 if (skb->nh.raw + sizeof(struct ipv6hdr) <= skb->tail)
121 return IP6_ECN_set_ce(skb->nh.ipv6h);
122 break;
123 }
124
125 return 0;
126}
127
108#endif 128#endif
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index f50f95968340..07840baa9341 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -125,9 +125,7 @@ struct inet_hashinfo {
125 rwlock_t lhash_lock ____cacheline_aligned; 125 rwlock_t lhash_lock ____cacheline_aligned;
126 atomic_t lhash_users; 126 atomic_t lhash_users;
127 wait_queue_head_t lhash_wait; 127 wait_queue_head_t lhash_wait;
128 spinlock_t portalloc_lock;
129 kmem_cache_t *bind_bucket_cachep; 128 kmem_cache_t *bind_bucket_cachep;
130 int port_rover;
131}; 129};
132 130
133static inline unsigned int inet_ehashfn(const __u32 laddr, const __u16 lport, 131static inline unsigned int inet_ehashfn(const __u32 laddr, const __u16 lport,
diff --git a/include/net/red.h b/include/net/red.h
new file mode 100644
index 000000000000..2ed4358e3295
--- /dev/null
+++ b/include/net/red.h
@@ -0,0 +1,325 @@
1#ifndef __NET_SCHED_RED_H
2#define __NET_SCHED_RED_H
3
4#include <linux/config.h>
5#include <linux/types.h>
6#include <net/pkt_sched.h>
7#include <net/inet_ecn.h>
8#include <net/dsfield.h>
9
10/* Random Early Detection (RED) algorithm.
11 =======================================
12
13 Source: Sally Floyd and Van Jacobson, "Random Early Detection Gateways
14 for Congestion Avoidance", 1993, IEEE/ACM Transactions on Networking.
15
16 This file codes a "divisionless" version of RED algorithm
17 as written down in Fig.17 of the paper.
18
19 Short description.
20 ------------------
21
22 When a new packet arrives we calculate the average queue length:
23
24 avg = (1-W)*avg + W*current_queue_len,
25
26 W is the filter time constant (chosen as 2^(-Wlog)), it controls
27 the inertia of the algorithm. To allow larger bursts, W should be
28 decreased.
29
30 if (avg > th_max) -> packet marked (dropped).
31 if (avg < th_min) -> packet passes.
32 if (th_min < avg < th_max) we calculate probability:
33
34 Pb = max_P * (avg - th_min)/(th_max-th_min)
35
36 and mark (drop) packet with this probability.
37 Pb changes from 0 (at avg==th_min) to max_P (avg==th_max).
38 max_P should be small (not 1), usually 0.01..0.02 is good value.
39
40 max_P is chosen as a number, so that max_P/(th_max-th_min)
41 is a negative power of two in order arithmetics to contain
42 only shifts.
43
44
45 Parameters, settable by user:
46 -----------------------------
47
48 qth_min - bytes (should be < qth_max/2)
49 qth_max - bytes (should be at least 2*qth_min and less limit)
50 Wlog - bits (<32) log(1/W).
51 Plog - bits (<32)
52
53 Plog is related to max_P by formula:
54
55 max_P = (qth_max-qth_min)/2^Plog;
56
57 F.e. if qth_max=128K and qth_min=32K, then Plog=22
58 corresponds to max_P=0.02
59
60 Scell_log
61 Stab
62
63 Lookup table for log((1-W)^(t/t_ave).
64
65
66 NOTES:
67
68 Upper bound on W.
69 -----------------
70
71 If you want to allow bursts of L packets of size S,
72 you should choose W:
73
74 L + 1 - th_min/S < (1-(1-W)^L)/W
75
76 th_min/S = 32 th_min/S = 4
77
78 log(W) L
79 -1 33
80 -2 35
81 -3 39
82 -4 46
83 -5 57
84 -6 75
85 -7 101
86 -8 135
87 -9 190
88 etc.
89 */
90
91#define RED_STAB_SIZE 256
92#define RED_STAB_MASK (RED_STAB_SIZE - 1)
93
94struct red_stats
95{
96 u32 prob_drop; /* Early probability drops */
97 u32 prob_mark; /* Early probability marks */
98 u32 forced_drop; /* Forced drops, qavg > max_thresh */
99 u32 forced_mark; /* Forced marks, qavg > max_thresh */
100 u32 pdrop; /* Drops due to queue limits */
101 u32 other; /* Drops due to drop() calls */
102 u32 backlog;
103};
104
105struct red_parms
106{
107 /* Parameters */
108 u32 qth_min; /* Min avg length threshold: A scaled */
109 u32 qth_max; /* Max avg length threshold: A scaled */
110 u32 Scell_max;
111 u32 Rmask; /* Cached random mask, see red_rmask */
112 u8 Scell_log;
113 u8 Wlog; /* log(W) */
114 u8 Plog; /* random number bits */
115 u8 Stab[RED_STAB_SIZE];
116
117 /* Variables */
118 int qcount; /* Number of packets since last random
119 number generation */
120 u32 qR; /* Cached random number */
121
122 unsigned long qavg; /* Average queue length: A scaled */
123 psched_time_t qidlestart; /* Start of current idle period */
124};
125
126static inline u32 red_rmask(u8 Plog)
127{
128 return Plog < 32 ? ((1 << Plog) - 1) : ~0UL;
129}
130
131static inline void red_set_parms(struct red_parms *p,
132 u32 qth_min, u32 qth_max, u8 Wlog, u8 Plog,
133 u8 Scell_log, u8 *stab)
134{
135 /* Reset average queue length, the value is strictly bound
136 * to the parameters below, reseting hurts a bit but leaving
137 * it might result in an unreasonable qavg for a while. --TGR
138 */
139 p->qavg = 0;
140
141 p->qcount = -1;
142 p->qth_min = qth_min << Wlog;
143 p->qth_max = qth_max << Wlog;
144 p->Wlog = Wlog;
145 p->Plog = Plog;
146 p->Rmask = red_rmask(Plog);
147 p->Scell_log = Scell_log;
148 p->Scell_max = (255 << Scell_log);
149
150 memcpy(p->Stab, stab, sizeof(p->Stab));
151}
152
153static inline int red_is_idling(struct red_parms *p)
154{
155 return !PSCHED_IS_PASTPERFECT(p->qidlestart);
156}
157
158static inline void red_start_of_idle_period(struct red_parms *p)
159{
160 PSCHED_GET_TIME(p->qidlestart);
161}
162
163static inline void red_end_of_idle_period(struct red_parms *p)
164{
165 PSCHED_SET_PASTPERFECT(p->qidlestart);
166}
167
168static inline void red_restart(struct red_parms *p)
169{
170 red_end_of_idle_period(p);
171 p->qavg = 0;
172 p->qcount = -1;
173}
174
175static inline unsigned long red_calc_qavg_from_idle_time(struct red_parms *p)
176{
177 psched_time_t now;
178 long us_idle;
179 int shift;
180
181 PSCHED_GET_TIME(now);
182 us_idle = PSCHED_TDIFF_SAFE(now, p->qidlestart, p->Scell_max);
183
184 /*
185 * The problem: ideally, average length queue recalcultion should
186 * be done over constant clock intervals. This is too expensive, so
187 * that the calculation is driven by outgoing packets.
188 * When the queue is idle we have to model this clock by hand.
189 *
190 * SF+VJ proposed to "generate":
191 *
192 * m = idletime / (average_pkt_size / bandwidth)
193 *
194 * dummy packets as a burst after idle time, i.e.
195 *
196 * p->qavg *= (1-W)^m
197 *
198 * This is an apparently overcomplicated solution (f.e. we have to
199 * precompute a table to make this calculation in reasonable time)
200 * I believe that a simpler model may be used here,
201 * but it is field for experiments.
202 */
203
204 shift = p->Stab[(us_idle >> p->Scell_log) & RED_STAB_MASK];
205
206 if (shift)
207 return p->qavg >> shift;
208 else {
209 /* Approximate initial part of exponent with linear function:
210 *
211 * (1-W)^m ~= 1-mW + ...
212 *
213 * Seems, it is the best solution to
214 * problem of too coarse exponent tabulation.
215 */
216 us_idle = (p->qavg * us_idle) >> p->Scell_log;
217
218 if (us_idle < (p->qavg >> 1))
219 return p->qavg - us_idle;
220 else
221 return p->qavg >> 1;
222 }
223}
224
225static inline unsigned long red_calc_qavg_no_idle_time(struct red_parms *p,
226 unsigned int backlog)
227{
228 /*
229 * NOTE: p->qavg is fixed point number with point at Wlog.
230 * The formula below is equvalent to floating point
231 * version:
232 *
233 * qavg = qavg*(1-W) + backlog*W;
234 *
235 * --ANK (980924)
236 */
237 return p->qavg + (backlog - (p->qavg >> p->Wlog));
238}
239
240static inline unsigned long red_calc_qavg(struct red_parms *p,
241 unsigned int backlog)
242{
243 if (!red_is_idling(p))
244 return red_calc_qavg_no_idle_time(p, backlog);
245 else
246 return red_calc_qavg_from_idle_time(p);
247}
248
249static inline u32 red_random(struct red_parms *p)
250{
251 return net_random() & p->Rmask;
252}
253
254static inline int red_mark_probability(struct red_parms *p, unsigned long qavg)
255{
256 /* The formula used below causes questions.
257
258 OK. qR is random number in the interval 0..Rmask
259 i.e. 0..(2^Plog). If we used floating point
260 arithmetics, it would be: (2^Plog)*rnd_num,
261 where rnd_num is less 1.
262
263 Taking into account, that qavg have fixed
264 point at Wlog, and Plog is related to max_P by
265 max_P = (qth_max-qth_min)/2^Plog; two lines
266 below have the following floating point equivalent:
267
268 max_P*(qavg - qth_min)/(qth_max-qth_min) < rnd/qcount
269
270 Any questions? --ANK (980924)
271 */
272 return !(((qavg - p->qth_min) >> p->Wlog) * p->qcount < p->qR);
273}
274
275enum {
276 RED_BELOW_MIN_THRESH,
277 RED_BETWEEN_TRESH,
278 RED_ABOVE_MAX_TRESH,
279};
280
281static inline int red_cmp_thresh(struct red_parms *p, unsigned long qavg)
282{
283 if (qavg < p->qth_min)
284 return RED_BELOW_MIN_THRESH;
285 else if (qavg >= p->qth_max)
286 return RED_ABOVE_MAX_TRESH;
287 else
288 return RED_BETWEEN_TRESH;
289}
290
291enum {
292 RED_DONT_MARK,
293 RED_PROB_MARK,
294 RED_HARD_MARK,
295};
296
297static inline int red_action(struct red_parms *p, unsigned long qavg)
298{
299 switch (red_cmp_thresh(p, qavg)) {
300 case RED_BELOW_MIN_THRESH:
301 p->qcount = -1;
302 return RED_DONT_MARK;
303
304 case RED_BETWEEN_TRESH:
305 if (++p->qcount) {
306 if (red_mark_probability(p, qavg)) {
307 p->qcount = 0;
308 p->qR = red_random(p);
309 return RED_PROB_MARK;
310 }
311 } else
312 p->qR = red_random(p);
313
314 return RED_DONT_MARK;
315
316 case RED_ABOVE_MAX_TRESH:
317 p->qcount = -1;
318 return RED_HARD_MARK;
319 }
320
321 BUG();
322 return RED_DONT_MARK;
323}
324
325#endif
diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
index d11f34832a97..7f0ca79d6c98 100644
--- a/include/sound/ac97_codec.h
+++ b/include/sound/ac97_codec.h
@@ -387,15 +387,6 @@
387#define AC97_RATES_MIC_ADC 4 387#define AC97_RATES_MIC_ADC 4
388#define AC97_RATES_SPDIF 5 388#define AC97_RATES_SPDIF 5
389 389
390/* shared controllers */
391enum {
392 AC97_SHARED_TYPE_NONE,
393 AC97_SHARED_TYPE_ICH,
394 AC97_SHARED_TYPE_ATIIXP,
395 AC97_SHARED_TYPE_VIA,
396 AC97_SHARED_TYPES
397};
398
399/* 390/*
400 * 391 *
401 */ 392 */
@@ -468,7 +459,6 @@ struct _snd_ac97_bus {
468 unsigned short used_slots[2][4]; /* actually used PCM slots */ 459 unsigned short used_slots[2][4]; /* actually used PCM slots */
469 unsigned short pcms_count; /* count of PCMs */ 460 unsigned short pcms_count; /* count of PCMs */
470 struct ac97_pcm *pcms; 461 struct ac97_pcm *pcms;
471 unsigned int shared_type; /* type of shared controller betwen audio and modem */
472 ac97_t *codec[4]; 462 ac97_t *codec[4];
473 snd_info_entry_t *proc; 463 snd_info_entry_t *proc;
474}; 464};
diff --git a/include/sound/core.h b/include/sound/core.h
index 6d971a4c4ca0..2be65ad2fd83 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -29,7 +29,6 @@
29#include <linux/pm.h> /* pm_message_t */ 29#include <linux/pm.h> /* pm_message_t */
30 30
31/* Typedef's */ 31/* Typedef's */
32typedef struct timespec snd_timestamp_t;
33typedef struct sndrv_interval snd_interval_t; 32typedef struct sndrv_interval snd_interval_t;
34typedef enum sndrv_card_type snd_card_type; 33typedef enum sndrv_card_type snd_card_type;
35typedef struct sndrv_xferi snd_xferi_t; 34typedef struct sndrv_xferi snd_xferi_t;
@@ -256,6 +255,7 @@ typedef struct _snd_minor snd_minor_t;
256 255
257/* sound.c */ 256/* sound.c */
258 257
258extern int snd_major;
259extern int snd_ecards_limit; 259extern int snd_ecards_limit;
260 260
261void snd_request_card(int card); 261void snd_request_card(int card);
@@ -285,39 +285,6 @@ int snd_oss_init_module(void);
285 285
286/* memory.c */ 286/* memory.c */
287 287
288#ifdef CONFIG_SND_DEBUG_MEMORY
289void snd_memory_init(void);
290void snd_memory_done(void);
291int snd_memory_info_init(void);
292int snd_memory_info_done(void);
293void *snd_hidden_kmalloc(size_t size, gfp_t flags);
294void *snd_hidden_kzalloc(size_t size, gfp_t flags);
295void *snd_hidden_kcalloc(size_t n, size_t size, gfp_t flags);
296void snd_hidden_kfree(const void *obj);
297void *snd_hidden_vmalloc(unsigned long size);
298void snd_hidden_vfree(void *obj);
299char *snd_hidden_kstrdup(const char *s, gfp_t flags);
300#define kmalloc(size, flags) snd_hidden_kmalloc(size, flags)
301#define kzalloc(size, flags) snd_hidden_kzalloc(size, flags)
302#define kcalloc(n, size, flags) snd_hidden_kcalloc(n, size, flags)
303#define kfree(obj) snd_hidden_kfree(obj)
304#define vmalloc(size) snd_hidden_vmalloc(size)
305#define vfree(obj) snd_hidden_vfree(obj)
306#define kmalloc_nocheck(size, flags) snd_wrapper_kmalloc(size, flags)
307#define vmalloc_nocheck(size) snd_wrapper_vmalloc(size)
308#define kfree_nocheck(obj) snd_wrapper_kfree(obj)
309#define vfree_nocheck(obj) snd_wrapper_vfree(obj)
310#define kstrdup(s, flags) snd_hidden_kstrdup(s, flags)
311#else
312#define snd_memory_init() /*NOP*/
313#define snd_memory_done() /*NOP*/
314#define snd_memory_info_init() /*NOP*/
315#define snd_memory_info_done() /*NOP*/
316#define kmalloc_nocheck(size, flags) kmalloc(size, flags)
317#define vmalloc_nocheck(size) vmalloc(size)
318#define kfree_nocheck(obj) kfree(obj)
319#define vfree_nocheck(obj) vfree(obj)
320#endif
321int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count); 288int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
322int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count); 289int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
323 290
@@ -373,8 +340,9 @@ unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
373#endif 340#endif
374 341
375/* misc.c */ 342/* misc.c */
343struct resource;
344void release_and_free_resource(struct resource *res);
376 345
377int snd_task_name(struct task_struct *task, char *name, size_t size);
378#ifdef CONFIG_SND_VERBOSE_PRINTK 346#ifdef CONFIG_SND_VERBOSE_PRINTK
379void snd_verbose_printk(const char *file, int line, const char *format, ...) 347void snd_verbose_printk(const char *file, int line, const char *format, ...)
380 __attribute__ ((format (printf, 3, 4))); 348 __attribute__ ((format (printf, 3, 4)));
@@ -429,34 +397,24 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
429 * When CONFIG_SND_DEBUG is not set, the expression is executed but 397 * When CONFIG_SND_DEBUG is not set, the expression is executed but
430 * not checked. 398 * not checked.
431 */ 399 */
432#define snd_assert(expr, args...) do {\ 400#define snd_assert(expr, args...) do { \
433 if (unlikely(!(expr))) { \ 401 if (unlikely(!(expr))) { \
434 snd_printk(KERN_ERR "BUG? (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\ 402 snd_printk(KERN_ERR "BUG? (%s)\n", __ASTRING__(expr)); \
435 args;\ 403 dump_stack(); \
436 }\ 404 args; \
405 } \
437} while (0) 406} while (0)
438/** 407
439 * snd_runtime_check - run-time assertion macro 408#define snd_BUG() do { \
440 * @expr: expression 409 snd_printk(KERN_ERR "BUG?\n"); \
441 * @args...: the action 410 dump_stack(); \
442 *
443 * This macro checks the expression in run-time and invokes the commands
444 * given in the rest arguments if the assertion is failed.
445 * Unlike snd_assert(), the action commands are executed even if
446 * CONFIG_SND_DEBUG is not set but without any error messages.
447 */
448#define snd_runtime_check(expr, args...) do {\
449 if (unlikely(!(expr))) { \
450 snd_printk(KERN_ERR "ERROR (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
451 args;\
452 }\
453} while (0) 411} while (0)
454 412
455#else /* !CONFIG_SND_DEBUG */ 413#else /* !CONFIG_SND_DEBUG */
456 414
457#define snd_printd(fmt, args...) /* nothing */ 415#define snd_printd(fmt, args...) /* nothing */
458#define snd_assert(expr, args...) (void)(expr) 416#define snd_assert(expr, args...) (void)(expr)
459#define snd_runtime_check(expr, args...) do { if (!(expr)) { args; } } while (0) 417#define snd_BUG() /* nothing */
460 418
461#endif /* CONFIG_SND_DEBUG */ 419#endif /* CONFIG_SND_DEBUG */
462 420
@@ -473,30 +431,6 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
473#define snd_printdd(format, args...) /* nothing */ 431#define snd_printdd(format, args...) /* nothing */
474#endif 432#endif
475 433
476#define snd_BUG() snd_assert(0, )
477
478
479static inline void snd_timestamp_now(struct timespec *tstamp, int timespec)
480{
481 struct timeval val;
482 /* FIXME: use a linear time source */
483 do_gettimeofday(&val);
484 tstamp->tv_sec = val.tv_sec;
485 tstamp->tv_nsec = val.tv_usec;
486 if (timespec)
487 tstamp->tv_nsec *= 1000L;
488}
489
490static inline void snd_timestamp_zero(struct timespec *tstamp)
491{
492 tstamp->tv_sec = 0;
493 tstamp->tv_nsec = 0;
494}
495
496static inline int snd_timestamp_null(struct timespec *tstamp)
497{
498 return tstamp->tv_sec == 0 && tstamp->tv_nsec == 0;
499}
500 434
501#define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */ 435#define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */
502 436
diff --git a/include/sound/driver.h b/include/sound/driver.h
index 1ec2fae050a6..3f0416ac24d9 100644
--- a/include/sound/driver.h
+++ b/include/sound/driver.h
@@ -44,21 +44,4 @@
44 44
45#include <linux/module.h> 45#include <linux/module.h>
46 46
47/*
48 * ==========================================================================
49 */
50
51#ifdef CONFIG_SND_DEBUG_MEMORY
52#include <linux/slab.h>
53#include <linux/vmalloc.h>
54void *snd_wrapper_kmalloc(size_t, gfp_t);
55#undef kmalloc
56void snd_wrapper_kfree(const void *);
57#undef kfree
58void *snd_wrapper_vmalloc(size_t);
59#undef vmalloc
60void snd_wrapper_vfree(void *);
61#undef vfree
62#endif
63
64#endif /* __SOUND_DRIVER_H */ 47#endif /* __SOUND_DRIVER_H */
diff --git a/include/sound/emu10k1.h b/include/sound/emu10k1.h
index 46e3c0bf3c94..8411c7ef6f11 100644
--- a/include/sound/emu10k1.h
+++ b/include/sound/emu10k1.h
@@ -48,7 +48,8 @@
48 48
49/* FIXME? - according to the OSS driver the EMU10K1 needs a 29 bit DMA mask */ 49/* FIXME? - according to the OSS driver the EMU10K1 needs a 29 bit DMA mask */
50#define EMU10K1_DMA_MASK 0x7fffffffUL /* 31bit */ 50#define EMU10K1_DMA_MASK 0x7fffffffUL /* 31bit */
51#define AUDIGY_DMA_MASK 0xffffffffUL /* 32bit */ 51#define AUDIGY_DMA_MASK 0x7fffffffUL /* 31bit FIXME - 32 should work? */
52 /* See ALSA bug #1276 - rlrevell */
52 53
53#define TMEMSIZE 256*1024 54#define TMEMSIZE 256*1024
54#define TMEMSIZEREG 4 55#define TMEMSIZEREG 4
diff --git a/include/sound/minors.h b/include/sound/minors.h
index b7b0d8309449..a17b5c9961bb 100644
--- a/include/sound/minors.h
+++ b/include/sound/minors.h
@@ -27,8 +27,9 @@
27#define SNDRV_MINOR(card, dev) (((card) << 5) | (dev)) 27#define SNDRV_MINOR(card, dev) (((card) << 5) | (dev))
28 28
29#define SNDRV_MINOR_CONTROL 0 /* 0 - 0 */ 29#define SNDRV_MINOR_CONTROL 0 /* 0 - 0 */
30#define SNDRV_MINOR_SEQUENCER 1 30#define SNDRV_MINOR_GLOBAL 1 /* 1 */
31#define SNDRV_MINOR_TIMER (1+32) 31#define SNDRV_MINOR_SEQUENCER (SNDRV_MINOR_GLOBAL + 0 * 32)
32#define SNDRV_MINOR_TIMER (SNDRV_MINOR_GLOBAL + 1 * 32)
32#define SNDRV_MINOR_HWDEP 4 /* 4 - 7 */ 33#define SNDRV_MINOR_HWDEP 4 /* 4 - 7 */
33#define SNDRV_MINOR_HWDEPS 4 34#define SNDRV_MINOR_HWDEPS 4
34#define SNDRV_MINOR_RAWMIDI 8 /* 8 - 15 */ 35#define SNDRV_MINOR_RAWMIDI 8 /* 8 - 15 */
@@ -39,12 +40,9 @@
39 40
40#define SNDRV_DEVICE_TYPE_CONTROL SNDRV_MINOR_CONTROL 41#define SNDRV_DEVICE_TYPE_CONTROL SNDRV_MINOR_CONTROL
41#define SNDRV_DEVICE_TYPE_HWDEP SNDRV_MINOR_HWDEP 42#define SNDRV_DEVICE_TYPE_HWDEP SNDRV_MINOR_HWDEP
42#define SNDRV_DEVICE_TYPE_MIXER SNDRV_MINOR_MIXER
43#define SNDRV_DEVICE_TYPE_RAWMIDI SNDRV_MINOR_RAWMIDI 43#define SNDRV_DEVICE_TYPE_RAWMIDI SNDRV_MINOR_RAWMIDI
44#define SNDRV_DEVICE_TYPE_PCM_PLAYBACK SNDRV_MINOR_PCM_PLAYBACK 44#define SNDRV_DEVICE_TYPE_PCM_PLAYBACK SNDRV_MINOR_PCM_PLAYBACK
45#define SNDRV_DEVICE_TYPE_PCM_PLOOP SNDRV_MINOR_PCM_PLOOP
46#define SNDRV_DEVICE_TYPE_PCM_CAPTURE SNDRV_MINOR_PCM_CAPTURE 45#define SNDRV_DEVICE_TYPE_PCM_CAPTURE SNDRV_MINOR_PCM_CAPTURE
47#define SNDRV_DEVICE_TYPE_PCM_CLOOP SNDRV_MINOR_PCM_CLOOP
48#define SNDRV_DEVICE_TYPE_SEQUENCER SNDRV_MINOR_SEQUENCER 46#define SNDRV_DEVICE_TYPE_SEQUENCER SNDRV_MINOR_SEQUENCER
49#define SNDRV_DEVICE_TYPE_TIMER SNDRV_MINOR_TIMER 47#define SNDRV_DEVICE_TYPE_TIMER SNDRV_MINOR_TIMER
50 48
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 2b23a5967071..acc4fa9d5abe 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -281,7 +281,7 @@ typedef struct {
281struct _snd_pcm_runtime { 281struct _snd_pcm_runtime {
282 /* -- Status -- */ 282 /* -- Status -- */
283 snd_pcm_substream_t *trigger_master; 283 snd_pcm_substream_t *trigger_master;
284 snd_timestamp_t trigger_tstamp; /* trigger timestamp */ 284 struct timespec trigger_tstamp; /* trigger timestamp */
285 int overrange; 285 int overrange;
286 snd_pcm_uframes_t avail_max; 286 snd_pcm_uframes_t avail_max;
287 snd_pcm_uframes_t hw_ptr_base; /* Position at buffer restart */ 287 snd_pcm_uframes_t hw_ptr_base; /* Position at buffer restart */
@@ -306,7 +306,6 @@ struct _snd_pcm_runtime {
306 unsigned int rate_den; 306 unsigned int rate_den;
307 307
308 /* -- SW params -- */ 308 /* -- SW params -- */
309 int tstamp_timespec; /* use timeval (0) or timespec (1) */
310 snd_pcm_tstamp_t tstamp_mode; /* mmap timestamp is updated */ 309 snd_pcm_tstamp_t tstamp_mode; /* mmap timestamp is updated */
311 unsigned int period_step; 310 unsigned int period_step;
312 unsigned int sleep_min; /* min ticks to sleep */ 311 unsigned int sleep_min; /* min ticks to sleep */
diff --git a/include/sound/timer.h b/include/sound/timer.h
index 1898511a0f38..b55f38ae56e1 100644
--- a/include/sound/timer.h
+++ b/include/sound/timer.h
@@ -88,6 +88,7 @@ struct _snd_timer_hardware {
88struct _snd_timer { 88struct _snd_timer {
89 snd_timer_class_t tmr_class; 89 snd_timer_class_t tmr_class;
90 snd_card_t *card; 90 snd_card_t *card;
91 struct module *module;
91 int tmr_device; 92 int tmr_device;
92 int tmr_subdevice; 93 int tmr_subdevice;
93 char id[64]; 94 char id[64];
diff --git a/include/sound/version.h b/include/sound/version.h
index ee32af20dba9..d1bd3b723967 100644
--- a/include/sound/version.h
+++ b/include/sound/version.h
@@ -1,3 +1,3 @@
1/* include/version.h. Generated by configure. */ 1/* include/version.h. Generated by configure. */
2#define CONFIG_SND_VERSION "1.0.10rc1" 2#define CONFIG_SND_VERSION "1.0.10rc3"
3#define CONFIG_SND_DATE " (Mon Sep 12 08:13:09 2005 UTC)" 3#define CONFIG_SND_DATE " (Mon Nov 07 13:30:21 2005 UTC)"
diff --git a/init/Kconfig b/init/Kconfig
index 3dcbd5bfd498..ea097e0a9c02 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -501,3 +501,7 @@ config STOP_MACHINE
501 help 501 help
502 Need stop_machine() primitive. 502 Need stop_machine() primitive.
503endmenu 503endmenu
504
505menu "Block layer"
506source "block/Kconfig"
507endmenu
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index a0f18c9cc89d..c8943b53d8e6 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -2,7 +2,7 @@
2 * POSIX message queues filesystem for Linux. 2 * POSIX message queues filesystem for Linux.
3 * 3 *
4 * Copyright (C) 2003,2004 Krzysztof Benedyczak (golbi@mat.uni.torun.pl) 4 * Copyright (C) 2003,2004 Krzysztof Benedyczak (golbi@mat.uni.torun.pl)
5 * Michal Wronski (wrona@mat.uni.torun.pl) 5 * Michal Wronski (Michal.Wronski@motorola.com)
6 * 6 *
7 * Spinlocks: Mohamed Abbas (abbas.mohamed@intel.com) 7 * Spinlocks: Mohamed Abbas (abbas.mohamed@intel.com)
8 * Lockless receive & send, fd based notify: 8 * Lockless receive & send, fd based notify:
diff --git a/ipc/shm.c b/ipc/shm.c
index b58c651d31ae..587d836d80d9 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -212,8 +212,16 @@ static int newseg (key_t key, int shmflg, size_t size)
212 file = hugetlb_zero_setup(size); 212 file = hugetlb_zero_setup(size);
213 shp->mlock_user = current->user; 213 shp->mlock_user = current->user;
214 } else { 214 } else {
215 int acctflag = VM_ACCOUNT;
216 /*
217 * Do not allow no accounting for OVERCOMMIT_NEVER, even
218 * if it's asked for.
219 */
220 if ((shmflg & SHM_NORESERVE) &&
221 sysctl_overcommit_memory != OVERCOMMIT_NEVER)
222 acctflag = 0;
215 sprintf (name, "SYSV%08x", key); 223 sprintf (name, "SYSV%08x", key);
216 file = shmem_file_setup(name, size, VM_ACCOUNT); 224 file = shmem_file_setup(name, size, acctflag);
217 } 225 }
218 error = PTR_ERR(file); 226 error = PTR_ERR(file);
219 if (IS_ERR(file)) 227 if (IS_ERR(file))
diff --git a/ipc/util.c b/ipc/util.c
index 10e836d0d89e..23f1cec150c1 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -410,7 +410,8 @@ void ipc_rcu_getref(void *ptr)
410} 410}
411 411
412/** 412/**
413 * ipc_schedule_free - free ipc + rcu space 413 * ipc_schedule_free - free ipc + rcu space
414 * @head: RCU callback structure for queued work
414 * 415 *
415 * Since RCU callback function is called in bh, 416 * Since RCU callback function is called in bh,
416 * we need to defer the vfree to schedule_work 417 * we need to defer the vfree to schedule_work
@@ -427,10 +428,10 @@ static void ipc_schedule_free(struct rcu_head *head)
427} 428}
428 429
429/** 430/**
430 * ipc_immediate_free - free ipc + rcu space 431 * ipc_immediate_free - free ipc + rcu space
431 * 432 * @head: RCU callback structure that contains pointer to be freed
432 * Free from the RCU callback context
433 * 433 *
434 * Free from the RCU callback context
434 */ 435 */
435static void ipc_immediate_free(struct rcu_head *head) 436static void ipc_immediate_free(struct rcu_head *head)
436{ 437{
diff --git a/kernel/acct.c b/kernel/acct.c
index 2e3f4a47e7d0..6312d6bd43e3 100644
--- a/kernel/acct.c
+++ b/kernel/acct.c
@@ -54,6 +54,7 @@
54#include <linux/jiffies.h> 54#include <linux/jiffies.h>
55#include <linux/times.h> 55#include <linux/times.h>
56#include <linux/syscalls.h> 56#include <linux/syscalls.h>
57#include <linux/mount.h>
57#include <asm/uaccess.h> 58#include <asm/uaccess.h>
58#include <asm/div64.h> 59#include <asm/div64.h>
59#include <linux/blkdev.h> /* sector_div */ 60#include <linux/blkdev.h> /* sector_div */
@@ -192,6 +193,7 @@ static void acct_file_reopen(struct file *file)
192 add_timer(&acct_globals.timer); 193 add_timer(&acct_globals.timer);
193 } 194 }
194 if (old_acct) { 195 if (old_acct) {
196 mnt_unpin(old_acct->f_vfsmnt);
195 spin_unlock(&acct_globals.lock); 197 spin_unlock(&acct_globals.lock);
196 do_acct_process(0, old_acct); 198 do_acct_process(0, old_acct);
197 filp_close(old_acct, NULL); 199 filp_close(old_acct, NULL);
@@ -199,6 +201,42 @@ static void acct_file_reopen(struct file *file)
199 } 201 }
200} 202}
201 203
204static int acct_on(char *name)
205{
206 struct file *file;
207 int error;
208
209 /* Difference from BSD - they don't do O_APPEND */
210 file = filp_open(name, O_WRONLY|O_APPEND|O_LARGEFILE, 0);
211 if (IS_ERR(file))
212 return PTR_ERR(file);
213
214 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
215 filp_close(file, NULL);
216 return -EACCES;
217 }
218
219 if (!file->f_op->write) {
220 filp_close(file, NULL);
221 return -EIO;
222 }
223
224 error = security_acct(file);
225 if (error) {
226 filp_close(file, NULL);
227 return error;
228 }
229
230 spin_lock(&acct_globals.lock);
231 mnt_pin(file->f_vfsmnt);
232 acct_file_reopen(file);
233 spin_unlock(&acct_globals.lock);
234
235 mntput(file->f_vfsmnt); /* it's pinned, now give up active reference */
236
237 return 0;
238}
239
202/** 240/**
203 * sys_acct - enable/disable process accounting 241 * sys_acct - enable/disable process accounting
204 * @name: file name for accounting records or NULL to shutdown accounting 242 * @name: file name for accounting records or NULL to shutdown accounting
@@ -212,47 +250,41 @@ static void acct_file_reopen(struct file *file)
212 */ 250 */
213asmlinkage long sys_acct(const char __user *name) 251asmlinkage long sys_acct(const char __user *name)
214{ 252{
215 struct file *file = NULL;
216 char *tmp;
217 int error; 253 int error;
218 254
219 if (!capable(CAP_SYS_PACCT)) 255 if (!capable(CAP_SYS_PACCT))
220 return -EPERM; 256 return -EPERM;
221 257
222 if (name) { 258 if (name) {
223 tmp = getname(name); 259 char *tmp = getname(name);
224 if (IS_ERR(tmp)) { 260 if (IS_ERR(tmp))
225 return (PTR_ERR(tmp)); 261 return (PTR_ERR(tmp));
226 } 262 error = acct_on(tmp);
227 /* Difference from BSD - they don't do O_APPEND */
228 file = filp_open(tmp, O_WRONLY|O_APPEND|O_LARGEFILE, 0);
229 putname(tmp); 263 putname(tmp);
230 if (IS_ERR(file)) { 264 } else {
231 return (PTR_ERR(file)); 265 error = security_acct(NULL);
232 } 266 if (!error) {
233 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) { 267 spin_lock(&acct_globals.lock);
234 filp_close(file, NULL); 268 acct_file_reopen(NULL);
235 return (-EACCES); 269 spin_unlock(&acct_globals.lock);
236 }
237
238 if (!file->f_op->write) {
239 filp_close(file, NULL);
240 return (-EIO);
241 } 270 }
242 } 271 }
272 return error;
273}
243 274
244 error = security_acct(file); 275/**
245 if (error) { 276 * acct_auto_close - turn off a filesystem's accounting if it is on
246 if (file) 277 * @m: vfsmount being shut down
247 filp_close(file, NULL); 278 *
248 return error; 279 * If the accounting is turned on for a file in the subtree pointed to
249 } 280 * to by m, turn accounting off. Done when m is about to die.
250 281 */
282void acct_auto_close_mnt(struct vfsmount *m)
283{
251 spin_lock(&acct_globals.lock); 284 spin_lock(&acct_globals.lock);
252 acct_file_reopen(file); 285 if (acct_globals.file && acct_globals.file->f_vfsmnt == m)
286 acct_file_reopen(NULL);
253 spin_unlock(&acct_globals.lock); 287 spin_unlock(&acct_globals.lock);
254
255 return (0);
256} 288}
257 289
258/** 290/**
@@ -266,8 +298,8 @@ void acct_auto_close(struct super_block *sb)
266{ 298{
267 spin_lock(&acct_globals.lock); 299 spin_lock(&acct_globals.lock);
268 if (acct_globals.file && 300 if (acct_globals.file &&
269 acct_globals.file->f_dentry->d_inode->i_sb == sb) { 301 acct_globals.file->f_vfsmnt->mnt_sb == sb) {
270 acct_file_reopen((struct file *)NULL); 302 acct_file_reopen(NULL);
271 } 303 }
272 spin_unlock(&acct_globals.lock); 304 spin_unlock(&acct_globals.lock);
273} 305}
diff --git a/kernel/exit.c b/kernel/exit.c
index 537394b25e8d..452a1d116178 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -28,6 +28,7 @@
28#include <linux/cpuset.h> 28#include <linux/cpuset.h>
29#include <linux/syscalls.h> 29#include <linux/syscalls.h>
30#include <linux/signal.h> 30#include <linux/signal.h>
31#include <linux/cn_proc.h>
31 32
32#include <asm/uaccess.h> 33#include <asm/uaccess.h>
33#include <asm/unistd.h> 34#include <asm/unistd.h>
@@ -863,6 +864,7 @@ fastcall NORET_TYPE void do_exit(long code)
863 module_put(tsk->binfmt->module); 864 module_put(tsk->binfmt->module);
864 865
865 tsk->exit_code = code; 866 tsk->exit_code = code;
867 proc_exit_connector(tsk);
866 exit_notify(tsk); 868 exit_notify(tsk);
867#ifdef CONFIG_NUMA 869#ifdef CONFIG_NUMA
868 mpol_free(tsk->mempolicy); 870 mpol_free(tsk->mempolicy);
diff --git a/kernel/fork.c b/kernel/fork.c
index 8a069612eac3..158710d22566 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -42,6 +42,7 @@
42#include <linux/profile.h> 42#include <linux/profile.h>
43#include <linux/rmap.h> 43#include <linux/rmap.h>
44#include <linux/acct.h> 44#include <linux/acct.h>
45#include <linux/cn_proc.h>
45 46
46#include <asm/pgtable.h> 47#include <asm/pgtable.h>
47#include <asm/pgalloc.h> 48#include <asm/pgalloc.h>
@@ -469,13 +470,6 @@ static int copy_mm(unsigned long clone_flags, struct task_struct * tsk)
469 if (clone_flags & CLONE_VM) { 470 if (clone_flags & CLONE_VM) {
470 atomic_inc(&oldmm->mm_users); 471 atomic_inc(&oldmm->mm_users);
471 mm = oldmm; 472 mm = oldmm;
472 /*
473 * There are cases where the PTL is held to ensure no
474 * new threads start up in user mode using an mm, which
475 * allows optimizing out ipis; the tlb_gather_mmu code
476 * is an example.
477 */
478 spin_unlock_wait(&oldmm->page_table_lock);
479 goto good_mm; 473 goto good_mm;
480 } 474 }
481 475
@@ -1143,6 +1137,7 @@ static task_t *copy_process(unsigned long clone_flags,
1143 __get_cpu_var(process_counts)++; 1137 __get_cpu_var(process_counts)++;
1144 } 1138 }
1145 1139
1140 proc_fork_connector(p);
1146 if (!current->signal->tty && p->signal->tty) 1141 if (!current->signal->tty && p->signal->tty)
1147 p->signal->tty = NULL; 1142 p->signal->tty = NULL;
1148 1143
diff --git a/kernel/futex.c b/kernel/futex.c
index 3b4d5ad44cc6..aca8d10704f6 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -365,6 +365,11 @@ retry:
365 if (bh1 != bh2) 365 if (bh1 != bh2)
366 spin_unlock(&bh2->lock); 366 spin_unlock(&bh2->lock);
367 367
368 if (unlikely(op_ret != -EFAULT)) {
369 ret = op_ret;
370 goto out;
371 }
372
368 /* futex_atomic_op_inuser needs to both read and write 373 /* futex_atomic_op_inuser needs to both read and write
369 * *(int __user *)uaddr2, but we can't modify it 374 * *(int __user *)uaddr2, but we can't modify it
370 * non-atomically. Therefore, if get_user below is not 375 * non-atomically. Therefore, if get_user below is not
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 1cfdb08ddf20..3bd7226d15fa 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -24,6 +24,7 @@ cpumask_t __cacheline_aligned pending_irq_cpumask[NR_IRQS];
24 24
25/** 25/**
26 * synchronize_irq - wait for pending IRQ handlers (on other CPUs) 26 * synchronize_irq - wait for pending IRQ handlers (on other CPUs)
27 * @irq: interrupt number to wait for
27 * 28 *
28 * This function waits for any pending IRQ handlers for this interrupt 29 * This function waits for any pending IRQ handlers for this interrupt
29 * to complete before returning. If you use this function while 30 * to complete before returning. If you use this function while
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index ce4915dd683a..5beda378cc75 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -32,7 +32,6 @@
32 * <prasanna@in.ibm.com> added function-return probes. 32 * <prasanna@in.ibm.com> added function-return probes.
33 */ 33 */
34#include <linux/kprobes.h> 34#include <linux/kprobes.h>
35#include <linux/spinlock.h>
36#include <linux/hash.h> 35#include <linux/hash.h>
37#include <linux/init.h> 36#include <linux/init.h>
38#include <linux/slab.h> 37#include <linux/slab.h>
@@ -49,9 +48,9 @@
49static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE]; 48static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];
50static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE]; 49static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];
51 50
52unsigned int kprobe_cpu = NR_CPUS; 51static DEFINE_SPINLOCK(kprobe_lock); /* Protects kprobe_table */
53static DEFINE_SPINLOCK(kprobe_lock); 52DEFINE_SPINLOCK(kretprobe_lock); /* Protects kretprobe_inst_table */
54static struct kprobe *curr_kprobe; 53static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL;
55 54
56/* 55/*
57 * kprobe->ainsn.insn points to the copy of the instruction to be 56 * kprobe->ainsn.insn points to the copy of the instruction to be
@@ -153,50 +152,31 @@ void __kprobes free_insn_slot(kprobe_opcode_t *slot)
153 } 152 }
154} 153}
155 154
156/* Locks kprobe: irqs must be disabled */ 155/* We have preemption disabled.. so it is safe to use __ versions */
157void __kprobes lock_kprobes(void) 156static inline void set_kprobe_instance(struct kprobe *kp)
158{ 157{
159 unsigned long flags = 0; 158 __get_cpu_var(kprobe_instance) = kp;
160
161 /* Avoiding local interrupts to happen right after we take the kprobe_lock
162 * and before we get a chance to update kprobe_cpu, this to prevent
163 * deadlock when we have a kprobe on ISR routine and a kprobe on task
164 * routine
165 */
166 local_irq_save(flags);
167
168 spin_lock(&kprobe_lock);
169 kprobe_cpu = smp_processor_id();
170
171 local_irq_restore(flags);
172} 159}
173 160
174void __kprobes unlock_kprobes(void) 161static inline void reset_kprobe_instance(void)
175{ 162{
176 unsigned long flags = 0; 163 __get_cpu_var(kprobe_instance) = NULL;
177
178 /* Avoiding local interrupts to happen right after we update
179 * kprobe_cpu and before we get a a chance to release kprobe_lock,
180 * this to prevent deadlock when we have a kprobe on ISR routine and
181 * a kprobe on task routine
182 */
183 local_irq_save(flags);
184
185 kprobe_cpu = NR_CPUS;
186 spin_unlock(&kprobe_lock);
187
188 local_irq_restore(flags);
189} 164}
190 165
191/* You have to be holding the kprobe_lock */ 166/*
167 * This routine is called either:
168 * - under the kprobe_lock spinlock - during kprobe_[un]register()
169 * OR
170 * - with preemption disabled - from arch/xxx/kernel/kprobes.c
171 */
192struct kprobe __kprobes *get_kprobe(void *addr) 172struct kprobe __kprobes *get_kprobe(void *addr)
193{ 173{
194 struct hlist_head *head; 174 struct hlist_head *head;
195 struct hlist_node *node; 175 struct hlist_node *node;
176 struct kprobe *p;
196 177
197 head = &kprobe_table[hash_ptr(addr, KPROBE_HASH_BITS)]; 178 head = &kprobe_table[hash_ptr(addr, KPROBE_HASH_BITS)];
198 hlist_for_each(node, head) { 179 hlist_for_each_entry_rcu(p, node, head, hlist) {
199 struct kprobe *p = hlist_entry(node, struct kprobe, hlist);
200 if (p->addr == addr) 180 if (p->addr == addr)
201 return p; 181 return p;
202 } 182 }
@@ -211,13 +191,13 @@ static int __kprobes aggr_pre_handler(struct kprobe *p, struct pt_regs *regs)
211{ 191{
212 struct kprobe *kp; 192 struct kprobe *kp;
213 193
214 list_for_each_entry(kp, &p->list, list) { 194 list_for_each_entry_rcu(kp, &p->list, list) {
215 if (kp->pre_handler) { 195 if (kp->pre_handler) {
216 curr_kprobe = kp; 196 set_kprobe_instance(kp);
217 if (kp->pre_handler(kp, regs)) 197 if (kp->pre_handler(kp, regs))
218 return 1; 198 return 1;
219 } 199 }
220 curr_kprobe = NULL; 200 reset_kprobe_instance();
221 } 201 }
222 return 0; 202 return 0;
223} 203}
@@ -227,11 +207,11 @@ static void __kprobes aggr_post_handler(struct kprobe *p, struct pt_regs *regs,
227{ 207{
228 struct kprobe *kp; 208 struct kprobe *kp;
229 209
230 list_for_each_entry(kp, &p->list, list) { 210 list_for_each_entry_rcu(kp, &p->list, list) {
231 if (kp->post_handler) { 211 if (kp->post_handler) {
232 curr_kprobe = kp; 212 set_kprobe_instance(kp);
233 kp->post_handler(kp, regs, flags); 213 kp->post_handler(kp, regs, flags);
234 curr_kprobe = NULL; 214 reset_kprobe_instance();
235 } 215 }
236 } 216 }
237 return; 217 return;
@@ -240,12 +220,14 @@ static void __kprobes aggr_post_handler(struct kprobe *p, struct pt_regs *regs,
240static int __kprobes aggr_fault_handler(struct kprobe *p, struct pt_regs *regs, 220static int __kprobes aggr_fault_handler(struct kprobe *p, struct pt_regs *regs,
241 int trapnr) 221 int trapnr)
242{ 222{
223 struct kprobe *cur = __get_cpu_var(kprobe_instance);
224
243 /* 225 /*
244 * if we faulted "during" the execution of a user specified 226 * if we faulted "during" the execution of a user specified
245 * probe handler, invoke just that probe's fault handler 227 * probe handler, invoke just that probe's fault handler
246 */ 228 */
247 if (curr_kprobe && curr_kprobe->fault_handler) { 229 if (cur && cur->fault_handler) {
248 if (curr_kprobe->fault_handler(curr_kprobe, regs, trapnr)) 230 if (cur->fault_handler(cur, regs, trapnr))
249 return 1; 231 return 1;
250 } 232 }
251 return 0; 233 return 0;
@@ -253,17 +235,18 @@ static int __kprobes aggr_fault_handler(struct kprobe *p, struct pt_regs *regs,
253 235
254static int __kprobes aggr_break_handler(struct kprobe *p, struct pt_regs *regs) 236static int __kprobes aggr_break_handler(struct kprobe *p, struct pt_regs *regs)
255{ 237{
256 struct kprobe *kp = curr_kprobe; 238 struct kprobe *cur = __get_cpu_var(kprobe_instance);
257 if (curr_kprobe && kp->break_handler) { 239 int ret = 0;
258 if (kp->break_handler(kp, regs)) { 240
259 curr_kprobe = NULL; 241 if (cur && cur->break_handler) {
260 return 1; 242 if (cur->break_handler(cur, regs))
261 } 243 ret = 1;
262 } 244 }
263 curr_kprobe = NULL; 245 reset_kprobe_instance();
264 return 0; 246 return ret;
265} 247}
266 248
249/* Called with kretprobe_lock held */
267struct kretprobe_instance __kprobes *get_free_rp_inst(struct kretprobe *rp) 250struct kretprobe_instance __kprobes *get_free_rp_inst(struct kretprobe *rp)
268{ 251{
269 struct hlist_node *node; 252 struct hlist_node *node;
@@ -273,6 +256,7 @@ struct kretprobe_instance __kprobes *get_free_rp_inst(struct kretprobe *rp)
273 return NULL; 256 return NULL;
274} 257}
275 258
259/* Called with kretprobe_lock held */
276static struct kretprobe_instance __kprobes *get_used_rp_inst(struct kretprobe 260static struct kretprobe_instance __kprobes *get_used_rp_inst(struct kretprobe
277 *rp) 261 *rp)
278{ 262{
@@ -283,6 +267,7 @@ static struct kretprobe_instance __kprobes *get_used_rp_inst(struct kretprobe
283 return NULL; 267 return NULL;
284} 268}
285 269
270/* Called with kretprobe_lock held */
286void __kprobes add_rp_inst(struct kretprobe_instance *ri) 271void __kprobes add_rp_inst(struct kretprobe_instance *ri)
287{ 272{
288 /* 273 /*
@@ -301,6 +286,7 @@ void __kprobes add_rp_inst(struct kretprobe_instance *ri)
301 hlist_add_head(&ri->uflist, &ri->rp->used_instances); 286 hlist_add_head(&ri->uflist, &ri->rp->used_instances);
302} 287}
303 288
289/* Called with kretprobe_lock held */
304void __kprobes recycle_rp_inst(struct kretprobe_instance *ri) 290void __kprobes recycle_rp_inst(struct kretprobe_instance *ri)
305{ 291{
306 /* remove rp inst off the rprobe_inst_table */ 292 /* remove rp inst off the rprobe_inst_table */
@@ -334,13 +320,13 @@ void __kprobes kprobe_flush_task(struct task_struct *tk)
334 struct hlist_node *node, *tmp; 320 struct hlist_node *node, *tmp;
335 unsigned long flags = 0; 321 unsigned long flags = 0;
336 322
337 spin_lock_irqsave(&kprobe_lock, flags); 323 spin_lock_irqsave(&kretprobe_lock, flags);
338 head = kretprobe_inst_table_head(current); 324 head = kretprobe_inst_table_head(current);
339 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) { 325 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
340 if (ri->task == tk) 326 if (ri->task == tk)
341 recycle_rp_inst(ri); 327 recycle_rp_inst(ri);
342 } 328 }
343 spin_unlock_irqrestore(&kprobe_lock, flags); 329 spin_unlock_irqrestore(&kretprobe_lock, flags);
344} 330}
345 331
346/* 332/*
@@ -351,9 +337,12 @@ static int __kprobes pre_handler_kretprobe(struct kprobe *p,
351 struct pt_regs *regs) 337 struct pt_regs *regs)
352{ 338{
353 struct kretprobe *rp = container_of(p, struct kretprobe, kp); 339 struct kretprobe *rp = container_of(p, struct kretprobe, kp);
340 unsigned long flags = 0;
354 341
355 /*TODO: consider to only swap the RA after the last pre_handler fired */ 342 /*TODO: consider to only swap the RA after the last pre_handler fired */
343 spin_lock_irqsave(&kretprobe_lock, flags);
356 arch_prepare_kretprobe(rp, regs); 344 arch_prepare_kretprobe(rp, regs);
345 spin_unlock_irqrestore(&kretprobe_lock, flags);
357 return 0; 346 return 0;
358} 347}
359 348
@@ -384,13 +373,13 @@ static int __kprobes add_new_kprobe(struct kprobe *old_p, struct kprobe *p)
384 struct kprobe *kp; 373 struct kprobe *kp;
385 374
386 if (p->break_handler) { 375 if (p->break_handler) {
387 list_for_each_entry(kp, &old_p->list, list) { 376 list_for_each_entry_rcu(kp, &old_p->list, list) {
388 if (kp->break_handler) 377 if (kp->break_handler)
389 return -EEXIST; 378 return -EEXIST;
390 } 379 }
391 list_add_tail(&p->list, &old_p->list); 380 list_add_tail_rcu(&p->list, &old_p->list);
392 } else 381 } else
393 list_add(&p->list, &old_p->list); 382 list_add_rcu(&p->list, &old_p->list);
394 return 0; 383 return 0;
395} 384}
396 385
@@ -408,18 +397,18 @@ static inline void add_aggr_kprobe(struct kprobe *ap, struct kprobe *p)
408 ap->break_handler = aggr_break_handler; 397 ap->break_handler = aggr_break_handler;
409 398
410 INIT_LIST_HEAD(&ap->list); 399 INIT_LIST_HEAD(&ap->list);
411 list_add(&p->list, &ap->list); 400 list_add_rcu(&p->list, &ap->list);
412 401
413 INIT_HLIST_NODE(&ap->hlist); 402 INIT_HLIST_NODE(&ap->hlist);
414 hlist_del(&p->hlist); 403 hlist_del_rcu(&p->hlist);
415 hlist_add_head(&ap->hlist, 404 hlist_add_head_rcu(&ap->hlist,
416 &kprobe_table[hash_ptr(ap->addr, KPROBE_HASH_BITS)]); 405 &kprobe_table[hash_ptr(ap->addr, KPROBE_HASH_BITS)]);
417} 406}
418 407
419/* 408/*
420 * This is the second or subsequent kprobe at the address - handle 409 * This is the second or subsequent kprobe at the address - handle
421 * the intricacies 410 * the intricacies
422 * TODO: Move kcalloc outside the spinlock 411 * TODO: Move kcalloc outside the spin_lock
423 */ 412 */
424static int __kprobes register_aggr_kprobe(struct kprobe *old_p, 413static int __kprobes register_aggr_kprobe(struct kprobe *old_p,
425 struct kprobe *p) 414 struct kprobe *p)
@@ -445,7 +434,7 @@ static int __kprobes register_aggr_kprobe(struct kprobe *old_p,
445static inline void cleanup_kprobe(struct kprobe *p, unsigned long flags) 434static inline void cleanup_kprobe(struct kprobe *p, unsigned long flags)
446{ 435{
447 arch_disarm_kprobe(p); 436 arch_disarm_kprobe(p);
448 hlist_del(&p->hlist); 437 hlist_del_rcu(&p->hlist);
449 spin_unlock_irqrestore(&kprobe_lock, flags); 438 spin_unlock_irqrestore(&kprobe_lock, flags);
450 arch_remove_kprobe(p); 439 arch_remove_kprobe(p);
451} 440}
@@ -453,11 +442,10 @@ static inline void cleanup_kprobe(struct kprobe *p, unsigned long flags)
453static inline void cleanup_aggr_kprobe(struct kprobe *old_p, 442static inline void cleanup_aggr_kprobe(struct kprobe *old_p,
454 struct kprobe *p, unsigned long flags) 443 struct kprobe *p, unsigned long flags)
455{ 444{
456 list_del(&p->list); 445 list_del_rcu(&p->list);
457 if (list_empty(&old_p->list)) { 446 if (list_empty(&old_p->list))
458 cleanup_kprobe(old_p, flags); 447 cleanup_kprobe(old_p, flags);
459 kfree(old_p); 448 else
460 } else
461 spin_unlock_irqrestore(&kprobe_lock, flags); 449 spin_unlock_irqrestore(&kprobe_lock, flags);
462} 450}
463 451
@@ -480,9 +468,9 @@ int __kprobes register_kprobe(struct kprobe *p)
480 if ((ret = arch_prepare_kprobe(p)) != 0) 468 if ((ret = arch_prepare_kprobe(p)) != 0)
481 goto rm_kprobe; 469 goto rm_kprobe;
482 470
471 p->nmissed = 0;
483 spin_lock_irqsave(&kprobe_lock, flags); 472 spin_lock_irqsave(&kprobe_lock, flags);
484 old_p = get_kprobe(p->addr); 473 old_p = get_kprobe(p->addr);
485 p->nmissed = 0;
486 if (old_p) { 474 if (old_p) {
487 ret = register_aggr_kprobe(old_p, p); 475 ret = register_aggr_kprobe(old_p, p);
488 goto out; 476 goto out;
@@ -490,7 +478,7 @@ int __kprobes register_kprobe(struct kprobe *p)
490 478
491 arch_copy_kprobe(p); 479 arch_copy_kprobe(p);
492 INIT_HLIST_NODE(&p->hlist); 480 INIT_HLIST_NODE(&p->hlist);
493 hlist_add_head(&p->hlist, 481 hlist_add_head_rcu(&p->hlist,
494 &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]); 482 &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]);
495 483
496 arch_arm_kprobe(p); 484 arch_arm_kprobe(p);
@@ -511,10 +499,16 @@ void __kprobes unregister_kprobe(struct kprobe *p)
511 spin_lock_irqsave(&kprobe_lock, flags); 499 spin_lock_irqsave(&kprobe_lock, flags);
512 old_p = get_kprobe(p->addr); 500 old_p = get_kprobe(p->addr);
513 if (old_p) { 501 if (old_p) {
502 /* cleanup_*_kprobe() does the spin_unlock_irqrestore */
514 if (old_p->pre_handler == aggr_pre_handler) 503 if (old_p->pre_handler == aggr_pre_handler)
515 cleanup_aggr_kprobe(old_p, p, flags); 504 cleanup_aggr_kprobe(old_p, p, flags);
516 else 505 else
517 cleanup_kprobe(p, flags); 506 cleanup_kprobe(p, flags);
507
508 synchronize_sched();
509 if (old_p->pre_handler == aggr_pre_handler &&
510 list_empty(&old_p->list))
511 kfree(old_p);
518 } else 512 } else
519 spin_unlock_irqrestore(&kprobe_lock, flags); 513 spin_unlock_irqrestore(&kprobe_lock, flags);
520} 514}
@@ -591,13 +585,13 @@ void __kprobes unregister_kretprobe(struct kretprobe *rp)
591 585
592 unregister_kprobe(&rp->kp); 586 unregister_kprobe(&rp->kp);
593 /* No race here */ 587 /* No race here */
594 spin_lock_irqsave(&kprobe_lock, flags); 588 spin_lock_irqsave(&kretprobe_lock, flags);
595 free_rp_inst(rp); 589 free_rp_inst(rp);
596 while ((ri = get_used_rp_inst(rp)) != NULL) { 590 while ((ri = get_used_rp_inst(rp)) != NULL) {
597 ri->rp = NULL; 591 ri->rp = NULL;
598 hlist_del(&ri->uflist); 592 hlist_del(&ri->uflist);
599 } 593 }
600 spin_unlock_irqrestore(&kprobe_lock, flags); 594 spin_unlock_irqrestore(&kretprobe_lock, flags);
601} 595}
602 596
603static int __init init_kprobes(void) 597static int __init init_kprobes(void)
diff --git a/kernel/module.c b/kernel/module.c
index ff5c500ab625..2ea929d51ad0 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -37,6 +37,7 @@
37#include <linux/stop_machine.h> 37#include <linux/stop_machine.h>
38#include <linux/device.h> 38#include <linux/device.h>
39#include <linux/string.h> 39#include <linux/string.h>
40#include <linux/sched.h>
40#include <asm/uaccess.h> 41#include <asm/uaccess.h>
41#include <asm/semaphore.h> 42#include <asm/semaphore.h>
42#include <asm/cacheflush.h> 43#include <asm/cacheflush.h>
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 91a894264941..84af54c39e1b 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -497,7 +497,7 @@ static void process_timer_rebalance(struct task_struct *p,
497 left = cputime_div(cputime_sub(expires.cpu, val.cpu), 497 left = cputime_div(cputime_sub(expires.cpu, val.cpu),
498 nthreads); 498 nthreads);
499 do { 499 do {
500 if (!unlikely(t->flags & PF_EXITING)) { 500 if (likely(!(t->flags & PF_EXITING))) {
501 ticks = cputime_add(prof_ticks(t), left); 501 ticks = cputime_add(prof_ticks(t), left);
502 if (cputime_eq(t->it_prof_expires, 502 if (cputime_eq(t->it_prof_expires,
503 cputime_zero) || 503 cputime_zero) ||
@@ -512,7 +512,7 @@ static void process_timer_rebalance(struct task_struct *p,
512 left = cputime_div(cputime_sub(expires.cpu, val.cpu), 512 left = cputime_div(cputime_sub(expires.cpu, val.cpu),
513 nthreads); 513 nthreads);
514 do { 514 do {
515 if (!unlikely(t->flags & PF_EXITING)) { 515 if (likely(!(t->flags & PF_EXITING))) {
516 ticks = cputime_add(virt_ticks(t), left); 516 ticks = cputime_add(virt_ticks(t), left);
517 if (cputime_eq(t->it_virt_expires, 517 if (cputime_eq(t->it_virt_expires,
518 cputime_zero) || 518 cputime_zero) ||
@@ -527,7 +527,7 @@ static void process_timer_rebalance(struct task_struct *p,
527 nsleft = expires.sched - val.sched; 527 nsleft = expires.sched - val.sched;
528 do_div(nsleft, nthreads); 528 do_div(nsleft, nthreads);
529 do { 529 do {
530 if (!unlikely(t->flags & PF_EXITING)) { 530 if (likely(!(t->flags & PF_EXITING))) {
531 ns = t->sched_time + nsleft; 531 ns = t->sched_time + nsleft;
532 if (t->it_sched_expires == 0 || 532 if (t->it_sched_expires == 0 ||
533 t->it_sched_expires > ns) { 533 t->it_sched_expires > ns) {
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 42a628704398..723f5179883e 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -168,9 +168,8 @@ static unsigned count_data_pages(void)
168{ 168{
169 struct zone *zone; 169 struct zone *zone;
170 unsigned long zone_pfn; 170 unsigned long zone_pfn;
171 unsigned n; 171 unsigned int n = 0;
172 172
173 n = 0;
174 for_each_zone (zone) { 173 for_each_zone (zone) {
175 if (is_highmem(zone)) 174 if (is_highmem(zone))
176 continue; 175 continue;
@@ -250,10 +249,10 @@ static inline void fill_pb_page(struct pbe *pbpage)
250 * of memory pages allocated with alloc_pagedir() 249 * of memory pages allocated with alloc_pagedir()
251 */ 250 */
252 251
253void create_pbe_list(struct pbe *pblist, unsigned nr_pages) 252void create_pbe_list(struct pbe *pblist, unsigned int nr_pages)
254{ 253{
255 struct pbe *pbpage, *p; 254 struct pbe *pbpage, *p;
256 unsigned num = PBES_PER_PAGE; 255 unsigned int num = PBES_PER_PAGE;
257 256
258 for_each_pb_page (pbpage, pblist) { 257 for_each_pb_page (pbpage, pblist) {
259 if (num >= nr_pages) 258 if (num >= nr_pages)
@@ -293,9 +292,9 @@ static void *alloc_image_page(void)
293 * On each page we set up a list of struct_pbe elements. 292 * On each page we set up a list of struct_pbe elements.
294 */ 293 */
295 294
296struct pbe *alloc_pagedir(unsigned nr_pages) 295struct pbe *alloc_pagedir(unsigned int nr_pages)
297{ 296{
298 unsigned num; 297 unsigned int num;
299 struct pbe *pblist, *pbe; 298 struct pbe *pblist, *pbe;
300 299
301 if (!nr_pages) 300 if (!nr_pages)
@@ -329,7 +328,7 @@ void swsusp_free(void)
329 for_each_zone(zone) { 328 for_each_zone(zone) {
330 for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn) 329 for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn)
331 if (pfn_valid(zone_pfn + zone->zone_start_pfn)) { 330 if (pfn_valid(zone_pfn + zone->zone_start_pfn)) {
332 struct page * page; 331 struct page *page;
333 page = pfn_to_page(zone_pfn + zone->zone_start_pfn); 332 page = pfn_to_page(zone_pfn + zone->zone_start_pfn);
334 if (PageNosave(page) && PageNosaveFree(page)) { 333 if (PageNosave(page) && PageNosaveFree(page)) {
335 ClearPageNosave(page); 334 ClearPageNosave(page);
@@ -348,7 +347,7 @@ void swsusp_free(void)
348 * free pages. 347 * free pages.
349 */ 348 */
350 349
351static int enough_free_mem(unsigned nr_pages) 350static int enough_free_mem(unsigned int nr_pages)
352{ 351{
353 pr_debug("swsusp: available memory: %u pages\n", nr_free_pages()); 352 pr_debug("swsusp: available memory: %u pages\n", nr_free_pages());
354 return nr_free_pages() > (nr_pages + PAGES_FOR_IO + 353 return nr_free_pages() > (nr_pages + PAGES_FOR_IO +
@@ -356,7 +355,7 @@ static int enough_free_mem(unsigned nr_pages)
356} 355}
357 356
358 357
359static struct pbe *swsusp_alloc(unsigned nr_pages) 358static struct pbe *swsusp_alloc(unsigned int nr_pages)
360{ 359{
361 struct pbe *pblist, *p; 360 struct pbe *pblist, *p;
362 361
@@ -380,7 +379,7 @@ static struct pbe *swsusp_alloc(unsigned nr_pages)
380 379
381asmlinkage int swsusp_save(void) 380asmlinkage int swsusp_save(void)
382{ 381{
383 unsigned nr_pages; 382 unsigned int nr_pages;
384 383
385 pr_debug("swsusp: critical section: \n"); 384 pr_debug("swsusp: critical section: \n");
386 if (save_highmem()) { 385 if (save_highmem()) {
diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c
index 12db1d2ad61f..e1ab28b9b217 100644
--- a/kernel/power/swsusp.c
+++ b/kernel/power/swsusp.c
@@ -85,18 +85,11 @@ unsigned int nr_copy_pages __nosavedata = 0;
85/* Suspend pagedir is allocated before final copy, therefore it 85/* Suspend pagedir is allocated before final copy, therefore it
86 must be freed after resume 86 must be freed after resume
87 87
88 Warning: this is evil. There are actually two pagedirs at time of
89 resume. One is "pagedir_save", which is empty frame allocated at
90 time of suspend, that must be freed. Second is "pagedir_nosave",
91 allocated at time of resume, that travels through memory not to
92 collide with anything.
93
94 Warning: this is even more evil than it seems. Pagedirs this file 88 Warning: this is even more evil than it seems. Pagedirs this file
95 talks about are completely different from page directories used by 89 talks about are completely different from page directories used by
96 MMU hardware. 90 MMU hardware.
97 */ 91 */
98suspend_pagedir_t *pagedir_nosave __nosavedata = NULL; 92suspend_pagedir_t *pagedir_nosave __nosavedata = NULL;
99suspend_pagedir_t *pagedir_save;
100 93
101#define SWSUSP_SIG "S1SUSPEND" 94#define SWSUSP_SIG "S1SUSPEND"
102 95
@@ -122,8 +115,8 @@ static struct swsusp_info swsusp_info;
122static unsigned short swapfile_used[MAX_SWAPFILES]; 115static unsigned short swapfile_used[MAX_SWAPFILES];
123static unsigned short root_swap; 116static unsigned short root_swap;
124 117
125static int write_page(unsigned long addr, swp_entry_t * loc); 118static int write_page(unsigned long addr, swp_entry_t *loc);
126static int bio_read_page(pgoff_t page_off, void * page); 119static int bio_read_page(pgoff_t page_off, void *page);
127 120
128static u8 key_iv[MAXKEY+MAXIV]; 121static u8 key_iv[MAXKEY+MAXIV];
129 122
@@ -355,7 +348,7 @@ static void lock_swapdevices(void)
355 * This is a partial improvement, since we will at least return other 348 * This is a partial improvement, since we will at least return other
356 * errors, though we need to eventually fix the damn code. 349 * errors, though we need to eventually fix the damn code.
357 */ 350 */
358static int write_page(unsigned long addr, swp_entry_t * loc) 351static int write_page(unsigned long addr, swp_entry_t *loc)
359{ 352{
360 swp_entry_t entry; 353 swp_entry_t entry;
361 int error = 0; 354 int error = 0;
@@ -383,9 +376,9 @@ static int write_page(unsigned long addr, swp_entry_t * loc)
383static void data_free(void) 376static void data_free(void)
384{ 377{
385 swp_entry_t entry; 378 swp_entry_t entry;
386 struct pbe * p; 379 struct pbe *p;
387 380
388 for_each_pbe(p, pagedir_nosave) { 381 for_each_pbe (p, pagedir_nosave) {
389 entry = p->swap_address; 382 entry = p->swap_address;
390 if (entry.val) 383 if (entry.val)
391 swap_free(entry); 384 swap_free(entry);
@@ -492,8 +485,8 @@ static void free_pagedir_entries(void)
492static int write_pagedir(void) 485static int write_pagedir(void)
493{ 486{
494 int error = 0; 487 int error = 0;
495 unsigned n = 0; 488 unsigned int n = 0;
496 struct pbe * pbe; 489 struct pbe *pbe;
497 490
498 printk( "Writing pagedir..."); 491 printk( "Writing pagedir...");
499 for_each_pb_page (pbe, pagedir_nosave) { 492 for_each_pb_page (pbe, pagedir_nosave) {
@@ -543,7 +536,7 @@ static int write_suspend_image(void)
543 * We should only consider resume_device. 536 * We should only consider resume_device.
544 */ 537 */
545 538
546int enough_swap(unsigned nr_pages) 539int enough_swap(unsigned int nr_pages)
547{ 540{
548 struct sysinfo i; 541 struct sysinfo i;
549 542
@@ -694,7 +687,7 @@ static int check_pagedir(struct pbe *pblist)
694 * restore from the loaded pages later. We relocate them here. 687 * restore from the loaded pages later. We relocate them here.
695 */ 688 */
696 689
697static struct pbe * swsusp_pagedir_relocate(struct pbe *pblist) 690static struct pbe *swsusp_pagedir_relocate(struct pbe *pblist)
698{ 691{
699 struct zone *zone; 692 struct zone *zone;
700 unsigned long zone_pfn; 693 unsigned long zone_pfn;
@@ -770,7 +763,7 @@ static struct pbe * swsusp_pagedir_relocate(struct pbe *pblist)
770 763
771static atomic_t io_done = ATOMIC_INIT(0); 764static atomic_t io_done = ATOMIC_INIT(0);
772 765
773static int end_io(struct bio * bio, unsigned int num, int err) 766static int end_io(struct bio *bio, unsigned int num, int err)
774{ 767{
775 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) 768 if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
776 panic("I/O error reading memory image"); 769 panic("I/O error reading memory image");
@@ -778,7 +771,7 @@ static int end_io(struct bio * bio, unsigned int num, int err)
778 return 0; 771 return 0;
779} 772}
780 773
781static struct block_device * resume_bdev; 774static struct block_device *resume_bdev;
782 775
783/** 776/**
784 * submit - submit BIO request. 777 * submit - submit BIO request.
@@ -791,10 +784,10 @@ static struct block_device * resume_bdev;
791 * Then submit it and wait. 784 * Then submit it and wait.
792 */ 785 */
793 786
794static int submit(int rw, pgoff_t page_off, void * page) 787static int submit(int rw, pgoff_t page_off, void *page)
795{ 788{
796 int error = 0; 789 int error = 0;
797 struct bio * bio; 790 struct bio *bio;
798 791
799 bio = bio_alloc(GFP_ATOMIC, 1); 792 bio = bio_alloc(GFP_ATOMIC, 1);
800 if (!bio) 793 if (!bio)
@@ -823,12 +816,12 @@ static int submit(int rw, pgoff_t page_off, void * page)
823 return error; 816 return error;
824} 817}
825 818
826static int bio_read_page(pgoff_t page_off, void * page) 819static int bio_read_page(pgoff_t page_off, void *page)
827{ 820{
828 return submit(READ, page_off, page); 821 return submit(READ, page_off, page);
829} 822}
830 823
831static int bio_write_page(pgoff_t page_off, void * page) 824static int bio_write_page(pgoff_t page_off, void *page)
832{ 825{
833 return submit(WRITE, page_off, page); 826 return submit(WRITE, page_off, page);
834} 827}
@@ -838,7 +831,7 @@ static int bio_write_page(pgoff_t page_off, void * page)
838 * I really don't think that it's foolproof but more than nothing.. 831 * I really don't think that it's foolproof but more than nothing..
839 */ 832 */
840 833
841static const char * sanity_check(void) 834static const char *sanity_check(void)
842{ 835{
843 dump_info(); 836 dump_info();
844 if (swsusp_info.version_code != LINUX_VERSION_CODE) 837 if (swsusp_info.version_code != LINUX_VERSION_CODE)
@@ -864,7 +857,7 @@ static const char * sanity_check(void)
864 857
865static int check_header(void) 858static int check_header(void)
866{ 859{
867 const char * reason = NULL; 860 const char *reason = NULL;
868 int error; 861 int error;
869 862
870 if ((error = bio_read_page(swp_offset(swsusp_header.swsusp_info), &swsusp_info))) 863 if ((error = bio_read_page(swp_offset(swsusp_header.swsusp_info), &swsusp_info)))
@@ -912,7 +905,7 @@ static int check_sig(void)
912 905
913static int data_read(struct pbe *pblist) 906static int data_read(struct pbe *pblist)
914{ 907{
915 struct pbe * p; 908 struct pbe *p;
916 int error = 0; 909 int error = 0;
917 int i = 0; 910 int i = 0;
918 int mod = swsusp_info.image_pages / 100; 911 int mod = swsusp_info.image_pages / 100;
@@ -950,7 +943,7 @@ static int data_read(struct pbe *pblist)
950static int read_pagedir(struct pbe *pblist) 943static int read_pagedir(struct pbe *pblist)
951{ 944{
952 struct pbe *pbpage, *p; 945 struct pbe *pbpage, *p;
953 unsigned i = 0; 946 unsigned int i = 0;
954 int error; 947 int error;
955 948
956 if (!pblist) 949 if (!pblist)
diff --git a/kernel/printk.c b/kernel/printk.c
index 3cb9708209bc..e9be027bc930 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -806,7 +806,6 @@ void console_unblank(void)
806 c->unblank(); 806 c->unblank();
807 release_console_sem(); 807 release_console_sem();
808} 808}
809EXPORT_SYMBOL(console_unblank);
810 809
811/* 810/*
812 * Return the console tty driver structure and its associated index 811 * Return the console tty driver structure and its associated index
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 863eee8bff47..5b8dd98a230e 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -406,3 +406,85 @@ int ptrace_request(struct task_struct *child, long request,
406 406
407 return ret; 407 return ret;
408} 408}
409
410#ifndef __ARCH_SYS_PTRACE
411static int ptrace_get_task_struct(long request, long pid,
412 struct task_struct **childp)
413{
414 struct task_struct *child;
415 int ret;
416
417 /*
418 * Callers use child == NULL as an indication to exit early even
419 * when the return value is 0, so make sure it is non-NULL here.
420 */
421 *childp = NULL;
422
423 if (request == PTRACE_TRACEME) {
424 /*
425 * Are we already being traced?
426 */
427 if (current->ptrace & PT_PTRACED)
428 return -EPERM;
429 ret = security_ptrace(current->parent, current);
430 if (ret)
431 return -EPERM;
432 /*
433 * Set the ptrace bit in the process ptrace flags.
434 */
435 current->ptrace |= PT_PTRACED;
436 return 0;
437 }
438
439 /*
440 * You may not mess with init
441 */
442 if (pid == 1)
443 return -EPERM;
444
445 ret = -ESRCH;
446 read_lock(&tasklist_lock);
447 child = find_task_by_pid(pid);
448 if (child)
449 get_task_struct(child);
450 read_unlock(&tasklist_lock);
451 if (!child)
452 return -ESRCH;
453
454 *childp = child;
455 return 0;
456}
457
458asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
459{
460 struct task_struct *child;
461 long ret;
462
463 /*
464 * This lock_kernel fixes a subtle race with suid exec
465 */
466 lock_kernel();
467 ret = ptrace_get_task_struct(request, pid, &child);
468 if (!child)
469 goto out;
470
471 if (request == PTRACE_ATTACH) {
472 ret = ptrace_attach(child);
473 goto out;
474 }
475
476 ret = ptrace_check_attach(child, request == PTRACE_KILL);
477 if (ret < 0)
478 goto out_put_task_struct;
479
480 ret = arch_ptrace(child, request, addr, data);
481 if (ret < 0)
482 goto out_put_task_struct;
483
484 out_put_task_struct:
485 put_task_struct(child);
486 out:
487 unlock_kernel();
488 return ret;
489}
490#endif /* __ARCH_SYS_PTRACE */
diff --git a/kernel/sched.c b/kernel/sched.c
index b4f4eb613537..3ce26954be12 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3563,8 +3563,6 @@ int idle_cpu(int cpu)
3563 return cpu_curr(cpu) == cpu_rq(cpu)->idle; 3563 return cpu_curr(cpu) == cpu_rq(cpu)->idle;
3564} 3564}
3565 3565
3566EXPORT_SYMBOL_GPL(idle_cpu);
3567
3568/** 3566/**
3569 * idle_task - return the idle task for a given cpu. 3567 * idle_task - return the idle task for a given cpu.
3570 * @cpu: the processor in question. 3568 * @cpu: the processor in question.
@@ -4680,7 +4678,8 @@ static int migration_call(struct notifier_block *nfb, unsigned long action,
4680#ifdef CONFIG_HOTPLUG_CPU 4678#ifdef CONFIG_HOTPLUG_CPU
4681 case CPU_UP_CANCELED: 4679 case CPU_UP_CANCELED:
4682 /* Unbind it from offline cpu so it can run. Fall thru. */ 4680 /* Unbind it from offline cpu so it can run. Fall thru. */
4683 kthread_bind(cpu_rq(cpu)->migration_thread,smp_processor_id()); 4681 kthread_bind(cpu_rq(cpu)->migration_thread,
4682 any_online_cpu(cpu_online_map));
4684 kthread_stop(cpu_rq(cpu)->migration_thread); 4683 kthread_stop(cpu_rq(cpu)->migration_thread);
4685 cpu_rq(cpu)->migration_thread = NULL; 4684 cpu_rq(cpu)->migration_thread = NULL;
4686 break; 4685 break;
diff --git a/kernel/softirq.c b/kernel/softirq.c
index f766b2fc48be..ad3295cdded5 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -470,7 +470,8 @@ static int __devinit cpu_callback(struct notifier_block *nfb,
470#ifdef CONFIG_HOTPLUG_CPU 470#ifdef CONFIG_HOTPLUG_CPU
471 case CPU_UP_CANCELED: 471 case CPU_UP_CANCELED:
472 /* Unbind so it can run. Fall thru. */ 472 /* Unbind so it can run. Fall thru. */
473 kthread_bind(per_cpu(ksoftirqd, hotcpu), smp_processor_id()); 473 kthread_bind(per_cpu(ksoftirqd, hotcpu),
474 any_online_cpu(cpu_online_map));
474 case CPU_DEAD: 475 case CPU_DEAD:
475 p = per_cpu(ksoftirqd, hotcpu); 476 p = per_cpu(ksoftirqd, hotcpu);
476 per_cpu(ksoftirqd, hotcpu) = NULL; 477 per_cpu(ksoftirqd, hotcpu) = NULL;
diff --git a/kernel/softlockup.c b/kernel/softlockup.c
index 75976209cea7..a2dcceb9437d 100644
--- a/kernel/softlockup.c
+++ b/kernel/softlockup.c
@@ -123,7 +123,8 @@ cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
123#ifdef CONFIG_HOTPLUG_CPU 123#ifdef CONFIG_HOTPLUG_CPU
124 case CPU_UP_CANCELED: 124 case CPU_UP_CANCELED:
125 /* Unbind so it can run. Fall thru. */ 125 /* Unbind so it can run. Fall thru. */
126 kthread_bind(per_cpu(watchdog_task, hotcpu), smp_processor_id()); 126 kthread_bind(per_cpu(watchdog_task, hotcpu),
127 any_online_cpu(cpu_online_map));
127 case CPU_DEAD: 128 case CPU_DEAD:
128 p = per_cpu(watchdog_task, hotcpu); 129 p = per_cpu(watchdog_task, hotcpu);
129 per_cpu(watchdog_task, hotcpu) = NULL; 130 per_cpu(watchdog_task, hotcpu) = NULL;
diff --git a/kernel/sys.c b/kernel/sys.c
index 2fa1ed18123c..c43b3e22bbda 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -28,6 +28,7 @@
28#include <linux/suspend.h> 28#include <linux/suspend.h>
29#include <linux/tty.h> 29#include <linux/tty.h>
30#include <linux/signal.h> 30#include <linux/signal.h>
31#include <linux/cn_proc.h>
31 32
32#include <linux/compat.h> 33#include <linux/compat.h>
33#include <linux/syscalls.h> 34#include <linux/syscalls.h>
@@ -375,18 +376,21 @@ void emergency_restart(void)
375} 376}
376EXPORT_SYMBOL_GPL(emergency_restart); 377EXPORT_SYMBOL_GPL(emergency_restart);
377 378
378/**
379 * kernel_restart - reboot the system
380 *
381 * Shutdown everything and perform a clean reboot.
382 * This is not safe to call in interrupt context.
383 */
384void kernel_restart_prepare(char *cmd) 379void kernel_restart_prepare(char *cmd)
385{ 380{
386 notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd); 381 notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
387 system_state = SYSTEM_RESTART; 382 system_state = SYSTEM_RESTART;
388 device_shutdown(); 383 device_shutdown();
389} 384}
385
386/**
387 * kernel_restart - reboot the system
388 * @cmd: pointer to buffer containing command to execute for restart
389 * or %NULL
390 *
391 * Shutdown everything and perform a clean reboot.
392 * This is not safe to call in interrupt context.
393 */
390void kernel_restart(char *cmd) 394void kernel_restart(char *cmd)
391{ 395{
392 kernel_restart_prepare(cmd); 396 kernel_restart_prepare(cmd);
@@ -623,6 +627,7 @@ asmlinkage long sys_setregid(gid_t rgid, gid_t egid)
623 current->egid = new_egid; 627 current->egid = new_egid;
624 current->gid = new_rgid; 628 current->gid = new_rgid;
625 key_fsgid_changed(current); 629 key_fsgid_changed(current);
630 proc_id_connector(current, PROC_EVENT_GID);
626 return 0; 631 return 0;
627} 632}
628 633
@@ -662,6 +667,7 @@ asmlinkage long sys_setgid(gid_t gid)
662 return -EPERM; 667 return -EPERM;
663 668
664 key_fsgid_changed(current); 669 key_fsgid_changed(current);
670 proc_id_connector(current, PROC_EVENT_GID);
665 return 0; 671 return 0;
666} 672}
667 673
@@ -751,6 +757,7 @@ asmlinkage long sys_setreuid(uid_t ruid, uid_t euid)
751 current->fsuid = current->euid; 757 current->fsuid = current->euid;
752 758
753 key_fsuid_changed(current); 759 key_fsuid_changed(current);
760 proc_id_connector(current, PROC_EVENT_UID);
754 761
755 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RE); 762 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RE);
756} 763}
@@ -798,6 +805,7 @@ asmlinkage long sys_setuid(uid_t uid)
798 current->suid = new_suid; 805 current->suid = new_suid;
799 806
800 key_fsuid_changed(current); 807 key_fsuid_changed(current);
808 proc_id_connector(current, PROC_EVENT_UID);
801 809
802 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_ID); 810 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_ID);
803} 811}
@@ -846,6 +854,7 @@ asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)
846 current->suid = suid; 854 current->suid = suid;
847 855
848 key_fsuid_changed(current); 856 key_fsuid_changed(current);
857 proc_id_connector(current, PROC_EVENT_UID);
849 858
850 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RES); 859 return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RES);
851} 860}
@@ -898,6 +907,7 @@ asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
898 current->sgid = sgid; 907 current->sgid = sgid;
899 908
900 key_fsgid_changed(current); 909 key_fsgid_changed(current);
910 proc_id_connector(current, PROC_EVENT_GID);
901 return 0; 911 return 0;
902} 912}
903 913
@@ -940,6 +950,7 @@ asmlinkage long sys_setfsuid(uid_t uid)
940 } 950 }
941 951
942 key_fsuid_changed(current); 952 key_fsuid_changed(current);
953 proc_id_connector(current, PROC_EVENT_UID);
943 954
944 security_task_post_setuid(old_fsuid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS); 955 security_task_post_setuid(old_fsuid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS);
945 956
@@ -968,6 +979,7 @@ asmlinkage long sys_setfsgid(gid_t gid)
968 } 979 }
969 current->fsgid = gid; 980 current->fsgid = gid;
970 key_fsgid_changed(current); 981 key_fsgid_changed(current);
982 proc_id_connector(current, PROC_EVENT_GID);
971 } 983 }
972 return old_fsgid; 984 return old_fsgid;
973} 985}
@@ -1485,8 +1497,6 @@ EXPORT_SYMBOL(in_egroup_p);
1485 1497
1486DECLARE_RWSEM(uts_sem); 1498DECLARE_RWSEM(uts_sem);
1487 1499
1488EXPORT_SYMBOL(uts_sem);
1489
1490asmlinkage long sys_newuname(struct new_utsname __user * name) 1500asmlinkage long sys_newuname(struct new_utsname __user * name)
1491{ 1501{
1492 int errno = 0; 1502 int errno = 0;
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 8e56e2495542..c4f35f96884d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -952,7 +952,7 @@ static ctl_table fs_table[] = {
952 .data = &aio_nr, 952 .data = &aio_nr,
953 .maxlen = sizeof(aio_nr), 953 .maxlen = sizeof(aio_nr),
954 .mode = 0444, 954 .mode = 0444,
955 .proc_handler = &proc_dointvec, 955 .proc_handler = &proc_doulongvec_minmax,
956 }, 956 },
957 { 957 {
958 .ctl_name = FS_AIO_MAX_NR, 958 .ctl_name = FS_AIO_MAX_NR,
@@ -960,7 +960,7 @@ static ctl_table fs_table[] = {
960 .data = &aio_max_nr, 960 .data = &aio_max_nr,
961 .maxlen = sizeof(aio_max_nr), 961 .maxlen = sizeof(aio_max_nr),
962 .mode = 0644, 962 .mode = 0644,
963 .proc_handler = &proc_dointvec, 963 .proc_handler = &proc_doulongvec_minmax,
964 }, 964 },
965#ifdef CONFIG_INOTIFY 965#ifdef CONFIG_INOTIFY
966 { 966 {
@@ -1997,6 +1997,7 @@ int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1997 * @filp: the file structure 1997 * @filp: the file structure
1998 * @buffer: the user buffer 1998 * @buffer: the user buffer
1999 * @lenp: the size of the user buffer 1999 * @lenp: the size of the user buffer
2000 * @ppos: pointer to the file position
2000 * 2001 *
2001 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 2002 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2002 * values from/to the user buffer, treated as an ASCII string. 2003 * values from/to the user buffer, treated as an ASCII string.
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 7cee222231bc..42df83d7fad2 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -524,7 +524,7 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb,
524 list_for_each_entry(wq, &workqueues, list) { 524 list_for_each_entry(wq, &workqueues, list) {
525 /* Unbind so it can run. */ 525 /* Unbind so it can run. */
526 kthread_bind(per_cpu_ptr(wq->cpu_wq, hotcpu)->thread, 526 kthread_bind(per_cpu_ptr(wq->cpu_wq, hotcpu)->thread,
527 smp_processor_id()); 527 any_online_cpu(cpu_online_map));
528 cleanup_workqueue_thread(wq, hotcpu); 528 cleanup_workqueue_thread(wq, hotcpu);
529 } 529 }
530 break; 530 break;
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index d1c057e71b68..88511c3805ad 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -281,35 +281,60 @@ int radix_tree_insert(struct radix_tree_root *root,
281} 281}
282EXPORT_SYMBOL(radix_tree_insert); 282EXPORT_SYMBOL(radix_tree_insert);
283 283
284/** 284static inline void **__lookup_slot(struct radix_tree_root *root,
285 * radix_tree_lookup - perform lookup operation on a radix tree 285 unsigned long index)
286 * @root: radix tree root
287 * @index: index key
288 *
289 * Lookup the item at the position @index in the radix tree @root.
290 */
291void *radix_tree_lookup(struct radix_tree_root *root, unsigned long index)
292{ 286{
293 unsigned int height, shift; 287 unsigned int height, shift;
294 struct radix_tree_node *slot; 288 struct radix_tree_node **slot;
295 289
296 height = root->height; 290 height = root->height;
297 if (index > radix_tree_maxindex(height)) 291 if (index > radix_tree_maxindex(height))
298 return NULL; 292 return NULL;
299 293
300 shift = (height-1) * RADIX_TREE_MAP_SHIFT; 294 shift = (height-1) * RADIX_TREE_MAP_SHIFT;
301 slot = root->rnode; 295 slot = &root->rnode;
302 296
303 while (height > 0) { 297 while (height > 0) {
304 if (slot == NULL) 298 if (*slot == NULL)
305 return NULL; 299 return NULL;
306 300
307 slot = slot->slots[(index >> shift) & RADIX_TREE_MAP_MASK]; 301 slot = (struct radix_tree_node **)
302 ((*slot)->slots +
303 ((index >> shift) & RADIX_TREE_MAP_MASK));
308 shift -= RADIX_TREE_MAP_SHIFT; 304 shift -= RADIX_TREE_MAP_SHIFT;
309 height--; 305 height--;
310 } 306 }
311 307
312 return slot; 308 return (void **)slot;
309}
310
311/**
312 * radix_tree_lookup_slot - lookup a slot in a radix tree
313 * @root: radix tree root
314 * @index: index key
315 *
316 * Lookup the slot corresponding to the position @index in the radix tree
317 * @root. This is useful for update-if-exists operations.
318 */
319void **radix_tree_lookup_slot(struct radix_tree_root *root, unsigned long index)
320{
321 return __lookup_slot(root, index);
322}
323EXPORT_SYMBOL(radix_tree_lookup_slot);
324
325/**
326 * radix_tree_lookup - perform lookup operation on a radix tree
327 * @root: radix tree root
328 * @index: index key
329 *
330 * Lookup the item at the position @index in the radix tree @root.
331 */
332void *radix_tree_lookup(struct radix_tree_root *root, unsigned long index)
333{
334 void **slot;
335
336 slot = __lookup_slot(root, index);
337 return slot != NULL ? *slot : NULL;
313} 338}
314EXPORT_SYMBOL(radix_tree_lookup); 339EXPORT_SYMBOL(radix_tree_lookup);
315 340
diff --git a/lib/reed_solomon/Makefile b/lib/reed_solomon/Makefile
index 747a2de29346..c3d7136827ed 100644
--- a/lib/reed_solomon/Makefile
+++ b/lib/reed_solomon/Makefile
@@ -1,5 +1,5 @@
1# 1#
2# This is a modified version of reed solomon lib, 2# This is a modified version of reed solomon lib,
3# 3#
4 4
5obj-$(CONFIG_REED_SOLOMON) += reed_solomon.o 5obj-$(CONFIG_REED_SOLOMON) += reed_solomon.o
diff --git a/lib/reed_solomon/decode_rs.c b/lib/reed_solomon/decode_rs.c
index d401decd6289..a58df56f09b6 100644
--- a/lib/reed_solomon/decode_rs.c
+++ b/lib/reed_solomon/decode_rs.c
@@ -1,22 +1,22 @@
1/* 1/*
2 * lib/reed_solomon/decode_rs.c 2 * lib/reed_solomon/decode_rs.c
3 * 3 *
4 * Overview: 4 * Overview:
5 * Generic Reed Solomon encoder / decoder library 5 * Generic Reed Solomon encoder / decoder library
6 * 6 *
7 * Copyright 2002, Phil Karn, KA9Q 7 * Copyright 2002, Phil Karn, KA9Q
8 * May be used under the terms of the GNU General Public License (GPL) 8 * May be used under the terms of the GNU General Public License (GPL)
9 * 9 *
10 * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de) 10 * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de)
11 * 11 *
12 * $Id: decode_rs.c,v 1.6 2004/10/22 15:41:47 gleixner Exp $ 12 * $Id: decode_rs.c,v 1.7 2005/11/07 11:14:59 gleixner Exp $
13 * 13 *
14 */ 14 */
15 15
16/* Generic data width independent code which is included by the 16/* Generic data width independent code which is included by the
17 * wrappers. 17 * wrappers.
18 */ 18 */
19{ 19{
20 int deg_lambda, el, deg_omega; 20 int deg_lambda, el, deg_omega;
21 int i, j, r, k, pad; 21 int i, j, r, k, pad;
22 int nn = rs->nn; 22 int nn = rs->nn;
@@ -41,9 +41,9 @@
41 pad = nn - nroots - len; 41 pad = nn - nroots - len;
42 if (pad < 0 || pad >= nn) 42 if (pad < 0 || pad >= nn)
43 return -ERANGE; 43 return -ERANGE;
44 44
45 /* Does the caller provide the syndrome ? */ 45 /* Does the caller provide the syndrome ? */
46 if (s != NULL) 46 if (s != NULL)
47 goto decode; 47 goto decode;
48 48
49 /* form the syndromes; i.e., evaluate data(x) at roots of 49 /* form the syndromes; i.e., evaluate data(x) at roots of
@@ -54,11 +54,11 @@
54 for (j = 1; j < len; j++) { 54 for (j = 1; j < len; j++) {
55 for (i = 0; i < nroots; i++) { 55 for (i = 0; i < nroots; i++) {
56 if (syn[i] == 0) { 56 if (syn[i] == 0) {
57 syn[i] = (((uint16_t) data[j]) ^ 57 syn[i] = (((uint16_t) data[j]) ^
58 invmsk) & msk; 58 invmsk) & msk;
59 } else { 59 } else {
60 syn[i] = ((((uint16_t) data[j]) ^ 60 syn[i] = ((((uint16_t) data[j]) ^
61 invmsk) & msk) ^ 61 invmsk) & msk) ^
62 alpha_to[rs_modnn(rs, index_of[syn[i]] + 62 alpha_to[rs_modnn(rs, index_of[syn[i]] +
63 (fcr + i) * prim)]; 63 (fcr + i) * prim)];
64 } 64 }
@@ -70,7 +70,7 @@
70 if (syn[i] == 0) { 70 if (syn[i] == 0) {
71 syn[i] = ((uint16_t) par[j]) & msk; 71 syn[i] = ((uint16_t) par[j]) & msk;
72 } else { 72 } else {
73 syn[i] = (((uint16_t) par[j]) & msk) ^ 73 syn[i] = (((uint16_t) par[j]) & msk) ^
74 alpha_to[rs_modnn(rs, index_of[syn[i]] + 74 alpha_to[rs_modnn(rs, index_of[syn[i]] +
75 (fcr+i)*prim)]; 75 (fcr+i)*prim)];
76 } 76 }
@@ -99,14 +99,14 @@
99 99
100 if (no_eras > 0) { 100 if (no_eras > 0) {
101 /* Init lambda to be the erasure locator polynomial */ 101 /* Init lambda to be the erasure locator polynomial */
102 lambda[1] = alpha_to[rs_modnn(rs, 102 lambda[1] = alpha_to[rs_modnn(rs,
103 prim * (nn - 1 - eras_pos[0]))]; 103 prim * (nn - 1 - eras_pos[0]))];
104 for (i = 1; i < no_eras; i++) { 104 for (i = 1; i < no_eras; i++) {
105 u = rs_modnn(rs, prim * (nn - 1 - eras_pos[i])); 105 u = rs_modnn(rs, prim * (nn - 1 - eras_pos[i]));
106 for (j = i + 1; j > 0; j--) { 106 for (j = i + 1; j > 0; j--) {
107 tmp = index_of[lambda[j - 1]]; 107 tmp = index_of[lambda[j - 1]];
108 if (tmp != nn) { 108 if (tmp != nn) {
109 lambda[j] ^= 109 lambda[j] ^=
110 alpha_to[rs_modnn(rs, u + tmp)]; 110 alpha_to[rs_modnn(rs, u + tmp)];
111 } 111 }
112 } 112 }
@@ -127,8 +127,8 @@
127 discr_r = 0; 127 discr_r = 0;
128 for (i = 0; i < r; i++) { 128 for (i = 0; i < r; i++) {
129 if ((lambda[i] != 0) && (s[r - i - 1] != nn)) { 129 if ((lambda[i] != 0) && (s[r - i - 1] != nn)) {
130 discr_r ^= 130 discr_r ^=
131 alpha_to[rs_modnn(rs, 131 alpha_to[rs_modnn(rs,
132 index_of[lambda[i]] + 132 index_of[lambda[i]] +
133 s[r - i - 1])]; 133 s[r - i - 1])];
134 } 134 }
@@ -143,7 +143,7 @@
143 t[0] = lambda[0]; 143 t[0] = lambda[0];
144 for (i = 0; i < nroots; i++) { 144 for (i = 0; i < nroots; i++) {
145 if (b[i] != nn) { 145 if (b[i] != nn) {
146 t[i + 1] = lambda[i + 1] ^ 146 t[i + 1] = lambda[i + 1] ^
147 alpha_to[rs_modnn(rs, discr_r + 147 alpha_to[rs_modnn(rs, discr_r +
148 b[i])]; 148 b[i])];
149 } else 149 } else
@@ -229,7 +229,7 @@
229 num1 = 0; 229 num1 = 0;
230 for (i = deg_omega; i >= 0; i--) { 230 for (i = deg_omega; i >= 0; i--) {
231 if (omega[i] != nn) 231 if (omega[i] != nn)
232 num1 ^= alpha_to[rs_modnn(rs, omega[i] + 232 num1 ^= alpha_to[rs_modnn(rs, omega[i] +
233 i * root[j])]; 233 i * root[j])];
234 } 234 }
235 num2 = alpha_to[rs_modnn(rs, root[j] * (fcr - 1) + nn)]; 235 num2 = alpha_to[rs_modnn(rs, root[j] * (fcr - 1) + nn)];
@@ -239,13 +239,13 @@
239 * lambda_pr of lambda[i] */ 239 * lambda_pr of lambda[i] */
240 for (i = min(deg_lambda, nroots - 1) & ~1; i >= 0; i -= 2) { 240 for (i = min(deg_lambda, nroots - 1) & ~1; i >= 0; i -= 2) {
241 if (lambda[i + 1] != nn) { 241 if (lambda[i + 1] != nn) {
242 den ^= alpha_to[rs_modnn(rs, lambda[i + 1] + 242 den ^= alpha_to[rs_modnn(rs, lambda[i + 1] +
243 i * root[j])]; 243 i * root[j])];
244 } 244 }
245 } 245 }
246 /* Apply error to data */ 246 /* Apply error to data */
247 if (num1 != 0 && loc[j] >= pad) { 247 if (num1 != 0 && loc[j] >= pad) {
248 uint16_t cor = alpha_to[rs_modnn(rs,index_of[num1] + 248 uint16_t cor = alpha_to[rs_modnn(rs,index_of[num1] +
249 index_of[num2] + 249 index_of[num2] +
250 nn - index_of[den])]; 250 nn - index_of[den])];
251 /* Store the error correction pattern, if a 251 /* Store the error correction pattern, if a
diff --git a/lib/reed_solomon/encode_rs.c b/lib/reed_solomon/encode_rs.c
index 237bf65ae886..0b5b1a6728ec 100644
--- a/lib/reed_solomon/encode_rs.c
+++ b/lib/reed_solomon/encode_rs.c
@@ -1,19 +1,19 @@
1/* 1/*
2 * lib/reed_solomon/encode_rs.c 2 * lib/reed_solomon/encode_rs.c
3 * 3 *
4 * Overview: 4 * Overview:
5 * Generic Reed Solomon encoder / decoder library 5 * Generic Reed Solomon encoder / decoder library
6 * 6 *
7 * Copyright 2002, Phil Karn, KA9Q 7 * Copyright 2002, Phil Karn, KA9Q
8 * May be used under the terms of the GNU General Public License (GPL) 8 * May be used under the terms of the GNU General Public License (GPL)
9 * 9 *
10 * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de) 10 * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de)
11 * 11 *
12 * $Id: encode_rs.c,v 1.4 2004/10/22 15:41:47 gleixner Exp $ 12 * $Id: encode_rs.c,v 1.5 2005/11/07 11:14:59 gleixner Exp $
13 * 13 *
14 */ 14 */
15 15
16/* Generic data width independent code which is included by the 16/* Generic data width independent code which is included by the
17 * wrappers. 17 * wrappers.
18 * int encode_rsX (struct rs_control *rs, uintX_t *data, int len, uintY_t *par) 18 * int encode_rsX (struct rs_control *rs, uintX_t *data, int len, uintY_t *par)
19 */ 19 */
@@ -35,16 +35,16 @@
35 for (i = 0; i < len; i++) { 35 for (i = 0; i < len; i++) {
36 fb = index_of[((((uint16_t) data[i])^invmsk) & msk) ^ par[0]]; 36 fb = index_of[((((uint16_t) data[i])^invmsk) & msk) ^ par[0]];
37 /* feedback term is non-zero */ 37 /* feedback term is non-zero */
38 if (fb != nn) { 38 if (fb != nn) {
39 for (j = 1; j < nroots; j++) { 39 for (j = 1; j < nroots; j++) {
40 par[j] ^= alpha_to[rs_modnn(rs, fb + 40 par[j] ^= alpha_to[rs_modnn(rs, fb +
41 genpoly[nroots - j])]; 41 genpoly[nroots - j])];
42 } 42 }
43 } 43 }
44 /* Shift */ 44 /* Shift */
45 memmove(&par[0], &par[1], sizeof(uint16_t) * (nroots - 1)); 45 memmove(&par[0], &par[1], sizeof(uint16_t) * (nroots - 1));
46 if (fb != nn) { 46 if (fb != nn) {
47 par[nroots - 1] = alpha_to[rs_modnn(rs, 47 par[nroots - 1] = alpha_to[rs_modnn(rs,
48 fb + genpoly[0])]; 48 fb + genpoly[0])];
49 } else { 49 } else {
50 par[nroots - 1] = 0; 50 par[nroots - 1] = 0;
diff --git a/lib/reed_solomon/reed_solomon.c b/lib/reed_solomon/reed_solomon.c
index 6604e3b1940c..f5fef948a415 100644
--- a/lib/reed_solomon/reed_solomon.c
+++ b/lib/reed_solomon/reed_solomon.c
@@ -1,22 +1,22 @@
1/* 1/*
2 * lib/reed_solomon/rslib.c 2 * lib/reed_solomon/rslib.c
3 * 3 *
4 * Overview: 4 * Overview:
5 * Generic Reed Solomon encoder / decoder library 5 * Generic Reed Solomon encoder / decoder library
6 * 6 *
7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de) 7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)
8 * 8 *
9 * Reed Solomon code lifted from reed solomon library written by Phil Karn 9 * Reed Solomon code lifted from reed solomon library written by Phil Karn
10 * Copyright 2002 Phil Karn, KA9Q 10 * Copyright 2002 Phil Karn, KA9Q
11 * 11 *
12 * $Id: rslib.c,v 1.5 2004/10/22 15:41:47 gleixner Exp $ 12 * $Id: rslib.c,v 1.7 2005/11/07 11:14:59 gleixner Exp $
13 * 13 *
14 * This program is free software; you can redistribute it and/or modify 14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as 15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation. 16 * published by the Free Software Foundation.
17 * 17 *
18 * Description: 18 * Description:
19 * 19 *
20 * The generic Reed Solomon library provides runtime configurable 20 * The generic Reed Solomon library provides runtime configurable
21 * encoding / decoding of RS codes. 21 * encoding / decoding of RS codes.
22 * Each user must call init_rs to get a pointer to a rs_control 22 * Each user must call init_rs to get a pointer to a rs_control
@@ -25,11 +25,11 @@
25 * If a structure is generated then the polynomial arrays for 25 * If a structure is generated then the polynomial arrays for
26 * fast encoding / decoding are built. This can take some time so 26 * fast encoding / decoding are built. This can take some time so
27 * make sure not to call this function from a time critical path. 27 * make sure not to call this function from a time critical path.
28 * Usually a module / driver should initialize the necessary 28 * Usually a module / driver should initialize the necessary
29 * rs_control structure on module / driver init and release it 29 * rs_control structure on module / driver init and release it
30 * on exit. 30 * on exit.
31 * The encoding puts the calculated syndrome into a given syndrome 31 * The encoding puts the calculated syndrome into a given syndrome
32 * buffer. 32 * buffer.
33 * The decoding is a two step process. The first step calculates 33 * The decoding is a two step process. The first step calculates
34 * the syndrome over the received (data + syndrome) and calls the 34 * the syndrome over the received (data + syndrome) and calls the
35 * second stage, which does the decoding / error correction itself. 35 * second stage, which does the decoding / error correction itself.
@@ -51,7 +51,7 @@ static LIST_HEAD (rslist);
51/* Protection for the list */ 51/* Protection for the list */
52static DECLARE_MUTEX(rslistlock); 52static DECLARE_MUTEX(rslistlock);
53 53
54/** 54/**
55 * rs_init - Initialize a Reed-Solomon codec 55 * rs_init - Initialize a Reed-Solomon codec
56 * 56 *
57 * @symsize: symbol size, bits (1-8) 57 * @symsize: symbol size, bits (1-8)
@@ -63,7 +63,7 @@ static DECLARE_MUTEX(rslistlock);
63 * Allocate a control structure and the polynom arrays for faster 63 * Allocate a control structure and the polynom arrays for faster
64 * en/decoding. Fill the arrays according to the given parameters 64 * en/decoding. Fill the arrays according to the given parameters
65 */ 65 */
66static struct rs_control *rs_init(int symsize, int gfpoly, int fcr, 66static struct rs_control *rs_init(int symsize, int gfpoly, int fcr,
67 int prim, int nroots) 67 int prim, int nroots)
68{ 68{
69 struct rs_control *rs; 69 struct rs_control *rs;
@@ -124,15 +124,15 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int fcr,
124 /* Multiply rs->genpoly[] by @**(root + x) */ 124 /* Multiply rs->genpoly[] by @**(root + x) */
125 for (j = i; j > 0; j--) { 125 for (j = i; j > 0; j--) {
126 if (rs->genpoly[j] != 0) { 126 if (rs->genpoly[j] != 0) {
127 rs->genpoly[j] = rs->genpoly[j -1] ^ 127 rs->genpoly[j] = rs->genpoly[j -1] ^
128 rs->alpha_to[rs_modnn(rs, 128 rs->alpha_to[rs_modnn(rs,
129 rs->index_of[rs->genpoly[j]] + root)]; 129 rs->index_of[rs->genpoly[j]] + root)];
130 } else 130 } else
131 rs->genpoly[j] = rs->genpoly[j - 1]; 131 rs->genpoly[j] = rs->genpoly[j - 1];
132 } 132 }
133 /* rs->genpoly[0] can never be zero */ 133 /* rs->genpoly[0] can never be zero */
134 rs->genpoly[0] = 134 rs->genpoly[0] =
135 rs->alpha_to[rs_modnn(rs, 135 rs->alpha_to[rs_modnn(rs,
136 rs->index_of[rs->genpoly[0]] + root)]; 136 rs->index_of[rs->genpoly[0]] + root)];
137 } 137 }
138 /* convert rs->genpoly[] to index form for quicker encoding */ 138 /* convert rs->genpoly[] to index form for quicker encoding */
@@ -153,7 +153,7 @@ errrs:
153} 153}
154 154
155 155
156/** 156/**
157 * free_rs - Free the rs control structure, if its not longer used 157 * free_rs - Free the rs control structure, if its not longer used
158 * 158 *
159 * @rs: the control structure which is not longer used by the 159 * @rs: the control structure which is not longer used by the
@@ -173,19 +173,19 @@ void free_rs(struct rs_control *rs)
173 up(&rslistlock); 173 up(&rslistlock);
174} 174}
175 175
176/** 176/**
177 * init_rs - Find a matching or allocate a new rs control structure 177 * init_rs - Find a matching or allocate a new rs control structure
178 * 178 *
179 * @symsize: the symbol size (number of bits) 179 * @symsize: the symbol size (number of bits)
180 * @gfpoly: the extended Galois field generator polynomial coefficients, 180 * @gfpoly: the extended Galois field generator polynomial coefficients,
181 * with the 0th coefficient in the low order bit. The polynomial 181 * with the 0th coefficient in the low order bit. The polynomial
182 * must be primitive; 182 * must be primitive;
183 * @fcr: the first consecutive root of the rs code generator polynomial 183 * @fcr: the first consecutive root of the rs code generator polynomial
184 * in index form 184 * in index form
185 * @prim: primitive element to generate polynomial roots 185 * @prim: primitive element to generate polynomial roots
186 * @nroots: RS code generator polynomial degree (number of roots) 186 * @nroots: RS code generator polynomial degree (number of roots)
187 */ 187 */
188struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim, 188struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim,
189 int nroots) 189 int nroots)
190{ 190{
191 struct list_head *tmp; 191 struct list_head *tmp;
@@ -198,9 +198,9 @@ struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim,
198 return NULL; 198 return NULL;
199 if (prim <= 0 || prim >= (1<<symsize)) 199 if (prim <= 0 || prim >= (1<<symsize))
200 return NULL; 200 return NULL;
201 if (nroots < 0 || nroots >= (1<<symsize) || nroots > 8) 201 if (nroots < 0 || nroots >= (1<<symsize))
202 return NULL; 202 return NULL;
203 203
204 down(&rslistlock); 204 down(&rslistlock);
205 205
206 /* Walk through the list and look for a matching entry */ 206 /* Walk through the list and look for a matching entry */
@@ -211,9 +211,9 @@ struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim,
211 if (gfpoly != rs->gfpoly) 211 if (gfpoly != rs->gfpoly)
212 continue; 212 continue;
213 if (fcr != rs->fcr) 213 if (fcr != rs->fcr)
214 continue; 214 continue;
215 if (prim != rs->prim) 215 if (prim != rs->prim)
216 continue; 216 continue;
217 if (nroots != rs->nroots) 217 if (nroots != rs->nroots)
218 continue; 218 continue;
219 /* We have a matching one already */ 219 /* We have a matching one already */
@@ -227,18 +227,18 @@ struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim,
227 rs->users = 1; 227 rs->users = 1;
228 list_add(&rs->list, &rslist); 228 list_add(&rs->list, &rslist);
229 } 229 }
230out: 230out:
231 up(&rslistlock); 231 up(&rslistlock);
232 return rs; 232 return rs;
233} 233}
234 234
235#ifdef CONFIG_REED_SOLOMON_ENC8 235#ifdef CONFIG_REED_SOLOMON_ENC8
236/** 236/**
237 * encode_rs8 - Calculate the parity for data values (8bit data width) 237 * encode_rs8 - Calculate the parity for data values (8bit data width)
238 * 238 *
239 * @rs: the rs control structure 239 * @rs: the rs control structure
240 * @data: data field of a given type 240 * @data: data field of a given type
241 * @len: data length 241 * @len: data length
242 * @par: parity data, must be initialized by caller (usually all 0) 242 * @par: parity data, must be initialized by caller (usually all 0)
243 * @invmsk: invert data mask (will be xored on data) 243 * @invmsk: invert data mask (will be xored on data)
244 * 244 *
@@ -246,7 +246,7 @@ out:
246 * symbol size > 8. The calling code must take care of encoding of the 246 * symbol size > 8. The calling code must take care of encoding of the
247 * syndrome result for storage itself. 247 * syndrome result for storage itself.
248 */ 248 */
249int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par, 249int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par,
250 uint16_t invmsk) 250 uint16_t invmsk)
251{ 251{
252#include "encode_rs.c" 252#include "encode_rs.c"
@@ -255,7 +255,7 @@ EXPORT_SYMBOL_GPL(encode_rs8);
255#endif 255#endif
256 256
257#ifdef CONFIG_REED_SOLOMON_DEC8 257#ifdef CONFIG_REED_SOLOMON_DEC8
258/** 258/**
259 * decode_rs8 - Decode codeword (8bit data width) 259 * decode_rs8 - Decode codeword (8bit data width)
260 * 260 *
261 * @rs: the rs control structure 261 * @rs: the rs control structure
@@ -273,7 +273,7 @@ EXPORT_SYMBOL_GPL(encode_rs8);
273 * syndrome result and the received parity before calling this code. 273 * syndrome result and the received parity before calling this code.
274 */ 274 */
275int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len, 275int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len,
276 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, 276 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,
277 uint16_t *corr) 277 uint16_t *corr)
278{ 278{
279#include "decode_rs.c" 279#include "decode_rs.c"
@@ -287,13 +287,13 @@ EXPORT_SYMBOL_GPL(decode_rs8);
287 * 287 *
288 * @rs: the rs control structure 288 * @rs: the rs control structure
289 * @data: data field of a given type 289 * @data: data field of a given type
290 * @len: data length 290 * @len: data length
291 * @par: parity data, must be initialized by caller (usually all 0) 291 * @par: parity data, must be initialized by caller (usually all 0)
292 * @invmsk: invert data mask (will be xored on data, not on parity!) 292 * @invmsk: invert data mask (will be xored on data, not on parity!)
293 * 293 *
294 * Each field in the data array contains up to symbol size bits of valid data. 294 * Each field in the data array contains up to symbol size bits of valid data.
295 */ 295 */
296int encode_rs16(struct rs_control *rs, uint16_t *data, int len, uint16_t *par, 296int encode_rs16(struct rs_control *rs, uint16_t *data, int len, uint16_t *par,
297 uint16_t invmsk) 297 uint16_t invmsk)
298{ 298{
299#include "encode_rs.c" 299#include "encode_rs.c"
@@ -302,7 +302,7 @@ EXPORT_SYMBOL_GPL(encode_rs16);
302#endif 302#endif
303 303
304#ifdef CONFIG_REED_SOLOMON_DEC16 304#ifdef CONFIG_REED_SOLOMON_DEC16
305/** 305/**
306 * decode_rs16 - Decode codeword (16bit data width) 306 * decode_rs16 - Decode codeword (16bit data width)
307 * 307 *
308 * @rs: the rs control structure 308 * @rs: the rs control structure
@@ -312,13 +312,13 @@ EXPORT_SYMBOL_GPL(encode_rs16);
312 * @s: syndrome data field (if NULL, syndrome is calculated) 312 * @s: syndrome data field (if NULL, syndrome is calculated)
313 * @no_eras: number of erasures 313 * @no_eras: number of erasures
314 * @eras_pos: position of erasures, can be NULL 314 * @eras_pos: position of erasures, can be NULL
315 * @invmsk: invert data mask (will be xored on data, not on parity!) 315 * @invmsk: invert data mask (will be xored on data, not on parity!)
316 * @corr: buffer to store correction bitmask on eras_pos 316 * @corr: buffer to store correction bitmask on eras_pos
317 * 317 *
318 * Each field in the data array contains up to symbol size bits of valid data. 318 * Each field in the data array contains up to symbol size bits of valid data.
319 */ 319 */
320int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len, 320int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len,
321 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, 321 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,
322 uint16_t *corr) 322 uint16_t *corr)
323{ 323{
324#include "decode_rs.c" 324#include "decode_rs.c"
diff --git a/mm/Kconfig b/mm/Kconfig
index 1a4473fcb2ca..ae9ce6b73e8a 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -126,9 +126,11 @@ comment "Memory hotplug is currently incompatible with Software Suspend"
126# Default to 4 for wider testing, though 8 might be more appropriate. 126# Default to 4 for wider testing, though 8 might be more appropriate.
127# ARM's adjust_pte (unused if VIPT) depends on mm-wide page_table_lock. 127# ARM's adjust_pte (unused if VIPT) depends on mm-wide page_table_lock.
128# PA-RISC's debug spinlock_t is too large for the 32-bit struct page. 128# PA-RISC's debug spinlock_t is too large for the 32-bit struct page.
129# ARM26 and SPARC32 and PPC64 may use one page for multiple page tables.
129# 130#
130config SPLIT_PTLOCK_CPUS 131config SPLIT_PTLOCK_CPUS
131 int 132 int
132 default "4096" if ARM && !CPU_CACHE_VIPT 133 default "4096" if ARM && !CPU_CACHE_VIPT
133 default "4096" if PARISC && DEBUG_SPINLOCK && !64BIT 134 default "4096" if PARISC && DEBUG_SPINLOCK && !64BIT
135 default "4096" if ARM26 || SPARC32 || PPC64
134 default "4" 136 default "4"
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 9a565808da3f..728e9bda12ea 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -237,7 +237,6 @@ unsigned long hugetlb_total_pages(void)
237{ 237{
238 return nr_huge_pages * (HPAGE_SIZE / PAGE_SIZE); 238 return nr_huge_pages * (HPAGE_SIZE / PAGE_SIZE);
239} 239}
240EXPORT_SYMBOL(hugetlb_total_pages);
241 240
242/* 241/*
243 * We cannot handle pagefaults against hugetlb pages at all. They cause 242 * We cannot handle pagefaults against hugetlb pages at all. They cause
diff --git a/mm/mmap.c b/mm/mmap.c
index 320dda1778c3..6c997b159600 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -155,10 +155,6 @@ int __vm_enough_memory(long pages, int cap_sys_admin)
155 return -ENOMEM; 155 return -ENOMEM;
156} 156}
157 157
158EXPORT_SYMBOL(sysctl_overcommit_memory);
159EXPORT_SYMBOL(sysctl_overcommit_ratio);
160EXPORT_SYMBOL(sysctl_max_map_count);
161EXPORT_SYMBOL(vm_committed_space);
162EXPORT_SYMBOL(__vm_enough_memory); 158EXPORT_SYMBOL(__vm_enough_memory);
163 159
164/* 160/*
diff --git a/mm/nommu.c b/mm/nommu.c
index d1e076a487cb..6deb6ab3d6ad 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -44,10 +44,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
44int heap_stack_gap = 0; 44int heap_stack_gap = 0;
45 45
46EXPORT_SYMBOL(mem_map); 46EXPORT_SYMBOL(mem_map);
47EXPORT_SYMBOL(sysctl_max_map_count);
48EXPORT_SYMBOL(sysctl_overcommit_memory);
49EXPORT_SYMBOL(sysctl_overcommit_ratio);
50EXPORT_SYMBOL(vm_committed_space);
51EXPORT_SYMBOL(__vm_enough_memory); 47EXPORT_SYMBOL(__vm_enough_memory);
52 48
53/* list of shareable VMAs */ 49/* list of shareable VMAs */
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 0166ea15c9ee..74138c9a22b9 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -750,7 +750,6 @@ int clear_page_dirty_for_io(struct page *page)
750 } 750 }
751 return TestClearPageDirty(page); 751 return TestClearPageDirty(page);
752} 752}
753EXPORT_SYMBOL(clear_page_dirty_for_io);
754 753
755int test_clear_page_writeback(struct page *page) 754int test_clear_page_writeback(struct page *page)
756{ 755{
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 2dbdd98426fd..ff81b5c65511 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -64,7 +64,6 @@ long nr_swap_pages;
64int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES-1] = { 256, 32 }; 64int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES-1] = { 256, 32 };
65 65
66EXPORT_SYMBOL(totalram_pages); 66EXPORT_SYMBOL(totalram_pages);
67EXPORT_SYMBOL(nr_swap_pages);
68 67
69/* 68/*
70 * Used by page_zone() to look up the address of the struct zone whose 69 * Used by page_zone() to look up the address of the struct zone whose
diff --git a/mm/readahead.c b/mm/readahead.c
index d0b50034e245..72e7adbb87c7 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -254,7 +254,7 @@ out:
254 */ 254 */
255static int 255static int
256__do_page_cache_readahead(struct address_space *mapping, struct file *filp, 256__do_page_cache_readahead(struct address_space *mapping, struct file *filp,
257 unsigned long offset, unsigned long nr_to_read) 257 pgoff_t offset, unsigned long nr_to_read)
258{ 258{
259 struct inode *inode = mapping->host; 259 struct inode *inode = mapping->host;
260 struct page *page; 260 struct page *page;
@@ -274,7 +274,7 @@ __do_page_cache_readahead(struct address_space *mapping, struct file *filp,
274 */ 274 */
275 read_lock_irq(&mapping->tree_lock); 275 read_lock_irq(&mapping->tree_lock);
276 for (page_idx = 0; page_idx < nr_to_read; page_idx++) { 276 for (page_idx = 0; page_idx < nr_to_read; page_idx++) {
277 unsigned long page_offset = offset + page_idx; 277 pgoff_t page_offset = offset + page_idx;
278 278
279 if (page_offset > end_index) 279 if (page_offset > end_index)
280 break; 280 break;
@@ -311,7 +311,7 @@ out:
311 * memory at once. 311 * memory at once.
312 */ 312 */
313int force_page_cache_readahead(struct address_space *mapping, struct file *filp, 313int force_page_cache_readahead(struct address_space *mapping, struct file *filp,
314 unsigned long offset, unsigned long nr_to_read) 314 pgoff_t offset, unsigned long nr_to_read)
315{ 315{
316 int ret = 0; 316 int ret = 0;
317 317
@@ -368,7 +368,7 @@ static inline int check_ra_success(struct file_ra_state *ra,
368 * request queues. 368 * request queues.
369 */ 369 */
370int do_page_cache_readahead(struct address_space *mapping, struct file *filp, 370int do_page_cache_readahead(struct address_space *mapping, struct file *filp,
371 unsigned long offset, unsigned long nr_to_read) 371 pgoff_t offset, unsigned long nr_to_read)
372{ 372{
373 if (bdi_read_congested(mapping->backing_dev_info)) 373 if (bdi_read_congested(mapping->backing_dev_info))
374 return -1; 374 return -1;
@@ -385,7 +385,7 @@ int do_page_cache_readahead(struct address_space *mapping, struct file *filp,
385 */ 385 */
386static int 386static int
387blockable_page_cache_readahead(struct address_space *mapping, struct file *filp, 387blockable_page_cache_readahead(struct address_space *mapping, struct file *filp,
388 unsigned long offset, unsigned long nr_to_read, 388 pgoff_t offset, unsigned long nr_to_read,
389 struct file_ra_state *ra, int block) 389 struct file_ra_state *ra, int block)
390{ 390{
391 int actual; 391 int actual;
@@ -430,14 +430,27 @@ static int make_ahead_window(struct address_space *mapping, struct file *filp,
430 return ret; 430 return ret;
431} 431}
432 432
433/* 433/**
434 * page_cache_readahead is the main function. If performs the adaptive 434 * page_cache_readahead - generic adaptive readahead
435 * @mapping: address_space which holds the pagecache and I/O vectors
436 * @ra: file_ra_state which holds the readahead state
437 * @filp: passed on to ->readpage() and ->readpages()
438 * @offset: start offset into @mapping, in PAGE_CACHE_SIZE units
439 * @req_size: hint: total size of the read which the caller is performing in
440 * PAGE_CACHE_SIZE units
441 *
442 * page_cache_readahead() is the main function. If performs the adaptive
435 * readahead window size management and submits the readahead I/O. 443 * readahead window size management and submits the readahead I/O.
444 *
445 * Note that @filp is purely used for passing on to the ->readpage[s]()
446 * handler: it may refer to a different file from @mapping (so we may not use
447 * @filp->f_mapping or @filp->f_dentry->d_inode here).
448 * Also, @ra may not be equal to &@filp->f_ra.
449 *
436 */ 450 */
437unsigned long 451unsigned long
438page_cache_readahead(struct address_space *mapping, struct file_ra_state *ra, 452page_cache_readahead(struct address_space *mapping, struct file_ra_state *ra,
439 struct file *filp, unsigned long offset, 453 struct file *filp, pgoff_t offset, unsigned long req_size)
440 unsigned long req_size)
441{ 454{
442 unsigned long max, newsize; 455 unsigned long max, newsize;
443 int sequential; 456 int sequential;
diff --git a/mm/slab.c b/mm/slab.c
index 22bfb0b2ac8b..e291f5e1afbb 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -368,7 +368,7 @@ static inline void kmem_list3_init(struct kmem_list3 *parent)
368 * manages a cache. 368 * manages a cache.
369 */ 369 */
370 370
371struct kmem_cache_s { 371struct kmem_cache {
372/* 1) per-cpu data, touched during every alloc/free */ 372/* 1) per-cpu data, touched during every alloc/free */
373 struct array_cache *array[NR_CPUS]; 373 struct array_cache *array[NR_CPUS];
374 unsigned int batchcount; 374 unsigned int batchcount;
@@ -1502,6 +1502,7 @@ kmem_cache_create (const char *name, size_t size, size_t align,
1502{ 1502{
1503 size_t left_over, slab_size, ralign; 1503 size_t left_over, slab_size, ralign;
1504 kmem_cache_t *cachep = NULL; 1504 kmem_cache_t *cachep = NULL;
1505 struct list_head *p;
1505 1506
1506 /* 1507 /*
1507 * Sanity checks... these are all serious usage bugs. 1508 * Sanity checks... these are all serious usage bugs.
@@ -1516,6 +1517,35 @@ kmem_cache_create (const char *name, size_t size, size_t align,
1516 BUG(); 1517 BUG();
1517 } 1518 }
1518 1519
1520 down(&cache_chain_sem);
1521
1522 list_for_each(p, &cache_chain) {
1523 kmem_cache_t *pc = list_entry(p, kmem_cache_t, next);
1524 mm_segment_t old_fs = get_fs();
1525 char tmp;
1526 int res;
1527
1528 /*
1529 * This happens when the module gets unloaded and doesn't
1530 * destroy its slab cache and no-one else reuses the vmalloc
1531 * area of the module. Print a warning.
1532 */
1533 set_fs(KERNEL_DS);
1534 res = __get_user(tmp, pc->name);
1535 set_fs(old_fs);
1536 if (res) {
1537 printk("SLAB: cache with size %d has lost its name\n",
1538 pc->objsize);
1539 continue;
1540 }
1541
1542 if (!strcmp(pc->name,name)) {
1543 printk("kmem_cache_create: duplicate cache %s\n", name);
1544 dump_stack();
1545 goto oops;
1546 }
1547 }
1548
1519#if DEBUG 1549#if DEBUG
1520 WARN_ON(strchr(name, ' ')); /* It confuses parsers */ 1550 WARN_ON(strchr(name, ' ')); /* It confuses parsers */
1521 if ((flags & SLAB_DEBUG_INITIAL) && !ctor) { 1551 if ((flags & SLAB_DEBUG_INITIAL) && !ctor) {
@@ -1592,7 +1622,7 @@ kmem_cache_create (const char *name, size_t size, size_t align,
1592 /* Get cache's description obj. */ 1622 /* Get cache's description obj. */
1593 cachep = (kmem_cache_t *) kmem_cache_alloc(&cache_cache, SLAB_KERNEL); 1623 cachep = (kmem_cache_t *) kmem_cache_alloc(&cache_cache, SLAB_KERNEL);
1594 if (!cachep) 1624 if (!cachep)
1595 goto opps; 1625 goto oops;
1596 memset(cachep, 0, sizeof(kmem_cache_t)); 1626 memset(cachep, 0, sizeof(kmem_cache_t));
1597 1627
1598#if DEBUG 1628#if DEBUG
@@ -1686,7 +1716,7 @@ next:
1686 printk("kmem_cache_create: couldn't create cache %s.\n", name); 1716 printk("kmem_cache_create: couldn't create cache %s.\n", name);
1687 kmem_cache_free(&cache_cache, cachep); 1717 kmem_cache_free(&cache_cache, cachep);
1688 cachep = NULL; 1718 cachep = NULL;
1689 goto opps; 1719 goto oops;
1690 } 1720 }
1691 slab_size = ALIGN(cachep->num*sizeof(kmem_bufctl_t) 1721 slab_size = ALIGN(cachep->num*sizeof(kmem_bufctl_t)
1692 + sizeof(struct slab), align); 1722 + sizeof(struct slab), align);
@@ -1781,43 +1811,14 @@ next:
1781 cachep->limit = BOOT_CPUCACHE_ENTRIES; 1811 cachep->limit = BOOT_CPUCACHE_ENTRIES;
1782 } 1812 }
1783 1813
1784 /* Need the semaphore to access the chain. */
1785 down(&cache_chain_sem);
1786 {
1787 struct list_head *p;
1788 mm_segment_t old_fs;
1789
1790 old_fs = get_fs();
1791 set_fs(KERNEL_DS);
1792 list_for_each(p, &cache_chain) {
1793 kmem_cache_t *pc = list_entry(p, kmem_cache_t, next);
1794 char tmp;
1795 /* This happens when the module gets unloaded and doesn't
1796 destroy its slab cache and noone else reuses the vmalloc
1797 area of the module. Print a warning. */
1798 if (__get_user(tmp,pc->name)) {
1799 printk("SLAB: cache with size %d has lost its name\n",
1800 pc->objsize);
1801 continue;
1802 }
1803 if (!strcmp(pc->name,name)) {
1804 printk("kmem_cache_create: duplicate cache %s\n",name);
1805 up(&cache_chain_sem);
1806 unlock_cpu_hotplug();
1807 BUG();
1808 }
1809 }
1810 set_fs(old_fs);
1811 }
1812
1813 /* cache setup completed, link it into the list */ 1814 /* cache setup completed, link it into the list */
1814 list_add(&cachep->next, &cache_chain); 1815 list_add(&cachep->next, &cache_chain);
1815 up(&cache_chain_sem);
1816 unlock_cpu_hotplug(); 1816 unlock_cpu_hotplug();
1817opps: 1817oops:
1818 if (!cachep && (flags & SLAB_PANIC)) 1818 if (!cachep && (flags & SLAB_PANIC))
1819 panic("kmem_cache_create(): failed to create slab `%s'\n", 1819 panic("kmem_cache_create(): failed to create slab `%s'\n",
1820 name); 1820 name);
1821 up(&cache_chain_sem);
1821 return cachep; 1822 return cachep;
1822} 1823}
1823EXPORT_SYMBOL(kmem_cache_create); 1824EXPORT_SYMBOL(kmem_cache_create);
@@ -3262,6 +3263,7 @@ static void drain_array_locked(kmem_cache_t *cachep,
3262 3263
3263/** 3264/**
3264 * cache_reap - Reclaim memory from caches. 3265 * cache_reap - Reclaim memory from caches.
3266 * @unused: unused parameter
3265 * 3267 *
3266 * Called from workqueue/eventd every few seconds. 3268 * Called from workqueue/eventd every few seconds.
3267 * Purpose: 3269 * Purpose:
@@ -3278,7 +3280,7 @@ static void cache_reap(void *unused)
3278 3280
3279 if (down_trylock(&cache_chain_sem)) { 3281 if (down_trylock(&cache_chain_sem)) {
3280 /* Give up. Setup the next iteration. */ 3282 /* Give up. Setup the next iteration. */
3281 schedule_delayed_work(&__get_cpu_var(reap_work), REAPTIMEOUT_CPUC + smp_processor_id()); 3283 schedule_delayed_work(&__get_cpu_var(reap_work), REAPTIMEOUT_CPUC);
3282 return; 3284 return;
3283 } 3285 }
3284 3286
@@ -3347,7 +3349,7 @@ next:
3347 up(&cache_chain_sem); 3349 up(&cache_chain_sem);
3348 drain_remote_pages(); 3350 drain_remote_pages();
3349 /* Setup the next iteration */ 3351 /* Setup the next iteration */
3350 schedule_delayed_work(&__get_cpu_var(reap_work), REAPTIMEOUT_CPUC + smp_processor_id()); 3352 schedule_delayed_work(&__get_cpu_var(reap_work), REAPTIMEOUT_CPUC);
3351} 3353}
3352 3354
3353#ifdef CONFIG_PROC_FS 3355#ifdef CONFIG_PROC_FS
diff --git a/mm/swap.c b/mm/swap.c
index 154ae13d8b7e..d09cf7f03e76 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -413,7 +413,6 @@ void vm_acct_memory(long pages)
413 } 413 }
414 preempt_enable(); 414 preempt_enable();
415} 415}
416EXPORT_SYMBOL(vm_acct_memory);
417 416
418#ifdef CONFIG_HOTPLUG_CPU 417#ifdef CONFIG_HOTPLUG_CPU
419static void lru_drain_cache(unsigned int cpu) 418static void lru_drain_cache(unsigned int cpu)
diff --git a/mm/swap_state.c b/mm/swap_state.c
index dfd9a46755b8..0df9a57b1de8 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -40,7 +40,6 @@ struct address_space swapper_space = {
40 .i_mmap_nonlinear = LIST_HEAD_INIT(swapper_space.i_mmap_nonlinear), 40 .i_mmap_nonlinear = LIST_HEAD_INIT(swapper_space.i_mmap_nonlinear),
41 .backing_dev_info = &swap_backing_dev_info, 41 .backing_dev_info = &swap_backing_dev_info,
42}; 42};
43EXPORT_SYMBOL(swapper_space);
44 43
45#define INC_CACHE_INFO(x) do { swap_cache_info.x++; } while (0) 44#define INC_CACHE_INFO(x) do { swap_cache_info.x++; } while (0)
46 45
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 8970c0b74194..edafeace301f 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -36,8 +36,6 @@ unsigned int nr_swapfiles;
36long total_swap_pages; 36long total_swap_pages;
37static int swap_overflow; 37static int swap_overflow;
38 38
39EXPORT_SYMBOL(total_swap_pages);
40
41static const char Bad_file[] = "Bad swap file entry "; 39static const char Bad_file[] = "Bad swap file entry ";
42static const char Unused_file[] = "Unused swap file entry "; 40static const char Unused_file[] = "Unused swap file entry ";
43static const char Bad_offset[] = "Bad swap offset entry "; 41static const char Bad_offset[] = "Bad swap offset entry ";
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 54a90e83cb31..729eb3eec75f 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -457,7 +457,7 @@ void *__vmalloc_area(struct vm_struct *area, gfp_t gfp_mask, pgprot_t prot)
457 * @size: allocation size 457 * @size: allocation size
458 * @gfp_mask: flags for the page level allocator 458 * @gfp_mask: flags for the page level allocator
459 * @prot: protection mask for the allocated pages 459 * @prot: protection mask for the allocated pages
460 * @node node to use for allocation or -1 460 * @node: node to use for allocation or -1
461 * 461 *
462 * Allocate enough pages to cover @size from the page level 462 * Allocate enough pages to cover @size from the page level
463 * allocator with @gfp_mask flags. Map them into contiguous 463 * allocator with @gfp_mask flags. Map them into contiguous
@@ -507,7 +507,7 @@ EXPORT_SYMBOL(vmalloc);
507 * vmalloc_node - allocate memory on a specific node 507 * vmalloc_node - allocate memory on a specific node
508 * 508 *
509 * @size: allocation size 509 * @size: allocation size
510 * @node; numa node 510 * @node: numa node
511 * 511 *
512 * Allocate enough pages to cover @size from the page level 512 * Allocate enough pages to cover @size from the page level
513 * allocator and map them into contiguous kernel virtual space. 513 * allocator and map them into contiguous kernel virtual space.
diff --git a/net/core/stream.c b/net/core/stream.c
index ac9edfdf8742..15bfd03e8024 100644
--- a/net/core/stream.c
+++ b/net/core/stream.c
@@ -52,8 +52,9 @@ int sk_stream_wait_connect(struct sock *sk, long *timeo_p)
52{ 52{
53 struct task_struct *tsk = current; 53 struct task_struct *tsk = current;
54 DEFINE_WAIT(wait); 54 DEFINE_WAIT(wait);
55 int done;
55 56
56 while (1) { 57 do {
57 if (sk->sk_err) 58 if (sk->sk_err)
58 return sock_error(sk); 59 return sock_error(sk);
59 if ((1 << sk->sk_state) & ~(TCPF_SYN_SENT | TCPF_SYN_RECV)) 60 if ((1 << sk->sk_state) & ~(TCPF_SYN_SENT | TCPF_SYN_RECV))
@@ -65,13 +66,12 @@ int sk_stream_wait_connect(struct sock *sk, long *timeo_p)
65 66
66 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); 67 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
67 sk->sk_write_pending++; 68 sk->sk_write_pending++;
68 if (sk_wait_event(sk, timeo_p, 69 done = sk_wait_event(sk, timeo_p,
69 !((1 << sk->sk_state) & 70 !((1 << sk->sk_state) &
70 ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)))) 71 ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)));
71 break;
72 finish_wait(sk->sk_sleep, &wait); 72 finish_wait(sk->sk_sleep, &wait);
73 sk->sk_write_pending--; 73 sk->sk_write_pending--;
74 } 74 } while (!done);
75 return 0; 75 return 0;
76} 76}
77 77
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 6298cf58ff9e..4b9bc81ae1a3 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -31,8 +31,6 @@ struct inet_hashinfo __cacheline_aligned dccp_hashinfo = {
31 .lhash_lock = RW_LOCK_UNLOCKED, 31 .lhash_lock = RW_LOCK_UNLOCKED,
32 .lhash_users = ATOMIC_INIT(0), 32 .lhash_users = ATOMIC_INIT(0),
33 .lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER(dccp_hashinfo.lhash_wait), 33 .lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER(dccp_hashinfo.lhash_wait),
34 .portalloc_lock = SPIN_LOCK_UNLOCKED,
35 .port_rover = 1024 - 1,
36}; 34};
37 35
38EXPORT_SYMBOL_GPL(dccp_hashinfo); 36EXPORT_SYMBOL_GPL(dccp_hashinfo);
@@ -125,36 +123,15 @@ static int dccp_v4_hash_connect(struct sock *sk)
125 int ret; 123 int ret;
126 124
127 if (snum == 0) { 125 if (snum == 0) {
128 int rover;
129 int low = sysctl_local_port_range[0]; 126 int low = sysctl_local_port_range[0];
130 int high = sysctl_local_port_range[1]; 127 int high = sysctl_local_port_range[1];
131 int remaining = (high - low) + 1; 128 int remaining = (high - low) + 1;
129 int rover = net_random() % (high - low) + low;
132 struct hlist_node *node; 130 struct hlist_node *node;
133 struct inet_timewait_sock *tw = NULL; 131 struct inet_timewait_sock *tw = NULL;
134 132
135 local_bh_disable(); 133 local_bh_disable();
136
137 /* TODO. Actually it is not so bad idea to remove
138 * dccp_hashinfo.portalloc_lock before next submission to
139 * Linus.
140 * As soon as we touch this place at all it is time to think.
141 *
142 * Now it protects single _advisory_ variable
143 * dccp_hashinfo.port_rover, hence it is mostly useless.
144 * Code will work nicely if we just delete it, but
145 * I am afraid in contented case it will work not better or
146 * even worse: another cpu just will hit the same bucket
147 * and spin there.
148 * So some cpu salt could remove both contention and
149 * memory pingpong. Any ideas how to do this in a nice way?
150 */
151 spin_lock(&dccp_hashinfo.portalloc_lock);
152 rover = dccp_hashinfo.port_rover;
153
154 do { 134 do {
155 rover++;
156 if ((rover < low) || (rover > high))
157 rover = low;
158 head = &dccp_hashinfo.bhash[inet_bhashfn(rover, 135 head = &dccp_hashinfo.bhash[inet_bhashfn(rover,
159 dccp_hashinfo.bhash_size)]; 136 dccp_hashinfo.bhash_size)];
160 spin_lock(&head->lock); 137 spin_lock(&head->lock);
@@ -187,9 +164,9 @@ static int dccp_v4_hash_connect(struct sock *sk)
187 164
188 next_port: 165 next_port:
189 spin_unlock(&head->lock); 166 spin_unlock(&head->lock);
167 if (++rover > high)
168 rover = low;
190 } while (--remaining > 0); 169 } while (--remaining > 0);
191 dccp_hashinfo.port_rover = rover;
192 spin_unlock(&dccp_hashinfo.portalloc_lock);
193 170
194 local_bh_enable(); 171 local_bh_enable();
195 172
@@ -197,9 +174,6 @@ static int dccp_v4_hash_connect(struct sock *sk)
197 174
198ok: 175ok:
199 /* All locks still held and bhs disabled */ 176 /* All locks still held and bhs disabled */
200 dccp_hashinfo.port_rover = rover;
201 spin_unlock(&dccp_hashinfo.portalloc_lock);
202
203 inet_bind_hash(sk, tb, rover); 177 inet_bind_hash(sk, tb, rover);
204 if (sk_unhashed(sk)) { 178 if (sk_unhashed(sk)) {
205 inet_sk(sk)->sport = htons(rover); 179 inet_sk(sk)->sport = htons(rover);
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 94468a76c5b4..3fe021f1a566 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -78,17 +78,9 @@ int inet_csk_get_port(struct inet_hashinfo *hashinfo,
78 int low = sysctl_local_port_range[0]; 78 int low = sysctl_local_port_range[0];
79 int high = sysctl_local_port_range[1]; 79 int high = sysctl_local_port_range[1];
80 int remaining = (high - low) + 1; 80 int remaining = (high - low) + 1;
81 int rover; 81 int rover = net_random() % (high - low) + low;
82 82
83 spin_lock(&hashinfo->portalloc_lock);
84 if (hashinfo->port_rover < low)
85 rover = low;
86 else
87 rover = hashinfo->port_rover;
88 do { 83 do {
89 rover++;
90 if (rover > high)
91 rover = low;
92 head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)]; 84 head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
93 spin_lock(&head->lock); 85 spin_lock(&head->lock);
94 inet_bind_bucket_for_each(tb, node, &head->chain) 86 inet_bind_bucket_for_each(tb, node, &head->chain)
@@ -97,9 +89,9 @@ int inet_csk_get_port(struct inet_hashinfo *hashinfo,
97 break; 89 break;
98 next: 90 next:
99 spin_unlock(&head->lock); 91 spin_unlock(&head->lock);
92 if (++rover > high)
93 rover = low;
100 } while (--remaining > 0); 94 } while (--remaining > 0);
101 hashinfo->port_rover = rover;
102 spin_unlock(&hashinfo->portalloc_lock);
103 95
104 /* Exhausted local port range during search? It is not 96 /* Exhausted local port range during search? It is not
105 * possible for us to be holding one of the bind hash 97 * possible for us to be holding one of the bind hash
diff --git a/net/ipv4/netfilter/ip_conntrack_helper_pptp.c b/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
index 926a6684643d..4108a5e12b3c 100644
--- a/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
+++ b/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
@@ -270,14 +270,10 @@ exp_gre(struct ip_conntrack *master,
270 exp_orig->expectfn = pptp_expectfn; 270 exp_orig->expectfn = pptp_expectfn;
271 exp_orig->flags = 0; 271 exp_orig->flags = 0;
272 272
273 exp_orig->dir = IP_CT_DIR_ORIGINAL;
274
275 /* both expectations are identical apart from tuple */ 273 /* both expectations are identical apart from tuple */
276 memcpy(exp_reply, exp_orig, sizeof(*exp_reply)); 274 memcpy(exp_reply, exp_orig, sizeof(*exp_reply));
277 memcpy(&exp_reply->tuple, &exp_tuples[1], sizeof(exp_reply->tuple)); 275 memcpy(&exp_reply->tuple, &exp_tuples[1], sizeof(exp_reply->tuple));
278 276
279 exp_reply->dir = !exp_orig->dir;
280
281 if (ip_nat_pptp_hook_exp_gre) 277 if (ip_nat_pptp_hook_exp_gre)
282 ret = ip_nat_pptp_hook_exp_gre(exp_orig, exp_reply); 278 ret = ip_nat_pptp_hook_exp_gre(exp_orig, exp_reply);
283 else { 279 else {
diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c
index 166e6069f121..82a65043a8ef 100644
--- a/net/ipv4/netfilter/ip_conntrack_netlink.c
+++ b/net/ipv4/netfilter/ip_conntrack_netlink.c
@@ -815,7 +815,7 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
815 IPCTNL_MSG_CT_NEW, 1, ct); 815 IPCTNL_MSG_CT_NEW, 1, ct);
816 ip_conntrack_put(ct); 816 ip_conntrack_put(ct);
817 if (err <= 0) 817 if (err <= 0)
818 goto out; 818 goto free;
819 819
820 err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT); 820 err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
821 if (err < 0) 821 if (err < 0)
@@ -824,9 +824,9 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
824 DEBUGP("leaving\n"); 824 DEBUGP("leaving\n");
825 return 0; 825 return 0;
826 826
827free:
828 kfree_skb(skb2);
827out: 829out:
828 if (skb2)
829 kfree_skb(skb2);
830 return -1; 830 return -1;
831} 831}
832 832
@@ -1322,21 +1322,16 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1322 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW, 1322 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW,
1323 1, exp); 1323 1, exp);
1324 if (err <= 0) 1324 if (err <= 0)
1325 goto out; 1325 goto free;
1326 1326
1327 ip_conntrack_expect_put(exp); 1327 ip_conntrack_expect_put(exp);
1328 1328
1329 err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT); 1329 return netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
1330 if (err < 0)
1331 goto free;
1332
1333 return err;
1334 1330
1331free:
1332 kfree_skb(skb2);
1335out: 1333out:
1336 ip_conntrack_expect_put(exp); 1334 ip_conntrack_expect_put(exp);
1337free:
1338 if (skb2)
1339 kfree_skb(skb2);
1340 return err; 1335 return err;
1341} 1336}
1342 1337
diff --git a/net/ipv4/netfilter/ip_nat_core.c b/net/ipv4/netfilter/ip_nat_core.c
index c5e3abd24672..762f4d93936b 100644
--- a/net/ipv4/netfilter/ip_nat_core.c
+++ b/net/ipv4/netfilter/ip_nat_core.c
@@ -66,10 +66,8 @@ ip_nat_proto_find_get(u_int8_t protonum)
66 * removed until we've grabbed the reference */ 66 * removed until we've grabbed the reference */
67 preempt_disable(); 67 preempt_disable();
68 p = __ip_nat_proto_find(protonum); 68 p = __ip_nat_proto_find(protonum);
69 if (p) { 69 if (!try_module_get(p->me))
70 if (!try_module_get(p->me)) 70 p = &ip_nat_unknown_protocol;
71 p = &ip_nat_unknown_protocol;
72 }
73 preempt_enable(); 71 preempt_enable();
74 72
75 return p; 73 return p;
diff --git a/net/ipv4/netfilter/ip_nat_helper_pptp.c b/net/ipv4/netfilter/ip_nat_helper_pptp.c
index 3cdd0684d30d..ee6ab74ad3a9 100644
--- a/net/ipv4/netfilter/ip_nat_helper_pptp.c
+++ b/net/ipv4/netfilter/ip_nat_helper_pptp.c
@@ -216,6 +216,7 @@ pptp_exp_gre(struct ip_conntrack_expect *expect_orig,
216 expect_orig->saved_proto.gre.key = htons(nat_pptp_info->pac_call_id); 216 expect_orig->saved_proto.gre.key = htons(nat_pptp_info->pac_call_id);
217 expect_orig->tuple.src.u.gre.key = htons(nat_pptp_info->pns_call_id); 217 expect_orig->tuple.src.u.gre.key = htons(nat_pptp_info->pns_call_id);
218 expect_orig->tuple.dst.u.gre.key = htons(ct_pptp_info->pac_call_id); 218 expect_orig->tuple.dst.u.gre.key = htons(ct_pptp_info->pac_call_id);
219 expect_orig->dir = IP_CT_DIR_ORIGINAL;
219 inv_t.src.ip = reply_t->src.ip; 220 inv_t.src.ip = reply_t->src.ip;
220 inv_t.dst.ip = reply_t->dst.ip; 221 inv_t.dst.ip = reply_t->dst.ip;
221 inv_t.src.u.gre.key = htons(nat_pptp_info->pac_call_id); 222 inv_t.src.u.gre.key = htons(nat_pptp_info->pac_call_id);
@@ -233,6 +234,7 @@ pptp_exp_gre(struct ip_conntrack_expect *expect_orig,
233 expect_reply->saved_proto.gre.key = htons(nat_pptp_info->pns_call_id); 234 expect_reply->saved_proto.gre.key = htons(nat_pptp_info->pns_call_id);
234 expect_reply->tuple.src.u.gre.key = htons(nat_pptp_info->pac_call_id); 235 expect_reply->tuple.src.u.gre.key = htons(nat_pptp_info->pac_call_id);
235 expect_reply->tuple.dst.u.gre.key = htons(ct_pptp_info->pns_call_id); 236 expect_reply->tuple.dst.u.gre.key = htons(ct_pptp_info->pns_call_id);
237 expect_reply->dir = IP_CT_DIR_REPLY;
236 inv_t.src.ip = orig_t->src.ip; 238 inv_t.src.ip = orig_t->src.ip;
237 inv_t.dst.ip = orig_t->dst.ip; 239 inv_t.dst.ip = orig_t->dst.ip;
238 inv_t.src.u.gre.key = htons(nat_pptp_info->pns_call_id); 240 inv_t.src.u.gre.key = htons(nat_pptp_info->pns_call_id);
diff --git a/net/ipv4/netfilter/ip_nat_proto_gre.c b/net/ipv4/netfilter/ip_nat_proto_gre.c
index 7c1285401672..f7cad7cf1aec 100644
--- a/net/ipv4/netfilter/ip_nat_proto_gre.c
+++ b/net/ipv4/netfilter/ip_nat_proto_gre.c
@@ -139,8 +139,8 @@ gre_manip_pkt(struct sk_buff **pskb,
139 break; 139 break;
140 case GRE_VERSION_PPTP: 140 case GRE_VERSION_PPTP:
141 DEBUGP("call_id -> 0x%04x\n", 141 DEBUGP("call_id -> 0x%04x\n",
142 ntohl(tuple->dst.u.gre.key)); 142 ntohs(tuple->dst.u.gre.key));
143 pgreh->call_id = htons(ntohl(tuple->dst.u.gre.key)); 143 pgreh->call_id = tuple->dst.u.gre.key;
144 break; 144 break;
145 default: 145 default:
146 DEBUGP("can't nat unknown GRE version\n"); 146 DEBUGP("can't nat unknown GRE version\n");
diff --git a/net/ipv4/netfilter/ip_nat_proto_unknown.c b/net/ipv4/netfilter/ip_nat_proto_unknown.c
index 99bbef56f84e..f0099a646a0b 100644
--- a/net/ipv4/netfilter/ip_nat_proto_unknown.c
+++ b/net/ipv4/netfilter/ip_nat_proto_unknown.c
@@ -62,7 +62,7 @@ unknown_print_range(char *buffer, const struct ip_nat_range *range)
62 62
63struct ip_nat_protocol ip_nat_unknown_protocol = { 63struct ip_nat_protocol ip_nat_unknown_protocol = {
64 .name = "unknown", 64 .name = "unknown",
65 .me = THIS_MODULE, 65 /* .me isn't set: getting a ref to this cannot fail. */
66 .manip_pkt = unknown_manip_pkt, 66 .manip_pkt = unknown_manip_pkt,
67 .in_range = unknown_in_range, 67 .in_range = unknown_in_range,
68 .unique_tuple = unknown_unique_tuple, 68 .unique_tuple = unknown_unique_tuple,
diff --git a/net/ipv4/netfilter/ipt_CONNMARK.c b/net/ipv4/netfilter/ipt_CONNMARK.c
index 134638021339..05d66ab59424 100644
--- a/net/ipv4/netfilter/ipt_CONNMARK.c
+++ b/net/ipv4/netfilter/ipt_CONNMARK.c
@@ -109,6 +109,7 @@ static struct ipt_target ipt_connmark_reg = {
109 109
110static int __init init(void) 110static int __init init(void)
111{ 111{
112 need_ip_conntrack();
112 return ipt_register_target(&ipt_connmark_reg); 113 return ipt_register_target(&ipt_connmark_reg);
113} 114}
114 115
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index f3f0013a9580..72b7c22e1ea5 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2112,7 +2112,6 @@ void __init tcp_init(void)
2112 sysctl_tcp_max_orphans >>= (3 - order); 2112 sysctl_tcp_max_orphans >>= (3 - order);
2113 sysctl_max_syn_backlog = 128; 2113 sysctl_max_syn_backlog = 128;
2114 } 2114 }
2115 tcp_hashinfo.port_rover = sysctl_local_port_range[0] - 1;
2116 2115
2117 sysctl_tcp_mem[0] = 768 << order; 2116 sysctl_tcp_mem[0] = 768 << order;
2118 sysctl_tcp_mem[1] = 1024 << order; 2117 sysctl_tcp_mem[1] = 1024 << order;
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index c85819d8474b..49d67cd75edd 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -93,8 +93,6 @@ struct inet_hashinfo __cacheline_aligned tcp_hashinfo = {
93 .lhash_lock = RW_LOCK_UNLOCKED, 93 .lhash_lock = RW_LOCK_UNLOCKED,
94 .lhash_users = ATOMIC_INIT(0), 94 .lhash_users = ATOMIC_INIT(0),
95 .lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER(tcp_hashinfo.lhash_wait), 95 .lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER(tcp_hashinfo.lhash_wait),
96 .portalloc_lock = SPIN_LOCK_UNLOCKED,
97 .port_rover = 1024 - 1,
98}; 96};
99 97
100static int tcp_v4_get_port(struct sock *sk, unsigned short snum) 98static int tcp_v4_get_port(struct sock *sk, unsigned short snum)
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index d693cb988b78..d746d3b27efb 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -114,16 +114,9 @@ static int tcp_v6_get_port(struct sock *sk, unsigned short snum)
114 int low = sysctl_local_port_range[0]; 114 int low = sysctl_local_port_range[0];
115 int high = sysctl_local_port_range[1]; 115 int high = sysctl_local_port_range[1];
116 int remaining = (high - low) + 1; 116 int remaining = (high - low) + 1;
117 int rover; 117 int rover = net_random() % (high - low) + low;
118 118
119 spin_lock(&tcp_hashinfo.portalloc_lock); 119 do {
120 if (tcp_hashinfo.port_rover < low)
121 rover = low;
122 else
123 rover = tcp_hashinfo.port_rover;
124 do { rover++;
125 if (rover > high)
126 rover = low;
127 head = &tcp_hashinfo.bhash[inet_bhashfn(rover, tcp_hashinfo.bhash_size)]; 120 head = &tcp_hashinfo.bhash[inet_bhashfn(rover, tcp_hashinfo.bhash_size)];
128 spin_lock(&head->lock); 121 spin_lock(&head->lock);
129 inet_bind_bucket_for_each(tb, node, &head->chain) 122 inet_bind_bucket_for_each(tb, node, &head->chain)
@@ -132,9 +125,9 @@ static int tcp_v6_get_port(struct sock *sk, unsigned short snum)
132 break; 125 break;
133 next: 126 next:
134 spin_unlock(&head->lock); 127 spin_unlock(&head->lock);
128 if (++rover > high)
129 rover = low;
135 } while (--remaining > 0); 130 } while (--remaining > 0);
136 tcp_hashinfo.port_rover = rover;
137 spin_unlock(&tcp_hashinfo.portalloc_lock);
138 131
139 /* Exhausted local port range during search? It is not 132 /* Exhausted local port range during search? It is not
140 * possible for us to be holding one of the bind hash 133 * possible for us to be holding one of the bind hash
diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c
index d10d552d9c40..d3a4f30a7f22 100644
--- a/net/netfilter/nf_queue.c
+++ b/net/netfilter/nf_queue.c
@@ -117,7 +117,7 @@ int nf_queue(struct sk_buff **skb,
117 117
118 /* QUEUE == DROP if noone is waiting, to be safe. */ 118 /* QUEUE == DROP if noone is waiting, to be safe. */
119 read_lock(&queue_handler_lock); 119 read_lock(&queue_handler_lock);
120 if (!queue_handler[pf]->outfn) { 120 if (!queue_handler[pf] || !queue_handler[pf]->outfn) {
121 read_unlock(&queue_handler_lock); 121 read_unlock(&queue_handler_lock);
122 kfree_skb(*skb); 122 kfree_skb(*skb);
123 return 1; 123 return 1;
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index efcd10f996ba..d194676f3655 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -146,11 +146,10 @@ instance_create(u_int16_t group_num, int pid)
146 goto out_unlock; 146 goto out_unlock;
147 } 147 }
148 148
149 inst = kmalloc(sizeof(*inst), GFP_ATOMIC); 149 inst = kzalloc(sizeof(*inst), GFP_ATOMIC);
150 if (!inst) 150 if (!inst)
151 goto out_unlock; 151 goto out_unlock;
152 152
153 memset(inst, 0, sizeof(*inst));
154 INIT_HLIST_NODE(&inst->hlist); 153 INIT_HLIST_NODE(&inst->hlist);
155 inst->lock = SPIN_LOCK_UNLOCKED; 154 inst->lock = SPIN_LOCK_UNLOCKED;
156 /* needs to be two, since we _put() after creation */ 155 /* needs to be two, since we _put() after creation */
@@ -962,10 +961,9 @@ static int nful_open(struct inode *inode, struct file *file)
962 struct iter_state *is; 961 struct iter_state *is;
963 int ret; 962 int ret;
964 963
965 is = kmalloc(sizeof(*is), GFP_KERNEL); 964 is = kzalloc(sizeof(*is), GFP_KERNEL);
966 if (!is) 965 if (!is)
967 return -ENOMEM; 966 return -ENOMEM;
968 memset(is, 0, sizeof(*is));
969 ret = seq_open(file, &nful_seq_ops); 967 ret = seq_open(file, &nful_seq_ops);
970 if (ret < 0) 968 if (ret < 0)
971 goto out_free; 969 goto out_free;
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index eaa44c49567b..f065a6c94953 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -136,11 +136,10 @@ instance_create(u_int16_t queue_num, int pid)
136 goto out_unlock; 136 goto out_unlock;
137 } 137 }
138 138
139 inst = kmalloc(sizeof(*inst), GFP_ATOMIC); 139 inst = kzalloc(sizeof(*inst), GFP_ATOMIC);
140 if (!inst) 140 if (!inst)
141 goto out_unlock; 141 goto out_unlock;
142 142
143 memset(inst, 0, sizeof(*inst));
144 inst->queue_num = queue_num; 143 inst->queue_num = queue_num;
145 inst->peer_pid = pid; 144 inst->peer_pid = pid;
146 inst->queue_maxlen = NFQNL_QMAX_DEFAULT; 145 inst->queue_maxlen = NFQNL_QMAX_DEFAULT;
@@ -1036,10 +1035,9 @@ static int nfqnl_open(struct inode *inode, struct file *file)
1036 struct iter_state *is; 1035 struct iter_state *is;
1037 int ret; 1036 int ret;
1038 1037
1039 is = kmalloc(sizeof(*is), GFP_KERNEL); 1038 is = kzalloc(sizeof(*is), GFP_KERNEL);
1040 if (!is) 1039 if (!is)
1041 return -ENOMEM; 1040 return -ENOMEM;
1042 memset(is, 0, sizeof(*is));
1043 ret = seq_open(file, &nfqnl_seq_ops); 1041 ret = seq_open(file, &nfqnl_seq_ops);
1044 if (ret < 0) 1042 if (ret < 0)
1045 goto out_free; 1043 goto out_free;
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index 25c171c32715..29a2dd9f3029 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -15,247 +15,281 @@
15 * from Ren Liu 15 * from Ren Liu
16 * - More error checks 16 * - More error checks
17 * 17 *
18 * 18 * For all the glorious comments look at include/net/red.h
19 *
20 * For all the glorious comments look at Alexey's sch_red.c
21 */ 19 */
22 20
23#include <linux/config.h> 21#include <linux/config.h>
24#include <linux/module.h> 22#include <linux/module.h>
25#include <asm/uaccess.h>
26#include <asm/system.h>
27#include <linux/bitops.h>
28#include <linux/types.h> 23#include <linux/types.h>
29#include <linux/kernel.h> 24#include <linux/kernel.h>
30#include <linux/sched.h>
31#include <linux/string.h>
32#include <linux/mm.h>
33#include <linux/socket.h>
34#include <linux/sockios.h>
35#include <linux/in.h>
36#include <linux/errno.h>
37#include <linux/interrupt.h>
38#include <linux/if_ether.h>
39#include <linux/inet.h>
40#include <linux/netdevice.h> 25#include <linux/netdevice.h>
41#include <linux/etherdevice.h>
42#include <linux/notifier.h>
43#include <net/ip.h>
44#include <net/route.h>
45#include <linux/skbuff.h> 26#include <linux/skbuff.h>
46#include <net/sock.h>
47#include <net/pkt_sched.h> 27#include <net/pkt_sched.h>
28#include <net/red.h>
48 29
49#if 1 /* control */ 30#define GRED_DEF_PRIO (MAX_DPs / 2)
50#define DPRINTK(format,args...) printk(KERN_DEBUG format,##args) 31#define GRED_VQ_MASK (MAX_DPs - 1)
51#else
52#define DPRINTK(format,args...)
53#endif
54
55#if 0 /* data */
56#define D2PRINTK(format,args...) printk(KERN_DEBUG format,##args)
57#else
58#define D2PRINTK(format,args...)
59#endif
60 32
61struct gred_sched_data; 33struct gred_sched_data;
62struct gred_sched; 34struct gred_sched;
63 35
64struct gred_sched_data 36struct gred_sched_data
65{ 37{
66/* Parameters */
67 u32 limit; /* HARD maximal queue length */ 38 u32 limit; /* HARD maximal queue length */
68 u32 qth_min; /* Min average length threshold: A scaled */
69 u32 qth_max; /* Max average length threshold: A scaled */
70 u32 DP; /* the drop pramaters */ 39 u32 DP; /* the drop pramaters */
71 char Wlog; /* log(W) */
72 char Plog; /* random number bits */
73 u32 Scell_max;
74 u32 Rmask;
75 u32 bytesin; /* bytes seen on virtualQ so far*/ 40 u32 bytesin; /* bytes seen on virtualQ so far*/
76 u32 packetsin; /* packets seen on virtualQ so far*/ 41 u32 packetsin; /* packets seen on virtualQ so far*/
77 u32 backlog; /* bytes on the virtualQ */ 42 u32 backlog; /* bytes on the virtualQ */
78 u32 forced; /* packets dropped for exceeding limits */ 43 u8 prio; /* the prio of this vq */
79 u32 early; /* packets dropped as a warning */ 44
80 u32 other; /* packets dropped by invoking drop() */ 45 struct red_parms parms;
81 u32 pdrop; /* packets dropped because we exceeded physical queue limits */ 46 struct red_stats stats;
82 char Scell_log; 47};
83 u8 Stab[256]; 48
84 u8 prio; /* the prio of this vq */ 49enum {
85 50 GRED_WRED_MODE = 1,
86/* Variables */ 51 GRED_RIO_MODE,
87 unsigned long qave; /* Average queue length: A scaled */
88 int qcount; /* Packets since last random number generation */
89 u32 qR; /* Cached random number */
90
91 psched_time_t qidlestart; /* Start of idle period */
92}; 52};
93 53
94struct gred_sched 54struct gred_sched
95{ 55{
96 struct gred_sched_data *tab[MAX_DPs]; 56 struct gred_sched_data *tab[MAX_DPs];
97 u32 DPs; 57 unsigned long flags;
98 u32 def; 58 u32 red_flags;
99 u8 initd; 59 u32 DPs;
100 u8 grio; 60 u32 def;
101 u8 eqp; 61 struct red_parms wred_set;
102}; 62};
103 63
104static int 64static inline int gred_wred_mode(struct gred_sched *table)
105gred_enqueue(struct sk_buff *skb, struct Qdisc* sch)
106{ 65{
107 psched_time_t now; 66 return test_bit(GRED_WRED_MODE, &table->flags);
108 struct gred_sched_data *q=NULL; 67}
109 struct gred_sched *t= qdisc_priv(sch); 68
110 unsigned long qave=0; 69static inline void gred_enable_wred_mode(struct gred_sched *table)
111 int i=0; 70{
71 __set_bit(GRED_WRED_MODE, &table->flags);
72}
73
74static inline void gred_disable_wred_mode(struct gred_sched *table)
75{
76 __clear_bit(GRED_WRED_MODE, &table->flags);
77}
78
79static inline int gred_rio_mode(struct gred_sched *table)
80{
81 return test_bit(GRED_RIO_MODE, &table->flags);
82}
83
84static inline void gred_enable_rio_mode(struct gred_sched *table)
85{
86 __set_bit(GRED_RIO_MODE, &table->flags);
87}
88
89static inline void gred_disable_rio_mode(struct gred_sched *table)
90{
91 __clear_bit(GRED_RIO_MODE, &table->flags);
92}
93
94static inline int gred_wred_mode_check(struct Qdisc *sch)
95{
96 struct gred_sched *table = qdisc_priv(sch);
97 int i;
112 98
113 if (!t->initd && skb_queue_len(&sch->q) < (sch->dev->tx_queue_len ? : 1)) { 99 /* Really ugly O(n^2) but shouldn't be necessary too frequent. */
114 D2PRINTK("NO GRED Queues setup yet! Enqueued anyway\n"); 100 for (i = 0; i < table->DPs; i++) {
115 goto do_enqueue; 101 struct gred_sched_data *q = table->tab[i];
102 int n;
103
104 if (q == NULL)
105 continue;
106
107 for (n = 0; n < table->DPs; n++)
108 if (table->tab[n] && table->tab[n] != q &&
109 table->tab[n]->prio == q->prio)
110 return 1;
116 } 111 }
117 112
113 return 0;
114}
115
116static inline unsigned int gred_backlog(struct gred_sched *table,
117 struct gred_sched_data *q,
118 struct Qdisc *sch)
119{
120 if (gred_wred_mode(table))
121 return sch->qstats.backlog;
122 else
123 return q->backlog;
124}
125
126static inline u16 tc_index_to_dp(struct sk_buff *skb)
127{
128 return skb->tc_index & GRED_VQ_MASK;
129}
130
131static inline void gred_load_wred_set(struct gred_sched *table,
132 struct gred_sched_data *q)
133{
134 q->parms.qavg = table->wred_set.qavg;
135 q->parms.qidlestart = table->wred_set.qidlestart;
136}
137
138static inline void gred_store_wred_set(struct gred_sched *table,
139 struct gred_sched_data *q)
140{
141 table->wred_set.qavg = q->parms.qavg;
142}
143
144static inline int gred_use_ecn(struct gred_sched *t)
145{
146 return t->red_flags & TC_RED_ECN;
147}
118 148
119 if ( ((skb->tc_index&0xf) > (t->DPs -1)) || !(q=t->tab[skb->tc_index&0xf])) { 149static inline int gred_use_harddrop(struct gred_sched *t)
120 printk("GRED: setting to default (%d)\n ",t->def); 150{
121 if (!(q=t->tab[t->def])) { 151 return t->red_flags & TC_RED_HARDDROP;
122 DPRINTK("GRED: setting to default FAILED! dropping!! " 152}
123 "(%d)\n ", t->def); 153
124 goto drop; 154static int gred_enqueue(struct sk_buff *skb, struct Qdisc* sch)
155{
156 struct gred_sched_data *q=NULL;
157 struct gred_sched *t= qdisc_priv(sch);
158 unsigned long qavg = 0;
159 u16 dp = tc_index_to_dp(skb);
160
161 if (dp >= t->DPs || (q = t->tab[dp]) == NULL) {
162 dp = t->def;
163
164 if ((q = t->tab[dp]) == NULL) {
165 /* Pass through packets not assigned to a DP
166 * if no default DP has been configured. This
167 * allows for DP flows to be left untouched.
168 */
169 if (skb_queue_len(&sch->q) < sch->dev->tx_queue_len)
170 return qdisc_enqueue_tail(skb, sch);
171 else
172 goto drop;
125 } 173 }
174
126 /* fix tc_index? --could be controvesial but needed for 175 /* fix tc_index? --could be controvesial but needed for
127 requeueing */ 176 requeueing */
128 skb->tc_index=(skb->tc_index&0xfffffff0) | t->def; 177 skb->tc_index = (skb->tc_index & ~GRED_VQ_MASK) | dp;
129 } 178 }
130 179
131 D2PRINTK("gred_enqueue virtualQ 0x%x classid %x backlog %d " 180 /* sum up all the qaves of prios <= to ours to get the new qave */
132 "general backlog %d\n",skb->tc_index&0xf,sch->handle,q->backlog, 181 if (!gred_wred_mode(t) && gred_rio_mode(t)) {
133 sch->qstats.backlog); 182 int i;
134 /* sum up all the qaves of prios <= to ours to get the new qave*/ 183
135 if (!t->eqp && t->grio) { 184 for (i = 0; i < t->DPs; i++) {
136 for (i=0;i<t->DPs;i++) { 185 if (t->tab[i] && t->tab[i]->prio < q->prio &&
137 if ((!t->tab[i]) || (i==q->DP)) 186 !red_is_idling(&t->tab[i]->parms))
138 continue; 187 qavg +=t->tab[i]->parms.qavg;
139
140 if ((t->tab[i]->prio < q->prio) && (PSCHED_IS_PASTPERFECT(t->tab[i]->qidlestart)))
141 qave +=t->tab[i]->qave;
142 } 188 }
143 189
144 } 190 }
145 191
146 q->packetsin++; 192 q->packetsin++;
147 q->bytesin+=skb->len; 193 q->bytesin += skb->len;
148 194
149 if (t->eqp && t->grio) { 195 if (gred_wred_mode(t))
150 qave=0; 196 gred_load_wred_set(t, q);
151 q->qave=t->tab[t->def]->qave;
152 q->qidlestart=t->tab[t->def]->qidlestart;
153 }
154 197
155 if (!PSCHED_IS_PASTPERFECT(q->qidlestart)) { 198 q->parms.qavg = red_calc_qavg(&q->parms, gred_backlog(t, q, sch));
156 long us_idle;
157 PSCHED_GET_TIME(now);
158 us_idle = PSCHED_TDIFF_SAFE(now, q->qidlestart, q->Scell_max);
159 PSCHED_SET_PASTPERFECT(q->qidlestart);
160 199
161 q->qave >>= q->Stab[(us_idle>>q->Scell_log)&0xFF]; 200 if (red_is_idling(&q->parms))
162 } else { 201 red_end_of_idle_period(&q->parms);
163 if (t->eqp) {
164 q->qave += sch->qstats.backlog - (q->qave >> q->Wlog);
165 } else {
166 q->qave += q->backlog - (q->qave >> q->Wlog);
167 }
168 202
169 } 203 if (gred_wred_mode(t))
170 204 gred_store_wred_set(t, q);
171
172 if (t->eqp && t->grio)
173 t->tab[t->def]->qave=q->qave;
174
175 if ((q->qave+qave) < q->qth_min) {
176 q->qcount = -1;
177enqueue:
178 if (q->backlog + skb->len <= q->limit) {
179 q->backlog += skb->len;
180do_enqueue:
181 __skb_queue_tail(&sch->q, skb);
182 sch->qstats.backlog += skb->len;
183 sch->bstats.bytes += skb->len;
184 sch->bstats.packets++;
185 return 0;
186 } else {
187 q->pdrop++;
188 }
189 205
190drop: 206 switch (red_action(&q->parms, q->parms.qavg + qavg)) {
191 kfree_skb(skb); 207 case RED_DONT_MARK:
192 sch->qstats.drops++; 208 break;
193 return NET_XMIT_DROP; 209
194 } 210 case RED_PROB_MARK:
195 if ((q->qave+qave) >= q->qth_max) { 211 sch->qstats.overlimits++;
196 q->qcount = -1; 212 if (!gred_use_ecn(t) || !INET_ECN_set_ce(skb)) {
197 sch->qstats.overlimits++; 213 q->stats.prob_drop++;
198 q->forced++; 214 goto congestion_drop;
199 goto drop; 215 }
216
217 q->stats.prob_mark++;
218 break;
219
220 case RED_HARD_MARK:
221 sch->qstats.overlimits++;
222 if (gred_use_harddrop(t) || !gred_use_ecn(t) ||
223 !INET_ECN_set_ce(skb)) {
224 q->stats.forced_drop++;
225 goto congestion_drop;
226 }
227 q->stats.forced_mark++;
228 break;
200 } 229 }
201 if (++q->qcount) { 230
202 if ((((qave+q->qave) - q->qth_min)>>q->Wlog)*q->qcount < q->qR) 231 if (q->backlog + skb->len <= q->limit) {
203 goto enqueue; 232 q->backlog += skb->len;
204 q->qcount = 0; 233 return qdisc_enqueue_tail(skb, sch);
205 q->qR = net_random()&q->Rmask;
206 sch->qstats.overlimits++;
207 q->early++;
208 goto drop;
209 } 234 }
210 q->qR = net_random()&q->Rmask; 235
211 goto enqueue; 236 q->stats.pdrop++;
237drop:
238 return qdisc_drop(skb, sch);
239
240congestion_drop:
241 qdisc_drop(skb, sch);
242 return NET_XMIT_CN;
212} 243}
213 244
214static int 245static int gred_requeue(struct sk_buff *skb, struct Qdisc* sch)
215gred_requeue(struct sk_buff *skb, struct Qdisc* sch)
216{ 246{
247 struct gred_sched *t = qdisc_priv(sch);
217 struct gred_sched_data *q; 248 struct gred_sched_data *q;
218 struct gred_sched *t= qdisc_priv(sch); 249 u16 dp = tc_index_to_dp(skb);
219 q= t->tab[(skb->tc_index&0xf)]; 250
220/* error checking here -- probably unnecessary */ 251 if (dp >= t->DPs || (q = t->tab[dp]) == NULL) {
221 PSCHED_SET_PASTPERFECT(q->qidlestart); 252 if (net_ratelimit())
222 253 printk(KERN_WARNING "GRED: Unable to relocate VQ 0x%x "
223 __skb_queue_head(&sch->q, skb); 254 "for requeue, screwing up backlog.\n",
224 sch->qstats.backlog += skb->len; 255 tc_index_to_dp(skb));
225 sch->qstats.requeues++; 256 } else {
226 q->backlog += skb->len; 257 if (red_is_idling(&q->parms))
227 return 0; 258 red_end_of_idle_period(&q->parms);
259 q->backlog += skb->len;
260 }
261
262 return qdisc_requeue(skb, sch);
228} 263}
229 264
230static struct sk_buff * 265static struct sk_buff *gred_dequeue(struct Qdisc* sch)
231gred_dequeue(struct Qdisc* sch)
232{ 266{
233 struct sk_buff *skb; 267 struct sk_buff *skb;
234 struct gred_sched_data *q; 268 struct gred_sched *t = qdisc_priv(sch);
235 struct gred_sched *t= qdisc_priv(sch); 269
270 skb = qdisc_dequeue_head(sch);
236 271
237 skb = __skb_dequeue(&sch->q);
238 if (skb) { 272 if (skb) {
239 sch->qstats.backlog -= skb->len; 273 struct gred_sched_data *q;
240 q= t->tab[(skb->tc_index&0xf)]; 274 u16 dp = tc_index_to_dp(skb);
241 if (q) { 275
242 q->backlog -= skb->len; 276 if (dp >= t->DPs || (q = t->tab[dp]) == NULL) {
243 if (!q->backlog && !t->eqp) 277 if (net_ratelimit())
244 PSCHED_GET_TIME(q->qidlestart); 278 printk(KERN_WARNING "GRED: Unable to relocate "
279 "VQ 0x%x after dequeue, screwing up "
280 "backlog.\n", tc_index_to_dp(skb));
245 } else { 281 } else {
246 D2PRINTK("gred_dequeue: skb has bad tcindex %x\n",skb->tc_index&0xf); 282 q->backlog -= skb->len;
283
284 if (!q->backlog && !gred_wred_mode(t))
285 red_start_of_idle_period(&q->parms);
247 } 286 }
287
248 return skb; 288 return skb;
249 } 289 }
250 290
251 if (t->eqp) { 291 if (gred_wred_mode(t) && !red_is_idling(&t->wred_set))
252 q= t->tab[t->def]; 292 red_start_of_idle_period(&t->wred_set);
253 if (!q)
254 D2PRINTK("no default VQ set: Results will be "
255 "screwed up\n");
256 else
257 PSCHED_GET_TIME(q->qidlestart);
258 }
259 293
260 return NULL; 294 return NULL;
261} 295}
@@ -263,36 +297,34 @@ gred_dequeue(struct Qdisc* sch)
263static unsigned int gred_drop(struct Qdisc* sch) 297static unsigned int gred_drop(struct Qdisc* sch)
264{ 298{
265 struct sk_buff *skb; 299 struct sk_buff *skb;
300 struct gred_sched *t = qdisc_priv(sch);
266 301
267 struct gred_sched_data *q; 302 skb = qdisc_dequeue_tail(sch);
268 struct gred_sched *t= qdisc_priv(sch);
269
270 skb = __skb_dequeue_tail(&sch->q);
271 if (skb) { 303 if (skb) {
272 unsigned int len = skb->len; 304 unsigned int len = skb->len;
273 sch->qstats.backlog -= len; 305 struct gred_sched_data *q;
274 sch->qstats.drops++; 306 u16 dp = tc_index_to_dp(skb);
275 q= t->tab[(skb->tc_index&0xf)]; 307
276 if (q) { 308 if (dp >= t->DPs || (q = t->tab[dp]) == NULL) {
277 q->backlog -= len; 309 if (net_ratelimit())
278 q->other++; 310 printk(KERN_WARNING "GRED: Unable to relocate "
279 if (!q->backlog && !t->eqp) 311 "VQ 0x%x while dropping, screwing up "
280 PSCHED_GET_TIME(q->qidlestart); 312 "backlog.\n", tc_index_to_dp(skb));
281 } else { 313 } else {
282 D2PRINTK("gred_dequeue: skb has bad tcindex %x\n",skb->tc_index&0xf); 314 q->backlog -= len;
315 q->stats.other++;
316
317 if (!q->backlog && !gred_wred_mode(t))
318 red_start_of_idle_period(&q->parms);
283 } 319 }
284 320
285 kfree_skb(skb); 321 qdisc_drop(skb, sch);
286 return len; 322 return len;
287 } 323 }
288 324
289 q=t->tab[t->def]; 325 if (gred_wred_mode(t) && !red_is_idling(&t->wred_set))
290 if (!q) { 326 red_start_of_idle_period(&t->wred_set);
291 D2PRINTK("no default VQ set: Results might be screwed up\n");
292 return 0;
293 }
294 327
295 PSCHED_GET_TIME(q->qidlestart);
296 return 0; 328 return 0;
297 329
298} 330}
@@ -300,293 +332,241 @@ static unsigned int gred_drop(struct Qdisc* sch)
300static void gred_reset(struct Qdisc* sch) 332static void gred_reset(struct Qdisc* sch)
301{ 333{
302 int i; 334 int i;
303 struct gred_sched_data *q; 335 struct gred_sched *t = qdisc_priv(sch);
304 struct gred_sched *t= qdisc_priv(sch); 336
337 qdisc_reset_queue(sch);
305 338
306 __skb_queue_purge(&sch->q); 339 for (i = 0; i < t->DPs; i++) {
340 struct gred_sched_data *q = t->tab[i];
307 341
308 sch->qstats.backlog = 0; 342 if (!q)
343 continue;
309 344
310 for (i=0;i<t->DPs;i++) { 345 red_restart(&q->parms);
311 q= t->tab[i];
312 if (!q)
313 continue;
314 PSCHED_SET_PASTPERFECT(q->qidlestart);
315 q->qave = 0;
316 q->qcount = -1;
317 q->backlog = 0; 346 q->backlog = 0;
318 q->other=0;
319 q->forced=0;
320 q->pdrop=0;
321 q->early=0;
322 } 347 }
323} 348}
324 349
325static int gred_change(struct Qdisc *sch, struct rtattr *opt) 350static inline void gred_destroy_vq(struct gred_sched_data *q)
351{
352 kfree(q);
353}
354
355static inline int gred_change_table_def(struct Qdisc *sch, struct rtattr *dps)
326{ 356{
327 struct gred_sched *table = qdisc_priv(sch); 357 struct gred_sched *table = qdisc_priv(sch);
328 struct gred_sched_data *q;
329 struct tc_gred_qopt *ctl;
330 struct tc_gred_sopt *sopt; 358 struct tc_gred_sopt *sopt;
331 struct rtattr *tb[TCA_GRED_STAB];
332 struct rtattr *tb2[TCA_GRED_DPS];
333 int i; 359 int i;
334 360
335 if (opt == NULL || rtattr_parse_nested(tb, TCA_GRED_STAB, opt)) 361 if (dps == NULL || RTA_PAYLOAD(dps) < sizeof(*sopt))
336 return -EINVAL; 362 return -EINVAL;
337 363
338 if (tb[TCA_GRED_PARMS-1] == 0 && tb[TCA_GRED_STAB-1] == 0) { 364 sopt = RTA_DATA(dps);
339 rtattr_parse_nested(tb2, TCA_GRED_DPS, opt); 365
366 if (sopt->DPs > MAX_DPs || sopt->DPs == 0 || sopt->def_DP >= sopt->DPs)
367 return -EINVAL;
340 368
341 if (tb2[TCA_GRED_DPS-1] == 0) 369 sch_tree_lock(sch);
342 return -EINVAL; 370 table->DPs = sopt->DPs;
371 table->def = sopt->def_DP;
372 table->red_flags = sopt->flags;
373
374 /*
375 * Every entry point to GRED is synchronized with the above code
376 * and the DP is checked against DPs, i.e. shadowed VQs can no
377 * longer be found so we can unlock right here.
378 */
379 sch_tree_unlock(sch);
380
381 if (sopt->grio) {
382 gred_enable_rio_mode(table);
383 gred_disable_wred_mode(table);
384 if (gred_wred_mode_check(sch))
385 gred_enable_wred_mode(table);
386 } else {
387 gred_disable_rio_mode(table);
388 gred_disable_wred_mode(table);
389 }
343 390
344 sopt = RTA_DATA(tb2[TCA_GRED_DPS-1]); 391 for (i = table->DPs; i < MAX_DPs; i++) {
345 table->DPs=sopt->DPs; 392 if (table->tab[i]) {
346 table->def=sopt->def_DP; 393 printk(KERN_WARNING "GRED: Warning: Destroying "
347 table->grio=sopt->grio; 394 "shadowed VQ 0x%x\n", i);
348 table->initd=0; 395 gred_destroy_vq(table->tab[i]);
349 /* probably need to clear all the table DP entries as well */ 396 table->tab[i] = NULL;
350 return 0; 397 }
351 } 398 }
352 399
400 return 0;
401}
353 402
354 if (!table->DPs || tb[TCA_GRED_PARMS-1] == 0 || tb[TCA_GRED_STAB-1] == 0 || 403static inline int gred_change_vq(struct Qdisc *sch, int dp,
355 RTA_PAYLOAD(tb[TCA_GRED_PARMS-1]) < sizeof(*ctl) || 404 struct tc_gred_qopt *ctl, int prio, u8 *stab)
356 RTA_PAYLOAD(tb[TCA_GRED_STAB-1]) < 256) 405{
357 return -EINVAL; 406 struct gred_sched *table = qdisc_priv(sch);
407 struct gred_sched_data *q;
358 408
359 ctl = RTA_DATA(tb[TCA_GRED_PARMS-1]); 409 if (table->tab[dp] == NULL) {
360 if (ctl->DP > MAX_DPs-1 ) { 410 table->tab[dp] = kmalloc(sizeof(*q), GFP_KERNEL);
361 /* misbehaving is punished! Put in the default drop probability */ 411 if (table->tab[dp] == NULL)
362 DPRINTK("\nGRED: DP %u not in the proper range fixed. New DP "
363 "set to default at %d\n",ctl->DP,table->def);
364 ctl->DP=table->def;
365 }
366
367 if (table->tab[ctl->DP] == NULL) {
368 table->tab[ctl->DP]=kmalloc(sizeof(struct gred_sched_data),
369 GFP_KERNEL);
370 if (NULL == table->tab[ctl->DP])
371 return -ENOMEM; 412 return -ENOMEM;
372 memset(table->tab[ctl->DP], 0, (sizeof(struct gred_sched_data))); 413 memset(table->tab[dp], 0, sizeof(*q));
373 }
374 q= table->tab[ctl->DP];
375
376 if (table->grio) {
377 if (ctl->prio <=0) {
378 if (table->def && table->tab[table->def]) {
379 DPRINTK("\nGRED: DP %u does not have a prio"
380 "setting default to %d\n",ctl->DP,
381 table->tab[table->def]->prio);
382 q->prio=table->tab[table->def]->prio;
383 } else {
384 DPRINTK("\nGRED: DP %u does not have a prio"
385 " setting default to 8\n",ctl->DP);
386 q->prio=8;
387 }
388 } else {
389 q->prio=ctl->prio;
390 }
391 } else {
392 q->prio=8;
393 } 414 }
394 415
395 416 q = table->tab[dp];
396 q->DP=ctl->DP; 417 q->DP = dp;
397 q->Wlog = ctl->Wlog; 418 q->prio = prio;
398 q->Plog = ctl->Plog;
399 q->limit = ctl->limit; 419 q->limit = ctl->limit;
400 q->Scell_log = ctl->Scell_log;
401 q->Rmask = ctl->Plog < 32 ? ((1<<ctl->Plog) - 1) : ~0UL;
402 q->Scell_max = (255<<q->Scell_log);
403 q->qth_min = ctl->qth_min<<ctl->Wlog;
404 q->qth_max = ctl->qth_max<<ctl->Wlog;
405 q->qave=0;
406 q->backlog=0;
407 q->qcount = -1;
408 q->other=0;
409 q->forced=0;
410 q->pdrop=0;
411 q->early=0;
412
413 PSCHED_SET_PASTPERFECT(q->qidlestart);
414 memcpy(q->Stab, RTA_DATA(tb[TCA_GRED_STAB-1]), 256);
415
416 if ( table->initd && table->grio) {
417 /* this looks ugly but it's not in the fast path */
418 for (i=0;i<table->DPs;i++) {
419 if ((!table->tab[i]) || (i==q->DP) )
420 continue;
421 if (table->tab[i]->prio == q->prio ){
422 /* WRED mode detected */
423 table->eqp=1;
424 break;
425 }
426 }
427 }
428 420
429 if (!table->initd) { 421 if (q->backlog == 0)
430 table->initd=1; 422 red_end_of_idle_period(&q->parms);
431 /*
432 the first entry also goes into the default until
433 over-written
434 */
435
436 if (table->tab[table->def] == NULL) {
437 table->tab[table->def]=
438 kmalloc(sizeof(struct gred_sched_data), GFP_KERNEL);
439 if (NULL == table->tab[table->def])
440 return -ENOMEM;
441
442 memset(table->tab[table->def], 0,
443 (sizeof(struct gred_sched_data)));
444 }
445 q= table->tab[table->def];
446 q->DP=table->def;
447 q->Wlog = ctl->Wlog;
448 q->Plog = ctl->Plog;
449 q->limit = ctl->limit;
450 q->Scell_log = ctl->Scell_log;
451 q->Rmask = ctl->Plog < 32 ? ((1<<ctl->Plog) - 1) : ~0UL;
452 q->Scell_max = (255<<q->Scell_log);
453 q->qth_min = ctl->qth_min<<ctl->Wlog;
454 q->qth_max = ctl->qth_max<<ctl->Wlog;
455
456 if (table->grio)
457 q->prio=table->tab[ctl->DP]->prio;
458 else
459 q->prio=8;
460
461 q->qcount = -1;
462 PSCHED_SET_PASTPERFECT(q->qidlestart);
463 memcpy(q->Stab, RTA_DATA(tb[TCA_GRED_STAB-1]), 256);
464 }
465 return 0;
466 423
424 red_set_parms(&q->parms,
425 ctl->qth_min, ctl->qth_max, ctl->Wlog, ctl->Plog,
426 ctl->Scell_log, stab);
427
428 return 0;
467} 429}
468 430
469static int gred_init(struct Qdisc *sch, struct rtattr *opt) 431static int gred_change(struct Qdisc *sch, struct rtattr *opt)
470{ 432{
471 struct gred_sched *table = qdisc_priv(sch); 433 struct gred_sched *table = qdisc_priv(sch);
472 struct tc_gred_sopt *sopt; 434 struct tc_gred_qopt *ctl;
473 struct rtattr *tb[TCA_GRED_STAB]; 435 struct rtattr *tb[TCA_GRED_MAX];
474 struct rtattr *tb2[TCA_GRED_DPS]; 436 int err = -EINVAL, prio = GRED_DEF_PRIO;
437 u8 *stab;
475 438
476 if (opt == NULL || rtattr_parse_nested(tb, TCA_GRED_STAB, opt)) 439 if (opt == NULL || rtattr_parse_nested(tb, TCA_GRED_MAX, opt))
477 return -EINVAL; 440 return -EINVAL;
478 441
479 if (tb[TCA_GRED_PARMS-1] == 0 && tb[TCA_GRED_STAB-1] == 0) { 442 if (tb[TCA_GRED_PARMS-1] == NULL && tb[TCA_GRED_STAB-1] == NULL)
480 rtattr_parse_nested(tb2, TCA_GRED_DPS, opt); 443 return gred_change_table_def(sch, opt);
444
445 if (tb[TCA_GRED_PARMS-1] == NULL ||
446 RTA_PAYLOAD(tb[TCA_GRED_PARMS-1]) < sizeof(*ctl) ||
447 tb[TCA_GRED_STAB-1] == NULL ||
448 RTA_PAYLOAD(tb[TCA_GRED_STAB-1]) < 256)
449 return -EINVAL;
450
451 ctl = RTA_DATA(tb[TCA_GRED_PARMS-1]);
452 stab = RTA_DATA(tb[TCA_GRED_STAB-1]);
453
454 if (ctl->DP >= table->DPs)
455 goto errout;
481 456
482 if (tb2[TCA_GRED_DPS-1] == 0) 457 if (gred_rio_mode(table)) {
483 return -EINVAL; 458 if (ctl->prio == 0) {
459 int def_prio = GRED_DEF_PRIO;
484 460
485 sopt = RTA_DATA(tb2[TCA_GRED_DPS-1]); 461 if (table->tab[table->def])
486 table->DPs=sopt->DPs; 462 def_prio = table->tab[table->def]->prio;
487 table->def=sopt->def_DP; 463
488 table->grio=sopt->grio; 464 printk(KERN_DEBUG "GRED: DP %u does not have a prio "
489 table->initd=0; 465 "setting default to %d\n", ctl->DP, def_prio);
490 return 0; 466
467 prio = def_prio;
468 } else
469 prio = ctl->prio;
470 }
471
472 sch_tree_lock(sch);
473
474 err = gred_change_vq(sch, ctl->DP, ctl, prio, stab);
475 if (err < 0)
476 goto errout_locked;
477
478 if (gred_rio_mode(table)) {
479 gred_disable_wred_mode(table);
480 if (gred_wred_mode_check(sch))
481 gred_enable_wred_mode(table);
491 } 482 }
492 483
493 DPRINTK("\n GRED_INIT error!\n"); 484 err = 0;
494 return -EINVAL; 485
486errout_locked:
487 sch_tree_unlock(sch);
488errout:
489 return err;
495} 490}
496 491
497static int gred_dump(struct Qdisc *sch, struct sk_buff *skb) 492static int gred_init(struct Qdisc *sch, struct rtattr *opt)
498{ 493{
499 unsigned long qave; 494 struct rtattr *tb[TCA_GRED_MAX];
500 struct rtattr *rta;
501 struct tc_gred_qopt *opt = NULL ;
502 struct tc_gred_qopt *dst;
503 struct gred_sched *table = qdisc_priv(sch);
504 struct gred_sched_data *q;
505 int i;
506 unsigned char *b = skb->tail;
507 495
508 rta = (struct rtattr*)b; 496 if (opt == NULL || rtattr_parse_nested(tb, TCA_GRED_MAX, opt))
509 RTA_PUT(skb, TCA_OPTIONS, 0, NULL); 497 return -EINVAL;
510 498
511 opt=kmalloc(sizeof(struct tc_gred_qopt)*MAX_DPs, GFP_KERNEL); 499 if (tb[TCA_GRED_PARMS-1] || tb[TCA_GRED_STAB-1])
500 return -EINVAL;
512 501
513 if (opt == NULL) { 502 return gred_change_table_def(sch, tb[TCA_GRED_DPS-1]);
514 DPRINTK("gred_dump:failed to malloc for %Zd\n", 503}
515 sizeof(struct tc_gred_qopt)*MAX_DPs);
516 goto rtattr_failure;
517 }
518 504
519 memset(opt, 0, (sizeof(struct tc_gred_qopt))*table->DPs); 505static int gred_dump(struct Qdisc *sch, struct sk_buff *skb)
506{
507 struct gred_sched *table = qdisc_priv(sch);
508 struct rtattr *parms, *opts = NULL;
509 int i;
510 struct tc_gred_sopt sopt = {
511 .DPs = table->DPs,
512 .def_DP = table->def,
513 .grio = gred_rio_mode(table),
514 .flags = table->red_flags,
515 };
520 516
521 if (!table->initd) { 517 opts = RTA_NEST(skb, TCA_OPTIONS);
522 DPRINTK("NO GRED Queues setup!\n"); 518 RTA_PUT(skb, TCA_GRED_DPS, sizeof(sopt), &sopt);
523 } 519 parms = RTA_NEST(skb, TCA_GRED_PARMS);
520
521 for (i = 0; i < MAX_DPs; i++) {
522 struct gred_sched_data *q = table->tab[i];
523 struct tc_gred_qopt opt;
524 524
525 for (i=0;i<MAX_DPs;i++) { 525 memset(&opt, 0, sizeof(opt));
526 dst= &opt[i];
527 q= table->tab[i];
528 526
529 if (!q) { 527 if (!q) {
530 /* hack -- fix at some point with proper message 528 /* hack -- fix at some point with proper message
531 This is how we indicate to tc that there is no VQ 529 This is how we indicate to tc that there is no VQ
532 at this DP */ 530 at this DP */
533 531
534 dst->DP=MAX_DPs+i; 532 opt.DP = MAX_DPs + i;
535 continue; 533 goto append_opt;
536 } 534 }
537 535
538 dst->limit=q->limit; 536 opt.limit = q->limit;
539 dst->qth_min=q->qth_min>>q->Wlog; 537 opt.DP = q->DP;
540 dst->qth_max=q->qth_max>>q->Wlog; 538 opt.backlog = q->backlog;
541 dst->DP=q->DP; 539 opt.prio = q->prio;
542 dst->backlog=q->backlog; 540 opt.qth_min = q->parms.qth_min >> q->parms.Wlog;
543 if (q->qave) { 541 opt.qth_max = q->parms.qth_max >> q->parms.Wlog;
544 if (table->eqp && table->grio) { 542 opt.Wlog = q->parms.Wlog;
545 q->qidlestart=table->tab[table->def]->qidlestart; 543 opt.Plog = q->parms.Plog;
546 q->qave=table->tab[table->def]->qave; 544 opt.Scell_log = q->parms.Scell_log;
547 } 545 opt.other = q->stats.other;
548 if (!PSCHED_IS_PASTPERFECT(q->qidlestart)) { 546 opt.early = q->stats.prob_drop;
549 long idle; 547 opt.forced = q->stats.forced_drop;
550 psched_time_t now; 548 opt.pdrop = q->stats.pdrop;
551 PSCHED_GET_TIME(now); 549 opt.packets = q->packetsin;
552 idle = PSCHED_TDIFF_SAFE(now, q->qidlestart, q->Scell_max); 550 opt.bytesin = q->bytesin;
553 qave = q->qave >> q->Stab[(idle>>q->Scell_log)&0xFF]; 551
554 dst->qave = qave >> q->Wlog; 552 if (gred_wred_mode(table)) {
555 553 q->parms.qidlestart =
556 } else { 554 table->tab[table->def]->parms.qidlestart;
557 dst->qave = q->qave >> q->Wlog; 555 q->parms.qavg = table->tab[table->def]->parms.qavg;
558 }
559 } else {
560 dst->qave = 0;
561 } 556 }
562 557
563 558 opt.qave = red_calc_qavg(&q->parms, q->parms.qavg);
564 dst->Wlog = q->Wlog; 559
565 dst->Plog = q->Plog; 560append_opt:
566 dst->Scell_log = q->Scell_log; 561 RTA_APPEND(skb, sizeof(opt), &opt);
567 dst->other = q->other;
568 dst->forced = q->forced;
569 dst->early = q->early;
570 dst->pdrop = q->pdrop;
571 dst->prio = q->prio;
572 dst->packets=q->packetsin;
573 dst->bytesin=q->bytesin;
574 } 562 }
575 563
576 RTA_PUT(skb, TCA_GRED_PARMS, sizeof(struct tc_gred_qopt)*MAX_DPs, opt); 564 RTA_NEST_END(skb, parms);
577 rta->rta_len = skb->tail - b;
578 565
579 kfree(opt); 566 return RTA_NEST_END(skb, opts);
580 return skb->len;
581 567
582rtattr_failure: 568rtattr_failure:
583 if (opt) 569 return RTA_NEST_CANCEL(skb, opts);
584 kfree(opt);
585 DPRINTK("gred_dump: FAILURE!!!!\n");
586
587/* also free the opt struct here */
588 skb_trim(skb, b - skb->data);
589 return -1;
590} 570}
591 571
592static void gred_destroy(struct Qdisc *sch) 572static void gred_destroy(struct Qdisc *sch)
@@ -594,15 +574,13 @@ static void gred_destroy(struct Qdisc *sch)
594 struct gred_sched *table = qdisc_priv(sch); 574 struct gred_sched *table = qdisc_priv(sch);
595 int i; 575 int i;
596 576
597 for (i = 0;i < table->DPs; i++) { 577 for (i = 0; i < table->DPs; i++) {
598 if (table->tab[i]) 578 if (table->tab[i])
599 kfree(table->tab[i]); 579 gred_destroy_vq(table->tab[i]);
600 } 580 }
601} 581}
602 582
603static struct Qdisc_ops gred_qdisc_ops = { 583static struct Qdisc_ops gred_qdisc_ops = {
604 .next = NULL,
605 .cl_ops = NULL,
606 .id = "gred", 584 .id = "gred",
607 .priv_size = sizeof(struct gred_sched), 585 .priv_size = sizeof(struct gred_sched),
608 .enqueue = gred_enqueue, 586 .enqueue = gred_enqueue,
@@ -621,10 +599,13 @@ static int __init gred_module_init(void)
621{ 599{
622 return register_qdisc(&gred_qdisc_ops); 600 return register_qdisc(&gred_qdisc_ops);
623} 601}
624static void __exit gred_module_exit(void) 602
603static void __exit gred_module_exit(void)
625{ 604{
626 unregister_qdisc(&gred_qdisc_ops); 605 unregister_qdisc(&gred_qdisc_ops);
627} 606}
607
628module_init(gred_module_init) 608module_init(gred_module_init)
629module_exit(gred_module_exit) 609module_exit(gred_module_exit)
610
630MODULE_LICENSE("GPL"); 611MODULE_LICENSE("GPL");
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index bb9bf8d5003c..cdc8d283791c 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -25,6 +25,8 @@
25 25
26#include <net/pkt_sched.h> 26#include <net/pkt_sched.h>
27 27
28#define VERSION "1.1"
29
28/* Network Emulation Queuing algorithm. 30/* Network Emulation Queuing algorithm.
29 ==================================== 31 ====================================
30 32
@@ -185,10 +187,13 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
185 || q->counter < q->gap /* inside last reordering gap */ 187 || q->counter < q->gap /* inside last reordering gap */
186 || q->reorder < get_crandom(&q->reorder_cor)) { 188 || q->reorder < get_crandom(&q->reorder_cor)) {
187 psched_time_t now; 189 psched_time_t now;
190 psched_tdiff_t delay;
191
192 delay = tabledist(q->latency, q->jitter,
193 &q->delay_cor, q->delay_dist);
194
188 PSCHED_GET_TIME(now); 195 PSCHED_GET_TIME(now);
189 PSCHED_TADD2(now, tabledist(q->latency, q->jitter, 196 PSCHED_TADD2(now, delay, cb->time_to_send);
190 &q->delay_cor, q->delay_dist),
191 cb->time_to_send);
192 ++q->counter; 197 ++q->counter;
193 ret = q->qdisc->enqueue(skb, q->qdisc); 198 ret = q->qdisc->enqueue(skb, q->qdisc);
194 } else { 199 } else {
@@ -248,24 +253,31 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch)
248 const struct netem_skb_cb *cb 253 const struct netem_skb_cb *cb
249 = (const struct netem_skb_cb *)skb->cb; 254 = (const struct netem_skb_cb *)skb->cb;
250 psched_time_t now; 255 psched_time_t now;
251 long delay;
252 256
253 /* if more time remaining? */ 257 /* if more time remaining? */
254 PSCHED_GET_TIME(now); 258 PSCHED_GET_TIME(now);
255 delay = PSCHED_US2JIFFIE(PSCHED_TDIFF(cb->time_to_send, now)); 259
256 pr_debug("netem_run: skb=%p delay=%ld\n", skb, delay); 260 if (PSCHED_TLESS(cb->time_to_send, now)) {
257 if (delay <= 0) {
258 pr_debug("netem_dequeue: return skb=%p\n", skb); 261 pr_debug("netem_dequeue: return skb=%p\n", skb);
259 sch->q.qlen--; 262 sch->q.qlen--;
260 sch->flags &= ~TCQ_F_THROTTLED; 263 sch->flags &= ~TCQ_F_THROTTLED;
261 return skb; 264 return skb;
262 } 265 } else {
266 psched_tdiff_t delay = PSCHED_TDIFF(cb->time_to_send, now);
267
268 if (q->qdisc->ops->requeue(skb, q->qdisc) != NET_XMIT_SUCCESS) {
269 sch->qstats.drops++;
263 270
264 mod_timer(&q->timer, jiffies + delay); 271 /* After this qlen is confused */
265 sch->flags |= TCQ_F_THROTTLED; 272 printk(KERN_ERR "netem: queue discpline %s could not requeue\n",
273 q->qdisc->ops->id);
266 274
267 if (q->qdisc->ops->requeue(skb, q->qdisc) != 0) 275 sch->q.qlen--;
268 sch->qstats.drops++; 276 }
277
278 mod_timer(&q->timer, jiffies + PSCHED_US2JIFFIE(delay));
279 sch->flags |= TCQ_F_THROTTLED;
280 }
269 } 281 }
270 282
271 return NULL; 283 return NULL;
@@ -290,11 +302,16 @@ static void netem_reset(struct Qdisc *sch)
290 del_timer_sync(&q->timer); 302 del_timer_sync(&q->timer);
291} 303}
292 304
305/* Pass size change message down to embedded FIFO */
293static int set_fifo_limit(struct Qdisc *q, int limit) 306static int set_fifo_limit(struct Qdisc *q, int limit)
294{ 307{
295 struct rtattr *rta; 308 struct rtattr *rta;
296 int ret = -ENOMEM; 309 int ret = -ENOMEM;
297 310
311 /* Hack to avoid sending change message to non-FIFO */
312 if (strncmp(q->ops->id + 1, "fifo", 4) != 0)
313 return 0;
314
298 rta = kmalloc(RTA_LENGTH(sizeof(struct tc_fifo_qopt)), GFP_KERNEL); 315 rta = kmalloc(RTA_LENGTH(sizeof(struct tc_fifo_qopt)), GFP_KERNEL);
299 if (rta) { 316 if (rta) {
300 rta->rta_type = RTM_NEWQDISC; 317 rta->rta_type = RTM_NEWQDISC;
@@ -426,6 +443,84 @@ static int netem_change(struct Qdisc *sch, struct rtattr *opt)
426 return 0; 443 return 0;
427} 444}
428 445
446/*
447 * Special case version of FIFO queue for use by netem.
448 * It queues in order based on timestamps in skb's
449 */
450struct fifo_sched_data {
451 u32 limit;
452};
453
454static int tfifo_enqueue(struct sk_buff *nskb, struct Qdisc *sch)
455{
456 struct fifo_sched_data *q = qdisc_priv(sch);
457 struct sk_buff_head *list = &sch->q;
458 const struct netem_skb_cb *ncb
459 = (const struct netem_skb_cb *)nskb->cb;
460 struct sk_buff *skb;
461
462 if (likely(skb_queue_len(list) < q->limit)) {
463 skb_queue_reverse_walk(list, skb) {
464 const struct netem_skb_cb *cb
465 = (const struct netem_skb_cb *)skb->cb;
466
467 if (PSCHED_TLESS(cb->time_to_send, ncb->time_to_send))
468 break;
469 }
470
471 __skb_queue_after(list, skb, nskb);
472
473 sch->qstats.backlog += nskb->len;
474 sch->bstats.bytes += nskb->len;
475 sch->bstats.packets++;
476
477 return NET_XMIT_SUCCESS;
478 }
479
480 return qdisc_drop(nskb, sch);
481}
482
483static int tfifo_init(struct Qdisc *sch, struct rtattr *opt)
484{
485 struct fifo_sched_data *q = qdisc_priv(sch);
486
487 if (opt) {
488 struct tc_fifo_qopt *ctl = RTA_DATA(opt);
489 if (RTA_PAYLOAD(opt) < sizeof(*ctl))
490 return -EINVAL;
491
492 q->limit = ctl->limit;
493 } else
494 q->limit = max_t(u32, sch->dev->tx_queue_len, 1);
495
496 return 0;
497}
498
499static int tfifo_dump(struct Qdisc *sch, struct sk_buff *skb)
500{
501 struct fifo_sched_data *q = qdisc_priv(sch);
502 struct tc_fifo_qopt opt = { .limit = q->limit };
503
504 RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
505 return skb->len;
506
507rtattr_failure:
508 return -1;
509}
510
511static struct Qdisc_ops tfifo_qdisc_ops = {
512 .id = "tfifo",
513 .priv_size = sizeof(struct fifo_sched_data),
514 .enqueue = tfifo_enqueue,
515 .dequeue = qdisc_dequeue_head,
516 .requeue = qdisc_requeue,
517 .drop = qdisc_queue_drop,
518 .init = tfifo_init,
519 .reset = qdisc_reset_queue,
520 .change = tfifo_init,
521 .dump = tfifo_dump,
522};
523
429static int netem_init(struct Qdisc *sch, struct rtattr *opt) 524static int netem_init(struct Qdisc *sch, struct rtattr *opt)
430{ 525{
431 struct netem_sched_data *q = qdisc_priv(sch); 526 struct netem_sched_data *q = qdisc_priv(sch);
@@ -438,7 +533,7 @@ static int netem_init(struct Qdisc *sch, struct rtattr *opt)
438 q->timer.function = netem_watchdog; 533 q->timer.function = netem_watchdog;
439 q->timer.data = (unsigned long) sch; 534 q->timer.data = (unsigned long) sch;
440 535
441 q->qdisc = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops); 536 q->qdisc = qdisc_create_dflt(sch->dev, &tfifo_qdisc_ops);
442 if (!q->qdisc) { 537 if (!q->qdisc) {
443 pr_debug("netem: qdisc create failed\n"); 538 pr_debug("netem: qdisc create failed\n");
444 return -ENOMEM; 539 return -ENOMEM;
@@ -601,6 +696,7 @@ static struct Qdisc_ops netem_qdisc_ops = {
601 696
602static int __init netem_module_init(void) 697static int __init netem_module_init(void)
603{ 698{
699 pr_info("netem: version " VERSION "\n");
604 return register_qdisc(&netem_qdisc_ops); 700 return register_qdisc(&netem_qdisc_ops);
605} 701}
606static void __exit netem_module_exit(void) 702static void __exit netem_module_exit(void)
diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c
index 7845d045eec4..dccfa44c2d71 100644
--- a/net/sched/sch_red.c
+++ b/net/sched/sch_red.c
@@ -9,76 +9,23 @@
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 * 10 *
11 * Changes: 11 * Changes:
12 * J Hadi Salim <hadi@nortel.com> 980914: computation fixes 12 * J Hadi Salim 980914: computation fixes
13 * Alexey Makarenko <makar@phoenix.kharkov.ua> 990814: qave on idle link was calculated incorrectly. 13 * Alexey Makarenko <makar@phoenix.kharkov.ua> 990814: qave on idle link was calculated incorrectly.
14 * J Hadi Salim <hadi@nortelnetworks.com> 980816: ECN support 14 * J Hadi Salim 980816: ECN support
15 */ 15 */
16 16
17#include <linux/config.h> 17#include <linux/config.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <asm/uaccess.h>
20#include <asm/system.h>
21#include <linux/bitops.h>
22#include <linux/types.h> 19#include <linux/types.h>
23#include <linux/kernel.h> 20#include <linux/kernel.h>
24#include <linux/sched.h>
25#include <linux/string.h>
26#include <linux/mm.h>
27#include <linux/socket.h>
28#include <linux/sockios.h>
29#include <linux/in.h>
30#include <linux/errno.h>
31#include <linux/interrupt.h>
32#include <linux/if_ether.h>
33#include <linux/inet.h>
34#include <linux/netdevice.h> 21#include <linux/netdevice.h>
35#include <linux/etherdevice.h>
36#include <linux/notifier.h>
37#include <net/ip.h>
38#include <net/route.h>
39#include <linux/skbuff.h> 22#include <linux/skbuff.h>
40#include <net/sock.h>
41#include <net/pkt_sched.h> 23#include <net/pkt_sched.h>
42#include <net/inet_ecn.h> 24#include <net/inet_ecn.h>
43#include <net/dsfield.h> 25#include <net/red.h>
44 26
45 27
46/* Random Early Detection (RED) algorithm. 28/* Parameters, settable by user:
47 =======================================
48
49 Source: Sally Floyd and Van Jacobson, "Random Early Detection Gateways
50 for Congestion Avoidance", 1993, IEEE/ACM Transactions on Networking.
51
52 This file codes a "divisionless" version of RED algorithm
53 as written down in Fig.17 of the paper.
54
55Short description.
56------------------
57
58 When a new packet arrives we calculate the average queue length:
59
60 avg = (1-W)*avg + W*current_queue_len,
61
62 W is the filter time constant (chosen as 2^(-Wlog)), it controls
63 the inertia of the algorithm. To allow larger bursts, W should be
64 decreased.
65
66 if (avg > th_max) -> packet marked (dropped).
67 if (avg < th_min) -> packet passes.
68 if (th_min < avg < th_max) we calculate probability:
69
70 Pb = max_P * (avg - th_min)/(th_max-th_min)
71
72 and mark (drop) packet with this probability.
73 Pb changes from 0 (at avg==th_min) to max_P (avg==th_max).
74 max_P should be small (not 1), usually 0.01..0.02 is good value.
75
76 max_P is chosen as a number, so that max_P/(th_max-th_min)
77 is a negative power of two in order arithmetics to contain
78 only shifts.
79
80
81 Parameters, settable by user:
82 ----------------------------- 29 -----------------------------
83 30
84 limit - bytes (must be > qth_max + burst) 31 limit - bytes (must be > qth_max + burst)
@@ -89,243 +36,93 @@ Short description.
89 arbitrarily high (well, less than ram size) 36 arbitrarily high (well, less than ram size)
90 Really, this limit will never be reached 37 Really, this limit will never be reached
91 if RED works correctly. 38 if RED works correctly.
92
93 qth_min - bytes (should be < qth_max/2)
94 qth_max - bytes (should be at least 2*qth_min and less limit)
95 Wlog - bits (<32) log(1/W).
96 Plog - bits (<32)
97
98 Plog is related to max_P by formula:
99
100 max_P = (qth_max-qth_min)/2^Plog;
101
102 F.e. if qth_max=128K and qth_min=32K, then Plog=22
103 corresponds to max_P=0.02
104
105 Scell_log
106 Stab
107
108 Lookup table for log((1-W)^(t/t_ave).
109
110
111NOTES:
112
113Upper bound on W.
114-----------------
115
116 If you want to allow bursts of L packets of size S,
117 you should choose W:
118
119 L + 1 - th_min/S < (1-(1-W)^L)/W
120
121 th_min/S = 32 th_min/S = 4
122
123 log(W) L
124 -1 33
125 -2 35
126 -3 39
127 -4 46
128 -5 57
129 -6 75
130 -7 101
131 -8 135
132 -9 190
133 etc.
134 */ 39 */
135 40
136struct red_sched_data 41struct red_sched_data
137{ 42{
138/* Parameters */ 43 u32 limit; /* HARD maximal queue length */
139 u32 limit; /* HARD maximal queue length */ 44 unsigned char flags;
140 u32 qth_min; /* Min average length threshold: A scaled */ 45 struct red_parms parms;
141 u32 qth_max; /* Max average length threshold: A scaled */ 46 struct red_stats stats;
142 u32 Rmask;
143 u32 Scell_max;
144 unsigned char flags;
145 char Wlog; /* log(W) */
146 char Plog; /* random number bits */
147 char Scell_log;
148 u8 Stab[256];
149
150/* Variables */
151 unsigned long qave; /* Average queue length: A scaled */
152 int qcount; /* Packets since last random number generation */
153 u32 qR; /* Cached random number */
154
155 psched_time_t qidlestart; /* Start of idle period */
156 struct tc_red_xstats st;
157}; 47};
158 48
159static int red_ecn_mark(struct sk_buff *skb) 49static inline int red_use_ecn(struct red_sched_data *q)
160{ 50{
161 if (skb->nh.raw + 20 > skb->tail) 51 return q->flags & TC_RED_ECN;
162 return 0;
163
164 switch (skb->protocol) {
165 case __constant_htons(ETH_P_IP):
166 if (INET_ECN_is_not_ect(skb->nh.iph->tos))
167 return 0;
168 IP_ECN_set_ce(skb->nh.iph);
169 return 1;
170 case __constant_htons(ETH_P_IPV6):
171 if (INET_ECN_is_not_ect(ipv6_get_dsfield(skb->nh.ipv6h)))
172 return 0;
173 IP6_ECN_set_ce(skb->nh.ipv6h);
174 return 1;
175 default:
176 return 0;
177 }
178} 52}
179 53
180static int 54static inline int red_use_harddrop(struct red_sched_data *q)
181red_enqueue(struct sk_buff *skb, struct Qdisc* sch) 55{
56 return q->flags & TC_RED_HARDDROP;
57}
58
59static int red_enqueue(struct sk_buff *skb, struct Qdisc* sch)
182{ 60{
183 struct red_sched_data *q = qdisc_priv(sch); 61 struct red_sched_data *q = qdisc_priv(sch);
184 62
185 psched_time_t now; 63 q->parms.qavg = red_calc_qavg(&q->parms, sch->qstats.backlog);
186 64
187 if (!PSCHED_IS_PASTPERFECT(q->qidlestart)) { 65 if (red_is_idling(&q->parms))
188 long us_idle; 66 red_end_of_idle_period(&q->parms);
189 int shift;
190 67
191 PSCHED_GET_TIME(now); 68 switch (red_action(&q->parms, q->parms.qavg)) {
192 us_idle = PSCHED_TDIFF_SAFE(now, q->qidlestart, q->Scell_max); 69 case RED_DONT_MARK:
193 PSCHED_SET_PASTPERFECT(q->qidlestart); 70 break;
194 71
195/* 72 case RED_PROB_MARK:
196 The problem: ideally, average length queue recalcultion should 73 sch->qstats.overlimits++;
197 be done over constant clock intervals. This is too expensive, so that 74 if (!red_use_ecn(q) || !INET_ECN_set_ce(skb)) {
198 the calculation is driven by outgoing packets. 75 q->stats.prob_drop++;
199 When the queue is idle we have to model this clock by hand. 76 goto congestion_drop;
200 77 }
201 SF+VJ proposed to "generate" m = idletime/(average_pkt_size/bandwidth)
202 dummy packets as a burst after idle time, i.e.
203
204 q->qave *= (1-W)^m
205
206 This is an apparently overcomplicated solution (f.e. we have to precompute
207 a table to make this calculation in reasonable time)
208 I believe that a simpler model may be used here,
209 but it is field for experiments.
210*/
211 shift = q->Stab[us_idle>>q->Scell_log];
212
213 if (shift) {
214 q->qave >>= shift;
215 } else {
216 /* Approximate initial part of exponent
217 with linear function:
218 (1-W)^m ~= 1-mW + ...
219
220 Seems, it is the best solution to
221 problem of too coarce exponent tabulation.
222 */
223
224 us_idle = (q->qave * us_idle)>>q->Scell_log;
225 if (us_idle < q->qave/2)
226 q->qave -= us_idle;
227 else
228 q->qave >>= 1;
229 }
230 } else {
231 q->qave += sch->qstats.backlog - (q->qave >> q->Wlog);
232 /* NOTE:
233 q->qave is fixed point number with point at Wlog.
234 The formulae above is equvalent to floating point
235 version:
236
237 qave = qave*(1-W) + sch->qstats.backlog*W;
238 --ANK (980924)
239 */
240 }
241 78
242 if (q->qave < q->qth_min) { 79 q->stats.prob_mark++;
243 q->qcount = -1; 80 break;
244enqueue: 81
245 if (sch->qstats.backlog + skb->len <= q->limit) { 82 case RED_HARD_MARK:
246 __skb_queue_tail(&sch->q, skb); 83 sch->qstats.overlimits++;
247 sch->qstats.backlog += skb->len; 84 if (red_use_harddrop(q) || !red_use_ecn(q) ||
248 sch->bstats.bytes += skb->len; 85 !INET_ECN_set_ce(skb)) {
249 sch->bstats.packets++; 86 q->stats.forced_drop++;
250 return NET_XMIT_SUCCESS; 87 goto congestion_drop;
251 } else { 88 }
252 q->st.pdrop++;
253 }
254 kfree_skb(skb);
255 sch->qstats.drops++;
256 return NET_XMIT_DROP;
257 }
258 if (q->qave >= q->qth_max) {
259 q->qcount = -1;
260 sch->qstats.overlimits++;
261mark:
262 if (!(q->flags&TC_RED_ECN) || !red_ecn_mark(skb)) {
263 q->st.early++;
264 goto drop;
265 }
266 q->st.marked++;
267 goto enqueue;
268 }
269 89
270 if (++q->qcount) { 90 q->stats.forced_mark++;
271 /* The formula used below causes questions. 91 break;
272
273 OK. qR is random number in the interval 0..Rmask
274 i.e. 0..(2^Plog). If we used floating point
275 arithmetics, it would be: (2^Plog)*rnd_num,
276 where rnd_num is less 1.
277
278 Taking into account, that qave have fixed
279 point at Wlog, and Plog is related to max_P by
280 max_P = (qth_max-qth_min)/2^Plog; two lines
281 below have the following floating point equivalent:
282
283 max_P*(qave - qth_min)/(qth_max-qth_min) < rnd/qcount
284
285 Any questions? --ANK (980924)
286 */
287 if (((q->qave - q->qth_min)>>q->Wlog)*q->qcount < q->qR)
288 goto enqueue;
289 q->qcount = 0;
290 q->qR = net_random()&q->Rmask;
291 sch->qstats.overlimits++;
292 goto mark;
293 } 92 }
294 q->qR = net_random()&q->Rmask;
295 goto enqueue;
296 93
297drop: 94 if (sch->qstats.backlog + skb->len <= q->limit)
298 kfree_skb(skb); 95 return qdisc_enqueue_tail(skb, sch);
299 sch->qstats.drops++; 96
97 q->stats.pdrop++;
98 return qdisc_drop(skb, sch);
99
100congestion_drop:
101 qdisc_drop(skb, sch);
300 return NET_XMIT_CN; 102 return NET_XMIT_CN;
301} 103}
302 104
303static int 105static int red_requeue(struct sk_buff *skb, struct Qdisc* sch)
304red_requeue(struct sk_buff *skb, struct Qdisc* sch)
305{ 106{
306 struct red_sched_data *q = qdisc_priv(sch); 107 struct red_sched_data *q = qdisc_priv(sch);
307 108
308 PSCHED_SET_PASTPERFECT(q->qidlestart); 109 if (red_is_idling(&q->parms))
110 red_end_of_idle_period(&q->parms);
309 111
310 __skb_queue_head(&sch->q, skb); 112 return qdisc_requeue(skb, sch);
311 sch->qstats.backlog += skb->len;
312 sch->qstats.requeues++;
313 return 0;
314} 113}
315 114
316static struct sk_buff * 115static struct sk_buff * red_dequeue(struct Qdisc* sch)
317red_dequeue(struct Qdisc* sch)
318{ 116{
319 struct sk_buff *skb; 117 struct sk_buff *skb;
320 struct red_sched_data *q = qdisc_priv(sch); 118 struct red_sched_data *q = qdisc_priv(sch);
321 119
322 skb = __skb_dequeue(&sch->q); 120 skb = qdisc_dequeue_head(sch);
323 if (skb) { 121
324 sch->qstats.backlog -= skb->len; 122 if (skb == NULL && !red_is_idling(&q->parms))
325 return skb; 123 red_start_of_idle_period(&q->parms);
326 } 124
327 PSCHED_GET_TIME(q->qidlestart); 125 return skb;
328 return NULL;
329} 126}
330 127
331static unsigned int red_drop(struct Qdisc* sch) 128static unsigned int red_drop(struct Qdisc* sch)
@@ -333,16 +130,17 @@ static unsigned int red_drop(struct Qdisc* sch)
333 struct sk_buff *skb; 130 struct sk_buff *skb;
334 struct red_sched_data *q = qdisc_priv(sch); 131 struct red_sched_data *q = qdisc_priv(sch);
335 132
336 skb = __skb_dequeue_tail(&sch->q); 133 skb = qdisc_dequeue_tail(sch);
337 if (skb) { 134 if (skb) {
338 unsigned int len = skb->len; 135 unsigned int len = skb->len;
339 sch->qstats.backlog -= len; 136 q->stats.other++;
340 sch->qstats.drops++; 137 qdisc_drop(skb, sch);
341 q->st.other++;
342 kfree_skb(skb);
343 return len; 138 return len;
344 } 139 }
345 PSCHED_GET_TIME(q->qidlestart); 140
141 if (!red_is_idling(&q->parms))
142 red_start_of_idle_period(&q->parms);
143
346 return 0; 144 return 0;
347} 145}
348 146
@@ -350,43 +148,38 @@ static void red_reset(struct Qdisc* sch)
350{ 148{
351 struct red_sched_data *q = qdisc_priv(sch); 149 struct red_sched_data *q = qdisc_priv(sch);
352 150
353 __skb_queue_purge(&sch->q); 151 qdisc_reset_queue(sch);
354 sch->qstats.backlog = 0; 152 red_restart(&q->parms);
355 PSCHED_SET_PASTPERFECT(q->qidlestart);
356 q->qave = 0;
357 q->qcount = -1;
358} 153}
359 154
360static int red_change(struct Qdisc *sch, struct rtattr *opt) 155static int red_change(struct Qdisc *sch, struct rtattr *opt)
361{ 156{
362 struct red_sched_data *q = qdisc_priv(sch); 157 struct red_sched_data *q = qdisc_priv(sch);
363 struct rtattr *tb[TCA_RED_STAB]; 158 struct rtattr *tb[TCA_RED_MAX];
364 struct tc_red_qopt *ctl; 159 struct tc_red_qopt *ctl;
365 160
366 if (opt == NULL || 161 if (opt == NULL || rtattr_parse_nested(tb, TCA_RED_MAX, opt))
367 rtattr_parse_nested(tb, TCA_RED_STAB, opt) || 162 return -EINVAL;
368 tb[TCA_RED_PARMS-1] == 0 || tb[TCA_RED_STAB-1] == 0 || 163
164 if (tb[TCA_RED_PARMS-1] == NULL ||
369 RTA_PAYLOAD(tb[TCA_RED_PARMS-1]) < sizeof(*ctl) || 165 RTA_PAYLOAD(tb[TCA_RED_PARMS-1]) < sizeof(*ctl) ||
370 RTA_PAYLOAD(tb[TCA_RED_STAB-1]) < 256) 166 tb[TCA_RED_STAB-1] == NULL ||
167 RTA_PAYLOAD(tb[TCA_RED_STAB-1]) < RED_STAB_SIZE)
371 return -EINVAL; 168 return -EINVAL;
372 169
373 ctl = RTA_DATA(tb[TCA_RED_PARMS-1]); 170 ctl = RTA_DATA(tb[TCA_RED_PARMS-1]);
374 171
375 sch_tree_lock(sch); 172 sch_tree_lock(sch);
376 q->flags = ctl->flags; 173 q->flags = ctl->flags;
377 q->Wlog = ctl->Wlog;
378 q->Plog = ctl->Plog;
379 q->Rmask = ctl->Plog < 32 ? ((1<<ctl->Plog) - 1) : ~0UL;
380 q->Scell_log = ctl->Scell_log;
381 q->Scell_max = (255<<q->Scell_log);
382 q->qth_min = ctl->qth_min<<ctl->Wlog;
383 q->qth_max = ctl->qth_max<<ctl->Wlog;
384 q->limit = ctl->limit; 174 q->limit = ctl->limit;
385 memcpy(q->Stab, RTA_DATA(tb[TCA_RED_STAB-1]), 256);
386 175
387 q->qcount = -1; 176 red_set_parms(&q->parms, ctl->qth_min, ctl->qth_max, ctl->Wlog,
177 ctl->Plog, ctl->Scell_log,
178 RTA_DATA(tb[TCA_RED_STAB-1]));
179
388 if (skb_queue_empty(&sch->q)) 180 if (skb_queue_empty(&sch->q))
389 PSCHED_SET_PASTPERFECT(q->qidlestart); 181 red_end_of_idle_period(&q->parms);
182
390 sch_tree_unlock(sch); 183 sch_tree_unlock(sch);
391 return 0; 184 return 0;
392} 185}
@@ -399,39 +192,39 @@ static int red_init(struct Qdisc* sch, struct rtattr *opt)
399static int red_dump(struct Qdisc *sch, struct sk_buff *skb) 192static int red_dump(struct Qdisc *sch, struct sk_buff *skb)
400{ 193{
401 struct red_sched_data *q = qdisc_priv(sch); 194 struct red_sched_data *q = qdisc_priv(sch);
402 unsigned char *b = skb->tail; 195 struct rtattr *opts = NULL;
403 struct rtattr *rta; 196 struct tc_red_qopt opt = {
404 struct tc_red_qopt opt; 197 .limit = q->limit,
405 198 .flags = q->flags,
406 rta = (struct rtattr*)b; 199 .qth_min = q->parms.qth_min >> q->parms.Wlog,
407 RTA_PUT(skb, TCA_OPTIONS, 0, NULL); 200 .qth_max = q->parms.qth_max >> q->parms.Wlog,
408 opt.limit = q->limit; 201 .Wlog = q->parms.Wlog,
409 opt.qth_min = q->qth_min>>q->Wlog; 202 .Plog = q->parms.Plog,
410 opt.qth_max = q->qth_max>>q->Wlog; 203 .Scell_log = q->parms.Scell_log,
411 opt.Wlog = q->Wlog; 204 };
412 opt.Plog = q->Plog; 205
413 opt.Scell_log = q->Scell_log; 206 opts = RTA_NEST(skb, TCA_OPTIONS);
414 opt.flags = q->flags;
415 RTA_PUT(skb, TCA_RED_PARMS, sizeof(opt), &opt); 207 RTA_PUT(skb, TCA_RED_PARMS, sizeof(opt), &opt);
416 rta->rta_len = skb->tail - b; 208 return RTA_NEST_END(skb, opts);
417
418 return skb->len;
419 209
420rtattr_failure: 210rtattr_failure:
421 skb_trim(skb, b - skb->data); 211 return RTA_NEST_CANCEL(skb, opts);
422 return -1;
423} 212}
424 213
425static int red_dump_stats(struct Qdisc *sch, struct gnet_dump *d) 214static int red_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
426{ 215{
427 struct red_sched_data *q = qdisc_priv(sch); 216 struct red_sched_data *q = qdisc_priv(sch);
428 217 struct tc_red_xstats st = {
429 return gnet_stats_copy_app(d, &q->st, sizeof(q->st)); 218 .early = q->stats.prob_drop + q->stats.forced_drop,
219 .pdrop = q->stats.pdrop,
220 .other = q->stats.other,
221 .marked = q->stats.prob_mark + q->stats.forced_mark,
222 };
223
224 return gnet_stats_copy_app(d, &st, sizeof(st));
430} 225}
431 226
432static struct Qdisc_ops red_qdisc_ops = { 227static struct Qdisc_ops red_qdisc_ops = {
433 .next = NULL,
434 .cl_ops = NULL,
435 .id = "red", 228 .id = "red",
436 .priv_size = sizeof(struct red_sched_data), 229 .priv_size = sizeof(struct red_sched_data),
437 .enqueue = red_enqueue, 230 .enqueue = red_enqueue,
@@ -450,10 +243,13 @@ static int __init red_module_init(void)
450{ 243{
451 return register_qdisc(&red_qdisc_ops); 244 return register_qdisc(&red_qdisc_ops);
452} 245}
453static void __exit red_module_exit(void) 246
247static void __exit red_module_exit(void)
454{ 248{
455 unregister_qdisc(&red_qdisc_ops); 249 unregister_qdisc(&red_qdisc_ops);
456} 250}
251
457module_init(red_module_init) 252module_init(red_module_init)
458module_exit(red_module_exit) 253module_exit(red_module_exit)
254
459MODULE_LICENSE("GPL"); 255MODULE_LICENSE("GPL");
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index e9bd91265f70..5a220b2bb376 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -313,6 +313,11 @@ svc_process(struct svc_serv *serv, struct svc_rqst *rqstp)
313 rqstp->rq_proc = proc = ntohl(svc_getu32(argv)); /* procedure number */ 313 rqstp->rq_proc = proc = ntohl(svc_getu32(argv)); /* procedure number */
314 314
315 progp = serv->sv_program; 315 progp = serv->sv_program;
316
317 for (progp = serv->sv_program; progp; progp = progp->pg_next)
318 if (prog == progp->pg_prog)
319 break;
320
316 /* 321 /*
317 * Decode auth data, and add verifier to reply buffer. 322 * Decode auth data, and add verifier to reply buffer.
318 * We do this before anything else in order to get a decent 323 * We do this before anything else in order to get a decent
@@ -320,7 +325,7 @@ svc_process(struct svc_serv *serv, struct svc_rqst *rqstp)
320 */ 325 */
321 auth_res = svc_authenticate(rqstp, &auth_stat); 326 auth_res = svc_authenticate(rqstp, &auth_stat);
322 /* Also give the program a chance to reject this call: */ 327 /* Also give the program a chance to reject this call: */
323 if (auth_res == SVC_OK) { 328 if (auth_res == SVC_OK && progp) {
324 auth_stat = rpc_autherr_badcred; 329 auth_stat = rpc_autherr_badcred;
325 auth_res = progp->pg_authenticate(rqstp); 330 auth_res = progp->pg_authenticate(rqstp);
326 } 331 }
@@ -340,10 +345,7 @@ svc_process(struct svc_serv *serv, struct svc_rqst *rqstp)
340 case SVC_COMPLETE: 345 case SVC_COMPLETE:
341 goto sendit; 346 goto sendit;
342 } 347 }
343 348
344 for (progp = serv->sv_program; progp; progp = progp->pg_next)
345 if (prog == progp->pg_prog)
346 break;
347 if (progp == NULL) 349 if (progp == NULL)
348 goto err_bad_prog; 350 goto err_bad_prog;
349 351
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 455aeabd95dd..c65c435c4923 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -118,7 +118,7 @@ clean-files := lkc_defs.h qconf.moc .tmp_qtcheck \
118 118
119# Needed for systems without gettext 119# Needed for systems without gettext
120KBUILD_HAVE_NLS := $(shell \ 120KBUILD_HAVE_NLS := $(shell \
121 if echo "\#include <libint.h>" | $(HOSTCC) $(HOSTCFLAGS) -E - > /dev/null 2>&1 ; \ 121 if echo "\#include <libintl.h>" | $(HOSTCC) $(HOSTCFLAGS) -E - > /dev/null 2>&1 ; \
122 then echo yes ; \ 122 then echo yes ; \
123 else echo no ; fi) 123 else echo no ; fi)
124ifeq ($(KBUILD_HAVE_NLS),no) 124ifeq ($(KBUILD_HAVE_NLS),no)
diff --git a/security/keys/key.c b/security/keys/key.c
index ccde17aff616..01bcfecb7eae 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -115,8 +115,7 @@ struct key_user *key_user_lookup(uid_t uid)
115 found: 115 found:
116 atomic_inc(&user->usage); 116 atomic_inc(&user->usage);
117 spin_unlock(&key_user_lock); 117 spin_unlock(&key_user_lock);
118 if (candidate) 118 kfree(candidate);
119 kfree(candidate);
120 out: 119 out:
121 return user; 120 return user;
122 121
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index e1cc4dd79012..c7a0ab1cfda3 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -434,8 +434,8 @@ ascend:
434 if (sp >= KEYRING_SEARCH_MAX_DEPTH) 434 if (sp >= KEYRING_SEARCH_MAX_DEPTH)
435 continue; 435 continue;
436 436
437 if (!key_task_permission(make_key_ref(key, possessed), 437 if (key_task_permission(make_key_ref(key, possessed),
438 context, KEY_SEARCH) < 0) 438 context, KEY_SEARCH) < 0)
439 continue; 439 continue;
440 440
441 /* stack the current position */ 441 /* stack the current position */
@@ -621,8 +621,8 @@ struct key *find_keyring_by_name(const char *name, key_serial_t bound)
621 if (strcmp(keyring->description, name) != 0) 621 if (strcmp(keyring->description, name) != 0)
622 continue; 622 continue;
623 623
624 if (!key_permission(make_key_ref(keyring, 0), 624 if (key_permission(make_key_ref(keyring, 0),
625 KEY_SEARCH) < 0) 625 KEY_SEARCH) < 0)
626 continue; 626 continue;
627 627
628 /* found a potential candidate, but we still need to 628 /* found a potential candidate, but we still need to
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 2f5f539875f2..0ac311dc8371 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -632,22 +632,22 @@ void policydb_destroy(struct policydb *p)
632 cond_policydb_destroy(p); 632 cond_policydb_destroy(p);
633 633
634 for (tr = p->role_tr; tr; tr = tr->next) { 634 for (tr = p->role_tr; tr; tr = tr->next) {
635 if (ltr) kfree(ltr); 635 kfree(ltr);
636 ltr = tr; 636 ltr = tr;
637 } 637 }
638 if (ltr) kfree(ltr); 638 kfree(ltr);
639 639
640 for (ra = p->role_allow; ra; ra = ra -> next) { 640 for (ra = p->role_allow; ra; ra = ra -> next) {
641 if (lra) kfree(lra); 641 kfree(lra);
642 lra = ra; 642 lra = ra;
643 } 643 }
644 if (lra) kfree(lra); 644 kfree(lra);
645 645
646 for (rt = p->range_tr; rt; rt = rt -> next) { 646 for (rt = p->range_tr; rt; rt = rt -> next) {
647 if (lrt) kfree(lrt); 647 kfree(lrt);
648 lrt = rt; 648 lrt = rt;
649 } 649 }
650 if (lrt) kfree(lrt); 650 kfree(lrt);
651 651
652 if (p->type_attr_map) { 652 if (p->type_attr_map) {
653 for (i = 0; i < p->p_types.nprim; i++) 653 for (i = 0; i < p->p_types.nprim; i++)
diff --git a/sound/Kconfig b/sound/Kconfig
index b65ee4701f98..d8f11408ce27 100644
--- a/sound/Kconfig
+++ b/sound/Kconfig
@@ -48,6 +48,14 @@ config SND
48 48
49 For more information, see <http://www.alsa-project.org/> 49 For more information, see <http://www.alsa-project.org/>
50 50
51config SND_AC97_CODEC
52 tristate
53 select SND_PCM
54 select SND_AC97_BUS
55
56config SND_AC97_BUS
57 tristate
58
51source "sound/core/Kconfig" 59source "sound/core/Kconfig"
52 60
53source "sound/drivers/Kconfig" 61source "sound/drivers/Kconfig"
diff --git a/sound/core/Kconfig b/sound/core/Kconfig
index 48cf45cfd0b7..82718836f937 100644
--- a/sound/core/Kconfig
+++ b/sound/core/Kconfig
@@ -127,12 +127,6 @@ config SND_DEBUG
127 help 127 help
128 Say Y here to enable ALSA debug code. 128 Say Y here to enable ALSA debug code.
129 129
130config SND_DEBUG_MEMORY
131 bool "Debug memory"
132 depends on SND_DEBUG
133 help
134 Say Y here to enable debugging of memory allocations.
135
136config SND_DEBUG_DETECT 130config SND_DEBUG_DETECT
137 bool "Debug detection" 131 bool "Debug detection"
138 depends on SND_DEBUG 132 depends on SND_DEBUG
diff --git a/sound/core/Makefile b/sound/core/Makefile
index 969d75528bde..5a01c76d02e8 100644
--- a/sound/core/Makefile
+++ b/sound/core/Makefile
@@ -3,8 +3,7 @@
3# Copyright (c) 1999,2001 by Jaroslav Kysela <perex@suse.cz> 3# Copyright (c) 1999,2001 by Jaroslav Kysela <perex@suse.cz>
4# 4#
5 5
6snd-objs := sound.o init.o memory.o info.o control.o misc.o \ 6snd-objs := sound.o init.o memory.o info.o control.o misc.o device.o
7 device.o wrappers.o
8ifeq ($(CONFIG_ISA_DMA_API),y) 7ifeq ($(CONFIG_ISA_DMA_API),y)
9snd-objs += isadma.o 8snd-objs += isadma.o
10endif 9endif
diff --git a/sound/core/control.c b/sound/core/control.c
index 736edf358e05..212c46a94376 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -144,7 +144,7 @@ void snd_ctl_notify(snd_card_t *card, unsigned int mask, snd_ctl_elem_id_t *id)
144 snd_ctl_file_t *ctl; 144 snd_ctl_file_t *ctl;
145 snd_kctl_event_t *ev; 145 snd_kctl_event_t *ev;
146 146
147 snd_runtime_check(card != NULL && id != NULL, return); 147 snd_assert(card != NULL && id != NULL, return);
148 read_lock(&card->ctl_files_rwlock); 148 read_lock(&card->ctl_files_rwlock);
149#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) 149#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
150 card->mixer_oss_change_count++; 150 card->mixer_oss_change_count++;
@@ -193,8 +193,8 @@ snd_kcontrol_t *snd_ctl_new(snd_kcontrol_t * control, unsigned int access)
193 snd_kcontrol_t *kctl; 193 snd_kcontrol_t *kctl;
194 unsigned int idx; 194 unsigned int idx;
195 195
196 snd_runtime_check(control != NULL, return NULL); 196 snd_assert(control != NULL, return NULL);
197 snd_runtime_check(control->count > 0, return NULL); 197 snd_assert(control->count > 0, return NULL);
198 kctl = kzalloc(sizeof(*kctl) + sizeof(snd_kcontrol_volatile_t) * control->count, GFP_KERNEL); 198 kctl = kzalloc(sizeof(*kctl) + sizeof(snd_kcontrol_volatile_t) * control->count, GFP_KERNEL);
199 if (kctl == NULL) 199 if (kctl == NULL)
200 return NULL; 200 return NULL;
@@ -220,7 +220,7 @@ snd_kcontrol_t *snd_ctl_new1(const snd_kcontrol_new_t * ncontrol, void *private_
220 snd_kcontrol_t kctl; 220 snd_kcontrol_t kctl;
221 unsigned int access; 221 unsigned int access;
222 222
223 snd_runtime_check(ncontrol != NULL, return NULL); 223 snd_assert(ncontrol != NULL, return NULL);
224 snd_assert(ncontrol->info != NULL, return NULL); 224 snd_assert(ncontrol->info != NULL, return NULL);
225 memset(&kctl, 0, sizeof(kctl)); 225 memset(&kctl, 0, sizeof(kctl));
226 kctl.id.iface = ncontrol->iface; 226 kctl.id.iface = ncontrol->iface;
@@ -309,7 +309,7 @@ int snd_ctl_add(snd_card_t * card, snd_kcontrol_t * kcontrol)
309 snd_ctl_elem_id_t id; 309 snd_ctl_elem_id_t id;
310 unsigned int idx; 310 unsigned int idx;
311 311
312 snd_runtime_check(card != NULL && kcontrol != NULL, return -EINVAL); 312 snd_assert(card != NULL && kcontrol != NULL, return -EINVAL);
313 snd_assert(kcontrol->info != NULL, return -EINVAL); 313 snd_assert(kcontrol->info != NULL, return -EINVAL);
314 id = kcontrol->id; 314 id = kcontrol->id;
315 down_write(&card->controls_rwsem); 315 down_write(&card->controls_rwsem);
@@ -355,7 +355,7 @@ int snd_ctl_remove(snd_card_t * card, snd_kcontrol_t * kcontrol)
355 snd_ctl_elem_id_t id; 355 snd_ctl_elem_id_t id;
356 unsigned int idx; 356 unsigned int idx;
357 357
358 snd_runtime_check(card != NULL && kcontrol != NULL, return -EINVAL); 358 snd_assert(card != NULL && kcontrol != NULL, return -EINVAL);
359 list_del(&kcontrol->list); 359 list_del(&kcontrol->list);
360 card->controls_count -= kcontrol->count; 360 card->controls_count -= kcontrol->count;
361 id = kcontrol->id; 361 id = kcontrol->id;
@@ -468,7 +468,7 @@ snd_kcontrol_t *snd_ctl_find_numid(snd_card_t * card, unsigned int numid)
468 struct list_head *list; 468 struct list_head *list;
469 snd_kcontrol_t *kctl; 469 snd_kcontrol_t *kctl;
470 470
471 snd_runtime_check(card != NULL && numid != 0, return NULL); 471 snd_assert(card != NULL && numid != 0, return NULL);
472 list_for_each(list, &card->controls) { 472 list_for_each(list, &card->controls) {
473 kctl = snd_kcontrol(list); 473 kctl = snd_kcontrol(list);
474 if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid) 474 if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid)
@@ -494,7 +494,7 @@ snd_kcontrol_t *snd_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id)
494 struct list_head *list; 494 struct list_head *list;
495 snd_kcontrol_t *kctl; 495 snd_kcontrol_t *kctl;
496 496
497 snd_runtime_check(card != NULL && id != NULL, return NULL); 497 snd_assert(card != NULL && id != NULL, return NULL);
498 if (id->numid != 0) 498 if (id->numid != 0)
499 return snd_ctl_find_numid(card, id->numid); 499 return snd_ctl_find_numid(card, id->numid);
500 list_for_each(list, &card->controls) { 500 list_for_each(list, &card->controls) {
@@ -1215,7 +1215,7 @@ static int _snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn, struct list_head
1215 struct list_head *list; 1215 struct list_head *list;
1216 snd_kctl_ioctl_t *p; 1216 snd_kctl_ioctl_t *p;
1217 1217
1218 snd_runtime_check(fcn != NULL, return -EINVAL); 1218 snd_assert(fcn != NULL, return -EINVAL);
1219 down_write(&snd_ioctl_rwsem); 1219 down_write(&snd_ioctl_rwsem);
1220 list_for_each(list, lists) { 1220 list_for_each(list, lists) {
1221 p = list_entry(list, snd_kctl_ioctl_t, list); 1221 p = list_entry(list, snd_kctl_ioctl_t, list);
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c
index 9383f1294fb5..e91cee35a4b9 100644
--- a/sound/core/hwdep.c
+++ b/sound/core/hwdep.c
@@ -81,20 +81,16 @@ static int snd_hwdep_open(struct inode *inode, struct file * file)
81 int err; 81 int err;
82 wait_queue_t wait; 82 wait_queue_t wait;
83 83
84 switch (major) { 84 if (major == snd_major) {
85 case CONFIG_SND_MAJOR:
86 cardnum = SNDRV_MINOR_CARD(iminor(inode)); 85 cardnum = SNDRV_MINOR_CARD(iminor(inode));
87 device = SNDRV_MINOR_DEVICE(iminor(inode)) - SNDRV_MINOR_HWDEP; 86 device = SNDRV_MINOR_DEVICE(iminor(inode)) - SNDRV_MINOR_HWDEP;
88 break;
89#ifdef CONFIG_SND_OSSEMUL 87#ifdef CONFIG_SND_OSSEMUL
90 case SOUND_MAJOR: 88 } else if (major == SOUND_MAJOR) {
91 cardnum = SNDRV_MINOR_OSS_CARD(iminor(inode)); 89 cardnum = SNDRV_MINOR_OSS_CARD(iminor(inode));
92 device = 0; 90 device = 0;
93 break;
94#endif 91#endif
95 default: 92 } else
96 return -ENXIO; 93 return -ENXIO;
97 }
98 cardnum %= SNDRV_CARDS; 94 cardnum %= SNDRV_CARDS;
99 device %= SNDRV_MINOR_HWDEPS; 95 device %= SNDRV_MINOR_HWDEPS;
100 hw = snd_hwdep_devices[(cardnum * SNDRV_MINOR_HWDEPS) + device]; 96 hw = snd_hwdep_devices[(cardnum * SNDRV_MINOR_HWDEPS) + device];
diff --git a/sound/core/info.c b/sound/core/info.c
index 37024d68a26e..39f9b97d9219 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -566,7 +566,6 @@ int __init snd_info_init(void)
566 } 566 }
567#endif 567#endif
568 snd_info_version_init(); 568 snd_info_version_init();
569 snd_memory_info_init();
570 snd_minor_info_init(); 569 snd_minor_info_init();
571 snd_minor_info_oss_init(); 570 snd_minor_info_oss_init();
572 snd_card_info_init(); 571 snd_card_info_init();
@@ -578,7 +577,6 @@ int __exit snd_info_done(void)
578 snd_card_info_done(); 577 snd_card_info_done();
579 snd_minor_info_oss_done(); 578 snd_minor_info_oss_done();
580 snd_minor_info_done(); 579 snd_minor_info_done();
581 snd_memory_info_done();
582 snd_info_version_done(); 580 snd_info_version_done();
583 if (snd_proc_root) { 581 if (snd_proc_root) {
584#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE) 582#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
diff --git a/sound/core/init.c b/sound/core/init.c
index 41e224986f35..d9ee27ae9a51 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -420,7 +420,7 @@ int snd_card_register(snd_card_t * card)
420 int err; 420 int err;
421 snd_info_entry_t *entry; 421 snd_info_entry_t *entry;
422 422
423 snd_runtime_check(card != NULL, return -EINVAL); 423 snd_assert(card != NULL, return -EINVAL);
424 if ((err = snd_device_register_all(card)) < 0) 424 if ((err = snd_device_register_all(card)) < 0)
425 return err; 425 return err;
426 write_lock(&snd_card_rwlock); 426 write_lock(&snd_card_rwlock);
@@ -524,7 +524,8 @@ int __init snd_card_info_init(void)
524 snd_info_entry_t *entry; 524 snd_info_entry_t *entry;
525 525
526 entry = snd_info_create_module_entry(THIS_MODULE, "cards", NULL); 526 entry = snd_info_create_module_entry(THIS_MODULE, "cards", NULL);
527 snd_runtime_check(entry != NULL, return -ENOMEM); 527 if (! entry)
528 return -ENOMEM;
528 entry->c.text.read_size = PAGE_SIZE; 529 entry->c.text.read_size = PAGE_SIZE;
529 entry->c.text.read = snd_card_info_read; 530 entry->c.text.read = snd_card_info_read;
530 if (snd_info_register(entry) < 0) { 531 if (snd_info_register(entry) < 0) {
@@ -840,7 +841,7 @@ static int snd_generic_resume(struct device *dev)
840 card = get_snd_generic_card(dev); 841 card = get_snd_generic_card(dev);
841 if (card->power_state == SNDRV_CTL_POWER_D0) 842 if (card->power_state == SNDRV_CTL_POWER_D0)
842 return 0; 843 return 0;
843 if (card->pm_suspend) 844 if (card->pm_resume)
844 card->pm_resume(card); 845 card->pm_resume(card);
845 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 846 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
846 return 0; 847 return 0;
diff --git a/sound/core/memory.c b/sound/core/memory.c
index 7d8e2eebba51..862d62d2e144 100644
--- a/sound/core/memory.c
+++ b/sound/core/memory.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz> 2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * 3 *
4 * Memory allocation helpers. 4 * Misc memory accessors
5 * 5 *
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -20,221 +20,9 @@
20 * 20 *
21 */ 21 */
22 22
23#include <sound/driver.h> 23#include <linux/config.h>
24#include <asm/io.h> 24#include <asm/io.h>
25#include <asm/uaccess.h> 25#include <asm/uaccess.h>
26#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/time.h>
29#include <linux/pci.h>
30#include <sound/core.h>
31#include <sound/info.h>
32
33/*
34 * memory allocation helpers and debug routines
35 */
36
37#ifdef CONFIG_SND_DEBUG_MEMORY
38
39struct snd_alloc_track {
40 unsigned long magic;
41 void *caller;
42 size_t size;
43 struct list_head list;
44 long data[0];
45};
46
47#define snd_alloc_track_entry(obj) (struct snd_alloc_track *)((char*)obj - (unsigned long)((struct snd_alloc_track *)0)->data)
48
49static long snd_alloc_kmalloc;
50static long snd_alloc_vmalloc;
51static LIST_HEAD(snd_alloc_kmalloc_list);
52static LIST_HEAD(snd_alloc_vmalloc_list);
53static DEFINE_SPINLOCK(snd_alloc_kmalloc_lock);
54static DEFINE_SPINLOCK(snd_alloc_vmalloc_lock);
55#define KMALLOC_MAGIC 0x87654321
56#define VMALLOC_MAGIC 0x87654320
57static snd_info_entry_t *snd_memory_info_entry;
58
59void __init snd_memory_init(void)
60{
61 snd_alloc_kmalloc = 0;
62 snd_alloc_vmalloc = 0;
63}
64
65void snd_memory_done(void)
66{
67 struct list_head *head;
68 struct snd_alloc_track *t;
69
70 if (snd_alloc_kmalloc > 0)
71 snd_printk(KERN_ERR "Not freed snd_alloc_kmalloc = %li\n", snd_alloc_kmalloc);
72 if (snd_alloc_vmalloc > 0)
73 snd_printk(KERN_ERR "Not freed snd_alloc_vmalloc = %li\n", snd_alloc_vmalloc);
74 list_for_each_prev(head, &snd_alloc_kmalloc_list) {
75 t = list_entry(head, struct snd_alloc_track, list);
76 if (t->magic != KMALLOC_MAGIC) {
77 snd_printk(KERN_ERR "Corrupted kmalloc\n");
78 break;
79 }
80 snd_printk(KERN_ERR "kmalloc(%ld) from %p not freed\n", (long) t->size, t->caller);
81 }
82 list_for_each_prev(head, &snd_alloc_vmalloc_list) {
83 t = list_entry(head, struct snd_alloc_track, list);
84 if (t->magic != VMALLOC_MAGIC) {
85 snd_printk(KERN_ERR "Corrupted vmalloc\n");
86 break;
87 }
88 snd_printk(KERN_ERR "vmalloc(%ld) from %p not freed\n", (long) t->size, t->caller);
89 }
90}
91
92static void *__snd_kmalloc(size_t size, gfp_t flags, void *caller)
93{
94 unsigned long cpu_flags;
95 struct snd_alloc_track *t;
96 void *ptr;
97
98 ptr = snd_wrapper_kmalloc(size + sizeof(struct snd_alloc_track), flags);
99 if (ptr != NULL) {
100 t = (struct snd_alloc_track *)ptr;
101 t->magic = KMALLOC_MAGIC;
102 t->caller = caller;
103 spin_lock_irqsave(&snd_alloc_kmalloc_lock, cpu_flags);
104 list_add_tail(&t->list, &snd_alloc_kmalloc_list);
105 spin_unlock_irqrestore(&snd_alloc_kmalloc_lock, cpu_flags);
106 t->size = size;
107 snd_alloc_kmalloc += size;
108 ptr = t->data;
109 }
110 return ptr;
111}
112
113#define _snd_kmalloc(size, flags) __snd_kmalloc((size), (flags), __builtin_return_address(0));
114void *snd_hidden_kmalloc(size_t size, gfp_t flags)
115{
116 return _snd_kmalloc(size, flags);
117}
118
119void *snd_hidden_kzalloc(size_t size, gfp_t flags)
120{
121 void *ret = _snd_kmalloc(size, flags);
122 if (ret)
123 memset(ret, 0, size);
124 return ret;
125}
126EXPORT_SYMBOL(snd_hidden_kzalloc);
127
128void *snd_hidden_kcalloc(size_t n, size_t size, gfp_t flags)
129{
130 void *ret = NULL;
131 if (n != 0 && size > INT_MAX / n)
132 return ret;
133 return snd_hidden_kzalloc(n * size, flags);
134}
135
136void snd_hidden_kfree(const void *obj)
137{
138 unsigned long flags;
139 struct snd_alloc_track *t;
140 if (obj == NULL)
141 return;
142 t = snd_alloc_track_entry(obj);
143 if (t->magic != KMALLOC_MAGIC) {
144 snd_printk(KERN_WARNING "bad kfree (called from %p)\n", __builtin_return_address(0));
145 return;
146 }
147 spin_lock_irqsave(&snd_alloc_kmalloc_lock, flags);
148 list_del(&t->list);
149 spin_unlock_irqrestore(&snd_alloc_kmalloc_lock, flags);
150 t->magic = 0;
151 snd_alloc_kmalloc -= t->size;
152 obj = t;
153 snd_wrapper_kfree(obj);
154}
155
156void *snd_hidden_vmalloc(unsigned long size)
157{
158 void *ptr;
159 ptr = snd_wrapper_vmalloc(size + sizeof(struct snd_alloc_track));
160 if (ptr) {
161 struct snd_alloc_track *t = (struct snd_alloc_track *)ptr;
162 t->magic = VMALLOC_MAGIC;
163 t->caller = __builtin_return_address(0);
164 spin_lock(&snd_alloc_vmalloc_lock);
165 list_add_tail(&t->list, &snd_alloc_vmalloc_list);
166 spin_unlock(&snd_alloc_vmalloc_lock);
167 t->size = size;
168 snd_alloc_vmalloc += size;
169 ptr = t->data;
170 }
171 return ptr;
172}
173
174void snd_hidden_vfree(void *obj)
175{
176 struct snd_alloc_track *t;
177 if (obj == NULL)
178 return;
179 t = snd_alloc_track_entry(obj);
180 if (t->magic != VMALLOC_MAGIC) {
181 snd_printk(KERN_ERR "bad vfree (called from %p)\n", __builtin_return_address(0));
182 return;
183 }
184 spin_lock(&snd_alloc_vmalloc_lock);
185 list_del(&t->list);
186 spin_unlock(&snd_alloc_vmalloc_lock);
187 t->magic = 0;
188 snd_alloc_vmalloc -= t->size;
189 obj = t;
190 snd_wrapper_vfree(obj);
191}
192
193char *snd_hidden_kstrdup(const char *s, gfp_t flags)
194{
195 int len;
196 char *buf;
197
198 if (!s) return NULL;
199
200 len = strlen(s) + 1;
201 buf = _snd_kmalloc(len, flags);
202 if (buf)
203 memcpy(buf, s, len);
204 return buf;
205}
206
207static void snd_memory_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer)
208{
209 snd_iprintf(buffer, "kmalloc: %li bytes\n", snd_alloc_kmalloc);
210 snd_iprintf(buffer, "vmalloc: %li bytes\n", snd_alloc_vmalloc);
211}
212
213int __init snd_memory_info_init(void)
214{
215 snd_info_entry_t *entry;
216
217 entry = snd_info_create_module_entry(THIS_MODULE, "meminfo", NULL);
218 if (entry) {
219 entry->c.text.read_size = 256;
220 entry->c.text.read = snd_memory_info_read;
221 if (snd_info_register(entry) < 0) {
222 snd_info_free_entry(entry);
223 entry = NULL;
224 }
225 }
226 snd_memory_info_entry = entry;
227 return 0;
228}
229
230int __exit snd_memory_info_done(void)
231{
232 if (snd_memory_info_entry)
233 snd_info_unregister(snd_memory_info_entry);
234 return 0;
235}
236
237#endif /* CONFIG_SND_DEBUG_MEMORY */
238 26
239/** 27/**
240 * copy_to_user_fromio - copy data from mmio-space to user-space 28 * copy_to_user_fromio - copy data from mmio-space to user-space
diff --git a/sound/core/misc.c b/sound/core/misc.c
index 1a81fe4df218..b53e563c09e6 100644
--- a/sound/core/misc.c
+++ b/sound/core/misc.c
@@ -23,17 +23,15 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/sched.h> 24#include <linux/sched.h>
25#include <linux/time.h> 25#include <linux/time.h>
26#include <linux/ioport.h>
26#include <sound/core.h> 27#include <sound/core.h>
27 28
28int snd_task_name(struct task_struct *task, char *name, size_t size) 29void release_and_free_resource(struct resource *res)
29{ 30{
30 unsigned int idx; 31 if (res) {
31 32 release_resource(res);
32 snd_assert(task != NULL && name != NULL && size >= 2, return -EINVAL); 33 kfree(res);
33 for (idx = 0; idx < sizeof(task->comm) && idx + 1 < size; idx++) 34 }
34 name[idx] = task->comm[idx];
35 name[idx] = '\0';
36 return 0;
37} 35}
38 36
39#ifdef CONFIG_SND_VERBOSE_PRINTK 37#ifdef CONFIG_SND_VERBOSE_PRINTK
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index 69e1059112d1..214933cf5d49 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -521,9 +521,13 @@ static void snd_mixer_oss_get_volume1_vol(snd_mixer_oss_file_t *fmixer,
521 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 521 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
522 if (uinfo == NULL || uctl == NULL) 522 if (uinfo == NULL || uctl == NULL)
523 goto __unalloc; 523 goto __unalloc;
524 snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); 524 if (kctl->info(kctl, uinfo))
525 snd_runtime_check(!kctl->get(kctl, uctl), goto __unalloc); 525 goto __unalloc;
526 snd_runtime_check(uinfo->type != SNDRV_CTL_ELEM_TYPE_BOOLEAN || uinfo->value.integer.min != 0 || uinfo->value.integer.max != 1, goto __unalloc); 526 if (kctl->get(kctl, uctl))
527 goto __unalloc;
528 if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN &&
529 uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1)
530 goto __unalloc;
527 *left = snd_mixer_oss_conv1(uctl->value.integer.value[0], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[0]); 531 *left = snd_mixer_oss_conv1(uctl->value.integer.value[0], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[0]);
528 if (uinfo->count > 1) 532 if (uinfo->count > 1)
529 *right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]); 533 *right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]);
@@ -555,8 +559,10 @@ static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer,
555 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 559 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
556 if (uinfo == NULL || uctl == NULL) 560 if (uinfo == NULL || uctl == NULL)
557 goto __unalloc; 561 goto __unalloc;
558 snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); 562 if (kctl->info(kctl, uinfo))
559 snd_runtime_check(!kctl->get(kctl, uctl), goto __unalloc); 563 goto __unalloc;
564 if (kctl->get(kctl, uctl))
565 goto __unalloc;
560 if (!uctl->value.integer.value[0]) { 566 if (!uctl->value.integer.value[0]) {
561 *left = 0; 567 *left = 0;
562 if (uinfo->count == 1) 568 if (uinfo->count == 1)
@@ -616,12 +622,16 @@ static void snd_mixer_oss_put_volume1_vol(snd_mixer_oss_file_t *fmixer,
616 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 622 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
617 if (uinfo == NULL || uctl == NULL) 623 if (uinfo == NULL || uctl == NULL)
618 goto __unalloc; 624 goto __unalloc;
619 snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); 625 if (kctl->info(kctl, uinfo))
620 snd_runtime_check(uinfo->type != SNDRV_CTL_ELEM_TYPE_BOOLEAN || uinfo->value.integer.min != 0 || uinfo->value.integer.max != 1, goto __unalloc); 626 goto __unalloc;
627 if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN &&
628 uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1)
629 goto __unalloc;
621 uctl->value.integer.value[0] = snd_mixer_oss_conv2(left, uinfo->value.integer.min, uinfo->value.integer.max); 630 uctl->value.integer.value[0] = snd_mixer_oss_conv2(left, uinfo->value.integer.min, uinfo->value.integer.max);
622 if (uinfo->count > 1) 631 if (uinfo->count > 1)
623 uctl->value.integer.value[1] = snd_mixer_oss_conv2(right, uinfo->value.integer.min, uinfo->value.integer.max); 632 uctl->value.integer.value[1] = snd_mixer_oss_conv2(right, uinfo->value.integer.min, uinfo->value.integer.max);
624 snd_runtime_check((res = kctl->put(kctl, uctl)) >= 0, goto __unalloc); 633 if ((res = kctl->put(kctl, uctl)) < 0)
634 goto __unalloc;
625 if (res > 0) 635 if (res > 0)
626 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); 636 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
627 __unalloc: 637 __unalloc:
@@ -653,7 +663,8 @@ static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer,
653 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 663 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
654 if (uinfo == NULL || uctl == NULL) 664 if (uinfo == NULL || uctl == NULL)
655 goto __unalloc; 665 goto __unalloc;
656 snd_runtime_check(!kctl->info(kctl, uinfo), goto __unalloc); 666 if (kctl->info(kctl, uinfo))
667 goto __unalloc;
657 if (uinfo->count > 1) { 668 if (uinfo->count > 1) {
658 uctl->value.integer.value[0] = left > 0 ? 1 : 0; 669 uctl->value.integer.value[0] = left > 0 ? 1 : 0;
659 uctl->value.integer.value[route ? 3 : 1] = right > 0 ? 1 : 0; 670 uctl->value.integer.value[route ? 3 : 1] = right > 0 ? 1 : 0;
@@ -664,7 +675,8 @@ static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer,
664 } else { 675 } else {
665 uctl->value.integer.value[0] = (left > 0 || right > 0) ? 1 : 0; 676 uctl->value.integer.value[0] = (left > 0 || right > 0) ? 1 : 0;
666 } 677 }
667 snd_runtime_check((res = kctl->put(kctl, uctl)) >= 0, goto __unalloc); 678 if ((res = kctl->put(kctl, uctl)) < 0)
679 goto __unalloc;
668 if (res > 0) 680 if (res > 0)
669 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); 681 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
670 __unalloc: 682 __unalloc:
@@ -776,9 +788,14 @@ static int snd_mixer_oss_get_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int
776 } 788 }
777 down_read(&card->controls_rwsem); 789 down_read(&card->controls_rwsem);
778 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); 790 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
779 snd_runtime_check(kctl != NULL, err = -ENOENT; goto __unlock); 791 if (! kctl) {
780 snd_runtime_check(!(err = kctl->info(kctl, uinfo)), goto __unlock); 792 err = -ENOENT;
781 snd_runtime_check(!(err = kctl->get(kctl, uctl)), goto __unlock); 793 goto __unlock;
794 }
795 if ((err = kctl->info(kctl, uinfo)) < 0)
796 goto __unlock;
797 if ((err = kctl->get(kctl, uctl)) < 0)
798 goto __unlock;
782 for (idx = 0; idx < 32; idx++) { 799 for (idx = 0; idx < 32; idx++) {
783 if (!(mixer->mask_recsrc & (1 << idx))) 800 if (!(mixer->mask_recsrc & (1 << idx)))
784 continue; 801 continue;
@@ -821,8 +838,12 @@ static int snd_mixer_oss_put_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int
821 } 838 }
822 down_read(&card->controls_rwsem); 839 down_read(&card->controls_rwsem);
823 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); 840 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
824 snd_runtime_check(kctl != NULL, err = -ENOENT; goto __unlock); 841 if (! kctl) {
825 snd_runtime_check(!(err = kctl->info(kctl, uinfo)), goto __unlock); 842 err = -ENOENT;
843 goto __unlock;
844 }
845 if ((err = kctl->info(kctl, uinfo)) < 0)
846 goto __unlock;
826 for (idx = 0; idx < 32; idx++) { 847 for (idx = 0; idx < 32; idx++) {
827 if (!(mixer->mask_recsrc & (1 << idx))) 848 if (!(mixer->mask_recsrc & (1 << idx)))
828 continue; 849 continue;
@@ -836,10 +857,11 @@ static int snd_mixer_oss_put_recsrc2(snd_mixer_oss_file_t *fmixer, unsigned int
836 break; 857 break;
837 slot = NULL; 858 slot = NULL;
838 } 859 }
839 snd_runtime_check(slot != NULL, goto __unlock); 860 if (! slot)
861 goto __unlock;
840 for (idx = 0; idx < uinfo->count; idx++) 862 for (idx = 0; idx < uinfo->count; idx++)
841 uctl->value.enumerated.item[idx] = slot->capture_item; 863 uctl->value.enumerated.item[idx] = slot->capture_item;
842 snd_runtime_check((err = kctl->put(kctl, uctl)) >= 0, ); 864 err = kctl->put(kctl, uctl);
843 if (err > 0) 865 if (err > 0)
844 snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); 866 snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
845 err = 0; 867 err = 0;
@@ -1008,7 +1030,8 @@ static int snd_mixer_oss_build_input(snd_mixer_oss_t *mixer, struct snd_mixer_os
1008 up_read(&mixer->card->controls_rwsem); 1030 up_read(&mixer->card->controls_rwsem);
1009 if (slot.present != 0) { 1031 if (slot.present != 0) {
1010 pslot = (struct slot *)kmalloc(sizeof(slot), GFP_KERNEL); 1032 pslot = (struct slot *)kmalloc(sizeof(slot), GFP_KERNEL);
1011 snd_runtime_check(pslot != NULL, return -ENOMEM); 1033 if (! pslot)
1034 return -ENOMEM;
1012 *pslot = slot; 1035 *pslot = slot;
1013 pslot->signature = SNDRV_MIXER_OSS_SIGNATURE; 1036 pslot->signature = SNDRV_MIXER_OSS_SIGNATURE;
1014 pslot->assigned = ptr; 1037 pslot->assigned = ptr;
@@ -1271,7 +1294,8 @@ static int snd_mixer_oss_notify_handler(snd_card_t * card, int cmd)
1271 card, 0, 1294 card, 0,
1272 &snd_mixer_oss_reg, 1295 &snd_mixer_oss_reg,
1273 name)) < 0) { 1296 name)) < 0) {
1274 snd_printk("unable to register OSS mixer device %i:%i\n", card->number, 0); 1297 snd_printk(KERN_ERR "unable to register OSS mixer device %i:%i\n",
1298 card->number, 0);
1275 kfree(mixer); 1299 kfree(mixer);
1276 return err; 1300 return err;
1277 } 1301 }
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 842c28b2ed55..bcc970759134 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -1821,6 +1821,17 @@ static int snd_pcm_oss_open_file(struct file *file,
1821} 1821}
1822 1822
1823 1823
1824static int snd_task_name(struct task_struct *task, char *name, size_t size)
1825{
1826 unsigned int idx;
1827
1828 snd_assert(task != NULL && name != NULL && size >= 2, return -EINVAL);
1829 for (idx = 0; idx < sizeof(task->comm) && idx + 1 < size; idx++)
1830 name[idx] = task->comm[idx];
1831 name[idx] = '\0';
1832 return 0;
1833}
1834
1824static int snd_pcm_oss_open(struct inode *inode, struct file *file) 1835static int snd_pcm_oss_open(struct inode *inode, struct file *file)
1825{ 1836{
1826 int minor = iminor(inode); 1837 int minor = iminor(inode);
@@ -2446,7 +2457,8 @@ static void register_oss_dsp(snd_pcm_t *pcm, int index)
2446 if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM, 2457 if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM,
2447 pcm->card, index, &snd_pcm_oss_reg, 2458 pcm->card, index, &snd_pcm_oss_reg,
2448 name) < 0) { 2459 name) < 0) {
2449 snd_printk("unable to register OSS PCM device %i:%i\n", pcm->card->number, pcm->device); 2460 snd_printk(KERN_ERR "unable to register OSS PCM device %i:%i\n",
2461 pcm->card->number, pcm->device);
2450 } 2462 }
2451} 2463}
2452 2464
@@ -2528,11 +2540,13 @@ static int __init alsa_pcm_oss_init(void)
2528 /* check device map table */ 2540 /* check device map table */
2529 for (i = 0; i < SNDRV_CARDS; i++) { 2541 for (i = 0; i < SNDRV_CARDS; i++) {
2530 if (dsp_map[i] < 0 || dsp_map[i] >= SNDRV_PCM_DEVICES) { 2542 if (dsp_map[i] < 0 || dsp_map[i] >= SNDRV_PCM_DEVICES) {
2531 snd_printk("invalid dsp_map[%d] = %d\n", i, dsp_map[i]); 2543 snd_printk(KERN_ERR "invalid dsp_map[%d] = %d\n",
2544 i, dsp_map[i]);
2532 dsp_map[i] = 0; 2545 dsp_map[i] = 0;
2533 } 2546 }
2534 if (adsp_map[i] < 0 || adsp_map[i] >= SNDRV_PCM_DEVICES) { 2547 if (adsp_map[i] < 0 || adsp_map[i] >= SNDRV_PCM_DEVICES) {
2535 snd_printk("invalid adsp_map[%d] = %d\n", i, adsp_map[i]); 2548 snd_printk(KERN_ERR "invalid adsp_map[%d] = %d\n",
2549 i, adsp_map[i]);
2536 adsp_map[i] = 1; 2550 adsp_map[i] = 1;
2537 } 2551 }
2538 } 2552 }
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 1be470e942ef..184e74b75ba9 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -273,7 +273,8 @@ static void snd_pcm_proc_info_read(snd_pcm_substream_t *substream, snd_info_buff
273 snd_pcm_info_t *info; 273 snd_pcm_info_t *info;
274 int err; 274 int err;
275 275
276 snd_runtime_check(substream, return); 276 if (! substream)
277 return;
277 278
278 info = kmalloc(sizeof(*info), GFP_KERNEL); 279 info = kmalloc(sizeof(*info), GFP_KERNEL);
279 if (! info) { 280 if (! info) {
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 0503980c23d9..3dbf9bf2ac16 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -152,13 +152,12 @@ static inline snd_pcm_uframes_t snd_pcm_update_hw_ptr_pos(snd_pcm_substream_t *s
152 if (pos == SNDRV_PCM_POS_XRUN) 152 if (pos == SNDRV_PCM_POS_XRUN)
153 return pos; /* XRUN */ 153 return pos; /* XRUN */
154 if (runtime->tstamp_mode & SNDRV_PCM_TSTAMP_MMAP) 154 if (runtime->tstamp_mode & SNDRV_PCM_TSTAMP_MMAP)
155 snd_timestamp_now((snd_timestamp_t*)&runtime->status->tstamp, runtime->tstamp_timespec); 155 getnstimeofday((struct timespec *)&runtime->status->tstamp);
156#ifdef CONFIG_SND_DEBUG 156#ifdef CONFIG_SND_DEBUG
157 if (pos >= runtime->buffer_size) { 157 if (pos >= runtime->buffer_size) {
158 snd_printk(KERN_ERR "BUG: stream = %i, pos = 0x%lx, buffer size = 0x%lx, period size = 0x%lx\n", substream->stream, pos, runtime->buffer_size, runtime->period_size); 158 snd_printk(KERN_ERR "BUG: stream = %i, pos = 0x%lx, buffer size = 0x%lx, period size = 0x%lx\n", substream->stream, pos, runtime->buffer_size, runtime->period_size);
159 } else 159 }
160#endif 160#endif
161 snd_runtime_check(pos < runtime->buffer_size, return 0);
162 pos -= pos % runtime->min_align; 161 pos -= pos % runtime->min_align;
163 return pos; 162 return pos;
164} 163}
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index e97b2d162cc7..16e252f54954 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -565,9 +565,9 @@ int snd_pcm_status(snd_pcm_substream_t *substream,
565 if (runtime->tstamp_mode & SNDRV_PCM_TSTAMP_MMAP) 565 if (runtime->tstamp_mode & SNDRV_PCM_TSTAMP_MMAP)
566 status->tstamp = runtime->status->tstamp; 566 status->tstamp = runtime->status->tstamp;
567 else 567 else
568 snd_timestamp_now(&status->tstamp, runtime->tstamp_timespec); 568 getnstimeofday(&status->tstamp);
569 } else 569 } else
570 snd_timestamp_now(&status->tstamp, runtime->tstamp_timespec); 570 getnstimeofday(&status->tstamp);
571 status->appl_ptr = runtime->control->appl_ptr; 571 status->appl_ptr = runtime->control->appl_ptr;
572 status->hw_ptr = runtime->status->hw_ptr; 572 status->hw_ptr = runtime->status->hw_ptr;
573 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 573 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
@@ -652,7 +652,7 @@ static void snd_pcm_trigger_tstamp(snd_pcm_substream_t *substream)
652 if (runtime->trigger_master == NULL) 652 if (runtime->trigger_master == NULL)
653 return; 653 return;
654 if (runtime->trigger_master == substream) { 654 if (runtime->trigger_master == substream) {
655 snd_timestamp_now(&runtime->trigger_tstamp, runtime->tstamp_timespec); 655 getnstimeofday(&runtime->trigger_tstamp);
656 } else { 656 } else {
657 snd_pcm_trigger_tstamp(runtime->trigger_master); 657 snd_pcm_trigger_tstamp(runtime->trigger_master);
658 runtime->trigger_tstamp = runtime->trigger_master->runtime->trigger_tstamp; 658 runtime->trigger_tstamp = runtime->trigger_master->runtime->trigger_tstamp;
@@ -1522,7 +1522,6 @@ static int snd_pcm_drop(snd_pcm_substream_t *substream)
1522 1522
1523 1523
1524/* WARNING: Don't forget to fput back the file */ 1524/* WARNING: Don't forget to fput back the file */
1525extern int snd_major;
1526static struct file *snd_pcm_file_fd(int fd) 1525static struct file *snd_pcm_file_fd(int fd)
1527{ 1526{
1528 struct file *file; 1527 struct file *file;
@@ -2053,7 +2052,8 @@ static int snd_pcm_open(struct inode *inode, struct file *file)
2053 snd_pcm_file_t *pcm_file; 2052 snd_pcm_file_t *pcm_file;
2054 wait_queue_t wait; 2053 wait_queue_t wait;
2055 2054
2056 snd_runtime_check(device >= SNDRV_MINOR_PCM_PLAYBACK && device < SNDRV_MINOR_DEVICES, return -ENXIO); 2055 if (device < SNDRV_MINOR_PCM_PLAYBACK || device >= SNDRV_MINOR_DEVICES)
2056 return -ENXIO;
2057 pcm = snd_pcm_devices[(cardnum * SNDRV_PCM_DEVICES) + (device % SNDRV_MINOR_PCMS)]; 2057 pcm = snd_pcm_devices[(cardnum * SNDRV_PCM_DEVICES) + (device % SNDRV_MINOR_PCMS)];
2058 if (pcm == NULL) { 2058 if (pcm == NULL) {
2059 err = -ENODEV; 2059 err = -ENODEV;
@@ -2445,14 +2445,8 @@ static int snd_pcm_common_ioctl1(snd_pcm_substream_t *substream,
2445 return put_user(SNDRV_PCM_VERSION, (int __user *)arg) ? -EFAULT : 0; 2445 return put_user(SNDRV_PCM_VERSION, (int __user *)arg) ? -EFAULT : 0;
2446 case SNDRV_PCM_IOCTL_INFO: 2446 case SNDRV_PCM_IOCTL_INFO:
2447 return snd_pcm_info_user(substream, arg); 2447 return snd_pcm_info_user(substream, arg);
2448 case SNDRV_PCM_IOCTL_TSTAMP: 2448 case SNDRV_PCM_IOCTL_TSTAMP: /* just for compatibility */
2449 {
2450 int xarg;
2451 if (get_user(xarg, (int __user *)arg))
2452 return -EFAULT;
2453 substream->runtime->tstamp_timespec = xarg ? 1 : 0;
2454 return 0; 2449 return 0;
2455 }
2456 case SNDRV_PCM_IOCTL_HW_REFINE: 2450 case SNDRV_PCM_IOCTL_HW_REFINE:
2457 return snd_pcm_hw_refine_user(substream, arg); 2451 return snd_pcm_hw_refine_user(substream, arg);
2458 case SNDRV_PCM_IOCTL_HW_PARAMS: 2452 case SNDRV_PCM_IOCTL_HW_PARAMS:
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 7c20eafecb8a..d033e61c05c7 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -378,24 +378,20 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
378 struct list_head *list; 378 struct list_head *list;
379 snd_ctl_file_t *kctl; 379 snd_ctl_file_t *kctl;
380 380
381 switch (maj) { 381 if (maj == snd_major) {
382 case CONFIG_SND_MAJOR:
383 cardnum = SNDRV_MINOR_CARD(iminor(inode)); 382 cardnum = SNDRV_MINOR_CARD(iminor(inode));
384 cardnum %= SNDRV_CARDS; 383 cardnum %= SNDRV_CARDS;
385 device = SNDRV_MINOR_DEVICE(iminor(inode)) - SNDRV_MINOR_RAWMIDI; 384 device = SNDRV_MINOR_DEVICE(iminor(inode)) - SNDRV_MINOR_RAWMIDI;
386 device %= SNDRV_MINOR_RAWMIDIS; 385 device %= SNDRV_MINOR_RAWMIDIS;
387 break;
388#ifdef CONFIG_SND_OSSEMUL 386#ifdef CONFIG_SND_OSSEMUL
389 case SOUND_MAJOR: 387 } else if (maj == SOUND_MAJOR) {
390 cardnum = SNDRV_MINOR_OSS_CARD(iminor(inode)); 388 cardnum = SNDRV_MINOR_OSS_CARD(iminor(inode));
391 cardnum %= SNDRV_CARDS; 389 cardnum %= SNDRV_CARDS;
392 device = SNDRV_MINOR_OSS_DEVICE(iminor(inode)) == SNDRV_MINOR_OSS_MIDI ? 390 device = SNDRV_MINOR_OSS_DEVICE(iminor(inode)) == SNDRV_MINOR_OSS_MIDI ?
393 midi_map[cardnum] : amidi_map[cardnum]; 391 midi_map[cardnum] : amidi_map[cardnum];
394 break;
395#endif 392#endif
396 default: 393 } else
397 return -ENXIO; 394 return -ENXIO;
398 }
399 395
400 rmidi = snd_rawmidi_devices[(cardnum * SNDRV_RAWMIDI_DEVICES) + device]; 396 rmidi = snd_rawmidi_devices[(cardnum * SNDRV_RAWMIDI_DEVICES) + device];
401 if (rmidi == NULL) 397 if (rmidi == NULL)
@@ -411,7 +407,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
411 if (err < 0) 407 if (err < 0)
412 return -ENODEV; 408 return -ENODEV;
413 fflags = snd_rawmidi_file_flags(file); 409 fflags = snd_rawmidi_file_flags(file);
414 if ((file->f_flags & O_APPEND) || maj != CONFIG_SND_MAJOR) /* OSS emul? */ 410 if ((file->f_flags & O_APPEND) || maj == SOUND_MAJOR) /* OSS emul? */
415 fflags |= SNDRV_RAWMIDI_LFLG_APPEND; 411 fflags |= SNDRV_RAWMIDI_LFLG_APPEND;
416 fflags |= SNDRV_RAWMIDI_LFLG_NOOPENLOCK; 412 fflags |= SNDRV_RAWMIDI_LFLG_NOOPENLOCK;
417 rawmidi_file = kmalloc(sizeof(*rawmidi_file), GFP_KERNEL); 413 rawmidi_file = kmalloc(sizeof(*rawmidi_file), GFP_KERNEL);
diff --git a/sound/core/rtctimer.c b/sound/core/rtctimer.c
index bd5d584d284d..c3c18568207e 100644
--- a/sound/core/rtctimer.c
+++ b/sound/core/rtctimer.c
@@ -60,7 +60,6 @@ static struct _snd_timer_hardware rtc_hw = {
60 60
61static int rtctimer_freq = RTC_FREQ; /* frequency */ 61static int rtctimer_freq = RTC_FREQ; /* frequency */
62static snd_timer_t *rtctimer; 62static snd_timer_t *rtctimer;
63static atomic_t rtc_inc = ATOMIC_INIT(0);
64static rtc_task_t rtc_task; 63static rtc_task_t rtc_task;
65 64
66 65
@@ -94,7 +93,6 @@ rtctimer_start(snd_timer_t *timer)
94 snd_assert(rtc != NULL, return -EINVAL); 93 snd_assert(rtc != NULL, return -EINVAL);
95 rtc_control(rtc, RTC_IRQP_SET, rtctimer_freq); 94 rtc_control(rtc, RTC_IRQP_SET, rtctimer_freq);
96 rtc_control(rtc, RTC_PIE_ON, 0); 95 rtc_control(rtc, RTC_PIE_ON, 0);
97 atomic_set(&rtc_inc, 0);
98 return 0; 96 return 0;
99} 97}
100 98
@@ -112,12 +110,7 @@ rtctimer_stop(snd_timer_t *timer)
112 */ 110 */
113static void rtctimer_interrupt(void *private_data) 111static void rtctimer_interrupt(void *private_data)
114{ 112{
115 int ticks; 113 snd_timer_interrupt(private_data, 1);
116
117 atomic_inc(&rtc_inc);
118 ticks = atomic_read(&rtc_inc);
119 snd_timer_interrupt((snd_timer_t*)private_data, ticks);
120 atomic_sub(ticks, &rtc_inc);
121} 114}
122 115
123 116
@@ -126,17 +119,13 @@ static void rtctimer_interrupt(void *private_data)
126 */ 119 */
127static int __init rtctimer_init(void) 120static int __init rtctimer_init(void)
128{ 121{
129 int order, err; 122 int err;
130 snd_timer_t *timer; 123 snd_timer_t *timer;
131 124
132 if (rtctimer_freq < 2 || rtctimer_freq > 8192) { 125 if (rtctimer_freq < 2 || rtctimer_freq > 8192 ||
133 snd_printk(KERN_ERR "rtctimer: invalid frequency %d\n", rtctimer_freq); 126 (rtctimer_freq & (rtctimer_freq - 1)) != 0) {
134 return -EINVAL; 127 snd_printk(KERN_ERR "rtctimer: invalid frequency %d\n",
135 } 128 rtctimer_freq);
136 for (order = 1; rtctimer_freq > order; order <<= 1)
137 ;
138 if (rtctimer_freq != order) {
139 snd_printk(KERN_ERR "rtctimer: invalid frequency %d\n", rtctimer_freq);
140 return -EINVAL; 129 return -EINVAL;
141 } 130 }
142 131
@@ -145,6 +134,7 @@ static int __init rtctimer_init(void)
145 if (err < 0) 134 if (err < 0)
146 return err; 135 return err;
147 136
137 timer->module = THIS_MODULE;
148 strcpy(timer->name, "RTC timer"); 138 strcpy(timer->name, "RTC timer");
149 timer->hw = rtc_hw; 139 timer->hw = rtc_hw;
150 timer->hw.resolution = NANO_SEC / rtctimer_freq; 140 timer->hw.resolution = NANO_SEC / rtctimer_freq;
diff --git a/sound/core/seq/seq_instr.c b/sound/core/seq/seq_instr.c
index 019d43a462d7..1d525b13ebb6 100644
--- a/sound/core/seq/seq_instr.c
+++ b/sound/core/seq/seq_instr.c
@@ -109,8 +109,7 @@ void snd_seq_instr_list_free(snd_seq_kinstr_list_t **list_ptr)
109 spin_lock_irqsave(&list->lock, flags); 109 spin_lock_irqsave(&list->lock, flags);
110 while (instr->use) { 110 while (instr->use) {
111 spin_unlock_irqrestore(&list->lock, flags); 111 spin_unlock_irqrestore(&list->lock, flags);
112 set_current_state(TASK_INTERRUPTIBLE); 112 schedule_timeout_interruptible(1);
113 schedule_timeout(1);
114 spin_lock_irqsave(&list->lock, flags); 113 spin_lock_irqsave(&list->lock, flags);
115 } 114 }
116 spin_unlock_irqrestore(&list->lock, flags); 115 spin_unlock_irqrestore(&list->lock, flags);
@@ -199,10 +198,8 @@ int snd_seq_instr_list_free_cond(snd_seq_kinstr_list_t *list,
199 while (flist) { 198 while (flist) {
200 instr = flist; 199 instr = flist;
201 flist = instr->next; 200 flist = instr->next;
202 while (instr->use) { 201 while (instr->use)
203 set_current_state(TASK_INTERRUPTIBLE); 202 schedule_timeout_interruptible(1);
204 schedule_timeout(1);
205 }
206 if (snd_seq_instr_free(instr, atomic)<0) 203 if (snd_seq_instr_free(instr, atomic)<0)
207 snd_printk(KERN_WARNING "instrument free problem\n"); 204 snd_printk(KERN_WARNING "instrument free problem\n");
208 instr = next; 205 instr = next;
@@ -554,8 +551,7 @@ static int instr_free(snd_seq_kinstr_ops_t *ops,
554 instr->ops->notify(instr->ops->private_data, instr, SNDRV_SEQ_INSTR_NOTIFY_REMOVE); 551 instr->ops->notify(instr->ops->private_data, instr, SNDRV_SEQ_INSTR_NOTIFY_REMOVE);
555 while (instr->use) { 552 while (instr->use) {
556 spin_unlock_irqrestore(&list->lock, flags); 553 spin_unlock_irqrestore(&list->lock, flags);
557 set_current_state(TASK_INTERRUPTIBLE); 554 schedule_timeout_interruptible(1);
558 schedule_timeout(1);
559 spin_lock_irqsave(&list->lock, flags); 555 spin_lock_irqsave(&list->lock, flags);
560 } 556 }
561 spin_unlock_irqrestore(&list->lock, flags); 557 spin_unlock_irqrestore(&list->lock, flags);
diff --git a/sound/core/seq/seq_lock.c b/sound/core/seq/seq_lock.c
index b09cee058fa7..a837a94b2d2a 100644
--- a/sound/core/seq/seq_lock.c
+++ b/sound/core/seq/seq_lock.c
@@ -39,8 +39,7 @@ void snd_use_lock_sync_helper(snd_use_lock_t *lockp, const char *file, int line)
39 snd_printk(KERN_WARNING "seq_lock: timeout [%d left] in %s:%d\n", atomic_read(lockp), file, line); 39 snd_printk(KERN_WARNING "seq_lock: timeout [%d left] in %s:%d\n", atomic_read(lockp), file, line);
40 break; 40 break;
41 } 41 }
42 set_current_state(TASK_UNINTERRUPTIBLE); 42 schedule_timeout_uninterruptible(1);
43 schedule_timeout(1);
44 max_count--; 43 max_count--;
45 } 44 }
46} 45}
diff --git a/sound/core/seq/seq_memory.c b/sound/core/seq/seq_memory.c
index d4d7d326c4b1..8416bcffa091 100644
--- a/sound/core/seq/seq_memory.c
+++ b/sound/core/seq/seq_memory.c
@@ -423,8 +423,7 @@ int snd_seq_pool_done(pool_t *pool)
423 snd_printk(KERN_WARNING "snd_seq_pool_done timeout: %d cells remain\n", atomic_read(&pool->counter)); 423 snd_printk(KERN_WARNING "snd_seq_pool_done timeout: %d cells remain\n", atomic_read(&pool->counter));
424 break; 424 break;
425 } 425 }
426 set_current_state(TASK_UNINTERRUPTIBLE); 426 schedule_timeout_uninterruptible(1);
427 schedule_timeout(1);
428 max_count--; 427 max_count--;
429 } 428 }
430 429
diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
index b4674ae3bc30..f89f40f44876 100644
--- a/sound/core/seq/seq_midi.c
+++ b/sound/core/seq/seq_midi.c
@@ -449,11 +449,9 @@ snd_seq_midisynth_unregister_port(snd_seq_device_t *dev)
449 client->ports_per_device[device] = 0; 449 client->ports_per_device[device] = 0;
450 msynth = client->ports[device]; 450 msynth = client->ports[device];
451 client->ports[device] = NULL; 451 client->ports[device] = NULL;
452 snd_runtime_check(msynth != NULL || ports <= 0, goto __skip);
453 for (p = 0; p < ports; p++) 452 for (p = 0; p < ports; p++)
454 snd_seq_midisynth_delete(&msynth[p]); 453 snd_seq_midisynth_delete(&msynth[p]);
455 kfree(msynth); 454 kfree(msynth);
456 __skip:
457 client->num_ports--; 455 client->num_ports--;
458 if (client->num_ports <= 0) { 456 if (client->num_ports <= 0) {
459 snd_seq_delete_kernel_client(client->seq_client); 457 snd_seq_delete_kernel_client(client->seq_client);
diff --git a/sound/core/seq/seq_timer.c b/sound/core/seq/seq_timer.c
index b57a3c07ff6f..65b64a7c456d 100644
--- a/sound/core/seq/seq_timer.c
+++ b/sound/core/seq/seq_timer.c
@@ -34,10 +34,15 @@ extern int seq_default_timer_device;
34extern int seq_default_timer_subdevice; 34extern int seq_default_timer_subdevice;
35extern int seq_default_timer_resolution; 35extern int seq_default_timer_resolution;
36 36
37/* allowed sequencer timer frequencies, in Hz */
38#define MIN_FREQUENCY 10
39#define MAX_FREQUENCY 6250
40#define DEFAULT_FREQUENCY 1000
41
37#define SKEW_BASE 0x10000 /* 16bit shift */ 42#define SKEW_BASE 0x10000 /* 16bit shift */
38 43
39static void snd_seq_timer_set_tick_resolution(seq_timer_tick_t *tick, 44static void snd_seq_timer_set_tick_resolution(seq_timer_tick_t *tick,
40 int tempo, int ppq, int nticks) 45 int tempo, int ppq)
41{ 46{
42 if (tempo < 1000000) 47 if (tempo < 1000000)
43 tick->resolution = (tempo * 1000) / ppq; 48 tick->resolution = (tempo * 1000) / ppq;
@@ -51,7 +56,6 @@ static void snd_seq_timer_set_tick_resolution(seq_timer_tick_t *tick,
51 } 56 }
52 if (tick->resolution <= 0) 57 if (tick->resolution <= 0)
53 tick->resolution = 1; 58 tick->resolution = 1;
54 tick->resolution *= nticks;
55 snd_seq_timer_update_tick(tick, 0); 59 snd_seq_timer_update_tick(tick, 0);
56} 60}
57 61
@@ -100,7 +104,7 @@ void snd_seq_timer_defaults(seq_timer_t * tmr)
100 /* setup defaults */ 104 /* setup defaults */
101 tmr->ppq = 96; /* 96 PPQ */ 105 tmr->ppq = 96; /* 96 PPQ */
102 tmr->tempo = 500000; /* 120 BPM */ 106 tmr->tempo = 500000; /* 120 BPM */
103 snd_seq_timer_set_tick_resolution(&tmr->tick, tmr->tempo, tmr->ppq, 1); 107 snd_seq_timer_set_tick_resolution(&tmr->tick, tmr->tempo, tmr->ppq);
104 tmr->running = 0; 108 tmr->running = 0;
105 109
106 tmr->type = SNDRV_SEQ_TIMER_ALSA; 110 tmr->type = SNDRV_SEQ_TIMER_ALSA;
@@ -183,7 +187,7 @@ int snd_seq_timer_set_tempo(seq_timer_t * tmr, int tempo)
183 spin_lock_irqsave(&tmr->lock, flags); 187 spin_lock_irqsave(&tmr->lock, flags);
184 if ((unsigned int)tempo != tmr->tempo) { 188 if ((unsigned int)tempo != tmr->tempo) {
185 tmr->tempo = tempo; 189 tmr->tempo = tempo;
186 snd_seq_timer_set_tick_resolution(&tmr->tick, tmr->tempo, tmr->ppq, 1); 190 snd_seq_timer_set_tick_resolution(&tmr->tick, tmr->tempo, tmr->ppq);
187 } 191 }
188 spin_unlock_irqrestore(&tmr->lock, flags); 192 spin_unlock_irqrestore(&tmr->lock, flags);
189 return 0; 193 return 0;
@@ -207,7 +211,7 @@ int snd_seq_timer_set_ppq(seq_timer_t * tmr, int ppq)
207 } 211 }
208 212
209 tmr->ppq = ppq; 213 tmr->ppq = ppq;
210 snd_seq_timer_set_tick_resolution(&tmr->tick, tmr->tempo, tmr->ppq, 1); 214 snd_seq_timer_set_tick_resolution(&tmr->tick, tmr->tempo, tmr->ppq);
211 spin_unlock_irqrestore(&tmr->lock, flags); 215 spin_unlock_irqrestore(&tmr->lock, flags);
212 return 0; 216 return 0;
213} 217}
@@ -326,17 +330,26 @@ int snd_seq_timer_stop(seq_timer_t * tmr)
326static int initialize_timer(seq_timer_t *tmr) 330static int initialize_timer(seq_timer_t *tmr)
327{ 331{
328 snd_timer_t *t; 332 snd_timer_t *t;
333 unsigned long freq;
334
329 t = tmr->timeri->timer; 335 t = tmr->timeri->timer;
330 snd_assert(t, return -EINVAL); 336 snd_assert(t, return -EINVAL);
331 337
338 freq = tmr->preferred_resolution;
339 if (!freq)
340 freq = DEFAULT_FREQUENCY;
341 else if (freq < MIN_FREQUENCY)
342 freq = MIN_FREQUENCY;
343 else if (freq > MAX_FREQUENCY)
344 freq = MAX_FREQUENCY;
345
332 tmr->ticks = 1; 346 tmr->ticks = 1;
333 if (tmr->preferred_resolution && 347 if (!(t->hw.flags & SNDRV_TIMER_HW_SLAVE)) {
334 ! (t->hw.flags & SNDRV_TIMER_HW_SLAVE)) {
335 unsigned long r = t->hw.resolution; 348 unsigned long r = t->hw.resolution;
336 if (! r && t->hw.c_resolution) 349 if (! r && t->hw.c_resolution)
337 r = t->hw.c_resolution(t); 350 r = t->hw.c_resolution(t);
338 if (r) { 351 if (r) {
339 tmr->ticks = (unsigned int)(1000000000uL / (r * tmr->preferred_resolution)); 352 tmr->ticks = (unsigned int)(1000000000uL / (r * freq));
340 if (! tmr->ticks) 353 if (! tmr->ticks)
341 tmr->ticks = 1; 354 tmr->ticks = 1;
342 } 355 }
diff --git a/sound/core/sound.c b/sound/core/sound.c
index b57519a3e3d9..1139dd8ca8eb 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -130,7 +130,7 @@ static int snd_open(struct inode *inode, struct file *file)
130 struct file_operations *old_fops; 130 struct file_operations *old_fops;
131 int err = 0; 131 int err = 0;
132 132
133 if (dev != SNDRV_MINOR_SEQUENCER && dev != SNDRV_MINOR_TIMER) { 133 if (dev != SNDRV_MINOR_GLOBAL) {
134 if (snd_cards[card] == NULL) { 134 if (snd_cards[card] == NULL) {
135#ifdef CONFIG_KMOD 135#ifdef CONFIG_KMOD
136 snd_request_card(card); 136 snd_request_card(card);
@@ -287,7 +287,7 @@ static void snd_minor_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buf
287 for (card = 0; card < SNDRV_CARDS; card++) { 287 for (card = 0; card < SNDRV_CARDS; card++) {
288 list_for_each(list, &snd_minors_hash[card]) { 288 list_for_each(list, &snd_minors_hash[card]) {
289 mptr = list_entry(list, snd_minor_t, list); 289 mptr = list_entry(list, snd_minor_t, list);
290 if (SNDRV_MINOR_DEVICE(mptr->number) != SNDRV_MINOR_SEQUENCER) { 290 if (SNDRV_MINOR_DEVICE(mptr->number) != SNDRV_MINOR_GLOBAL) {
291 if ((device = mptr->device) >= 0) 291 if ((device = mptr->device) >= 0)
292 snd_iprintf(buffer, "%3i: [%i-%2i]: %s\n", mptr->number, card, device, mptr->comment); 292 snd_iprintf(buffer, "%3i: [%i-%2i]: %s\n", mptr->number, card, device, mptr->comment);
293 else 293 else
@@ -350,9 +350,7 @@ static int __init alsa_sound_init(void)
350 devfs_remove("snd"); 350 devfs_remove("snd");
351 return -EIO; 351 return -EIO;
352 } 352 }
353 snd_memory_init();
354 if (snd_info_init() < 0) { 353 if (snd_info_init() < 0) {
355 snd_memory_done();
356 unregister_chrdev(major, "alsa"); 354 unregister_chrdev(major, "alsa");
357 devfs_remove("snd"); 355 devfs_remove("snd");
358 return -ENOMEM; 356 return -ENOMEM;
@@ -381,7 +379,6 @@ static void __exit alsa_sound_exit(void)
381#endif 379#endif
382 snd_info_minor_unregister(); 380 snd_info_minor_unregister();
383 snd_info_done(); 381 snd_info_done();
384 snd_memory_done();
385 if (unregister_chrdev(major, "alsa") != 0) 382 if (unregister_chrdev(major, "alsa") != 0)
386 snd_printk(KERN_ERR "unable to unregister major device number %d\n", major); 383 snd_printk(KERN_ERR "unable to unregister major device number %d\n", major);
387 devfs_remove("snd"); 384 devfs_remove("snd");
@@ -403,14 +400,6 @@ EXPORT_SYMBOL(snd_register_oss_device);
403EXPORT_SYMBOL(snd_unregister_oss_device); 400EXPORT_SYMBOL(snd_unregister_oss_device);
404#endif 401#endif
405 /* memory.c */ 402 /* memory.c */
406#ifdef CONFIG_SND_DEBUG_MEMORY
407EXPORT_SYMBOL(snd_hidden_kmalloc);
408EXPORT_SYMBOL(snd_hidden_kcalloc);
409EXPORT_SYMBOL(snd_hidden_kfree);
410EXPORT_SYMBOL(snd_hidden_vmalloc);
411EXPORT_SYMBOL(snd_hidden_vfree);
412EXPORT_SYMBOL(snd_hidden_kstrdup);
413#endif
414EXPORT_SYMBOL(copy_to_user_fromio); 403EXPORT_SYMBOL(copy_to_user_fromio);
415EXPORT_SYMBOL(copy_from_user_toio); 404EXPORT_SYMBOL(copy_from_user_toio);
416 /* init.c */ 405 /* init.c */
@@ -487,17 +476,10 @@ EXPORT_SYMBOL(snd_ctl_unregister_ioctl_compat);
487EXPORT_SYMBOL(snd_ctl_elem_read); 476EXPORT_SYMBOL(snd_ctl_elem_read);
488EXPORT_SYMBOL(snd_ctl_elem_write); 477EXPORT_SYMBOL(snd_ctl_elem_write);
489 /* misc.c */ 478 /* misc.c */
490EXPORT_SYMBOL(snd_task_name); 479EXPORT_SYMBOL(release_and_free_resource);
491#ifdef CONFIG_SND_VERBOSE_PRINTK 480#ifdef CONFIG_SND_VERBOSE_PRINTK
492EXPORT_SYMBOL(snd_verbose_printk); 481EXPORT_SYMBOL(snd_verbose_printk);
493#endif 482#endif
494#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK) 483#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK)
495EXPORT_SYMBOL(snd_verbose_printd); 484EXPORT_SYMBOL(snd_verbose_printd);
496#endif 485#endif
497 /* wrappers */
498#ifdef CONFIG_SND_DEBUG_MEMORY
499EXPORT_SYMBOL(snd_wrapper_kmalloc);
500EXPORT_SYMBOL(snd_wrapper_kfree);
501EXPORT_SYMBOL(snd_wrapper_vmalloc);
502EXPORT_SYMBOL(snd_wrapper_vfree);
503#endif
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 22b104624084..1b90a38d10ff 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -55,7 +55,7 @@ MODULE_PARM_DESC(timer_limit, "Maximum global timers in system.");
55 55
56typedef struct { 56typedef struct {
57 snd_timer_instance_t *timeri; 57 snd_timer_instance_t *timeri;
58 int tread; /* enhanced read with timestamps and events */ 58 int tread; /* enhanced read with timestamps and events */
59 unsigned long ticks; 59 unsigned long ticks;
60 unsigned long overrun; 60 unsigned long overrun;
61 int qhead; 61 int qhead;
@@ -95,7 +95,8 @@ static void snd_timer_reschedule(snd_timer_t * timer, unsigned long ticks_left);
95 * create a timer instance with the given owner string. 95 * create a timer instance with the given owner string.
96 * when timer is not NULL, increments the module counter 96 * when timer is not NULL, increments the module counter
97 */ 97 */
98static snd_timer_instance_t *snd_timer_instance_new(char *owner, snd_timer_t *timer) 98static snd_timer_instance_t *snd_timer_instance_new(char *owner,
99 snd_timer_t *timer)
99{ 100{
100 snd_timer_instance_t *timeri; 101 snd_timer_instance_t *timeri;
101 timeri = kzalloc(sizeof(*timeri), GFP_KERNEL); 102 timeri = kzalloc(sizeof(*timeri), GFP_KERNEL);
@@ -113,7 +114,7 @@ static snd_timer_instance_t *snd_timer_instance_new(char *owner, snd_timer_t *ti
113 INIT_LIST_HEAD(&timeri->slave_active_head); 114 INIT_LIST_HEAD(&timeri->slave_active_head);
114 115
115 timeri->timer = timer; 116 timeri->timer = timer;
116 if (timer && timer->card && !try_module_get(timer->card->module)) { 117 if (timer && !try_module_get(timer->module)) {
117 kfree(timeri->owner); 118 kfree(timeri->owner);
118 kfree(timeri); 119 kfree(timeri);
119 return NULL; 120 return NULL;
@@ -131,7 +132,7 @@ static snd_timer_t *snd_timer_find(snd_timer_id_t *tid)
131 struct list_head *p; 132 struct list_head *p;
132 133
133 list_for_each(p, &snd_timer_list) { 134 list_for_each(p, &snd_timer_list) {
134 timer = (snd_timer_t *)list_entry(p, snd_timer_t, device_list); 135 timer = list_entry(p, snd_timer_t, device_list);
135 136
136 if (timer->tmr_class != tid->dev_class) 137 if (timer->tmr_class != tid->dev_class)
137 continue; 138 continue;
@@ -186,13 +187,14 @@ static void snd_timer_check_slave(snd_timer_instance_t *slave)
186 187
187 /* FIXME: it's really dumb to look up all entries.. */ 188 /* FIXME: it's really dumb to look up all entries.. */
188 list_for_each(p, &snd_timer_list) { 189 list_for_each(p, &snd_timer_list) {
189 timer = (snd_timer_t *)list_entry(p, snd_timer_t, device_list); 190 timer = list_entry(p, snd_timer_t, device_list);
190 list_for_each(q, &timer->open_list_head) { 191 list_for_each(q, &timer->open_list_head) {
191 master = (snd_timer_instance_t *)list_entry(q, snd_timer_instance_t, open_list); 192 master = list_entry(q, snd_timer_instance_t, open_list);
192 if (slave->slave_class == master->slave_class && 193 if (slave->slave_class == master->slave_class &&
193 slave->slave_id == master->slave_id) { 194 slave->slave_id == master->slave_id) {
194 list_del(&slave->open_list); 195 list_del(&slave->open_list);
195 list_add_tail(&slave->open_list, &master->slave_list_head); 196 list_add_tail(&slave->open_list,
197 &master->slave_list_head);
196 spin_lock_irq(&slave_active_lock); 198 spin_lock_irq(&slave_active_lock);
197 slave->master = master; 199 slave->master = master;
198 slave->timer = master->timer; 200 slave->timer = master->timer;
@@ -216,7 +218,7 @@ static void snd_timer_check_master(snd_timer_instance_t *master)
216 218
217 /* check all pending slaves */ 219 /* check all pending slaves */
218 list_for_each_safe(p, n, &snd_timer_slave_list) { 220 list_for_each_safe(p, n, &snd_timer_slave_list) {
219 slave = (snd_timer_instance_t *)list_entry(p, snd_timer_instance_t, open_list); 221 slave = list_entry(p, snd_timer_instance_t, open_list);
220 if (slave->slave_class == master->slave_class && 222 if (slave->slave_class == master->slave_class &&
221 slave->slave_id == master->slave_id) { 223 slave->slave_id == master->slave_id) {
222 list_del(p); 224 list_del(p);
@@ -225,7 +227,8 @@ static void snd_timer_check_master(snd_timer_instance_t *master)
225 slave->master = master; 227 slave->master = master;
226 slave->timer = master->timer; 228 slave->timer = master->timer;
227 if (slave->flags & SNDRV_TIMER_IFLG_RUNNING) 229 if (slave->flags & SNDRV_TIMER_IFLG_RUNNING)
228 list_add_tail(&slave->active_list, &master->slave_active_head); 230 list_add_tail(&slave->active_list,
231 &master->slave_active_head);
229 spin_unlock_irq(&slave_active_lock); 232 spin_unlock_irq(&slave_active_lock);
230 } 233 }
231 } 234 }
@@ -241,7 +244,7 @@ int snd_timer_open(snd_timer_instance_t **ti,
241{ 244{
242 snd_timer_t *timer; 245 snd_timer_t *timer;
243 snd_timer_instance_t *timeri = NULL; 246 snd_timer_instance_t *timeri = NULL;
244 247
245 if (tid->dev_class == SNDRV_TIMER_CLASS_SLAVE) { 248 if (tid->dev_class == SNDRV_TIMER_CLASS_SLAVE) {
246 /* open a slave instance */ 249 /* open a slave instance */
247 if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE || 250 if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE ||
@@ -251,6 +254,10 @@ int snd_timer_open(snd_timer_instance_t **ti,
251 } 254 }
252 down(&register_mutex); 255 down(&register_mutex);
253 timeri = snd_timer_instance_new(owner, NULL); 256 timeri = snd_timer_instance_new(owner, NULL);
257 if (!timeri) {
258 up(&register_mutex);
259 return -ENOMEM;
260 }
254 timeri->slave_class = tid->dev_sclass; 261 timeri->slave_class = tid->dev_sclass;
255 timeri->slave_id = tid->device; 262 timeri->slave_id = tid->device;
256 timeri->flags |= SNDRV_TIMER_IFLG_SLAVE; 263 timeri->flags |= SNDRV_TIMER_IFLG_SLAVE;
@@ -272,33 +279,36 @@ int snd_timer_open(snd_timer_instance_t **ti,
272 timer = snd_timer_find(tid); 279 timer = snd_timer_find(tid);
273 } 280 }
274#endif 281#endif
275 if (timer) { 282 if (!timer) {
276 if (!list_empty(&timer->open_list_head)) {
277 timeri = (snd_timer_instance_t *)list_entry(timer->open_list_head.next, snd_timer_instance_t, open_list);
278 if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) {
279 up(&register_mutex);
280 return -EBUSY;
281 }
282 }
283 timeri = snd_timer_instance_new(owner, timer);
284 if (timeri) {
285 timeri->slave_class = tid->dev_sclass;
286 timeri->slave_id = slave_id;
287 if (list_empty(&timer->open_list_head) && timer->hw.open)
288 timer->hw.open(timer);
289 list_add_tail(&timeri->open_list, &timer->open_list_head);
290 snd_timer_check_master(timeri);
291 }
292 } else {
293 up(&register_mutex); 283 up(&register_mutex);
294 return -ENODEV; 284 return -ENODEV;
295 } 285 }
286 if (!list_empty(&timer->open_list_head)) {
287 timeri = list_entry(timer->open_list_head.next,
288 snd_timer_instance_t, open_list);
289 if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) {
290 up(&register_mutex);
291 return -EBUSY;
292 }
293 }
294 timeri = snd_timer_instance_new(owner, timer);
295 if (!timeri) {
296 up(&register_mutex);
297 return -ENOMEM;
298 }
299 timeri->slave_class = tid->dev_sclass;
300 timeri->slave_id = slave_id;
301 if (list_empty(&timer->open_list_head) && timer->hw.open)
302 timer->hw.open(timer);
303 list_add_tail(&timeri->open_list, &timer->open_list_head);
304 snd_timer_check_master(timeri);
296 up(&register_mutex); 305 up(&register_mutex);
297 *ti = timeri; 306 *ti = timeri;
298 return 0; 307 return 0;
299} 308}
300 309
301static int _snd_timer_stop(snd_timer_instance_t * timeri, int keep_flag, enum sndrv_timer_event event); 310static int _snd_timer_stop(snd_timer_instance_t * timeri,
311 int keep_flag, enum sndrv_timer_event event);
302 312
303/* 313/*
304 * close a timer instance 314 * close a timer instance
@@ -338,11 +348,12 @@ int snd_timer_close(snd_timer_instance_t * timeri)
338 spin_unlock_irq(&timer->lock); 348 spin_unlock_irq(&timer->lock);
339 down(&register_mutex); 349 down(&register_mutex);
340 list_del(&timeri->open_list); 350 list_del(&timeri->open_list);
341 if (timer && list_empty(&timer->open_list_head) && timer->hw.close) 351 if (timer && list_empty(&timer->open_list_head) &&
352 timer->hw.close)
342 timer->hw.close(timer); 353 timer->hw.close(timer);
343 /* remove slave links */ 354 /* remove slave links */
344 list_for_each_safe(p, n, &timeri->slave_list_head) { 355 list_for_each_safe(p, n, &timeri->slave_list_head) {
345 slave = (snd_timer_instance_t *)list_entry(p, snd_timer_instance_t, open_list); 356 slave = list_entry(p, snd_timer_instance_t, open_list);
346 spin_lock_irq(&slave_active_lock); 357 spin_lock_irq(&slave_active_lock);
347 _snd_timer_stop(slave, 1, SNDRV_TIMER_EVENT_RESOLUTION); 358 _snd_timer_stop(slave, 1, SNDRV_TIMER_EVENT_RESOLUTION);
348 list_del(p); 359 list_del(p);
@@ -357,8 +368,8 @@ int snd_timer_close(snd_timer_instance_t * timeri)
357 timeri->private_free(timeri); 368 timeri->private_free(timeri);
358 kfree(timeri->owner); 369 kfree(timeri->owner);
359 kfree(timeri); 370 kfree(timeri);
360 if (timer && timer->card) 371 if (timer)
361 module_put(timer->card->module); 372 module_put(timer->module);
362 return 0; 373 return 0;
363} 374}
364 375
@@ -376,7 +387,8 @@ unsigned long snd_timer_resolution(snd_timer_instance_t * timeri)
376 return 0; 387 return 0;
377} 388}
378 389
379static void snd_timer_notify1(snd_timer_instance_t *ti, enum sndrv_timer_event event) 390static void snd_timer_notify1(snd_timer_instance_t *ti,
391 enum sndrv_timer_event event)
380{ 392{
381 snd_timer_t *timer; 393 snd_timer_t *timer;
382 unsigned long flags; 394 unsigned long flags;
@@ -385,9 +397,11 @@ static void snd_timer_notify1(snd_timer_instance_t *ti, enum sndrv_timer_event e
385 struct list_head *n; 397 struct list_head *n;
386 struct timespec tstamp; 398 struct timespec tstamp;
387 399
388 snd_timestamp_now(&tstamp, 1); 400 getnstimeofday(&tstamp);
389 snd_assert(event >= SNDRV_TIMER_EVENT_START && event <= SNDRV_TIMER_EVENT_PAUSE, return); 401 snd_assert(event >= SNDRV_TIMER_EVENT_START &&
390 if (event == SNDRV_TIMER_EVENT_START || event == SNDRV_TIMER_EVENT_CONTINUE) 402 event <= SNDRV_TIMER_EVENT_PAUSE, return);
403 if (event == SNDRV_TIMER_EVENT_START ||
404 event == SNDRV_TIMER_EVENT_CONTINUE)
391 resolution = snd_timer_resolution(ti); 405 resolution = snd_timer_resolution(ti);
392 if (ti->ccallback) 406 if (ti->ccallback)
393 ti->ccallback(ti, SNDRV_TIMER_EVENT_START, &tstamp, resolution); 407 ti->ccallback(ti, SNDRV_TIMER_EVENT_START, &tstamp, resolution);
@@ -400,14 +414,15 @@ static void snd_timer_notify1(snd_timer_instance_t *ti, enum sndrv_timer_event e
400 return; 414 return;
401 spin_lock_irqsave(&timer->lock, flags); 415 spin_lock_irqsave(&timer->lock, flags);
402 list_for_each(n, &ti->slave_active_head) { 416 list_for_each(n, &ti->slave_active_head) {
403 ts = (snd_timer_instance_t *)list_entry(n, snd_timer_instance_t, active_list); 417 ts = list_entry(n, snd_timer_instance_t, active_list);
404 if (ts->ccallback) 418 if (ts->ccallback)
405 ts->ccallback(ti, event + 100, &tstamp, resolution); 419 ts->ccallback(ti, event + 100, &tstamp, resolution);
406 } 420 }
407 spin_unlock_irqrestore(&timer->lock, flags); 421 spin_unlock_irqrestore(&timer->lock, flags);
408} 422}
409 423
410static int snd_timer_start1(snd_timer_t *timer, snd_timer_instance_t *timeri, unsigned long sticks) 424static int snd_timer_start1(snd_timer_t *timer, snd_timer_instance_t *timeri,
425 unsigned long sticks)
411{ 426{
412 list_del(&timeri->active_list); 427 list_del(&timeri->active_list);
413 list_add_tail(&timeri->active_list, &timer->active_list_head); 428 list_add_tail(&timeri->active_list, &timer->active_list_head);
@@ -434,14 +449,15 @@ static int snd_timer_start_slave(snd_timer_instance_t *timeri)
434 spin_lock_irqsave(&slave_active_lock, flags); 449 spin_lock_irqsave(&slave_active_lock, flags);
435 timeri->flags |= SNDRV_TIMER_IFLG_RUNNING; 450 timeri->flags |= SNDRV_TIMER_IFLG_RUNNING;
436 if (timeri->master) 451 if (timeri->master)
437 list_add_tail(&timeri->active_list, &timeri->master->slave_active_head); 452 list_add_tail(&timeri->active_list,
453 &timeri->master->slave_active_head);
438 spin_unlock_irqrestore(&slave_active_lock, flags); 454 spin_unlock_irqrestore(&slave_active_lock, flags);
439 return 1; /* delayed start */ 455 return 1; /* delayed start */
440} 456}
441 457
442/* 458/*
443 * start the timer instance 459 * start the timer instance
444 */ 460 */
445int snd_timer_start(snd_timer_instance_t * timeri, unsigned int ticks) 461int snd_timer_start(snd_timer_instance_t * timeri, unsigned int ticks)
446{ 462{
447 snd_timer_t *timer; 463 snd_timer_t *timer;
@@ -467,7 +483,8 @@ int snd_timer_start(snd_timer_instance_t * timeri, unsigned int ticks)
467 return result; 483 return result;
468} 484}
469 485
470static int _snd_timer_stop(snd_timer_instance_t * timeri, int keep_flag, enum sndrv_timer_event event) 486static int _snd_timer_stop(snd_timer_instance_t * timeri,
487 int keep_flag, enum sndrv_timer_event event)
471{ 488{
472 snd_timer_t *timer; 489 snd_timer_t *timer;
473 unsigned long flags; 490 unsigned long flags;
@@ -501,7 +518,8 @@ static int _snd_timer_stop(snd_timer_instance_t * timeri, int keep_flag, enum sn
501 } 518 }
502 } 519 }
503 if (!keep_flag) 520 if (!keep_flag)
504 timeri->flags &= ~(SNDRV_TIMER_IFLG_RUNNING|SNDRV_TIMER_IFLG_START); 521 timeri->flags &=
522 ~(SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START);
505 spin_unlock_irqrestore(&timer->lock, flags); 523 spin_unlock_irqrestore(&timer->lock, flags);
506 __end: 524 __end:
507 if (event != SNDRV_TIMER_EVENT_RESOLUTION) 525 if (event != SNDRV_TIMER_EVENT_RESOLUTION)
@@ -578,7 +596,7 @@ static void snd_timer_reschedule(snd_timer_t * timer, unsigned long ticks_left)
578 struct list_head *p; 596 struct list_head *p;
579 597
580 list_for_each(p, &timer->active_list_head) { 598 list_for_each(p, &timer->active_list_head) {
581 ti = (snd_timer_instance_t *)list_entry(p, snd_timer_instance_t, active_list); 599 ti = list_entry(p, snd_timer_instance_t, active_list);
582 if (ti->flags & SNDRV_TIMER_IFLG_START) { 600 if (ti->flags & SNDRV_TIMER_IFLG_START) {
583 ti->flags &= ~SNDRV_TIMER_IFLG_START; 601 ti->flags &= ~SNDRV_TIMER_IFLG_START;
584 ti->flags |= SNDRV_TIMER_IFLG_RUNNING; 602 ti->flags |= SNDRV_TIMER_IFLG_RUNNING;
@@ -615,11 +633,11 @@ static void snd_timer_tasklet(unsigned long arg)
615 /* now process all callbacks */ 633 /* now process all callbacks */
616 while (!list_empty(&timer->sack_list_head)) { 634 while (!list_empty(&timer->sack_list_head)) {
617 p = timer->sack_list_head.next; /* get first item */ 635 p = timer->sack_list_head.next; /* get first item */
618 ti = (snd_timer_instance_t *)list_entry(p, snd_timer_instance_t, ack_list); 636 ti = list_entry(p, snd_timer_instance_t, ack_list);
619 637
620 /* remove from ack_list and make empty */ 638 /* remove from ack_list and make empty */
621 list_del_init(p); 639 list_del_init(p);
622 640
623 ticks = ti->pticks; 641 ticks = ti->pticks;
624 ti->pticks = 0; 642 ti->pticks = 0;
625 resolution = ti->resolution; 643 resolution = ti->resolution;
@@ -644,7 +662,7 @@ void snd_timer_interrupt(snd_timer_t * timer, unsigned long ticks_left)
644{ 662{
645 snd_timer_instance_t *ti, *ts; 663 snd_timer_instance_t *ti, *ts;
646 unsigned long resolution, ticks; 664 unsigned long resolution, ticks;
647 struct list_head *p, *q, *n; 665 struct list_head *p, *q, *n, *ack_list_head;
648 int use_tasklet = 0; 666 int use_tasklet = 0;
649 667
650 if (timer == NULL) 668 if (timer == NULL)
@@ -659,11 +677,12 @@ void snd_timer_interrupt(snd_timer_t * timer, unsigned long ticks_left)
659 resolution = timer->hw.resolution; 677 resolution = timer->hw.resolution;
660 678
661 /* loop for all active instances 679 /* loop for all active instances
662 * here we cannot use list_for_each because the active_list of a processed 680 * Here we cannot use list_for_each because the active_list of a
663 * instance is relinked to done_list_head before callback is called. 681 * processed instance is relinked to done_list_head before the callback
682 * is called.
664 */ 683 */
665 list_for_each_safe(p, n, &timer->active_list_head) { 684 list_for_each_safe(p, n, &timer->active_list_head) {
666 ti = (snd_timer_instance_t *)list_entry(p, snd_timer_instance_t, active_list); 685 ti = list_entry(p, snd_timer_instance_t, active_list);
667 if (!(ti->flags & SNDRV_TIMER_IFLG_RUNNING)) 686 if (!(ti->flags & SNDRV_TIMER_IFLG_RUNNING))
668 continue; 687 continue;
669 ti->pticks += ticks_left; 688 ti->pticks += ticks_left;
@@ -681,26 +700,19 @@ void snd_timer_interrupt(snd_timer_t * timer, unsigned long ticks_left)
681 if (--timer->running) 700 if (--timer->running)
682 list_del(p); 701 list_del(p);
683 } 702 }
684 if (list_empty(&ti->ack_list)) { 703 if ((timer->hw.flags & SNDRV_TIMER_HW_TASKLET) ||
685 if ((timer->hw.flags & SNDRV_TIMER_HW_TASKLET) || 704 (ti->flags & SNDRV_TIMER_IFLG_FAST))
686 (ti->flags & SNDRV_TIMER_IFLG_FAST)) { 705 ack_list_head = &timer->ack_list_head;
687 list_add_tail(&ti->ack_list, &timer->ack_list_head); 706 else
688 } else { 707 ack_list_head = &timer->sack_list_head;
689 list_add_tail(&ti->ack_list, &timer->sack_list_head); 708 if (list_empty(&ti->ack_list))
690 } 709 list_add_tail(&ti->ack_list, ack_list_head);
691 }
692 list_for_each(q, &ti->slave_active_head) { 710 list_for_each(q, &ti->slave_active_head) {
693 ts = (snd_timer_instance_t *)list_entry(q, snd_timer_instance_t, active_list); 711 ts = list_entry(q, snd_timer_instance_t, active_list);
694 ts->pticks = ti->pticks; 712 ts->pticks = ti->pticks;
695 ts->resolution = resolution; 713 ts->resolution = resolution;
696 if (list_empty(&ts->ack_list)) { 714 if (list_empty(&ts->ack_list))
697 if ((timer->hw.flags & SNDRV_TIMER_HW_TASKLET) || 715 list_add_tail(&ts->ack_list, ack_list_head);
698 (ti->flags & SNDRV_TIMER_IFLG_FAST)) {
699 list_add_tail(&ts->ack_list, &timer->ack_list_head);
700 } else {
701 list_add_tail(&ts->ack_list, &timer->sack_list_head);
702 }
703 }
704 } 716 }
705 } 717 }
706 if (timer->flags & SNDRV_TIMER_FLG_RESCHED) 718 if (timer->flags & SNDRV_TIMER_FLG_RESCHED)
@@ -723,11 +735,11 @@ void snd_timer_interrupt(snd_timer_t * timer, unsigned long ticks_left)
723 /* now process all fast callbacks */ 735 /* now process all fast callbacks */
724 while (!list_empty(&timer->ack_list_head)) { 736 while (!list_empty(&timer->ack_list_head)) {
725 p = timer->ack_list_head.next; /* get first item */ 737 p = timer->ack_list_head.next; /* get first item */
726 ti = (snd_timer_instance_t *)list_entry(p, snd_timer_instance_t, ack_list); 738 ti = list_entry(p, snd_timer_instance_t, ack_list);
727 739
728 /* remove from ack_list and make empty */ 740 /* remove from ack_list and make empty */
729 list_del_init(p); 741 list_del_init(p);
730 742
731 ticks = ti->pticks; 743 ticks = ti->pticks;
732 ti->pticks = 0; 744 ti->pticks = 0;
733 745
@@ -751,7 +763,8 @@ void snd_timer_interrupt(snd_timer_t * timer, unsigned long ticks_left)
751 763
752 */ 764 */
753 765
754int snd_timer_new(snd_card_t *card, char *id, snd_timer_id_t *tid, snd_timer_t ** rtimer) 766int snd_timer_new(snd_card_t *card, char *id, snd_timer_id_t *tid,
767 snd_timer_t **rtimer)
755{ 768{
756 snd_timer_t *timer; 769 snd_timer_t *timer;
757 int err; 770 int err;
@@ -779,9 +792,12 @@ int snd_timer_new(snd_card_t *card, char *id, snd_timer_id_t *tid, snd_timer_t *
779 INIT_LIST_HEAD(&timer->ack_list_head); 792 INIT_LIST_HEAD(&timer->ack_list_head);
780 INIT_LIST_HEAD(&timer->sack_list_head); 793 INIT_LIST_HEAD(&timer->sack_list_head);
781 spin_lock_init(&timer->lock); 794 spin_lock_init(&timer->lock);
782 tasklet_init(&timer->task_queue, snd_timer_tasklet, (unsigned long)timer); 795 tasklet_init(&timer->task_queue, snd_timer_tasklet,
796 (unsigned long)timer);
783 if (card != NULL) { 797 if (card != NULL) {
784 if ((err = snd_device_new(card, SNDRV_DEV_TIMER, timer, &ops)) < 0) { 798 timer->module = card->module;
799 err = snd_device_new(card, SNDRV_DEV_TIMER, timer, &ops);
800 if (err < 0) {
785 snd_timer_free(timer); 801 snd_timer_free(timer);
786 return err; 802 return err;
787 } 803 }
@@ -811,14 +827,15 @@ static int snd_timer_dev_register(snd_device_t *dev)
811 snd_timer_t *timer1; 827 snd_timer_t *timer1;
812 struct list_head *p; 828 struct list_head *p;
813 829
814 snd_assert(timer != NULL && timer->hw.start != NULL && timer->hw.stop != NULL, return -ENXIO); 830 snd_assert(timer != NULL && timer->hw.start != NULL &&
831 timer->hw.stop != NULL, return -ENXIO);
815 if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) && 832 if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) &&
816 !timer->hw.resolution && timer->hw.c_resolution == NULL) 833 !timer->hw.resolution && timer->hw.c_resolution == NULL)
817 return -EINVAL; 834 return -EINVAL;
818 835
819 down(&register_mutex); 836 down(&register_mutex);
820 list_for_each(p, &snd_timer_list) { 837 list_for_each(p, &snd_timer_list) {
821 timer1 = (snd_timer_t *)list_entry(p, snd_timer_t, device_list); 838 timer1 = list_entry(p, snd_timer_t, device_list);
822 if (timer1->tmr_class > timer->tmr_class) 839 if (timer1->tmr_class > timer->tmr_class)
823 break; 840 break;
824 if (timer1->tmr_class < timer->tmr_class) 841 if (timer1->tmr_class < timer->tmr_class)
@@ -857,7 +874,7 @@ static int snd_timer_unregister(snd_timer_t *timer)
857 snd_printk(KERN_WARNING "timer 0x%lx is busy?\n", (long)timer); 874 snd_printk(KERN_WARNING "timer 0x%lx is busy?\n", (long)timer);
858 list_for_each_safe(p, n, &timer->open_list_head) { 875 list_for_each_safe(p, n, &timer->open_list_head) {
859 list_del_init(p); 876 list_del_init(p);
860 ti = (snd_timer_instance_t *)list_entry(p, snd_timer_instance_t, open_list); 877 ti = list_entry(p, snd_timer_instance_t, open_list);
861 ti->timer = NULL; 878 ti->timer = NULL;
862 } 879 }
863 } 880 }
@@ -872,15 +889,18 @@ static int snd_timer_dev_unregister(snd_device_t *device)
872 return snd_timer_unregister(timer); 889 return snd_timer_unregister(timer);
873} 890}
874 891
875void snd_timer_notify(snd_timer_t *timer, enum sndrv_timer_event event, struct timespec *tstamp) 892void snd_timer_notify(snd_timer_t *timer, enum sndrv_timer_event event,
893 struct timespec *tstamp)
876{ 894{
877 unsigned long flags; 895 unsigned long flags;
878 unsigned long resolution = 0; 896 unsigned long resolution = 0;
879 snd_timer_instance_t *ti, *ts; 897 snd_timer_instance_t *ti, *ts;
880 struct list_head *p, *n; 898 struct list_head *p, *n;
881 899
882 snd_runtime_check(timer->hw.flags & SNDRV_TIMER_HW_SLAVE, return); 900 if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE))
883 snd_assert(event >= SNDRV_TIMER_EVENT_MSTART && event <= SNDRV_TIMER_EVENT_MRESUME, return); 901 return;
902 snd_assert(event >= SNDRV_TIMER_EVENT_MSTART &&
903 event <= SNDRV_TIMER_EVENT_MRESUME, return);
884 spin_lock_irqsave(&timer->lock, flags); 904 spin_lock_irqsave(&timer->lock, flags);
885 if (event == SNDRV_TIMER_EVENT_MSTART || 905 if (event == SNDRV_TIMER_EVENT_MSTART ||
886 event == SNDRV_TIMER_EVENT_MCONTINUE || 906 event == SNDRV_TIMER_EVENT_MCONTINUE ||
@@ -891,11 +911,11 @@ void snd_timer_notify(snd_timer_t *timer, enum sndrv_timer_event event, struct t
891 resolution = timer->hw.resolution; 911 resolution = timer->hw.resolution;
892 } 912 }
893 list_for_each(p, &timer->active_list_head) { 913 list_for_each(p, &timer->active_list_head) {
894 ti = (snd_timer_instance_t *)list_entry(p, snd_timer_instance_t, active_list); 914 ti = list_entry(p, snd_timer_instance_t, active_list);
895 if (ti->ccallback) 915 if (ti->ccallback)
896 ti->ccallback(ti, event, tstamp, resolution); 916 ti->ccallback(ti, event, tstamp, resolution);
897 list_for_each(n, &ti->slave_active_head) { 917 list_for_each(n, &ti->slave_active_head) {
898 ts = (snd_timer_instance_t *)list_entry(n, snd_timer_instance_t, active_list); 918 ts = list_entry(n, snd_timer_instance_t, active_list);
899 if (ts->ccallback) 919 if (ts->ccallback)
900 ts->ccallback(ts, event, tstamp, resolution); 920 ts->ccallback(ts, event, tstamp, resolution);
901 } 921 }
@@ -909,7 +929,7 @@ void snd_timer_notify(snd_timer_t *timer, enum sndrv_timer_event event, struct t
909int snd_timer_global_new(char *id, int device, snd_timer_t **rtimer) 929int snd_timer_global_new(char *id, int device, snd_timer_t **rtimer)
910{ 930{
911 snd_timer_id_t tid; 931 snd_timer_id_t tid;
912 932
913 tid.dev_class = SNDRV_TIMER_CLASS_GLOBAL; 933 tid.dev_class = SNDRV_TIMER_CLASS_GLOBAL;
914 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; 934 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
915 tid.card = -1; 935 tid.card = -1;
@@ -937,7 +957,7 @@ int snd_timer_global_unregister(snd_timer_t *timer)
937 return snd_timer_unregister(timer); 957 return snd_timer_unregister(timer);
938} 958}
939 959
940/* 960/*
941 * System timer 961 * System timer
942 */ 962 */
943 963
@@ -1013,7 +1033,8 @@ static int snd_timer_register_system(void)
1013 struct snd_timer_system_private *priv; 1033 struct snd_timer_system_private *priv;
1014 int err; 1034 int err;
1015 1035
1016 if ((err = snd_timer_global_new("system", SNDRV_TIMER_GLOBAL_SYSTEM, &timer)) < 0) 1036 err = snd_timer_global_new("system", SNDRV_TIMER_GLOBAL_SYSTEM, &timer);
1037 if (err < 0)
1017 return err; 1038 return err;
1018 strcpy(timer->name, "system timer"); 1039 strcpy(timer->name, "system timer");
1019 timer->hw = snd_timer_system; 1040 timer->hw = snd_timer_system;
@@ -1044,33 +1065,41 @@ static void snd_timer_proc_read(snd_info_entry_t *entry,
1044 1065
1045 down(&register_mutex); 1066 down(&register_mutex);
1046 list_for_each(p, &snd_timer_list) { 1067 list_for_each(p, &snd_timer_list) {
1047 timer = (snd_timer_t *)list_entry(p, snd_timer_t, device_list); 1068 timer = list_entry(p, snd_timer_t, device_list);
1048 switch (timer->tmr_class) { 1069 switch (timer->tmr_class) {
1049 case SNDRV_TIMER_CLASS_GLOBAL: 1070 case SNDRV_TIMER_CLASS_GLOBAL:
1050 snd_iprintf(buffer, "G%i: ", timer->tmr_device); 1071 snd_iprintf(buffer, "G%i: ", timer->tmr_device);
1051 break; 1072 break;
1052 case SNDRV_TIMER_CLASS_CARD: 1073 case SNDRV_TIMER_CLASS_CARD:
1053 snd_iprintf(buffer, "C%i-%i: ", timer->card->number, timer->tmr_device); 1074 snd_iprintf(buffer, "C%i-%i: ",
1075 timer->card->number, timer->tmr_device);
1054 break; 1076 break;
1055 case SNDRV_TIMER_CLASS_PCM: 1077 case SNDRV_TIMER_CLASS_PCM:
1056 snd_iprintf(buffer, "P%i-%i-%i: ", timer->card->number, timer->tmr_device, timer->tmr_subdevice); 1078 snd_iprintf(buffer, "P%i-%i-%i: ", timer->card->number,
1079 timer->tmr_device, timer->tmr_subdevice);
1057 break; 1080 break;
1058 default: 1081 default:
1059 snd_iprintf(buffer, "?%i-%i-%i-%i: ", timer->tmr_class, timer->card ? timer->card->number : -1, timer->tmr_device, timer->tmr_subdevice); 1082 snd_iprintf(buffer, "?%i-%i-%i-%i: ", timer->tmr_class,
1083 timer->card ? timer->card->number : -1,
1084 timer->tmr_device, timer->tmr_subdevice);
1060 } 1085 }
1061 snd_iprintf(buffer, "%s :", timer->name); 1086 snd_iprintf(buffer, "%s :", timer->name);
1062 if (timer->hw.resolution) 1087 if (timer->hw.resolution)
1063 snd_iprintf(buffer, " %lu.%03luus (%lu ticks)", timer->hw.resolution / 1000, timer->hw.resolution % 1000, timer->hw.ticks); 1088 snd_iprintf(buffer, " %lu.%03luus (%lu ticks)",
1089 timer->hw.resolution / 1000,
1090 timer->hw.resolution % 1000,
1091 timer->hw.ticks);
1064 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) 1092 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)
1065 snd_iprintf(buffer, " SLAVE"); 1093 snd_iprintf(buffer, " SLAVE");
1066 snd_iprintf(buffer, "\n"); 1094 snd_iprintf(buffer, "\n");
1067 spin_lock_irqsave(&timer->lock, flags); 1095 spin_lock_irqsave(&timer->lock, flags);
1068 list_for_each(q, &timer->open_list_head) { 1096 list_for_each(q, &timer->open_list_head) {
1069 ti = (snd_timer_instance_t *)list_entry(q, snd_timer_instance_t, open_list); 1097 ti = list_entry(q, snd_timer_instance_t, open_list);
1070 snd_iprintf(buffer, " Client %s : %s : lost interrupts %li\n", 1098 snd_iprintf(buffer, " Client %s : %s\n",
1071 ti->owner ? ti->owner : "unknown", 1099 ti->owner ? ti->owner : "unknown",
1072 ti->flags & (SNDRV_TIMER_IFLG_START|SNDRV_TIMER_IFLG_RUNNING) ? "running" : "stopped", 1100 ti->flags & (SNDRV_TIMER_IFLG_START |
1073 ti->lost); 1101 SNDRV_TIMER_IFLG_RUNNING)
1102 ? "running" : "stopped");
1074 } 1103 }
1075 spin_unlock_irqrestore(&timer->lock, flags); 1104 spin_unlock_irqrestore(&timer->lock, flags);
1076 } 1105 }
@@ -1088,7 +1117,7 @@ static void snd_timer_user_interrupt(snd_timer_instance_t *timeri,
1088 snd_timer_user_t *tu = timeri->callback_data; 1117 snd_timer_user_t *tu = timeri->callback_data;
1089 snd_timer_read_t *r; 1118 snd_timer_read_t *r;
1090 int prev; 1119 int prev;
1091 1120
1092 spin_lock(&tu->qlock); 1121 spin_lock(&tu->qlock);
1093 if (tu->qused > 0) { 1122 if (tu->qused > 0) {
1094 prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; 1123 prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1;
@@ -1113,7 +1142,8 @@ static void snd_timer_user_interrupt(snd_timer_instance_t *timeri,
1113 wake_up(&tu->qchange_sleep); 1142 wake_up(&tu->qchange_sleep);
1114} 1143}
1115 1144
1116static void snd_timer_user_append_to_tqueue(snd_timer_user_t *tu, snd_timer_tread_t *tread) 1145static void snd_timer_user_append_to_tqueue(snd_timer_user_t *tu,
1146 snd_timer_tread_t *tread)
1117{ 1147{
1118 if (tu->qused >= tu->queue_size) { 1148 if (tu->qused >= tu->queue_size) {
1119 tu->overrun++; 1149 tu->overrun++;
@@ -1132,7 +1162,8 @@ static void snd_timer_user_ccallback(snd_timer_instance_t *timeri,
1132 snd_timer_user_t *tu = timeri->callback_data; 1162 snd_timer_user_t *tu = timeri->callback_data;
1133 snd_timer_tread_t r1; 1163 snd_timer_tread_t r1;
1134 1164
1135 if (event >= SNDRV_TIMER_EVENT_START && event <= SNDRV_TIMER_EVENT_PAUSE) 1165 if (event >= SNDRV_TIMER_EVENT_START &&
1166 event <= SNDRV_TIMER_EVENT_PAUSE)
1136 tu->tstamp = *tstamp; 1167 tu->tstamp = *tstamp;
1137 if ((tu->filter & (1 << event)) == 0 || !tu->tread) 1168 if ((tu->filter & (1 << event)) == 0 || !tu->tread)
1138 return; 1169 return;
@@ -1155,15 +1186,17 @@ static void snd_timer_user_tinterrupt(snd_timer_instance_t *timeri,
1155 struct timespec tstamp; 1186 struct timespec tstamp;
1156 int prev, append = 0; 1187 int prev, append = 0;
1157 1188
1158 snd_timestamp_zero(&tstamp); 1189 memset(&tstamp, 0, sizeof(tstamp));
1159 spin_lock(&tu->qlock); 1190 spin_lock(&tu->qlock);
1160 if ((tu->filter & ((1 << SNDRV_TIMER_EVENT_RESOLUTION)|(1 << SNDRV_TIMER_EVENT_TICK))) == 0) { 1191 if ((tu->filter & ((1 << SNDRV_TIMER_EVENT_RESOLUTION) |
1192 (1 << SNDRV_TIMER_EVENT_TICK))) == 0) {
1161 spin_unlock(&tu->qlock); 1193 spin_unlock(&tu->qlock);
1162 return; 1194 return;
1163 } 1195 }
1164 if (tu->last_resolution != resolution || ticks > 0) 1196 if (tu->last_resolution != resolution || ticks > 0)
1165 snd_timestamp_now(&tstamp, 1); 1197 getnstimeofday(&tstamp);
1166 if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) && tu->last_resolution != resolution) { 1198 if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) &&
1199 tu->last_resolution != resolution) {
1167 r1.event = SNDRV_TIMER_EVENT_RESOLUTION; 1200 r1.event = SNDRV_TIMER_EVENT_RESOLUTION;
1168 r1.tstamp = tstamp; 1201 r1.tstamp = tstamp;
1169 r1.val = resolution; 1202 r1.val = resolution;
@@ -1201,7 +1234,7 @@ static void snd_timer_user_tinterrupt(snd_timer_instance_t *timeri,
1201static int snd_timer_user_open(struct inode *inode, struct file *file) 1234static int snd_timer_user_open(struct inode *inode, struct file *file)
1202{ 1235{
1203 snd_timer_user_t *tu; 1236 snd_timer_user_t *tu;
1204 1237
1205 tu = kzalloc(sizeof(*tu), GFP_KERNEL); 1238 tu = kzalloc(sizeof(*tu), GFP_KERNEL);
1206 if (tu == NULL) 1239 if (tu == NULL)
1207 return -ENOMEM; 1240 return -ENOMEM;
@@ -1210,7 +1243,8 @@ static int snd_timer_user_open(struct inode *inode, struct file *file)
1210 init_MUTEX(&tu->tread_sem); 1243 init_MUTEX(&tu->tread_sem);
1211 tu->ticks = 1; 1244 tu->ticks = 1;
1212 tu->queue_size = 128; 1245 tu->queue_size = 128;
1213 tu->queue = (snd_timer_read_t *)kmalloc(tu->queue_size * sizeof(snd_timer_read_t), GFP_KERNEL); 1246 tu->queue = kmalloc(tu->queue_size * sizeof(snd_timer_read_t),
1247 GFP_KERNEL);
1214 if (tu->queue == NULL) { 1248 if (tu->queue == NULL) {
1215 kfree(tu); 1249 kfree(tu);
1216 return -ENOMEM; 1250 return -ENOMEM;
@@ -1259,7 +1293,7 @@ static int snd_timer_user_next_device(snd_timer_id_t __user *_tid)
1259 snd_timer_id_t id; 1293 snd_timer_id_t id;
1260 snd_timer_t *timer; 1294 snd_timer_t *timer;
1261 struct list_head *p; 1295 struct list_head *p;
1262 1296
1263 if (copy_from_user(&id, _tid, sizeof(id))) 1297 if (copy_from_user(&id, _tid, sizeof(id)))
1264 return -EFAULT; 1298 return -EFAULT;
1265 down(&register_mutex); 1299 down(&register_mutex);
@@ -1267,7 +1301,8 @@ static int snd_timer_user_next_device(snd_timer_id_t __user *_tid)
1267 if (list_empty(&snd_timer_list)) 1301 if (list_empty(&snd_timer_list))
1268 snd_timer_user_zero_id(&id); 1302 snd_timer_user_zero_id(&id);
1269 else { 1303 else {
1270 timer = (snd_timer_t *)list_entry(snd_timer_list.next, snd_timer_t, device_list); 1304 timer = list_entry(snd_timer_list.next,
1305 snd_timer_t, device_list);
1271 snd_timer_user_copy_id(&id, timer); 1306 snd_timer_user_copy_id(&id, timer);
1272 } 1307 }
1273 } else { 1308 } else {
@@ -1275,7 +1310,7 @@ static int snd_timer_user_next_device(snd_timer_id_t __user *_tid)
1275 case SNDRV_TIMER_CLASS_GLOBAL: 1310 case SNDRV_TIMER_CLASS_GLOBAL:
1276 id.device = id.device < 0 ? 0 : id.device + 1; 1311 id.device = id.device < 0 ? 0 : id.device + 1;
1277 list_for_each(p, &snd_timer_list) { 1312 list_for_each(p, &snd_timer_list) {
1278 timer = (snd_timer_t *)list_entry(p, snd_timer_t, device_list); 1313 timer = list_entry(p, snd_timer_t, device_list);
1279 if (timer->tmr_class > SNDRV_TIMER_CLASS_GLOBAL) { 1314 if (timer->tmr_class > SNDRV_TIMER_CLASS_GLOBAL) {
1280 snd_timer_user_copy_id(&id, timer); 1315 snd_timer_user_copy_id(&id, timer);
1281 break; 1316 break;
@@ -1299,12 +1334,16 @@ static int snd_timer_user_next_device(snd_timer_id_t __user *_tid)
1299 if (id.device < 0) { 1334 if (id.device < 0) {
1300 id.device = 0; 1335 id.device = 0;
1301 } else { 1336 } else {
1302 id.subdevice = id.subdevice < 0 ? 0 : id.subdevice + 1; 1337 if (id.subdevice < 0) {
1338 id.subdevice = 0;
1339 } else {
1340 id.subdevice++;
1341 }
1303 } 1342 }
1304 } 1343 }
1305 } 1344 }
1306 list_for_each(p, &snd_timer_list) { 1345 list_for_each(p, &snd_timer_list) {
1307 timer = (snd_timer_t *)list_entry(p, snd_timer_t, device_list); 1346 timer = list_entry(p, snd_timer_t, device_list);
1308 if (timer->tmr_class > id.dev_class) { 1347 if (timer->tmr_class > id.dev_class) {
1309 snd_timer_user_copy_id(&id, timer); 1348 snd_timer_user_copy_id(&id, timer);
1310 break; 1349 break;
@@ -1343,9 +1382,10 @@ static int snd_timer_user_next_device(snd_timer_id_t __user *_tid)
1343 if (copy_to_user(_tid, &id, sizeof(*_tid))) 1382 if (copy_to_user(_tid, &id, sizeof(*_tid)))
1344 return -EFAULT; 1383 return -EFAULT;
1345 return 0; 1384 return 0;
1346} 1385}
1347 1386
1348static int snd_timer_user_ginfo(struct file *file, snd_timer_ginfo_t __user *_ginfo) 1387static int snd_timer_user_ginfo(struct file *file,
1388 snd_timer_ginfo_t __user *_ginfo)
1349{ 1389{
1350 snd_timer_ginfo_t *ginfo; 1390 snd_timer_ginfo_t *ginfo;
1351 snd_timer_id_t tid; 1391 snd_timer_id_t tid;
@@ -1389,7 +1429,8 @@ static int snd_timer_user_ginfo(struct file *file, snd_timer_ginfo_t __user *_gi
1389 return err; 1429 return err;
1390} 1430}
1391 1431
1392static int snd_timer_user_gparams(struct file *file, snd_timer_gparams_t __user *_gparams) 1432static int snd_timer_user_gparams(struct file *file,
1433 snd_timer_gparams_t __user *_gparams)
1393{ 1434{
1394 snd_timer_gparams_t gparams; 1435 snd_timer_gparams_t gparams;
1395 snd_timer_t *t; 1436 snd_timer_t *t;
@@ -1399,23 +1440,26 @@ static int snd_timer_user_gparams(struct file *file, snd_timer_gparams_t __user
1399 return -EFAULT; 1440 return -EFAULT;
1400 down(&register_mutex); 1441 down(&register_mutex);
1401 t = snd_timer_find(&gparams.tid); 1442 t = snd_timer_find(&gparams.tid);
1402 if (t != NULL) { 1443 if (!t) {
1403 if (list_empty(&t->open_list_head)) {
1404 if (t->hw.set_period)
1405 err = t->hw.set_period(t, gparams.period_num, gparams.period_den);
1406 else
1407 err = -ENOSYS;
1408 } else {
1409 err = -EBUSY;
1410 }
1411 } else {
1412 err = -ENODEV; 1444 err = -ENODEV;
1445 goto _error;
1446 }
1447 if (!list_empty(&t->open_list_head)) {
1448 err = -EBUSY;
1449 goto _error;
1413 } 1450 }
1451 if (!t->hw.set_period) {
1452 err = -ENOSYS;
1453 goto _error;
1454 }
1455 err = t->hw.set_period(t, gparams.period_num, gparams.period_den);
1456_error:
1414 up(&register_mutex); 1457 up(&register_mutex);
1415 return err; 1458 return err;
1416} 1459}
1417 1460
1418static int snd_timer_user_gstatus(struct file *file, snd_timer_gstatus_t __user *_gstatus) 1461static int snd_timer_user_gstatus(struct file *file,
1462 snd_timer_gstatus_t __user *_gstatus)
1419{ 1463{
1420 snd_timer_gstatus_t gstatus; 1464 snd_timer_gstatus_t gstatus;
1421 snd_timer_id_t tid; 1465 snd_timer_id_t tid;
@@ -1435,7 +1479,8 @@ static int snd_timer_user_gstatus(struct file *file, snd_timer_gstatus_t __user
1435 else 1479 else
1436 gstatus.resolution = t->hw.resolution; 1480 gstatus.resolution = t->hw.resolution;
1437 if (t->hw.precise_resolution) { 1481 if (t->hw.precise_resolution) {
1438 t->hw.precise_resolution(t, &gstatus.resolution_num, &gstatus.resolution_den); 1482 t->hw.precise_resolution(t, &gstatus.resolution_num,
1483 &gstatus.resolution_den);
1439 } else { 1484 } else {
1440 gstatus.resolution_num = gstatus.resolution; 1485 gstatus.resolution_num = gstatus.resolution;
1441 gstatus.resolution_den = 1000000000uL; 1486 gstatus.resolution_den = 1000000000uL;
@@ -1449,13 +1494,14 @@ static int snd_timer_user_gstatus(struct file *file, snd_timer_gstatus_t __user
1449 return err; 1494 return err;
1450} 1495}
1451 1496
1452static int snd_timer_user_tselect(struct file *file, snd_timer_select_t __user *_tselect) 1497static int snd_timer_user_tselect(struct file *file,
1498 snd_timer_select_t __user *_tselect)
1453{ 1499{
1454 snd_timer_user_t *tu; 1500 snd_timer_user_t *tu;
1455 snd_timer_select_t tselect; 1501 snd_timer_select_t tselect;
1456 char str[32]; 1502 char str[32];
1457 int err = 0; 1503 int err = 0;
1458 1504
1459 tu = file->private_data; 1505 tu = file->private_data;
1460 down(&tu->tread_sem); 1506 down(&tu->tread_sem);
1461 if (tu->timeri) { 1507 if (tu->timeri) {
@@ -1469,7 +1515,8 @@ static int snd_timer_user_tselect(struct file *file, snd_timer_select_t __user *
1469 sprintf(str, "application %i", current->pid); 1515 sprintf(str, "application %i", current->pid);
1470 if (tselect.id.dev_class != SNDRV_TIMER_CLASS_SLAVE) 1516 if (tselect.id.dev_class != SNDRV_TIMER_CLASS_SLAVE)
1471 tselect.id.dev_sclass = SNDRV_TIMER_SCLASS_APPLICATION; 1517 tselect.id.dev_sclass = SNDRV_TIMER_SCLASS_APPLICATION;
1472 if ((err = snd_timer_open(&tu->timeri, str, &tselect.id, current->pid)) < 0) 1518 err = snd_timer_open(&tu->timeri, str, &tselect.id, current->pid);
1519 if (err < 0)
1473 goto __err; 1520 goto __err;
1474 1521
1475 kfree(tu->queue); 1522 kfree(tu->queue);
@@ -1477,21 +1524,24 @@ static int snd_timer_user_tselect(struct file *file, snd_timer_select_t __user *
1477 kfree(tu->tqueue); 1524 kfree(tu->tqueue);
1478 tu->tqueue = NULL; 1525 tu->tqueue = NULL;
1479 if (tu->tread) { 1526 if (tu->tread) {
1480 tu->tqueue = (snd_timer_tread_t *)kmalloc(tu->queue_size * sizeof(snd_timer_tread_t), GFP_KERNEL); 1527 tu->tqueue = kmalloc(tu->queue_size * sizeof(snd_timer_tread_t),
1528 GFP_KERNEL);
1481 if (tu->tqueue == NULL) 1529 if (tu->tqueue == NULL)
1482 err = -ENOMEM; 1530 err = -ENOMEM;
1483 } else { 1531 } else {
1484 tu->queue = (snd_timer_read_t *)kmalloc(tu->queue_size * sizeof(snd_timer_read_t), GFP_KERNEL); 1532 tu->queue = kmalloc(tu->queue_size * sizeof(snd_timer_read_t),
1533 GFP_KERNEL);
1485 if (tu->queue == NULL) 1534 if (tu->queue == NULL)
1486 err = -ENOMEM; 1535 err = -ENOMEM;
1487 } 1536 }
1488 1537
1489 if (err < 0) { 1538 if (err < 0) {
1490 snd_timer_close(tu->timeri); 1539 snd_timer_close(tu->timeri);
1491 tu->timeri = NULL; 1540 tu->timeri = NULL;
1492 } else { 1541 } else {
1493 tu->timeri->flags |= SNDRV_TIMER_IFLG_FAST; 1542 tu->timeri->flags |= SNDRV_TIMER_IFLG_FAST;
1494 tu->timeri->callback = tu->tread ? snd_timer_user_tinterrupt : snd_timer_user_interrupt; 1543 tu->timeri->callback = tu->tread
1544 ? snd_timer_user_tinterrupt : snd_timer_user_interrupt;
1495 tu->timeri->ccallback = snd_timer_user_ccallback; 1545 tu->timeri->ccallback = snd_timer_user_ccallback;
1496 tu->timeri->callback_data = (void *)tu; 1546 tu->timeri->callback_data = (void *)tu;
1497 } 1547 }
@@ -1501,7 +1551,8 @@ static int snd_timer_user_tselect(struct file *file, snd_timer_select_t __user *
1501 return err; 1551 return err;
1502} 1552}
1503 1553
1504static int snd_timer_user_info(struct file *file, snd_timer_info_t __user *_info) 1554static int snd_timer_user_info(struct file *file,
1555 snd_timer_info_t __user *_info)
1505{ 1556{
1506 snd_timer_user_t *tu; 1557 snd_timer_user_t *tu;
1507 snd_timer_info_t *info; 1558 snd_timer_info_t *info;
@@ -1528,7 +1579,8 @@ static int snd_timer_user_info(struct file *file, snd_timer_info_t __user *_info
1528 return err; 1579 return err;
1529} 1580}
1530 1581
1531static int snd_timer_user_params(struct file *file, snd_timer_params_t __user *_params) 1582static int snd_timer_user_params(struct file *file,
1583 snd_timer_params_t __user *_params)
1532{ 1584{
1533 snd_timer_user_t *tu; 1585 snd_timer_user_t *tu;
1534 snd_timer_params_t params; 1586 snd_timer_params_t params;
@@ -1536,7 +1588,7 @@ static int snd_timer_user_params(struct file *file, snd_timer_params_t __user *_
1536 snd_timer_read_t *tr; 1588 snd_timer_read_t *tr;
1537 snd_timer_tread_t *ttr; 1589 snd_timer_tread_t *ttr;
1538 int err; 1590 int err;
1539 1591
1540 tu = file->private_data; 1592 tu = file->private_data;
1541 snd_assert(tu->timeri != NULL, return -ENXIO); 1593 snd_assert(tu->timeri != NULL, return -ENXIO);
1542 t = tu->timeri->timer; 1594 t = tu->timeri->timer;
@@ -1547,7 +1599,8 @@ static int snd_timer_user_params(struct file *file, snd_timer_params_t __user *_
1547 err = -EINVAL; 1599 err = -EINVAL;
1548 goto _end; 1600 goto _end;
1549 } 1601 }
1550 if (params.queue_size > 0 && (params.queue_size < 32 || params.queue_size > 1024)) { 1602 if (params.queue_size > 0 &&
1603 (params.queue_size < 32 || params.queue_size > 1024)) {
1551 err = -EINVAL; 1604 err = -EINVAL;
1552 goto _end; 1605 goto _end;
1553 } 1606 }
@@ -1580,16 +1633,19 @@ static int snd_timer_user_params(struct file *file, snd_timer_params_t __user *_
1580 if (params.flags & SNDRV_TIMER_PSFLG_EARLY_EVENT) 1633 if (params.flags & SNDRV_TIMER_PSFLG_EARLY_EVENT)
1581 tu->timeri->flags |= SNDRV_TIMER_IFLG_EARLY_EVENT; 1634 tu->timeri->flags |= SNDRV_TIMER_IFLG_EARLY_EVENT;
1582 spin_unlock_irq(&t->lock); 1635 spin_unlock_irq(&t->lock);
1583 if (params.queue_size > 0 && (unsigned int)tu->queue_size != params.queue_size) { 1636 if (params.queue_size > 0 &&
1637 (unsigned int)tu->queue_size != params.queue_size) {
1584 if (tu->tread) { 1638 if (tu->tread) {
1585 ttr = (snd_timer_tread_t *)kmalloc(params.queue_size * sizeof(snd_timer_tread_t), GFP_KERNEL); 1639 ttr = kmalloc(params.queue_size * sizeof(*ttr),
1640 GFP_KERNEL);
1586 if (ttr) { 1641 if (ttr) {
1587 kfree(tu->tqueue); 1642 kfree(tu->tqueue);
1588 tu->queue_size = params.queue_size; 1643 tu->queue_size = params.queue_size;
1589 tu->tqueue = ttr; 1644 tu->tqueue = ttr;
1590 } 1645 }
1591 } else { 1646 } else {
1592 tr = (snd_timer_read_t *)kmalloc(params.queue_size * sizeof(snd_timer_read_t), GFP_KERNEL); 1647 tr = kmalloc(params.queue_size * sizeof(*tr),
1648 GFP_KERNEL);
1593 if (tr) { 1649 if (tr) {
1594 kfree(tu->queue); 1650 kfree(tu->queue);
1595 tu->queue_size = params.queue_size; 1651 tu->queue_size = params.queue_size;
@@ -1613,7 +1669,6 @@ static int snd_timer_user_params(struct file *file, snd_timer_params_t __user *_
1613 tu->qused++; 1669 tu->qused++;
1614 tu->qtail++; 1670 tu->qtail++;
1615 } 1671 }
1616
1617 } 1672 }
1618 tu->filter = params.filter; 1673 tu->filter = params.filter;
1619 tu->ticks = params.ticks; 1674 tu->ticks = params.ticks;
@@ -1624,11 +1679,12 @@ static int snd_timer_user_params(struct file *file, snd_timer_params_t __user *_
1624 return err; 1679 return err;
1625} 1680}
1626 1681
1627static int snd_timer_user_status(struct file *file, snd_timer_status_t __user *_status) 1682static int snd_timer_user_status(struct file *file,
1683 snd_timer_status_t __user *_status)
1628{ 1684{
1629 snd_timer_user_t *tu; 1685 snd_timer_user_t *tu;
1630 snd_timer_status_t status; 1686 snd_timer_status_t status;
1631 1687
1632 tu = file->private_data; 1688 tu = file->private_data;
1633 snd_assert(tu->timeri != NULL, return -ENXIO); 1689 snd_assert(tu->timeri != NULL, return -ENXIO);
1634 memset(&status, 0, sizeof(status)); 1690 memset(&status, 0, sizeof(status));
@@ -1648,7 +1704,7 @@ static int snd_timer_user_start(struct file *file)
1648{ 1704{
1649 int err; 1705 int err;
1650 snd_timer_user_t *tu; 1706 snd_timer_user_t *tu;
1651 1707
1652 tu = file->private_data; 1708 tu = file->private_data;
1653 snd_assert(tu->timeri != NULL, return -ENXIO); 1709 snd_assert(tu->timeri != NULL, return -ENXIO);
1654 snd_timer_stop(tu->timeri); 1710 snd_timer_stop(tu->timeri);
@@ -1661,7 +1717,7 @@ static int snd_timer_user_stop(struct file *file)
1661{ 1717{
1662 int err; 1718 int err;
1663 snd_timer_user_t *tu; 1719 snd_timer_user_t *tu;
1664 1720
1665 tu = file->private_data; 1721 tu = file->private_data;
1666 snd_assert(tu->timeri != NULL, return -ENXIO); 1722 snd_assert(tu->timeri != NULL, return -ENXIO);
1667 return (err = snd_timer_stop(tu->timeri)) < 0 ? err : 0; 1723 return (err = snd_timer_stop(tu->timeri)) < 0 ? err : 0;
@@ -1671,7 +1727,7 @@ static int snd_timer_user_continue(struct file *file)
1671{ 1727{
1672 int err; 1728 int err;
1673 snd_timer_user_t *tu; 1729 snd_timer_user_t *tu;
1674 1730
1675 tu = file->private_data; 1731 tu = file->private_data;
1676 snd_assert(tu->timeri != NULL, return -ENXIO); 1732 snd_assert(tu->timeri != NULL, return -ENXIO);
1677 tu->timeri->lost = 0; 1733 tu->timeri->lost = 0;
@@ -1682,7 +1738,7 @@ static int snd_timer_user_pause(struct file *file)
1682{ 1738{
1683 int err; 1739 int err;
1684 snd_timer_user_t *tu; 1740 snd_timer_user_t *tu;
1685 1741
1686 tu = file->private_data; 1742 tu = file->private_data;
1687 snd_assert(tu->timeri != NULL, return -ENXIO); 1743 snd_assert(tu->timeri != NULL, return -ENXIO);
1688 return (err = snd_timer_pause(tu->timeri)) < 0 ? err : 0; 1744 return (err = snd_timer_pause(tu->timeri)) < 0 ? err : 0;
@@ -1695,12 +1751,13 @@ enum {
1695 SNDRV_TIMER_IOCTL_PAUSE_OLD = _IO('T', 0x23), 1751 SNDRV_TIMER_IOCTL_PAUSE_OLD = _IO('T', 0x23),
1696}; 1752};
1697 1753
1698static long snd_timer_user_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 1754static long snd_timer_user_ioctl(struct file *file, unsigned int cmd,
1755 unsigned long arg)
1699{ 1756{
1700 snd_timer_user_t *tu; 1757 snd_timer_user_t *tu;
1701 void __user *argp = (void __user *)arg; 1758 void __user *argp = (void __user *)arg;
1702 int __user *p = argp; 1759 int __user *p = argp;
1703 1760
1704 tu = file->private_data; 1761 tu = file->private_data;
1705 switch (cmd) { 1762 switch (cmd) {
1706 case SNDRV_TIMER_IOCTL_PVERSION: 1763 case SNDRV_TIMER_IOCTL_PVERSION:
@@ -1710,7 +1767,7 @@ static long snd_timer_user_ioctl(struct file *file, unsigned int cmd, unsigned l
1710 case SNDRV_TIMER_IOCTL_TREAD: 1767 case SNDRV_TIMER_IOCTL_TREAD:
1711 { 1768 {
1712 int xarg; 1769 int xarg;
1713 1770
1714 down(&tu->tread_sem); 1771 down(&tu->tread_sem);
1715 if (tu->timeri) { /* too late */ 1772 if (tu->timeri) { /* too late */
1716 up(&tu->tread_sem); 1773 up(&tu->tread_sem);
@@ -1758,7 +1815,7 @@ static int snd_timer_user_fasync(int fd, struct file * file, int on)
1758{ 1815{
1759 snd_timer_user_t *tu; 1816 snd_timer_user_t *tu;
1760 int err; 1817 int err;
1761 1818
1762 tu = file->private_data; 1819 tu = file->private_data;
1763 err = fasync_helper(fd, file, on, &tu->fasync); 1820 err = fasync_helper(fd, file, on, &tu->fasync);
1764 if (err < 0) 1821 if (err < 0)
@@ -1766,12 +1823,13 @@ static int snd_timer_user_fasync(int fd, struct file * file, int on)
1766 return 0; 1823 return 0;
1767} 1824}
1768 1825
1769static ssize_t snd_timer_user_read(struct file *file, char __user *buffer, size_t count, loff_t *offset) 1826static ssize_t snd_timer_user_read(struct file *file, char __user *buffer,
1827 size_t count, loff_t *offset)
1770{ 1828{
1771 snd_timer_user_t *tu; 1829 snd_timer_user_t *tu;
1772 long result = 0, unit; 1830 long result = 0, unit;
1773 int err = 0; 1831 int err = 0;
1774 1832
1775 tu = file->private_data; 1833 tu = file->private_data;
1776 unit = tu->tread ? sizeof(snd_timer_tread_t) : sizeof(snd_timer_read_t); 1834 unit = tu->tread ? sizeof(snd_timer_tread_t) : sizeof(snd_timer_read_t);
1777 spin_lock_irq(&tu->qlock); 1835 spin_lock_irq(&tu->qlock);
@@ -1805,12 +1863,14 @@ static ssize_t snd_timer_user_read(struct file *file, char __user *buffer, size_
1805 goto _error; 1863 goto _error;
1806 1864
1807 if (tu->tread) { 1865 if (tu->tread) {
1808 if (copy_to_user(buffer, &tu->tqueue[tu->qhead++], sizeof(snd_timer_tread_t))) { 1866 if (copy_to_user(buffer, &tu->tqueue[tu->qhead++],
1867 sizeof(snd_timer_tread_t))) {
1809 err = -EFAULT; 1868 err = -EFAULT;
1810 goto _error; 1869 goto _error;
1811 } 1870 }
1812 } else { 1871 } else {
1813 if (copy_to_user(buffer, &tu->queue[tu->qhead++], sizeof(snd_timer_read_t))) { 1872 if (copy_to_user(buffer, &tu->queue[tu->qhead++],
1873 sizeof(snd_timer_read_t))) {
1814 err = -EFAULT; 1874 err = -EFAULT;
1815 goto _error; 1875 goto _error;
1816 } 1876 }
@@ -1837,7 +1897,7 @@ static unsigned int snd_timer_user_poll(struct file *file, poll_table * wait)
1837 tu = file->private_data; 1897 tu = file->private_data;
1838 1898
1839 poll_wait(file, &tu->qchange_sleep, wait); 1899 poll_wait(file, &tu->qchange_sleep, wait);
1840 1900
1841 mask = 0; 1901 mask = 0;
1842 if (tu->qused) 1902 if (tu->qused)
1843 mask |= POLLIN | POLLRDNORM; 1903 mask |= POLLIN | POLLRDNORM;
@@ -1881,9 +1941,11 @@ static int __init alsa_timer_init(void)
1881 snd_info_entry_t *entry; 1941 snd_info_entry_t *entry;
1882 1942
1883#ifdef SNDRV_OSS_INFO_DEV_TIMERS 1943#ifdef SNDRV_OSS_INFO_DEV_TIMERS
1884 snd_oss_info_register(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1, "system timer"); 1944 snd_oss_info_register(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1,
1945 "system timer");
1885#endif 1946#endif
1886 if ((entry = snd_info_create_module_entry(THIS_MODULE, "timers", NULL)) != NULL) { 1947 entry = snd_info_create_module_entry(THIS_MODULE, "timers", NULL);
1948 if (entry != NULL) {
1887 entry->c.text.read_size = SNDRV_TIMER_DEVICES * 128; 1949 entry->c.text.read_size = SNDRV_TIMER_DEVICES * 128;
1888 entry->c.text.read = snd_timer_proc_read; 1950 entry->c.text.read = snd_timer_proc_read;
1889 if (snd_info_register(entry) < 0) { 1951 if (snd_info_register(entry) < 0) {
@@ -1893,10 +1955,12 @@ static int __init alsa_timer_init(void)
1893 } 1955 }
1894 snd_timer_proc_entry = entry; 1956 snd_timer_proc_entry = entry;
1895 if ((err = snd_timer_register_system()) < 0) 1957 if ((err = snd_timer_register_system()) < 0)
1896 snd_printk(KERN_ERR "unable to register system timer (%i)\n", err); 1958 snd_printk(KERN_ERR "unable to register system timer (%i)\n",
1959 err);
1897 if ((err = snd_register_device(SNDRV_DEVICE_TYPE_TIMER, 1960 if ((err = snd_register_device(SNDRV_DEVICE_TYPE_TIMER,
1898 NULL, 0, &snd_timer_reg, "timer"))<0) 1961 NULL, 0, &snd_timer_reg, "timer"))<0)
1899 snd_printk(KERN_ERR "unable to register timer device (%i)\n", err); 1962 snd_printk(KERN_ERR "unable to register timer device (%i)\n",
1963 err);
1900 return 0; 1964 return 0;
1901} 1965}
1902 1966
@@ -1907,7 +1971,7 @@ static void __exit alsa_timer_exit(void)
1907 snd_unregister_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0); 1971 snd_unregister_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0);
1908 /* unregister the system timer */ 1972 /* unregister the system timer */
1909 list_for_each_safe(p, n, &snd_timer_list) { 1973 list_for_each_safe(p, n, &snd_timer_list) {
1910 snd_timer_t *timer = (snd_timer_t *)list_entry(p, snd_timer_t, device_list); 1974 snd_timer_t *timer = list_entry(p, snd_timer_t, device_list);
1911 snd_timer_unregister(timer); 1975 snd_timer_unregister(timer);
1912 } 1976 }
1913 if (snd_timer_proc_entry) { 1977 if (snd_timer_proc_entry) {
diff --git a/sound/core/wrappers.c b/sound/core/wrappers.c
deleted file mode 100644
index 296b716f1376..000000000000
--- a/sound/core/wrappers.c
+++ /dev/null
@@ -1,50 +0,0 @@
1/*
2 * Various wrappers
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include <linux/config.h>
23#include <linux/module.h>
24#include <linux/slab.h>
25#include <linux/ioport.h>
26#include <linux/vmalloc.h>
27#include <linux/fs.h>
28
29#ifdef CONFIG_SND_DEBUG_MEMORY
30void *snd_wrapper_kmalloc(size_t size, gfp_t flags)
31{
32 return kmalloc(size, flags);
33}
34
35void snd_wrapper_kfree(const void *obj)
36{
37 kfree(obj);
38}
39
40void *snd_wrapper_vmalloc(unsigned long size)
41{
42 return vmalloc(size);
43}
44
45void snd_wrapper_vfree(void *obj)
46{
47 vfree(obj);
48}
49#endif
50
diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
index fe3f921ffbe3..bdeb2c00dac5 100644
--- a/sound/drivers/mpu401/mpu401_uart.c
+++ b/sound/drivers/mpu401/mpu401_uart.c
@@ -423,10 +423,7 @@ static void snd_mpu401_uart_free(snd_rawmidi_t *rmidi)
423 mpu401_t *mpu = rmidi->private_data; 423 mpu401_t *mpu = rmidi->private_data;
424 if (mpu->irq_flags && mpu->irq >= 0) 424 if (mpu->irq_flags && mpu->irq >= 0)
425 free_irq(mpu->irq, (void *) mpu); 425 free_irq(mpu->irq, (void *) mpu);
426 if (mpu->res) { 426 release_and_free_resource(mpu->res);
427 release_resource(mpu->res);
428 kfree_nocheck(mpu->res);
429 }
430 kfree(mpu); 427 kfree(mpu);
431} 428}
432 429
diff --git a/sound/drivers/mtpav.c b/sound/drivers/mtpav.c
index 3a25c89d2983..e9d52c668edc 100644
--- a/sound/drivers/mtpav.c
+++ b/sound/drivers/mtpav.c
@@ -717,10 +717,7 @@ static void free_mtpav(mtpav_t * crd)
717 spin_unlock_irqrestore(&crd->spinlock, flags); 717 spin_unlock_irqrestore(&crd->spinlock, flags);
718 if (crd->irq >= 0) 718 if (crd->irq >= 0)
719 free_irq(crd->irq, (void *)crd); 719 free_irq(crd->irq, (void *)crd);
720 if (crd->res_port) { 720 release_and_free_resource(crd->res_port);
721 release_resource(crd->res_port);
722 kfree_nocheck(crd->res_port);
723 }
724 kfree(crd); 721 kfree(crd);
725} 722}
726 723
diff --git a/sound/drivers/opl3/opl3_lib.c b/sound/drivers/opl3/opl3_lib.c
index 1f84d78260de..06246503083c 100644
--- a/sound/drivers/opl3/opl3_lib.c
+++ b/sound/drivers/opl3/opl3_lib.c
@@ -325,14 +325,8 @@ static int snd_opl3_free(opl3_t *opl3)
325 snd_assert(opl3 != NULL, return -ENXIO); 325 snd_assert(opl3 != NULL, return -ENXIO);
326 if (opl3->private_free) 326 if (opl3->private_free)
327 opl3->private_free(opl3); 327 opl3->private_free(opl3);
328 if (opl3->res_l_port) { 328 release_and_free_resource(opl3->res_l_port);
329 release_resource(opl3->res_l_port); 329 release_and_free_resource(opl3->res_r_port);
330 kfree_nocheck(opl3->res_l_port);
331 }
332 if (opl3->res_r_port) {
333 release_resource(opl3->res_r_port);
334 kfree_nocheck(opl3->res_r_port);
335 }
336 kfree(opl3); 330 kfree(opl3);
337 return 0; 331 return 0;
338} 332}
diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
index 380c2c704c54..4ae5dd8f011e 100644
--- a/sound/drivers/opl4/opl4_lib.c
+++ b/sound/drivers/opl4/opl4_lib.c
@@ -169,14 +169,8 @@ static void snd_opl4_free(opl4_t *opl4)
169#ifdef CONFIG_PROC_FS 169#ifdef CONFIG_PROC_FS
170 snd_opl4_free_proc(opl4); 170 snd_opl4_free_proc(opl4);
171#endif 171#endif
172 if (opl4->res_fm_port) { 172 release_and_free_resource(opl4->res_fm_port);
173 release_resource(opl4->res_fm_port); 173 release_and_free_resource(opl4->res_pcm_port);
174 kfree_nocheck(opl4->res_fm_port);
175 }
176 if (opl4->res_pcm_port) {
177 release_resource(opl4->res_pcm_port);
178 kfree_nocheck(opl4->res_pcm_port);
179 }
180 kfree(opl4); 174 kfree(opl4);
181} 175}
182 176
diff --git a/sound/drivers/serial-u16550.c b/sound/drivers/serial-u16550.c
index 416172ea1f47..1ed58df42671 100644
--- a/sound/drivers/serial-u16550.c
+++ b/sound/drivers/serial-u16550.c
@@ -749,10 +749,7 @@ static int snd_uart16550_free(snd_uart16550_t *uart)
749{ 749{
750 if (uart->irq >= 0) 750 if (uart->irq >= 0)
751 free_irq(uart->irq, (void *)uart); 751 free_irq(uart->irq, (void *)uart);
752 if (uart->res_base) { 752 release_and_free_resource(uart->res_base);
753 release_resource(uart->res_base);
754 kfree_nocheck(uart->res_base);
755 }
756 kfree(uart); 753 kfree(uart);
757 return 0; 754 return 0;
758}; 755};
diff --git a/sound/drivers/vx/vx_pcm.c b/sound/drivers/vx/vx_pcm.c
index c2312d912fc7..2b46758fe86f 100644
--- a/sound/drivers/vx/vx_pcm.c
+++ b/sound/drivers/vx/vx_pcm.c
@@ -79,7 +79,7 @@ static int snd_pcm_alloc_vmalloc_buffer(snd_pcm_substream_t *subs, size_t size)
79 /* already allocated */ 79 /* already allocated */
80 if (runtime->dma_bytes >= size) 80 if (runtime->dma_bytes >= size)
81 return 0; /* already enough large */ 81 return 0; /* already enough large */
82 vfree_nocheck(runtime->dma_area); /* bypass the memory wrapper */ 82 vfree(runtime->dma_area);
83 } 83 }
84 runtime->dma_area = vmalloc_32(size); 84 runtime->dma_area = vmalloc_32(size);
85 if (! runtime->dma_area) 85 if (! runtime->dma_area)
@@ -98,7 +98,7 @@ static int snd_pcm_free_vmalloc_buffer(snd_pcm_substream_t *subs)
98{ 98{
99 snd_pcm_runtime_t *runtime = subs->runtime; 99 snd_pcm_runtime_t *runtime = subs->runtime;
100 if (runtime->dma_area) { 100 if (runtime->dma_area) {
101 vfree_nocheck(runtime->dma_area); /* bypass the memory wrapper */ 101 vfree(runtime->dma_area);
102 runtime->dma_area = NULL; 102 runtime->dma_area = NULL;
103 } 103 }
104 return 0; 104 return 0;
diff --git a/sound/i2c/cs8427.c b/sound/i2c/cs8427.c
index a21f7d541f86..1a05cfbdc7c6 100644
--- a/sound/i2c/cs8427.c
+++ b/sound/i2c/cs8427.c
@@ -75,7 +75,7 @@ int snd_cs8427_reg_write(snd_i2c_device_t *device, unsigned char reg, unsigned c
75 buf[0] = reg & 0x7f; 75 buf[0] = reg & 0x7f;
76 buf[1] = val; 76 buf[1] = val;
77 if ((err = snd_i2c_sendbytes(device, buf, 2)) != 2) { 77 if ((err = snd_i2c_sendbytes(device, buf, 2)) != 2) {
78 snd_printk("unable to send bytes 0x%02x:0x%02x to CS8427 (%i)\n", buf[0], buf[1], err); 78 snd_printk(KERN_ERR "unable to send bytes 0x%02x:0x%02x to CS8427 (%i)\n", buf[0], buf[1], err);
79 return err < 0 ? err : -EIO; 79 return err < 0 ? err : -EIO;
80 } 80 }
81 return 0; 81 return 0;
@@ -87,11 +87,11 @@ static int snd_cs8427_reg_read(snd_i2c_device_t *device, unsigned char reg)
87 unsigned char buf; 87 unsigned char buf;
88 88
89 if ((err = snd_i2c_sendbytes(device, &reg, 1)) != 1) { 89 if ((err = snd_i2c_sendbytes(device, &reg, 1)) != 1) {
90 snd_printk("unable to send register 0x%x byte to CS8427\n", reg); 90 snd_printk(KERN_ERR "unable to send register 0x%x byte to CS8427\n", reg);
91 return err < 0 ? err : -EIO; 91 return err < 0 ? err : -EIO;
92 } 92 }
93 if ((err = snd_i2c_readbytes(device, &buf, 1)) != 1) { 93 if ((err = snd_i2c_readbytes(device, &buf, 1)) != 1) {
94 snd_printk("unable to read register 0x%x byte from CS8427\n", reg); 94 snd_printk(KERN_ERR "unable to read register 0x%x byte from CS8427\n", reg);
95 return err < 0 ? err : -EIO; 95 return err < 0 ? err : -EIO;
96 } 96 }
97 return buf; 97 return buf;
@@ -210,7 +210,7 @@ int snd_cs8427_create(snd_i2c_bus_t *bus,
210 snd_i2c_lock(bus); 210 snd_i2c_lock(bus);
211 if ((err = snd_cs8427_reg_read(device, CS8427_REG_ID_AND_VER)) != CS8427_VER8427A) { 211 if ((err = snd_cs8427_reg_read(device, CS8427_REG_ID_AND_VER)) != CS8427_VER8427A) {
212 snd_i2c_unlock(bus); 212 snd_i2c_unlock(bus);
213 snd_printk("unable to find CS8427 signature (expected 0x%x, read 0x%x), initialization is not completed\n", CS8427_VER8427A, err); 213 snd_printk(KERN_ERR "unable to find CS8427 signature (expected 0x%x, read 0x%x), initialization is not completed\n", CS8427_VER8427A, err);
214 return -EFAULT; 214 return -EFAULT;
215 } 215 }
216 /* turn off run bit while making changes to configuration */ 216 /* turn off run bit while making changes to configuration */
@@ -260,7 +260,7 @@ int snd_cs8427_create(snd_i2c_bus_t *bus,
260 snd_i2c_sendbytes(device, buf, 1); 260 snd_i2c_sendbytes(device, buf, 1);
261 snd_i2c_readbytes(device, buf, 127); 261 snd_i2c_readbytes(device, buf, 127);
262 for (xx = 0; xx < 127; xx++) 262 for (xx = 0; xx < 127; xx++)
263 printk("reg[0x%x] = 0x%x\n", xx+1, buf[xx]); 263 printk(KERN_DEBUG "reg[0x%x] = 0x%x\n", xx+1, buf[xx]);
264 } 264 }
265#endif 265#endif
266 266
@@ -302,8 +302,7 @@ static void snd_cs8427_reset(snd_i2c_device_t *cs8427)
302 snd_i2c_unlock(cs8427->bus); 302 snd_i2c_unlock(cs8427->bus);
303 if (!(data & CS8427_UNLOCK)) 303 if (!(data & CS8427_UNLOCK))
304 break; 304 break;
305 set_current_state(TASK_UNINTERRUPTIBLE); 305 schedule_timeout_uninterruptible(1);
306 schedule_timeout(1);
307 } 306 }
308 snd_i2c_lock(cs8427->bus); 307 snd_i2c_lock(cs8427->bus);
309 chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~CS8427_RXDMASK; 308 chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~CS8427_RXDMASK;
@@ -354,12 +353,12 @@ static int snd_cs8427_qsubcode_get(snd_kcontrol_t *kcontrol,
354 353
355 snd_i2c_lock(device->bus); 354 snd_i2c_lock(device->bus);
356 if ((err = snd_i2c_sendbytes(device, &reg, 1)) != 1) { 355 if ((err = snd_i2c_sendbytes(device, &reg, 1)) != 1) {
357 snd_printk("unable to send register 0x%x byte to CS8427\n", reg); 356 snd_printk(KERN_ERR "unable to send register 0x%x byte to CS8427\n", reg);
358 snd_i2c_unlock(device->bus); 357 snd_i2c_unlock(device->bus);
359 return err < 0 ? err : -EIO; 358 return err < 0 ? err : -EIO;
360 } 359 }
361 if ((err = snd_i2c_readbytes(device, ucontrol->value.bytes.data, 10)) != 10) { 360 if ((err = snd_i2c_readbytes(device, ucontrol->value.bytes.data, 10)) != 10) {
362 snd_printk("unable to read Q-subcode bytes from CS8427\n"); 361 snd_printk(KERN_ERR "unable to read Q-subcode bytes from CS8427\n");
363 snd_i2c_unlock(device->bus); 362 snd_i2c_unlock(device->bus);
364 return err < 0 ? err : -EIO; 363 return err < 0 ? err : -EIO;
365 } 364 }
diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c
index af5eadcddd92..d351b3aa1916 100644
--- a/sound/i2c/other/ak4114.c
+++ b/sound/i2c/other/ak4114.c
@@ -56,9 +56,9 @@ static void reg_dump(ak4114_t *ak4114)
56{ 56{
57 int i; 57 int i;
58 58
59 printk("AK4114 REG DUMP:\n"); 59 printk(KERN_DEBUG "AK4114 REG DUMP:\n");
60 for (i = 0; i < 0x20; i++) 60 for (i = 0; i < 0x20; i++)
61 printk("reg[%02x] = %02x (%02x)\n", i, reg_read(ak4114, i), i < sizeof(ak4114->regmap) ? ak4114->regmap[i] : 0); 61 printk(KERN_DEBUG "reg[%02x] = %02x (%02x)\n", i, reg_read(ak4114, i), i < sizeof(ak4114->regmap) ? ak4114->regmap[i] : 0);
62} 62}
63#endif 63#endif
64 64
@@ -552,7 +552,7 @@ int snd_ak4114_check_rate_and_errors(ak4114_t *ak4114, unsigned int flags)
552 if (!(flags & AK4114_CHECK_NO_RATE) && runtime && runtime->rate != res) { 552 if (!(flags & AK4114_CHECK_NO_RATE) && runtime && runtime->rate != res) {
553 snd_pcm_stream_lock_irqsave(ak4114->capture_substream, _flags); 553 snd_pcm_stream_lock_irqsave(ak4114->capture_substream, _flags);
554 if (snd_pcm_running(ak4114->capture_substream)) { 554 if (snd_pcm_running(ak4114->capture_substream)) {
555 // printk("rate changed (%i <- %i)\n", runtime->rate, res); 555 // printk(KERN_DEBUG "rate changed (%i <- %i)\n", runtime->rate, res);
556 snd_pcm_stop(ak4114->capture_substream, SNDRV_PCM_STATE_DRAINING); 556 snd_pcm_stop(ak4114->capture_substream, SNDRV_PCM_STATE_DRAINING);
557 res = 1; 557 res = 1;
558 } 558 }
diff --git a/sound/i2c/other/ak4117.c b/sound/i2c/other/ak4117.c
index d51b51dd86d6..35b4584483a3 100644
--- a/sound/i2c/other/ak4117.c
+++ b/sound/i2c/other/ak4117.c
@@ -54,9 +54,9 @@ static void reg_dump(ak4117_t *ak4117)
54{ 54{
55 int i; 55 int i;
56 56
57 printk("AK4117 REG DUMP:\n"); 57 printk(KERN_DEBUG "AK4117 REG DUMP:\n");
58 for (i = 0; i < 0x1b; i++) 58 for (i = 0; i < 0x1b; i++)
59 printk("reg[%02x] = %02x (%02x)\n", i, reg_read(ak4117, i), i < sizeof(ak4117->regmap) ? ak4117->regmap[i] : 0); 59 printk(KERN_DEBUG "reg[%02x] = %02x (%02x)\n", i, reg_read(ak4117, i), i < sizeof(ak4117->regmap) ? ak4117->regmap[i] : 0);
60} 60}
61#endif 61#endif
62 62
@@ -477,7 +477,7 @@ int snd_ak4117_check_rate_and_errors(ak4117_t *ak4117, unsigned int flags)
477 goto __rate; 477 goto __rate;
478 rcs0 = reg_read(ak4117, AK4117_REG_RCS0); 478 rcs0 = reg_read(ak4117, AK4117_REG_RCS0);
479 rcs2 = reg_read(ak4117, AK4117_REG_RCS2); 479 rcs2 = reg_read(ak4117, AK4117_REG_RCS2);
480 // printk("AK IRQ: rcs0 = 0x%x, rcs1 = 0x%x, rcs2 = 0x%x\n", rcs0, rcs1, rcs2); 480 // printk(KERN_DEBUG "AK IRQ: rcs0 = 0x%x, rcs1 = 0x%x, rcs2 = 0x%x\n", rcs0, rcs1, rcs2);
481 spin_lock_irqsave(&ak4117->lock, _flags); 481 spin_lock_irqsave(&ak4117->lock, _flags);
482 if (rcs0 & AK4117_PAR) 482 if (rcs0 & AK4117_PAR)
483 ak4117->parity_errors++; 483 ak4117->parity_errors++;
@@ -530,7 +530,7 @@ int snd_ak4117_check_rate_and_errors(ak4117_t *ak4117, unsigned int flags)
530 if (!(flags & AK4117_CHECK_NO_RATE) && runtime && runtime->rate != res) { 530 if (!(flags & AK4117_CHECK_NO_RATE) && runtime && runtime->rate != res) {
531 snd_pcm_stream_lock_irqsave(ak4117->substream, _flags); 531 snd_pcm_stream_lock_irqsave(ak4117->substream, _flags);
532 if (snd_pcm_running(ak4117->substream)) { 532 if (snd_pcm_running(ak4117->substream)) {
533 // printk("rate changed (%i <- %i)\n", runtime->rate, res); 533 // printk(KERN_DEBUG "rate changed (%i <- %i)\n", runtime->rate, res);
534 snd_pcm_stop(ak4117->substream, SNDRV_PCM_STATE_DRAINING); 534 snd_pcm_stop(ak4117->substream, SNDRV_PCM_STATE_DRAINING);
535 wake_up(&runtime->sleep); 535 wake_up(&runtime->sleep);
536 res = 1; 536 res = 1;
diff --git a/sound/i2c/tea6330t.c b/sound/i2c/tea6330t.c
index fd65da654267..4fdd1fb57dfe 100644
--- a/sound/i2c/tea6330t.c
+++ b/sound/i2c/tea6330t.c
@@ -58,7 +58,7 @@ static void snd_tea6330t_set(tea6330t_t *tea,
58 unsigned char addr, unsigned char value) 58 unsigned char addr, unsigned char value)
59{ 59{
60#if 0 60#if 0
61 printk("set - 0x%x/0x%x\n", addr, value); 61 printk(KERN_DEBUG "set - 0x%x/0x%x\n", addr, value);
62#endif 62#endif
63 snd_i2c_write(tea->bus, TEA6330T_ADDR, addr, value, 1); 63 snd_i2c_write(tea->bus, TEA6330T_ADDR, addr, value, 1);
64} 64}
diff --git a/sound/isa/ad1816a/ad1816a_lib.c b/sound/isa/ad1816a/ad1816a_lib.c
index 27a9dcfbba00..7ae02396cae2 100644
--- a/sound/isa/ad1816a/ad1816a_lib.c
+++ b/sound/isa/ad1816a/ad1816a_lib.c
@@ -542,10 +542,7 @@ static int snd_ad1816a_probe(ad1816a_t *chip)
542 542
543static int snd_ad1816a_free(ad1816a_t *chip) 543static int snd_ad1816a_free(ad1816a_t *chip)
544{ 544{
545 if (chip->res_port) { 545 release_and_free_resource(chip->res_port);
546 release_resource(chip->res_port);
547 kfree_nocheck(chip->res_port);
548 }
549 if (chip->irq >= 0) 546 if (chip->irq >= 0)
550 free_irq(chip->irq, (void *) chip); 547 free_irq(chip->irq, (void *) chip);
551 if (chip->dma1 >= 0) { 548 if (chip->dma1 >= 0) {
diff --git a/sound/isa/ad1848/ad1848_lib.c b/sound/isa/ad1848/ad1848_lib.c
index 303861cd03cd..891bacc94f68 100644
--- a/sound/isa/ad1848/ad1848_lib.c
+++ b/sound/isa/ad1848/ad1848_lib.c
@@ -109,7 +109,7 @@ void snd_ad1848_out(ad1848_t *chip,
109 udelay(100); 109 udelay(100);
110#ifdef CONFIG_SND_DEBUG 110#ifdef CONFIG_SND_DEBUG
111 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) 111 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
112 snd_printk("auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); 112 snd_printk(KERN_WARNING "auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
113#endif 113#endif
114 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL)); 114 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
115 outb(chip->image[reg] = value, AD1848P(chip, REG)); 115 outb(chip->image[reg] = value, AD1848P(chip, REG));
@@ -139,7 +139,7 @@ static unsigned char snd_ad1848_in(ad1848_t *chip, unsigned char reg)
139 udelay(100); 139 udelay(100);
140#ifdef CONFIG_SND_DEBUG 140#ifdef CONFIG_SND_DEBUG
141 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) 141 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
142 snd_printk("auto calibration time out - reg = 0x%x\n", reg); 142 snd_printk(KERN_WARNING "auto calibration time out - reg = 0x%x\n", reg);
143#endif 143#endif
144 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL)); 144 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
145 mb(); 145 mb();
@@ -185,13 +185,13 @@ static void snd_ad1848_mce_up(ad1848_t *chip)
185 udelay(100); 185 udelay(100);
186#ifdef CONFIG_SND_DEBUG 186#ifdef CONFIG_SND_DEBUG
187 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) 187 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
188 snd_printk("mce_up - auto calibration time out (0)\n"); 188 snd_printk(KERN_WARNING "mce_up - auto calibration time out (0)\n");
189#endif 189#endif
190 spin_lock_irqsave(&chip->reg_lock, flags); 190 spin_lock_irqsave(&chip->reg_lock, flags);
191 chip->mce_bit |= AD1848_MCE; 191 chip->mce_bit |= AD1848_MCE;
192 timeout = inb(AD1848P(chip, REGSEL)); 192 timeout = inb(AD1848P(chip, REGSEL));
193 if (timeout == 0x80) 193 if (timeout == 0x80)
194 snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port); 194 snd_printk(KERN_WARNING "mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
195 if (!(timeout & AD1848_MCE)) 195 if (!(timeout & AD1848_MCE))
196 outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL)); 196 outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL));
197 spin_unlock_irqrestore(&chip->reg_lock, flags); 197 spin_unlock_irqrestore(&chip->reg_lock, flags);
@@ -214,13 +214,13 @@ static void snd_ad1848_mce_down(ad1848_t *chip)
214#endif 214#endif
215#ifdef CONFIG_SND_DEBUG 215#ifdef CONFIG_SND_DEBUG
216 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) 216 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
217 snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", AD1848P(chip, REGSEL)); 217 snd_printk(KERN_WARNING "mce_down [0x%lx] - auto calibration time out (0)\n", AD1848P(chip, REGSEL));
218#endif 218#endif
219 chip->mce_bit &= ~AD1848_MCE; 219 chip->mce_bit &= ~AD1848_MCE;
220 timeout = inb(AD1848P(chip, REGSEL)); 220 timeout = inb(AD1848P(chip, REGSEL));
221 outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL)); 221 outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL));
222 if (timeout == 0x80) 222 if (timeout == 0x80)
223 snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port); 223 snd_printk(KERN_WARNING "mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
224 if ((timeout & AD1848_MCE) == 0) { 224 if ((timeout & AD1848_MCE) == 0) {
225 spin_unlock_irqrestore(&chip->reg_lock, flags); 225 spin_unlock_irqrestore(&chip->reg_lock, flags);
226 return; 226 return;
@@ -240,11 +240,10 @@ static void snd_ad1848_mce_down(ad1848_t *chip)
240 while (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) { 240 while (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) {
241 spin_unlock_irqrestore(&chip->reg_lock, flags); 241 spin_unlock_irqrestore(&chip->reg_lock, flags);
242 if (time <= 0) { 242 if (time <= 0) {
243 snd_printk("mce_down - auto calibration time out (2)\n"); 243 snd_printk(KERN_ERR "mce_down - auto calibration time out (2)\n");
244 return; 244 return;
245 } 245 }
246 set_current_state(TASK_INTERRUPTIBLE); 246 time = schedule_timeout_interruptible(time);
247 time = schedule_timeout(time);
248 spin_lock_irqsave(&chip->reg_lock, flags); 247 spin_lock_irqsave(&chip->reg_lock, flags);
249 } 248 }
250#if 0 249#if 0
@@ -254,11 +253,10 @@ static void snd_ad1848_mce_down(ad1848_t *chip)
254 while (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) { 253 while (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) {
255 spin_unlock_irqrestore(&chip->reg_lock, flags); 254 spin_unlock_irqrestore(&chip->reg_lock, flags);
256 if (time <= 0) { 255 if (time <= 0) {
257 snd_printk("mce_down - auto calibration time out (3)\n"); 256 snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
258 return; 257 return;
259 } 258 }
260 set_current_state(TASK_INTERRUPTIBLE); 259 time = schedule_timeout_interruptible(time);
261 time = schedule_timeout(time);
262 spin_lock_irqsave(&chip->reg_lock, flags); 260 spin_lock_irqsave(&chip->reg_lock, flags);
263 } 261 }
264 spin_unlock_irqrestore(&chip->reg_lock, flags); 262 spin_unlock_irqrestore(&chip->reg_lock, flags);
@@ -846,10 +844,7 @@ static int snd_ad1848_capture_close(snd_pcm_substream_t * substream)
846 844
847static int snd_ad1848_free(ad1848_t *chip) 845static int snd_ad1848_free(ad1848_t *chip)
848{ 846{
849 if (chip->res_port) { 847 release_and_free_resource(chip->res_port);
850 release_resource(chip->res_port);
851 kfree_nocheck(chip->res_port);
852 }
853 if (chip->irq >= 0) 848 if (chip->irq >= 0)
854 free_irq(chip->irq, (void *) chip); 849 free_irq(chip->irq, (void *) chip);
855 if (chip->dma >= 0) { 850 if (chip->dma >= 0) {
diff --git a/sound/isa/cs423x/cs4231_lib.c b/sound/isa/cs423x/cs4231_lib.c
index 32318258cd8e..4af769030beb 100644
--- a/sound/isa/cs423x/cs4231_lib.c
+++ b/sound/isa/cs423x/cs4231_lib.c
@@ -1417,14 +1417,8 @@ static int snd_cs4231_pm_resume(snd_card_t *card)
1417 1417
1418static int snd_cs4231_free(cs4231_t *chip) 1418static int snd_cs4231_free(cs4231_t *chip)
1419{ 1419{
1420 if (chip->res_port) { 1420 release_and_free_resource(chip->res_port);
1421 release_resource(chip->res_port); 1421 release_and_free_resource(chip->res_cport);
1422 kfree_nocheck(chip->res_port);
1423 }
1424 if (chip->res_cport) {
1425 release_resource(chip->res_cport);
1426 kfree_nocheck(chip->res_cport);
1427 }
1428 if (chip->irq >= 0) { 1422 if (chip->irq >= 0) {
1429 disable_irq(chip->irq); 1423 disable_irq(chip->irq);
1430 if (!(chip->hwshare & CS4231_HWSHARE_IRQ)) 1424 if (!(chip->hwshare & CS4231_HWSHARE_IRQ))
diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c
index d28315dc72f7..d60a55e6a0b1 100644
--- a/sound/isa/cs423x/cs4236.c
+++ b/sound/isa/cs423x/cs4236.c
@@ -379,12 +379,8 @@ static void snd_card_cs4236_free(snd_card_t *card)
379{ 379{
380 struct snd_card_cs4236 *acard = (struct snd_card_cs4236 *)card->private_data; 380 struct snd_card_cs4236 *acard = (struct snd_card_cs4236 *)card->private_data;
381 381
382 if (acard) { 382 if (acard)
383 if (acard->res_sb_port) { 383 release_and_free_resource(acard->res_sb_port);
384 release_resource(acard->res_sb_port);
385 kfree_nocheck(acard->res_sb_port);
386 }
387 }
388} 384}
389 385
390#ifdef CONFIG_PNP 386#ifdef CONFIG_PNP
diff --git a/sound/isa/cs423x/cs4236_lib.c b/sound/isa/cs423x/cs4236_lib.c
index 2128d4bdef41..1adb88d5f8f4 100644
--- a/sound/isa/cs423x/cs4236_lib.c
+++ b/sound/isa/cs423x/cs4236_lib.c
@@ -173,7 +173,10 @@ static unsigned char divisor_to_rate_register(unsigned int divisor)
173 case 2117: return 6; 173 case 2117: return 6;
174 case 2558: return 7; 174 case 2558: return 7;
175 default: 175 default:
176 snd_runtime_check(divisor >= 21 && divisor <= 192, return 192); 176 if (divisor < 21 || divisor > 192) {
177 snd_BUG();
178 return 192;
179 }
177 return divisor; 180 return divisor;
178 } 181 }
179} 182}
diff --git a/sound/isa/es1688/es1688_lib.c b/sound/isa/es1688/es1688_lib.c
index aac898765c02..2edc9c9f0445 100644
--- a/sound/isa/es1688/es1688_lib.c
+++ b/sound/isa/es1688/es1688_lib.c
@@ -606,8 +606,7 @@ static int snd_es1688_free(es1688_t *chip)
606{ 606{
607 if (chip->res_port) { 607 if (chip->res_port) {
608 snd_es1688_init(chip, 0); 608 snd_es1688_init(chip, 0);
609 release_resource(chip->res_port); 609 release_and_free_resource(chip->res_port);
610 kfree_nocheck(chip->res_port);
611 } 610 }
612 if (chip->irq >= 0) 611 if (chip->irq >= 0)
613 free_irq(chip->irq, (void *) chip); 612 free_irq(chip->irq, (void *) chip);
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c
index d0ea19f42703..970e2aaade27 100644
--- a/sound/isa/es18xx.c
+++ b/sound/isa/es18xx.c
@@ -173,7 +173,7 @@ static int snd_es18xx_dsp_command(es18xx_t *chip, unsigned char val)
173 outb(val, chip->port + 0x0C); 173 outb(val, chip->port + 0x0C);
174 return 0; 174 return 0;
175 } 175 }
176 snd_printk("dsp_command: timeout (0x%x)\n", val); 176 snd_printk(KERN_ERR "dsp_command: timeout (0x%x)\n", val);
177 return -EINVAL; 177 return -EINVAL;
178} 178}
179 179
@@ -184,7 +184,8 @@ static int snd_es18xx_dsp_get_byte(es18xx_t *chip)
184 for(i = MILLISECOND/10; i; i--) 184 for(i = MILLISECOND/10; i; i--)
185 if (inb(chip->port + 0x0C) & 0x40) 185 if (inb(chip->port + 0x0C) & 0x40)
186 return inb(chip->port + 0x0A); 186 return inb(chip->port + 0x0A);
187 snd_printk("dsp_get_byte failed: 0x%lx = 0x%x!!!\n", chip->port + 0x0A, inb(chip->port + 0x0A)); 187 snd_printk(KERN_ERR "dsp_get_byte failed: 0x%lx = 0x%x!!!\n",
188 chip->port + 0x0A, inb(chip->port + 0x0A));
188 return -ENODEV; 189 return -ENODEV;
189} 190}
190 191
@@ -204,7 +205,7 @@ static int snd_es18xx_write(es18xx_t *chip,
204 end: 205 end:
205 spin_unlock_irqrestore(&chip->reg_lock, flags); 206 spin_unlock_irqrestore(&chip->reg_lock, flags);
206#ifdef REG_DEBUG 207#ifdef REG_DEBUG
207 snd_printk("Reg %02x set to %02x\n", reg, data); 208 snd_printk(KERN_DEBUG "Reg %02x set to %02x\n", reg, data);
208#endif 209#endif
209 return ret; 210 return ret;
210} 211}
@@ -223,7 +224,7 @@ static int snd_es18xx_read(es18xx_t *chip, unsigned char reg)
223 data = snd_es18xx_dsp_get_byte(chip); 224 data = snd_es18xx_dsp_get_byte(chip);
224 ret = data; 225 ret = data;
225#ifdef REG_DEBUG 226#ifdef REG_DEBUG
226 snd_printk("Reg %02x now is %02x (%d)\n", reg, data, ret); 227 snd_printk(KERN_DEBUG "Reg %02x now is %02x (%d)\n", reg, data, ret);
227#endif 228#endif
228 end: 229 end:
229 spin_unlock_irqrestore(&chip->reg_lock, flags); 230 spin_unlock_irqrestore(&chip->reg_lock, flags);
@@ -259,7 +260,8 @@ static int snd_es18xx_bits(es18xx_t *chip, unsigned char reg,
259 if (ret < 0) 260 if (ret < 0)
260 goto end; 261 goto end;
261#ifdef REG_DEBUG 262#ifdef REG_DEBUG
262 snd_printk("Reg %02x was %02x, set to %02x (%d)\n", reg, old, new, ret); 263 snd_printk(KERN_DEBUG "Reg %02x was %02x, set to %02x (%d)\n",
264 reg, old, new, ret);
263#endif 265#endif
264 } 266 }
265 ret = oval; 267 ret = oval;
@@ -277,7 +279,7 @@ static inline void snd_es18xx_mixer_write(es18xx_t *chip,
277 outb(data, chip->port + 0x05); 279 outb(data, chip->port + 0x05);
278 spin_unlock_irqrestore(&chip->mixer_lock, flags); 280 spin_unlock_irqrestore(&chip->mixer_lock, flags);
279#ifdef REG_DEBUG 281#ifdef REG_DEBUG
280 snd_printk("Mixer reg %02x set to %02x\n", reg, data); 282 snd_printk(KERN_DEBUG "Mixer reg %02x set to %02x\n", reg, data);
281#endif 283#endif
282} 284}
283 285
@@ -290,7 +292,7 @@ static inline int snd_es18xx_mixer_read(es18xx_t *chip, unsigned char reg)
290 data = inb(chip->port + 0x05); 292 data = inb(chip->port + 0x05);
291 spin_unlock_irqrestore(&chip->mixer_lock, flags); 293 spin_unlock_irqrestore(&chip->mixer_lock, flags);
292#ifdef REG_DEBUG 294#ifdef REG_DEBUG
293 snd_printk("Mixer reg %02x now is %02x\n", reg, data); 295 snd_printk(KERN_DEBUG "Mixer reg %02x now is %02x\n", reg, data);
294#endif 296#endif
295 return data; 297 return data;
296} 298}
@@ -309,7 +311,8 @@ static inline int snd_es18xx_mixer_bits(es18xx_t *chip, unsigned char reg,
309 new = (old & ~mask) | (val & mask); 311 new = (old & ~mask) | (val & mask);
310 outb(new, chip->port + 0x05); 312 outb(new, chip->port + 0x05);
311#ifdef REG_DEBUG 313#ifdef REG_DEBUG
312 snd_printk("Mixer reg %02x was %02x, set to %02x\n", reg, old, new); 314 snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x\n",
315 reg, old, new);
313#endif 316#endif
314 } 317 }
315 spin_unlock_irqrestore(&chip->mixer_lock, flags); 318 spin_unlock_irqrestore(&chip->mixer_lock, flags);
@@ -329,7 +332,8 @@ static inline int snd_es18xx_mixer_writable(es18xx_t *chip, unsigned char reg,
329 new = inb(chip->port + 0x05); 332 new = inb(chip->port + 0x05);
330 spin_unlock_irqrestore(&chip->mixer_lock, flags); 333 spin_unlock_irqrestore(&chip->mixer_lock, flags);
331#ifdef REG_DEBUG 334#ifdef REG_DEBUG
332 snd_printk("Mixer reg %02x was %02x, set to %02x, now is %02x\n", reg, old, expected, new); 335 snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x, now is %02x\n",
336 reg, old, expected, new);
333#endif 337#endif
334 return expected == new; 338 return expected == new;
335} 339}
@@ -1281,7 +1285,7 @@ static void __devinit snd_es18xx_config_write(es18xx_t *chip,
1281 outb(reg, chip->ctrl_port); 1285 outb(reg, chip->ctrl_port);
1282 outb(data, chip->ctrl_port + 1); 1286 outb(data, chip->ctrl_port + 1);
1283#ifdef REG_DEBUG 1287#ifdef REG_DEBUG
1284 snd_printk("Config reg %02x set to %02x\n", reg, data); 1288 snd_printk(KERN_DEBUG "Config reg %02x set to %02x\n", reg, data);
1285#endif 1289#endif
1286} 1290}
1287 1291
@@ -1346,7 +1350,7 @@ static int __devinit snd_es18xx_initialize(es18xx_t *chip)
1346 irqmask = 3; 1350 irqmask = 3;
1347 break; 1351 break;
1348 default: 1352 default:
1349 snd_printk("invalid irq %d\n", chip->irq); 1353 snd_printk(KERN_ERR "invalid irq %d\n", chip->irq);
1350 return -ENODEV; 1354 return -ENODEV;
1351 } 1355 }
1352 switch (chip->dma1) { 1356 switch (chip->dma1) {
@@ -1360,7 +1364,7 @@ static int __devinit snd_es18xx_initialize(es18xx_t *chip)
1360 dma1mask = 3; 1364 dma1mask = 3;
1361 break; 1365 break;
1362 default: 1366 default:
1363 snd_printk("invalid dma1 %d\n", chip->dma1); 1367 snd_printk(KERN_ERR "invalid dma1 %d\n", chip->dma1);
1364 return -ENODEV; 1368 return -ENODEV;
1365 } 1369 }
1366 switch (chip->dma2) { 1370 switch (chip->dma2) {
@@ -1377,7 +1381,7 @@ static int __devinit snd_es18xx_initialize(es18xx_t *chip)
1377 dma2mask = 3; 1381 dma2mask = 3;
1378 break; 1382 break;
1379 default: 1383 default:
1380 snd_printk("invalid dma2 %d\n", chip->dma2); 1384 snd_printk(KERN_ERR "invalid dma2 %d\n", chip->dma2);
1381 return -ENODEV; 1385 return -ENODEV;
1382 } 1386 }
1383 1387
@@ -1440,7 +1444,7 @@ static int __devinit snd_es18xx_identify(es18xx_t *chip)
1440 1444
1441 /* reset */ 1445 /* reset */
1442 if (snd_es18xx_reset(chip) < 0) { 1446 if (snd_es18xx_reset(chip) < 0) {
1443 snd_printk("reset at 0x%lx failed!!!\n", chip->port); 1447 snd_printk(KERN_ERR "reset at 0x%lx failed!!!\n", chip->port);
1444 return -ENODEV; 1448 return -ENODEV;
1445 } 1449 }
1446 1450
@@ -1527,7 +1531,7 @@ static int __devinit snd_es18xx_probe(es18xx_t *chip)
1527 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_HWV; 1531 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_HWV;
1528 break; 1532 break;
1529 default: 1533 default:
1530 snd_printk("[0x%lx] unsupported chip ES%x\n", 1534 snd_printk(KERN_ERR "[0x%lx] unsupported chip ES%x\n",
1531 chip->port, chip->version); 1535 chip->port, chip->version);
1532 return -ENODEV; 1536 return -ENODEV;
1533 } 1537 }
@@ -1640,18 +1644,9 @@ static int snd_es18xx_resume(snd_card_t *card)
1640 1644
1641static int snd_es18xx_free(es18xx_t *chip) 1645static int snd_es18xx_free(es18xx_t *chip)
1642{ 1646{
1643 if (chip->res_port) { 1647 release_and_free_resource(chip->res_port);
1644 release_resource(chip->res_port); 1648 release_and_free_resource(chip->res_ctrl_port);
1645 kfree_nocheck(chip->res_port); 1649 release_and_free_resource(chip->res_mpu_port);
1646 }
1647 if (chip->res_ctrl_port) {
1648 release_resource(chip->res_ctrl_port);
1649 kfree_nocheck(chip->res_ctrl_port);
1650 }
1651 if (chip->res_mpu_port) {
1652 release_resource(chip->res_mpu_port);
1653 kfree_nocheck(chip->res_mpu_port);
1654 }
1655 if (chip->irq >= 0) 1650 if (chip->irq >= 0)
1656 free_irq(chip->irq, (void *) chip); 1651 free_irq(chip->irq, (void *) chip);
1657 if (chip->dma1 >= 0) { 1652 if (chip->dma1 >= 0) {
diff --git a/sound/isa/gus/gus_dma.c b/sound/isa/gus/gus_dma.c
index de4b56d80b35..ef1b2e9832e4 100644
--- a/sound/isa/gus/gus_dma.c
+++ b/sound/isa/gus/gus_dma.c
@@ -199,7 +199,7 @@ int snd_gf1_dma_transfer_block(snd_gus_card_t * gus,
199 199
200 block = kmalloc(sizeof(*block), atomic ? GFP_ATOMIC : GFP_KERNEL); 200 block = kmalloc(sizeof(*block), atomic ? GFP_ATOMIC : GFP_KERNEL);
201 if (block == NULL) { 201 if (block == NULL) {
202 snd_printk("gf1: DMA transfer failure; not enough memory\n"); 202 snd_printk(KERN_ERR "gf1: DMA transfer failure; not enough memory\n");
203 return -ENOMEM; 203 return -ENOMEM;
204 } 204 }
205 *block = *__block; 205 *block = *__block;
diff --git a/sound/isa/gus/gus_io.c b/sound/isa/gus/gus_io.c
index 23e1b5f19e1a..8d5752b23787 100644
--- a/sound/isa/gus/gus_io.c
+++ b/sound/isa/gus/gus_io.c
@@ -343,7 +343,7 @@ void snd_gf1_pokew(snd_gus_card_t * gus, unsigned int addr, unsigned short data)
343 343
344#ifdef CONFIG_SND_DEBUG 344#ifdef CONFIG_SND_DEBUG
345 if (!gus->interwave) 345 if (!gus->interwave)
346 snd_printk("snd_gf1_pokew - GF1!!!\n"); 346 snd_printk(KERN_DEBUG "snd_gf1_pokew - GF1!!!\n");
347#endif 347#endif
348 spin_lock_irqsave(&gus->reg_lock, flags); 348 spin_lock_irqsave(&gus->reg_lock, flags);
349 outb(SNDRV_GF1_GW_DRAM_IO_LOW, gus->gf1.reg_regsel); 349 outb(SNDRV_GF1_GW_DRAM_IO_LOW, gus->gf1.reg_regsel);
@@ -367,7 +367,7 @@ unsigned short snd_gf1_peekw(snd_gus_card_t * gus, unsigned int addr)
367 367
368#ifdef CONFIG_SND_DEBUG 368#ifdef CONFIG_SND_DEBUG
369 if (!gus->interwave) 369 if (!gus->interwave)
370 snd_printk("snd_gf1_peekw - GF1!!!\n"); 370 snd_printk(KERN_DEBUG "snd_gf1_peekw - GF1!!!\n");
371#endif 371#endif
372 spin_lock_irqsave(&gus->reg_lock, flags); 372 spin_lock_irqsave(&gus->reg_lock, flags);
373 outb(SNDRV_GF1_GW_DRAM_IO_LOW, gus->gf1.reg_regsel); 373 outb(SNDRV_GF1_GW_DRAM_IO_LOW, gus->gf1.reg_regsel);
@@ -393,7 +393,7 @@ void snd_gf1_dram_setmem(snd_gus_card_t * gus, unsigned int addr,
393 393
394#ifdef CONFIG_SND_DEBUG 394#ifdef CONFIG_SND_DEBUG
395 if (!gus->interwave) 395 if (!gus->interwave)
396 snd_printk("snd_gf1_dram_setmem - GF1!!!\n"); 396 snd_printk(KERN_DEBUG "snd_gf1_dram_setmem - GF1!!!\n");
397#endif 397#endif
398 addr &= ~1; 398 addr &= ~1;
399 count >>= 1; 399 count >>= 1;
@@ -449,30 +449,30 @@ void snd_gf1_print_voice_registers(snd_gus_card_t * gus)
449 int voice, ctrl; 449 int voice, ctrl;
450 450
451 voice = gus->gf1.active_voice; 451 voice = gus->gf1.active_voice;
452 printk(" -%i- GF1 voice ctrl, ramp ctrl = 0x%x, 0x%x\n", voice, ctrl = snd_gf1_i_read8(gus, 0), snd_gf1_i_read8(gus, 0x0d)); 452 printk(KERN_INFO " -%i- GF1 voice ctrl, ramp ctrl = 0x%x, 0x%x\n", voice, ctrl = snd_gf1_i_read8(gus, 0), snd_gf1_i_read8(gus, 0x0d));
453 printk(" -%i- GF1 frequency = 0x%x\n", voice, snd_gf1_i_read16(gus, 1)); 453 printk(KERN_INFO " -%i- GF1 frequency = 0x%x\n", voice, snd_gf1_i_read16(gus, 1));
454 printk(" -%i- GF1 loop start, end = 0x%x (0x%x), 0x%x (0x%x)\n", voice, snd_gf1_i_read_addr(gus, 2, ctrl & 4), snd_gf1_i_read_addr(gus, 2, (ctrl & 4) ^ 4), snd_gf1_i_read_addr(gus, 4, ctrl & 4), snd_gf1_i_read_addr(gus, 4, (ctrl & 4) ^ 4)); 454 printk(KERN_INFO " -%i- GF1 loop start, end = 0x%x (0x%x), 0x%x (0x%x)\n", voice, snd_gf1_i_read_addr(gus, 2, ctrl & 4), snd_gf1_i_read_addr(gus, 2, (ctrl & 4) ^ 4), snd_gf1_i_read_addr(gus, 4, ctrl & 4), snd_gf1_i_read_addr(gus, 4, (ctrl & 4) ^ 4));
455 printk(" -%i- GF1 ramp start, end, rate = 0x%x, 0x%x, 0x%x\n", voice, snd_gf1_i_read8(gus, 7), snd_gf1_i_read8(gus, 8), snd_gf1_i_read8(gus, 6)); 455 printk(KERN_INFO " -%i- GF1 ramp start, end, rate = 0x%x, 0x%x, 0x%x\n", voice, snd_gf1_i_read8(gus, 7), snd_gf1_i_read8(gus, 8), snd_gf1_i_read8(gus, 6));
456 printk(" -%i- GF1 volume = 0x%x\n", voice, snd_gf1_i_read16(gus, 9)); 456 printk(KERN_INFO" -%i- GF1 volume = 0x%x\n", voice, snd_gf1_i_read16(gus, 9));
457 printk(" -%i- GF1 position = 0x%x (0x%x)\n", voice, snd_gf1_i_read_addr(gus, 0x0a, ctrl & 4), snd_gf1_i_read_addr(gus, 0x0a, (ctrl & 4) ^ 4)); 457 printk(KERN_INFO " -%i- GF1 position = 0x%x (0x%x)\n", voice, snd_gf1_i_read_addr(gus, 0x0a, ctrl & 4), snd_gf1_i_read_addr(gus, 0x0a, (ctrl & 4) ^ 4));
458 if (gus->interwave && snd_gf1_i_read8(gus, 0x19) & 0x01) { /* enhanced mode */ 458 if (gus->interwave && snd_gf1_i_read8(gus, 0x19) & 0x01) { /* enhanced mode */
459 mode = snd_gf1_i_read8(gus, 0x15); 459 mode = snd_gf1_i_read8(gus, 0x15);
460 printk(" -%i- GFA1 mode = 0x%x\n", voice, mode); 460 printk(KERN_INFO " -%i- GFA1 mode = 0x%x\n", voice, mode);
461 if (mode & 0x01) { /* Effect processor */ 461 if (mode & 0x01) { /* Effect processor */
462 printk(" -%i- GFA1 effect address = 0x%x\n", voice, snd_gf1_i_read_addr(gus, 0x11, ctrl & 4)); 462 printk(KERN_INFO " -%i- GFA1 effect address = 0x%x\n", voice, snd_gf1_i_read_addr(gus, 0x11, ctrl & 4));
463 printk(" -%i- GFA1 effect volume = 0x%x\n", voice, snd_gf1_i_read16(gus, 0x16)); 463 printk(KERN_INFO " -%i- GFA1 effect volume = 0x%x\n", voice, snd_gf1_i_read16(gus, 0x16));
464 printk(" -%i- GFA1 effect volume final = 0x%x\n", voice, snd_gf1_i_read16(gus, 0x1d)); 464 printk(KERN_INFO " -%i- GFA1 effect volume final = 0x%x\n", voice, snd_gf1_i_read16(gus, 0x1d));
465 printk(" -%i- GFA1 effect acumulator = 0x%x\n", voice, snd_gf1_i_read8(gus, 0x14)); 465 printk(KERN_INFO " -%i- GFA1 effect acumulator = 0x%x\n", voice, snd_gf1_i_read8(gus, 0x14));
466 } 466 }
467 if (mode & 0x20) { 467 if (mode & 0x20) {
468 printk(" -%i- GFA1 left offset = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x13), snd_gf1_i_read16(gus, 0x13) >> 4); 468 printk(KERN_INFO " -%i- GFA1 left offset = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x13), snd_gf1_i_read16(gus, 0x13) >> 4);
469 printk(" -%i- GFA1 left offset final = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x1c), snd_gf1_i_read16(gus, 0x1c) >> 4); 469 printk(KERN_INFO " -%i- GFA1 left offset final = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x1c), snd_gf1_i_read16(gus, 0x1c) >> 4);
470 printk(" -%i- GFA1 right offset = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x0c), snd_gf1_i_read16(gus, 0x0c) >> 4); 470 printk(KERN_INFO " -%i- GFA1 right offset = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x0c), snd_gf1_i_read16(gus, 0x0c) >> 4);
471 printk(" -%i- GFA1 right offset final = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x1b), snd_gf1_i_read16(gus, 0x1b) >> 4); 471 printk(KERN_INFO " -%i- GFA1 right offset final = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x1b), snd_gf1_i_read16(gus, 0x1b) >> 4);
472 } else 472 } else
473 printk(" -%i- GF1 pan = 0x%x\n", voice, snd_gf1_i_read8(gus, 0x0c)); 473 printk(KERN_INFO " -%i- GF1 pan = 0x%x\n", voice, snd_gf1_i_read8(gus, 0x0c));
474 } else 474 } else
475 printk(" -%i- GF1 pan = 0x%x\n", voice, snd_gf1_i_read8(gus, 0x0c)); 475 printk(KERN_INFO " -%i- GF1 pan = 0x%x\n", voice, snd_gf1_i_read8(gus, 0x0c));
476} 476}
477 477
478#if 0 478#if 0
@@ -481,45 +481,45 @@ void snd_gf1_print_global_registers(snd_gus_card_t * gus)
481{ 481{
482 unsigned char global_mode = 0x00; 482 unsigned char global_mode = 0x00;
483 483
484 printk(" -G- GF1 active voices = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_ACTIVE_VOICES)); 484 printk(KERN_INFO " -G- GF1 active voices = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_ACTIVE_VOICES));
485 if (gus->interwave) { 485 if (gus->interwave) {
486 global_mode = snd_gf1_i_read8(gus, SNDRV_GF1_GB_GLOBAL_MODE); 486 global_mode = snd_gf1_i_read8(gus, SNDRV_GF1_GB_GLOBAL_MODE);
487 printk(" -G- GF1 global mode = 0x%x\n", global_mode); 487 printk(KERN_INFO " -G- GF1 global mode = 0x%x\n", global_mode);
488 } 488 }
489 if (global_mode & 0x02) /* LFO enabled? */ 489 if (global_mode & 0x02) /* LFO enabled? */
490 printk(" -G- GF1 LFO base = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_LFO_BASE)); 490 printk(KERN_INFO " -G- GF1 LFO base = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_LFO_BASE));
491 printk(" -G- GF1 voices IRQ read = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_VOICES_IRQ_READ)); 491 printk(KERN_INFO " -G- GF1 voices IRQ read = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_VOICES_IRQ_READ));
492 printk(" -G- GF1 DRAM DMA control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL)); 492 printk(KERN_INFO " -G- GF1 DRAM DMA control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL));
493 printk(" -G- GF1 DRAM DMA high/low = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_HIGH), snd_gf1_i_read16(gus, SNDRV_GF1_GW_DRAM_DMA_LOW)); 493 printk(KERN_INFO " -G- GF1 DRAM DMA high/low = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_HIGH), snd_gf1_i_read16(gus, SNDRV_GF1_GW_DRAM_DMA_LOW));
494 printk(" -G- GF1 DRAM IO high/low = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_IO_HIGH), snd_gf1_i_read16(gus, SNDRV_GF1_GW_DRAM_IO_LOW)); 494 printk(KERN_INFO " -G- GF1 DRAM IO high/low = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_IO_HIGH), snd_gf1_i_read16(gus, SNDRV_GF1_GW_DRAM_IO_LOW));
495 if (!gus->interwave) 495 if (!gus->interwave)
496 printk(" -G- GF1 record DMA control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL)); 496 printk(KERN_INFO " -G- GF1 record DMA control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL));
497 printk(" -G- GF1 DRAM IO 16 = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_DRAM_IO16)); 497 printk(KERN_INFO " -G- GF1 DRAM IO 16 = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_DRAM_IO16));
498 if (gus->gf1.enh_mode) { 498 if (gus->gf1.enh_mode) {
499 printk(" -G- GFA1 memory config = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG)); 499 printk(KERN_INFO " -G- GFA1 memory config = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG));
500 printk(" -G- GFA1 memory control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_MEMORY_CONTROL)); 500 printk(KERN_INFO " -G- GFA1 memory control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_MEMORY_CONTROL));
501 printk(" -G- GFA1 FIFO record base = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_FIFO_RECORD_BASE_ADDR)); 501 printk(KERN_INFO " -G- GFA1 FIFO record base = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_FIFO_RECORD_BASE_ADDR));
502 printk(" -G- GFA1 FIFO playback base = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_FIFO_PLAY_BASE_ADDR)); 502 printk(KERN_INFO " -G- GFA1 FIFO playback base = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_FIFO_PLAY_BASE_ADDR));
503 printk(" -G- GFA1 interleave control = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_INTERLEAVE)); 503 printk(KERN_INFO " -G- GFA1 interleave control = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_INTERLEAVE));
504 } 504 }
505} 505}
506 506
507void snd_gf1_print_setup_registers(snd_gus_card_t * gus) 507void snd_gf1_print_setup_registers(snd_gus_card_t * gus)
508{ 508{
509 printk(" -S- mix control = 0x%x\n", inb(GUSP(gus, MIXCNTRLREG))); 509 printk(KERN_INFO " -S- mix control = 0x%x\n", inb(GUSP(gus, MIXCNTRLREG)));
510 printk(" -S- IRQ status = 0x%x\n", inb(GUSP(gus, IRQSTAT))); 510 printk(KERN_INFO " -S- IRQ status = 0x%x\n", inb(GUSP(gus, IRQSTAT)));
511 printk(" -S- timer control = 0x%x\n", inb(GUSP(gus, TIMERCNTRL))); 511 printk(KERN_INFO " -S- timer control = 0x%x\n", inb(GUSP(gus, TIMERCNTRL)));
512 printk(" -S- timer data = 0x%x\n", inb(GUSP(gus, TIMERDATA))); 512 printk(KERN_INFO " -S- timer data = 0x%x\n", inb(GUSP(gus, TIMERDATA)));
513 printk(" -S- status read = 0x%x\n", inb(GUSP(gus, REGCNTRLS))); 513 printk(KERN_INFO " -S- status read = 0x%x\n", inb(GUSP(gus, REGCNTRLS)));
514 printk(" -S- Sound Blaster control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL)); 514 printk(KERN_INFO " -S- Sound Blaster control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL));
515 printk(" -S- AdLib timer 1/2 = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_ADLIB_TIMER_1), snd_gf1_i_look8(gus, SNDRV_GF1_GB_ADLIB_TIMER_2)); 515 printk(KERN_INFO " -S- AdLib timer 1/2 = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_ADLIB_TIMER_1), snd_gf1_i_look8(gus, SNDRV_GF1_GB_ADLIB_TIMER_2));
516 printk(" -S- reset = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)); 516 printk(KERN_INFO " -S- reset = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET));
517 if (gus->interwave) { 517 if (gus->interwave) {
518 printk(" -S- compatibility = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_COMPATIBILITY)); 518 printk(KERN_INFO " -S- compatibility = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_COMPATIBILITY));
519 printk(" -S- decode control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DECODE_CONTROL)); 519 printk(KERN_INFO " -S- decode control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DECODE_CONTROL));
520 printk(" -S- version number = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER)); 520 printk(KERN_INFO " -S- version number = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER));
521 printk(" -S- MPU-401 emul. control A/B = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A), snd_gf1_i_look8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B)); 521 printk(KERN_INFO " -S- MPU-401 emul. control A/B = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A), snd_gf1_i_look8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B));
522 printk(" -S- emulation IRQ = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_EMULATION_IRQ)); 522 printk(KERN_INFO " -S- emulation IRQ = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_EMULATION_IRQ));
523 } 523 }
524} 524}
525 525
diff --git a/sound/isa/gus/gus_main.c b/sound/isa/gus/gus_main.c
index 8f2872f8e8f6..4f57ff4ab351 100644
--- a/sound/isa/gus/gus_main.c
+++ b/sound/isa/gus/gus_main.c
@@ -113,14 +113,8 @@ static int snd_gus_free(snd_gus_card_t *gus)
113 snd_gf1_stop(gus); 113 snd_gf1_stop(gus);
114 snd_gus_init_dma_irq(gus, 0); 114 snd_gus_init_dma_irq(gus, 0);
115 __hw_end: 115 __hw_end:
116 if (gus->gf1.res_port1) { 116 release_and_free_resource(gus->gf1.res_port1);
117 release_resource(gus->gf1.res_port1); 117 release_and_free_resource(gus->gf1.res_port2);
118 kfree_nocheck(gus->gf1.res_port1);
119 }
120 if (gus->gf1.res_port2) {
121 release_resource(gus->gf1.res_port2);
122 kfree_nocheck(gus->gf1.res_port2);
123 }
124 if (gus->gf1.irq >= 0) 118 if (gus->gf1.irq >= 0)
125 free_irq(gus->gf1.irq, (void *) gus); 119 free_irq(gus->gf1.irq, (void *) gus);
126 if (gus->gf1.dma1 >= 0) { 120 if (gus->gf1.dma1 >= 0) {
@@ -252,7 +246,7 @@ static int snd_gus_detect_memory(snd_gus_card_t * gus)
252 snd_gf1_poke(gus, 0L, 0xaa); 246 snd_gf1_poke(gus, 0L, 0xaa);
253 snd_gf1_poke(gus, 1L, 0x55); 247 snd_gf1_poke(gus, 1L, 0x55);
254 if (snd_gf1_peek(gus, 0L) != 0xaa || snd_gf1_peek(gus, 1L) != 0x55) { 248 if (snd_gf1_peek(gus, 0L) != 0xaa || snd_gf1_peek(gus, 1L) != 0x55) {
255 snd_printk("plain GF1 card at 0x%lx without onboard DRAM?\n", gus->gf1.port); 249 snd_printk(KERN_ERR "plain GF1 card at 0x%lx without onboard DRAM?\n", gus->gf1.port);
256 return -ENOMEM; 250 return -ENOMEM;
257 } 251 }
258 for (idx = 1, d = 0xab; idx < 4; idx++, d++) { 252 for (idx = 1, d = 0xab; idx < 4; idx++, d++) {
@@ -305,20 +299,17 @@ static int snd_gus_init_dma_irq(snd_gus_card_t * gus, int latches)
305 dma2 = gus->gf1.dma2; 299 dma2 = gus->gf1.dma2;
306 dma2 = dma2 < 0 ? -dma2 : dma2; 300 dma2 = dma2 < 0 ? -dma2 : dma2;
307 dma2 = dmas[dma2 & 7]; 301 dma2 = dmas[dma2 & 7];
308#if 0
309 printk("dma1 = %i, dma2 = %i\n", gus->gf1.dma1, gus->gf1.dma2);
310#endif
311 dma1 |= gus->equal_dma ? 0x40 : (dma2 << 3); 302 dma1 |= gus->equal_dma ? 0x40 : (dma2 << 3);
312 303
313 if ((dma1 & 7) == 0 || (dma2 & 7) == 0) { 304 if ((dma1 & 7) == 0 || (dma2 & 7) == 0) {
314 snd_printk("Error! DMA isn't defined.\n"); 305 snd_printk(KERN_ERR "Error! DMA isn't defined.\n");
315 return -EINVAL; 306 return -EINVAL;
316 } 307 }
317 irq = gus->gf1.irq; 308 irq = gus->gf1.irq;
318 irq = irq < 0 ? -irq : irq; 309 irq = irq < 0 ? -irq : irq;
319 irq = irqs[irq & 0x0f]; 310 irq = irqs[irq & 0x0f];
320 if (irq == 0) { 311 if (irq == 0) {
321 snd_printk("Error! IRQ isn't defined.\n"); 312 snd_printk(KERN_ERR "Error! IRQ isn't defined.\n");
322 return -EINVAL; 313 return -EINVAL;
323 } 314 }
324 irq |= 0x40; 315 irq |= 0x40;
@@ -406,8 +397,8 @@ static int snd_gus_check_version(snd_gus_card_t * gus)
406 strcpy(card->longname, "Gravis UltraSound Extreme"); 397 strcpy(card->longname, "Gravis UltraSound Extreme");
407 gus->ess_flag = 1; 398 gus->ess_flag = 1;
408 } else { 399 } else {
409 snd_printk("unknown GF1 revision number at 0x%lx - 0x%x (0x%x)\n", gus->gf1.port, rev, val); 400 snd_printk(KERN_ERR "unknown GF1 revision number at 0x%lx - 0x%x (0x%x)\n", gus->gf1.port, rev, val);
410 snd_printk(" please - report to <perex@suse.cz>\n"); 401 snd_printk(KERN_ERR " please - report to <perex@suse.cz>\n");
411 } 402 }
412 } 403 }
413 } 404 }
@@ -431,7 +422,7 @@ int snd_gus_initialize(snd_gus_card_t *gus)
431 422
432 if (!gus->interwave) { 423 if (!gus->interwave) {
433 if ((err = snd_gus_check_version(gus)) < 0) { 424 if ((err = snd_gus_check_version(gus)) < 0) {
434 snd_printk("version check failed\n"); 425 snd_printk(KERN_ERR "version check failed\n");
435 return err; 426 return err;
436 } 427 }
437 if ((err = snd_gus_detect_memory(gus)) < 0) 428 if ((err = snd_gus_detect_memory(gus)) < 0)
diff --git a/sound/isa/gus/gus_mem.c b/sound/isa/gus/gus_mem.c
index 5eb766dd564b..2e23f2a8c627 100644
--- a/sound/isa/gus/gus_mem.c
+++ b/sound/isa/gus/gus_mem.c
@@ -198,7 +198,7 @@ snd_gf1_mem_block_t *snd_gf1_mem_alloc(snd_gf1_mem_t * alloc, int owner,
198 if (nblock != NULL) { 198 if (nblock != NULL) {
199 if (size != (int)nblock->size) { 199 if (size != (int)nblock->size) {
200 /* TODO: remove in the future */ 200 /* TODO: remove in the future */
201 snd_printk("snd_gf1_mem_alloc - share: sizes differ\n"); 201 snd_printk(KERN_ERR "snd_gf1_mem_alloc - share: sizes differ\n");
202 goto __std; 202 goto __std;
203 } 203 }
204 nblock->share++; 204 nblock->share++;
diff --git a/sound/isa/gus/gus_pcm.c b/sound/isa/gus/gus_pcm.c
index beb01365dc46..1cc89fb67bf2 100644
--- a/sound/isa/gus/gus_pcm.c
+++ b/sound/isa/gus/gus_pcm.c
@@ -333,8 +333,7 @@ static int snd_gf1_pcm_poke_block(snd_gus_card_t *gus, unsigned char *buf,
333 } 333 }
334 } 334 }
335 if (count > 0 && !in_interrupt()) { 335 if (count > 0 && !in_interrupt()) {
336 set_current_state(TASK_INTERRUPTIBLE); 336 schedule_timeout_interruptible(1);
337 schedule_timeout(1);
338 if (signal_pending(current)) 337 if (signal_pending(current))
339 return -EAGAIN; 338 return -EAGAIN;
340 } 339 }
@@ -698,7 +697,7 @@ static int snd_gf1_pcm_playback_close(snd_pcm_substream_t * substream)
698 gus_pcm_private_t *pcmp = runtime->private_data; 697 gus_pcm_private_t *pcmp = runtime->private_data;
699 698
700 if (!wait_event_timeout(pcmp->sleep, (atomic_read(&pcmp->dma_count) <= 0), 2*HZ)) 699 if (!wait_event_timeout(pcmp->sleep, (atomic_read(&pcmp->dma_count) <= 0), 2*HZ))
701 snd_printk("gf1 pcm - serious DMA problem\n"); 700 snd_printk(KERN_ERR "gf1 pcm - serious DMA problem\n");
702 701
703 snd_gf1_dma_done(gus); 702 snd_gf1_dma_done(gus);
704 return 0; 703 return 0;
diff --git a/sound/isa/gus/gus_reset.c b/sound/isa/gus/gus_reset.c
index ef687abc7070..90710969ef7f 100644
--- a/sound/isa/gus/gus_reset.c
+++ b/sound/isa/gus/gus_reset.c
@@ -134,7 +134,7 @@ void snd_gf1_smart_stop_voice(snd_gus_card_t * gus, unsigned short voice)
134 spin_lock_irqsave(&gus->reg_lock, flags); 134 spin_lock_irqsave(&gus->reg_lock, flags);
135 snd_gf1_select_voice(gus, voice); 135 snd_gf1_select_voice(gus, voice);
136#if 0 136#if 0
137 printk(" -%i- smart stop voice - volume = 0x%x\n", voice, snd_gf1_i_read16(gus, SNDRV_GF1_VW_VOLUME)); 137 printk(KERN_DEBUG " -%i- smart stop voice - volume = 0x%x\n", voice, snd_gf1_i_read16(gus, SNDRV_GF1_VW_VOLUME));
138#endif 138#endif
139 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL); 139 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
140 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); 140 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
@@ -148,7 +148,7 @@ void snd_gf1_stop_voice(snd_gus_card_t * gus, unsigned short voice)
148 spin_lock_irqsave(&gus->reg_lock, flags); 148 spin_lock_irqsave(&gus->reg_lock, flags);
149 snd_gf1_select_voice(gus, voice); 149 snd_gf1_select_voice(gus, voice);
150#if 0 150#if 0
151 printk(" -%i- stop voice - volume = 0x%x\n", voice, snd_gf1_i_read16(gus, SNDRV_GF1_VW_VOLUME)); 151 printk(KERN_DEBUG " -%i- stop voice - volume = 0x%x\n", voice, snd_gf1_i_read16(gus, SNDRV_GF1_VW_VOLUME));
152#endif 152#endif
153 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL); 153 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
154 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); 154 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
diff --git a/sound/isa/gus/gus_simple.c b/sound/isa/gus/gus_simple.c
index c122e7be6ceb..dfed85b58b3a 100644
--- a/sound/isa/gus/gus_simple.c
+++ b/sound/isa/gus/gus_simple.c
@@ -136,7 +136,7 @@ static void do_volume_envelope(snd_gus_card_t *gus, snd_gus_voice_t *voice)
136 snd_gf1_select_voice(gus, voice->number); 136 snd_gf1_select_voice(gus, voice->number);
137 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); 137 snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
138 snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, voice->gf1_volume); 138 snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, voice->gf1_volume);
139 printk("gf1_volume = 0x%x\n", voice->gf1_volume); 139 /* printk("gf1_volume = 0x%x\n", voice->gf1_volume); */
140 spin_unlock_irqrestore(&gus->reg_lock, flags); 140 spin_unlock_irqrestore(&gus->reg_lock, flags);
141 return; 141 return;
142 } 142 }
diff --git a/sound/isa/gus/gus_uart.c b/sound/isa/gus/gus_uart.c
index 1bc2da8784e0..fbc95e99105c 100644
--- a/sound/isa/gus/gus_uart.c
+++ b/sound/isa/gus/gus_uart.c
@@ -104,7 +104,7 @@ static int snd_gf1_uart_output_open(snd_rawmidi_substream_t * substream)
104 gus->midi_substream_output = substream; 104 gus->midi_substream_output = substream;
105 spin_unlock_irqrestore(&gus->uart_cmd_lock, flags); 105 spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
106#if 0 106#if 0
107 snd_printk("write init - cmd = 0x%x, stat = 0x%x\n", gus->gf1.uart_cmd, snd_gf1_uart_stat(gus)); 107 snd_printk(KERN_DEBUG "write init - cmd = 0x%x, stat = 0x%x\n", gus->gf1.uart_cmd, snd_gf1_uart_stat(gus));
108#endif 108#endif
109 return 0; 109 return 0;
110} 110}
@@ -126,7 +126,7 @@ static int snd_gf1_uart_input_open(snd_rawmidi_substream_t * substream)
126 for (i = 0; i < 1000 && (snd_gf1_uart_stat(gus) & 0x01); i++) 126 for (i = 0; i < 1000 && (snd_gf1_uart_stat(gus) & 0x01); i++)
127 snd_gf1_uart_get(gus); /* clean Rx */ 127 snd_gf1_uart_get(gus); /* clean Rx */
128 if (i >= 1000) 128 if (i >= 1000)
129 snd_printk("gus midi uart init read - cleanup error\n"); 129 snd_printk(KERN_ERR "gus midi uart init read - cleanup error\n");
130 } 130 }
131 spin_unlock_irqrestore(&gus->uart_cmd_lock, flags); 131 spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
132#if 0 132#if 0
diff --git a/sound/isa/gus/gus_volume.c b/sound/isa/gus/gus_volume.c
index 3d36f6c8ee6a..b3382fec5298 100644
--- a/sound/isa/gus/gus_volume.c
+++ b/sound/isa/gus/gus_volume.c
@@ -119,7 +119,7 @@ unsigned short snd_gf1_translate_freq(snd_gus_card_t * gus, unsigned int freq16)
119 freq16 = 50; 119 freq16 = 50;
120 if (freq16 & 0xf8000000) { 120 if (freq16 & 0xf8000000) {
121 freq16 = ~0xf8000000; 121 freq16 = ~0xf8000000;
122 snd_printk("snd_gf1_translate_freq: overflow - freq = 0x%x\n", freq16); 122 snd_printk(KERN_ERR "snd_gf1_translate_freq: overflow - freq = 0x%x\n", freq16);
123 } 123 }
124 return ((freq16 << 9) + (gus->gf1.playback_freq >> 1)) / gus->gf1.playback_freq; 124 return ((freq16 << 9) + (gus->gf1.playback_freq >> 1)) / gus->gf1.playback_freq;
125} 125}
@@ -203,14 +203,14 @@ unsigned short snd_gf1_compute_freq(unsigned int freq,
203 fc = (freq << 10) / rate; 203 fc = (freq << 10) / rate;
204 if (fc > 97391L) { 204 if (fc > 97391L) {
205 fc = 97391; 205 fc = 97391;
206 snd_printk("patch: (1) fc frequency overflow - %u\n", fc); 206 snd_printk(KERN_ERR "patch: (1) fc frequency overflow - %u\n", fc);
207 } 207 }
208 fc = (fc * 44100UL) / mix_rate; 208 fc = (fc * 44100UL) / mix_rate;
209 while (scale--) 209 while (scale--)
210 fc <<= 1; 210 fc <<= 1;
211 if (fc > 65535L) { 211 if (fc > 65535L) {
212 fc = 65535; 212 fc = 65535;
213 snd_printk("patch: (2) fc frequency overflow - %u\n", fc); 213 snd_printk(KERN_ERR "patch: (2) fc frequency overflow - %u\n", fc);
214 } 214 }
215 return (unsigned short) fc; 215 return (unsigned short) fc;
216} 216}
diff --git a/sound/isa/gus/interwave.c b/sound/isa/gus/interwave.c
index 358cba9d738f..f703a9f4257c 100644
--- a/sound/isa/gus/interwave.c
+++ b/sound/isa/gus/interwave.c
@@ -437,7 +437,7 @@ static void __devinit snd_interwave_detect_memory(snd_gus_card_t * gus)
437 for (i = 0; i < 8; ++i) 437 for (i = 0; i < 8; ++i)
438 iwave[i] = snd_gf1_peek(gus, bank_pos + i); 438 iwave[i] = snd_gf1_peek(gus, bank_pos + i);
439#ifdef CONFIG_SND_DEBUG_ROM 439#ifdef CONFIG_SND_DEBUG_ROM
440 printk("ROM at 0x%06x = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", bank_pos, 440 printk(KERN_DEBUG "ROM at 0x%06x = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", bank_pos,
441 iwave[0], iwave[1], iwave[2], iwave[3], 441 iwave[0], iwave[1], iwave[2], iwave[3],
442 iwave[4], iwave[5], iwave[6], iwave[7]); 442 iwave[4], iwave[5], iwave[6], iwave[7]);
443#endif 443#endif
@@ -447,7 +447,7 @@ static void __devinit snd_interwave_detect_memory(snd_gus_card_t * gus)
447 for (i = 0; i < sizeof(struct rom_hdr); i++) 447 for (i = 0; i < sizeof(struct rom_hdr); i++)
448 csum += snd_gf1_peek(gus, bank_pos + i); 448 csum += snd_gf1_peek(gus, bank_pos + i);
449#ifdef CONFIG_SND_DEBUG_ROM 449#ifdef CONFIG_SND_DEBUG_ROM
450 printk("ROM checksum = 0x%x (computed)\n", csum); 450 printk(KERN_DEBUG "ROM checksum = 0x%x (computed)\n", csum);
451#endif 451#endif
452 if (csum != 0) 452 if (csum != 0)
453 continue; /* not valid rom */ 453 continue; /* not valid rom */
@@ -638,10 +638,7 @@ static void snd_interwave_free(snd_card_t *card)
638 if (iwcard == NULL) 638 if (iwcard == NULL)
639 return; 639 return;
640#ifdef SNDRV_STB 640#ifdef SNDRV_STB
641 if (iwcard->i2c_res) { 641 release_and_free_resource(iwcard->i2c_res);
642 release_resource(iwcard->i2c_res);
643 kfree_nocheck(iwcard->i2c_res);
644 }
645#endif 642#endif
646 if (iwcard->irq >= 0) 643 if (iwcard->irq >= 0)
647 free_irq(iwcard->irq, (void *)iwcard); 644 free_irq(iwcard->irq, (void *)iwcard);
diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c
index 4ba268f251e3..47cabda792b6 100644
--- a/sound/isa/opl3sa2.c
+++ b/sound/isa/opl3sa2.c
@@ -656,10 +656,7 @@ static int snd_opl3sa2_free(opl3sa2_t *chip)
656{ 656{
657 if (chip->irq >= 0) 657 if (chip->irq >= 0)
658 free_irq(chip->irq, (void *)chip); 658 free_irq(chip->irq, (void *)chip);
659 if (chip->res_port) { 659 release_and_free_resource(chip->res_port);
660 release_resource(chip->res_port);
661 kfree_nocheck(chip->res_port);
662 }
663 kfree(chip); 660 kfree(chip);
664 return 0; 661 return 0;
665} 662}
diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c
index 73573cb1db6a..b94339f8306f 100644
--- a/sound/isa/opti9xx/opti92x-ad1848.c
+++ b/sound/isa/opti9xx/opti92x-ad1848.c
@@ -299,10 +299,8 @@ static char * snd_opti9xx_names[] = {
299static long snd_legacy_find_free_ioport(long *port_table, long size) 299static long snd_legacy_find_free_ioport(long *port_table, long size)
300{ 300{
301 while (*port_table != -1) { 301 while (*port_table != -1) {
302 struct resource *res; 302 if (request_region(*port_table, size, "ALSA test")) {
303 if ((res = request_region(*port_table, size, "ALSA test")) != NULL) { 303 release_region(*port_table, size);
304 release_resource(res);
305 kfree_nocheck(res);
306 return *port_table; 304 return *port_table;
307 } 305 }
308 port_table++; 306 port_table++;
@@ -1227,10 +1225,7 @@ static int snd_opti93x_probe(opti93x_t *chip)
1227 1225
1228static int snd_opti93x_free(opti93x_t *chip) 1226static int snd_opti93x_free(opti93x_t *chip)
1229{ 1227{
1230 if (chip->res_port) { 1228 release_and_free_resource(chip->res_port);
1231 release_resource(chip->res_port);
1232 kfree_nocheck(chip->res_port);
1233 }
1234 if (chip->dma1 >= 0) { 1229 if (chip->dma1 >= 0) {
1235 disable_dma(chip->dma1); 1230 disable_dma(chip->dma1);
1236 free_dma(chip->dma1); 1231 free_dma(chip->dma1);
@@ -1656,8 +1651,7 @@ static int __devinit snd_card_opti9xx_detect(snd_card_t *card, opti9xx_t *chip)
1656 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1))) 1651 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
1657 return 1; 1652 return 1;
1658 1653
1659 release_resource(chip->res_mc_base); 1654 release_and_free_resource(chip->res_mc_base);
1660 kfree_nocheck(chip->res_mc_base);
1661 chip->res_mc_base = NULL; 1655 chip->res_mc_base = NULL;
1662 1656
1663 } 1657 }
@@ -1683,8 +1677,7 @@ static int __devinit snd_card_opti9xx_detect(snd_card_t *card, opti9xx_t *chip)
1683 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value) 1677 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
1684 return 1; 1678 return 1;
1685 1679
1686 release_resource(chip->res_mc_base); 1680 release_and_free_resource(chip->res_mc_base);
1687 kfree_nocheck(chip->res_mc_base);
1688 chip->res_mc_base = NULL; 1681 chip->res_mc_base = NULL;
1689 } 1682 }
1690#endif /* OPTi93X */ 1683#endif /* OPTi93X */
@@ -1886,12 +1879,8 @@ static void snd_card_opti9xx_free(snd_card_t *card)
1886{ 1879{
1887 opti9xx_t *chip = (opti9xx_t *)card->private_data; 1880 opti9xx_t *chip = (opti9xx_t *)card->private_data;
1888 1881
1889 if (chip) { 1882 if (chip)
1890 if (chip->res_mc_base) { 1883 release_and_free_resource(chip->res_mc_base);
1891 release_resource(chip->res_mc_base);
1892 kfree_nocheck(chip->res_mc_base);
1893 }
1894 }
1895} 1884}
1896 1885
1897static int snd_card_opti9xx_probe(struct pnp_card_link *pcard, 1886static int snd_card_opti9xx_probe(struct pnp_card_link *pcard,
diff --git a/sound/isa/sb/emu8000.c b/sound/isa/sb/emu8000.c
index 5375705c054b..b09c6575e01a 100644
--- a/sound/isa/sb/emu8000.c
+++ b/sound/isa/sb/emu8000.c
@@ -135,8 +135,7 @@ static void __init
135snd_emu8000_read_wait(emu8000_t *emu) 135snd_emu8000_read_wait(emu8000_t *emu)
136{ 136{
137 while ((EMU8000_SMALR_READ(emu) & 0x80000000) != 0) { 137 while ((EMU8000_SMALR_READ(emu) & 0x80000000) != 0) {
138 set_current_state(TASK_INTERRUPTIBLE); 138 schedule_timeout_interruptible(1);
139 schedule_timeout(1);
140 if (signal_pending(current)) 139 if (signal_pending(current))
141 break; 140 break;
142 } 141 }
@@ -148,8 +147,7 @@ static void __init
148snd_emu8000_write_wait(emu8000_t *emu) 147snd_emu8000_write_wait(emu8000_t *emu)
149{ 148{
150 while ((EMU8000_SMALW_READ(emu) & 0x80000000) != 0) { 149 while ((EMU8000_SMALW_READ(emu) & 0x80000000) != 0) {
151 set_current_state(TASK_INTERRUPTIBLE); 150 schedule_timeout_interruptible(1);
152 schedule_timeout(1);
153 if (signal_pending(current)) 151 if (signal_pending(current))
154 break; 152 break;
155 } 153 }
@@ -437,8 +435,7 @@ size_dram(emu8000_t *emu)
437 for (i = 0; i < 10000; i++) { 435 for (i = 0; i < 10000; i++) {
438 if ((EMU8000_SMALW_READ(emu) & 0x80000000) == 0) 436 if ((EMU8000_SMALW_READ(emu) & 0x80000000) == 0)
439 break; 437 break;
440 set_current_state(TASK_INTERRUPTIBLE); 438 schedule_timeout_interruptible(1);
441 schedule_timeout(1);
442 if (signal_pending(current)) 439 if (signal_pending(current))
443 break; 440 break;
444 } 441 }
@@ -1054,18 +1051,9 @@ __error:
1054 */ 1051 */
1055static int snd_emu8000_free(emu8000_t *hw) 1052static int snd_emu8000_free(emu8000_t *hw)
1056{ 1053{
1057 if (hw->res_port1) { 1054 release_and_free_resource(hw->res_port1);
1058 release_resource(hw->res_port1); 1055 release_and_free_resource(hw->res_port2);
1059 kfree_nocheck(hw->res_port1); 1056 release_and_free_resource(hw->res_port3);
1060 }
1061 if (hw->res_port2) {
1062 release_resource(hw->res_port2);
1063 kfree_nocheck(hw->res_port2);
1064 }
1065 if (hw->res_port3) {
1066 release_resource(hw->res_port3);
1067 kfree_nocheck(hw->res_port3);
1068 }
1069 kfree(hw); 1057 kfree(hw);
1070 return 0; 1058 return 0;
1071} 1059}
diff --git a/sound/isa/sb/emu8000_patch.c b/sound/isa/sb/emu8000_patch.c
index 26e693078cb3..2fea67e71c78 100644
--- a/sound/isa/sb/emu8000_patch.c
+++ b/sound/isa/sb/emu8000_patch.c
@@ -109,8 +109,7 @@ static void
109snd_emu8000_write_wait(emu8000_t *emu) 109snd_emu8000_write_wait(emu8000_t *emu)
110{ 110{
111 while ((EMU8000_SMALW_READ(emu) & 0x80000000) != 0) { 111 while ((EMU8000_SMALW_READ(emu) & 0x80000000) != 0) {
112 set_current_state(TASK_INTERRUPTIBLE); 112 schedule_timeout_interruptible(1);
113 schedule_timeout(1);
114 if (signal_pending(current)) 113 if (signal_pending(current))
115 break; 114 break;
116 } 115 }
diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c
index 0209790dc4b5..b323beeeda15 100644
--- a/sound/isa/sb/emu8000_pcm.c
+++ b/sound/isa/sb/emu8000_pcm.c
@@ -117,8 +117,7 @@ snd_emu8000_write_wait(emu8000_t *emu, int can_schedule)
117{ 117{
118 while ((EMU8000_SMALW_READ(emu) & 0x80000000) != 0) { 118 while ((EMU8000_SMALW_READ(emu) & 0x80000000) != 0) {
119 if (can_schedule) { 119 if (can_schedule) {
120 set_current_state(TASK_INTERRUPTIBLE); 120 schedule_timeout_interruptible(1);
121 schedule_timeout(1);
122 if (signal_pending(current)) 121 if (signal_pending(current))
123 break; 122 break;
124 } 123 }
diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
index 1f63aa52d596..f68e217416a6 100644
--- a/sound/isa/sb/emu8000_synth.c
+++ b/sound/isa/sb/emu8000_synth.c
@@ -56,7 +56,7 @@ static int snd_emu8000_new_device(snd_seq_device_t *dev)
56 emu->num_ports = hw->seq_ports; 56 emu->num_ports = hw->seq_ports;
57 57
58 if (hw->memhdr) { 58 if (hw->memhdr) {
59 snd_printk("memhdr is already initialized!?\n"); 59 snd_printk(KERN_ERR "memhdr is already initialized!?\n");
60 snd_util_memhdr_free(hw->memhdr); 60 snd_util_memhdr_free(hw->memhdr);
61 } 61 }
62 hw->memhdr = snd_util_memhdr_new(hw->mem_size); 62 hw->memhdr = snd_util_memhdr_new(hw->mem_size);
diff --git a/sound/isa/sb/sb16.c b/sound/isa/sb/sb16.c
index 7888783d68f5..c2fa451bc8f0 100644
--- a/sound/isa/sb/sb16.c
+++ b/sound/isa/sb/sb16.c
@@ -345,10 +345,7 @@ static void snd_sb16_free(snd_card_t *card)
345 345
346 if (acard == NULL) 346 if (acard == NULL)
347 return; 347 return;
348 if (acard->fm_res) { 348 release_and_free_resource(acard->fm_res);
349 release_resource(acard->fm_res);
350 kfree_nocheck(acard->fm_res);
351 }
352} 349}
353 350
354#ifdef CONFIG_PNP 351#ifdef CONFIG_PNP
diff --git a/sound/isa/sb/sb16_main.c b/sound/isa/sb/sb16_main.c
index a99e642a68b5..556b95e3e22f 100644
--- a/sound/isa/sb/sb16_main.c
+++ b/sound/isa/sb/sb16_main.c
@@ -747,7 +747,7 @@ int snd_sb16dsp_configure(sb_t * chip)
747 unsigned char realirq, realdma, realmpureg; 747 unsigned char realirq, realdma, realmpureg;
748 /* note: mpu register should be present only on SB16 Vibra soundcards */ 748 /* note: mpu register should be present only on SB16 Vibra soundcards */
749 749
750 // printk("codec->irq=%i, codec->dma8=%i, codec->dma16=%i\n", chip->irq, chip->dma8, chip->dma16); 750 // printk(KERN_DEBUG "codec->irq=%i, codec->dma8=%i, codec->dma16=%i\n", chip->irq, chip->dma8, chip->dma16);
751 spin_lock_irqsave(&chip->mixer_lock, flags); 751 spin_lock_irqsave(&chip->mixer_lock, flags);
752 mpureg = snd_sbmixer_read(chip, SB_DSP4_MPUSETUP) & ~0x06; 752 mpureg = snd_sbmixer_read(chip, SB_DSP4_MPUSETUP) & ~0x06;
753 spin_unlock_irqrestore(&chip->mixer_lock, flags); 753 spin_unlock_irqrestore(&chip->mixer_lock, flags);
@@ -821,9 +821,9 @@ int snd_sb16dsp_configure(sb_t * chip)
821 821
822 spin_unlock_irqrestore(&chip->mixer_lock, flags); 822 spin_unlock_irqrestore(&chip->mixer_lock, flags);
823 if ((~realirq) & irqreg || (~realdma) & dmareg) { 823 if ((~realirq) & irqreg || (~realdma) & dmareg) {
824 snd_printk("SB16 [0x%lx]: unable to set DMA & IRQ (PnP device?)\n", chip->port); 824 snd_printk(KERN_ERR "SB16 [0x%lx]: unable to set DMA & IRQ (PnP device?)\n", chip->port);
825 snd_printk("SB16 [0x%lx]: wanted: irqreg=0x%x, dmareg=0x%x, mpureg = 0x%x\n", chip->port, realirq, realdma, realmpureg); 825 snd_printk(KERN_ERR "SB16 [0x%lx]: wanted: irqreg=0x%x, dmareg=0x%x, mpureg = 0x%x\n", chip->port, realirq, realdma, realmpureg);
826 snd_printk("SB16 [0x%lx]: got: irqreg=0x%x, dmareg=0x%x, mpureg = 0x%x\n", chip->port, irqreg, dmareg, mpureg); 826 snd_printk(KERN_ERR "SB16 [0x%lx]: got: irqreg=0x%x, dmareg=0x%x, mpureg = 0x%x\n", chip->port, irqreg, dmareg, mpureg);
827 return -ENODEV; 827 return -ENODEV;
828 } 828 }
829 return 0; 829 return 0;
diff --git a/sound/isa/sb/sb8.c b/sound/isa/sb/sb8.c
index c41ac25e85ca..0bc0a3afdabc 100644
--- a/sound/isa/sb/sb8.c
+++ b/sound/isa/sb/sb8.c
@@ -78,10 +78,7 @@ static void snd_sb8_free(snd_card_t *card)
78 78
79 if (acard == NULL) 79 if (acard == NULL)
80 return; 80 return;
81 if (acard->fm_res) { 81 release_and_free_resource(acard->fm_res);
82 release_resource(acard->fm_res);
83 kfree_nocheck(acard->fm_res);
84 }
85} 82}
86 83
87static int __init snd_sb8_probe(int dev) 84static int __init snd_sb8_probe(int dev)
diff --git a/sound/isa/sb/sb8_main.c b/sound/isa/sb/sb8_main.c
index 87c9b1ba06cf..5ddc6e41d909 100644
--- a/sound/isa/sb/sb8_main.c
+++ b/sound/isa/sb/sb8_main.c
@@ -334,9 +334,6 @@ irqreturn_t snd_sb8dsp_interrupt(sb_t *chip)
334 snd_pcm_substream_t *substream; 334 snd_pcm_substream_t *substream;
335 snd_pcm_runtime_t *runtime; 335 snd_pcm_runtime_t *runtime;
336 336
337#if 0
338 snd_printk("sb8: interrupt\n");
339#endif
340 snd_sb_ack_8bit(chip); 337 snd_sb_ack_8bit(chip);
341 switch (chip->mode) { 338 switch (chip->mode) {
342 case SB_MODE_PLAYBACK_8: /* ok.. playback is active */ 339 case SB_MODE_PLAYBACK_8: /* ok.. playback is active */
diff --git a/sound/isa/sb/sb_common.c b/sound/isa/sb/sb_common.c
index f0f205ae425f..603e923b5d2f 100644
--- a/sound/isa/sb/sb_common.c
+++ b/sound/isa/sb/sb_common.c
@@ -45,7 +45,7 @@ int snd_sbdsp_command(sb_t *chip, unsigned char val)
45{ 45{
46 int i; 46 int i;
47#ifdef IO_DEBUG 47#ifdef IO_DEBUG
48 snd_printk("command 0x%x\n", val); 48 snd_printk(KERN_DEBUG "command 0x%x\n", val);
49#endif 49#endif
50 for (i = BUSY_LOOPS; i; i--) 50 for (i = BUSY_LOOPS; i; i--)
51 if ((inb(SBP(chip, STATUS)) & 0x80) == 0) { 51 if ((inb(SBP(chip, STATUS)) & 0x80) == 0) {
@@ -64,7 +64,7 @@ int snd_sbdsp_get_byte(sb_t *chip)
64 if (inb(SBP(chip, DATA_AVAIL)) & 0x80) { 64 if (inb(SBP(chip, DATA_AVAIL)) & 0x80) {
65 val = inb(SBP(chip, READ)); 65 val = inb(SBP(chip, READ));
66#ifdef IO_DEBUG 66#ifdef IO_DEBUG
67 snd_printk("get_byte 0x%x\n", val); 67 snd_printk(KERN_DEBUG "get_byte 0x%x\n", val);
68#endif 68#endif
69 return val; 69 return val;
70 } 70 }
@@ -154,7 +154,7 @@ static int snd_sbdsp_probe(sb_t * chip)
154 str = "16"; 154 str = "16";
155 break; 155 break;
156 default: 156 default:
157 snd_printk("SB [0x%lx]: unknown DSP chip version %i.%i\n", 157 snd_printk(KERN_INFO "SB [0x%lx]: unknown DSP chip version %i.%i\n",
158 chip->port, major, minor); 158 chip->port, major, minor);
159 return -ENODEV; 159 return -ENODEV;
160 } 160 }
@@ -178,10 +178,8 @@ static int snd_sbdsp_probe(sb_t * chip)
178 178
179static int snd_sbdsp_free(sb_t *chip) 179static int snd_sbdsp_free(sb_t *chip)
180{ 180{
181 if (chip->res_port) { 181 if (chip->res_port)
182 release_resource(chip->res_port); 182 release_and_free_resource(chip->res_port);
183 kfree_nocheck(chip->res_port);
184 }
185 if (chip->irq >= 0) 183 if (chip->irq >= 0)
186 free_irq(chip->irq, (void *) chip); 184 free_irq(chip->irq, (void *) chip);
187#ifdef CONFIG_ISA 185#ifdef CONFIG_ISA
diff --git a/sound/isa/sb/sb_mixer.c b/sound/isa/sb/sb_mixer.c
index ff4b59968027..5a926a452d38 100644
--- a/sound/isa/sb/sb_mixer.c
+++ b/sound/isa/sb/sb_mixer.c
@@ -36,7 +36,7 @@ void snd_sbmixer_write(sb_t *chip, unsigned char reg, unsigned char data)
36 outb(data, SBP(chip, MIXER_DATA)); 36 outb(data, SBP(chip, MIXER_DATA));
37 udelay(10); 37 udelay(10);
38#ifdef IO_DEBUG 38#ifdef IO_DEBUG
39 snd_printk("mixer_write 0x%x 0x%x\n", reg, data); 39 snd_printk(KERN_DEBUG "mixer_write 0x%x 0x%x\n", reg, data);
40#endif 40#endif
41} 41}
42 42
@@ -49,7 +49,7 @@ unsigned char snd_sbmixer_read(sb_t *chip, unsigned char reg)
49 result = inb(SBP(chip, MIXER_DATA)); 49 result = inb(SBP(chip, MIXER_DATA));
50 udelay(10); 50 udelay(10);
51#ifdef IO_DEBUG 51#ifdef IO_DEBUG
52 snd_printk("mixer_read 0x%x 0x%x\n", reg, result); 52 snd_printk(KERN_DEBUG "mixer_read 0x%x 0x%x\n", reg, result);
53#endif 53#endif
54 return result; 54 return result;
55} 55}
diff --git a/sound/isa/sscape.c b/sound/isa/sscape.c
index 9f6b58c79209..11588067fa4f 100644
--- a/sound/isa/sscape.c
+++ b/sound/isa/sscape.c
@@ -338,25 +338,11 @@ static inline void activate_ad1845_unsafe(unsigned io_base)
338static void soundscape_free(snd_card_t * c) 338static void soundscape_free(snd_card_t * c)
339{ 339{
340 register struct soundscape *sscape = get_card_soundscape(c); 340 register struct soundscape *sscape = get_card_soundscape(c);
341 release_resource(sscape->io_res); 341 release_and_free_resource(sscape->io_res);
342 kfree_nocheck(sscape->io_res);
343 free_dma(sscape->chip->dma1); 342 free_dma(sscape->chip->dma1);
344} 343}
345 344
346/* 345/*
347 * Put this process into an idle wait-state for a certain number
348 * of "jiffies". The process can almost certainly be rescheduled
349 * while we're waiting, and so we must NOT be holding any spinlocks
350 * when we call this function. If we are then we risk DEADLOCK in
351 * SMP (Ha!) or pre-emptible kernels.
352 */
353static inline void sleep(long jiffs, int state)
354{
355 set_current_state(state);
356 schedule_timeout(jiffs);
357}
358
359/*
360 * Tell the SoundScape to begin a DMA tranfer using the given channel. 346 * Tell the SoundScape to begin a DMA tranfer using the given channel.
361 * All locking issues are left to the caller. 347 * All locking issues are left to the caller.
362 */ 348 */
@@ -393,7 +379,7 @@ static int obp_startup_ack(struct soundscape *s, unsigned timeout)
393 unsigned long flags; 379 unsigned long flags;
394 unsigned char x; 380 unsigned char x;
395 381
396 sleep(1, TASK_INTERRUPTIBLE); 382 schedule_timeout_interruptible(1);
397 383
398 spin_lock_irqsave(&s->lock, flags); 384 spin_lock_irqsave(&s->lock, flags);
399 x = inb(HOST_DATA_IO(s->io_base)); 385 x = inb(HOST_DATA_IO(s->io_base));
@@ -420,7 +406,7 @@ static int host_startup_ack(struct soundscape *s, unsigned timeout)
420 unsigned long flags; 406 unsigned long flags;
421 unsigned char x; 407 unsigned char x;
422 408
423 sleep(1, TASK_INTERRUPTIBLE); 409 schedule_timeout_interruptible(1);
424 410
425 spin_lock_irqsave(&s->lock, flags); 411 spin_lock_irqsave(&s->lock, flags);
426 x = inb(HOST_DATA_IO(s->io_base)); 412 x = inb(HOST_DATA_IO(s->io_base));
@@ -1288,8 +1274,7 @@ static int __devinit create_sscape(const struct params *params, snd_card_t **rca
1288 free_dma(params->dma1); 1274 free_dma(params->dma1);
1289 1275
1290 _release_region: 1276 _release_region:
1291 release_resource(io_res); 1277 release_and_free_resource(io_res);
1292 kfree_nocheck(io_res);
1293 1278
1294 return err; 1279 return err;
1295} 1280}
diff --git a/sound/isa/wavefront/wavefront.c b/sound/isa/wavefront/wavefront.c
index 0a572e0a47e6..1818f1013c3f 100644
--- a/sound/isa/wavefront/wavefront.c
+++ b/sound/isa/wavefront/wavefront.c
@@ -379,10 +379,7 @@ snd_wavefront_free(snd_card_t *card)
379 snd_wavefront_card_t *acard = (snd_wavefront_card_t *)card->private_data; 379 snd_wavefront_card_t *acard = (snd_wavefront_card_t *)card->private_data;
380 380
381 if (acard) { 381 if (acard) {
382 if (acard->wavefront.res_base != NULL) { 382 release_and_free_resource(acard->wavefront.res_base);
383 release_resource(acard->wavefront.res_base);
384 kfree_nocheck(acard->wavefront.res_base);
385 }
386 if (acard->wavefront.irq > 0) 383 if (acard->wavefront.irq > 0)
387 free_irq(acard->wavefront.irq, (void *)acard); 384 free_irq(acard->wavefront.irq, (void *)acard);
388 } 385 }
diff --git a/sound/isa/wavefront/wavefront_synth.c b/sound/isa/wavefront/wavefront_synth.c
index 0c3c951009d8..abd79b781412 100644
--- a/sound/isa/wavefront/wavefront_synth.c
+++ b/sound/isa/wavefront/wavefront_synth.c
@@ -275,8 +275,7 @@ static int
275wavefront_sleep (int limit) 275wavefront_sleep (int limit)
276 276
277{ 277{
278 set_current_state(TASK_INTERRUPTIBLE); 278 schedule_timeout_interruptible(limit);
279 schedule_timeout(limit);
280 279
281 return signal_pending(current); 280 return signal_pending(current);
282} 281}
@@ -1788,8 +1787,7 @@ wavefront_should_cause_interrupt (snd_wavefront_t *dev,
1788 outb (val,port); 1787 outb (val,port);
1789 spin_unlock_irq(&dev->irq_lock); 1788 spin_unlock_irq(&dev->irq_lock);
1790 while (1) { 1789 while (1) {
1791 set_current_state(TASK_INTERRUPTIBLE); 1790 if ((timeout = schedule_timeout_interruptible(timeout)) == 0)
1792 if ((timeout = schedule_timeout(timeout)) == 0)
1793 return; 1791 return;
1794 if (dev->irq_ok) 1792 if (dev->irq_ok)
1795 return; 1793 return;
diff --git a/sound/mips/au1x00.c b/sound/mips/au1x00.c
index 3f9684f1d1d2..d08a42b24b1f 100644
--- a/sound/mips/au1x00.c
+++ b/sound/mips/au1x00.c
@@ -57,8 +57,6 @@ MODULE_CLASSES("{sound}");
57MODULE_DEVICES("{{AMD,Au1000 AC'97}}"); 57MODULE_DEVICES("{{AMD,Au1000 AC'97}}");
58#endif 58#endif
59 59
60#define chip_t au1000_t
61
62#define PLAYBACK 0 60#define PLAYBACK 0
63#define CAPTURE 1 61#define CAPTURE 1
64#define AC97_SLOT_3 0x01 62#define AC97_SLOT_3 0x01
@@ -474,7 +472,7 @@ snd_au1000_ac97_read(ac97_t *ac97, unsigned short reg)
474 u32 volatile cmd; 472 u32 volatile cmd;
475 u16 volatile data; 473 u16 volatile data;
476 int i; 474 int i;
477 spin_lock(au1000->ac97_lock); 475 spin_lock(&au1000->ac97_lock);
478/* would rather use the interupt than this polling but it works and I can't 476/* would rather use the interupt than this polling but it works and I can't
479get the interupt driven case to work efficiently */ 477get the interupt driven case to work efficiently */
480 for (i = 0; i < 0x5000; i++) 478 for (i = 0; i < 0x5000; i++)
@@ -497,7 +495,7 @@ get the interupt driven case to work efficiently */
497 } 495 }
498 496
499 data = au1000->ac97_ioport->cmd & 0xffff; 497 data = au1000->ac97_ioport->cmd & 0xffff;
500 spin_unlock(au1000->ac97_lock); 498 spin_unlock(&au1000->ac97_lock);
501 499
502 return data; 500 return data;
503 501
@@ -509,7 +507,7 @@ snd_au1000_ac97_write(ac97_t *ac97, unsigned short reg, unsigned short val)
509{ 507{
510 u32 cmd; 508 u32 cmd;
511 int i; 509 int i;
512 spin_lock(au1000->ac97_lock); 510 spin_lock(&au1000->ac97_lock);
513/* would rather use the interupt than this polling but it works and I can't 511/* would rather use the interupt than this polling but it works and I can't
514get the interupt driven case to work efficiently */ 512get the interupt driven case to work efficiently */
515 for (i = 0; i < 0x5000; i++) 513 for (i = 0; i < 0x5000; i++)
@@ -522,7 +520,7 @@ get the interupt driven case to work efficiently */
522 cmd &= ~AC97C_READ; 520 cmd &= ~AC97C_READ;
523 cmd |= ((u32) val << AC97C_WD_BIT); 521 cmd |= ((u32) val << AC97C_WD_BIT);
524 au1000->ac97_ioport->cmd = cmd; 522 au1000->ac97_ioport->cmd = cmd;
525 spin_unlock(au1000->ac97_lock); 523 spin_unlock(&au1000->ac97_lock);
526} 524}
527static void 525static void
528snd_au1000_ac97_free(ac97_t *ac97) 526snd_au1000_ac97_free(ac97_t *ac97)
@@ -606,8 +604,7 @@ snd_au1000_free(snd_card_t *card)
606 /* put internal AC97 block into reset */ 604 /* put internal AC97 block into reset */
607 au1000->ac97_ioport->cntrl = AC97C_RS; 605 au1000->ac97_ioport->cntrl = AC97C_RS;
608 au1000->ac97_ioport = NULL; 606 au1000->ac97_ioport = NULL;
609 release_resource(au1000->ac97_res_port); 607 release_and_free_resource(au1000->ac97_res_port);
610 kfree_nocheck(au1000->ac97_res_port);
611 } 608 }
612 609
613 if (au1000->stream[PLAYBACK]->dma >= 0) 610 if (au1000->stream[PLAYBACK]->dma >= 0)
diff --git a/sound/oss/au1000.c b/sound/oss/au1000.c
index 2c2ae2ee01ac..c407de86cbb6 100644
--- a/sound/oss/au1000.c
+++ b/sound/oss/au1000.c
@@ -563,7 +563,7 @@ static void start_adc(struct au1000_state *s)
563#define DMABUF_DEFAULTORDER (17-PAGE_SHIFT) 563#define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
564#define DMABUF_MINORDER 1 564#define DMABUF_MINORDER 1
565 565
566extern inline void dealloc_dmabuf(struct au1000_state *s, struct dmabuf *db) 566static inline void dealloc_dmabuf(struct au1000_state *s, struct dmabuf *db)
567{ 567{
568 struct page *page, *pend; 568 struct page *page, *pend;
569 569
@@ -667,14 +667,14 @@ static int prog_dmabuf(struct au1000_state *s, struct dmabuf *db)
667 return 0; 667 return 0;
668} 668}
669 669
670extern inline int prog_dmabuf_adc(struct au1000_state *s) 670static inline int prog_dmabuf_adc(struct au1000_state *s)
671{ 671{
672 stop_adc(s); 672 stop_adc(s);
673 return prog_dmabuf(s, &s->dma_adc); 673 return prog_dmabuf(s, &s->dma_adc);
674 674
675} 675}
676 676
677extern inline int prog_dmabuf_dac(struct au1000_state *s) 677static inline int prog_dmabuf_dac(struct au1000_state *s)
678{ 678{
679 stop_dac(s); 679 stop_dac(s);
680 return prog_dmabuf(s, &s->dma_dac); 680 return prog_dmabuf(s, &s->dma_dac);
diff --git a/sound/oss/dmasound/dmasound_awacs.c b/sound/oss/dmasound/dmasound_awacs.c
index b2bf8bac842d..cebd881b91ae 100644
--- a/sound/oss/dmasound/dmasound_awacs.c
+++ b/sound/oss/dmasound/dmasound_awacs.c
@@ -2805,16 +2805,7 @@ __init setup_beep(void)
2805 return 0 ; 2805 return 0 ;
2806} 2806}
2807 2807
2808static struct input_dev awacs_beep_dev = { 2808static struct input_dev *awacs_beep_dev;
2809 .evbit = { BIT(EV_SND) },
2810 .sndbit = { BIT(SND_BELL) | BIT(SND_TONE) },
2811 .event = awacs_beep_event,
2812 .name = "dmasound beeper",
2813 .phys = "macio/input0", /* what the heck is this?? */
2814 .id = {
2815 .bustype = BUS_HOST,
2816 },
2817};
2818 2809
2819int __init dmasound_awacs_init(void) 2810int __init dmasound_awacs_init(void)
2820{ 2811{
@@ -2907,6 +2898,22 @@ printk("dmasound_pmac: couldn't find a Codec we can handle\n");
2907 return -ENODEV; 2898 return -ENODEV;
2908 } 2899 }
2909 2900
2901 awacs_beep_dev = input_allocate_device();
2902 if (!awacs_beep_dev) {
2903 release_OF_resource(io, 0);
2904 release_OF_resource(io, 1);
2905 release_OF_resource(io, 2);
2906 printk(KERN_ERR "dmasound: can't allocate input device !\n");
2907 return -ENOMEM;
2908 }
2909
2910 awacs_beep_dev->name = "dmasound beeper";
2911 awacs_beep_dev->phys = "macio/input0";
2912 awacs_beep_dev->id.bustype = BUS_HOST;
2913 awacs_beep_dev->event = awacs_beep_event;
2914 awacs_beep_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
2915 awacs_beep_dev->evbit[0] = BIT(EV_SND);
2916
2910 /* all OF versions I've seen use this value */ 2917 /* all OF versions I've seen use this value */
2911 if (i2s_node) 2918 if (i2s_node)
2912 i2s = ioremap(io->addrs[0].address, 0x1000); 2919 i2s = ioremap(io->addrs[0].address, 0x1000);
@@ -3140,14 +3147,14 @@ printk("dmasound_pmac: Awacs/Screamer Codec Mfct: %d Rev %d\n", mfg, rev);
3140 * XXX: we should handle errors here, but that would mean 3147 * XXX: we should handle errors here, but that would mean
3141 * rewriting the whole init code. later.. 3148 * rewriting the whole init code. later..
3142 */ 3149 */
3143 input_register_device(&awacs_beep_dev); 3150 input_register_device(awacs_beep_dev);
3144 3151
3145 return dmasound_init(); 3152 return dmasound_init();
3146} 3153}
3147 3154
3148static void __exit dmasound_awacs_cleanup(void) 3155static void __exit dmasound_awacs_cleanup(void)
3149{ 3156{
3150 input_unregister_device(&awacs_beep_dev); 3157 input_unregister_device(awacs_beep_dev);
3151 3158
3152 switch (awacs_revision) { 3159 switch (awacs_revision) {
3153 case AWACS_TUMBLER: 3160 case AWACS_TUMBLER:
diff --git a/sound/oss/nec_vrc5477.c b/sound/oss/nec_vrc5477.c
index 0481e5e54ddf..9ac4bf7e1e89 100644
--- a/sound/oss/nec_vrc5477.c
+++ b/sound/oss/nec_vrc5477.c
@@ -435,7 +435,7 @@ static int ac97_codec_not_present(struct ac97_codec *codec)
435 435
436/* --------------------------------------------------------------------- */ 436/* --------------------------------------------------------------------- */
437 437
438extern inline void 438static inline void
439stop_dac(struct vrc5477_ac97_state *s) 439stop_dac(struct vrc5477_ac97_state *s)
440{ 440{
441 struct dmabuf* db = &s->dma_dac; 441 struct dmabuf* db = &s->dma_dac;
@@ -553,7 +553,7 @@ static void start_dac(struct vrc5477_ac97_state *s)
553 spin_unlock_irqrestore(&s->lock, flags); 553 spin_unlock_irqrestore(&s->lock, flags);
554} 554}
555 555
556extern inline void stop_adc(struct vrc5477_ac97_state *s) 556static inline void stop_adc(struct vrc5477_ac97_state *s)
557{ 557{
558 struct dmabuf* db = &s->dma_adc; 558 struct dmabuf* db = &s->dma_adc;
559 unsigned long flags; 559 unsigned long flags;
@@ -652,7 +652,7 @@ static void start_adc(struct vrc5477_ac97_state *s)
652#define DMABUF_DEFAULTORDER (16-PAGE_SHIFT) 652#define DMABUF_DEFAULTORDER (16-PAGE_SHIFT)
653#define DMABUF_MINORDER 1 653#define DMABUF_MINORDER 1
654 654
655extern inline void dealloc_dmabuf(struct vrc5477_ac97_state *s, 655static inline void dealloc_dmabuf(struct vrc5477_ac97_state *s,
656 struct dmabuf *db) 656 struct dmabuf *db)
657{ 657{
658 if (db->lbuf) { 658 if (db->lbuf) {
diff --git a/sound/oss/sequencer_syms.c b/sound/oss/sequencer_syms.c
index 45edfd767e4e..5d008798c310 100644
--- a/sound/oss/sequencer_syms.c
+++ b/sound/oss/sequencer_syms.c
@@ -19,7 +19,6 @@ EXPORT_SYMBOL(sequencer_timer);
19EXPORT_SYMBOL(sound_timer_init); 19EXPORT_SYMBOL(sound_timer_init);
20EXPORT_SYMBOL(sound_timer_interrupt); 20EXPORT_SYMBOL(sound_timer_interrupt);
21EXPORT_SYMBOL(sound_timer_syncinterval); 21EXPORT_SYMBOL(sound_timer_syncinterval);
22EXPORT_SYMBOL(reprogram_timer);
23 22
24/* Tuning */ 23/* Tuning */
25 24
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index a5d593c66f9f..0fb16cf335ea 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -1,13 +1,5 @@
1# ALSA PCI drivers 1# ALSA PCI drivers
2 2
3config SND_AC97_CODEC
4 tristate
5 select SND_PCM
6 select SND_AC97_BUS
7
8config SND_AC97_BUS
9 tristate
10
11menu "PCI devices" 3menu "PCI devices"
12 depends on SND!=n && PCI 4 depends on SND!=n && PCI
13 5
@@ -192,6 +184,7 @@ config SND_CA0106
192 tristate "SB Audigy LS / Live 24bit" 184 tristate "SB Audigy LS / Live 24bit"
193 depends on SND 185 depends on SND
194 select SND_AC97_CODEC 186 select SND_AC97_CODEC
187 select SND_RAWMIDI
195 help 188 help
196 Say Y here to include support for the Sound Blaster Audigy LS 189 Say Y here to include support for the Sound Blaster Audigy LS
197 and Live 24bit. 190 and Live 24bit.
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 41fc290149ed..9bde76c4c6a2 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -220,12 +220,6 @@ const char *snd_ac97_stereo_enhancements[] =
220 /* 31 */ "Reserved 31" 220 /* 31 */ "Reserved 31"
221}; 221};
222 222
223/*
224 * Shared AC97 controllers (ICH, ATIIXP...)
225 */
226static DECLARE_MUTEX(shared_codec_mutex);
227static ac97_t *shared_codec[AC97_SHARED_TYPES][4];
228
229 223
230/* 224/*
231 * I/O routines 225 * I/O routines
@@ -996,14 +990,8 @@ static int snd_ac97_free(ac97_t *ac97)
996{ 990{
997 if (ac97) { 991 if (ac97) {
998 snd_ac97_proc_done(ac97); 992 snd_ac97_proc_done(ac97);
999 if (ac97->bus) { 993 if (ac97->bus)
1000 ac97->bus->codec[ac97->num] = NULL; 994 ac97->bus->codec[ac97->num] = NULL;
1001 if (ac97->bus->shared_type) {
1002 down(&shared_codec_mutex);
1003 shared_codec[ac97->bus->shared_type-1][ac97->num] = NULL;
1004 up(&shared_codec_mutex);
1005 }
1006 }
1007 if (ac97->private_free) 995 if (ac97->private_free)
1008 ac97->private_free(ac97); 996 ac97->private_free(ac97);
1009 kfree(ac97); 997 kfree(ac97);
@@ -1139,7 +1127,6 @@ snd_kcontrol_t *snd_ac97_cnew(const snd_kcontrol_new_t *_template, ac97_t * ac97
1139{ 1127{
1140 snd_kcontrol_new_t template; 1128 snd_kcontrol_new_t template;
1141 memcpy(&template, _template, sizeof(template)); 1129 memcpy(&template, _template, sizeof(template));
1142 snd_runtime_check(!template.index, return NULL);
1143 template.index = ac97->num; 1130 template.index = ac97->num;
1144 return snd_ctl_new1(&template, ac97); 1131 return snd_ctl_new1(&template, ac97);
1145} 1132}
@@ -1758,8 +1745,7 @@ static int ac97_reset_wait(ac97_t *ac97, int timeout, int with_modem)
1758 if ((snd_ac97_read(ac97, AC97_REC_GAIN) & 0x7fff) == 0x0a05) 1745 if ((snd_ac97_read(ac97, AC97_REC_GAIN) & 0x7fff) == 0x0a05)
1759 return 0; 1746 return 0;
1760 } 1747 }
1761 set_current_state(TASK_UNINTERRUPTIBLE); 1748 schedule_timeout_uninterruptible(1);
1762 schedule_timeout(1);
1763 } while (time_after_eq(end_time, jiffies)); 1749 } while (time_after_eq(end_time, jiffies));
1764 return -ENODEV; 1750 return -ENODEV;
1765} 1751}
@@ -1889,21 +1875,6 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
1889 snd_assert(bus != NULL && template != NULL, return -EINVAL); 1875 snd_assert(bus != NULL && template != NULL, return -EINVAL);
1890 snd_assert(template->num < 4 && bus->codec[template->num] == NULL, return -EINVAL); 1876 snd_assert(template->num < 4 && bus->codec[template->num] == NULL, return -EINVAL);
1891 1877
1892 snd_assert(bus->shared_type <= AC97_SHARED_TYPES, return -EINVAL);
1893 if (bus->shared_type) {
1894 /* already shared? */
1895 down(&shared_codec_mutex);
1896 ac97 = shared_codec[bus->shared_type-1][template->num];
1897 if (ac97) {
1898 if ((ac97_is_audio(ac97) && (template->scaps & AC97_SCAP_SKIP_AUDIO)) ||
1899 (ac97_is_modem(ac97) && (template->scaps & AC97_SCAP_SKIP_MODEM))) {
1900 up(&shared_codec_mutex);
1901 return -EACCES; /* skip this */
1902 }
1903 }
1904 up(&shared_codec_mutex);
1905 }
1906
1907 card = bus->card; 1878 card = bus->card;
1908 ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL); 1879 ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL);
1909 if (ac97 == NULL) 1880 if (ac97 == NULL)
@@ -2020,8 +1991,7 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
2020 do { 1991 do {
2021 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f) 1992 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f)
2022 goto __ready_ok; 1993 goto __ready_ok;
2023 set_current_state(TASK_UNINTERRUPTIBLE); 1994 schedule_timeout_uninterruptible(1);
2024 schedule_timeout(1);
2025 } while (time_after_eq(end_time, jiffies)); 1995 } while (time_after_eq(end_time, jiffies));
2026 snd_printk(KERN_WARNING "AC'97 %d analog subsections not ready\n", ac97->num); 1996 snd_printk(KERN_WARNING "AC'97 %d analog subsections not ready\n", ac97->num);
2027 } 1997 }
@@ -2053,8 +2023,7 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
2053 do { 2023 do {
2054 if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp) 2024 if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp)
2055 goto __ready_ok; 2025 goto __ready_ok;
2056 set_current_state(TASK_UNINTERRUPTIBLE); 2026 schedule_timeout_uninterruptible(1);
2057 schedule_timeout(1);
2058 } while (time_after_eq(end_time, jiffies)); 2027 } while (time_after_eq(end_time, jiffies));
2059 snd_printk(KERN_WARNING "MC'97 %d converters and GPIO not ready (0x%x)\n", ac97->num, snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS)); 2028 snd_printk(KERN_WARNING "MC'97 %d converters and GPIO not ready (0x%x)\n", ac97->num, snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS));
2060 } 2029 }
@@ -2077,6 +2046,8 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
2077 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, AC97_GP_DRSS_78); 2046 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, AC97_GP_DRSS_78);
2078 if ((snd_ac97_read(ac97, AC97_GENERAL_PURPOSE) & AC97_GP_DRSS_MASK) == AC97_GP_DRSS_78) 2047 if ((snd_ac97_read(ac97, AC97_GENERAL_PURPOSE) & AC97_GP_DRSS_MASK) == AC97_GP_DRSS_78)
2079 ac97->flags |= AC97_DOUBLE_RATE; 2048 ac97->flags |= AC97_DOUBLE_RATE;
2049 /* restore to slots 10/11 to avoid the confliction with surrounds */
2050 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, 0);
2080 } 2051 }
2081 if (ac97->ext_id & AC97_EI_VRA) { /* VRA support */ 2052 if (ac97->ext_id & AC97_EI_VRA) { /* VRA support */
2082 snd_ac97_determine_rates(ac97, AC97_PCM_FRONT_DAC_RATE, 0, &ac97->rates[AC97_RATES_FRONT_DAC]); 2053 snd_ac97_determine_rates(ac97, AC97_PCM_FRONT_DAC_RATE, 0, &ac97->rates[AC97_RATES_FRONT_DAC]);
@@ -2153,7 +2124,7 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
2153 } 2124 }
2154 } 2125 }
2155 /* make sure the proper powerdown bits are cleared */ 2126 /* make sure the proper powerdown bits are cleared */
2156 if (ac97->scaps) { 2127 if (ac97->scaps && ac97_is_audio(ac97)) {
2157 reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 2128 reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2158 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) 2129 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
2159 reg &= ~AC97_EA_PRJ; 2130 reg &= ~AC97_EA_PRJ;
@@ -2167,13 +2138,6 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
2167 return err; 2138 return err;
2168 } 2139 }
2169 *rac97 = ac97; 2140 *rac97 = ac97;
2170
2171 if (bus->shared_type) {
2172 down(&shared_codec_mutex);
2173 shared_codec[bus->shared_type-1][ac97->num] = ac97;
2174 up(&shared_codec_mutex);
2175 }
2176
2177 return 0; 2141 return 0;
2178} 2142}
2179 2143
@@ -2295,8 +2259,7 @@ void snd_ac97_resume(ac97_t *ac97)
2295 do { 2259 do {
2296 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101) 2260 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101)
2297 break; 2261 break;
2298 set_current_state(TASK_UNINTERRUPTIBLE); 2262 schedule_timeout_uninterruptible(1);
2299 schedule_timeout(1);
2300 } while (time_after_eq(end_time, jiffies)); 2263 } while (time_after_eq(end_time, jiffies));
2301 /* FIXME: extra delay */ 2264 /* FIXME: extra delay */
2302 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8000); 2265 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8000);
@@ -2308,8 +2271,7 @@ void snd_ac97_resume(ac97_t *ac97)
2308 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID); 2271 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
2309 if (val != 0xffff && (val & 1) != 0) 2272 if (val != 0xffff && (val & 1) != 0)
2310 break; 2273 break;
2311 set_current_state(TASK_UNINTERRUPTIBLE); 2274 schedule_timeout_uninterruptible(1);
2312 schedule_timeout(1);
2313 } while (time_after_eq(end_time, jiffies)); 2275 } while (time_after_eq(end_time, jiffies));
2314 } 2276 }
2315__reset_ready: 2277__reset_ready:
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 0238cc65d32a..de1c72ad2c6b 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -163,14 +163,24 @@ static int ac97_channel_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t
163 .private_value = 1, \ 163 .private_value = 1, \
164 } 164 }
165 165
166static inline int is_surround_on(ac97_t *ac97)
167{
168 return ac97->channel_mode >= 1;
169}
170
171static inline int is_clfe_on(ac97_t *ac97)
172{
173 return ac97->channel_mode >= 2;
174}
175
166static inline int is_shared_linein(ac97_t *ac97) 176static inline int is_shared_linein(ac97_t *ac97)
167{ 177{
168 return ! ac97->indep_surround && ac97->channel_mode >= 1; 178 return ! ac97->indep_surround && is_surround_on(ac97);
169} 179}
170 180
171static inline int is_shared_micin(ac97_t *ac97) 181static inline int is_shared_micin(ac97_t *ac97)
172{ 182{
173 return ! ac97->indep_surround && ac97->channel_mode >= 2; 183 return ! ac97->indep_surround && is_clfe_on(ac97);
174} 184}
175 185
176 186
@@ -1450,7 +1460,8 @@ int patch_ad1881(ac97_t * ac97)
1450 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14)); 1460 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1451 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13)); 1461 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1452 1462
1453 snd_runtime_check(codecs[0] | codecs[1] | codecs[2], goto __end); 1463 if (! (codecs[0] || codecs[1] || codecs[2]))
1464 goto __end;
1454 1465
1455 for (idx = 0; idx < 3; idx++) 1466 for (idx = 0; idx < 3; idx++)
1456 if (ac97->spec.ad18xx.unchained[idx]) 1467 if (ac97->spec.ad18xx.unchained[idx])
@@ -1753,12 +1764,13 @@ static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_va
1753 1764
1754static void ad1888_update_jacks(ac97_t *ac97) 1765static void ad1888_update_jacks(ac97_t *ac97)
1755{ 1766{
1767 unsigned short val = 0;
1768 if (! is_shared_linein(ac97))
1769 val |= (1 << 12);
1770 if (! is_shared_micin(ac97))
1771 val |= (1 << 11);
1756 /* shared Line-In */ 1772 /* shared Line-In */
1757 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12, 1773 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
1758 is_shared_linein(ac97) ? 0 : 1 << 12);
1759 /* shared Mic */
1760 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11,
1761 is_shared_micin(ac97) ? 0 : 1 << 11);
1762} 1774}
1763 1775
1764static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = { 1776static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = {
@@ -1852,12 +1864,7 @@ static const snd_kcontrol_new_t snd_ac97_ad1985_controls[] = {
1852 1864
1853static void ad1985_update_jacks(ac97_t *ac97) 1865static void ad1985_update_jacks(ac97_t *ac97)
1854{ 1866{
1855 /* shared Line-In */ 1867 ad1888_update_jacks(ac97);
1856 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12,
1857 is_shared_linein(ac97) ? 0 : 1 << 12);
1858 /* shared Mic */
1859 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11,
1860 is_shared_micin(ac97) ? 0 : 1 << 11);
1861 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9, 1868 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
1862 is_shared_micin(ac97) ? 0 : 1 << 9); 1869 is_shared_micin(ac97) ? 0 : 1 << 9);
1863} 1870}
@@ -2442,21 +2449,37 @@ int patch_cm9739(ac97_t * ac97)
2442 2449
2443static void cm9761_update_jacks(ac97_t *ac97) 2450static void cm9761_update_jacks(ac97_t *ac97)
2444{ 2451{
2445 unsigned short surr_vals[2][2] = { 2452 /* FIXME: check the bits for each model
2446 { 0x0008, 0x0400 }, /* off, on */ 2453 * model 83 is confirmed to work
2447 { 0x0000, 0x0408 }, /* off, on (9761-82 rev.B) */ 2454 */
2455 static unsigned short surr_on[3][2] = {
2456 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
2457 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
2458 { 0x0000, 0x0008 }, /* 9761-83 */
2459 };
2460 static unsigned short clfe_on[3][2] = {
2461 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
2462 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
2463 { 0x0000, 0x1000 }, /* 9761-83 */
2464 };
2465 static unsigned short surr_shared[3][2] = {
2466 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
2467 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
2468 { 0x0000, 0x0400 }, /* 9761-83 */
2448 }; 2469 };
2449 unsigned short clfe_vals[2][2] = { 2470 static unsigned short clfe_shared[3][2] = {
2450 { 0x2000, 0x1880 }, /* off, on */ 2471 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
2451 { 0x1000, 0x2880 }, /* off, on (9761-82 rev.B) */ 2472 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
2473 { 0x2000, 0x0800 }, /* 9761-83 */
2452 }; 2474 };
2475 unsigned short val = 0;
2453 2476
2454 /* shared Line-In */ 2477 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
2455 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x0408, 2478 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
2456 surr_vals[ac97->spec.dev_flags][is_shared_linein(ac97)]); 2479 val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
2457 /* shared Mic */ 2480 val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
2458 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3880, 2481
2459 clfe_vals[ac97->spec.dev_flags][is_shared_micin(ac97)]); 2482 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
2460} 2483}
2461 2484
2462static const snd_kcontrol_new_t snd_ac97_cm9761_controls[] = { 2485static const snd_kcontrol_new_t snd_ac97_cm9761_controls[] = {
@@ -2551,7 +2574,7 @@ int patch_cm9761(ac97_t *ac97)
2551 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808); 2574 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2552 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808); 2575 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2553 2576
2554 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B */ 2577 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
2555 if (ac97->id == AC97_ID_CM9761_82) { 2578 if (ac97->id == AC97_ID_CM9761_82) {
2556 unsigned short tmp; 2579 unsigned short tmp;
2557 /* check page 1, reg 0x60 */ 2580 /* check page 1, reg 0x60 */
@@ -2560,7 +2583,8 @@ int patch_cm9761(ac97_t *ac97)
2560 tmp = snd_ac97_read(ac97, 0x60); 2583 tmp = snd_ac97_read(ac97, 0x60);
2561 ac97->spec.dev_flags = tmp & 1; /* revision B? */ 2584 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2562 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val); 2585 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
2563 } 2586 } else if (ac97->id == AC97_ID_CM9761_83)
2587 ac97->spec.dev_flags = 2;
2564 2588
2565 ac97->build_ops = &patch_cm9761_ops; 2589 ac97->build_ops = &patch_cm9761_ops;
2566 2590
diff --git a/sound/pci/ac97/ac97_pcm.c b/sound/pci/ac97/ac97_pcm.c
index dd289b9512e1..ded13165d635 100644
--- a/sound/pci/ac97/ac97_pcm.c
+++ b/sound/pci/ac97/ac97_pcm.c
@@ -303,6 +303,15 @@ int snd_ac97_set_rate(ac97_t *ac97, int reg, unsigned int rate)
303 AC97_EA_DRA, dbl ? AC97_EA_DRA : 0); 303 AC97_EA_DRA, dbl ? AC97_EA_DRA : 0);
304 snd_ac97_update(ac97, reg, tmp & 0xffff); 304 snd_ac97_update(ac97, reg, tmp & 0xffff);
305 snd_ac97_read(ac97, reg); 305 snd_ac97_read(ac97, reg);
306 if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE) {
307 /* Intel controllers require double rate data to be put in
308 * slots 7+8
309 */
310 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE,
311 AC97_GP_DRSS_MASK,
312 dbl ? AC97_GP_DRSS_78 : 0);
313 snd_ac97_read(ac97, AC97_GENERAL_PURPOSE);
314 }
306 return 0; 315 return 0;
307} 316}
308 317
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index d7d99a25c5e5..e72ccd1a004f 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -50,7 +50,7 @@
50#include "ad1889.h" 50#include "ad1889.h"
51#include "ac97/ac97_id.h" 51#include "ac97/ac97_id.h"
52 52
53#define AD1889_DRVVER "$Revision: 1.3 $" 53#define AD1889_DRVVER "$Revision: 1.4 $"
54 54
55MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>, Thibaut Varene <t-bone@parisc-linux.org>"); 55MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>, Thibaut Varene <t-bone@parisc-linux.org>");
56MODULE_DESCRIPTION("Analog Devices AD1889 ALSA sound driver"); 56MODULE_DESCRIPTION("Analog Devices AD1889 ALSA sound driver");
@@ -982,8 +982,7 @@ snd_ad1889_create(snd_card_t *card,
982 return 0; 982 return 0;
983 983
984free_and_ret: 984free_and_ret:
985 if (chip) 985 kfree(chip);
986 kfree(chip);
987 pci_disable_device(pci); 986 pci_disable_device(pci);
988 987
989 return err; 988 return err;
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index f35b558c29b2..4e76c4a636d9 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -45,23 +45,25 @@ MODULE_DESCRIPTION("ALI M5451");
45MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
46MODULE_SUPPORTED_DEVICE("{{ALI,M5451,pci},{ALI,M5451}}"); 46MODULE_SUPPORTED_DEVICE("{{ALI,M5451,pci},{ALI,M5451}}");
47 47
48static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 48static int index = SNDRV_DEFAULT_IDX1; /* Index */
49static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 49static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
50static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 50static int pcm_channels = 32;
51static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 32}; 51static int spdif = 0;
52static int spdif[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
53 52
54module_param_array(index, int, NULL, 0444); 53module_param(index, int, 0444);
55MODULE_PARM_DESC(index, "Index value for ALI M5451 PCI Audio."); 54MODULE_PARM_DESC(index, "Index value for ALI M5451 PCI Audio.");
56module_param_array(id, charp, NULL, 0444); 55module_param(id, charp, 0444);
57MODULE_PARM_DESC(id, "ID string for ALI M5451 PCI Audio."); 56MODULE_PARM_DESC(id, "ID string for ALI M5451 PCI Audio.");
58module_param_array(enable, bool, NULL, 0444); 57module_param(pcm_channels, int, 0444);
59MODULE_PARM_DESC(enable, "Enable ALI 5451 PCI Audio.");
60module_param_array(pcm_channels, int, NULL, 0444);
61MODULE_PARM_DESC(pcm_channels, "PCM Channels"); 58MODULE_PARM_DESC(pcm_channels, "PCM Channels");
62module_param_array(spdif, bool, NULL, 0444); 59module_param(spdif, bool, 0444);
63MODULE_PARM_DESC(spdif, "Support SPDIF I/O"); 60MODULE_PARM_DESC(spdif, "Support SPDIF I/O");
64 61
62/* just for backward compatibility */
63static int enable;
64module_param(enable, bool, 0444);
65
66
65/* 67/*
66 * Debug part definitions 68 * Debug part definitions
67 */ 69 */
@@ -396,10 +398,8 @@ static int snd_ali_codec_ready( ali_t *codec,
396 res = snd_ali_5451_peek(codec,port); 398 res = snd_ali_5451_peek(codec,port);
397 if (! (res & 0x8000)) 399 if (! (res & 0x8000))
398 return 0; 400 return 0;
399 if (sched) { 401 if (sched)
400 set_current_state(TASK_UNINTERRUPTIBLE); 402 schedule_timeout_uninterruptible(1);
401 schedule_timeout(1);
402 }
403 } while (time_after_eq(end_time, jiffies)); 403 } while (time_after_eq(end_time, jiffies));
404 snd_ali_5451_poke(codec, port, res & ~0x8000); 404 snd_ali_5451_poke(codec, port, res & ~0x8000);
405 snd_printdd("ali_codec_ready: codec is not ready.\n "); 405 snd_printdd("ali_codec_ready: codec is not ready.\n ");
@@ -419,12 +419,10 @@ static int snd_ali_stimer_ready(ali_t *codec, int sched)
419 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); 419 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER);
420 if (dwChk2 != dwChk1) 420 if (dwChk2 != dwChk1)
421 return 0; 421 return 0;
422 if (sched) { 422 if (sched)
423 set_current_state(TASK_UNINTERRUPTIBLE); 423 schedule_timeout_uninterruptible(1);
424 schedule_timeout(1);
425 }
426 } while (time_after_eq(end_time, jiffies)); 424 } while (time_after_eq(end_time, jiffies));
427 snd_printk("ali_stimer_read: stimer is not ready.\n"); 425 snd_printk(KERN_ERR "ali_stimer_read: stimer is not ready.\n");
428 return -EIO; 426 return -EIO;
429} 427}
430 428
@@ -436,7 +434,7 @@ static void snd_ali_codec_poke(ali_t *codec,int secondary,
436 unsigned int port = 0; 434 unsigned int port = 0;
437 435
438 if (reg >= 0x80) { 436 if (reg >= 0x80) {
439 snd_printk("ali_codec_poke: reg(%xh) invalid.\n", reg); 437 snd_printk(KERN_ERR "ali_codec_poke: reg(%xh) invalid.\n", reg);
440 return; 438 return;
441 } 439 }
442 440
@@ -465,7 +463,7 @@ static unsigned short snd_ali_codec_peek( ali_t *codec,
465 unsigned int port = 0; 463 unsigned int port = 0;
466 464
467 if (reg >= 0x80) { 465 if (reg >= 0x80) {
468 snd_printk("ali_codec_peek: reg(%xh) invalid.\n", reg); 466 snd_printk(KERN_ERR "ali_codec_peek: reg(%xh) invalid.\n", reg);
469 return ~0; 467 return ~0;
470 } 468 }
471 469
@@ -669,7 +667,7 @@ static int snd_ali_alloc_pcm_channel(ali_t *codec, int channel)
669 unsigned int idx = channel & 0x1f; 667 unsigned int idx = channel & 0x1f;
670 668
671 if (codec->synth.chcnt >= ALI_CHANNELS){ 669 if (codec->synth.chcnt >= ALI_CHANNELS){
672 snd_printk("ali_alloc_pcm_channel: no free channels.\n"); 670 snd_printk(KERN_ERR "ali_alloc_pcm_channel: no free channels.\n");
673 return -1; 671 return -1;
674 } 672 }
675 673
@@ -700,7 +698,7 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec)
700 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) { 698 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) {
701 return result; 699 return result;
702 } else { 700 } else {
703 snd_printk("ali_find_free_channel: record channel is busy now.\n"); 701 snd_printk(KERN_ERR "ali_find_free_channel: record channel is busy now.\n");
704 return -1; 702 return -1;
705 } 703 }
706 } 704 }
@@ -712,7 +710,7 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec)
712 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) { 710 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) {
713 return result; 711 return result;
714 } else { 712 } else {
715 snd_printk("ali_find_free_channel: S/PDIF out channel is in busy now.\n"); 713 snd_printk(KERN_ERR "ali_find_free_channel: S/PDIF out channel is in busy now.\n");
716 } 714 }
717 } 715 }
718 716
@@ -720,7 +718,7 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec)
720 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) 718 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0)
721 return result; 719 return result;
722 } 720 }
723 snd_printk("ali_find_free_channel: no free channels.\n"); 721 snd_printk(KERN_ERR "ali_find_free_channel: no free channels.\n");
724 return -1; 722 return -1;
725} 723}
726 724
@@ -734,7 +732,7 @@ static void snd_ali_free_channel_pcm(ali_t *codec, int channel)
734 return; 732 return;
735 733
736 if (!(codec->synth.chmap & (1 << idx))) { 734 if (!(codec->synth.chmap & (1 << idx))) {
737 snd_printk("ali_free_channel_pcm: channel %d is not in use.\n",channel); 735 snd_printk(KERN_ERR "ali_free_channel_pcm: channel %d is not in use.\n",channel);
738 return; 736 return;
739 } else { 737 } else {
740 codec->synth.chmap &= ~(1 << idx); 738 codec->synth.chmap &= ~(1 << idx);
@@ -796,7 +794,7 @@ static void snd_ali_detect_spdif_rate(ali_t *codec)
796 } 794 }
797 795
798 if (count > 50000) { 796 if (count > 50000) {
799 snd_printk("ali_detect_spdif_rate: timeout!\n"); 797 snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n");
800 return; 798 return;
801 } 799 }
802 800
@@ -809,7 +807,7 @@ static void snd_ali_detect_spdif_rate(ali_t *codec)
809 } 807 }
810 808
811 if (count > 50000) { 809 if (count > 50000) {
812 snd_printk("ali_detect_spdif_rate: timeout!\n"); 810 snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n");
813 return; 811 return;
814 } 812 }
815 813
@@ -1077,7 +1075,7 @@ static snd_ali_voice_t *snd_ali_alloc_voice(ali_t * codec, int type, int rec, in
1077 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) : 1075 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) :
1078 snd_ali_find_free_channel(codec,rec); 1076 snd_ali_find_free_channel(codec,rec);
1079 if(idx < 0) { 1077 if(idx < 0) {
1080 snd_printk("ali_alloc_voice: err.\n"); 1078 snd_printk(KERN_ERR "ali_alloc_voice: err.\n");
1081 spin_unlock_irqrestore(&codec->voice_alloc, flags); 1079 spin_unlock_irqrestore(&codec->voice_alloc, flags);
1082 return NULL; 1080 return NULL;
1083 } 1081 }
@@ -1479,13 +1477,13 @@ static int snd_ali_prepare(snd_pcm_substream_t * substream)
1479 } 1477 }
1480 rate = snd_ali_get_spdif_in_rate(codec); 1478 rate = snd_ali_get_spdif_in_rate(codec);
1481 if (rate == 0) { 1479 if (rate == 0) {
1482 snd_printk("ali_capture_preapre: spdif rate detect err!\n"); 1480 snd_printk(KERN_WARNING "ali_capture_preapre: spdif rate detect err!\n");
1483 rate = 48000; 1481 rate = 48000;
1484 } 1482 }
1485 bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL)); 1483 bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL));
1486 if (bValue & 0x10) { 1484 if (bValue & 0x10) {
1487 outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL)); 1485 outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL));
1488 printk("clear SPDIF parity error flag.\n"); 1486 printk(KERN_WARNING "clear SPDIF parity error flag.\n");
1489 } 1487 }
1490 1488
1491 if (rate != 48000) 1489 if (rate != 48000)
@@ -1795,6 +1793,7 @@ struct ali_pcm_description {
1795 unsigned int capture_num; 1793 unsigned int capture_num;
1796 snd_pcm_ops_t *playback_ops; 1794 snd_pcm_ops_t *playback_ops;
1797 snd_pcm_ops_t *capture_ops; 1795 snd_pcm_ops_t *capture_ops;
1796 unsigned short class;
1798}; 1797};
1799 1798
1800 1799
@@ -1813,12 +1812,11 @@ static int __devinit snd_ali_pcm(ali_t * codec, int device, struct ali_pcm_descr
1813 err = snd_pcm_new(codec->card, desc->name, device, 1812 err = snd_pcm_new(codec->card, desc->name, device,
1814 desc->playback_num, desc->capture_num, &pcm); 1813 desc->playback_num, desc->capture_num, &pcm);
1815 if (err < 0) { 1814 if (err < 0) {
1816 snd_printk("snd_ali_pcm: err called snd_pcm_new.\n"); 1815 snd_printk(KERN_ERR "snd_ali_pcm: err called snd_pcm_new.\n");
1817 return err; 1816 return err;
1818 } 1817 }
1819 pcm->private_data = codec; 1818 pcm->private_data = codec;
1820 pcm->private_free = snd_ali_pcm_free; 1819 pcm->private_free = snd_ali_pcm_free;
1821 pcm->info_flags = 0;
1822 if (desc->playback_ops) 1820 if (desc->playback_ops)
1823 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, desc->playback_ops); 1821 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, desc->playback_ops);
1824 if (desc->capture_ops) 1822 if (desc->capture_ops)
@@ -1828,6 +1826,7 @@ static int __devinit snd_ali_pcm(ali_t * codec, int device, struct ali_pcm_descr
1828 snd_dma_pci_data(codec->pci), 64*1024, 128*1024); 1826 snd_dma_pci_data(codec->pci), 64*1024, 128*1024);
1829 1827
1830 pcm->info_flags = 0; 1828 pcm->info_flags = 0;
1829 pcm->dev_class = desc->class;
1831 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; 1830 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
1832 strcpy(pcm->name, desc->name); 1831 strcpy(pcm->name, desc->name);
1833 codec->pcm[0] = pcm; 1832 codec->pcm[0] = pcm;
@@ -1836,7 +1835,7 @@ static int __devinit snd_ali_pcm(ali_t * codec, int device, struct ali_pcm_descr
1836 1835
1837static struct ali_pcm_description ali_pcms[] = { 1836static struct ali_pcm_description ali_pcms[] = {
1838 { "ALI 5451", ALI_CHANNELS, 1, &snd_ali_playback_ops, &snd_ali_capture_ops }, 1837 { "ALI 5451", ALI_CHANNELS, 1, &snd_ali_playback_ops, &snd_ali_capture_ops },
1839 { "ALI 5451 modem", 1, 1, &snd_ali_modem_playback_ops, &snd_ali_modem_capture_ops } 1838 { "ALI 5451 modem", 1, 1, &snd_ali_modem_playback_ops, &snd_ali_modem_capture_ops, SNDRV_PCM_CLASS_MODEM }
1840}; 1839};
1841 1840
1842static int __devinit snd_ali_build_pcms(ali_t *codec) 1841static int __devinit snd_ali_build_pcms(ali_t *codec)
@@ -1991,7 +1990,7 @@ static int __devinit snd_ali_mixer(ali_t * codec)
1991 for ( i = 0 ; i < codec->num_of_codecs ; i++) { 1990 for ( i = 0 ; i < codec->num_of_codecs ; i++) {
1992 ac97.num = i; 1991 ac97.num = i;
1993 if ((err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i])) < 0) { 1992 if ((err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i])) < 0) {
1994 snd_printk("ali mixer %d creating error.\n", i); 1993 snd_printk(KERN_ERR "ali mixer %d creating error.\n", i);
1995 if(i == 0) 1994 if(i == 0)
1996 return err; 1995 return err;
1997 codec->num_of_codecs = 1; 1996 codec->num_of_codecs = 1;
@@ -2125,7 +2124,7 @@ static int snd_ali_chip_init(ali_t *codec)
2125 snd_ali_printk("chip initializing ... \n"); 2124 snd_ali_printk("chip initializing ... \n");
2126 2125
2127 if (snd_ali_reset_5451(codec)) { 2126 if (snd_ali_reset_5451(codec)) {
2128 snd_printk("ali_chip_init: reset 5451 error.\n"); 2127 snd_printk(KERN_ERR "ali_chip_init: reset 5451 error.\n");
2129 return -1; 2128 return -1;
2130 } 2129 }
2131 2130
@@ -2200,7 +2199,7 @@ static int __devinit snd_ali_resources(ali_t *codec)
2200 codec->port = pci_resource_start(codec->pci, 0); 2199 codec->port = pci_resource_start(codec->pci, 0);
2201 2200
2202 if (request_irq(codec->pci->irq, snd_ali_card_interrupt, SA_INTERRUPT|SA_SHIRQ, "ALI 5451", (void *)codec)) { 2201 if (request_irq(codec->pci->irq, snd_ali_card_interrupt, SA_INTERRUPT|SA_SHIRQ, "ALI 5451", (void *)codec)) {
2203 snd_printk("Unable to request irq.\n"); 2202 snd_printk(KERN_ERR "Unable to request irq.\n");
2204 return -EBUSY; 2203 return -EBUSY;
2205 } 2204 }
2206 codec->irq = codec->pci->irq; 2205 codec->irq = codec->pci->irq;
@@ -2240,7 +2239,7 @@ static int __devinit snd_ali_create(snd_card_t * card,
2240 /* check, if we can restrict PCI DMA transfers to 31 bits */ 2239 /* check, if we can restrict PCI DMA transfers to 31 bits */
2241 if (pci_set_dma_mask(pci, 0x7fffffff) < 0 || 2240 if (pci_set_dma_mask(pci, 0x7fffffff) < 0 ||
2242 pci_set_consistent_dma_mask(pci, 0x7fffffff) < 0) { 2241 pci_set_consistent_dma_mask(pci, 0x7fffffff) < 0) {
2243 snd_printk("architecture does not support 31bit PCI busmaster DMA\n"); 2242 snd_printk(KERN_ERR "architecture does not support 31bit PCI busmaster DMA\n");
2244 pci_disable_device(pci); 2243 pci_disable_device(pci);
2245 return -ENXIO; 2244 return -ENXIO;
2246 } 2245 }
@@ -2329,7 +2328,7 @@ static int __devinit snd_ali_create(snd_card_t * card,
2329 } 2328 }
2330 2329
2331 if ((err = snd_ali_chip_init(codec)) < 0) { 2330 if ((err = snd_ali_chip_init(codec)) < 0) {
2332 snd_printk("ali create: chip init error.\n"); 2331 snd_printk(KERN_ERR "ali create: chip init error.\n");
2333 return err; 2332 return err;
2334 } 2333 }
2335 2334
@@ -2352,25 +2351,17 @@ static int __devinit snd_ali_create(snd_card_t * card,
2352static int __devinit snd_ali_probe(struct pci_dev *pci, 2351static int __devinit snd_ali_probe(struct pci_dev *pci,
2353 const struct pci_device_id *pci_id) 2352 const struct pci_device_id *pci_id)
2354{ 2353{
2355 static int dev;
2356 snd_card_t *card; 2354 snd_card_t *card;
2357 ali_t *codec; 2355 ali_t *codec;
2358 int err; 2356 int err;
2359 2357
2360 snd_ali_printk("probe ...\n"); 2358 snd_ali_printk("probe ...\n");
2361 2359
2362 if (dev >= SNDRV_CARDS) 2360 card = snd_card_new(index, id, THIS_MODULE, 0);
2363 return -ENODEV;
2364 if (!enable[dev]) {
2365 dev++;
2366 return -ENOENT;
2367 }
2368
2369 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2370 if (card == NULL) 2361 if (card == NULL)
2371 return -ENOMEM; 2362 return -ENOMEM;
2372 2363
2373 if ((err = snd_ali_create(card, pci, pcm_channels[dev], spdif[dev], &codec)) < 0) { 2364 if ((err = snd_ali_create(card, pci, pcm_channels, spdif, &codec)) < 0) {
2374 snd_card_free(card); 2365 snd_card_free(card);
2375 return err; 2366 return err;
2376 } 2367 }
@@ -2401,7 +2392,6 @@ static int __devinit snd_ali_probe(struct pci_dev *pci,
2401 return err; 2392 return err;
2402 } 2393 }
2403 pci_set_drvdata(pci, card); 2394 pci_set_drvdata(pci, card);
2404 dev++;
2405 return 0; 2395 return 0;
2406} 2396}
2407 2397
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c
index 196ec1c61bb4..7c61561f297f 100644
--- a/sound/pci/als4000.c
+++ b/sound/pci/als4000.c
@@ -594,8 +594,7 @@ static int __devinit snd_als4000_create_gameport(snd_card_als4000_t *acard, int
594 acard->gameport = gp = gameport_allocate_port(); 594 acard->gameport = gp = gameport_allocate_port();
595 if (!gp) { 595 if (!gp) {
596 printk(KERN_ERR "als4000: cannot allocate memory for gameport\n"); 596 printk(KERN_ERR "als4000: cannot allocate memory for gameport\n");
597 release_resource(r); 597 release_and_free_resource(r);
598 kfree_nocheck(r);
599 return -ENOMEM; 598 return -ENOMEM;
600 } 599 }
601 600
@@ -622,8 +621,7 @@ static void snd_als4000_free_gameport(snd_card_als4000_t *acard)
622 acard->gameport = NULL; 621 acard->gameport = NULL;
623 622
624 snd_als4000_set_addr(acard->gcr, 0, 0, 0, 0); /* disable joystick */ 623 snd_als4000_set_addr(acard->gcr, 0, 0, 0, 0); /* disable joystick */
625 release_resource(r); 624 release_and_free_resource(r);
626 kfree_nocheck(r);
627 } 625 }
628} 626}
629#else 627#else
@@ -669,7 +667,7 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
669 /* check, if we can restrict PCI DMA transfers to 24 bits */ 667 /* check, if we can restrict PCI DMA transfers to 24 bits */
670 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 || 668 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
671 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) { 669 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
672 snd_printk("architecture does not support 24bit PCI busmaster DMA\n"); 670 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n");
673 pci_disable_device(pci); 671 pci_disable_device(pci);
674 return -ENXIO; 672 return -ENXIO;
675 } 673 }
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index 241eacf1e652..f5dad9248e39 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -39,26 +39,27 @@ MODULE_DESCRIPTION("ATI IXP AC97 controller");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250/300/400}}"); 40MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250/300/400}}");
41 41
42static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 42static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
43static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 43static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
44static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 44static int ac97_clock = 48000;
45static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 48000}; 45static char *ac97_quirk;
46static char *ac97_quirk[SNDRV_CARDS]; 46static int spdif_aclink = 1;
47static int spdif_aclink[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; 47
48 48module_param(index, int, 0444);
49module_param_array(index, int, NULL, 0444);
50MODULE_PARM_DESC(index, "Index value for ATI IXP controller."); 49MODULE_PARM_DESC(index, "Index value for ATI IXP controller.");
51module_param_array(id, charp, NULL, 0444); 50module_param(id, charp, 0444);
52MODULE_PARM_DESC(id, "ID string for ATI IXP controller."); 51MODULE_PARM_DESC(id, "ID string for ATI IXP controller.");
53module_param_array(enable, bool, NULL, 0444); 52module_param(ac97_clock, int, 0444);
54MODULE_PARM_DESC(enable, "Enable audio part of ATI IXP controller.");
55module_param_array(ac97_clock, int, NULL, 0444);
56MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz)."); 53MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
57module_param_array(ac97_quirk, charp, NULL, 0444); 54module_param(ac97_quirk, charp, 0444);
58MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); 55MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
59module_param_array(spdif_aclink, bool, NULL, 0444); 56module_param(spdif_aclink, bool, 0444);
60MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link."); 57MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link.");
61 58
59/* just for backward compatibility */
60static int enable;
61module_param(enable, bool, 0444);
62
62 63
63/* 64/*
64 */ 65 */
@@ -329,8 +330,7 @@ static int snd_atiixp_update_bits(atiixp_t *chip, unsigned int reg,
329 330
330/* delay for one tick */ 331/* delay for one tick */
331#define do_delay() do { \ 332#define do_delay() do { \
332 set_current_state(TASK_UNINTERRUPTIBLE); \ 333 schedule_timeout_uninterruptible(1); \
333 schedule_timeout(1); \
334} while (0) 334} while (0)
335 335
336 336
@@ -1372,7 +1372,6 @@ static int __devinit snd_atiixp_mixer_new(atiixp_t *chip, int clock, const char
1372 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0) 1372 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0)
1373 return err; 1373 return err;
1374 pbus->clock = clock; 1374 pbus->clock = clock;
1375 pbus->shared_type = AC97_SHARED_TYPE_ATIIXP; /* shared with modem driver */
1376 chip->ac97_bus = pbus; 1375 chip->ac97_bus = pbus;
1377 1376
1378 codec_count = 0; 1377 codec_count = 0;
@@ -1579,26 +1578,18 @@ static int __devinit snd_atiixp_create(snd_card_t *card,
1579static int __devinit snd_atiixp_probe(struct pci_dev *pci, 1578static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1580 const struct pci_device_id *pci_id) 1579 const struct pci_device_id *pci_id)
1581{ 1580{
1582 static int dev;
1583 snd_card_t *card; 1581 snd_card_t *card;
1584 atiixp_t *chip; 1582 atiixp_t *chip;
1585 unsigned char revision; 1583 unsigned char revision;
1586 int err; 1584 int err;
1587 1585
1588 if (dev >= SNDRV_CARDS) 1586 card = snd_card_new(index, id, THIS_MODULE, 0);
1589 return -ENODEV;
1590 if (!enable[dev]) {
1591 dev++;
1592 return -ENOENT;
1593 }
1594
1595 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1596 if (card == NULL) 1587 if (card == NULL)
1597 return -ENOMEM; 1588 return -ENOMEM;
1598 1589
1599 pci_read_config_byte(pci, PCI_REVISION_ID, &revision); 1590 pci_read_config_byte(pci, PCI_REVISION_ID, &revision);
1600 1591
1601 strcpy(card->driver, spdif_aclink[dev] ? "ATIIXP" : "ATIIXP-SPDMA"); 1592 strcpy(card->driver, spdif_aclink ? "ATIIXP" : "ATIIXP-SPDMA");
1602 strcpy(card->shortname, "ATI IXP"); 1593 strcpy(card->shortname, "ATI IXP");
1603 if ((err = snd_atiixp_create(card, pci, &chip)) < 0) 1594 if ((err = snd_atiixp_create(card, pci, &chip)) < 0)
1604 goto __error; 1595 goto __error;
@@ -1606,9 +1597,9 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1606 if ((err = snd_atiixp_aclink_reset(chip)) < 0) 1597 if ((err = snd_atiixp_aclink_reset(chip)) < 0)
1607 goto __error; 1598 goto __error;
1608 1599
1609 chip->spdif_over_aclink = spdif_aclink[dev]; 1600 chip->spdif_over_aclink = spdif_aclink;
1610 1601
1611 if ((err = snd_atiixp_mixer_new(chip, ac97_clock[dev], ac97_quirk[dev])) < 0) 1602 if ((err = snd_atiixp_mixer_new(chip, ac97_clock, ac97_quirk)) < 0)
1612 goto __error; 1603 goto __error;
1613 1604
1614 if ((err = snd_atiixp_pcm_new(chip)) < 0) 1605 if ((err = snd_atiixp_pcm_new(chip)) < 0)
@@ -1629,7 +1620,6 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1629 goto __error; 1620 goto __error;
1630 1621
1631 pci_set_drvdata(pci, card); 1622 pci_set_drvdata(pci, card);
1632 dev++;
1633 return 0; 1623 return 0;
1634 1624
1635 __error: 1625 __error:
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index c1a239a4dac6..0cf202079571 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -39,20 +39,21 @@ MODULE_DESCRIPTION("ATI IXP MC97 controller");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250}}"); 40MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250}}");
41 41
42static int index[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -2}; /* Exclude the first card */ 42static int index = -2; /* Exclude the first card */
43static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 43static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
44static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 44static int ac97_clock = 48000;
45static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 48000};
46 45
47module_param_array(index, int, NULL, 0444); 46module_param(index, int, 0444);
48MODULE_PARM_DESC(index, "Index value for ATI IXP controller."); 47MODULE_PARM_DESC(index, "Index value for ATI IXP controller.");
49module_param_array(id, charp, NULL, 0444); 48module_param(id, charp, 0444);
50MODULE_PARM_DESC(id, "ID string for ATI IXP controller."); 49MODULE_PARM_DESC(id, "ID string for ATI IXP controller.");
51module_param_array(enable, bool, NULL, 0444); 50module_param(ac97_clock, int, 0444);
52MODULE_PARM_DESC(enable, "Enable audio part of ATI IXP controller.");
53module_param_array(ac97_clock, int, NULL, 0444);
54MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz)."); 51MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
55 52
53/* just for backward compatibility */
54static int enable;
55module_param(enable, bool, 0444);
56
56 57
57/* 58/*
58 */ 59 */
@@ -306,8 +307,7 @@ static int snd_atiixp_update_bits(atiixp_t *chip, unsigned int reg,
306 307
307/* delay for one tick */ 308/* delay for one tick */
308#define do_delay() do { \ 309#define do_delay() do { \
309 set_current_state(TASK_UNINTERRUPTIBLE); \ 310 schedule_timeout_uninterruptible(1); \
310 schedule_timeout(1); \
311} while (0) 311} while (0)
312 312
313 313
@@ -989,6 +989,7 @@ static int __devinit snd_atiixp_pcm_new(atiixp_t *chip)
989 return err; 989 return err;
990 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_atiixp_playback_ops); 990 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_atiixp_playback_ops);
991 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_atiixp_capture_ops); 991 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_atiixp_capture_ops);
992 pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
992 pcm->private_data = chip; 993 pcm->private_data = chip;
993 strcpy(pcm->name, "ATI IXP MC97"); 994 strcpy(pcm->name, "ATI IXP MC97");
994 chip->pcmdevs[ATI_PCMDEV_ANALOG] = pcm; 995 chip->pcmdevs[ATI_PCMDEV_ANALOG] = pcm;
@@ -1067,7 +1068,6 @@ static int __devinit snd_atiixp_mixer_new(atiixp_t *chip, int clock)
1067 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0) 1068 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0)
1068 return err; 1069 return err;
1069 pbus->clock = clock; 1070 pbus->clock = clock;
1070 pbus->shared_type = AC97_SHARED_TYPE_ATIIXP; /* shared with audio driver */
1071 chip->ac97_bus = pbus; 1071 chip->ac97_bus = pbus;
1072 1072
1073 codec_count = 0; 1073 codec_count = 0;
@@ -1256,20 +1256,12 @@ static int __devinit snd_atiixp_create(snd_card_t *card,
1256static int __devinit snd_atiixp_probe(struct pci_dev *pci, 1256static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1257 const struct pci_device_id *pci_id) 1257 const struct pci_device_id *pci_id)
1258{ 1258{
1259 static int dev;
1260 snd_card_t *card; 1259 snd_card_t *card;
1261 atiixp_t *chip; 1260 atiixp_t *chip;
1262 unsigned char revision; 1261 unsigned char revision;
1263 int err; 1262 int err;
1264 1263
1265 if (dev >= SNDRV_CARDS) 1264 card = snd_card_new(index, id, THIS_MODULE, 0);
1266 return -ENODEV;
1267 if (!enable[dev]) {
1268 dev++;
1269 return -ENOENT;
1270 }
1271
1272 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1273 if (card == NULL) 1265 if (card == NULL)
1274 return -ENOMEM; 1266 return -ENOMEM;
1275 1267
@@ -1283,7 +1275,7 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1283 if ((err = snd_atiixp_aclink_reset(chip)) < 0) 1275 if ((err = snd_atiixp_aclink_reset(chip)) < 0)
1284 goto __error; 1276 goto __error;
1285 1277
1286 if ((err = snd_atiixp_mixer_new(chip, ac97_clock[dev])) < 0) 1278 if ((err = snd_atiixp_mixer_new(chip, ac97_clock)) < 0)
1287 goto __error; 1279 goto __error;
1288 1280
1289 if ((err = snd_atiixp_pcm_new(chip)) < 0) 1281 if ((err = snd_atiixp_pcm_new(chip)) < 0)
@@ -1302,7 +1294,6 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1302 goto __error; 1294 goto __error;
1303 1295
1304 pci_set_drvdata(pci, card); 1296 pci_set_drvdata(pci, card);
1305 dev++;
1306 return 0; 1297 return 0;
1307 1298
1308 __error: 1299 __error:
diff --git a/sound/pci/au88x0/au8810.h b/sound/pci/au88x0/au8810.h
index 3837d2ba5e67..5d69c31fe3f4 100644
--- a/sound/pci/au88x0/au8810.h
+++ b/sound/pci/au88x0/au8810.h
@@ -178,11 +178,6 @@
178#define EN_SPDIF 0x000c0000 178#define EN_SPDIF 0x000c0000
179 179
180#define VORTEX_CODEC_CHN 0x29080 180#define VORTEX_CODEC_CHN 0x29080
181#define VORTEX_CODEC_WRITE 0x00800000
182#define VORTEX_CODEC_ADDSHIFT 16
183#define VORTEX_CODEC_ADDMASK 0x7f0000 /* 0x000f0000 */
184#define VORTEX_CODEC_DATSHIFT 0
185#define VORTEX_CODEC_DATMASK 0xffff
186#define VORTEX_CODEC_IO 0x29188 181#define VORTEX_CODEC_IO 0x29188
187 182
188/* SPDIF */ 183/* SPDIF */
diff --git a/sound/pci/au88x0/au8820.h b/sound/pci/au88x0/au8820.h
index be8022e78714..abbe85e4f7a9 100644
--- a/sound/pci/au88x0/au8820.h
+++ b/sound/pci/au88x0/au8820.h
@@ -162,11 +162,6 @@
162#define EN_SPORT 0x00030000 162#define EN_SPORT 0x00030000
163#define EN_SPDIF 0x000c0000 163#define EN_SPDIF 0x000c0000
164#define VORTEX_CODEC_CHN 0x11880 164#define VORTEX_CODEC_CHN 0x11880
165#define VORTEX_CODEC_WRITE 0x00800000
166#define VORTEX_CODEC_ADDSHIFT 16
167#define VORTEX_CODEC_ADDMASK 0x7f0000 /* 0x000f0000 */
168#define VORTEX_CODEC_DATSHIFT 0
169#define VORTEX_CODEC_DATMASK 0xffff
170#define VORTEX_CODEC_IO 0x11988 165#define VORTEX_CODEC_IO 0x11988
171 166
172#define VORTEX_SPDIF_FLAGS 0x1005c /* FIXME */ 167#define VORTEX_SPDIF_FLAGS 0x1005c /* FIXME */
diff --git a/sound/pci/au88x0/au8830.h b/sound/pci/au88x0/au8830.h
index aa77826b5e59..04ece1b1c218 100644
--- a/sound/pci/au88x0/au8830.h
+++ b/sound/pci/au88x0/au8830.h
@@ -194,11 +194,6 @@
194 194
195#define VORTEX_CODEC_CTRL 0x29184 195#define VORTEX_CODEC_CTRL 0x29184
196#define VORTEX_CODEC_IO 0x29188 196#define VORTEX_CODEC_IO 0x29188
197#define VORTEX_CODEC_WRITE 0x00800000
198#define VORTEX_CODEC_ADDSHIFT 16
199#define VORTEX_CODEC_ADDMASK 0x7f0000 /* 0x000f0000 */
200#define VORTEX_CODEC_DATSHIFT 0
201#define VORTEX_CODEC_DATMASK 0xffff
202 197
203#define VORTEX_CODEC_SPORTCTRL 0x2918c 198#define VORTEX_CODEC_SPORTCTRL 0x2918c
204 199
diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c
index 04b695d6fd48..6af3b13f2fd1 100644
--- a/sound/pci/au88x0/au88x0.c
+++ b/sound/pci/au88x0/au88x0.c
@@ -303,7 +303,7 @@ snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
303 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH, 303 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH,
304 sizeof(snd_vortex_synth_arg_t), &wave) < 0 304 sizeof(snd_vortex_synth_arg_t), &wave) < 0
305 || wave == NULL) { 305 || wave == NULL) {
306 snd_printk("Can't initialize Aureal wavetable synth\n"); 306 snd_printk(KERN_ERR "Can't initialize Aureal wavetable synth\n");
307 } else { 307 } else {
308 snd_vortex_synth_arg_t *arg; 308 snd_vortex_synth_arg_t *arg;
309 309
diff --git a/sound/pci/au88x0/au88x0.h b/sound/pci/au88x0/au88x0.h
index ee1ede1979f6..b1197cfab3fb 100644
--- a/sound/pci/au88x0/au88x0.h
+++ b/sound/pci/au88x0/au88x0.h
@@ -79,6 +79,14 @@
79#define VORTEX_RESOURCE_A3D 0x00000004 79#define VORTEX_RESOURCE_A3D 0x00000004
80#define VORTEX_RESOURCE_LAST 0x00000005 80#define VORTEX_RESOURCE_LAST 0x00000005
81 81
82/* codec io: VORTEX_CODEC_IO bits */
83#define VORTEX_CODEC_ID_SHIFT 24
84#define VORTEX_CODEC_WRITE 0x00800000
85#define VORTEX_CODEC_ADDSHIFT 16
86#define VORTEX_CODEC_ADDMASK 0x7f0000
87#define VORTEX_CODEC_DATSHIFT 0
88#define VORTEX_CODEC_DATMASK 0xffff
89
82/* Check for SDAC bit in "Extended audio ID" AC97 register */ 90/* Check for SDAC bit in "Extended audio ID" AC97 register */
83//#define VORTEX_IS_QUAD(x) (((x)->codec == NULL) ? 0 : ((x)->codec->ext_id&0x80)) 91//#define VORTEX_IS_QUAD(x) (((x)->codec == NULL) ? 0 : ((x)->codec->ext_id&0x80))
84#define VORTEX_IS_QUAD(x) ((x)->isquad) 92#define VORTEX_IS_QUAD(x) ((x)->isquad)
diff --git a/sound/pci/au88x0/au88x0_a3d.c b/sound/pci/au88x0/au88x0_a3d.c
index 9ea2ba7bc3c8..d5755db5141f 100644
--- a/sound/pci/au88x0/au88x0_a3d.c
+++ b/sound/pci/au88x0/au88x0_a3d.c
@@ -488,7 +488,7 @@ static void a3dsrc_ZeroStateA3D(a3dsrc_t * a)
488 int i, var, var2; 488 int i, var, var2;
489 489
490 if ((a->vortex) == NULL) { 490 if ((a->vortex) == NULL) {
491 printk("vortex: ZeroStateA3D: ERROR: a->vortex is NULL\n"); 491 printk(KERN_ERR "vortex: ZeroStateA3D: ERROR: a->vortex is NULL\n");
492 return; 492 return;
493 } 493 }
494 494
diff --git a/sound/pci/au88x0/au88x0_core.c b/sound/pci/au88x0/au88x0_core.c
index f0eda4bbbb39..5905188d06b5 100644
--- a/sound/pci/au88x0/au88x0_core.c
+++ b/sound/pci/au88x0/au88x0_core.c
@@ -2033,7 +2033,7 @@ vortex_adb_checkinout(vortex_t * vortex, int resmap[], int out, int restype)
2033 } 2033 }
2034 } 2034 }
2035 } 2035 }
2036 printk("vortex: FATAL: ResManager: resource type %d exhausted.\n", restype); 2036 printk(KERN_ERR "vortex: FATAL: ResManager: resource type %d exhausted.\n", restype);
2037 return -ENOMEM; 2037 return -ENOMEM;
2038} 2038}
2039 2039
@@ -2165,7 +2165,7 @@ vortex_adb_allocroute(vortex_t * vortex, int dma, int nr_ch, int dir, int type)
2165 memset(stream->resources, 0, 2165 memset(stream->resources, 0,
2166 sizeof(unsigned char) * 2166 sizeof(unsigned char) *
2167 VORTEX_RESOURCE_LAST); 2167 VORTEX_RESOURCE_LAST);
2168 printk("vortex: out of A3D sources. Sorry\n"); 2168 printk(KERN_ERR "vortex: out of A3D sources. Sorry\n");
2169 return -EBUSY; 2169 return -EBUSY;
2170 } 2170 }
2171 /* (De)Initialize A3D hardware source. */ 2171 /* (De)Initialize A3D hardware source. */
@@ -2532,7 +2532,8 @@ vortex_codec_write(ac97_t * codec, unsigned short addr, unsigned short data)
2532 hwwrite(card->mmio, VORTEX_CODEC_IO, 2532 hwwrite(card->mmio, VORTEX_CODEC_IO,
2533 ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK) | 2533 ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK) |
2534 ((data << VORTEX_CODEC_DATSHIFT) & VORTEX_CODEC_DATMASK) | 2534 ((data << VORTEX_CODEC_DATSHIFT) & VORTEX_CODEC_DATMASK) |
2535 VORTEX_CODEC_WRITE); 2535 VORTEX_CODEC_WRITE |
2536 (codec->num << VORTEX_CODEC_ID_SHIFT) );
2536 2537
2537 /* Flush Caches. */ 2538 /* Flush Caches. */
2538 hwread(card->mmio, VORTEX_CODEC_IO); 2539 hwread(card->mmio, VORTEX_CODEC_IO);
@@ -2554,7 +2555,8 @@ static unsigned short vortex_codec_read(ac97_t * codec, unsigned short addr)
2554 } 2555 }
2555 } 2556 }
2556 /* set up read address */ 2557 /* set up read address */
2557 read_addr = ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK); 2558 read_addr = ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK) |
2559 (codec->num << VORTEX_CODEC_ID_SHIFT) ;
2558 hwwrite(card->mmio, VORTEX_CODEC_IO, read_addr); 2560 hwwrite(card->mmio, VORTEX_CODEC_IO, read_addr);
2559 2561
2560 /* wait for address */ 2562 /* wait for address */
diff --git a/sound/pci/au88x0/au88x0_eq.c b/sound/pci/au88x0/au88x0_eq.c
index 53b47a42c7d8..9d933cc0ea0b 100644
--- a/sound/pci/au88x0/au88x0_eq.c
+++ b/sound/pci/au88x0/au88x0_eq.c
@@ -854,7 +854,7 @@ snd_vortex_peaks_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
854 854
855 vortex_Eqlzr_GetAllPeaks(vortex, peaks, &count); 855 vortex_Eqlzr_GetAllPeaks(vortex, peaks, &count);
856 if (count != 20) { 856 if (count != 20) {
857 printk("vortex: peak count error 20 != %d \n", count); 857 printk(KERN_ERR "vortex: peak count error 20 != %d \n", count);
858 return -1; 858 return -1;
859 } 859 }
860 for (i = 0; i < 20; i++) 860 for (i = 0; i < 20; i++)
diff --git a/sound/pci/au88x0/au88x0_synth.c b/sound/pci/au88x0/au88x0_synth.c
index 400417d34609..65f375bad43a 100644
--- a/sound/pci/au88x0/au88x0_synth.c
+++ b/sound/pci/au88x0/au88x0_synth.c
@@ -90,7 +90,7 @@ static int vortex_wt_allocroute(vortex_t * vortex, int wt, int nr_ch)
90 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0); 90 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0);
91 91
92 temp = hwread(vortex->mmio, WT_PARM(wt, 3)); 92 temp = hwread(vortex->mmio, WT_PARM(wt, 3));
93 printk("vortex: WT PARM3: %x\n", temp); 93 printk(KERN_DEBUG "vortex: WT PARM3: %x\n", temp);
94 //hwwrite(vortex->mmio, WT_PARM(wt, 3), temp); 94 //hwwrite(vortex->mmio, WT_PARM(wt, 3), temp);
95 95
96 hwwrite(vortex->mmio, WT_DELAY(wt, 0), 0); 96 hwwrite(vortex->mmio, WT_DELAY(wt, 0), 0);
@@ -98,7 +98,7 @@ static int vortex_wt_allocroute(vortex_t * vortex, int wt, int nr_ch)
98 hwwrite(vortex->mmio, WT_DELAY(wt, 2), 0); 98 hwwrite(vortex->mmio, WT_DELAY(wt, 2), 0);
99 hwwrite(vortex->mmio, WT_DELAY(wt, 3), 0); 99 hwwrite(vortex->mmio, WT_DELAY(wt, 3), 0);
100 100
101 printk("vortex: WT GMODE: %x\n", hwread(vortex->mmio, WT_GMODE(wt))); 101 printk(KERN_DEBUG "vortex: WT GMODE: %x\n", hwread(vortex->mmio, WT_GMODE(wt)));
102 102
103 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0xffffffff); 103 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0xffffffff);
104 hwwrite(vortex->mmio, WT_PARM(wt, 3), 0xcff1c810); 104 hwwrite(vortex->mmio, WT_PARM(wt, 3), 0xcff1c810);
@@ -106,7 +106,7 @@ static int vortex_wt_allocroute(vortex_t * vortex, int wt, int nr_ch)
106 voice->parm0 = voice->parm1 = 0xcfb23e2f; 106 voice->parm0 = voice->parm1 = 0xcfb23e2f;
107 hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0); 107 hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0);
108 hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1); 108 hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1);
109 printk("vortex: WT GMODE 2 : %x\n", hwread(vortex->mmio, WT_GMODE(wt))); 109 printk(KERN_DEBUG "vortex: WT GMODE 2 : %x\n", hwread(vortex->mmio, WT_GMODE(wt)));
110 return 0; 110 return 0;
111} 111}
112 112
@@ -203,7 +203,7 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
203 } 203 }
204 } else { 204 } else {
205 if (wt >= NR_WT) { 205 if (wt >= NR_WT) {
206 printk("vortex: WT SetReg: voice out of range\n"); 206 printk(KERN_ERR "vortex: WT SetReg: voice out of range\n");
207 return 0; 207 return 0;
208 } 208 }
209 } 209 }
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index d5261bdec583..da99b1be2e8f 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * azt3328.c - driver for Aztech AZF3328 based soundcards (e.g. PCI168). 2 * azt3328.c - driver for Aztech AZF3328 based soundcards (e.g. PCI168).
3 * Copyright (C) 2002 by Andreas Mohr <hw7oshyuv3001@sneakemail.com> 3 * Copyright (C) 2002, 2005 by Andreas Mohr <andi AT lisas.de>
4 * 4 *
5 * Framework borrowed from Bart Hartgers's als4000.c. 5 * Framework borrowed from Bart Hartgers's als4000.c.
6 * Driver developed on PCI168 AP(W) version (PCI rev. 10, subsystem ID 1801), 6 * Driver developed on PCI168 AP(W) version (PCI rev. 10, subsystem ID 1801),
@@ -46,7 +46,7 @@
46 * - MPU401 (+ legacy address support) FIXME: how to enable legacy addr?? 46 * - MPU401 (+ legacy address support) FIXME: how to enable legacy addr??
47 * - game port (legacy address support) 47 * - game port (legacy address support)
48 * - built-in General DirectX timer having a 20 bits counter 48 * - built-in General DirectX timer having a 20 bits counter
49 * with 1us resolution (FIXME: where is it?) 49 * with 1us resolution (see below!)
50 * - I2S serial port for external DAC 50 * - I2S serial port for external DAC
51 * - supports 33MHz PCI spec 2.1, PCI power management 1.0, compliant with ACPI 51 * - supports 33MHz PCI spec 2.1, PCI power management 1.0, compliant with ACPI
52 * - supports hardware volume control 52 * - supports hardware volume control
@@ -55,13 +55,23 @@
55 * required for Microsoft's logo compliance (FIXME: where?) 55 * required for Microsoft's logo compliance (FIXME: where?)
56 * - PCI168 AP(W) card: power amplifier with 4 Watts/channel at 4 Ohms 56 * - PCI168 AP(W) card: power amplifier with 4 Watts/channel at 4 Ohms
57 * 57 *
58 * Note that this driver now is actually *better* than the Windows driver,
59 * since it additionally supports the card's 1MHz DirectX timer - just try
60 * the following snd-seq module parameters etc.:
61 * - options snd-seq seq_default_timer_class=2 seq_default_timer_sclass=0
62 * seq_default_timer_card=0 seq_client_load=1 seq_default_timer_device=0
63 * seq_default_timer_subdevice=0 seq_default_timer_resolution=1000000
64 * - "timidity -iAv -B2,8 -Os -EFreverb=0"
65 * - "pmidi -p 128:0 jazz.mid"
66 *
58 * Certain PCI versions of this card are susceptible to DMA traffic underruns 67 * Certain PCI versions of this card are susceptible to DMA traffic underruns
59 * in some systems (resulting in sound crackling/clicking/popping), 68 * in some systems (resulting in sound crackling/clicking/popping),
60 * probably because they don't have a DMA FIFO buffer or so. 69 * probably because they don't have a DMA FIFO buffer or so.
61 * Overview (PCI ID/PCI subID/PCI rev.): 70 * Overview (PCI ID/PCI subID/PCI rev.):
62 * - no DMA crackling on SiS735: 0x50DC/0x1801/16 71 * - no DMA crackling on SiS735: 0x50DC/0x1801/16
63 * - unknown performance: 0x50DC/0x1801/10 72 * - unknown performance: 0x50DC/0x1801/10
64 * 73 * (well, it's not bad on an Athlon 1800 with now very optimized IRQ handler)
74 *
65 * Crackling happens with VIA chipsets or, in my case, an SiS735, which is 75 * Crackling happens with VIA chipsets or, in my case, an SiS735, which is
66 * supposed to be very fast and supposed to get rid of crackling much 76 * supposed to be very fast and supposed to get rid of crackling much
67 * better than a VIA, yet ironically I still get crackling, like many other 77 * better than a VIA, yet ironically I still get crackling, like many other
@@ -76,18 +86,13 @@
76 * - Disable ACPI/power management/"Auto Detect RAM/PCI Clk" in BIOS 86 * - Disable ACPI/power management/"Auto Detect RAM/PCI Clk" in BIOS
77 * 87 *
78 * BUGS 88 * BUGS
79 * - when Ctrl-C'ing mpg321, the playback loops a bit 89 * - full-duplex might *still* be problematic, not fully tested recently
80 * (premature DMA playback reset?)
81 * - full-duplex sometimes breaks (IRQ management issues?).
82 * Once even a spontaneous REBOOT happened!!!
83 * 90 *
84 * TODO 91 * TODO
85 * - test MPU401 MIDI playback etc. 92 * - test MPU401 MIDI playback etc.
86 * - power management (CONFIG_PM). See e.g. intel8x0 or cs4281. 93 * - power management. See e.g. intel8x0 or cs4281.
87 * This would be nice since the chip runs a bit hot, and it's *required* 94 * This would be nice since the chip runs a bit hot, and it's *required*
88 * anyway for proper ACPI power management. In other words: rest 95 * anyway for proper ACPI power management.
89 * assured that I *will* implement this very soon; as soon as Linux 2.5.x
90 * has power management that's bugfree enough to work properly on my desktop.
91 * - figure out what all unknown port bits are responsible for 96 * - figure out what all unknown port bits are responsible for
92 */ 97 */
93 98
@@ -108,7 +113,7 @@
108#include <sound/initval.h> 113#include <sound/initval.h>
109#include "azt3328.h" 114#include "azt3328.h"
110 115
111MODULE_AUTHOR("Andreas Mohr <hw7oshyuv3001@sneakemail.com>"); 116MODULE_AUTHOR("Andreas Mohr <andi AT lisas.de>");
112MODULE_DESCRIPTION("Aztech AZF3328 (PCI168)"); 117MODULE_DESCRIPTION("Aztech AZF3328 (PCI168)");
113MODULE_LICENSE("GPL"); 118MODULE_LICENSE("GPL");
114MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}"); 119MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
@@ -122,6 +127,7 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
122#define DEBUG_MIXER 0 127#define DEBUG_MIXER 0
123#define DEBUG_PLAY_REC 0 128#define DEBUG_PLAY_REC 0
124#define DEBUG_IO 0 129#define DEBUG_IO 0
130#define DEBUG_TIMER 0
125#define MIXER_TESTING 0 131#define MIXER_TESTING 0
126 132
127#if DEBUG_MISC 133#if DEBUG_MISC
@@ -132,8 +138,8 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
132 138
133#if DEBUG_CALLS 139#if DEBUG_CALLS
134#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args) 140#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args)
135#define snd_azf3328_dbgcallenter() printk(KERN_ERR "entering %s\n", __FUNCTION__) 141#define snd_azf3328_dbgcallenter() printk(KERN_ERR "--> %s\n", __FUNCTION__)
136#define snd_azf3328_dbgcallleave() printk(KERN_ERR "leaving %s\n", __FUNCTION__) 142#define snd_azf3328_dbgcallleave() printk(KERN_ERR "<-- %s\n", __FUNCTION__)
137#else 143#else
138#define snd_azf3328_dbgcalls(format, args...) 144#define snd_azf3328_dbgcalls(format, args...)
139#define snd_azf3328_dbgcallenter() 145#define snd_azf3328_dbgcallenter()
@@ -152,13 +158,12 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
152#define snd_azf3328_dbgplay(format, args...) 158#define snd_azf3328_dbgplay(format, args...)
153#endif 159#endif
154 160
155#if DEBUG_IO 161#if DEBUG_MISC
156#define snd_azf3328_dbgio(chip, where) \ 162#define snd_azf3328_dbgtimer(format, args...) printk(KERN_ERR format, ##args)
157 printk(KERN_ERR "%s: IDX_IO_PLAY_FLAGS %04x, IDX_IO_PLAY_IRQMASK %04x, IDX_IO_IRQSTATUS %04x\n", where, inw(chip->codec_port+IDX_IO_PLAY_FLAGS), inw(chip->codec_port+IDX_IO_PLAY_IRQMASK), inw(chip->codec_port+IDX_IO_IRQSTATUS))
158#else 163#else
159#define snd_azf3328_dbgio(chip, where) 164#define snd_azf3328_dbgtimer(format, args...)
160#endif 165#endif
161 166
162static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 167static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
163module_param_array(index, int, NULL, 0444); 168module_param_array(index, int, NULL, 0444);
164MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard."); 169MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard.");
@@ -177,35 +182,40 @@ module_param_array(joystick, bool, NULL, 0444);
177MODULE_PARM_DESC(joystick, "Enable joystick for AZF3328 soundcard."); 182MODULE_PARM_DESC(joystick, "Enable joystick for AZF3328 soundcard.");
178#endif 183#endif
179 184
180typedef struct _snd_azf3328 azf3328_t; 185static int seqtimer_scaling = 128;
181 186module_param(seqtimer_scaling, int, 0444);
182struct _snd_azf3328 { 187MODULE_PARM_DESC(seqtimer_scaling, "Set 1024000Hz sequencer timer scale factor (lockup danger!). Default 128.");
183 int irq;
184 188
189typedef struct _snd_azf3328 {
190 /* often-used fields towards beginning, then grouped */
185 unsigned long codec_port; 191 unsigned long codec_port;
186 unsigned long io2_port; 192 unsigned long io2_port;
187 unsigned long mpu_port; 193 unsigned long mpu_port;
188 unsigned long synth_port; 194 unsigned long synth_port;
189 unsigned long mixer_port; 195 unsigned long mixer_port;
190 196
191#ifdef SUPPORT_JOYSTICK 197 spinlock_t reg_lock;
192 struct gameport *gameport;
193#endif
194
195 struct pci_dev *pci;
196 snd_card_t *card;
197 198
199 snd_timer_t *timer;
200
198 snd_pcm_t *pcm; 201 snd_pcm_t *pcm;
199 snd_rawmidi_t *rmidi;
200 snd_pcm_substream_t *playback_substream; 202 snd_pcm_substream_t *playback_substream;
201 snd_pcm_substream_t *capture_substream; 203 snd_pcm_substream_t *capture_substream;
202 unsigned int is_playing; 204 unsigned int is_playing;
203 unsigned int is_recording; 205 unsigned int is_recording;
204 206
205 spinlock_t reg_lock; 207 snd_card_t *card;
206}; 208 snd_rawmidi_t *rmidi;
209
210#ifdef SUPPORT_JOYSTICK
211 struct gameport *gameport;
212#endif
207 213
208static struct pci_device_id snd_azf3328_ids[] = { 214 struct pci_dev *pci;
215 int irq;
216} azf3328_t;
217
218static const struct pci_device_id snd_azf3328_ids[] = {
209 { 0x122D, 0x50DC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* PCI168/3328 */ 219 { 0x122D, 0x50DC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* PCI168/3328 */
210 { 0x122D, 0x80DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 3328 */ 220 { 0x122D, 0x80DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 3328 */
211 { 0, } 221 { 0, }
@@ -213,57 +223,90 @@ static struct pci_device_id snd_azf3328_ids[] = {
213 223
214MODULE_DEVICE_TABLE(pci, snd_azf3328_ids); 224MODULE_DEVICE_TABLE(pci, snd_azf3328_ids);
215 225
216static inline void snd_azf3328_io2_write(azf3328_t *chip, int reg, unsigned char value) 226static inline void
227snd_azf3328_codec_outb(const azf3328_t *chip, int reg, u8 value)
228{
229 outb(value, chip->codec_port + reg);
230}
231
232static inline u8
233snd_azf3328_codec_inb(const azf3328_t *chip, int reg)
234{
235 return inb(chip->codec_port + reg);
236}
237
238static inline void
239snd_azf3328_codec_outw(const azf3328_t *chip, int reg, u16 value)
240{
241 outw(value, chip->codec_port + reg);
242}
243
244static inline u16
245snd_azf3328_codec_inw(const azf3328_t *chip, int reg)
246{
247 return inw(chip->codec_port + reg);
248}
249
250static inline void
251snd_azf3328_codec_outl(const azf3328_t *chip, int reg, u32 value)
252{
253 outl(value, chip->codec_port + reg);
254}
255
256static inline void
257snd_azf3328_io2_outb(const azf3328_t *chip, int reg, u8 value)
217{ 258{
218 outb(value, chip->io2_port + reg); 259 outb(value, chip->io2_port + reg);
219} 260}
220 261
221static inline unsigned char snd_azf3328_io2_read(azf3328_t *chip, int reg) 262static inline u8
263snd_azf3328_io2_inb(const azf3328_t *chip, int reg)
222{ 264{
223 return inb(chip->io2_port + reg); 265 return inb(chip->io2_port + reg);
224} 266}
225 267
226static void snd_azf3328_mixer_write(azf3328_t *chip, int reg, unsigned long value, int type) 268static inline void
269snd_azf3328_mixer_outw(const azf3328_t *chip, int reg, u16 value)
227{ 270{
228 switch(type) { 271 outw(value, chip->mixer_port + reg);
229 case WORD_VALUE: 272}
230 outw(value, chip->mixer_port + reg); 273
231 break; 274static inline u16
232 case DWORD_VALUE: 275snd_azf3328_mixer_inw(const azf3328_t *chip, int reg)
233 outl(value, chip->mixer_port + reg); 276{
234 break; 277 return inw(chip->mixer_port + reg);
235 case BYTE_VALUE:
236 outb(value, chip->mixer_port + reg);
237 break;
238 }
239} 278}
240 279
241static void snd_azf3328_mixer_set_mute(azf3328_t *chip, int reg, int do_mute) 280static void
281snd_azf3328_mixer_set_mute(const azf3328_t *chip, int reg, int do_mute)
242{ 282{
283 unsigned long portbase = chip->mixer_port + reg + 1;
243 unsigned char oldval; 284 unsigned char oldval;
244 285
245 /* the mute bit is on the *second* (i.e. right) register of a 286 /* the mute bit is on the *second* (i.e. right) register of a
246 * left/right channel setting */ 287 * left/right channel setting */
247 oldval = inb(chip->mixer_port + reg + 1); 288 oldval = inb(portbase);
248 if (do_mute) 289 if (do_mute)
249 oldval |= 0x80; 290 oldval |= 0x80;
250 else 291 else
251 oldval &= ~0x80; 292 oldval &= ~0x80;
252 outb(oldval, chip->mixer_port + reg + 1); 293 outb(oldval, portbase);
253} 294}
254 295
255static void snd_azf3328_mixer_write_volume_gradually(azf3328_t *chip, int reg, unsigned char dst_vol_left, unsigned char dst_vol_right, int chan_sel, int delay) 296static void
297snd_azf3328_mixer_write_volume_gradually(const azf3328_t *chip, int reg, unsigned char dst_vol_left, unsigned char dst_vol_right, int chan_sel, int delay)
256{ 298{
299 unsigned long portbase = chip->mixer_port + reg;
257 unsigned char curr_vol_left = 0, curr_vol_right = 0; 300 unsigned char curr_vol_left = 0, curr_vol_right = 0;
258 int left_done = 0, right_done = 0; 301 int left_done = 0, right_done = 0;
259 302
260 snd_azf3328_dbgcallenter(); 303 snd_azf3328_dbgcallenter();
261 if (chan_sel & SET_CHAN_LEFT) 304 if (chan_sel & SET_CHAN_LEFT)
262 curr_vol_left = inb(chip->mixer_port + reg + 1); 305 curr_vol_left = inb(portbase + 1);
263 else 306 else
264 left_done = 1; 307 left_done = 1;
265 if (chan_sel & SET_CHAN_RIGHT) 308 if (chan_sel & SET_CHAN_RIGHT)
266 curr_vol_right = inb(chip->mixer_port + reg + 0); 309 curr_vol_right = inb(portbase + 0);
267 else 310 else
268 right_done = 1; 311 right_done = 1;
269 312
@@ -284,7 +327,7 @@ static void snd_azf3328_mixer_write_volume_gradually(azf3328_t *chip, int reg, u
284 curr_vol_left++; 327 curr_vol_left++;
285 else 328 else
286 left_done = 1; 329 left_done = 1;
287 outb(curr_vol_left, chip->mixer_port + reg + 1); 330 outb(curr_vol_left, portbase + 1);
288 } 331 }
289 if (!right_done) 332 if (!right_done)
290 { 333 {
@@ -298,7 +341,7 @@ static void snd_azf3328_mixer_write_volume_gradually(azf3328_t *chip, int reg, u
298 /* during volume change, the right channel is crackling 341 /* during volume change, the right channel is crackling
299 * somewhat more than the left channel, unfortunately. 342 * somewhat more than the left channel, unfortunately.
300 * This seems to be a hardware issue. */ 343 * This seems to be a hardware issue. */
301 outb(curr_vol_right, chip->mixer_port + reg + 0); 344 outb(curr_vol_right, portbase + 0);
302 } 345 }
303 if (delay) 346 if (delay)
304 mdelay(delay); 347 mdelay(delay);
@@ -320,7 +363,11 @@ typedef struct azf3328_mixer_reg {
320} azf3328_mixer_reg_t; 363} azf3328_mixer_reg_t;
321 364
322#define COMPOSE_MIXER_REG(reg,lchan_shift,rchan_shift,mask,invert,stereo,enum_c) \ 365#define COMPOSE_MIXER_REG(reg,lchan_shift,rchan_shift,mask,invert,stereo,enum_c) \
323 ((reg) | (lchan_shift << 8) | (rchan_shift << 12) | (mask << 16) | (invert << 24) | (stereo << 25) | (enum_c << 26)) 366 ((reg) | (lchan_shift << 8) | (rchan_shift << 12) | \
367 (mask << 16) | \
368 (invert << 24) | \
369 (stereo << 25) | \
370 (enum_c << 26))
324 371
325static void snd_azf3328_mixer_reg_decode(azf3328_mixer_reg_t *r, unsigned long val) 372static void snd_azf3328_mixer_reg_decode(azf3328_mixer_reg_t *r, unsigned long val)
326{ 373{
@@ -372,13 +419,15 @@ static void snd_azf3328_mixer_reg_decode(azf3328_mixer_reg_t *r, unsigned long v
372 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0, 0, 0, enum_c), \ 419 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0, 0, 0, enum_c), \
373} 420}
374 421
375static int snd_azf3328_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 422static int
423snd_azf3328_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
376{ 424{
377 azf3328_mixer_reg_t reg; 425 azf3328_mixer_reg_t reg;
378 426
379 snd_azf3328_dbgcallenter(); 427 snd_azf3328_dbgcallenter();
380 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 428 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
381 uinfo->type = reg.mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; 429 uinfo->type = reg.mask == 1 ?
430 SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
382 uinfo->count = reg.stereo + 1; 431 uinfo->count = reg.stereo + 1;
383 uinfo->value.integer.min = 0; 432 uinfo->value.integer.min = 0;
384 uinfo->value.integer.max = reg.mask; 433 uinfo->value.integer.max = reg.mask;
@@ -386,7 +435,8 @@ static int snd_azf3328_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
386 return 0; 435 return 0;
387} 436}
388 437
389static int snd_azf3328_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 438static int
439snd_azf3328_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
390{ 440{
391 azf3328_t *chip = snd_kcontrol_chip(kcontrol); 441 azf3328_t *chip = snd_kcontrol_chip(kcontrol);
392 azf3328_mixer_reg_t reg; 442 azf3328_mixer_reg_t reg;
@@ -395,7 +445,7 @@ static int snd_azf3328_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
395 snd_azf3328_dbgcallenter(); 445 snd_azf3328_dbgcallenter();
396 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 446 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
397 447
398 oreg = inw(chip->mixer_port + reg.reg); 448 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
399 val = (oreg >> reg.lchan_shift) & reg.mask; 449 val = (oreg >> reg.lchan_shift) & reg.mask;
400 if (reg.invert) 450 if (reg.invert)
401 val = reg.mask - val; 451 val = reg.mask - val;
@@ -406,12 +456,17 @@ static int snd_azf3328_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
406 val = reg.mask - val; 456 val = reg.mask - val;
407 ucontrol->value.integer.value[1] = val; 457 ucontrol->value.integer.value[1] = val;
408 } 458 }
409 snd_azf3328_dbgmixer("get: %02x is %04x -> vol %02lx|%02lx (shift %02d|%02d, mask %02x, inv. %d, stereo %d)\n", reg.reg, oreg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1], reg.lchan_shift, reg.rchan_shift, reg.mask, reg.invert, reg.stereo); 459 snd_azf3328_dbgmixer("get: %02x is %04x -> vol %02lx|%02lx "
460 "(shift %02d|%02d, mask %02x, inv. %d, stereo %d)\n",
461 reg.reg, oreg,
462 ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
463 reg.lchan_shift, reg.rchan_shift, reg.mask, reg.invert, reg.stereo);
410 snd_azf3328_dbgcallleave(); 464 snd_azf3328_dbgcallleave();
411 return 0; 465 return 0;
412} 466}
413 467
414static int snd_azf3328_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 468static int
469snd_azf3328_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
415{ 470{
416 azf3328_t *chip = snd_kcontrol_chip(kcontrol); 471 azf3328_t *chip = snd_kcontrol_chip(kcontrol);
417 azf3328_mixer_reg_t reg; 472 azf3328_mixer_reg_t reg;
@@ -419,7 +474,7 @@ static int snd_azf3328_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
419 474
420 snd_azf3328_dbgcallenter(); 475 snd_azf3328_dbgcallenter();
421 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 476 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
422 oreg = inw(chip->mixer_port + reg.reg); 477 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
423 val = ucontrol->value.integer.value[0] & reg.mask; 478 val = ucontrol->value.integer.value[0] & reg.mask;
424 if (reg.invert) 479 if (reg.invert)
425 val = reg.mask - val; 480 val = reg.mask - val;
@@ -433,24 +488,37 @@ static int snd_azf3328_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
433 nreg |= (val << reg.rchan_shift); 488 nreg |= (val << reg.rchan_shift);
434 } 489 }
435 if (reg.mask >= 0x07) /* it's a volume control, so better take care */ 490 if (reg.mask >= 0x07) /* it's a volume control, so better take care */
436 snd_azf3328_mixer_write_volume_gradually(chip, reg.reg, nreg >> 8, nreg & 0xff, SET_CHAN_LEFT|SET_CHAN_RIGHT, 0); /* just set both channels, doesn't matter */ 491 snd_azf3328_mixer_write_volume_gradually(
492 chip, reg.reg, nreg >> 8, nreg & 0xff,
493 /* just set both channels, doesn't matter */
494 SET_CHAN_LEFT|SET_CHAN_RIGHT,
495 0);
437 else 496 else
438 outw(nreg, chip->mixer_port + reg.reg); 497 snd_azf3328_mixer_outw(chip, reg.reg, nreg);
439 498
440 snd_azf3328_dbgmixer("put: %02x to %02lx|%02lx, oreg %04x; shift %02d|%02d -> nreg %04x; after: %04x\n", reg.reg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1], oreg, reg.lchan_shift, reg.rchan_shift, nreg, inw(chip->mixer_port + reg.reg)); 499 snd_azf3328_dbgmixer("put: %02x to %02lx|%02lx, "
500 "oreg %04x; shift %02d|%02d -> nreg %04x; after: %04x\n",
501 reg.reg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
502 oreg, reg.lchan_shift, reg.rchan_shift,
503 nreg, snd_azf3328_mixer_inw(chip, reg.reg));
441 snd_azf3328_dbgcallleave(); 504 snd_azf3328_dbgcallleave();
442 return (nreg != oreg); 505 return (nreg != oreg);
443} 506}
444 507
445static int snd_azf3328_info_mixer_enum(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 508static int
509snd_azf3328_info_mixer_enum(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
446{ 510{
447 azf3328_mixer_reg_t reg; 511 static const char * const texts1[] = {
448 static char *texts1[2] = { "ModemOut1", "ModemOut2" }; 512 "ModemOut1", "ModemOut2"
449 static char *texts2[2] = { "MonoSelectSource1", "MonoSelectSource2" }; 513 };
450 static char *texts3[8] = { 514 static const char * const texts2[] = {
451 "Mic", "CD", "Video", "Aux", "Line", 515 "MonoSelectSource1", "MonoSelectSource2"
452 "Mix", "Mix Mono", "Phone" 516 };
517 static const char * const texts3[] = {
518 "Mic", "CD", "Video", "Aux",
519 "Line", "Mix", "Mix Mono", "Phone"
453 }; 520 };
521 azf3328_mixer_reg_t reg;
454 522
455 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 523 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
456 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 524 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
@@ -471,14 +539,15 @@ static int snd_azf3328_info_mixer_enum(snd_kcontrol_t *kcontrol, snd_ctl_elem_in
471 return 0; 539 return 0;
472} 540}
473 541
474static int snd_azf3328_get_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 542static int
543snd_azf3328_get_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
475{ 544{
476 azf3328_mixer_reg_t reg;
477 azf3328_t *chip = snd_kcontrol_chip(kcontrol); 545 azf3328_t *chip = snd_kcontrol_chip(kcontrol);
546 azf3328_mixer_reg_t reg;
478 unsigned short val; 547 unsigned short val;
479 548
480 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 549 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
481 val = inw(chip->mixer_port + reg.reg); 550 val = snd_azf3328_mixer_inw(chip, reg.reg);
482 if (reg.reg == IDX_MIXER_REC_SELECT) 551 if (reg.reg == IDX_MIXER_REC_SELECT)
483 { 552 {
484 ucontrol->value.enumerated.item[0] = (val >> 8) & (reg.enum_c - 1); 553 ucontrol->value.enumerated.item[0] = (val >> 8) & (reg.enum_c - 1);
@@ -486,18 +555,22 @@ static int snd_azf3328_get_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_va
486 } 555 }
487 else 556 else
488 ucontrol->value.enumerated.item[0] = (val >> reg.lchan_shift) & (reg.enum_c - 1); 557 ucontrol->value.enumerated.item[0] = (val >> reg.lchan_shift) & (reg.enum_c - 1);
489 snd_azf3328_dbgmixer("get_enum: %02x is %04x -> %d|%d (shift %02d, enum_c %d)\n", reg.reg, val, ucontrol->value.enumerated.item[0], ucontrol->value.enumerated.item[1], reg.lchan_shift, reg.enum_c); 558
559 snd_azf3328_dbgmixer("get_enum: %02x is %04x -> %d|%d (shift %02d, enum_c %d)\n",
560 reg.reg, val, ucontrol->value.enumerated.item[0], ucontrol->value.enumerated.item[1],
561 reg.lchan_shift, reg.enum_c);
490 return 0; 562 return 0;
491} 563}
492 564
493static int snd_azf3328_put_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 565static int
566snd_azf3328_put_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
494{ 567{
495 azf3328_mixer_reg_t reg;
496 azf3328_t *chip = snd_kcontrol_chip(kcontrol); 568 azf3328_t *chip = snd_kcontrol_chip(kcontrol);
569 azf3328_mixer_reg_t reg;
497 unsigned int oreg, nreg, val; 570 unsigned int oreg, nreg, val;
498 571
499 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 572 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
500 oreg = inw(chip->mixer_port + reg.reg); 573 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
501 val = oreg; 574 val = oreg;
502 if (reg.reg == IDX_MIXER_REC_SELECT) 575 if (reg.reg == IDX_MIXER_REC_SELECT)
503 { 576 {
@@ -514,19 +587,19 @@ static int snd_azf3328_put_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_va
514 val &= ~((reg.enum_c - 1) << reg.lchan_shift); 587 val &= ~((reg.enum_c - 1) << reg.lchan_shift);
515 val |= (ucontrol->value.enumerated.item[0] << reg.lchan_shift); 588 val |= (ucontrol->value.enumerated.item[0] << reg.lchan_shift);
516 } 589 }
517 outw(val, chip->mixer_port + reg.reg); 590 snd_azf3328_mixer_outw(chip, reg.reg, val);
518 nreg = val; 591 nreg = val;
519 592
520 snd_azf3328_dbgmixer("put_enum: %02x to %04x, oreg %04x\n", reg.reg, val, oreg); 593 snd_azf3328_dbgmixer("put_enum: %02x to %04x, oreg %04x\n", reg.reg, val, oreg);
521 return (nreg != oreg); 594 return (nreg != oreg);
522} 595}
523 596
524static snd_kcontrol_new_t snd_azf3328_mixer_controls[] __devinitdata = { 597static const snd_kcontrol_new_t snd_azf3328_mixer_controls[] __devinitdata = {
525 AZF3328_MIXER_SWITCH("Master Playback Switch", IDX_MIXER_PLAY_MASTER, 15, 1), 598 AZF3328_MIXER_SWITCH("Master Playback Switch", IDX_MIXER_PLAY_MASTER, 15, 1),
526 AZF3328_MIXER_VOL_STEREO("Master Playback Volume", IDX_MIXER_PLAY_MASTER, 0x1f, 1), 599 AZF3328_MIXER_VOL_STEREO("Master Playback Volume", IDX_MIXER_PLAY_MASTER, 0x1f, 1),
527 AZF3328_MIXER_SWITCH("Wave Playback Switch", IDX_MIXER_WAVEOUT, 15, 1), 600 AZF3328_MIXER_SWITCH("Wave Playback Switch", IDX_MIXER_WAVEOUT, 15, 1),
528 AZF3328_MIXER_VOL_STEREO("Wave Playback Volume", IDX_MIXER_WAVEOUT, 0x1f, 1), 601 AZF3328_MIXER_VOL_STEREO("Wave Playback Volume", IDX_MIXER_WAVEOUT, 0x1f, 1),
529 AZF3328_MIXER_SWITCH("Wave Playback 3D Bypass", IDX_MIXER_ADVCTL2, 7, 1), 602 AZF3328_MIXER_SWITCH("Wave 3D Bypass Playback Switch", IDX_MIXER_ADVCTL2, 7, 1),
530 AZF3328_MIXER_SWITCH("FM Playback Switch", IDX_MIXER_FMSYNTH, 15, 1), 603 AZF3328_MIXER_SWITCH("FM Playback Switch", IDX_MIXER_FMSYNTH, 15, 1),
531 AZF3328_MIXER_VOL_STEREO("FM Playback Volume", IDX_MIXER_FMSYNTH, 0x1f, 1), 604 AZF3328_MIXER_VOL_STEREO("FM Playback Volume", IDX_MIXER_FMSYNTH, 0x1f, 1),
532 AZF3328_MIXER_SWITCH("CD Playback Switch", IDX_MIXER_CDAUDIO, 15, 1), 605 AZF3328_MIXER_SWITCH("CD Playback Switch", IDX_MIXER_CDAUDIO, 15, 1),
@@ -539,8 +612,8 @@ static snd_kcontrol_new_t snd_azf3328_mixer_controls[] __devinitdata = {
539 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0), 612 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0),
540 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1), 613 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1),
541 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1), 614 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1),
542 AZF3328_MIXER_SWITCH("PCBeep Playback Switch", IDX_MIXER_PCBEEP, 15, 1), 615 AZF3328_MIXER_SWITCH("PC Speaker Playback Switch", IDX_MIXER_PCBEEP, 15, 1),
543 AZF3328_MIXER_VOL_SPECIAL("PCBeep Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1), 616 AZF3328_MIXER_VOL_SPECIAL("PC Speaker Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1),
544 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1), 617 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1),
545 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1), 618 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1),
546 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1), 619 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1),
@@ -553,8 +626,8 @@ static snd_kcontrol_new_t snd_azf3328_mixer_controls[] __devinitdata = {
553 AZF3328_MIXER_ENUM("Mono Select Source", IDX_MIXER_ADVCTL2, 2, 9), 626 AZF3328_MIXER_ENUM("Mono Select Source", IDX_MIXER_ADVCTL2, 2, 9),
554 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Treble", IDX_MIXER_BASSTREBLE, 0x07, 1, 0), 627 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Treble", IDX_MIXER_BASSTREBLE, 0x07, 1, 0),
555 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Bass", IDX_MIXER_BASSTREBLE, 0x07, 9, 0), 628 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Bass", IDX_MIXER_BASSTREBLE, 0x07, 9, 0),
556 AZF3328_MIXER_SWITCH("3D Control - Toggle", IDX_MIXER_ADVCTL2, 13, 0), 629 AZF3328_MIXER_SWITCH("3D Control - Switch", IDX_MIXER_ADVCTL2, 13, 0),
557 AZF3328_MIXER_VOL_SPECIAL("3D Control - Volume", IDX_MIXER_ADVCTL1, 0x07, 1, 0), /* "3D Width" */ 630 AZF3328_MIXER_VOL_SPECIAL("3D Control - Wide", IDX_MIXER_ADVCTL1, 0x07, 1, 0), /* "3D Width" */
558 AZF3328_MIXER_VOL_SPECIAL("3D Control - Space", IDX_MIXER_ADVCTL1, 0x03, 8, 0), /* "Hifi 3D" */ 631 AZF3328_MIXER_VOL_SPECIAL("3D Control - Space", IDX_MIXER_ADVCTL1, 0x03, 8, 0), /* "Hifi 3D" */
559#if MIXER_TESTING 632#if MIXER_TESTING
560 AZF3328_MIXER_SWITCH("0", IDX_MIXER_ADVCTL2, 0, 0), 633 AZF3328_MIXER_SWITCH("0", IDX_MIXER_ADVCTL2, 0, 0),
@@ -576,9 +649,7 @@ static snd_kcontrol_new_t snd_azf3328_mixer_controls[] __devinitdata = {
576#endif 649#endif
577}; 650};
578 651
579#define AZF3328_INIT_VALUES (sizeof(snd_azf3328_init_values)/sizeof(unsigned int)/2) 652static const u16 __devinitdata snd_azf3328_init_values[][2] = {
580
581static unsigned int snd_azf3328_init_values[][2] = {
582 { IDX_MIXER_PLAY_MASTER, MIXER_MUTE_MASK|0x1f1f }, 653 { IDX_MIXER_PLAY_MASTER, MIXER_MUTE_MASK|0x1f1f },
583 { IDX_MIXER_MODEMOUT, MIXER_MUTE_MASK|0x1f1f }, 654 { IDX_MIXER_MODEMOUT, MIXER_MUTE_MASK|0x1f1f },
584 { IDX_MIXER_BASSTREBLE, 0x0000 }, 655 { IDX_MIXER_BASSTREBLE, 0x0000 },
@@ -594,10 +665,11 @@ static unsigned int snd_azf3328_init_values[][2] = {
594 { IDX_MIXER_REC_VOLUME, MIXER_MUTE_MASK|0x0707 }, 665 { IDX_MIXER_REC_VOLUME, MIXER_MUTE_MASK|0x0707 },
595}; 666};
596 667
597static int __devinit snd_azf3328_mixer_new(azf3328_t *chip) 668static int __devinit
669snd_azf3328_mixer_new(azf3328_t *chip)
598{ 670{
599 snd_card_t *card; 671 snd_card_t *card;
600 snd_kcontrol_new_t *sw; 672 const snd_kcontrol_new_t *sw;
601 unsigned int idx; 673 unsigned int idx;
602 int err; 674 int err;
603 675
@@ -607,11 +679,13 @@ static int __devinit snd_azf3328_mixer_new(azf3328_t *chip)
607 card = chip->card; 679 card = chip->card;
608 680
609 /* mixer reset */ 681 /* mixer reset */
610 snd_azf3328_mixer_write(chip, IDX_MIXER_RESET, 0x0, WORD_VALUE); 682 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
611 683
612 /* mute and zero volume channels */ 684 /* mute and zero volume channels */
613 for (idx = 0; idx < AZF3328_INIT_VALUES; idx++) { 685 for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_init_values); idx++) {
614 snd_azf3328_mixer_write(chip, snd_azf3328_init_values[idx][0], snd_azf3328_init_values[idx][1], WORD_VALUE); 686 snd_azf3328_mixer_outw(chip,
687 snd_azf3328_init_values[idx][0],
688 snd_azf3328_init_values[idx][1]);
615 } 689 }
616 690
617 /* add mixer controls */ 691 /* add mixer controls */
@@ -627,7 +701,8 @@ static int __devinit snd_azf3328_mixer_new(azf3328_t *chip)
627 return 0; 701 return 0;
628} 702}
629 703
630static int snd_azf3328_hw_params(snd_pcm_substream_t * substream, 704static int
705snd_azf3328_hw_params(snd_pcm_substream_t * substream,
631 snd_pcm_hw_params_t * hw_params) 706 snd_pcm_hw_params_t * hw_params)
632{ 707{
633 int res; 708 int res;
@@ -637,7 +712,8 @@ static int snd_azf3328_hw_params(snd_pcm_substream_t * substream,
637 return res; 712 return res;
638} 713}
639 714
640static int snd_azf3328_hw_free(snd_pcm_substream_t * substream) 715static int
716snd_azf3328_hw_free(snd_pcm_substream_t * substream)
641{ 717{
642 snd_azf3328_dbgcallenter(); 718 snd_azf3328_dbgcallenter();
643 snd_pcm_lib_free_pages(substream); 719 snd_pcm_lib_free_pages(substream);
@@ -645,43 +721,48 @@ static int snd_azf3328_hw_free(snd_pcm_substream_t * substream)
645 return 0; 721 return 0;
646} 722}
647 723
648static void snd_azf3328_setfmt(azf3328_t *chip, 724static void
725snd_azf3328_setfmt(azf3328_t *chip,
649 unsigned int reg, 726 unsigned int reg,
650 unsigned int bitrate, 727 unsigned int bitrate,
651 unsigned int format_width, 728 unsigned int format_width,
652 unsigned int channels 729 unsigned int channels
653) 730)
654{ 731{
655 unsigned int val = 0xff00; 732 u16 val = 0xff00;
656 unsigned long flags; 733 unsigned long flags;
657 734
658 snd_azf3328_dbgcallenter(); 735 snd_azf3328_dbgcallenter();
659 switch (bitrate) { 736 switch (bitrate) {
660 case 5512: val |= 0x0d; break; /* the AZF3328 names it "5510" for some strange reason */ 737 case 4000: val |= SOUNDFORMAT_FREQ_SUSPECTED_4000; break;
661 case 6620: val |= 0x0b; break; 738 case 4800: val |= SOUNDFORMAT_FREQ_SUSPECTED_4800; break;
662 case 8000: val |= 0x00; break; 739 case 5512: val |= SOUNDFORMAT_FREQ_5510; break; /* the AZF3328 names it "5510" for some strange reason */
663 case 9600: val |= 0x08; break; 740 case 6620: val |= SOUNDFORMAT_FREQ_6620; break;
664 case 11025: val |= 0x01; break; 741 case 8000: val |= SOUNDFORMAT_FREQ_8000; break;
665 case 16000: val |= 0x02; break; 742 case 9600: val |= SOUNDFORMAT_FREQ_9600; break;
666 case 22050: val |= 0x03; break; 743 case 11025: val |= SOUNDFORMAT_FREQ_11025; break;
667 case 32000: val |= 0x04; break; 744 case 13240: val |= SOUNDFORMAT_FREQ_SUSPECTED_13240; break;
668 case 44100: val |= 0x05; break; 745 case 16000: val |= SOUNDFORMAT_FREQ_16000; break;
669 case 48000: val |= 0x06; break; 746 case 22050: val |= SOUNDFORMAT_FREQ_22050; break;
670 case 64000: val |= 0x07; break; 747 case 32000: val |= SOUNDFORMAT_FREQ_32000; break;
748 case 44100: val |= SOUNDFORMAT_FREQ_44100; break;
749 case 48000: val |= SOUNDFORMAT_FREQ_48000; break;
750 case 66200: val |= SOUNDFORMAT_FREQ_SUSPECTED_66200; break;
671 default: 751 default:
672 snd_printk("unknown bitrate %d, assuming 44.1kHz!\n", bitrate); 752 snd_printk(KERN_WARNING "unknown bitrate %d, assuming 44.1kHz!\n", bitrate);
673 val |= 0x05; /* 44100 */ 753 val |= SOUNDFORMAT_FREQ_44100;
674 break; 754 break;
675 } 755 }
676 /* val = 0xff07; 3m27.993s (65301Hz; -> 64000Hz???) */ 756 /* val = 0xff07; 3m27.993s (65301Hz; -> 64000Hz???) hmm, 66120, 65967, 66123 */
677 /* val = 0xff09; 17m15.098s (13123,478Hz; -> 12000Hz???) */ 757 /* val = 0xff09; 17m15.098s (13123,478Hz; -> 12000Hz???) hmm, 13237.2Hz? */
678 /* val = 0xff0a; 47m30.599s (4764,891Hz; -> 4800Hz???) */ 758 /* val = 0xff0a; 47m30.599s (4764,891Hz; -> 4800Hz???) yup, 4803Hz */
679 /* val = 0xff0c; 57m0.510s (4010,263Hz; -> 4000Hz???) */ 759 /* val = 0xff0c; 57m0.510s (4010,263Hz; -> 4000Hz???) yup, 4003Hz */
680 /* val = 0xff05; 5m11.556s (... -> 44100Hz) */ 760 /* val = 0xff05; 5m11.556s (... -> 44100Hz) */
681 /* val = 0xff03; 10m21.529s (21872,463Hz; -> 22050Hz???) */ 761 /* val = 0xff03; 10m21.529s (21872,463Hz; -> 22050Hz???) */
682 /* val = 0xff0f; 20m41.883s (10937,993Hz; -> 11025Hz???) */ 762 /* val = 0xff0f; 20m41.883s (10937,993Hz; -> 11025Hz???) */
683 /* val = 0xff0d; 41m23.135s (5523,600Hz; -> 5512Hz???) */ 763 /* val = 0xff0d; 41m23.135s (5523,600Hz; -> 5512Hz???) */
684 /* val = 0xff0e; 28m30.777s (8017Hz; -> 8000Hz???) */ 764 /* val = 0xff0e; 28m30.777s (8017Hz; -> 8000Hz???) */
765
685 if (channels == 2) 766 if (channels == 2)
686 val |= SOUNDFORMAT_FLAG_2CHANNELS; 767 val |= SOUNDFORMAT_FLAG_2CHANNELS;
687 768
@@ -691,7 +772,7 @@ static void snd_azf3328_setfmt(azf3328_t *chip,
691 spin_lock_irqsave(&chip->reg_lock, flags); 772 spin_lock_irqsave(&chip->reg_lock, flags);
692 773
693 /* set bitrate/format */ 774 /* set bitrate/format */
694 outw(val, chip->codec_port+reg); 775 snd_azf3328_codec_outw(chip, reg, val);
695 776
696 /* changing the bitrate/format settings switches off the 777 /* changing the bitrate/format settings switches off the
697 * audio output with an annoying click in case of 8/16bit format change 778 * audio output with an annoying click in case of 8/16bit format change
@@ -701,47 +782,67 @@ static void snd_azf3328_setfmt(azf3328_t *chip,
701 * FIXME: does this have some side effects for full-duplex 782 * FIXME: does this have some side effects for full-duplex
702 * or other dramatic side effects? */ 783 * or other dramatic side effects? */
703 if (reg == IDX_IO_PLAY_SOUNDFORMAT) /* only do it for playback */ 784 if (reg == IDX_IO_PLAY_SOUNDFORMAT) /* only do it for playback */
704 outw(inw(chip->codec_port + IDX_IO_PLAY_FLAGS)|DMA_PLAY_SOMETHING1|DMA_PLAY_SOMETHING2|SOMETHING_ALMOST_ALWAYS_SET|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port + IDX_IO_PLAY_FLAGS); 785 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
786 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS) |
787 DMA_PLAY_SOMETHING1 |
788 DMA_PLAY_SOMETHING2 |
789 SOMETHING_ALMOST_ALWAYS_SET |
790 DMA_EPILOGUE_SOMETHING |
791 DMA_SOMETHING_ELSE
792 );
705 793
706 spin_unlock_irqrestore(&chip->reg_lock, flags); 794 spin_unlock_irqrestore(&chip->reg_lock, flags);
707 snd_azf3328_dbgcallleave(); 795 snd_azf3328_dbgcallleave();
708} 796}
709 797
710static void snd_azf3328_setdmaa(azf3328_t *chip, 798static void
799snd_azf3328_setdmaa(azf3328_t *chip,
711 long unsigned int addr, 800 long unsigned int addr,
712 unsigned int count, 801 unsigned int count,
713 unsigned int size, 802 unsigned int size,
714 int do_recording) 803 int do_recording)
715{ 804{
716 long unsigned int addr1; 805 unsigned long flags, portbase;
717 long unsigned int addr2; 806 unsigned int is_running;
718 unsigned int count1;
719 unsigned int count2;
720 unsigned long flags;
721 int reg_offs = do_recording ? 0x20 : 0x00;
722 807
723 snd_azf3328_dbgcallenter(); 808 snd_azf3328_dbgcallenter();
809 if (do_recording)
810 {
811 /* access capture registers, i.e. skip playback reg section */
812 portbase = chip->codec_port + 0x20;
813 is_running = chip->is_recording;
814 }
815 else
816 {
817 /* access the playback register section */
818 portbase = chip->codec_port + 0x00;
819 is_running = chip->is_playing;
820 }
821
724 /* AZF3328 uses a two buffer pointer DMA playback approach */ 822 /* AZF3328 uses a two buffer pointer DMA playback approach */
725 if (!chip->is_playing) 823 if (!is_running)
726 { 824 {
727 addr1 = addr; 825 unsigned long addr_area2;
728 addr2 = addr+(size/2); 826 unsigned long count_areas, count_tmp; /* width 32bit -- overflow!! */
729 count1 = (size/2)-1; 827 count_areas = size/2;
730 count2 = (size/2)-1; 828 addr_area2 = addr+count_areas;
731#if DEBUG_PLAY_REC 829 count_areas--; /* max. index */
732 snd_azf3328_dbgplay("setting dma: buf1 %08lx[%d], buf2 %08lx[%d]\n", addr1, count1, addr2, count2); 830 snd_azf3328_dbgplay("set DMA: buf1 %08lx[%lu], buf2 %08lx[%lu]\n", addr, count_areas, addr_area2, count_areas);
733#endif 831
832 /* build combined I/O buffer length word */
833 count_tmp = count_areas;
834 count_areas |= (count_tmp << 16);
734 spin_lock_irqsave(&chip->reg_lock, flags); 835 spin_lock_irqsave(&chip->reg_lock, flags);
735 outl(addr1, chip->codec_port+reg_offs+IDX_IO_PLAY_DMA_START_1); 836 outl(addr, portbase + IDX_IO_PLAY_DMA_START_1);
736 outl(addr2, chip->codec_port+reg_offs+IDX_IO_PLAY_DMA_START_2); 837 outl(addr_area2, portbase + IDX_IO_PLAY_DMA_START_2);
737 outw(count1, chip->codec_port+reg_offs+IDX_IO_PLAY_DMA_LEN_1); 838 outl(count_areas, portbase + IDX_IO_PLAY_DMA_LEN_1);
738 outw(count2, chip->codec_port+reg_offs+IDX_IO_PLAY_DMA_LEN_2);
739 spin_unlock_irqrestore(&chip->reg_lock, flags); 839 spin_unlock_irqrestore(&chip->reg_lock, flags);
740 } 840 }
741 snd_azf3328_dbgcallleave(); 841 snd_azf3328_dbgcallleave();
742} 842}
743 843
744static int snd_azf3328_playback_prepare(snd_pcm_substream_t *substream) 844static int
845snd_azf3328_playback_prepare(snd_pcm_substream_t *substream)
745{ 846{
746#if 0 847#if 0
747 azf3328_t *chip = snd_pcm_substream_chip(substream); 848 azf3328_t *chip = snd_pcm_substream_chip(substream);
@@ -752,14 +853,18 @@ static int snd_azf3328_playback_prepare(snd_pcm_substream_t *substream)
752 853
753 snd_azf3328_dbgcallenter(); 854 snd_azf3328_dbgcallenter();
754#if 0 855#if 0
755 snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT, runtime->rate, snd_pcm_format_width(runtime->format), runtime->channels); 856 snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT,
857 runtime->rate,
858 snd_pcm_format_width(runtime->format),
859 runtime->channels);
756 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 0); 860 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 0);
757#endif 861#endif
758 snd_azf3328_dbgcallleave(); 862 snd_azf3328_dbgcallleave();
759 return 0; 863 return 0;
760} 864}
761 865
762static int snd_azf3328_capture_prepare(snd_pcm_substream_t * substream) 866static int
867snd_azf3328_capture_prepare(snd_pcm_substream_t * substream)
763{ 868{
764#if 0 869#if 0
765 azf3328_t *chip = snd_pcm_substream_chip(substream); 870 azf3328_t *chip = snd_pcm_substream_chip(substream);
@@ -770,14 +875,18 @@ static int snd_azf3328_capture_prepare(snd_pcm_substream_t * substream)
770 875
771 snd_azf3328_dbgcallenter(); 876 snd_azf3328_dbgcallenter();
772#if 0 877#if 0
773 snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT, runtime->rate, snd_pcm_format_width(runtime->format), runtime->channels); 878 snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
879 runtime->rate,
880 snd_pcm_format_width(runtime->format),
881 runtime->channels);
774 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 1); 882 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 1);
775#endif 883#endif
776 snd_azf3328_dbgcallleave(); 884 snd_azf3328_dbgcallleave();
777 return 0; 885 return 0;
778} 886}
779 887
780static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd) 888static int
889snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd)
781{ 890{
782 azf3328_t *chip = snd_pcm_substream_chip(substream); 891 azf3328_t *chip = snd_pcm_substream_chip(substream);
783 snd_pcm_runtime_t *runtime = substream->runtime; 892 snd_pcm_runtime_t *runtime = substream->runtime;
@@ -785,79 +894,98 @@ static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd
785 unsigned int status1; 894 unsigned int status1;
786 895
787 snd_azf3328_dbgcalls("snd_azf3328_playback_trigger cmd %d\n", cmd); 896 snd_azf3328_dbgcalls("snd_azf3328_playback_trigger cmd %d\n", cmd);
897
788 switch (cmd) { 898 switch (cmd) {
789 case SNDRV_PCM_TRIGGER_START: 899 case SNDRV_PCM_TRIGGER_START:
790 900 snd_azf3328_dbgplay("START PLAYBACK\n");
791 snd_azf3328_dbgio(chip, "trigger1");
792 901
793 /* mute WaveOut */ 902 /* mute WaveOut */
794 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1); 903 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
795 904
796 snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT, runtime->rate, snd_pcm_format_width(runtime->format), runtime->channels); 905 snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT,
906 runtime->rate,
907 snd_pcm_format_width(runtime->format),
908 runtime->channels);
797 909
798 spin_lock(&chip->reg_lock); 910 spin_lock(&chip->reg_lock);
799 /* stop playback */ 911 /* stop playback */
800 status1 = inw(chip->codec_port+IDX_IO_PLAY_FLAGS); 912 status1 = snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS);
801 status1 &= ~DMA_RESUME; 913 status1 &= ~DMA_RESUME;
802 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 914 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
803 915
804 /* FIXME: clear interrupts or what??? */ 916 /* FIXME: clear interrupts or what??? */
805 outw(0xffff, chip->codec_port+IDX_IO_PLAY_IRQMASK); 917 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_IRQTYPE, 0xffff);
806 spin_unlock(&chip->reg_lock); 918 spin_unlock(&chip->reg_lock);
807 919
808 snd_azf3328_setdmaa(chip, runtime->dma_addr, snd_pcm_lib_period_bytes(substream), snd_pcm_lib_buffer_bytes(substream), 0); 920 snd_azf3328_setdmaa(chip, runtime->dma_addr,
921 snd_pcm_lib_period_bytes(substream),
922 snd_pcm_lib_buffer_bytes(substream),
923 0);
809 924
810 spin_lock(&chip->reg_lock); 925 spin_lock(&chip->reg_lock);
811#ifdef WIN9X 926#ifdef WIN9X
812 /* FIXME: enable playback/recording??? */ 927 /* FIXME: enable playback/recording??? */
813 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2; 928 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2;
814 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 929 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
815 930
816 /* start playback again */ 931 /* start playback again */
817 /* FIXME: what is this value (0x0010)??? */ 932 /* FIXME: what is this value (0x0010)??? */
818 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING; 933 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING;
819 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 934 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
820#else /* NT4 */ 935#else /* NT4 */
821 outw(0x00, chip->codec_port+IDX_IO_PLAY_FLAGS); 936 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
822 outw(DMA_PLAY_SOMETHING1, chip->codec_port+IDX_IO_PLAY_FLAGS); 937 0x0000);
823 outw(DMA_PLAY_SOMETHING1|DMA_PLAY_SOMETHING2, chip->codec_port+IDX_IO_PLAY_FLAGS); 938 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
824 outw(DMA_RESUME|SOMETHING_ALMOST_ALWAYS_SET|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port+IDX_IO_PLAY_FLAGS); 939 DMA_PLAY_SOMETHING1);
940 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
941 DMA_PLAY_SOMETHING1 |
942 DMA_PLAY_SOMETHING2);
943 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
944 DMA_RESUME |
945 SOMETHING_ALMOST_ALWAYS_SET |
946 DMA_EPILOGUE_SOMETHING |
947 DMA_SOMETHING_ELSE);
825#endif 948#endif
826 spin_unlock(&chip->reg_lock); 949 spin_unlock(&chip->reg_lock);
827 950
828 /* now unmute WaveOut */ 951 /* now unmute WaveOut */
829 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0); 952 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
830 953
831 snd_azf3328_dbgio(chip, "trigger2");
832 chip->is_playing = 1; 954 chip->is_playing = 1;
955 snd_azf3328_dbgplay("STARTED PLAYBACK\n");
833 break; 956 break;
834 case SNDRV_PCM_TRIGGER_STOP: 957 case SNDRV_PCM_TRIGGER_STOP:
958 snd_azf3328_dbgplay("STOP PLAYBACK\n");
959
835 /* mute WaveOut */ 960 /* mute WaveOut */
836 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1); 961 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
837 962
838 spin_lock(&chip->reg_lock); 963 spin_lock(&chip->reg_lock);
839 /* stop playback */ 964 /* stop playback */
840 status1 = inw(chip->codec_port+IDX_IO_PLAY_FLAGS); 965 status1 = snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS);
841 966
842 status1 &= ~DMA_RESUME; 967 status1 &= ~DMA_RESUME;
843 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 968 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
844 969
970 /* hmm, is this really required? we're resetting the same bit
971 * immediately thereafter... */
845 status1 |= DMA_PLAY_SOMETHING1; 972 status1 |= DMA_PLAY_SOMETHING1;
846 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 973 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
847 974
848 status1 &= ~DMA_PLAY_SOMETHING1; 975 status1 &= ~DMA_PLAY_SOMETHING1;
849 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 976 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
850 spin_unlock(&chip->reg_lock); 977 spin_unlock(&chip->reg_lock);
851 978
852 /* now unmute WaveOut */ 979 /* now unmute WaveOut */
853 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0); 980 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
854 chip->is_playing = 0; 981 chip->is_playing = 0;
982 snd_azf3328_dbgplay("STOPPED PLAYBACK\n");
855 break; 983 break;
856 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 984 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
857 snd_printk("FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n"); 985 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
858 break; 986 break;
859 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 987 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
860 snd_printk("FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n"); 988 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
861 break; 989 break;
862 default: 990 default:
863 return -EINVAL; 991 return -EINVAL;
@@ -869,7 +997,8 @@ static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd
869 997
870/* this is just analogous to playback; I'm not quite sure whether recording 998/* this is just analogous to playback; I'm not quite sure whether recording
871 * should actually be triggered like that */ 999 * should actually be triggered like that */
872static int snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd) 1000static int
1001snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd)
873{ 1002{
874 azf3328_t *chip = snd_pcm_substream_chip(substream); 1003 azf3328_t *chip = snd_pcm_substream_chip(substream);
875 snd_pcm_runtime_t *runtime = substream->runtime; 1004 snd_pcm_runtime_t *runtime = substream->runtime;
@@ -877,68 +1006,86 @@ static int snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd)
877 unsigned int status1; 1006 unsigned int status1;
878 1007
879 snd_azf3328_dbgcalls("snd_azf3328_capture_trigger cmd %d\n", cmd); 1008 snd_azf3328_dbgcalls("snd_azf3328_capture_trigger cmd %d\n", cmd);
1009
880 switch (cmd) { 1010 switch (cmd) {
881 case SNDRV_PCM_TRIGGER_START: 1011 case SNDRV_PCM_TRIGGER_START:
882 1012
883 snd_azf3328_dbgio(chip, "trigger1"); 1013 snd_azf3328_dbgplay("START CAPTURE\n");
884 1014
885 snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT, runtime->rate, snd_pcm_format_width(runtime->format), runtime->channels); 1015 snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
1016 runtime->rate,
1017 snd_pcm_format_width(runtime->format),
1018 runtime->channels);
886 1019
887 spin_lock(&chip->reg_lock); 1020 spin_lock(&chip->reg_lock);
888 /* stop recording */ 1021 /* stop recording */
889 status1 = inw(chip->codec_port+IDX_IO_REC_FLAGS); 1022 status1 = snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS);
890 status1 &= ~DMA_RESUME; 1023 status1 &= ~DMA_RESUME;
891 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1024 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
892 1025
893 /* FIXME: clear interrupts or what??? */ 1026 /* FIXME: clear interrupts or what??? */
894 outw(0xffff, chip->codec_port+IDX_IO_REC_IRQMASK); 1027 snd_azf3328_codec_outw(chip, IDX_IO_REC_IRQTYPE, 0xffff);
895 spin_unlock(&chip->reg_lock); 1028 spin_unlock(&chip->reg_lock);
896 1029
897 snd_azf3328_setdmaa(chip, runtime->dma_addr, snd_pcm_lib_period_bytes(substream), snd_pcm_lib_buffer_bytes(substream), 1); 1030 snd_azf3328_setdmaa(chip, runtime->dma_addr,
1031 snd_pcm_lib_period_bytes(substream),
1032 snd_pcm_lib_buffer_bytes(substream),
1033 1);
898 1034
899 spin_lock(&chip->reg_lock); 1035 spin_lock(&chip->reg_lock);
900#ifdef WIN9X 1036#ifdef WIN9X
901 /* FIXME: enable playback/recording??? */ 1037 /* FIXME: enable playback/recording??? */
902 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2; 1038 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2;
903 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1039 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
904 1040
905 /* start playback again */ 1041 /* start capture again */
906 /* FIXME: what is this value (0x0010)??? */ 1042 /* FIXME: what is this value (0x0010)??? */
907 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING; 1043 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING;
908 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1044 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
909#else 1045#else
910 outw(0x00, chip->codec_port+IDX_IO_REC_FLAGS); 1046 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
911 outw(DMA_PLAY_SOMETHING1, chip->codec_port+IDX_IO_REC_FLAGS); 1047 0x0000);
912 outw(DMA_PLAY_SOMETHING1|DMA_PLAY_SOMETHING2, chip->codec_port+IDX_IO_REC_FLAGS); 1048 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
913 outw(DMA_RESUME|SOMETHING_ALMOST_ALWAYS_SET|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port+IDX_IO_REC_FLAGS); 1049 DMA_PLAY_SOMETHING1);
1050 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1051 DMA_PLAY_SOMETHING1 |
1052 DMA_PLAY_SOMETHING2);
1053 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1054 DMA_RESUME |
1055 SOMETHING_ALMOST_ALWAYS_SET |
1056 DMA_EPILOGUE_SOMETHING |
1057 DMA_SOMETHING_ELSE);
914#endif 1058#endif
915 spin_unlock(&chip->reg_lock); 1059 spin_unlock(&chip->reg_lock);
916 1060
917 snd_azf3328_dbgio(chip, "trigger2"); 1061 chip->is_recording = 1;
918 chip->is_playing = 1; 1062 snd_azf3328_dbgplay("STARTED CAPTURE\n");
919 break; 1063 break;
920 case SNDRV_PCM_TRIGGER_STOP: 1064 case SNDRV_PCM_TRIGGER_STOP:
1065 snd_azf3328_dbgplay("STOP CAPTURE\n");
1066
921 spin_lock(&chip->reg_lock); 1067 spin_lock(&chip->reg_lock);
922 /* stop recording */ 1068 /* stop recording */
923 status1 = inw(chip->codec_port+IDX_IO_REC_FLAGS); 1069 status1 = snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS);
924 1070
925 status1 &= ~DMA_RESUME; 1071 status1 &= ~DMA_RESUME;
926 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1072 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
927 1073
928 status1 |= DMA_PLAY_SOMETHING1; 1074 status1 |= DMA_PLAY_SOMETHING1;
929 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1075 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
930 1076
931 status1 &= ~DMA_PLAY_SOMETHING1; 1077 status1 &= ~DMA_PLAY_SOMETHING1;
932 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1078 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
933 spin_unlock(&chip->reg_lock); 1079 spin_unlock(&chip->reg_lock);
934 1080
935 chip->is_playing = 0; 1081 chip->is_recording = 0;
1082 snd_azf3328_dbgplay("STOPPED CAPTURE\n");
936 break; 1083 break;
937 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1084 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
938 snd_printk("FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n"); 1085 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
939 break; 1086 break;
940 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1087 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
941 snd_printk("FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n"); 1088 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
942 break; 1089 break;
943 default: 1090 default:
944 return -EINVAL; 1091 return -EINVAL;
@@ -948,11 +1095,11 @@ static int snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd)
948 return result; 1095 return result;
949} 1096}
950 1097
951static snd_pcm_uframes_t snd_azf3328_playback_pointer(snd_pcm_substream_t * substream) 1098static snd_pcm_uframes_t
1099snd_azf3328_playback_pointer(snd_pcm_substream_t * substream)
952{ 1100{
953 azf3328_t *chip = snd_pcm_substream_chip(substream); 1101 azf3328_t *chip = snd_pcm_substream_chip(substream);
954 unsigned long bufptr, playptr; 1102 unsigned long bufptr, result;
955 unsigned long result;
956 snd_pcm_uframes_t frmres; 1103 snd_pcm_uframes_t frmres;
957 1104
958#ifdef QUERY_HARDWARE 1105#ifdef QUERY_HARDWARE
@@ -960,19 +1107,20 @@ static snd_pcm_uframes_t snd_azf3328_playback_pointer(snd_pcm_substream_t * subs
960#else 1107#else
961 bufptr = substream->runtime->dma_addr; 1108 bufptr = substream->runtime->dma_addr;
962#endif 1109#endif
963 playptr = inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS); 1110 result = inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS);
964 1111
965 result = playptr - bufptr; 1112 /* calculate offset */
966 frmres = bytes_to_frames( substream->runtime, result ); 1113 result -= bufptr;
967 snd_azf3328_dbgplay("result %lx, playptr %lx (base %x), frames %ld\n", result, playptr, substream->runtime->dma_addr, frmres); 1114 frmres = bytes_to_frames( substream->runtime, result);
1115 snd_azf3328_dbgplay("PLAY @ 0x%8lx, frames %8ld\n", result, frmres);
968 return frmres; 1116 return frmres;
969} 1117}
970 1118
971static snd_pcm_uframes_t snd_azf3328_capture_pointer(snd_pcm_substream_t * substream) 1119static snd_pcm_uframes_t
1120snd_azf3328_capture_pointer(snd_pcm_substream_t * substream)
972{ 1121{
973 azf3328_t *chip = snd_pcm_substream_chip(substream); 1122 azf3328_t *chip = snd_pcm_substream_chip(substream);
974 unsigned long bufptr, recptr; 1123 unsigned long bufptr, result;
975 unsigned long result;
976 snd_pcm_uframes_t frmres; 1124 snd_pcm_uframes_t frmres;
977 1125
978#ifdef QUERY_HARDWARE 1126#ifdef QUERY_HARDWARE
@@ -980,96 +1128,116 @@ static snd_pcm_uframes_t snd_azf3328_capture_pointer(snd_pcm_substream_t * subst
980#else 1128#else
981 bufptr = substream->runtime->dma_addr; 1129 bufptr = substream->runtime->dma_addr;
982#endif 1130#endif
983 recptr = inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS); 1131 result = inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS);
984 1132
985 result = recptr - bufptr; 1133 /* calculate offset */
986 frmres = bytes_to_frames( substream->runtime, result ); 1134 result -= bufptr;
987 snd_azf3328_dbgplay("result %lx, rec ptr %lx (base %x), frames %ld\n", result, recptr, substream->runtime->dma_addr, frmres); 1135 frmres = bytes_to_frames( substream->runtime, result);
1136 snd_azf3328_dbgplay("REC @ 0x%8lx, frames %8ld\n", result, frmres);
988 return frmres; 1137 return frmres;
989} 1138}
990 1139
991static irqreturn_t snd_azf3328_interrupt(int irq, void *dev_id, struct pt_regs *regs) 1140static irqreturn_t
1141snd_azf3328_interrupt(int irq, void *dev_id, struct pt_regs *regs)
992{ 1142{
993 azf3328_t *chip = dev_id; 1143 azf3328_t *chip = dev_id;
994 unsigned int status, which; 1144 u8 status, which;
995 static unsigned long count; 1145 static unsigned long irq_count;
996 1146
997 status = inw(chip->codec_port+IDX_IO_IRQSTATUS); 1147 status = snd_azf3328_codec_inb(chip, IDX_IO_IRQSTATUS);
998 1148
999 /* fast path out, to ease interrupt sharing */ 1149 /* fast path out, to ease interrupt sharing */
1000 if (!(status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_MPU401|IRQ_SOMEIRQ))) 1150 if (!(status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_MPU401|IRQ_TIMER)))
1001 return IRQ_NONE; /* must be interrupt for another device */ 1151 return IRQ_NONE; /* must be interrupt for another device */
1002 1152
1003 snd_azf3328_dbgplay("Interrupt %ld!\nIDX_IO_PLAY_FLAGS %04x, IDX_IO_PLAY_IRQMASK %04x, IDX_IO_IRQSTATUS %04x\n", count, inw(chip->codec_port+IDX_IO_PLAY_FLAGS), inw(chip->codec_port+IDX_IO_PLAY_IRQMASK), inw(chip->codec_port+IDX_IO_IRQSTATUS)); 1153 snd_azf3328_dbgplay("Interrupt %ld!\nIDX_IO_PLAY_FLAGS %04x, IDX_IO_PLAY_IRQTYPE %04x, IDX_IO_IRQSTATUS %04x\n",
1154 irq_count,
1155 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS),
1156 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_IRQTYPE),
1157 status);
1004 1158
1159 if (status & IRQ_TIMER)
1160 {
1161 /* snd_azf3328_dbgplay("timer %ld\n", inl(chip->codec_port+IDX_IO_TIMER_VALUE) & TIMER_VALUE_MASK); */
1162 if (chip->timer)
1163 snd_timer_interrupt(chip->timer, chip->timer->sticks);
1164 /* ACK timer */
1165 spin_lock(&chip->reg_lock);
1166 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x07);
1167 spin_unlock(&chip->reg_lock);
1168 snd_azf3328_dbgplay("azt3328: timer IRQ\n");
1169 }
1005 if (status & IRQ_PLAYBACK) 1170 if (status & IRQ_PLAYBACK)
1006 { 1171 {
1007 spin_lock(&chip->reg_lock); 1172 spin_lock(&chip->reg_lock);
1008 which = inw(chip->codec_port+IDX_IO_PLAY_IRQMASK); 1173 which = snd_azf3328_codec_inb(chip, IDX_IO_PLAY_IRQTYPE);
1009 if (which & IRQ_FINISHED_PLAYBUF_1) 1174 /* ack all IRQ types immediately */
1010 /* ack IRQ */ 1175 snd_azf3328_codec_outb(chip, IDX_IO_PLAY_IRQTYPE, which);
1011 outw(which | IRQ_FINISHED_PLAYBUF_1, chip->codec_port+IDX_IO_PLAY_IRQMASK); 1176 spin_unlock(&chip->reg_lock);
1012 if (which & IRQ_FINISHED_PLAYBUF_2) 1177
1013 /* ack IRQ */
1014 outw(which | IRQ_FINISHED_PLAYBUF_2, chip->codec_port+IDX_IO_PLAY_IRQMASK);
1015 if (which & IRQ_PLAY_SOMETHING)
1016 {
1017 snd_azf3328_dbgplay("azt3328: unknown play IRQ type occurred, please report!\n");
1018 }
1019 if (chip->pcm && chip->playback_substream) 1178 if (chip->pcm && chip->playback_substream)
1020 { 1179 {
1021 snd_azf3328_dbgplay("which %x, playptr %lx\n", which, inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS));
1022 snd_pcm_period_elapsed(chip->playback_substream); 1180 snd_pcm_period_elapsed(chip->playback_substream);
1023 snd_azf3328_dbgplay("period done, playptr %lx.\n", inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS)); 1181 snd_azf3328_dbgplay("PLAY period done (#%x), @ %x\n",
1182 which,
1183 inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS));
1024 } 1184 }
1025 else 1185 else
1026 snd_azf3328_dbgplay("azt3328: ouch, irq handler problem!\n"); 1186 snd_azf3328_dbgplay("azt3328: ouch, irq handler problem!\n");
1027 spin_unlock(&chip->reg_lock); 1187 if (which & IRQ_PLAY_SOMETHING)
1188 snd_azf3328_dbgplay("azt3328: unknown play IRQ type occurred, please report!\n");
1028 } 1189 }
1029 if (status & IRQ_RECORDING) 1190 if (status & IRQ_RECORDING)
1030 { 1191 {
1031 spin_lock(&chip->reg_lock); 1192 spin_lock(&chip->reg_lock);
1032 which = inw(chip->codec_port+IDX_IO_REC_IRQMASK); 1193 which = snd_azf3328_codec_inb(chip, IDX_IO_REC_IRQTYPE);
1033 if (which & IRQ_FINISHED_RECBUF_1) 1194 /* ack all IRQ types immediately */
1034 /* ack interrupt */ 1195 snd_azf3328_codec_outb(chip, IDX_IO_REC_IRQTYPE, which);
1035 outw(which | IRQ_FINISHED_RECBUF_1, chip->codec_port+IDX_IO_REC_IRQMASK); 1196 spin_unlock(&chip->reg_lock);
1036 if (which & IRQ_FINISHED_RECBUF_2) 1197
1037 /* ack interrupt */
1038 outw(which | IRQ_FINISHED_RECBUF_2, chip->codec_port+IDX_IO_REC_IRQMASK);
1039 if (which & IRQ_REC_SOMETHING)
1040 {
1041 snd_azf3328_dbgplay("azt3328: unknown rec IRQ type occurred, please report!\n");
1042 }
1043 if (chip->pcm && chip->capture_substream) 1198 if (chip->pcm && chip->capture_substream)
1044 { 1199 {
1045 snd_azf3328_dbgplay("which %x, recptr %lx\n", which, inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS));
1046 spin_unlock(&chip->reg_lock);
1047 snd_pcm_period_elapsed(chip->capture_substream); 1200 snd_pcm_period_elapsed(chip->capture_substream);
1048 spin_lock(&chip->reg_lock); 1201 snd_azf3328_dbgplay("REC period done (#%x), @ %x\n",
1049 snd_azf3328_dbgplay("period done, recptr %lx.\n", inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS)); 1202 which,
1203 inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS));
1050 } 1204 }
1051 spin_unlock(&chip->reg_lock); 1205 else
1206 snd_azf3328_dbgplay("azt3328: ouch, irq handler problem!\n");
1207 if (which & IRQ_REC_SOMETHING)
1208 snd_azf3328_dbgplay("azt3328: unknown rec IRQ type occurred, please report!\n");
1052 } 1209 }
1210 /* MPU401 has less critical IRQ requirements
1211 * than timer and playback/recording, right? */
1053 if (status & IRQ_MPU401) 1212 if (status & IRQ_MPU401)
1213 {
1054 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs); 1214 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
1055 if (status & IRQ_SOMEIRQ) 1215
1056 snd_azf3328_dbgplay("azt3328: unknown IRQ type occurred, please report!\n"); 1216 /* hmm, do we have to ack the IRQ here somehow?
1057 count++; 1217 * If so, then I don't know how... */
1218 snd_azf3328_dbgplay("azt3328: MPU401 IRQ\n");
1219 }
1220 irq_count++;
1058 return IRQ_HANDLED; 1221 return IRQ_HANDLED;
1059} 1222}
1060 1223
1061/*****************************************************************/ 1224/*****************************************************************/
1062 1225
1063static snd_pcm_hardware_t snd_azf3328_playback = 1226static const snd_pcm_hardware_t snd_azf3328_playback =
1064{ 1227{
1065 /* FIXME!! Correct? */ 1228 /* FIXME!! Correct? */
1066 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1229 .info = SNDRV_PCM_INFO_MMAP |
1067 SNDRV_PCM_INFO_MMAP_VALID), 1230 SNDRV_PCM_INFO_INTERLEAVED |
1068 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | 1231 SNDRV_PCM_INFO_MMAP_VALID,
1069 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE, 1232 .formats = SNDRV_PCM_FMTBIT_S8 |
1070 .rates = SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_KNOT, 1233 SNDRV_PCM_FMTBIT_U8 |
1071 .rate_min = 5512, 1234 SNDRV_PCM_FMTBIT_S16_LE |
1072 .rate_max = 64000, 1235 SNDRV_PCM_FMTBIT_U16_LE,
1236 .rates = SNDRV_PCM_RATE_5512 |
1237 SNDRV_PCM_RATE_8000_48000 |
1238 SNDRV_PCM_RATE_KNOT,
1239 .rate_min = 4000,
1240 .rate_max = 66200,
1073 .channels_min = 1, 1241 .channels_min = 1,
1074 .channels_max = 2, 1242 .channels_max = 2,
1075 .buffer_bytes_max = 65536, 1243 .buffer_bytes_max = 65536,
@@ -1083,16 +1251,21 @@ static snd_pcm_hardware_t snd_azf3328_playback =
1083 .fifo_size = 0, 1251 .fifo_size = 0,
1084}; 1252};
1085 1253
1086static snd_pcm_hardware_t snd_azf3328_capture = 1254static const snd_pcm_hardware_t snd_azf3328_capture =
1087{ 1255{
1088 /* FIXME */ 1256 /* FIXME */
1089 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1257 .info = SNDRV_PCM_INFO_MMAP |
1090 SNDRV_PCM_INFO_MMAP_VALID), 1258 SNDRV_PCM_INFO_INTERLEAVED |
1091 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | 1259 SNDRV_PCM_INFO_MMAP_VALID,
1092 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE, 1260 .formats = SNDRV_PCM_FMTBIT_S8 |
1093 .rates = SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_KNOT, 1261 SNDRV_PCM_FMTBIT_U8 |
1094 .rate_min = 5512, 1262 SNDRV_PCM_FMTBIT_S16_LE |
1095 .rate_max = 64000, 1263 SNDRV_PCM_FMTBIT_U16_LE,
1264 .rates = SNDRV_PCM_RATE_5512 |
1265 SNDRV_PCM_RATE_8000_48000 |
1266 SNDRV_PCM_RATE_KNOT,
1267 .rate_min = 4000,
1268 .rate_max = 66200,
1096 .channels_min = 1, 1269 .channels_min = 1,
1097 .channels_max = 2, 1270 .channels_max = 2,
1098 .buffer_bytes_max = 65536, 1271 .buffer_bytes_max = 65536,
@@ -1105,8 +1278,8 @@ static snd_pcm_hardware_t snd_azf3328_capture =
1105 1278
1106 1279
1107static unsigned int snd_azf3328_fixed_rates[] = { 1280static unsigned int snd_azf3328_fixed_rates[] = {
1108 5512, 6620, 8000, 9600, 11025, 16000, 22050, 32000, 44100, 48000, 64000 1281 4000, 4800, 5512, 6620, 8000, 9600, 11025, 13240, 16000, 22050, 32000,
1109}; 1282 44100, 48000, 66200 };
1110static snd_pcm_hw_constraint_list_t snd_azf3328_hw_constraints_rates = { 1283static snd_pcm_hw_constraint_list_t snd_azf3328_hw_constraints_rates = {
1111 .count = ARRAY_SIZE(snd_azf3328_fixed_rates), 1284 .count = ARRAY_SIZE(snd_azf3328_fixed_rates),
1112 .list = snd_azf3328_fixed_rates, 1285 .list = snd_azf3328_fixed_rates,
@@ -1115,7 +1288,8 @@ static snd_pcm_hw_constraint_list_t snd_azf3328_hw_constraints_rates = {
1115 1288
1116/*****************************************************************/ 1289/*****************************************************************/
1117 1290
1118static int snd_azf3328_playback_open(snd_pcm_substream_t * substream) 1291static int
1292snd_azf3328_playback_open(snd_pcm_substream_t * substream)
1119{ 1293{
1120 azf3328_t *chip = snd_pcm_substream_chip(substream); 1294 azf3328_t *chip = snd_pcm_substream_chip(substream);
1121 snd_pcm_runtime_t *runtime = substream->runtime; 1295 snd_pcm_runtime_t *runtime = substream->runtime;
@@ -1129,7 +1303,8 @@ static int snd_azf3328_playback_open(snd_pcm_substream_t * substream)
1129 return 0; 1303 return 0;
1130} 1304}
1131 1305
1132static int snd_azf3328_capture_open(snd_pcm_substream_t * substream) 1306static int
1307snd_azf3328_capture_open(snd_pcm_substream_t * substream)
1133{ 1308{
1134 azf3328_t *chip = snd_pcm_substream_chip(substream); 1309 azf3328_t *chip = snd_pcm_substream_chip(substream);
1135 snd_pcm_runtime_t *runtime = substream->runtime; 1310 snd_pcm_runtime_t *runtime = substream->runtime;
@@ -1143,7 +1318,8 @@ static int snd_azf3328_capture_open(snd_pcm_substream_t * substream)
1143 return 0; 1318 return 0;
1144} 1319}
1145 1320
1146static int snd_azf3328_playback_close(snd_pcm_substream_t * substream) 1321static int
1322snd_azf3328_playback_close(snd_pcm_substream_t * substream)
1147{ 1323{
1148 azf3328_t *chip = snd_pcm_substream_chip(substream); 1324 azf3328_t *chip = snd_pcm_substream_chip(substream);
1149 1325
@@ -1154,7 +1330,8 @@ static int snd_azf3328_playback_close(snd_pcm_substream_t * substream)
1154 return 0; 1330 return 0;
1155} 1331}
1156 1332
1157static int snd_azf3328_capture_close(snd_pcm_substream_t * substream) 1333static int
1334snd_azf3328_capture_close(snd_pcm_substream_t * substream)
1158{ 1335{
1159 azf3328_t *chip = snd_pcm_substream_chip(substream); 1336 azf3328_t *chip = snd_pcm_substream_chip(substream);
1160 1337
@@ -1188,14 +1365,16 @@ static snd_pcm_ops_t snd_azf3328_capture_ops = {
1188 .pointer = snd_azf3328_capture_pointer 1365 .pointer = snd_azf3328_capture_pointer
1189}; 1366};
1190 1367
1191static void snd_azf3328_pcm_free(snd_pcm_t *pcm) 1368static void
1369snd_azf3328_pcm_free(snd_pcm_t *pcm)
1192{ 1370{
1193 azf3328_t *chip = pcm->private_data; 1371 azf3328_t *chip = pcm->private_data;
1194 chip->pcm = NULL; 1372 chip->pcm = NULL;
1195 snd_pcm_lib_preallocate_free_for_all(pcm); 1373 snd_pcm_lib_preallocate_free_for_all(pcm);
1196} 1374}
1197 1375
1198static int __devinit snd_azf3328_pcm(azf3328_t *chip, int device) 1376static int __devinit
1377snd_azf3328_pcm(azf3328_t *chip, int device)
1199{ 1378{
1200 snd_pcm_t *pcm; 1379 snd_pcm_t *pcm;
1201 int err; 1380 int err;
@@ -1222,7 +1401,8 @@ static int __devinit snd_azf3328_pcm(azf3328_t *chip, int device)
1222/******************************************************************/ 1401/******************************************************************/
1223 1402
1224#ifdef SUPPORT_JOYSTICK 1403#ifdef SUPPORT_JOYSTICK
1225static int __devinit snd_azf3328_config_joystick(azf3328_t *chip, int dev) 1404static int __devinit
1405snd_azf3328_config_joystick(azf3328_t *chip, int dev)
1226{ 1406{
1227 struct gameport *gp; 1407 struct gameport *gp;
1228 struct resource *r; 1408 struct resource *r;
@@ -1238,8 +1418,7 @@ static int __devinit snd_azf3328_config_joystick(azf3328_t *chip, int dev)
1238 chip->gameport = gp = gameport_allocate_port(); 1418 chip->gameport = gp = gameport_allocate_port();
1239 if (!gp) { 1419 if (!gp) {
1240 printk(KERN_ERR "azt3328: cannot allocate memory for gameport\n"); 1420 printk(KERN_ERR "azt3328: cannot allocate memory for gameport\n");
1241 release_resource(r); 1421 release_and_free_resource(r);
1242 kfree_nocheck(r);
1243 return -ENOMEM; 1422 return -ENOMEM;
1244 } 1423 }
1245 1424
@@ -1249,15 +1428,16 @@ static int __devinit snd_azf3328_config_joystick(azf3328_t *chip, int dev)
1249 gp->io = 0x200; 1428 gp->io = 0x200;
1250 gameport_set_port_data(gp, r); 1429 gameport_set_port_data(gp, r);
1251 1430
1252 snd_azf3328_io2_write(chip, IDX_IO2_LEGACY_ADDR, 1431 snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
1253 snd_azf3328_io2_read(chip, IDX_IO2_LEGACY_ADDR) | LEGACY_JOY); 1432 snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) | LEGACY_JOY);
1254 1433
1255 gameport_register_port(chip->gameport); 1434 gameport_register_port(chip->gameport);
1256 1435
1257 return 0; 1436 return 0;
1258} 1437}
1259 1438
1260static void snd_azf3328_free_joystick(azf3328_t *chip) 1439static void
1440snd_azf3328_free_joystick(azf3328_t *chip)
1261{ 1441{
1262 if (chip->gameport) { 1442 if (chip->gameport) {
1263 struct resource *r = gameport_get_port_data(chip->gameport); 1443 struct resource *r = gameport_get_port_data(chip->gameport);
@@ -1265,33 +1445,36 @@ static void snd_azf3328_free_joystick(azf3328_t *chip)
1265 gameport_unregister_port(chip->gameport); 1445 gameport_unregister_port(chip->gameport);
1266 chip->gameport = NULL; 1446 chip->gameport = NULL;
1267 /* disable gameport */ 1447 /* disable gameport */
1268 snd_azf3328_io2_write(chip, IDX_IO2_LEGACY_ADDR, 1448 snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
1269 snd_azf3328_io2_read(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY); 1449 snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY);
1270 release_resource(r); 1450 release_and_free_resource(r);
1271 kfree_nocheck(r);
1272 } 1451 }
1273} 1452}
1274#else 1453#else
1275static inline int snd_azf3328_config_joystick(azf3328_t *chip, int dev) { return -ENOSYS; } 1454static inline int
1276static inline void snd_azf3328_free_joystick(azf3328_t *chip) { } 1455snd_azf3328_config_joystick(azf3328_t *chip, int dev) { return -ENOSYS; }
1456static inline void
1457snd_azf3328_free_joystick(azf3328_t *chip) { }
1277#endif 1458#endif
1278 1459
1279/******************************************************************/ 1460/******************************************************************/
1280 1461
1281static int snd_azf3328_free(azf3328_t *chip) 1462static int
1463snd_azf3328_free(azf3328_t *chip)
1282{ 1464{
1283 if (chip->irq < 0) 1465 if (chip->irq < 0)
1284 goto __end_hw; 1466 goto __end_hw;
1285 1467
1286 /* reset (close) mixer */ 1468 /* reset (close) mixer */
1287 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1); /* first mute master volume */ 1469 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1); /* first mute master volume */
1288 snd_azf3328_mixer_write(chip, IDX_MIXER_RESET, 0x0, WORD_VALUE); 1470 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
1289 1471
1290 /* interrupt setup - mask everything */ 1472 /* interrupt setup - mask everything (FIXME!) */
1291 /* FIXME */ 1473 /* well, at least we know how to disable the timer IRQ */
1474 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00);
1292 1475
1293 synchronize_irq(chip->irq); 1476 synchronize_irq(chip->irq);
1294 __end_hw: 1477__end_hw:
1295 snd_azf3328_free_joystick(chip); 1478 snd_azf3328_free_joystick(chip);
1296 if (chip->irq >= 0) 1479 if (chip->irq >= 0)
1297 free_irq(chip->irq, (void *)chip); 1480 free_irq(chip->irq, (void *)chip);
@@ -1302,15 +1485,129 @@ static int snd_azf3328_free(azf3328_t *chip)
1302 return 0; 1485 return 0;
1303} 1486}
1304 1487
1305static int snd_azf3328_dev_free(snd_device_t *device) 1488static int
1489snd_azf3328_dev_free(snd_device_t *device)
1306{ 1490{
1307 azf3328_t *chip = device->device_data; 1491 azf3328_t *chip = device->device_data;
1308 return snd_azf3328_free(chip); 1492 return snd_azf3328_free(chip);
1309} 1493}
1310 1494
1495/******************************************************************/
1496
1497/*** NOTE: the physical timer resolution actually is 1024000 ticks per second,
1498 *** but announcing those attributes to user-space would make programs
1499 *** configure the timer to a 1 tick value, resulting in an absolutely fatal
1500 *** timer IRQ storm.
1501 *** Thus I chose to announce a down-scaled virtual timer to the outside and
1502 *** calculate real timer countdown values internally.
1503 *** (the scale factor can be set via module parameter "seqtimer_scaling").
1504 ***/
1505
1506static int
1507snd_azf3328_timer_start(snd_timer_t *timer)
1508{
1509 azf3328_t *chip;
1510 unsigned long flags;
1511 unsigned int delay;
1512
1513 snd_azf3328_dbgcallenter();
1514 chip = snd_timer_chip(timer);
1515 delay = ((timer->sticks * seqtimer_scaling) - 1) & TIMER_VALUE_MASK;
1516 if (delay < 49)
1517 {
1518 /* uhoh, that's not good, since user-space won't know about
1519 * this timing tweak
1520 * (we need to do it to avoid a lockup, though) */
1521
1522 snd_azf3328_dbgtimer("delay was too low (%d)!\n", delay);
1523 delay = 49; /* minimum time is 49 ticks */
1524 }
1525 snd_azf3328_dbgtimer("setting timer countdown value %d, add COUNTDOWN|IRQ\n", delay);
1526 delay |= TIMER_ENABLE_COUNTDOWN | TIMER_ENABLE_IRQ;
1527 spin_lock_irqsave(&chip->reg_lock, flags);
1528 snd_azf3328_codec_outl(chip, IDX_IO_TIMER_VALUE, delay);
1529 spin_unlock_irqrestore(&chip->reg_lock, flags);
1530 snd_azf3328_dbgcallleave();
1531 return 0;
1532}
1533
1534static int
1535snd_azf3328_timer_stop(snd_timer_t *timer)
1536{
1537 azf3328_t *chip;
1538 unsigned long flags;
1539
1540 snd_azf3328_dbgcallenter();
1541 chip = snd_timer_chip(timer);
1542 spin_lock_irqsave(&chip->reg_lock, flags);
1543 /* disable timer countdown and interrupt */
1544 /* FIXME: should we write TIMER_ACK_IRQ here? */
1545 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0);
1546 spin_unlock_irqrestore(&chip->reg_lock, flags);
1547 snd_azf3328_dbgcallleave();
1548 return 0;
1549}
1550
1551
1552static int
1553snd_azf3328_timer_precise_resolution(snd_timer_t *timer,
1554 unsigned long *num, unsigned long *den)
1555{
1556 snd_azf3328_dbgcallenter();
1557 *num = 1;
1558 *den = 1024000 / seqtimer_scaling;
1559 snd_azf3328_dbgcallleave();
1560 return 0;
1561}
1562
1563static struct _snd_timer_hardware snd_azf3328_timer_hw = {
1564 .flags = SNDRV_TIMER_HW_AUTO,
1565 .resolution = 977, /* 1000000/1024000 = 0.9765625us */
1566 .ticks = 1024000, /* max tick count, defined by the value register; actually it's not 1024000, but 1048576, but we don't care */
1567 .start = snd_azf3328_timer_start,
1568 .stop = snd_azf3328_timer_stop,
1569 .precise_resolution = snd_azf3328_timer_precise_resolution,
1570};
1571
1572static int __devinit
1573snd_azf3328_timer(azf3328_t *chip, int device)
1574{
1575 snd_timer_t *timer = NULL;
1576 snd_timer_id_t tid;
1577 int err;
1578
1579 snd_azf3328_dbgcallenter();
1580 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
1581 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
1582 tid.card = chip->card->number;
1583 tid.device = device;
1584 tid.subdevice = 0;
1585
1586 snd_azf3328_timer_hw.resolution *= seqtimer_scaling;
1587 snd_azf3328_timer_hw.ticks /= seqtimer_scaling;
1588 if ((err = snd_timer_new(chip->card, "AZF3328", &tid, &timer)) < 0) {
1589 goto out;
1590 }
1591
1592 strcpy(timer->name, "AZF3328 timer");
1593 timer->private_data = chip;
1594 timer->hw = snd_azf3328_timer_hw;
1595
1596 chip->timer = timer;
1597
1598 err = 0;
1599
1600out:
1601 snd_azf3328_dbgcallleave();
1602 return err;
1603}
1604
1605/******************************************************************/
1606
1311#if 0 1607#if 0
1312/* check whether a bit can be modified */ 1608/* check whether a bit can be modified */
1313static void snd_azf3328_test_bit(unsigned int reg, int bit) 1609static void
1610snd_azf3328_test_bit(unsigned int reg, int bit)
1314{ 1611{
1315 unsigned char val, valoff, valon; 1612 unsigned char val, valoff, valon;
1316 1613
@@ -1328,7 +1625,26 @@ static void snd_azf3328_test_bit(unsigned int reg, int bit)
1328} 1625}
1329#endif 1626#endif
1330 1627
1331static int __devinit snd_azf3328_create(snd_card_t * card, 1628static void
1629snd_azf3328_debug_show_ports(const azf3328_t *chip)
1630{
1631#if DEBUG_MISC
1632 u16 tmp;
1633
1634 snd_azf3328_dbgmisc("codec_port 0x%lx, io2_port 0x%lx, mpu_port 0x%lx, synth_port 0x%lx, mixer_port 0x%lx, irq %d\n", chip->codec_port, chip->io2_port, chip->mpu_port, chip->synth_port, chip->mixer_port, chip->irq);
1635
1636 snd_azf3328_dbgmisc("io2 %02x %02x %02x %02x %02x %02x\n", snd_azf3328_io2_inb(chip, 0), snd_azf3328_io2_inb(chip, 1), snd_azf3328_io2_inb(chip, 2), snd_azf3328_io2_inb(chip, 3), snd_azf3328_io2_inb(chip, 4), snd_azf3328_io2_inb(chip, 5));
1637
1638 for (tmp=0; tmp <= 0x01; tmp += 1)
1639 snd_azf3328_dbgmisc("0x%02x: opl 0x%04x, mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, mpu330 0x%04x\n", tmp, inb(0x388 + tmp), inb(0x300 + tmp), inb(0x310 + tmp), inb(0x320 + tmp), inb(0x330 + tmp));
1640
1641 for (tmp = 0; tmp <= 0x6E; tmp += 2)
1642 snd_azf3328_dbgmisc("0x%02x: 0x%04x\n", tmp, snd_azf3328_codec_inb(chip, tmp));
1643#endif
1644}
1645
1646static int __devinit
1647snd_azf3328_create(snd_card_t * card,
1332 struct pci_dev *pci, 1648 struct pci_dev *pci,
1333 unsigned long device_type, 1649 unsigned long device_type,
1334 azf3328_t ** rchip) 1650 azf3328_t ** rchip)
@@ -1347,8 +1663,8 @@ static int __devinit snd_azf3328_create(snd_card_t * card,
1347 1663
1348 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1664 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1349 if (chip == NULL) { 1665 if (chip == NULL) {
1350 pci_disable_device(pci); 1666 err = -ENOMEM;
1351 return -ENOMEM; 1667 goto out_err;
1352 } 1668 }
1353 spin_lock_init(&chip->reg_lock); 1669 spin_lock_init(&chip->reg_lock);
1354 chip->card = card; 1670 chip->card = card;
@@ -1358,47 +1674,39 @@ static int __devinit snd_azf3328_create(snd_card_t * card,
1358 /* check if we can restrict PCI DMA transfers to 24 bits */ 1674 /* check if we can restrict PCI DMA transfers to 24 bits */
1359 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 || 1675 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
1360 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) { 1676 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
1361 snd_printk("architecture does not support 24bit PCI busmaster DMA\n"); 1677 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n");
1362 pci_disable_device(pci); 1678 err = -ENXIO;
1363 return -ENXIO; 1679 goto out_err;
1364 } 1680 }
1365 1681
1366 if ((err = pci_request_regions(pci, "Aztech AZF3328")) < 0) { 1682 if ((err = pci_request_regions(pci, "Aztech AZF3328")) < 0) {
1367 kfree(chip); 1683 goto out_err;
1368 pci_disable_device(pci);
1369 return err;
1370 } 1684 }
1371 1685
1372 chip->codec_port = pci_resource_start(pci, 0); 1686 chip->codec_port = pci_resource_start(pci, 0);
1373 chip->io2_port = pci_resource_start(pci, 1); 1687 chip->io2_port = pci_resource_start(pci, 1);
1374 chip->mpu_port = pci_resource_start(pci, 2); 1688 chip->mpu_port = pci_resource_start(pci, 2);
1375 chip->synth_port = pci_resource_start(pci, 3); 1689 chip->synth_port = pci_resource_start(pci, 3);
1376 chip->mixer_port = pci_resource_start(pci, 4); 1690 chip->mixer_port = pci_resource_start(pci, 4);
1377 1691
1378 if (request_irq(pci->irq, snd_azf3328_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) { 1692 if (request_irq(pci->irq, snd_azf3328_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
1379 snd_printk("unable to grab IRQ %d\n", pci->irq); 1693 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1380 snd_azf3328_free(chip); 1694 err = -EBUSY;
1381 return -EBUSY; 1695 goto out_err;
1382 } 1696 }
1383 chip->irq = pci->irq; 1697 chip->irq = pci->irq;
1384 pci_set_master(pci); 1698 pci_set_master(pci);
1385 synchronize_irq(chip->irq); 1699 synchronize_irq(chip->irq);
1386 1700
1387 snd_azf3328_dbgmisc("codec_port 0x%lx, io2_port 0x%lx, mpu_port 0x%lx, synth_port 0x%lx, mixer_port 0x%lx, irq %d\n", chip->codec_port, chip->io2_port, chip->mpu_port, chip->synth_port, chip->mixer_port, chip->irq); 1701 snd_azf3328_debug_show_ports(chip);
1388 1702
1389 snd_azf3328_dbgmisc("io2 %02x %02x %02x %02x %02x %02x\n", snd_azf3328_io2_read(chip, 0), snd_azf3328_io2_read(chip, 1), snd_azf3328_io2_read(chip, 2), snd_azf3328_io2_read(chip, 3), snd_azf3328_io2_read(chip, 4), snd_azf3328_io2_read(chip, 5));
1390
1391 for (tmp=0; tmp <= 0x01; tmp += 1)
1392 snd_azf3328_dbgmisc("0x%02x: opl 0x%04x, mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, mpu330 0x%04x\n", tmp, inb(0x388 + tmp), inb(0x300 + tmp), inb(0x310 + tmp), inb(0x320 + tmp), inb(0x330 + tmp));
1393
1394 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1703 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1395 snd_azf3328_free(chip); 1704 goto out_err;
1396 return err;
1397 } 1705 }
1398 1706
1399 /* create mixer interface & switches */ 1707 /* create mixer interface & switches */
1400 if ((err = snd_azf3328_mixer_new(chip)) < 0) 1708 if ((err = snd_azf3328_mixer_new(chip)) < 0)
1401 return err; 1709 goto out_err;
1402 1710
1403#if 0 1711#if 0
1404 /* set very low bitrate to reduce noise and power consumption? */ 1712 /* set very low bitrate to reduce noise and power consumption? */
@@ -1406,22 +1714,34 @@ static int __devinit snd_azf3328_create(snd_card_t * card,
1406#endif 1714#endif
1407 1715
1408 /* standard chip init stuff */ 1716 /* standard chip init stuff */
1409 spin_lock_irq(&chip->reg_lock); 1717 /* default IRQ init value */
1410 outb(DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port + IDX_IO_PLAY_FLAGS); 1718 tmp = DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE;
1411 outb(DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port + IDX_IO_SOMETHING_FLAGS);
1412 outb(DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port + IDX_IO_REC_FLAGS);
1413 outb(0x0, chip->codec_port + IDX_IO_IRQ63H);
1414 1719
1720 spin_lock_irq(&chip->reg_lock);
1721 snd_azf3328_codec_outb(chip, IDX_IO_PLAY_FLAGS, tmp);
1722 snd_azf3328_codec_outb(chip, IDX_IO_REC_FLAGS, tmp);
1723 snd_azf3328_codec_outb(chip, IDX_IO_SOMETHING_FLAGS, tmp);
1724 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00); /* disable timer */
1415 spin_unlock_irq(&chip->reg_lock); 1725 spin_unlock_irq(&chip->reg_lock);
1416 1726
1417 snd_card_set_dev(card, &pci->dev); 1727 snd_card_set_dev(card, &pci->dev);
1418 1728
1419 *rchip = chip; 1729 *rchip = chip;
1420 return 0; 1730
1731 err = 0;
1732 goto out;
1733
1734out_err:
1735 if (chip)
1736 snd_azf3328_free(chip);
1737 pci_disable_device(pci);
1738
1739out:
1740 return err;
1421} 1741}
1422 1742
1423static int __devinit snd_azf3328_probe(struct pci_dev *pci, 1743static int __devinit
1424 const struct pci_device_id *pci_id) 1744snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1425{ 1745{
1426 static int dev; 1746 static int dev;
1427 snd_card_t *card; 1747 snd_card_t *card;
@@ -1445,63 +1765,70 @@ static int __devinit snd_azf3328_probe(struct pci_dev *pci,
1445 strcpy(card->shortname, "Aztech AZF3328 (PCI168)"); 1765 strcpy(card->shortname, "Aztech AZF3328 (PCI168)");
1446 1766
1447 if ((err = snd_azf3328_create(card, pci, pci_id->driver_data, &chip)) < 0) { 1767 if ((err = snd_azf3328_create(card, pci, pci_id->driver_data, &chip)) < 0) {
1448 snd_card_free(card); 1768 goto out_err;
1449 return err;
1450 } 1769 }
1451 1770
1452 if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_MPU401, 1771 if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_MPU401,
1453 chip->mpu_port, 1, pci->irq, 0, 1772 chip->mpu_port, 1, pci->irq, 0,
1454 &chip->rmidi)) < 0) { 1773 &chip->rmidi)) < 0) {
1455 snd_printk("azf3328: no MPU-401 device at 0x%lx?\n", chip->mpu_port); 1774 snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n", chip->mpu_port);
1456 snd_card_free(card); 1775 goto out_err;
1457 return err; 1776 }
1777
1778 if ((err = snd_azf3328_timer(chip, 0)) < 0) {
1779 goto out_err;
1458 } 1780 }
1459 1781
1460 if ((err = snd_azf3328_pcm(chip, 0)) < 0) { 1782 if ((err = snd_azf3328_pcm(chip, 0)) < 0) {
1461 snd_card_free(card); 1783 goto out_err;
1462 return err;
1463 } 1784 }
1464 1785
1465 if (snd_opl3_create(card, chip->synth_port, chip->synth_port+2, 1786 if (snd_opl3_create(card, chip->synth_port, chip->synth_port+2,
1466 OPL3_HW_AUTO, 1, &opl3) < 0) { 1787 OPL3_HW_AUTO, 1, &opl3) < 0) {
1467 snd_printk("azf3328: no OPL3 device at 0x%lx-0x%lx?\n", 1788 snd_printk(KERN_ERR "azf3328: no OPL3 device at 0x%lx-0x%lx?\n",
1468 chip->synth_port, chip->synth_port+2 ); 1789 chip->synth_port, chip->synth_port+2 );
1469 } else { 1790 } else {
1470 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { 1791 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
1471 snd_card_free(card); 1792 goto out_err;
1472 return err;
1473 } 1793 }
1474 } 1794 }
1475 1795
1476 snd_azf3328_dbgio(chip, "create");
1477
1478 sprintf(card->longname, "%s at 0x%lx, irq %i", 1796 sprintf(card->longname, "%s at 0x%lx, irq %i",
1479 card->shortname, chip->codec_port, chip->irq); 1797 card->shortname, chip->codec_port, chip->irq);
1480 1798
1481 if ((err = snd_card_register(card)) < 0) { 1799 if ((err = snd_card_register(card)) < 0) {
1482 snd_card_free(card); 1800 goto out_err;
1483 return err;
1484 } 1801 }
1485 1802
1486#ifdef MODULE 1803#ifdef MODULE
1487 printk( 1804 printk(
1488"azt3328: Experimental driver for Aztech AZF3328-based soundcards such as PCI168.\n" 1805"azt3328: Sound driver for Aztech AZF3328-based soundcards such as PCI168\n"
1489"azt3328: ZERO support from Aztech: you might think hard about future purchase.\n" 1806"azt3328: (hardware was completely undocumented - ZERO support from Aztech).\n"
1490"azt3328: Feel free to contact hw7oshyuv3001@sneakemail.com for bug reports etc.!\n"); 1807"azt3328: Feel free to contact andi AT lisas.de for bug reports etc.!\n"
1808"azt3328: User-scalable sequencer timer set to %dHz (1024000Hz / %d).\n",
1809 1024000 / seqtimer_scaling, seqtimer_scaling);
1491#endif 1810#endif
1492 1811
1493 if (snd_azf3328_config_joystick(chip, dev) < 0) 1812 if (snd_azf3328_config_joystick(chip, dev) < 0)
1494 snd_azf3328_io2_write(chip, IDX_IO2_LEGACY_ADDR, 1813 snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
1495 snd_azf3328_io2_read(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY); 1814 snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY);
1496 1815
1497 pci_set_drvdata(pci, card); 1816 pci_set_drvdata(pci, card);
1498 dev++; 1817 dev++;
1499 1818
1819 err = 0;
1820 goto out;
1821
1822out_err:
1823 snd_card_free(card);
1824
1825out:
1500 snd_azf3328_dbgcallleave(); 1826 snd_azf3328_dbgcallleave();
1501 return 0; 1827 return err;
1502} 1828}
1503 1829
1504static void __devexit snd_azf3328_remove(struct pci_dev *pci) 1830static void __devexit
1831snd_azf3328_remove(struct pci_dev *pci)
1505{ 1832{
1506 snd_azf3328_dbgcallenter(); 1833 snd_azf3328_dbgcallenter();
1507 snd_card_free(pci_get_drvdata(pci)); 1834 snd_card_free(pci_get_drvdata(pci));
@@ -1517,7 +1844,8 @@ static struct pci_driver driver = {
1517 .remove = __devexit_p(snd_azf3328_remove), 1844 .remove = __devexit_p(snd_azf3328_remove),
1518}; 1845};
1519 1846
1520static int __init alsa_card_azf3328_init(void) 1847static int __init
1848alsa_card_azf3328_init(void)
1521{ 1849{
1522 int err; 1850 int err;
1523 snd_azf3328_dbgcallenter(); 1851 snd_azf3328_dbgcallenter();
@@ -1526,7 +1854,8 @@ static int __init alsa_card_azf3328_init(void)
1526 return err; 1854 return err;
1527} 1855}
1528 1856
1529static void __exit alsa_card_azf3328_exit(void) 1857static void __exit
1858alsa_card_azf3328_exit(void)
1530{ 1859{
1531 snd_azf3328_dbgcallenter(); 1860 snd_azf3328_dbgcallenter();
1532 pci_unregister_driver(&driver); 1861 pci_unregister_driver(&driver);
diff --git a/sound/pci/azt3328.h b/sound/pci/azt3328.h
index 7e0e79180977..f489bdaf6d40 100644
--- a/sound/pci/azt3328.h
+++ b/sound/pci/azt3328.h
@@ -1,19 +1,17 @@
1#ifndef __SOUND_AZF3328_H 1#ifndef __SOUND_AZT3328_H
2#define __SOUND_AZF3328_H 2#define __SOUND_AZT3328_H
3 3
4/* type argument to use for the I/O functions */ 4/* "PU" == "power-up value", as tested on PCI168 PCI rev. 10 */
5#define WORD_VALUE 0x1000
6#define DWORD_VALUE 0x2000
7#define BYTE_VALUE 0x4000
8 5
9/*** main I/O area port indices ***/ 6/*** main I/O area port indices ***/
10/* (only 0x70 of 0x80 bytes saved/restored by Windows driver) */ 7/* (only 0x70 of 0x80 bytes saved/restored by Windows driver) */
11/* the driver initialisation suggests a layout of 3 main areas: 8/* the driver initialisation suggests a layout of 4 main areas:
12 * from 0x00 (playback), from 0x20 (recording) and from 0x40 (maybe DirectX 9 * from 0x00 (playback), from 0x20 (recording) and from 0x40 (maybe MPU401??).
13 * timer ???). and probably another area from 0x60 to 0x6f 10 * And another area from 0x60 to 0x6f (DirectX timer, IRQ management,
14 * (IRQ management, power management etc. ???). */ 11 * power management etc.???). */
15/* playback area */ 12
16#define IDX_IO_PLAY_FLAGS 0x00 13/** playback area **/
14#define IDX_IO_PLAY_FLAGS 0x00 /* PU:0x0000 */
17 /* able to reactivate output after output muting due to 8/16bit 15 /* able to reactivate output after output muting due to 8/16bit
18 * output change, just like 0x0002. 16 * output change, just like 0x0002.
19 * 0x0001 is the only bit that's able to start the DMA counter */ 17 * 0x0001 is the only bit that's able to start the DMA counter */
@@ -29,7 +27,7 @@
29 #define DMA_EPILOGUE_SOMETHING 0x0010 27 #define DMA_EPILOGUE_SOMETHING 0x0010
30 #define DMA_SOMETHING_ELSE 0x0020 /* ??? */ 28 #define DMA_SOMETHING_ELSE 0x0020 /* ??? */
31 #define SOMETHING_UNMODIFIABLE 0xffc0 /* unused ? not modifiable */ 29 #define SOMETHING_UNMODIFIABLE 0xffc0 /* unused ? not modifiable */
32#define IDX_IO_PLAY_IRQMASK 0x02 30#define IDX_IO_PLAY_IRQTYPE 0x02 /* PU:0x0001 */
33 /* write back to flags in case flags are set, in order to ACK IRQ in handler 31 /* write back to flags in case flags are set, in order to ACK IRQ in handler
34 * (bit 1 of port 0x64 indicates interrupt for one of these three types) 32 * (bit 1 of port 0x64 indicates interrupt for one of these three types)
35 * sometimes in this case it just writes 0xffff to globally ACK all IRQs 33 * sometimes in this case it just writes 0xffff to globally ACK all IRQs
@@ -41,36 +39,39 @@
41 #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */ 39 #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */
42 #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */ 40 #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */
43 #define IRQMASK_UNMODIFIABLE 0xffe0 /* unused ? not modifiable */ 41 #define IRQMASK_UNMODIFIABLE 0xffe0 /* unused ? not modifiable */
44#define IDX_IO_PLAY_DMA_START_1 0x04 /* start address of 1st DMA play area */ 42#define IDX_IO_PLAY_DMA_START_1 0x04 /* start address of 1st DMA play area, PU:0x00000000 */
45#define IDX_IO_PLAY_DMA_START_2 0x08 /* start address of 2nd DMA play area */ 43#define IDX_IO_PLAY_DMA_START_2 0x08 /* start address of 2nd DMA play area, PU:0x00000000 */
46#define IDX_IO_PLAY_DMA_LEN_1 0x0c /* length of 1st DMA play area */ 44#define IDX_IO_PLAY_DMA_LEN_1 0x0c /* length of 1st DMA play area, PU:0x0000 */
47#define IDX_IO_PLAY_DMA_LEN_2 0x0e /* length of 2nd DMA play area */ 45#define IDX_IO_PLAY_DMA_LEN_2 0x0e /* length of 2nd DMA play area, PU:0x0000 */
48#define IDX_IO_PLAY_DMA_CURRPOS 0x10 /* current DMA position */ 46#define IDX_IO_PLAY_DMA_CURRPOS 0x10 /* current DMA position, PU:0x00000000 */
49#define IDX_IO_PLAY_DMA_CURROFS 0x14 /* offset within current DMA play area */ 47#define IDX_IO_PLAY_DMA_CURROFS 0x14 /* offset within current DMA play area, PU:0x0000 */
50#define IDX_IO_PLAY_SOUNDFORMAT 0x16 48#define IDX_IO_PLAY_SOUNDFORMAT 0x16 /* PU:0x0010 */
51 /* all unspecified bits can't be modified */ 49 /* all unspecified bits can't be modified */
52 #define SOUNDFORMAT_FREQUENCY_MASK 0x000f 50 #define SOUNDFORMAT_FREQUENCY_MASK 0x000f
51 #define SOUNDFORMAT_XTAL1 0x00
52 #define SOUNDFORMAT_XTAL2 0x01
53 /* all _SUSPECTED_ values are not used by Windows drivers, so we don't 53 /* all _SUSPECTED_ values are not used by Windows drivers, so we don't
54 * have any hard facts, only rough measurements */ 54 * have any hard facts, only rough measurements */
55 #define SOUNDFORMAT_FREQ_SUSPECTED_4000 0x0c 55 #define SOUNDFORMAT_FREQ_SUSPECTED_4000 0x0c | SOUNDFORMAT_XTAL1
56 #define SOUNDFORMAT_FREQ_SUSPECTED_4800 0x0a 56 #define SOUNDFORMAT_FREQ_SUSPECTED_4800 0x0a | SOUNDFORMAT_XTAL1
57 #define SOUNDFORMAT_FREQ_5510 0x0d 57 #define SOUNDFORMAT_FREQ_5510 0x0c | SOUNDFORMAT_XTAL2
58 #define SOUNDFORMAT_FREQ_6620 0x0b 58 #define SOUNDFORMAT_FREQ_6620 0x0a | SOUNDFORMAT_XTAL2
59 #define SOUNDFORMAT_FREQ_8000 0x00 /* also 0x0e ? */ 59 #define SOUNDFORMAT_FREQ_8000 0x00 | SOUNDFORMAT_XTAL1 /* also 0x0e | SOUNDFORMAT_XTAL1? */
60 #define SOUNDFORMAT_FREQ_9600 0x08 60 #define SOUNDFORMAT_FREQ_9600 0x08 | SOUNDFORMAT_XTAL1
61 #define SOUNDFORMAT_FREQ_SUSPECTED_12000 0x09 61 #define SOUNDFORMAT_FREQ_11025 0x00 | SOUNDFORMAT_XTAL2 /* also 0x0e | SOUNDFORMAT_XTAL2? */
62 #define SOUNDFORMAT_FREQ_11025 0x01 /* also 0x0f ? */ 62 #define SOUNDFORMAT_FREQ_SUSPECTED_13240 0x08 | SOUNDFORMAT_XTAL2 /* seems to be 6620 *2 */
63 #define SOUNDFORMAT_FREQ_16000 0x02 63 #define SOUNDFORMAT_FREQ_16000 0x02 | SOUNDFORMAT_XTAL1
64 #define SOUNDFORMAT_FREQ_22050 0x03 64 #define SOUNDFORMAT_FREQ_22050 0x02 | SOUNDFORMAT_XTAL2
65 #define SOUNDFORMAT_FREQ_32000 0x04 65 #define SOUNDFORMAT_FREQ_32000 0x04 | SOUNDFORMAT_XTAL1
66 #define SOUNDFORMAT_FREQ_44100 0x05 66 #define SOUNDFORMAT_FREQ_44100 0x04 | SOUNDFORMAT_XTAL2
67 #define SOUNDFORMAT_FREQ_48000 0x06 67 #define SOUNDFORMAT_FREQ_48000 0x06 | SOUNDFORMAT_XTAL1
68 #define SOUNDFORMAT_FREQ_SUSPECTED_64000 0x07 68 #define SOUNDFORMAT_FREQ_SUSPECTED_66200 0x06 | SOUNDFORMAT_XTAL2 /* 66200 (13240 * 5); 64000 may have been nicer :-\ */
69 #define SOUNDFORMAT_FLAG_16BIT 0x0010 69 #define SOUNDFORMAT_FLAG_16BIT 0x0010
70 #define SOUNDFORMAT_FLAG_2CHANNELS 0x0020 70 #define SOUNDFORMAT_FLAG_2CHANNELS 0x0020
71/* recording area (see also: playback bit flag definitions) */ 71
72#define IDX_IO_REC_FLAGS 0x20 /* ?? */ 72/** recording area (see also: playback bit flag definitions) **/
73#define IDX_IO_REC_IRQMASK 0x22 /* ?? */ 73#define IDX_IO_REC_FLAGS 0x20 /* ??, PU:0x0000 */
74#define IDX_IO_REC_IRQTYPE 0x22 /* ??, PU:0x0000 */
74 #define IRQ_REC_SOMETHING 0x0001 /* something & ACK */ 75 #define IRQ_REC_SOMETHING 0x0001 /* something & ACK */
75 #define IRQ_FINISHED_RECBUF_1 0x0002 /* 1st dmabuf finished & ACK */ 76 #define IRQ_FINISHED_RECBUF_1 0x0002 /* 1st dmabuf finished & ACK */
76 #define IRQ_FINISHED_RECBUF_2 0x0004 /* 2nd dmabuf finished & ACK */ 77 #define IRQ_FINISHED_RECBUF_2 0x0004 /* 2nd dmabuf finished & ACK */
@@ -78,39 +79,47 @@
78 * but OTOH they are most likely at port 0x22 instead */ 79 * but OTOH they are most likely at port 0x22 instead */
79 #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */ 80 #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */
80 #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */ 81 #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */
81#define IDX_IO_REC_DMA_START_1 0x24 82#define IDX_IO_REC_DMA_START_1 0x24 /* PU:0x00000000 */
82#define IDX_IO_REC_DMA_START_2 0x28 83#define IDX_IO_REC_DMA_START_2 0x28 /* PU:0x00000000 */
83#define IDX_IO_REC_DMA_LEN_1 0x2c 84#define IDX_IO_REC_DMA_LEN_1 0x2c /* PU:0x0000 */
84#define IDX_IO_REC_DMA_LEN_2 0x2e 85#define IDX_IO_REC_DMA_LEN_2 0x2e /* PU:0x0000 */
85#define IDX_IO_REC_DMA_CURRPOS 0x30 86#define IDX_IO_REC_DMA_CURRPOS 0x30 /* PU:0x00000000 */
86#define IDX_IO_REC_DMA_CURROFS 0x34 87#define IDX_IO_REC_DMA_CURROFS 0x34 /* PU:0x00000000 */
87#define IDX_IO_REC_SOUNDFORMAT 0x36 88#define IDX_IO_REC_SOUNDFORMAT 0x36 /* PU:0x0000 */
88/* some third area ? (after playback and recording) */ 89
89#define IDX_IO_SOMETHING_FLAGS 0x40 /* gets set to 0x34 just like port 0x0 and 0x20 on card init */ 90/** hmm, what is this I/O area for? MPU401?? (after playback, recording, ???, timer) **/
91#define IDX_IO_SOMETHING_FLAGS 0x40 /* gets set to 0x34 just like port 0x0 and 0x20 on card init, PU:0x0000 */
90/* general */ 92/* general */
91#define IDX_IO_60H 0x60 /* writing 0xffff returns 0xffff */ 93#define IDX_IO_42H 0x42 /* PU:0x0001 */
92#define IDX_IO_62H 0x62 /* writing to WORD 0x0062 can hang the box ! --> responsible for IRQ management as a whole ?? */ 94
93#define IDX_IO_IRQ63H 0x63 /* FIXME !! */ 95/** DirectX timer, main interrupt area (FIXME: and something else?) **/
94 #define IO_IRQ63H_SOMETHING 0x04 /* being set in IRQ handler in case port 0x00 had 0x0020 set upon IRQ handler */ 96#define IDX_IO_TIMER_VALUE 0x60 /* found this timer area by pure luck :-) */
97 #define TIMER_VALUE_MASK 0x000fffffUL /* timer countdown value; triggers IRQ when timer is finished */
98 #define TIMER_ENABLE_COUNTDOWN 0x01000000UL /* activate the timer countdown */
99 #define TIMER_ENABLE_IRQ 0x02000000UL /* trigger timer IRQ on zero transition */
100 #define TIMER_ACK_IRQ 0x04000000UL /* being set in IRQ handler in case port 0x00 (hmm, not port 0x64!?!?) had 0x0020 set upon IRQ handler */
95#define IDX_IO_IRQSTATUS 0x64 101#define IDX_IO_IRQSTATUS 0x64
96 #define IRQ_PLAYBACK 0x0001 102 #define IRQ_PLAYBACK 0x0001
97 #define IRQ_RECORDING 0x0002 103 #define IRQ_RECORDING 0x0002
98 #define IRQ_MPU401 0x0010 104 #define IRQ_MPU401 0x0010
99 #define IRQ_SOMEIRQ 0x0020 /* ???? */ 105 #define IRQ_TIMER 0x0020 /* DirectX timer */
100 #define IRQ_WHO_KNOWS_UNUSED 0x00e0 /* probably unused */ 106 #define IRQ_UNKNOWN1 0x0040 /* probably unused */
107 #define IRQ_UNKNOWN2 0x0080 /* probably unused */
101#define IDX_IO_66H 0x66 /* writing 0xffff returns 0x0000 */ 108#define IDX_IO_66H 0x66 /* writing 0xffff returns 0x0000 */
102#define IDX_IO_SOME_VALUE 0x68 /* this is always set to 0x3ff, and writable; maybe some buffer limit, but I couldn't find out more */ 109#define IDX_IO_SOME_VALUE 0x68 /* this is set to e.g. 0x3ff or 0x300, and writable; maybe some buffer limit, but I couldn't find out more, PU:0x00ff */
103#define IDX_IO_6AH 0x6A /* this WORD can be set to have bits 0x0028 activated; actually inhibits PCM playback !!! maybe power management ?? */ 110#define IDX_IO_6AH 0x6A /* this WORD can be set to have bits 0x0028 activated; actually inhibits PCM playback!!! maybe power management?? */
104#define IDX_IO_6CH 0x6C /* this WORD can have all its bits activated ? */ 111#define IDX_IO_6CH 0x6C
105#define IDX_IO_6EH 0x6E /* writing 0xffff returns 0x83fe */ 112#define IDX_IO_6EH 0x6E /* writing 0xffff returns 0x83fe */
106/* further I/O indices not saved/restored, so probably not used */ 113/* further I/O indices not saved/restored, so probably not used */
107 114
115
108/*** I/O 2 area port indices ***/ 116/*** I/O 2 area port indices ***/
109/* (only 0x06 of 0x08 bytes saved/restored by Windows driver) */ 117/* (only 0x06 of 0x08 bytes saved/restored by Windows driver) */
110#define IDX_IO2_LEGACY_ADDR 0x04 118#define IDX_IO2_LEGACY_ADDR 0x04
111 #define LEGACY_SOMETHING 0x01 /* OPL3 ?? */ 119 #define LEGACY_SOMETHING 0x01 /* OPL3?? */
112 #define LEGACY_JOY 0x08 120 #define LEGACY_JOY 0x08
113 121
122
114/*** mixer I/O area port indices ***/ 123/*** mixer I/O area port indices ***/
115/* (only 0x22 of 0x40 bytes saved/restored by Windows driver) 124/* (only 0x22 of 0x40 bytes saved/restored by Windows driver)
116 * generally spoken: AC97 register index = AZF3328 mixer reg index + 2 125 * generally spoken: AC97 register index = AZF3328 mixer reg index + 2
@@ -148,18 +157,18 @@
148 /* unlisted bits are unmodifiable */ 157 /* unlisted bits are unmodifiable */
149 #define MIXER_ADVCTL1_3DWIDTH_MASK 0x000e 158 #define MIXER_ADVCTL1_3DWIDTH_MASK 0x000e
150 #define MIXER_ADVCTL1_HIFI3D_MASK 0x0300 159 #define MIXER_ADVCTL1_HIFI3D_MASK 0x0300
151#define IDX_MIXER_ADVCTL2 0x20 /* resembles AC97_GENERAL_PURPOSE reg ! */ 160#define IDX_MIXER_ADVCTL2 0x20 /* resembles AC97_GENERAL_PURPOSE reg! */
152 /* unlisted bits are unmodifiable */ 161 /* unlisted bits are unmodifiable */
153 #define MIXER_ADVCTL2_BIT7 0x0080 /* WaveOut 3D Bypass ? mutes WaveOut at LineOut */ 162 #define MIXER_ADVCTL2_BIT7 0x0080 /* WaveOut 3D Bypass? mutes WaveOut at LineOut */
154 #define MIXER_ADVCTL2_BIT8 0x0100 /* is this Modem Out Select ? */ 163 #define MIXER_ADVCTL2_BIT8 0x0100 /* is this Modem Out Select? */
155 #define MIXER_ADVCTL2_BIT9 0x0200 /* Mono Select Source ? */ 164 #define MIXER_ADVCTL2_BIT9 0x0200 /* Mono Select Source? */
156 #define MIXER_ADVCTL2_BIT13 0x2000 /* 3D enable ? */ 165 #define MIXER_ADVCTL2_BIT13 0x2000 /* 3D enable? */
157 #define MIXER_ADVCTL2_BIT15 0x8000 /* unknown */ 166 #define MIXER_ADVCTL2_BIT15 0x8000 /* unknown */
158 167
159#define IDX_MIXER_SOMETHING30H 0x30 /* used, but unknown ??? */ 168#define IDX_MIXER_SOMETHING30H 0x30 /* used, but unknown??? */
160 169
161/* driver internal flags */ 170/* driver internal flags */
162#define SET_CHAN_LEFT 1 171#define SET_CHAN_LEFT 1
163#define SET_CHAN_RIGHT 2 172#define SET_CHAN_RIGHT 2
164 173
165#endif /* __SOUND_AZF3328_H */ 174#endif /* __SOUND_AZT3328_H */
diff --git a/sound/pci/ca0106/Makefile b/sound/pci/ca0106/Makefile
index 89c6ceee21f3..dcbae7b31546 100644
--- a/sound/pci/ca0106/Makefile
+++ b/sound/pci/ca0106/Makefile
@@ -1,3 +1,3 @@
1snd-ca0106-objs := ca0106_main.o ca0106_proc.o ca0106_mixer.o 1snd-ca0106-objs := ca0106_main.o ca0106_proc.o ca0106_mixer.o ca_midi.o
2 2
3obj-$(CONFIG_SND_CA0106) += snd-ca0106.o 3obj-$(CONFIG_SND_CA0106) += snd-ca0106.o
diff --git a/sound/pci/ca0106/ca0106.h b/sound/pci/ca0106/ca0106.h
index da09cab405a9..9a4b6406f7a5 100644
--- a/sound/pci/ca0106/ca0106.h
+++ b/sound/pci/ca0106/ca0106.h
@@ -399,10 +399,24 @@
399#define PLAYBACK_VOLUME2 0x6a /* Playback Analog volume per channel. Does not effect AC3 output */ 399#define PLAYBACK_VOLUME2 0x6a /* Playback Analog volume per channel. Does not effect AC3 output */
400 /* Similar to register 0x66, except that the destination is the I2S mixer instead of the SPDIF mixer. I.E. Outputs to the Analog outputs instead of SPDIF. */ 400 /* Similar to register 0x66, except that the destination is the I2S mixer instead of the SPDIF mixer. I.E. Outputs to the Analog outputs instead of SPDIF. */
401#define UNKNOWN6b 0x6b /* Unknown. Readonly. Default 00400000 00400000 00400000 00400000 */ 401#define UNKNOWN6b 0x6b /* Unknown. Readonly. Default 00400000 00400000 00400000 00400000 */
402#define UART_A_DATA 0x6c /* Uart, used in setting sample rates, bits per sample etc. */ 402#define MIDI_UART_A_DATA 0x6c /* Midi Uart A Data */
403#define UART_A_CMD 0x6d /* Uart, used in setting sample rates, bits per sample etc. */ 403#define MIDI_UART_A_CMD 0x6d /* Midi Uart A Command/Status */
404#define UART_B_DATA 0x6e /* Uart, Unknown. */ 404#define MIDI_UART_B_DATA 0x6e /* Midi Uart B Data (currently unused) */
405#define UART_B_CMD 0x6f /* Uart, Unknown. */ 405#define MIDI_UART_B_CMD 0x6f /* Midi Uart B Command/Status (currently unused) */
406
407/* unique channel identifier for midi->channel */
408
409#define CA0106_MIDI_CHAN_A 0x1
410#define CA0106_MIDI_CHAN_B 0x2
411
412/* from mpu401 */
413
414#define CA0106_MIDI_INPUT_AVAIL 0x80
415#define CA0106_MIDI_OUTPUT_READY 0x40
416#define CA0106_MPU401_RESET 0xff
417#define CA0106_MPU401_ENTER_UART 0x3f
418#define CA0106_MPU401_ACK 0xfe
419
406#define SAMPLE_RATE_TRACKER_STATUS 0x70 /* Readonly. Default 00108000 00108000 00500000 00500000 */ 420#define SAMPLE_RATE_TRACKER_STATUS 0x70 /* Readonly. Default 00108000 00108000 00500000 00500000 */
407 /* Estimated sample rate [19:0] Relative to 48kHz. 0x8000 = 1.0 421 /* Estimated sample rate [19:0] Relative to 48kHz. 0x8000 = 1.0
408 * Rate Locked [20] 422 * Rate Locked [20]
@@ -538,6 +552,8 @@
538#define CONTROL_CENTER_LFE_CHANNEL 1 552#define CONTROL_CENTER_LFE_CHANNEL 1
539#define CONTROL_UNKNOWN_CHANNEL 2 553#define CONTROL_UNKNOWN_CHANNEL 2
540 554
555#include "ca_midi.h"
556
541typedef struct snd_ca0106_channel ca0106_channel_t; 557typedef struct snd_ca0106_channel ca0106_channel_t;
542typedef struct snd_ca0106 ca0106_t; 558typedef struct snd_ca0106 ca0106_t;
543typedef struct snd_ca0106_pcm ca0106_pcm_t; 559typedef struct snd_ca0106_pcm ca0106_pcm_t;
@@ -592,6 +608,9 @@ struct snd_ca0106 {
592 int capture_mic_line_in; 608 int capture_mic_line_in;
593 609
594 struct snd_dma_buffer buffer; 610 struct snd_dma_buffer buffer;
611
612 ca_midi_t midi;
613 ca_midi_t midi2;
595}; 614};
596 615
597int __devinit snd_ca0106_mixer(ca0106_t *emu); 616int __devinit snd_ca0106_mixer(ca0106_t *emu);
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index ba07960921d8..ee58d16002e5 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -281,7 +281,7 @@ int snd_ca0106_i2c_write(ca0106_t *emu,
281 int retry; 281 int retry;
282 if ((reg > 0x7f) || (value > 0x1ff)) 282 if ((reg > 0x7f) || (value > 0x1ff))
283 { 283 {
284 snd_printk("i2c_write: invalid values.\n"); 284 snd_printk(KERN_ERR "i2c_write: invalid values.\n");
285 return -EINVAL; 285 return -EINVAL;
286 } 286 }
287 287
@@ -319,7 +319,7 @@ int snd_ca0106_i2c_write(ca0106_t *emu,
319 319
320 if(retry==10) 320 if(retry==10)
321 { 321 {
322 snd_printk("Writing to ADC failed!\n"); 322 snd_printk(KERN_ERR "Writing to ADC failed!\n");
323 return -EINVAL; 323 return -EINVAL;
324 } 324 }
325 325
@@ -338,6 +338,18 @@ static void snd_ca0106_intr_enable(ca0106_t *emu, unsigned int intrenb)
338 spin_unlock_irqrestore(&emu->emu_lock, flags); 338 spin_unlock_irqrestore(&emu->emu_lock, flags);
339} 339}
340 340
341static void snd_ca0106_intr_disable(ca0106_t *emu, unsigned int intrenb)
342{
343 unsigned long flags;
344 unsigned int enable;
345
346 spin_lock_irqsave(&emu->emu_lock, flags);
347 enable = inl(emu->port + INTE) & ~intrenb;
348 outl(enable, emu->port + INTE);
349 spin_unlock_irqrestore(&emu->emu_lock, flags);
350}
351
352
341static void snd_ca0106_pcm_free_substream(snd_pcm_runtime_t *runtime) 353static void snd_ca0106_pcm_free_substream(snd_pcm_runtime_t *runtime)
342{ 354{
343 kfree(runtime->private_data); 355 kfree(runtime->private_data);
@@ -421,7 +433,7 @@ static int snd_ca0106_pcm_open_capture_channel(snd_pcm_substream_t *substream, i
421 433
422 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); 434 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
423 if (epcm == NULL) { 435 if (epcm == NULL) {
424 snd_printk("open_capture_channel: failed epcm alloc\n"); 436 snd_printk(KERN_ERR "open_capture_channel: failed epcm alloc\n");
425 return -ENOMEM; 437 return -ENOMEM;
426 } 438 }
427 epcm->emu = chip; 439 epcm->emu = chip;
@@ -969,10 +981,8 @@ static int snd_ca0106_free(ca0106_t *chip)
969#endif 981#endif
970 982
971 // release the i/o port 983 // release the i/o port
972 if (chip->res_port) { 984 release_and_free_resource(chip->res_port);
973 release_resource(chip->res_port); 985
974 kfree_nocheck(chip->res_port);
975 }
976 // release the irq 986 // release the irq
977 if (chip->irq >= 0) 987 if (chip->irq >= 0)
978 free_irq(chip->irq, (void *)chip); 988 free_irq(chip->irq, (void *)chip);
@@ -1042,6 +1052,15 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
1042 1052
1043 snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76); 1053 snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76);
1044 spin_lock(&chip->emu_lock); 1054 spin_lock(&chip->emu_lock);
1055
1056 if (chip->midi.dev_id &&
1057 (status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) {
1058 if (chip->midi.interrupt)
1059 chip->midi.interrupt(&chip->midi, status);
1060 else
1061 chip->midi.interrupt_disable(&chip->midi, chip->midi.tx_enable | chip->midi.rx_enable);
1062 }
1063
1045 // acknowledge the interrupt if necessary 1064 // acknowledge the interrupt if necessary
1046 outl(status, chip->port+IPR); 1065 outl(status, chip->port+IPR);
1047 1066
@@ -1311,6 +1330,88 @@ static int __devinit snd_ca0106_create(snd_card_t *card,
1311 return 0; 1330 return 0;
1312} 1331}
1313 1332
1333
1334static void ca0106_midi_interrupt_enable(ca_midi_t *midi, int intr)
1335{
1336 snd_ca0106_intr_enable((ca0106_t *)(midi->dev_id), intr);
1337}
1338
1339static void ca0106_midi_interrupt_disable(ca_midi_t *midi, int intr)
1340{
1341 snd_ca0106_intr_disable((ca0106_t *)(midi->dev_id), intr);
1342}
1343
1344static unsigned char ca0106_midi_read(ca_midi_t *midi, int idx)
1345{
1346 return (unsigned char)snd_ca0106_ptr_read((ca0106_t *)(midi->dev_id), midi->port + idx, 0);
1347}
1348
1349static void ca0106_midi_write(ca_midi_t *midi, int data, int idx)
1350{
1351 snd_ca0106_ptr_write((ca0106_t *)(midi->dev_id), midi->port + idx, 0, data);
1352}
1353
1354static snd_card_t *ca0106_dev_id_card(void *dev_id)
1355{
1356 return ((ca0106_t *)dev_id)->card;
1357}
1358
1359static int ca0106_dev_id_port(void *dev_id)
1360{
1361 return ((ca0106_t *)dev_id)->port;
1362}
1363
1364static int __devinit snd_ca0106_midi(ca0106_t *chip, unsigned int channel)
1365{
1366 ca_midi_t *midi;
1367 char *name;
1368 int err;
1369
1370 if(channel==CA0106_MIDI_CHAN_B) {
1371 name = "CA0106 MPU-401 (UART) B";
1372 midi = &chip->midi2;
1373 midi->tx_enable = INTE_MIDI_TX_B;
1374 midi->rx_enable = INTE_MIDI_RX_B;
1375 midi->ipr_tx = IPR_MIDI_TX_B;
1376 midi->ipr_rx = IPR_MIDI_RX_B;
1377 midi->port = MIDI_UART_B_DATA;
1378 } else {
1379 name = "CA0106 MPU-401 (UART)";
1380 midi = &chip->midi;
1381 midi->tx_enable = INTE_MIDI_TX_A;
1382 midi->rx_enable = INTE_MIDI_TX_B;
1383 midi->ipr_tx = IPR_MIDI_TX_A;
1384 midi->ipr_rx = IPR_MIDI_RX_A;
1385 midi->port = MIDI_UART_A_DATA;
1386 }
1387
1388 midi->reset = CA0106_MPU401_RESET;
1389 midi->enter_uart = CA0106_MPU401_ENTER_UART;
1390 midi->ack = CA0106_MPU401_ACK;
1391
1392 midi->input_avail = CA0106_MIDI_INPUT_AVAIL;
1393 midi->output_ready = CA0106_MIDI_OUTPUT_READY;
1394
1395 midi->channel = channel;
1396
1397 midi->interrupt_enable = ca0106_midi_interrupt_enable;
1398 midi->interrupt_disable = ca0106_midi_interrupt_disable;
1399
1400 midi->read = ca0106_midi_read;
1401 midi->write = ca0106_midi_write;
1402
1403 midi->get_dev_id_card = ca0106_dev_id_card;
1404 midi->get_dev_id_port = ca0106_dev_id_port;
1405
1406 midi->dev_id = chip;
1407
1408 if ((err = ca_midi_init(chip, midi, 0, name)) < 0)
1409 return err;
1410
1411 return 0;
1412}
1413
1414
1314static int __devinit snd_ca0106_probe(struct pci_dev *pci, 1415static int __devinit snd_ca0106_probe(struct pci_dev *pci,
1315 const struct pci_device_id *pci_id) 1416 const struct pci_device_id *pci_id)
1316{ 1417{
@@ -1362,6 +1463,14 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci,
1362 return err; 1463 return err;
1363 } 1464 }
1364 1465
1466 snd_printdd("ca0106: probe for MIDI channel A ...");
1467 if ((err = snd_ca0106_midi(chip,CA0106_MIDI_CHAN_A)) < 0) {
1468 snd_card_free(card);
1469 snd_printdd(" failed, err=0x%x\n",err);
1470 return err;
1471 }
1472 snd_printdd(" done.\n");
1473
1365 snd_ca0106_proc_init(chip); 1474 snd_ca0106_proc_init(chip);
1366 1475
1367 if ((err = snd_card_register(card)) < 0) { 1476 if ((err = snd_card_register(card)) < 0) {
diff --git a/sound/pci/ca0106/ca_midi.c b/sound/pci/ca0106/ca_midi.c
new file mode 100644
index 000000000000..2e08b27b8349
--- /dev/null
+++ b/sound/pci/ca0106/ca_midi.c
@@ -0,0 +1,306 @@
1/*
2 * Copyright 10/16/2005 Tilman Kranz <tilde@tk-sls.de>
3 * Creative Audio MIDI, for the CA0106 Driver
4 * Version: 0.0.1
5 *
6 * Changelog:
7 * Implementation is based on mpu401 and emu10k1x and
8 * tested with ca0106.
9 * mpu401: Copyright (c) by Jaroslav Kysela <perex@suse.cz>
10 * emu10k1x: Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 *
27 */
28
29#include <linux/spinlock.h>
30#include <sound/driver.h>
31#include <sound/core.h>
32#include <sound/rawmidi.h>
33
34#include "ca_midi.h"
35
36#define ca_midi_write_data(midi, data) midi->write(midi, data, 0)
37#define ca_midi_write_cmd(midi, data) midi->write(midi, data, 1)
38#define ca_midi_read_data(midi) midi->read(midi, 0)
39#define ca_midi_read_stat(midi) midi->read(midi, 1)
40#define ca_midi_input_avail(midi) (!(ca_midi_read_stat(midi) & midi->input_avail))
41#define ca_midi_output_ready(midi) (!(ca_midi_read_stat(midi) & midi->output_ready))
42
43static void ca_midi_clear_rx(ca_midi_t *midi)
44{
45 int timeout = 100000;
46 for (; timeout > 0 && ca_midi_input_avail(midi); timeout--)
47 ca_midi_read_data(midi);
48#ifdef CONFIG_SND_DEBUG
49 if (timeout <= 0)
50 snd_printk(KERN_ERR "ca_midi_clear_rx: timeout (status = 0x%x)\n", ca_midi_read_stat(midi));
51#endif
52}
53
54static void ca_midi_interrupt(ca_midi_t *midi, unsigned int status) {
55 unsigned char byte;
56
57 if (midi->rmidi == NULL) {
58 midi->interrupt_disable(midi,midi->tx_enable | midi->rx_enable);
59 return;
60 }
61
62 spin_lock(&midi->input_lock);
63 if ((status & midi->ipr_rx) && ca_midi_input_avail(midi)) {
64 if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) {
65 ca_midi_clear_rx(midi);
66 } else {
67 byte = ca_midi_read_data(midi);
68 if(midi->substream_input)
69 snd_rawmidi_receive(midi->substream_input, &byte, 1);
70
71
72 }
73 }
74 spin_unlock(&midi->input_lock);
75
76 spin_lock(&midi->output_lock);
77 if ((status & midi->ipr_tx) && ca_midi_output_ready(midi)) {
78 if (midi->substream_output &&
79 snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) {
80 ca_midi_write_data(midi, byte);
81 } else {
82 midi->interrupt_disable(midi,midi->tx_enable);
83 }
84 }
85 spin_unlock(&midi->output_lock);
86
87}
88
89static void ca_midi_cmd(ca_midi_t *midi, unsigned char cmd, int ack)
90{
91 unsigned long flags;
92 int timeout, ok;
93
94 spin_lock_irqsave(&midi->input_lock, flags);
95 ca_midi_write_data(midi, 0x00);
96 /* ca_midi_clear_rx(midi); */
97
98 ca_midi_write_cmd(midi, cmd);
99 if (ack) {
100 ok = 0;
101 timeout = 10000;
102 while (!ok && timeout-- > 0) {
103 if (ca_midi_input_avail(midi)) {
104 if (ca_midi_read_data(midi) == midi->ack)
105 ok = 1;
106 }
107 }
108 if (!ok && ca_midi_read_data(midi) == midi->ack)
109 ok = 1;
110 } else {
111 ok = 1;
112 }
113 spin_unlock_irqrestore(&midi->input_lock, flags);
114 if (!ok)
115 snd_printk(KERN_ERR "ca_midi_cmd: 0x%x failed at 0x%x (status = 0x%x, data = 0x%x)!!!\n",
116 cmd,
117 midi->get_dev_id_port(midi->dev_id),
118 ca_midi_read_stat(midi),
119 ca_midi_read_data(midi));
120}
121
122static int ca_midi_input_open(snd_rawmidi_substream_t * substream)
123{
124 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
125 unsigned long flags;
126
127 snd_assert(midi->dev_id, return -ENXIO);
128 spin_lock_irqsave(&midi->open_lock, flags);
129 midi->midi_mode |= CA_MIDI_MODE_INPUT;
130 midi->substream_input = substream;
131 if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT)) {
132 spin_unlock_irqrestore(&midi->open_lock, flags);
133 ca_midi_cmd(midi, midi->reset, 1);
134 ca_midi_cmd(midi, midi->enter_uart, 1);
135 } else {
136 spin_unlock_irqrestore(&midi->open_lock, flags);
137 }
138 return 0;
139}
140
141static int ca_midi_output_open(snd_rawmidi_substream_t * substream)
142{
143 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
144 unsigned long flags;
145
146 snd_assert(midi->dev_id, return -ENXIO);
147 spin_lock_irqsave(&midi->open_lock, flags);
148 midi->midi_mode |= CA_MIDI_MODE_OUTPUT;
149 midi->substream_output = substream;
150 if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) {
151 spin_unlock_irqrestore(&midi->open_lock, flags);
152 ca_midi_cmd(midi, midi->reset, 1);
153 ca_midi_cmd(midi, midi->enter_uart, 1);
154 } else {
155 spin_unlock_irqrestore(&midi->open_lock, flags);
156 }
157 return 0;
158}
159
160static int ca_midi_input_close(snd_rawmidi_substream_t * substream)
161{
162 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
163 unsigned long flags;
164
165 snd_assert(midi->dev_id, return -ENXIO);
166 spin_lock_irqsave(&midi->open_lock, flags);
167 midi->interrupt_disable(midi,midi->rx_enable);
168 midi->midi_mode &= ~CA_MIDI_MODE_INPUT;
169 midi->substream_input = NULL;
170 if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT)) {
171 spin_unlock_irqrestore(&midi->open_lock, flags);
172 ca_midi_cmd(midi, midi->reset, 0);
173 } else {
174 spin_unlock_irqrestore(&midi->open_lock, flags);
175 }
176 return 0;
177}
178
179static int ca_midi_output_close(snd_rawmidi_substream_t * substream)
180{
181 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
182 unsigned long flags;
183 snd_assert(midi->dev_id, return -ENXIO);
184
185 spin_lock_irqsave(&midi->open_lock, flags);
186
187 midi->interrupt_disable(midi,midi->tx_enable);
188 midi->midi_mode &= ~CA_MIDI_MODE_OUTPUT;
189 midi->substream_output = NULL;
190
191 if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) {
192 spin_unlock_irqrestore(&midi->open_lock, flags);
193 ca_midi_cmd(midi, midi->reset, 0);
194 } else {
195 spin_unlock_irqrestore(&midi->open_lock, flags);
196 }
197 return 0;
198}
199
200static void ca_midi_input_trigger(snd_rawmidi_substream_t * substream, int up)
201{
202 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
203 snd_assert(midi->dev_id, return);
204
205 if (up) {
206 midi->interrupt_enable(midi,midi->rx_enable);
207 } else {
208 midi->interrupt_disable(midi, midi->rx_enable);
209 }
210}
211
212static void ca_midi_output_trigger(snd_rawmidi_substream_t * substream, int up)
213{
214 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
215 unsigned long flags;
216
217 snd_assert(midi->dev_id, return);
218
219 if (up) {
220 int max = 4;
221 unsigned char byte;
222
223 spin_lock_irqsave(&midi->output_lock, flags);
224
225 /* try to send some amount of bytes here before interrupts */
226 while (max > 0) {
227 if (ca_midi_output_ready(midi)) {
228 if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT) ||
229 snd_rawmidi_transmit(substream, &byte, 1) != 1) {
230 /* no more data */
231 spin_unlock_irqrestore(&midi->output_lock, flags);
232 return;
233 }
234 ca_midi_write_data(midi, byte);
235 max--;
236 } else {
237 break;
238 }
239 }
240
241 spin_unlock_irqrestore(&midi->output_lock, flags);
242 midi->interrupt_enable(midi,midi->tx_enable);
243
244 } else {
245 midi->interrupt_disable(midi,midi->tx_enable);
246 }
247}
248
249static snd_rawmidi_ops_t ca_midi_output =
250{
251 .open = ca_midi_output_open,
252 .close = ca_midi_output_close,
253 .trigger = ca_midi_output_trigger,
254};
255
256static snd_rawmidi_ops_t ca_midi_input =
257{
258 .open = ca_midi_input_open,
259 .close = ca_midi_input_close,
260 .trigger = ca_midi_input_trigger,
261};
262
263static void ca_midi_free(ca_midi_t *midi) {
264 midi->interrupt = NULL;
265 midi->interrupt_enable = NULL;
266 midi->interrupt_disable = NULL;
267 midi->read = NULL;
268 midi->write = NULL;
269 midi->get_dev_id_card = NULL;
270 midi->get_dev_id_port = NULL;
271 midi->rmidi = NULL;
272}
273
274static void ca_rmidi_free(snd_rawmidi_t *rmidi)
275{
276 ca_midi_free((ca_midi_t *)rmidi->private_data);
277}
278
279int __devinit ca_midi_init(void *dev_id, ca_midi_t *midi, int device, char *name)
280{
281 snd_rawmidi_t *rmidi;
282 int err;
283
284 if ((err = snd_rawmidi_new(midi->get_dev_id_card(midi->dev_id), name, device, 1, 1, &rmidi)) < 0)
285 return err;
286
287 midi->dev_id = dev_id;
288 midi->interrupt = ca_midi_interrupt;
289
290 spin_lock_init(&midi->open_lock);
291 spin_lock_init(&midi->input_lock);
292 spin_lock_init(&midi->output_lock);
293
294 strcpy(rmidi->name, name);
295 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &ca_midi_output);
296 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &ca_midi_input);
297 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
298 SNDRV_RAWMIDI_INFO_INPUT |
299 SNDRV_RAWMIDI_INFO_DUPLEX;
300 rmidi->private_data = midi;
301 rmidi->private_free = ca_rmidi_free;
302
303 midi->rmidi = rmidi;
304 return 0;
305}
306
diff --git a/sound/pci/ca0106/ca_midi.h b/sound/pci/ca0106/ca_midi.h
new file mode 100644
index 000000000000..b452cec2bf57
--- /dev/null
+++ b/sound/pci/ca0106/ca_midi.h
@@ -0,0 +1,69 @@
1/*
2 * Copyright 10/16/2005 Tilman Kranz <tilde@tk-sls.de>
3 * Creative Audio MIDI, for the CA0106 Driver
4 * Version: 0.0.1
5 *
6 * Changelog:
7 * See ca_midi.c
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include<linux/spinlock.h>
26#include<sound/rawmidi.h>
27#include<sound/mpu401.h>
28
29#define CA_MIDI_MODE_INPUT MPU401_MODE_INPUT
30#define CA_MIDI_MODE_OUTPUT MPU401_MODE_OUTPUT
31
32typedef struct ca_midi ca_midi_t;
33struct ca_midi {
34
35 snd_rawmidi_t *rmidi;
36 snd_rawmidi_substream_t *substream_input;
37 snd_rawmidi_substream_t *substream_output;
38
39 void *dev_id;
40
41 spinlock_t input_lock;
42 spinlock_t output_lock;
43 spinlock_t open_lock;
44
45 unsigned int channel;
46
47 unsigned int midi_mode;
48 int port;
49 int tx_enable, rx_enable;
50 int ipr_tx, ipr_rx;
51
52 int input_avail, output_ready;
53 int ack, reset, enter_uart;
54
55 void (*interrupt)(ca_midi_t *midi, unsigned int status);
56 void (*interrupt_enable)(ca_midi_t *midi, int intr);
57 void (*interrupt_disable)(ca_midi_t *midi, int intr);
58
59 unsigned char (*read)(ca_midi_t *midi, int idx);
60 void (*write)(ca_midi_t *midi, int data, int idx);
61
62 /* get info from dev_id */
63 snd_card_t *(*get_dev_id_card)(void *dev_id);
64 int (*get_dev_id_port)(void *dev_id);
65};
66
67int __devinit ca_midi_init(void *card, ca_midi_t *midi, int device, char *name);
68
69
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 1eb3315d136d..57e8e433d56f 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -446,9 +446,6 @@ struct snd_stru_cmipci {
446 snd_kcontrol_t *mixer_res_ctl[CM_SAVED_MIXERS]; 446 snd_kcontrol_t *mixer_res_ctl[CM_SAVED_MIXERS];
447 int mixer_res_status[CM_SAVED_MIXERS]; 447 int mixer_res_status[CM_SAVED_MIXERS];
448 448
449 opl3_t *opl3;
450 snd_hwdep_t *opl3hwdep;
451
452 cmipci_pcm_t channel[2]; /* ch0 - DAC, ch1 - ADC or 2nd DAC */ 449 cmipci_pcm_t channel[2]; /* ch0 - DAC, ch1 - ADC or 2nd DAC */
453 450
454 /* external MIDI */ 451 /* external MIDI */
@@ -2686,8 +2683,7 @@ static int __devinit snd_cmipci_create_gameport(cmipci_t *cm, int dev)
2686 cm->gameport = gp = gameport_allocate_port(); 2683 cm->gameport = gp = gameport_allocate_port();
2687 if (!gp) { 2684 if (!gp) {
2688 printk(KERN_ERR "cmipci: cannot allocate memory for gameport\n"); 2685 printk(KERN_ERR "cmipci: cannot allocate memory for gameport\n");
2689 release_resource(r); 2686 release_and_free_resource(r);
2690 kfree_nocheck(r);
2691 return -ENOMEM; 2687 return -ENOMEM;
2692 } 2688 }
2693 gameport_set_name(gp, "C-Media Gameport"); 2689 gameport_set_name(gp, "C-Media Gameport");
@@ -2712,8 +2708,7 @@ static void snd_cmipci_free_gameport(cmipci_t *cm)
2712 cm->gameport = NULL; 2708 cm->gameport = NULL;
2713 2709
2714 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN); 2710 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN);
2715 release_resource(r); 2711 release_and_free_resource(r);
2716 kfree_nocheck(r);
2717 } 2712 }
2718} 2713}
2719#else 2714#else
@@ -2753,6 +2748,51 @@ static int snd_cmipci_dev_free(snd_device_t *device)
2753 return snd_cmipci_free(cm); 2748 return snd_cmipci_free(cm);
2754} 2749}
2755 2750
2751static int __devinit snd_cmipci_create_fm(cmipci_t *cm, long fm_port)
2752{
2753 long iosynth;
2754 unsigned int val;
2755 opl3_t *opl3;
2756 int err;
2757
2758 /* first try FM regs in PCI port range */
2759 iosynth = cm->iobase + CM_REG_FM_PCI;
2760 err = snd_opl3_create(cm->card, iosynth, iosynth + 2,
2761 OPL3_HW_OPL3, 1, &opl3);
2762 if (err < 0) {
2763 /* then try legacy ports */
2764 val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL) & ~CM_FMSEL_MASK;
2765 iosynth = fm_port;
2766 switch (iosynth) {
2767 case 0x3E8: val |= CM_FMSEL_3E8; break;
2768 case 0x3E0: val |= CM_FMSEL_3E0; break;
2769 case 0x3C8: val |= CM_FMSEL_3C8; break;
2770 case 0x388: val |= CM_FMSEL_388; break;
2771 default:
2772 return 0;
2773 }
2774 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
2775 /* enable FM */
2776 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2777
2778 if (snd_opl3_create(cm->card, iosynth, iosynth + 2,
2779 OPL3_HW_OPL3, 0, &opl3) < 0) {
2780 printk(KERN_ERR "cmipci: no OPL device at %#lx, "
2781 "skipping...\n", iosynth);
2782 /* disable FM */
2783 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL,
2784 val & ~CM_FMSEL_MASK);
2785 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2786 return 0;
2787 }
2788 }
2789 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
2790 printk(KERN_ERR "cmipci: cannot create OPL3 hwdep\n");
2791 return err;
2792 }
2793 return 0;
2794}
2795
2756static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci, 2796static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2757 int dev, cmipci_t **rcmipci) 2797 int dev, cmipci_t **rcmipci)
2758{ 2798{
@@ -2762,8 +2802,8 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2762 .dev_free = snd_cmipci_dev_free, 2802 .dev_free = snd_cmipci_dev_free,
2763 }; 2803 };
2764 unsigned int val = 0; 2804 unsigned int val = 0;
2765 long iomidi = mpu_port[dev]; 2805 long iomidi;
2766 long iosynth = fm_port[dev]; 2806 int integrated_midi;
2767 int pcm_index, pcm_spdif_index; 2807 int pcm_index, pcm_spdif_index;
2768 static struct pci_device_id intel_82437vx[] = { 2808 static struct pci_device_id intel_82437vx[] = {
2769 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) }, 2809 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) },
@@ -2799,7 +2839,7 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2799 cm->iobase = pci_resource_start(pci, 0); 2839 cm->iobase = pci_resource_start(pci, 0);
2800 2840
2801 if (request_irq(pci->irq, snd_cmipci_interrupt, SA_INTERRUPT|SA_SHIRQ, card->driver, (void *)cm)) { 2841 if (request_irq(pci->irq, snd_cmipci_interrupt, SA_INTERRUPT|SA_SHIRQ, card->driver, (void *)cm)) {
2802 snd_printk("unable to grab IRQ %d\n", pci->irq); 2842 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2803 snd_cmipci_free(cm); 2843 snd_cmipci_free(cm);
2804 return -EBUSY; 2844 return -EBUSY;
2805 } 2845 }
@@ -2867,52 +2907,28 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2867 return err; 2907 return err;
2868 } 2908 }
2869 2909
2870 /* set MPU address */ 2910 integrated_midi = snd_cmipci_read_b(cm, CM_REG_MPU_PCI) != 0xff;
2871 switch (iomidi) { 2911 if (integrated_midi)
2872 case 0x320: val = CM_VMPU_320; break; 2912 iomidi = cm->iobase + CM_REG_MPU_PCI;
2873 case 0x310: val = CM_VMPU_310; break; 2913 else {
2874 case 0x300: val = CM_VMPU_300; break; 2914 iomidi = mpu_port[dev];
2875 case 0x330: val = CM_VMPU_330; break; 2915 switch (iomidi) {
2876 default: 2916 case 0x320: val = CM_VMPU_320; break;
2877 iomidi = 0; break; 2917 case 0x310: val = CM_VMPU_310; break;
2878 } 2918 case 0x300: val = CM_VMPU_300; break;
2879 if (iomidi > 0) { 2919 case 0x330: val = CM_VMPU_330; break;
2880 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val); 2920 default:
2881 /* enable UART */ 2921 iomidi = 0; break;
2882 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN); 2922 }
2883 } 2923 if (iomidi > 0) {
2884 2924 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
2885 /* set FM address */ 2925 /* enable UART */
2886 val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL) & ~CM_FMSEL_MASK; 2926 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN);
2887 switch (iosynth) {
2888 case 0x3E8: val |= CM_FMSEL_3E8; break;
2889 case 0x3E0: val |= CM_FMSEL_3E0; break;
2890 case 0x3C8: val |= CM_FMSEL_3C8; break;
2891 case 0x388: val |= CM_FMSEL_388; break;
2892 default:
2893 iosynth = 0; break;
2894 }
2895 if (iosynth > 0) {
2896 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
2897 /* enable FM */
2898 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2899
2900 if (snd_opl3_create(card, iosynth, iosynth + 2,
2901 OPL3_HW_OPL3, 0, &cm->opl3) < 0) {
2902 printk(KERN_ERR "cmipci: no OPL device at 0x%lx, skipping...\n", iosynth);
2903 iosynth = 0;
2904 } else {
2905 if ((err = snd_opl3_hwdep_new(cm->opl3, 0, 1, &cm->opl3hwdep)) < 0) {
2906 printk(KERN_ERR "cmipci: cannot create OPL3 hwdep\n");
2907 return err;
2908 }
2909 } 2927 }
2910 } 2928 }
2911 if (! iosynth) { 2929
2912 /* disable FM */ 2930 if ((err = snd_cmipci_create_fm(cm, fm_port[dev])) < 0)
2913 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val & ~CM_FMSEL_MASK); 2931 return err;
2914 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2915 }
2916 2932
2917 /* reset mixer */ 2933 /* reset mixer */
2918 snd_cmipci_mixer_write(cm, 0, 0); 2934 snd_cmipci_mixer_write(cm, 0, 0);
@@ -2941,7 +2957,7 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2941 2957
2942 if (iomidi > 0) { 2958 if (iomidi > 0) {
2943 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, 2959 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
2944 iomidi, 0, 2960 iomidi, integrated_midi,
2945 cm->irq, 0, &cm->rmidi)) < 0) { 2961 cm->irq, 0, &cm->rmidi)) < 0) {
2946 printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi); 2962 printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi);
2947 } 2963 }
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index dc87e0144b5a..aea2c47712f9 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -523,8 +523,7 @@ static void snd_cs4281_delay(unsigned int delay)
523 delay = 1; 523 delay = 1;
524 end_time = jiffies + delay; 524 end_time = jiffies + delay;
525 do { 525 do {
526 set_current_state(TASK_UNINTERRUPTIBLE); 526 schedule_timeout_uninterruptible(1);
527 schedule_timeout(1);
528 } while (time_after_eq(end_time, jiffies)); 527 } while (time_after_eq(end_time, jiffies));
529 } else { 528 } else {
530 udelay(delay); 529 udelay(delay);
@@ -533,8 +532,7 @@ static void snd_cs4281_delay(unsigned int delay)
533 532
534static inline void snd_cs4281_delay_long(void) 533static inline void snd_cs4281_delay_long(void)
535{ 534{
536 set_current_state(TASK_UNINTERRUPTIBLE); 535 schedule_timeout_uninterruptible(1);
537 schedule_timeout(1);
538} 536}
539 537
540static inline void snd_cs4281_pokeBA0(cs4281_t *chip, unsigned long offset, unsigned int val) 538static inline void snd_cs4281_pokeBA0(cs4281_t *chip, unsigned long offset, unsigned int val)
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index 6e3855b8b33d..9b8af5bcbb04 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -163,7 +163,7 @@ static unsigned short snd_cs46xx_codec_read(cs46xx_t *chip,
163 goto ok1; 163 goto ok1;
164 } 164 }
165 165
166 snd_printk("AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg); 166 snd_printk(KERN_ERR "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg);
167 result = 0xffff; 167 result = 0xffff;
168 goto end; 168 goto end;
169 169
@@ -182,7 +182,7 @@ static unsigned short snd_cs46xx_codec_read(cs46xx_t *chip,
182 udelay(10); 182 udelay(10);
183 } 183 }
184 184
185 snd_printk("AC'97 read problem (ACSTS_VSTS), codec_index %d, reg = 0x%x\n", codec_index, reg); 185 snd_printk(KERN_ERR "AC'97 read problem (ACSTS_VSTS), codec_index %d, reg = 0x%x\n", codec_index, reg);
186 result = 0xffff; 186 result = 0xffff;
187 goto end; 187 goto end;
188 188
@@ -281,7 +281,7 @@ static void snd_cs46xx_codec_write(cs46xx_t *chip,
281 goto end; 281 goto end;
282 } 282 }
283 } 283 }
284 snd_printk("AC'97 write problem, codec_index = %d, reg = 0x%x, val = 0x%x\n", codec_index, reg, val); 284 snd_printk(KERN_ERR "AC'97 write problem, codec_index = %d, reg = 0x%x, val = 0x%x\n", codec_index, reg, val);
285 end: 285 end:
286 chip->active_ctrl(chip, -1); 286 chip->active_ctrl(chip, -1);
287} 287}
@@ -510,7 +510,7 @@ static void snd_cs46xx_proc_start(cs46xx_t *chip)
510 } 510 }
511 511
512 if (snd_cs46xx_peek(chip, BA1_SPCR) & SPCR_RUNFR) 512 if (snd_cs46xx_peek(chip, BA1_SPCR) & SPCR_RUNFR)
513 snd_printk("SPCR_RUNFR never reset\n"); 513 snd_printk(KERN_ERR "SPCR_RUNFR never reset\n");
514} 514}
515 515
516static void snd_cs46xx_proc_stop(cs46xx_t *chip) 516static void snd_cs46xx_proc_stop(cs46xx_t *chip)
@@ -2403,7 +2403,7 @@ static void snd_cs46xx_codec_reset (ac97_t * ac97)
2403 msleep(10); 2403 msleep(10);
2404 } while (time_after_eq(end_time, jiffies)); 2404 } while (time_after_eq(end_time, jiffies));
2405 2405
2406 snd_printk("CS46xx secondary codec dont respond!\n"); 2406 snd_printk(KERN_ERR "CS46xx secondary codec doesn't respond!\n");
2407} 2407}
2408#endif 2408#endif
2409 2409
@@ -2906,10 +2906,7 @@ static int snd_cs46xx_free(cs46xx_t *chip)
2906 snd_cs46xx_region_t *region = &chip->region.idx[idx]; 2906 snd_cs46xx_region_t *region = &chip->region.idx[idx];
2907 if (region->remap_addr) 2907 if (region->remap_addr)
2908 iounmap(region->remap_addr); 2908 iounmap(region->remap_addr);
2909 if (region->resource) { 2909 release_and_free_resource(region->resource);
2910 release_resource(region->resource);
2911 kfree_nocheck(region->resource);
2912 }
2913 } 2910 }
2914 if (chip->irq >= 0) 2911 if (chip->irq >= 0)
2915 free_irq(chip->irq, (void *)chip); 2912 free_irq(chip->irq, (void *)chip);
@@ -3075,8 +3072,8 @@ static int snd_cs46xx_chip_init(cs46xx_t *chip)
3075 } 3072 }
3076 3073
3077 3074
3078 snd_printk("create - never read codec ready from AC'97\n"); 3075 snd_printk(KERN_ERR "create - never read codec ready from AC'97\n");
3079 snd_printk("it is not probably bug, try to use CS4236 driver\n"); 3076 snd_printk(KERN_ERR "it is not probably bug, try to use CS4236 driver\n");
3080 return -EIO; 3077 return -EIO;
3081 ok1: 3078 ok1:
3082#ifdef CONFIG_SND_CS46XX_NEW_DSP 3079#ifdef CONFIG_SND_CS46XX_NEW_DSP
@@ -3124,17 +3121,17 @@ static int snd_cs46xx_chip_init(cs46xx_t *chip)
3124 } 3121 }
3125 3122
3126#ifndef CONFIG_SND_CS46XX_NEW_DSP 3123#ifndef CONFIG_SND_CS46XX_NEW_DSP
3127 snd_printk("create - never read ISV3 & ISV4 from AC'97\n"); 3124 snd_printk(KERN_ERR "create - never read ISV3 & ISV4 from AC'97\n");
3128 return -EIO; 3125 return -EIO;
3129#else 3126#else
3130 /* This may happen on a cold boot with a Terratec SiXPack 5.1. 3127 /* This may happen on a cold boot with a Terratec SiXPack 5.1.
3131 Reloading the driver may help, if there's other soundcards 3128 Reloading the driver may help, if there's other soundcards
3132 with the same problem I would like to know. (Benny) */ 3129 with the same problem I would like to know. (Benny) */
3133 3130
3134 snd_printk("ERROR: snd-cs46xx: never read ISV3 & ISV4 from AC'97\n"); 3131 snd_printk(KERN_ERR "ERROR: snd-cs46xx: never read ISV3 & ISV4 from AC'97\n");
3135 snd_printk(" Try reloading the ALSA driver, if you find something\n"); 3132 snd_printk(KERN_ERR " Try reloading the ALSA driver, if you find something\n");
3136 snd_printk(" broken or not working on your soundcard upon\n"); 3133 snd_printk(KERN_ERR " broken or not working on your soundcard upon\n");
3137 snd_printk(" this message please report to alsa-devel@lists.sourceforge.net\n"); 3134 snd_printk(KERN_ERR " this message please report to alsa-devel@lists.sourceforge.net\n");
3138 3135
3139 return -EIO; 3136 return -EIO;
3140#endif 3137#endif
@@ -3215,7 +3212,7 @@ int __devinit snd_cs46xx_start_dsp(cs46xx_t *chip)
3215#else 3212#else
3216 /* old image */ 3213 /* old image */
3217 if (snd_cs46xx_download_image(chip) < 0) { 3214 if (snd_cs46xx_download_image(chip) < 0) {
3218 snd_printk("image download error\n"); 3215 snd_printk(KERN_ERR "image download error\n");
3219 return -EIO; 3216 return -EIO;
3220 } 3217 }
3221 3218
@@ -3790,7 +3787,7 @@ int __devinit snd_cs46xx_create(snd_card_t * card,
3790 chip->ba1_addr = pci_resource_start(pci, 1); 3787 chip->ba1_addr = pci_resource_start(pci, 1);
3791 if (chip->ba0_addr == 0 || chip->ba0_addr == (unsigned long)~0 || 3788 if (chip->ba0_addr == 0 || chip->ba0_addr == (unsigned long)~0 ||
3792 chip->ba1_addr == 0 || chip->ba1_addr == (unsigned long)~0) { 3789 chip->ba1_addr == 0 || chip->ba1_addr == (unsigned long)~0) {
3793 snd_printk("wrong address(es) - ba0 = 0x%lx, ba1 = 0x%lx\n", chip->ba0_addr, chip->ba1_addr); 3790 snd_printk(KERN_ERR "wrong address(es) - ba0 = 0x%lx, ba1 = 0x%lx\n", chip->ba0_addr, chip->ba1_addr);
3794 snd_cs46xx_free(chip); 3791 snd_cs46xx_free(chip);
3795 return -ENOMEM; 3792 return -ENOMEM;
3796 } 3793 }
@@ -3839,12 +3836,12 @@ int __devinit snd_cs46xx_create(snd_card_t * card,
3839 } 3836 }
3840 3837
3841 if (external_amp) { 3838 if (external_amp) {
3842 snd_printk("Crystal EAPD support forced on.\n"); 3839 snd_printk(KERN_INFO "Crystal EAPD support forced on.\n");
3843 chip->amplifier_ctrl = amp_voyetra; 3840 chip->amplifier_ctrl = amp_voyetra;
3844 } 3841 }
3845 3842
3846 if (thinkpad) { 3843 if (thinkpad) {
3847 snd_printk("Activating CLKRUN hack for Thinkpad.\n"); 3844 snd_printk(KERN_INFO "Activating CLKRUN hack for Thinkpad.\n");
3848 chip->active_ctrl = clkrun_hack; 3845 chip->active_ctrl = clkrun_hack;
3849 clkrun_init(chip); 3846 clkrun_init(chip);
3850 } 3847 }
@@ -3861,20 +3858,20 @@ int __devinit snd_cs46xx_create(snd_card_t * card,
3861 for (idx = 0; idx < 5; idx++) { 3858 for (idx = 0; idx < 5; idx++) {
3862 region = &chip->region.idx[idx]; 3859 region = &chip->region.idx[idx];
3863 if ((region->resource = request_mem_region(region->base, region->size, region->name)) == NULL) { 3860 if ((region->resource = request_mem_region(region->base, region->size, region->name)) == NULL) {
3864 snd_printk("unable to request memory region 0x%lx-0x%lx\n", region->base, region->base + region->size - 1); 3861 snd_printk(KERN_ERR "unable to request memory region 0x%lx-0x%lx\n", region->base, region->base + region->size - 1);
3865 snd_cs46xx_free(chip); 3862 snd_cs46xx_free(chip);
3866 return -EBUSY; 3863 return -EBUSY;
3867 } 3864 }
3868 region->remap_addr = ioremap_nocache(region->base, region->size); 3865 region->remap_addr = ioremap_nocache(region->base, region->size);
3869 if (region->remap_addr == NULL) { 3866 if (region->remap_addr == NULL) {
3870 snd_printk("%s ioremap problem\n", region->name); 3867 snd_printk(KERN_ERR "%s ioremap problem\n", region->name);
3871 snd_cs46xx_free(chip); 3868 snd_cs46xx_free(chip);
3872 return -ENOMEM; 3869 return -ENOMEM;
3873 } 3870 }
3874 } 3871 }
3875 3872
3876 if (request_irq(pci->irq, snd_cs46xx_interrupt, SA_INTERRUPT|SA_SHIRQ, "CS46XX", (void *) chip)) { 3873 if (request_irq(pci->irq, snd_cs46xx_interrupt, SA_INTERRUPT|SA_SHIRQ, "CS46XX", (void *) chip)) {
3877 snd_printk("unable to grab IRQ %d\n", pci->irq); 3874 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
3878 snd_cs46xx_free(chip); 3875 snd_cs46xx_free(chip);
3879 return -EBUSY; 3876 return -EBUSY;
3880 } 3877 }
diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c
index b0e00f0a7c2f..dd1ea9d3b81a 100644
--- a/sound/pci/emu10k1/emu10k1.c
+++ b/sound/pci/emu10k1/emu10k1.c
@@ -188,7 +188,7 @@ static int __devinit snd_card_emu10k1_probe(struct pci_dev *pci,
188 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, 188 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
189 sizeof(snd_emu10k1_synth_arg_t), &wave) < 0 || 189 sizeof(snd_emu10k1_synth_arg_t), &wave) < 0 ||
190 wave == NULL) { 190 wave == NULL) {
191 snd_printk("can't initialize Emu10k1 wavetable synth\n"); 191 snd_printk(KERN_WARNING "can't initialize Emu10k1 wavetable synth\n");
192 } else { 192 } else {
193 snd_emu10k1_synth_arg_t *arg; 193 snd_emu10k1_synth_arg_t *arg;
194 arg = SNDRV_SEQ_DEVICE_ARGPTR(wave); 194 arg = SNDRV_SEQ_DEVICE_ARGPTR(wave);
diff --git a/sound/pci/emu10k1/emu10k1_callback.c b/sound/pci/emu10k1/emu10k1_callback.c
index 7cf2f908eed9..6589bf24abcd 100644
--- a/sound/pci/emu10k1/emu10k1_callback.c
+++ b/sound/pci/emu10k1/emu10k1_callback.c
@@ -241,7 +241,7 @@ lookup_voices(snd_emux_t *emu, emu10k1_t *hw, best_voice_t *best, int active_onl
241 else if (state == SNDRV_EMUX_ST_RELEASED || 241 else if (state == SNDRV_EMUX_ST_RELEASED ||
242 state == SNDRV_EMUX_ST_PENDING) { 242 state == SNDRV_EMUX_ST_PENDING) {
243 bp = best + V_RELEASED; 243 bp = best + V_RELEASED;
244#if 0 244#if 1
245 val = snd_emu10k1_ptr_read(hw, CVCF_CURRENTVOL, vp->ch); 245 val = snd_emu10k1_ptr_read(hw, CVCF_CURRENTVOL, vp->ch);
246 if (! val) 246 if (! val)
247 bp = best + V_OFF; 247 bp = best + V_OFF;
@@ -349,7 +349,7 @@ start_voice(snd_emux_voice_t *vp)
349 } 349 }
350 350
351 /* channel to be silent and idle */ 351 /* channel to be silent and idle */
352 snd_emu10k1_ptr_write(hw, DCYSUSV, ch, 0x0080); 352 snd_emu10k1_ptr_write(hw, DCYSUSV, ch, 0x0000);
353 snd_emu10k1_ptr_write(hw, VTFT, ch, 0x0000FFFF); 353 snd_emu10k1_ptr_write(hw, VTFT, ch, 0x0000FFFF);
354 snd_emu10k1_ptr_write(hw, CVCF, ch, 0x0000FFFF); 354 snd_emu10k1_ptr_write(hw, CVCF, ch, 0x0000FFFF);
355 snd_emu10k1_ptr_write(hw, PTRX, ch, 0); 355 snd_emu10k1_ptr_write(hw, PTRX, ch, 0);
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index ad15755a63c3..cbb689474e7d 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -759,10 +759,8 @@ static int snd_emu10k1x_free(emu10k1x_t *chip)
759 outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG); 759 outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
760 760
761 // release the i/o port 761 // release the i/o port
762 if (chip->res_port) { 762 release_and_free_resource(chip->res_port);
763 release_resource(chip->res_port); 763
764 kfree_nocheck(chip->res_port);
765 }
766 // release the irq 764 // release the irq
767 if (chip->irq >= 0) 765 if (chip->irq >= 0)
768 free_irq(chip->irq, (void *)chip); 766 free_irq(chip->irq, (void *)chip);
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 646b5d972e6f..03e8c1678952 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -364,12 +364,18 @@ static int snd_emu10k1_gpr_ctl_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
364 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[i], 0, db_table[val]); 364 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[i], 0, db_table[val]);
365 break; 365 break;
366 case EMU10K1_GPR_TRANSLATION_BASS: 366 case EMU10K1_GPR_TRANSLATION_BASS:
367 snd_runtime_check((ctl->count % 5) == 0 && (ctl->count / 5) == ctl->vcount, change = -EIO; goto __error); 367 if ((ctl->count % 5) != 0 || (ctl->count / 5) != ctl->vcount) {
368 change = -EIO;
369 goto __error;
370 }
368 for (j = 0; j < 5; j++) 371 for (j = 0; j < 5; j++)
369 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, bass_table[val][j]); 372 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, bass_table[val][j]);
370 break; 373 break;
371 case EMU10K1_GPR_TRANSLATION_TREBLE: 374 case EMU10K1_GPR_TRANSLATION_TREBLE:
372 snd_runtime_check((ctl->count % 5) == 0 && (ctl->count / 5) == ctl->vcount, change = -EIO; goto __error); 375 if ((ctl->count % 5) != 0 || (ctl->count / 5) != ctl->vcount) {
376 change = -EIO;
377 goto __error;
378 }
373 for (j = 0; j < 5; j++) 379 for (j = 0; j < 5; j++)
374 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, treble_table[val][j]); 380 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, treble_table[val][j]);
375 break; 381 break;
@@ -412,8 +418,6 @@ int snd_emu10k1_fx8010_register_irq_handler(emu10k1_t *emu,
412 snd_emu10k1_fx8010_irq_t *irq; 418 snd_emu10k1_fx8010_irq_t *irq;
413 unsigned long flags; 419 unsigned long flags;
414 420
415 snd_runtime_check(emu, return -EINVAL);
416 snd_runtime_check(handler, return -EINVAL);
417 irq = kmalloc(sizeof(*irq), GFP_ATOMIC); 421 irq = kmalloc(sizeof(*irq), GFP_ATOMIC);
418 if (irq == NULL) 422 if (irq == NULL)
419 return -ENOMEM; 423 return -ENOMEM;
@@ -442,7 +446,6 @@ int snd_emu10k1_fx8010_unregister_irq_handler(emu10k1_t *emu,
442 snd_emu10k1_fx8010_irq_t *tmp; 446 snd_emu10k1_fx8010_irq_t *tmp;
443 unsigned long flags; 447 unsigned long flags;
444 448
445 snd_runtime_check(irq, return -EINVAL);
446 spin_lock_irqsave(&emu->fx8010.irq_lock, flags); 449 spin_lock_irqsave(&emu->fx8010.irq_lock, flags);
447 if ((tmp = emu->fx8010.irq_handlers) == irq) { 450 if ((tmp = emu->fx8010.irq_handlers) == irq) {
448 emu->fx8010.irq_handlers = tmp->next; 451 emu->fx8010.irq_handlers = tmp->next;
@@ -717,9 +720,15 @@ static int snd_emu10k1_add_controls(emu10k1_t *emu, emu10k1_fx8010_code_t *icode
717 err = -EFAULT; 720 err = -EFAULT;
718 goto __error; 721 goto __error;
719 } 722 }
720 snd_runtime_check(gctl->id.iface == SNDRV_CTL_ELEM_IFACE_MIXER || 723 if (gctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
721 gctl->id.iface == SNDRV_CTL_ELEM_IFACE_PCM, err = -EINVAL; goto __error); 724 gctl->id.iface != SNDRV_CTL_ELEM_IFACE_PCM) {
722 snd_runtime_check(gctl->id.name[0] != '\0', err = -EINVAL; goto __error); 725 err = -EINVAL;
726 goto __error;
727 }
728 if (! gctl->id.name[0]) {
729 err = -EINVAL;
730 goto __error;
731 }
723 ctl = snd_emu10k1_look_for_ctl(emu, &gctl->id); 732 ctl = snd_emu10k1_look_for_ctl(emu, &gctl->id);
724 memset(&knew, 0, sizeof(knew)); 733 memset(&knew, 0, sizeof(knew));
725 knew.iface = gctl->id.iface; 734 knew.iface = gctl->id.iface;
@@ -783,7 +792,8 @@ static int snd_emu10k1_del_controls(emu10k1_t *emu, emu10k1_fx8010_code_t *icode
783 792
784 for (i = 0, _id = icode->gpr_del_controls; 793 for (i = 0, _id = icode->gpr_del_controls;
785 i < icode->gpr_del_control_count; i++, _id++) { 794 i < icode->gpr_del_control_count; i++, _id++) {
786 snd_runtime_check(copy_from_user(&id, _id, sizeof(id)) == 0, return -EFAULT); 795 if (copy_from_user(&id, _id, sizeof(id)))
796 return -EFAULT;
787 down_write(&card->controls_rwsem); 797 down_write(&card->controls_rwsem);
788 ctl = snd_emu10k1_look_for_ctl(emu, &id); 798 ctl = snd_emu10k1_look_for_ctl(emu, &id);
789 if (ctl) 799 if (ctl)
@@ -964,8 +974,8 @@ static int snd_emu10k1_ipcm_peek(emu10k1_t *emu, emu10k1_fx8010_pcm_t *ipcm)
964 return err; 974 return err;
965} 975}
966 976
967#define SND_EMU10K1_GPR_CONTROLS 41 977#define SND_EMU10K1_GPR_CONTROLS 44
968#define SND_EMU10K1_INPUTS 10 978#define SND_EMU10K1_INPUTS 12
969#define SND_EMU10K1_PLAYBACK_CHANNELS 8 979#define SND_EMU10K1_PLAYBACK_CHANNELS 8
970#define SND_EMU10K1_CAPTURE_CHANNELS 4 980#define SND_EMU10K1_CAPTURE_CHANNELS 4
971 981
@@ -1382,7 +1392,7 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
1382 A_SWITCH(icode, &ptr, tmp + 1, playback + SND_EMU10K1_PLAYBACK_CHANNELS + z, tmp + 1); 1392 A_SWITCH(icode, &ptr, tmp + 1, playback + SND_EMU10K1_PLAYBACK_CHANNELS + z, tmp + 1);
1383 if ((z==1) && (emu->card_capabilities->spdif_bug)) { 1393 if ((z==1) && (emu->card_capabilities->spdif_bug)) {
1384 /* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */ 1394 /* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */
1385 snd_printk("Installing spdif_bug patch: %s\n", emu->card_capabilities->name); 1395 snd_printk(KERN_INFO "Installing spdif_bug patch: %s\n", emu->card_capabilities->name);
1386 A_OP(icode, &ptr, iACC3, A_EXTOUT(A_EXTOUT_FRONT_L + z), A_GPR(gpr - 3), A_C_00000000, A_C_00000000); 1396 A_OP(icode, &ptr, iACC3, A_EXTOUT(A_EXTOUT_FRONT_L + z), A_GPR(gpr - 3), A_C_00000000, A_C_00000000);
1387 A_OP(icode, &ptr, iACC3, A_GPR(gpr - 3), A_GPR(tmp + 0), A_GPR(tmp + 1), A_C_00000000); 1397 A_OP(icode, &ptr, iACC3, A_GPR(gpr - 3), A_GPR(tmp + 0), A_GPR(tmp + 1), A_C_00000000);
1388 } else { 1398 } else {
@@ -1527,7 +1537,7 @@ static int __devinit _snd_emu10k1_init_efx(emu10k1_t *emu)
1527 1537
1528 strcpy(icode->name, "SB Live! FX8010 code for ALSA v1.2 by Jaroslav Kysela"); 1538 strcpy(icode->name, "SB Live! FX8010 code for ALSA v1.2 by Jaroslav Kysela");
1529 ptr = 0; i = 0; 1539 ptr = 0; i = 0;
1530 /* we have 10 inputs */ 1540 /* we have 12 inputs */
1531 playback = SND_EMU10K1_INPUTS; 1541 playback = SND_EMU10K1_INPUTS;
1532 /* we have 6 playback channels and tone control doubles */ 1542 /* we have 6 playback channels and tone control doubles */
1533 capture = playback + (SND_EMU10K1_PLAYBACK_CHANNELS * 2); 1543 capture = playback + (SND_EMU10K1_PLAYBACK_CHANNELS * 2);
@@ -1551,6 +1561,8 @@ static int __devinit _snd_emu10k1_init_efx(emu10k1_t *emu)
1551 OP(icode, &ptr, iMACINT0, GPR(7), C_00000000, FXBUS(FXBUS_PCM_LFE), C_00000004); 1561 OP(icode, &ptr, iMACINT0, GPR(7), C_00000000, FXBUS(FXBUS_PCM_LFE), C_00000004);
1552 OP(icode, &ptr, iMACINT0, GPR(8), C_00000000, C_00000000, C_00000000); /* S/PDIF left */ 1562 OP(icode, &ptr, iMACINT0, GPR(8), C_00000000, C_00000000, C_00000000); /* S/PDIF left */
1553 OP(icode, &ptr, iMACINT0, GPR(9), C_00000000, C_00000000, C_00000000); /* S/PDIF right */ 1563 OP(icode, &ptr, iMACINT0, GPR(9), C_00000000, C_00000000, C_00000000); /* S/PDIF right */
1564 OP(icode, &ptr, iMACINT0, GPR(10), C_00000000, FXBUS(FXBUS_PCM_LEFT_FRONT), C_00000004);
1565 OP(icode, &ptr, iMACINT0, GPR(11), C_00000000, FXBUS(FXBUS_PCM_RIGHT_FRONT), C_00000004);
1554 1566
1555 /* Raw S/PDIF PCM */ 1567 /* Raw S/PDIF PCM */
1556 ipcm->substream = 0; 1568 ipcm->substream = 0;
@@ -1697,6 +1709,21 @@ static int __devinit _snd_emu10k1_init_efx(emu10k1_t *emu)
1697 VOLUME_ADD(icode, &ptr, playback + 5, 7, gpr); 1709 VOLUME_ADD(icode, &ptr, playback + 5, 7, gpr);
1698 snd_emu10k1_init_mono_control(controls + i++, "LFE Digital Playback Volume", gpr++, 100); 1710 snd_emu10k1_init_mono_control(controls + i++, "LFE Digital Playback Volume", gpr++, 100);
1699 1711
1712 /* Front Playback Volume */
1713 for (z = 0; z < 2; z++)
1714 VOLUME_ADD(icode, &ptr, playback + z, 10 + z, gpr + z);
1715 snd_emu10k1_init_stereo_control(controls + i++, "Front Playback Volume", gpr, 100);
1716 gpr += 2;
1717
1718 /* Front Capture Volume + Switch */
1719 for (z = 0; z < 2; z++) {
1720 SWITCH(icode, &ptr, tmp + 0, 10 + z, gpr + 2);
1721 VOLUME_ADD(icode, &ptr, capture + z, tmp + 0, gpr + z);
1722 }
1723 snd_emu10k1_init_stereo_control(controls + i++, "Front Capture Volume", gpr, 0);
1724 snd_emu10k1_init_mono_onoff_control(controls + i++, "Front Capture Switch", gpr + 2, 0);
1725 gpr += 3;
1726
1700 /* 1727 /*
1701 * Process inputs 1728 * Process inputs
1702 */ 1729 */
@@ -2058,14 +2085,16 @@ void snd_emu10k1_free_efx(emu10k1_t *emu)
2058#if 0 // FIXME: who use them? 2085#if 0 // FIXME: who use them?
2059int snd_emu10k1_fx8010_tone_control_activate(emu10k1_t *emu, int output) 2086int snd_emu10k1_fx8010_tone_control_activate(emu10k1_t *emu, int output)
2060{ 2087{
2061 snd_runtime_check(output >= 0 && output < 6, return -EINVAL); 2088 if (output < 0 || output >= 6)
2089 return -EINVAL;
2062 snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 1); 2090 snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 1);
2063 return 0; 2091 return 0;
2064} 2092}
2065 2093
2066int snd_emu10k1_fx8010_tone_control_deactivate(emu10k1_t *emu, int output) 2094int snd_emu10k1_fx8010_tone_control_deactivate(emu10k1_t *emu, int output)
2067{ 2095{
2068 snd_runtime_check(output >= 0 && output < 6, return -EINVAL); 2096 if (output < 0 || output >= 6)
2097 return -EINVAL;
2069 snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 0); 2098 snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 0);
2070 return 0; 2099 return 0;
2071} 2100}
diff --git a/sound/pci/emu10k1/emupcm.c b/sound/pci/emu10k1/emupcm.c
index 66ba27afe962..bf7490dae09b 100644
--- a/sound/pci/emu10k1/emupcm.c
+++ b/sound/pci/emu10k1/emupcm.c
@@ -965,7 +965,8 @@ static void snd_emu10k1_pcm_mixer_notify1(emu10k1_t *emu, snd_kcontrol_t *kctl,
965{ 965{
966 snd_ctl_elem_id_t id; 966 snd_ctl_elem_id_t id;
967 967
968 snd_runtime_check(kctl != NULL, return); 968 if (! kctl)
969 return;
969 if (activate) 970 if (activate)
970 kctl->vd[idx].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; 971 kctl->vd[idx].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
971 else 972 else
diff --git a/sound/pci/emu10k1/irq.c b/sound/pci/emu10k1/irq.c
index cd8460d56752..594ea063b140 100644
--- a/sound/pci/emu10k1/irq.c
+++ b/sound/pci/emu10k1/irq.c
@@ -41,7 +41,7 @@ irqreturn_t snd_emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
41 orig_status = status; 41 orig_status = status;
42 handled = 1; 42 handled = 1;
43 if (status & IPR_PCIERROR) { 43 if (status & IPR_PCIERROR) {
44 snd_printk("interrupt: PCI error\n"); 44 snd_printk(KERN_ERR "interrupt: PCI error\n");
45 snd_emu10k1_intr_disable(emu, INTE_PCIERRORENABLE); 45 snd_emu10k1_intr_disable(emu, INTE_PCIERRORENABLE);
46 status &= ~IPR_PCIERROR; 46 status &= ~IPR_PCIERROR;
47 } 47 }
diff --git a/sound/pci/emu10k1/memory.c b/sound/pci/emu10k1/memory.c
index 6afeaeab3e13..d42e4aeaa73a 100644
--- a/sound/pci/emu10k1/memory.c
+++ b/sound/pci/emu10k1/memory.c
@@ -232,11 +232,11 @@ __found_pages:
232static int is_valid_page(emu10k1_t *emu, dma_addr_t addr) 232static int is_valid_page(emu10k1_t *emu, dma_addr_t addr)
233{ 233{
234 if (addr & ~emu->dma_mask) { 234 if (addr & ~emu->dma_mask) {
235 snd_printk("max memory size is 0x%lx (addr = 0x%lx)!!\n", emu->dma_mask, (unsigned long)addr); 235 snd_printk(KERN_ERR "max memory size is 0x%lx (addr = 0x%lx)!!\n", emu->dma_mask, (unsigned long)addr);
236 return 0; 236 return 0;
237 } 237 }
238 if (addr & (EMUPAGESIZE-1)) { 238 if (addr & (EMUPAGESIZE-1)) {
239 snd_printk("page is not aligned\n"); 239 snd_printk(KERN_ERR "page is not aligned\n");
240 return 0; 240 return 0;
241 } 241 }
242 return 1; 242 return 1;
@@ -501,7 +501,7 @@ static inline void *offset_ptr(emu10k1_t *emu, int page, int offset)
501 snd_assert(page >= 0 && page < emu->max_cache_pages, return NULL); 501 snd_assert(page >= 0 && page < emu->max_cache_pages, return NULL);
502 ptr = emu->page_ptr_table[page]; 502 ptr = emu->page_ptr_table[page];
503 if (! ptr) { 503 if (! ptr) {
504 printk("emu10k1: access to NULL ptr: page = %d\n", page); 504 printk(KERN_ERR "emu10k1: access to NULL ptr: page = %d\n", page);
505 return NULL; 505 return NULL;
506 } 506 }
507 ptr += offset & (PAGE_SIZE - 1); 507 ptr += offset & (PAGE_SIZE - 1);
diff --git a/sound/pci/emu10k1/p16v.c b/sound/pci/emu10k1/p16v.c
index d59c7f345ad6..e27ebb9bb74a 100644
--- a/sound/pci/emu10k1/p16v.c
+++ b/sound/pci/emu10k1/p16v.c
@@ -546,7 +546,7 @@ snd_p16v_pcm_pointer_capture(snd_pcm_substream_t *substream)
546 ptr=ptr2; 546 ptr=ptr2;
547 if (ptr >= runtime->buffer_size) { 547 if (ptr >= runtime->buffer_size) {
548 ptr -= runtime->buffer_size; 548 ptr -= runtime->buffer_size;
549 printk("buffer capture limited!\n"); 549 printk(KERN_WARNING "buffer capture limited!\n");
550 } 550 }
551 //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate); 551 //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate);
552 552
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index bef9a59f46d7..92ff7c510f2b 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -508,7 +508,7 @@ static unsigned int snd_es1371_wait_src_ready(ensoniq_t * ensoniq)
508 return r; 508 return r;
509 cond_resched(); 509 cond_resched();
510 } 510 }
511 snd_printk("wait source ready timeout 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_SMPRATE), r); 511 snd_printk(KERN_ERR "wait source ready timeout 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_SMPRATE), r);
512 return 0; 512 return 0;
513} 513}
514 514
@@ -576,10 +576,9 @@ static void snd_es1370_codec_write(ak4531_t *ak4531,
576 outw(ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC)); 576 outw(ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC));
577 return; 577 return;
578 } 578 }
579 set_current_state(TASK_UNINTERRUPTIBLE); 579 schedule_timeout_uninterruptible(1);
580 schedule_timeout(1);
581 } while (time_after(end_time, jiffies)); 580 } while (time_after(end_time, jiffies));
582 snd_printk("codec write timeout, status = 0x%x\n", inl(ES_REG(ensoniq, STATUS))); 581 snd_printk(KERN_ERR "codec write timeout, status = 0x%x\n", inl(ES_REG(ensoniq, STATUS)));
583} 582}
584 583
585#endif /* CHIP1370 */ 584#endif /* CHIP1370 */
@@ -620,7 +619,7 @@ static void snd_es1371_codec_write(ac97_t *ac97,
620 } 619 }
621 } 620 }
622 up(&ensoniq->src_mutex); 621 up(&ensoniq->src_mutex);
623 snd_printk("codec write timeout at 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC))); 622 snd_printk(KERN_ERR "codec write timeout at 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
624} 623}
625 624
626static unsigned short snd_es1371_codec_read(ac97_t *ac97, 625static unsigned short snd_es1371_codec_read(ac97_t *ac97,
@@ -667,14 +666,14 @@ static unsigned short snd_es1371_codec_read(ac97_t *ac97,
667 } 666 }
668 up(&ensoniq->src_mutex); 667 up(&ensoniq->src_mutex);
669 if (++fail > 10) { 668 if (++fail > 10) {
670 snd_printk("codec read timeout (final) at 0x%lx, reg = 0x%x [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), reg, inl(ES_REG(ensoniq, 1371_CODEC))); 669 snd_printk(KERN_ERR "codec read timeout (final) at 0x%lx, reg = 0x%x [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), reg, inl(ES_REG(ensoniq, 1371_CODEC)));
671 return 0; 670 return 0;
672 } 671 }
673 goto __again; 672 goto __again;
674 } 673 }
675 } 674 }
676 up(&ensoniq->src_mutex); 675 up(&ensoniq->src_mutex);
677 snd_printk("es1371: codec read timeout at 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC))); 676 snd_printk(KERN_ERR "es1371: codec read timeout at 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
678 return 0; 677 return 0;
679} 678}
680 679
@@ -1960,7 +1959,7 @@ static int __devinit snd_ensoniq_create(snd_card_t * card,
1960 } 1959 }
1961 ensoniq->port = pci_resource_start(pci, 0); 1960 ensoniq->port = pci_resource_start(pci, 0);
1962 if (request_irq(pci->irq, snd_audiopci_interrupt, SA_INTERRUPT|SA_SHIRQ, "Ensoniq AudioPCI", (void *)ensoniq)) { 1961 if (request_irq(pci->irq, snd_audiopci_interrupt, SA_INTERRUPT|SA_SHIRQ, "Ensoniq AudioPCI", (void *)ensoniq)) {
1963 snd_printk("unable to grab IRQ %d\n", pci->irq); 1962 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1964 snd_ensoniq_free(ensoniq); 1963 snd_ensoniq_free(ensoniq);
1965 return -EBUSY; 1964 return -EBUSY;
1966 } 1965 }
@@ -1968,7 +1967,7 @@ static int __devinit snd_ensoniq_create(snd_card_t * card,
1968#ifdef CHIP1370 1967#ifdef CHIP1370
1969 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1968 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1970 16, &ensoniq->dma_bug) < 0) { 1969 16, &ensoniq->dma_bug) < 0) {
1971 snd_printk("unable to allocate space for phantom area - dma_bug\n"); 1970 snd_printk(KERN_ERR "unable to allocate space for phantom area - dma_bug\n");
1972 snd_ensoniq_free(ensoniq); 1971 snd_ensoniq_free(ensoniq);
1973 return -EBUSY; 1972 return -EBUSY;
1974 } 1973 }
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 17fa80c23870..78f90defcab1 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -267,7 +267,7 @@ static void snd_es1938_mixer_write(es1938_t *chip, unsigned char reg, unsigned c
267 outb(val, SLSB_REG(chip, MIXERDATA)); 267 outb(val, SLSB_REG(chip, MIXERDATA));
268 spin_unlock_irqrestore(&chip->mixer_lock, flags); 268 spin_unlock_irqrestore(&chip->mixer_lock, flags);
269#ifdef REG_DEBUG 269#ifdef REG_DEBUG
270 snd_printk("Mixer reg %02x set to %02x\n", reg, val); 270 snd_printk(KERN_DEBUG "Mixer reg %02x set to %02x\n", reg, val);
271#endif 271#endif
272} 272}
273 273
@@ -283,7 +283,7 @@ static int snd_es1938_mixer_read(es1938_t *chip, unsigned char reg)
283 data = inb(SLSB_REG(chip, MIXERDATA)); 283 data = inb(SLSB_REG(chip, MIXERDATA));
284 spin_unlock_irqrestore(&chip->mixer_lock, flags); 284 spin_unlock_irqrestore(&chip->mixer_lock, flags);
285#ifdef REG_DEBUG 285#ifdef REG_DEBUG
286 snd_printk("Mixer reg %02x now is %02x\n", reg, data); 286 snd_printk(KERN_DEBUG "Mixer reg %02x now is %02x\n", reg, data);
287#endif 287#endif
288 return data; 288 return data;
289} 289}
@@ -303,7 +303,8 @@ static int snd_es1938_mixer_bits(es1938_t *chip, unsigned char reg, unsigned cha
303 new = (old & ~mask) | (val & mask); 303 new = (old & ~mask) | (val & mask);
304 outb(new, SLSB_REG(chip, MIXERDATA)); 304 outb(new, SLSB_REG(chip, MIXERDATA));
305#ifdef REG_DEBUG 305#ifdef REG_DEBUG
306 snd_printk("Mixer reg %02x was %02x, set to %02x\n", reg, old, new); 306 snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x\n",
307 reg, old, new);
307#endif 308#endif
308 } 309 }
309 spin_unlock_irqrestore(&chip->mixer_lock, flags); 310 spin_unlock_irqrestore(&chip->mixer_lock, flags);
@@ -323,7 +324,7 @@ static void snd_es1938_write_cmd(es1938_t *chip, unsigned char cmd)
323 return; 324 return;
324 } 325 }
325 } 326 }
326 printk("snd_es1938_write_cmd timeout (0x02%x/0x02%x)\n", cmd, v); 327 printk(KERN_ERR "snd_es1938_write_cmd timeout (0x02%x/0x02%x)\n", cmd, v);
327} 328}
328 329
329/* ----------------------------------------------------------------- 330/* -----------------------------------------------------------------
@@ -336,7 +337,7 @@ static int snd_es1938_get_byte(es1938_t *chip)
336 for (i = GET_LOOP_TIMEOUT; i; i--) 337 for (i = GET_LOOP_TIMEOUT; i; i--)
337 if ((v = inb(SLSB_REG(chip, STATUS))) & 0x80) 338 if ((v = inb(SLSB_REG(chip, STATUS))) & 0x80)
338 return inb(SLSB_REG(chip, READDATA)); 339 return inb(SLSB_REG(chip, READDATA));
339 snd_printk("get_byte timeout: status 0x02%x\n", v); 340 snd_printk(KERN_ERR "get_byte timeout: status 0x02%x\n", v);
340 return -ENODEV; 341 return -ENODEV;
341} 342}
342 343
@@ -351,7 +352,7 @@ static void snd_es1938_write(es1938_t *chip, unsigned char reg, unsigned char va
351 snd_es1938_write_cmd(chip, val); 352 snd_es1938_write_cmd(chip, val);
352 spin_unlock_irqrestore(&chip->reg_lock, flags); 353 spin_unlock_irqrestore(&chip->reg_lock, flags);
353#ifdef REG_DEBUG 354#ifdef REG_DEBUG
354 snd_printk("Reg %02x set to %02x\n", reg, val); 355 snd_printk(KERN_DEBUG "Reg %02x set to %02x\n", reg, val);
355#endif 356#endif
356} 357}
357 358
@@ -368,7 +369,7 @@ static unsigned char snd_es1938_read(es1938_t *chip, unsigned char reg)
368 val = snd_es1938_get_byte(chip); 369 val = snd_es1938_get_byte(chip);
369 spin_unlock_irqrestore(&chip->reg_lock, flags); 370 spin_unlock_irqrestore(&chip->reg_lock, flags);
370#ifdef REG_DEBUG 371#ifdef REG_DEBUG
371 snd_printk("Reg %02x now is %02x\n", reg, val); 372 snd_printk(KERN_DEBUG "Reg %02x now is %02x\n", reg, val);
372#endif 373#endif
373 return val; 374 return val;
374} 375}
@@ -390,7 +391,8 @@ static int snd_es1938_bits(es1938_t *chip, unsigned char reg, unsigned char mask
390 new = (old & ~mask) | (val & mask); 391 new = (old & ~mask) | (val & mask);
391 snd_es1938_write_cmd(chip, new); 392 snd_es1938_write_cmd(chip, new);
392#ifdef REG_DEBUG 393#ifdef REG_DEBUG
393 snd_printk("Reg %02x was %02x, set to %02x\n", reg, old, new); 394 snd_printk(KERN_DEBUG "Reg %02x was %02x, set to %02x\n",
395 reg, old, new);
394#endif 396#endif
395 } 397 }
396 spin_unlock_irqrestore(&chip->reg_lock, flags); 398 spin_unlock_irqrestore(&chip->reg_lock, flags);
@@ -413,7 +415,7 @@ static void snd_es1938_reset(es1938_t *chip)
413 goto __next; 415 goto __next;
414 } 416 }
415 } 417 }
416 snd_printk("ESS Solo-1 reset failed\n"); 418 snd_printk(KERN_ERR "ESS Solo-1 reset failed\n");
417 419
418 __next: 420 __next:
419 snd_es1938_write_cmd(chip, ESS_CMD_ENABLEEXT); 421 snd_es1938_write_cmd(chip, ESS_CMD_ENABLEEXT);
@@ -543,10 +545,12 @@ static int snd_es1938_capture_trigger(snd_pcm_substream_t * substream,
543 int val; 545 int val;
544 switch (cmd) { 546 switch (cmd) {
545 case SNDRV_PCM_TRIGGER_START: 547 case SNDRV_PCM_TRIGGER_START:
548 case SNDRV_PCM_TRIGGER_RESUME:
546 val = 0x0f; 549 val = 0x0f;
547 chip->active |= ADC1; 550 chip->active |= ADC1;
548 break; 551 break;
549 case SNDRV_PCM_TRIGGER_STOP: 552 case SNDRV_PCM_TRIGGER_STOP:
553 case SNDRV_PCM_TRIGGER_SUSPEND:
550 val = 0x00; 554 val = 0x00;
551 chip->active &= ~ADC1; 555 chip->active &= ~ADC1;
552 break; 556 break;
@@ -563,6 +567,7 @@ static int snd_es1938_playback1_trigger(snd_pcm_substream_t * substream,
563 es1938_t *chip = snd_pcm_substream_chip(substream); 567 es1938_t *chip = snd_pcm_substream_chip(substream);
564 switch (cmd) { 568 switch (cmd) {
565 case SNDRV_PCM_TRIGGER_START: 569 case SNDRV_PCM_TRIGGER_START:
570 case SNDRV_PCM_TRIGGER_RESUME:
566 /* According to the documentation this should be: 571 /* According to the documentation this should be:
567 0x13 but that value may randomly swap stereo channels */ 572 0x13 but that value may randomly swap stereo channels */
568 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0x92); 573 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0x92);
@@ -575,6 +580,7 @@ static int snd_es1938_playback1_trigger(snd_pcm_substream_t * substream,
575 chip->active |= DAC2; 580 chip->active |= DAC2;
576 break; 581 break;
577 case SNDRV_PCM_TRIGGER_STOP: 582 case SNDRV_PCM_TRIGGER_STOP:
583 case SNDRV_PCM_TRIGGER_SUSPEND:
578 outb(0, SLIO_REG(chip, AUDIO2MODE)); 584 outb(0, SLIO_REG(chip, AUDIO2MODE));
579 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0); 585 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0);
580 chip->active &= ~DAC2; 586 chip->active &= ~DAC2;
@@ -592,10 +598,12 @@ static int snd_es1938_playback2_trigger(snd_pcm_substream_t * substream,
592 int val; 598 int val;
593 switch (cmd) { 599 switch (cmd) {
594 case SNDRV_PCM_TRIGGER_START: 600 case SNDRV_PCM_TRIGGER_START:
601 case SNDRV_PCM_TRIGGER_RESUME:
595 val = 5; 602 val = 5;
596 chip->active |= DAC1; 603 chip->active |= DAC1;
597 break; 604 break;
598 case SNDRV_PCM_TRIGGER_STOP: 605 case SNDRV_PCM_TRIGGER_STOP:
606 case SNDRV_PCM_TRIGGER_SUSPEND:
599 val = 0; 607 val = 0;
600 chip->active &= ~DAC1; 608 chip->active &= ~DAC1;
601 break; 609 break;
@@ -1390,7 +1398,8 @@ static int es1938_suspend(snd_card_t *card, pm_message_t state)
1390 *d = snd_es1938_reg_read(chip, *s); 1398 *d = snd_es1938_reg_read(chip, *s);
1391 1399
1392 outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */ 1400 outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */
1393 1401 if (chip->irq >= 0)
1402 free_irq(chip->irq, (void *)chip);
1394 pci_disable_device(chip->pci); 1403 pci_disable_device(chip->pci);
1395 return 0; 1404 return 0;
1396} 1405}
@@ -1401,6 +1410,9 @@ static int es1938_resume(snd_card_t *card)
1401 unsigned char *s, *d; 1410 unsigned char *s, *d;
1402 1411
1403 pci_enable_device(chip->pci); 1412 pci_enable_device(chip->pci);
1413 request_irq(chip->pci->irq, snd_es1938_interrupt,
1414 SA_INTERRUPT|SA_SHIRQ, "ES1938", (void *)chip);
1415 chip->irq = chip->pci->irq;
1404 snd_es1938_chip_init(chip); 1416 snd_es1938_chip_init(chip);
1405 1417
1406 /* restore mixer-related registers */ 1418 /* restore mixer-related registers */
@@ -1489,7 +1501,7 @@ static int __devinit snd_es1938_create(snd_card_t * card,
1489 /* check, if we can restrict PCI DMA transfers to 24 bits */ 1501 /* check, if we can restrict PCI DMA transfers to 24 bits */
1490 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 || 1502 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
1491 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) { 1503 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
1492 snd_printk("architecture does not support 24bit PCI busmaster DMA\n"); 1504 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n");
1493 pci_disable_device(pci); 1505 pci_disable_device(pci);
1494 return -ENXIO; 1506 return -ENXIO;
1495 } 1507 }
@@ -1514,13 +1526,13 @@ static int __devinit snd_es1938_create(snd_card_t * card,
1514 chip->mpu_port = pci_resource_start(pci, 3); 1526 chip->mpu_port = pci_resource_start(pci, 3);
1515 chip->game_port = pci_resource_start(pci, 4); 1527 chip->game_port = pci_resource_start(pci, 4);
1516 if (request_irq(pci->irq, snd_es1938_interrupt, SA_INTERRUPT|SA_SHIRQ, "ES1938", (void *)chip)) { 1528 if (request_irq(pci->irq, snd_es1938_interrupt, SA_INTERRUPT|SA_SHIRQ, "ES1938", (void *)chip)) {
1517 snd_printk("unable to grab IRQ %d\n", pci->irq); 1529 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1518 snd_es1938_free(chip); 1530 snd_es1938_free(chip);
1519 return -EBUSY; 1531 return -EBUSY;
1520 } 1532 }
1521 chip->irq = pci->irq; 1533 chip->irq = pci->irq;
1522#ifdef ES1938_DDEBUG 1534#ifdef ES1938_DDEBUG
1523 snd_printk("create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n", 1535 snd_printk(KERN_DEBUG "create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n",
1524 chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port); 1536 chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port);
1525#endif 1537#endif
1526 1538
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index ecdcada90ca2..ac8294e21cc1 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -1462,13 +1462,13 @@ snd_es1968_init_dmabuf(es1968_t *chip)
1462 snd_dma_pci_data(chip->pci), 1462 snd_dma_pci_data(chip->pci),
1463 chip->total_bufsize, &chip->dma); 1463 chip->total_bufsize, &chip->dma);
1464 if (err < 0 || ! chip->dma.area) { 1464 if (err < 0 || ! chip->dma.area) {
1465 snd_printk("es1968: can't allocate dma pages for size %d\n", 1465 snd_printk(KERN_ERR "es1968: can't allocate dma pages for size %d\n",
1466 chip->total_bufsize); 1466 chip->total_bufsize);
1467 return -ENOMEM; 1467 return -ENOMEM;
1468 } 1468 }
1469 if ((chip->dma.addr + chip->dma.bytes - 1) & ~((1 << 28) - 1)) { 1469 if ((chip->dma.addr + chip->dma.bytes - 1) & ~((1 << 28) - 1)) {
1470 snd_dma_free_pages(&chip->dma); 1470 snd_dma_free_pages(&chip->dma);
1471 snd_printk("es1968: DMA buffer beyond 256MB.\n"); 1471 snd_printk(KERN_ERR "es1968: DMA buffer beyond 256MB.\n");
1472 return -ENOMEM; 1472 return -ENOMEM;
1473 } 1473 }
1474 } 1474 }
@@ -1741,11 +1741,11 @@ static void __devinit es1968_measure_clock(es1968_t *chip)
1741 1741
1742 /* search 2 APUs (although one apu is enough) */ 1742 /* search 2 APUs (although one apu is enough) */
1743 if ((apu = snd_es1968_alloc_apu_pair(chip, ESM_APU_PCM_PLAY)) < 0) { 1743 if ((apu = snd_es1968_alloc_apu_pair(chip, ESM_APU_PCM_PLAY)) < 0) {
1744 snd_printk("Hmm, cannot find empty APU pair!?\n"); 1744 snd_printk(KERN_ERR "Hmm, cannot find empty APU pair!?\n");
1745 return; 1745 return;
1746 } 1746 }
1747 if ((memory = snd_es1968_new_memory(chip, CLOCK_MEASURE_BUFSIZE)) == NULL) { 1747 if ((memory = snd_es1968_new_memory(chip, CLOCK_MEASURE_BUFSIZE)) == NULL) {
1748 snd_printk("cannot allocate dma buffer - using default clock %d\n", chip->clock); 1748 snd_printk(KERN_ERR "cannot allocate dma buffer - using default clock %d\n", chip->clock);
1749 snd_es1968_free_apu_pair(chip, apu); 1749 snd_es1968_free_apu_pair(chip, apu);
1750 return; 1750 return;
1751 } 1751 }
@@ -1806,7 +1806,7 @@ static void __devinit es1968_measure_clock(es1968_t *chip)
1806 else 1806 else
1807 t += stop_time.tv_usec - start_time.tv_usec; 1807 t += stop_time.tv_usec - start_time.tv_usec;
1808 if (t == 0) { 1808 if (t == 0) {
1809 snd_printk("?? calculation error..\n"); 1809 snd_printk(KERN_ERR "?? calculation error..\n");
1810 } else { 1810 } else {
1811 offset *= 1000; 1811 offset *= 1000;
1812 offset = (offset / t) * 1000 + ((offset % t) * 1000) / t; 1812 offset = (offset / t) * 1000 + ((offset % t) * 1000) / t;
@@ -2090,7 +2090,7 @@ static void snd_es1968_ac97_reset(es1968_t *chip)
2090 outw(inw(ioaddr + 0x3c) & 0xfffc, ioaddr + 0x3c); 2090 outw(inw(ioaddr + 0x3c) & 0xfffc, ioaddr + 0x3c);
2091 2091
2092#if 0 /* the loop here needs to be much better if we want it.. */ 2092#if 0 /* the loop here needs to be much better if we want it.. */
2093 snd_printk("trying software reset\n"); 2093 snd_printk(KERN_INFO "trying software reset\n");
2094 /* try and do a software reset */ 2094 /* try and do a software reset */
2095 outb(0x80 | 0x7c, ioaddr + 0x30); 2095 outb(0x80 | 0x7c, ioaddr + 0x30);
2096 for (w = 0;; w++) { 2096 for (w = 0;; w++) {
@@ -2461,8 +2461,7 @@ static int __devinit snd_es1968_create_gameport(es1968_t *chip, int dev)
2461 chip->gameport = gp = gameport_allocate_port(); 2461 chip->gameport = gp = gameport_allocate_port();
2462 if (!gp) { 2462 if (!gp) {
2463 printk(KERN_ERR "es1968: cannot allocate memory for gameport\n"); 2463 printk(KERN_ERR "es1968: cannot allocate memory for gameport\n");
2464 release_resource(r); 2464 release_and_free_resource(r);
2465 kfree_nocheck(r);
2466 return -ENOMEM; 2465 return -ENOMEM;
2467 } 2466 }
2468 2467
@@ -2488,8 +2487,7 @@ static void snd_es1968_free_gameport(es1968_t *chip)
2488 gameport_unregister_port(chip->gameport); 2487 gameport_unregister_port(chip->gameport);
2489 chip->gameport = NULL; 2488 chip->gameport = NULL;
2490 2489
2491 release_resource(r); 2490 release_and_free_resource(r);
2492 kfree_nocheck(r);
2493 } 2491 }
2494} 2492}
2495#else 2493#else
@@ -2564,7 +2562,7 @@ static int __devinit snd_es1968_create(snd_card_t * card,
2564 /* check, if we can restrict PCI DMA transfers to 28 bits */ 2562 /* check, if we can restrict PCI DMA transfers to 28 bits */
2565 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 || 2563 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2566 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) { 2564 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2567 snd_printk("architecture does not support 28bit PCI busmaster DMA\n"); 2565 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
2568 pci_disable_device(pci); 2566 pci_disable_device(pci);
2569 return -ENXIO; 2567 return -ENXIO;
2570 } 2568 }
@@ -2599,7 +2597,7 @@ static int __devinit snd_es1968_create(snd_card_t * card,
2599 chip->io_port = pci_resource_start(pci, 0); 2597 chip->io_port = pci_resource_start(pci, 0);
2600 if (request_irq(pci->irq, snd_es1968_interrupt, SA_INTERRUPT|SA_SHIRQ, 2598 if (request_irq(pci->irq, snd_es1968_interrupt, SA_INTERRUPT|SA_SHIRQ,
2601 "ESS Maestro", (void*)chip)) { 2599 "ESS Maestro", (void*)chip)) {
2602 snd_printk("unable to grab IRQ %d\n", pci->irq); 2600 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2603 snd_es1968_free(chip); 2601 snd_es1968_free(chip);
2604 return -EBUSY; 2602 return -EBUSY;
2605 } 2603 }
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index e5cfa2a0c246..4c7c8d225c7f 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -237,7 +237,7 @@ static void snd_fm801_codec_write(ac97_t *ac97,
237 goto ok1; 237 goto ok1;
238 udelay(10); 238 udelay(10);
239 } 239 }
240 snd_printk("AC'97 interface is busy (1)\n"); 240 snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
241 return; 241 return;
242 242
243 ok1: 243 ok1:
@@ -252,7 +252,7 @@ static void snd_fm801_codec_write(ac97_t *ac97,
252 return; 252 return;
253 udelay(10); 253 udelay(10);
254 } 254 }
255 snd_printk("AC'97 interface #%d is busy (2)\n", ac97->num); 255 snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
256} 256}
257 257
258static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg) 258static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
@@ -268,7 +268,7 @@ static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
268 goto ok1; 268 goto ok1;
269 udelay(10); 269 udelay(10);
270 } 270 }
271 snd_printk("AC'97 interface is busy (1)\n"); 271 snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
272 return 0; 272 return 0;
273 273
274 ok1: 274 ok1:
@@ -279,7 +279,7 @@ static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
279 goto ok2; 279 goto ok2;
280 udelay(10); 280 udelay(10);
281 } 281 }
282 snd_printk("AC'97 interface #%d is busy (2)\n", ac97->num); 282 snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
283 return 0; 283 return 0;
284 284
285 ok2: 285 ok2:
@@ -288,7 +288,7 @@ static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
288 goto ok3; 288 goto ok3;
289 udelay(10); 289 udelay(10);
290 } 290 }
291 snd_printk("AC'97 interface #%d is not valid (2)\n", ac97->num); 291 snd_printk(KERN_ERR "AC'97 interface #%d is not valid (2)\n", ac97->num);
292 return 0; 292 return 0;
293 293
294 ok3: 294 ok3:
@@ -1279,7 +1279,7 @@ static int __devinit snd_fm801_create(snd_card_t * card,
1279 } 1279 }
1280 chip->port = pci_resource_start(pci, 0); 1280 chip->port = pci_resource_start(pci, 0);
1281 if (request_irq(pci->irq, snd_fm801_interrupt, SA_INTERRUPT|SA_SHIRQ, "FM801", (void *)chip)) { 1281 if (request_irq(pci->irq, snd_fm801_interrupt, SA_INTERRUPT|SA_SHIRQ, "FM801", (void *)chip)) {
1282 snd_printk("unable to grab IRQ %d\n", chip->irq); 1282 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq);
1283 snd_fm801_free(chip); 1283 snd_fm801_free(chip);
1284 return -EBUSY; 1284 return -EBUSY;
1285 } 1285 }
@@ -1303,10 +1303,9 @@ static int __devinit snd_fm801_create(snd_card_t * card,
1303 do { 1303 do {
1304 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8)) 1304 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
1305 goto __ac97_secondary; 1305 goto __ac97_secondary;
1306 set_current_state(TASK_UNINTERRUPTIBLE); 1306 schedule_timeout_uninterruptible(1);
1307 schedule_timeout(1);
1308 } while (time_after(timeout, jiffies)); 1307 } while (time_after(timeout, jiffies));
1309 snd_printk("Primary AC'97 codec not found\n"); 1308 snd_printk(KERN_ERR "Primary AC'97 codec not found\n");
1310 snd_fm801_free(chip); 1309 snd_fm801_free(chip);
1311 return -EIO; 1310 return -EIO;
1312 1311
@@ -1329,8 +1328,7 @@ static int __devinit snd_fm801_create(snd_card_t * card,
1329 goto __ac97_ok; 1328 goto __ac97_ok;
1330 } 1329 }
1331 } 1330 }
1332 set_current_state(TASK_UNINTERRUPTIBLE); 1331 schedule_timeout_uninterruptible(1);
1333 schedule_timeout(1);
1334 } while (time_after(timeout, jiffies)); 1332 } while (time_after(timeout, jiffies));
1335 } 1333 }
1336 1334
@@ -1343,10 +1341,9 @@ static int __devinit snd_fm801_create(snd_card_t * card,
1343 do { 1341 do {
1344 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8)) 1342 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
1345 goto __ac97_ok; 1343 goto __ac97_ok;
1346 set_current_state(TASK_UNINTERRUPTIBLE); 1344 schedule_timeout_uninterruptible(1);
1347 schedule_timeout(1);
1348 } while (time_after(timeout, jiffies)); 1345 } while (time_after(timeout, jiffies));
1349 snd_printk("Primary AC'97 codec not responding\n"); 1346 snd_printk(KERN_ERR "Primary AC'97 codec not responding\n");
1350 snd_fm801_free(chip); 1347 snd_fm801_free(chip);
1351 return -EIO; 1348 return -EIO;
1352 1349
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 3815403ed095..0dbeeaf6113a 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -518,6 +518,13 @@ int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
518 return -ENODEV; 518 return -ENODEV;
519 } 519 }
520 520
521 if (! codec->subsystem_id) {
522 hda_nid_t nid = codec->afg ? codec->afg : codec->mfg;
523 codec->subsystem_id = snd_hda_codec_read(codec, nid, 0,
524 AC_VERB_GET_SUBSYSTEM_ID,
525 0);
526 }
527
521 codec->preset = find_codec_preset(codec); 528 codec->preset = find_codec_preset(codec);
522 if (! *bus->card->mixername) 529 if (! *bus->card->mixername)
523 snd_hda_get_codec_name(codec, bus->card->mixername, 530 snd_hda_get_codec_name(codec, bus->card->mixername,
@@ -814,6 +821,51 @@ int snd_hda_mixer_amp_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t
814} 821}
815 822
816/* 823/*
824 * bound volume controls
825 *
826 * bind multiple volumes (# indices, from 0)
827 */
828
829#define AMP_VAL_IDX_SHIFT 19
830#define AMP_VAL_IDX_MASK (0x0f<<19)
831
832int snd_hda_mixer_bind_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
833{
834 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
835 unsigned long pval;
836 int err;
837
838 down(&codec->spdif_mutex); /* reuse spdif_mutex */
839 pval = kcontrol->private_value;
840 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
841 err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
842 kcontrol->private_value = pval;
843 up(&codec->spdif_mutex);
844 return err;
845}
846
847int snd_hda_mixer_bind_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
848{
849 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
850 unsigned long pval;
851 int i, indices, err = 0, change = 0;
852
853 down(&codec->spdif_mutex); /* reuse spdif_mutex */
854 pval = kcontrol->private_value;
855 indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT;
856 for (i = 0; i < indices; i++) {
857 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) | (i << AMP_VAL_IDX_SHIFT);
858 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
859 if (err < 0)
860 break;
861 change |= err;
862 }
863 kcontrol->private_value = pval;
864 up(&codec->spdif_mutex);
865 return err < 0 ? err : change;
866}
867
868/*
817 * SPDIF out controls 869 * SPDIF out controls
818 */ 870 */
819 871
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index bb53bcf76742..1179d6cfa82a 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -79,6 +79,8 @@ enum {
79#define AC_VERB_GET_GPIO_MASK 0x0f16 79#define AC_VERB_GET_GPIO_MASK 0x0f16
80#define AC_VERB_GET_GPIO_DIRECTION 0x0f17 80#define AC_VERB_GET_GPIO_DIRECTION 0x0f17
81#define AC_VERB_GET_CONFIG_DEFAULT 0x0f1c 81#define AC_VERB_GET_CONFIG_DEFAULT 0x0f1c
82/* f20: AFG/MFG */
83#define AC_VERB_GET_SUBSYSTEM_ID 0x0f20
82 84
83/* 85/*
84 * SET verbs 86 * SET verbs
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 6fe696e53ea6..9d1412a9f2f8 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -47,23 +47,24 @@
47#include "hda_codec.h" 47#include "hda_codec.h"
48 48
49 49
50static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 50static int index = SNDRV_DEFAULT_IDX1;
51static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 51static char *id = SNDRV_DEFAULT_STR1;
52static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 52static char *model;
53static char *model[SNDRV_CARDS]; 53static int position_fix;
54static int position_fix[SNDRV_CARDS];
55 54
56module_param_array(index, int, NULL, 0444); 55module_param(index, int, 0444);
57MODULE_PARM_DESC(index, "Index value for Intel HD audio interface."); 56MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
58module_param_array(id, charp, NULL, 0444); 57module_param(id, charp, 0444);
59MODULE_PARM_DESC(id, "ID string for Intel HD audio interface."); 58MODULE_PARM_DESC(id, "ID string for Intel HD audio interface.");
60module_param_array(enable, bool, NULL, 0444); 59module_param(model, charp, 0444);
61MODULE_PARM_DESC(enable, "Enable Intel HD audio interface.");
62module_param_array(model, charp, NULL, 0444);
63MODULE_PARM_DESC(model, "Use the given board model."); 60MODULE_PARM_DESC(model, "Use the given board model.");
64module_param_array(position_fix, int, NULL, 0444); 61module_param(position_fix, int, 0444);
65MODULE_PARM_DESC(position_fix, "Fix DMA pointer (0 = auto, 1 = none, 2 = POSBUF, 3 = FIFO size)."); 62MODULE_PARM_DESC(position_fix, "Fix DMA pointer (0 = auto, 1 = none, 2 = POSBUF, 3 = FIFO size).");
66 63
64/* just for backward compatibility */
65static int enable;
66module_param(enable, bool, 0444);
67
67MODULE_LICENSE("GPL"); 68MODULE_LICENSE("GPL");
68MODULE_SUPPORTED_DEVICE("{{Intel, ICH6}," 69MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
69 "{Intel, ICH6M}," 70 "{Intel, ICH6M},"
@@ -223,6 +224,9 @@ enum {
223#define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42 224#define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
224#define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02 225#define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
225 226
227/* Defines for Nvidia HDA support */
228#define NVIDIA_HDA_TRANSREG_ADDR 0x4e
229#define NVIDIA_HDA_ENABLE_COHBITS 0x0f
226 230
227/* 231/*
228 * Use CORB/RIRB for communication from/to codecs. 232 * Use CORB/RIRB for communication from/to codecs.
@@ -328,6 +332,7 @@ enum {
328 AZX_DRIVER_VIA, 332 AZX_DRIVER_VIA,
329 AZX_DRIVER_SIS, 333 AZX_DRIVER_SIS,
330 AZX_DRIVER_ULI, 334 AZX_DRIVER_ULI,
335 AZX_DRIVER_NVIDIA,
331}; 336};
332 337
333static char *driver_short_names[] __devinitdata = { 338static char *driver_short_names[] __devinitdata = {
@@ -335,7 +340,8 @@ static char *driver_short_names[] __devinitdata = {
335 [AZX_DRIVER_ATI] = "HDA ATI SB", 340 [AZX_DRIVER_ATI] = "HDA ATI SB",
336 [AZX_DRIVER_VIA] = "HDA VIA VT82xx", 341 [AZX_DRIVER_VIA] = "HDA VIA VT82xx",
337 [AZX_DRIVER_SIS] = "HDA SIS966", 342 [AZX_DRIVER_SIS] = "HDA SIS966",
338 [AZX_DRIVER_ULI] = "HDA ULI M5461" 343 [AZX_DRIVER_ULI] = "HDA ULI M5461",
344 [AZX_DRIVER_NVIDIA] = "HDA NVidia",
339}; 345};
340 346
341/* 347/*
@@ -710,14 +716,14 @@ static void azx_stream_stop(azx_t *chip, azx_dev_t *azx_dev)
710 */ 716 */
711static void azx_init_chip(azx_t *chip) 717static void azx_init_chip(azx_t *chip)
712{ 718{
713 unsigned char tcsel_reg, ati_misc_cntl2; 719 unsigned char reg;
714 720
715 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44) 721 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
716 * TCSEL == Traffic Class Select Register, which sets PCI express QOS 722 * TCSEL == Traffic Class Select Register, which sets PCI express QOS
717 * Ensuring these bits are 0 clears playback static on some HD Audio codecs 723 * Ensuring these bits are 0 clears playback static on some HD Audio codecs
718 */ 724 */
719 pci_read_config_byte (chip->pci, ICH6_PCIREG_TCSEL, &tcsel_reg); 725 pci_read_config_byte (chip->pci, ICH6_PCIREG_TCSEL, &reg);
720 pci_write_config_byte(chip->pci, ICH6_PCIREG_TCSEL, tcsel_reg & 0xf8); 726 pci_write_config_byte(chip->pci, ICH6_PCIREG_TCSEL, reg & 0xf8);
721 727
722 /* reset controller */ 728 /* reset controller */
723 azx_reset(chip); 729 azx_reset(chip);
@@ -733,13 +739,21 @@ static void azx_init_chip(azx_t *chip)
733 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr); 739 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
734 azx_writel(chip, DPUBASE, upper_32bit(chip->posbuf.addr)); 740 azx_writel(chip, DPUBASE, upper_32bit(chip->posbuf.addr));
735 741
736 /* For ATI SB450 azalia HD audio, we need to enable snoop */ 742 switch (chip->driver_type) {
737 if (chip->driver_type == AZX_DRIVER_ATI) { 743 case AZX_DRIVER_ATI:
744 /* For ATI SB450 azalia HD audio, we need to enable snoop */
738 pci_read_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 745 pci_read_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,
739 &ati_misc_cntl2); 746 &reg);
740 pci_write_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 747 pci_write_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,
741 (ati_misc_cntl2 & 0xf8) | ATI_SB450_HDAUDIO_ENABLE_SNOOP); 748 (reg & 0xf8) | ATI_SB450_HDAUDIO_ENABLE_SNOOP);
742 } 749 break;
750 case AZX_DRIVER_NVIDIA:
751 /* For NVIDIA HDA, enable snoop */
752 pci_read_config_byte(chip->pci,NVIDIA_HDA_TRANSREG_ADDR, &reg);
753 pci_write_config_byte(chip->pci,NVIDIA_HDA_TRANSREG_ADDR,
754 (reg & 0xf0) | NVIDIA_HDA_ENABLE_COHBITS);
755 break;
756 }
743} 757}
744 758
745 759
@@ -1264,6 +1278,7 @@ static int __devinit azx_pcm_create(azx_t *chip)
1264 err = create_codec_pcm(chip, codec, &codec->pcm_info[c], pcm_dev); 1278 err = create_codec_pcm(chip, codec, &codec->pcm_info[c], pcm_dev);
1265 if (err < 0) 1279 if (err < 0)
1266 return err; 1280 return err;
1281 chip->pcm[pcm_dev]->dev_class = SNDRV_PCM_CLASS_MODEM;
1267 pcm_dev++; 1282 pcm_dev++;
1268 } 1283 }
1269 } 1284 }
@@ -1530,32 +1545,24 @@ static int __devinit azx_create(snd_card_t *card, struct pci_dev *pci,
1530 1545
1531static int __devinit azx_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) 1546static int __devinit azx_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1532{ 1547{
1533 static int dev;
1534 snd_card_t *card; 1548 snd_card_t *card;
1535 azx_t *chip; 1549 azx_t *chip;
1536 int err = 0; 1550 int err = 0;
1537 1551
1538 if (dev >= SNDRV_CARDS) 1552 card = snd_card_new(index, id, THIS_MODULE, 0);
1539 return -ENODEV;
1540 if (! enable[dev]) {
1541 dev++;
1542 return -ENOENT;
1543 }
1544
1545 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1546 if (NULL == card) { 1553 if (NULL == card) {
1547 snd_printk(KERN_ERR SFX "Error creating card!\n"); 1554 snd_printk(KERN_ERR SFX "Error creating card!\n");
1548 return -ENOMEM; 1555 return -ENOMEM;
1549 } 1556 }
1550 1557
1551 if ((err = azx_create(card, pci, position_fix[dev], pci_id->driver_data, 1558 if ((err = azx_create(card, pci, position_fix, pci_id->driver_data,
1552 &chip)) < 0) { 1559 &chip)) < 0) {
1553 snd_card_free(card); 1560 snd_card_free(card);
1554 return err; 1561 return err;
1555 } 1562 }
1556 1563
1557 /* create codec instances */ 1564 /* create codec instances */
1558 if ((err = azx_codec_create(chip, model[dev])) < 0) { 1565 if ((err = azx_codec_create(chip, model)) < 0) {
1559 snd_card_free(card); 1566 snd_card_free(card);
1560 return err; 1567 return err;
1561 } 1568 }
@@ -1581,7 +1588,6 @@ static int __devinit azx_probe(struct pci_dev *pci, const struct pci_device_id *
1581 } 1588 }
1582 1589
1583 pci_set_drvdata(pci, card); 1590 pci_set_drvdata(pci, card);
1584 dev++;
1585 1591
1586 return err; 1592 return err;
1587} 1593}
@@ -1601,6 +1607,8 @@ static struct pci_device_id azx_ids[] = {
1601 { 0x1106, 0x3288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_VIA }, /* VIA VT8251/VT8237A */ 1607 { 0x1106, 0x3288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_VIA }, /* VIA VT8251/VT8237A */
1602 { 0x1039, 0x7502, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SIS }, /* SIS966 */ 1608 { 0x1039, 0x7502, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SIS }, /* SIS966 */
1603 { 0x10b9, 0x5461, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ULI }, /* ULI M5461 */ 1609 { 0x10b9, 0x5461, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ULI }, /* ULI M5461 */
1610 { 0x10de, 0x026c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA 026c */
1611 { 0x10de, 0x0371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA 0371 */
1604 { 0, } 1612 { 0, }
1605}; 1613};
1606MODULE_DEVICE_TABLE(pci, azx_ids); 1614MODULE_DEVICE_TABLE(pci, azx_ids);
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 810cfd2d9bba..f51a56f813c8 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -27,28 +27,36 @@
27 * for mixer controls 27 * for mixer controls
28 */ 28 */
29#define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) ((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19)) 29#define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) ((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19))
30/* mono volume with index (index=0,1,...) (channel=1,2) */
30#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 31#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
31 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 32 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
32 .info = snd_hda_mixer_amp_volume_info, \ 33 .info = snd_hda_mixer_amp_volume_info, \
33 .get = snd_hda_mixer_amp_volume_get, \ 34 .get = snd_hda_mixer_amp_volume_get, \
34 .put = snd_hda_mixer_amp_volume_put, \ 35 .put = snd_hda_mixer_amp_volume_put, \
35 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) } 36 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
37/* stereo volume with index */
36#define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \ 38#define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \
37 HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction) 39 HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
40/* mono volume */
38#define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \ 41#define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \
39 HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction) 42 HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction)
43/* stereo volume */
40#define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \ 44#define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \
41 HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction) 45 HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction)
46/* mono mute switch with index (index=0,1,...) (channel=1,2) */
42#define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 47#define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
43 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 48 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
44 .info = snd_hda_mixer_amp_switch_info, \ 49 .info = snd_hda_mixer_amp_switch_info, \
45 .get = snd_hda_mixer_amp_switch_get, \ 50 .get = snd_hda_mixer_amp_switch_get, \
46 .put = snd_hda_mixer_amp_switch_put, \ 51 .put = snd_hda_mixer_amp_switch_put, \
47 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) } 52 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
53/* stereo mute switch with index */
48#define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \ 54#define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \
49 HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction) 55 HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
56/* mono mute switch */
50#define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \ 57#define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \
51 HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction) 58 HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction)
59/* stereo mute switch */
52#define HDA_CODEC_MUTE(xname, nid, xindex, direction) \ 60#define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
53 HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction) 61 HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
54 62
@@ -59,6 +67,20 @@ int snd_hda_mixer_amp_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
59int snd_hda_mixer_amp_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol); 67int snd_hda_mixer_amp_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
60int snd_hda_mixer_amp_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol); 68int snd_hda_mixer_amp_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
61 69
70/* mono switch binding multiple inputs */
71#define HDA_BIND_MUTE_MONO(xname, nid, channel, indices, direction) \
72 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
73 .info = snd_hda_mixer_amp_switch_info, \
74 .get = snd_hda_mixer_bind_switch_get, \
75 .put = snd_hda_mixer_bind_switch_put, \
76 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, indices, direction) }
77
78/* stereo switch binding multiple inputs */
79#define HDA_BIND_MUTE(xname,nid,indices,dir) HDA_BIND_MUTE_MONO(xname,nid,3,indices,dir)
80
81int snd_hda_mixer_bind_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
82int snd_hda_mixer_bind_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
83
62int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid); 84int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid);
63int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid); 85int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
64 86
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 08f6a6efc5e6..39ddf1cd9019 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -281,6 +281,11 @@ static void print_codec_info(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
281 print_pcm_caps(buffer, codec, nid); 281 print_pcm_caps(buffer, codec, nid);
282 } 282 }
283 283
284 if (wid_caps & AC_WCAP_POWER)
285 snd_iprintf(buffer, " Power: 0x%x\n",
286 snd_hda_codec_read(codec, nid, 0,
287 AC_VERB_GET_POWER_STATE, 0));
288
284 if (wid_caps & AC_WCAP_CONN_LIST) { 289 if (wid_caps & AC_WCAP_CONN_LIST) {
285 int c, curr = -1; 290 int c, curr = -1;
286 if (conn_len > 1 && wid_type != AC_WID_AUD_MIX) 291 if (conn_len > 1 && wid_type != AC_WID_AUD_MIX)
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index da6874d3988c..d7d636decef8 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -28,15 +28,38 @@
28#include "hda_local.h" 28#include "hda_local.h"
29 29
30struct ad198x_spec { 30struct ad198x_spec {
31 struct semaphore amp_mutex; /* PCM volume/mute control mutex */ 31 snd_kcontrol_new_t *mixers[5];
32 struct hda_multi_out multiout; /* playback */ 32 int num_mixers;
33 hda_nid_t adc_nid; 33
34 const struct hda_verb *init_verbs[3]; /* initialization verbs
35 * don't forget NULL termination!
36 */
37 unsigned int num_init_verbs;
38
39 /* playback */
40 struct hda_multi_out multiout; /* playback set-up
41 * max_channels, dacs must be set
42 * dig_out_nid and hp_nid are optional
43 */
44
45 /* capture */
46 unsigned int num_adc_nids;
47 hda_nid_t *adc_nids;
48 hda_nid_t dig_in_nid; /* digital-in NID; optional */
49
50 /* capture source */
34 const struct hda_input_mux *input_mux; 51 const struct hda_input_mux *input_mux;
35 unsigned int cur_mux; /* capture source */ 52 unsigned int cur_mux[3];
53
54 /* channel model */
55 const struct alc_channel_mode *channel_mode;
56 int num_channel_mode;
57
58 /* PCM information */
59 struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */
60
61 struct semaphore amp_mutex; /* PCM volume/mute control mutex */
36 unsigned int spdif_route; 62 unsigned int spdif_route;
37 snd_kcontrol_new_t *mixers;
38 const struct hda_verb *init_verbs;
39 struct hda_pcm pcm_rec[2]; /* PCM information */
40}; 63};
41 64
42/* 65/*
@@ -54,8 +77,9 @@ static int ad198x_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u
54{ 77{
55 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 78 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
56 struct ad198x_spec *spec = codec->spec; 79 struct ad198x_spec *spec = codec->spec;
80 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
57 81
58 ucontrol->value.enumerated.item[0] = spec->cur_mux; 82 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
59 return 0; 83 return 0;
60} 84}
61 85
@@ -63,9 +87,10 @@ static int ad198x_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u
63{ 87{
64 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 88 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
65 struct ad198x_spec *spec = codec->spec; 89 struct ad198x_spec *spec = codec->spec;
90 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
66 91
67 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 92 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
68 spec->adc_nid, &spec->cur_mux); 93 spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);
69} 94}
70 95
71/* 96/*
@@ -74,22 +99,34 @@ static int ad198x_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u
74static int ad198x_init(struct hda_codec *codec) 99static int ad198x_init(struct hda_codec *codec)
75{ 100{
76 struct ad198x_spec *spec = codec->spec; 101 struct ad198x_spec *spec = codec->spec;
77 snd_hda_sequence_write(codec, spec->init_verbs); 102 int i;
103
104 for (i = 0; i < spec->num_init_verbs; i++)
105 snd_hda_sequence_write(codec, spec->init_verbs[i]);
78 return 0; 106 return 0;
79} 107}
80 108
81static int ad198x_build_controls(struct hda_codec *codec) 109static int ad198x_build_controls(struct hda_codec *codec)
82{ 110{
83 struct ad198x_spec *spec = codec->spec; 111 struct ad198x_spec *spec = codec->spec;
112 unsigned int i;
84 int err; 113 int err;
85 114
86 err = snd_hda_add_new_ctls(codec, spec->mixers); 115 for (i = 0; i < spec->num_mixers; i++) {
87 if (err < 0) 116 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
88 return err; 117 if (err < 0)
89 if (spec->multiout.dig_out_nid) 118 return err;
119 }
120 if (spec->multiout.dig_out_nid) {
90 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 121 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
91 if (err < 0) 122 if (err < 0)
92 return err; 123 return err;
124 }
125 if (spec->dig_in_nid) {
126 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
127 if (err < 0)
128 return err;
129 }
93 return 0; 130 return 0;
94} 131}
95 132
@@ -152,7 +189,8 @@ static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
152 snd_pcm_substream_t *substream) 189 snd_pcm_substream_t *substream)
153{ 190{
154 struct ad198x_spec *spec = codec->spec; 191 struct ad198x_spec *spec = codec->spec;
155 snd_hda_codec_setup_stream(codec, spec->adc_nid, stream_tag, 0, format); 192 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
193 stream_tag, 0, format);
156 return 0; 194 return 0;
157} 195}
158 196
@@ -161,7 +199,8 @@ static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
161 snd_pcm_substream_t *substream) 199 snd_pcm_substream_t *substream)
162{ 200{
163 struct ad198x_spec *spec = codec->spec; 201 struct ad198x_spec *spec = codec->spec;
164 snd_hda_codec_setup_stream(codec, spec->adc_nid, 0, 0, 0); 202 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
203 0, 0, 0);
165 return 0; 204 return 0;
166} 205}
167 206
@@ -171,7 +210,7 @@ static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
171static struct hda_pcm_stream ad198x_pcm_analog_playback = { 210static struct hda_pcm_stream ad198x_pcm_analog_playback = {
172 .substreams = 1, 211 .substreams = 1,
173 .channels_min = 2, 212 .channels_min = 2,
174 .channels_max = 6, 213 .channels_max = 6, /* changed later */
175 .nid = 0, /* fill later */ 214 .nid = 0, /* fill later */
176 .ops = { 215 .ops = {
177 .open = ad198x_playback_pcm_open, 216 .open = ad198x_playback_pcm_open,
@@ -181,7 +220,7 @@ static struct hda_pcm_stream ad198x_pcm_analog_playback = {
181}; 220};
182 221
183static struct hda_pcm_stream ad198x_pcm_analog_capture = { 222static struct hda_pcm_stream ad198x_pcm_analog_capture = {
184 .substreams = 2, 223 .substreams = 1,
185 .channels_min = 2, 224 .channels_min = 2,
186 .channels_max = 2, 225 .channels_max = 2,
187 .nid = 0, /* fill later */ 226 .nid = 0, /* fill later */
@@ -202,6 +241,13 @@ static struct hda_pcm_stream ad198x_pcm_digital_playback = {
202 }, 241 },
203}; 242};
204 243
244static struct hda_pcm_stream ad198x_pcm_digital_capture = {
245 .substreams = 1,
246 .channels_min = 2,
247 .channels_max = 2,
248 /* NID is set in alc_build_pcms */
249};
250
205static int ad198x_build_pcms(struct hda_codec *codec) 251static int ad198x_build_pcms(struct hda_codec *codec)
206{ 252{
207 struct ad198x_spec *spec = codec->spec; 253 struct ad198x_spec *spec = codec->spec;
@@ -215,7 +261,8 @@ static int ad198x_build_pcms(struct hda_codec *codec)
215 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels; 261 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
216 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; 262 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
217 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture; 263 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
218 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nid; 264 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
265 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
219 266
220 if (spec->multiout.dig_out_nid) { 267 if (spec->multiout.dig_out_nid) {
221 info++; 268 info++;
@@ -223,6 +270,10 @@ static int ad198x_build_pcms(struct hda_codec *codec)
223 info->name = "AD198x Digital"; 270 info->name = "AD198x Digital";
224 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback; 271 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
225 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 272 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
273 if (spec->dig_in_nid) {
274 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
275 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
276 }
226 } 277 }
227 278
228 return 0; 279 return 0;
@@ -237,10 +288,15 @@ static void ad198x_free(struct hda_codec *codec)
237static int ad198x_resume(struct hda_codec *codec) 288static int ad198x_resume(struct hda_codec *codec)
238{ 289{
239 struct ad198x_spec *spec = codec->spec; 290 struct ad198x_spec *spec = codec->spec;
291 int i;
240 292
241 ad198x_init(codec); 293 ad198x_init(codec);
242 snd_hda_resume_ctls(codec, spec->mixers); 294 for (i = 0; i < spec->num_mixers; i++)
243 snd_hda_resume_spdif_out(codec); 295 snd_hda_resume_ctls(codec, spec->mixers[i]);
296 if (spec->multiout.dig_out_nid)
297 snd_hda_resume_spdif_out(codec);
298 if (spec->dig_in_nid)
299 snd_hda_resume_spdif_in(codec);
244 return 0; 300 return 0;
245} 301}
246#endif 302#endif
@@ -269,6 +325,7 @@ static struct hda_codec_ops ad198x_patch_ops = {
269static hda_nid_t ad1986a_dac_nids[3] = { 325static hda_nid_t ad1986a_dac_nids[3] = {
270 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC 326 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
271}; 327};
328static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
272 329
273static struct hda_input_mux ad1986a_capture_source = { 330static struct hda_input_mux ad1986a_capture_source = {
274 .num_items = 7, 331 .num_items = 7,
@@ -476,10 +533,13 @@ static int patch_ad1986a(struct hda_codec *codec)
476 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids); 533 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
477 spec->multiout.dac_nids = ad1986a_dac_nids; 534 spec->multiout.dac_nids = ad1986a_dac_nids;
478 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT; 535 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
479 spec->adc_nid = AD1986A_ADC; 536 spec->num_adc_nids = 1;
537 spec->adc_nids = ad1986a_adc_nids;
480 spec->input_mux = &ad1986a_capture_source; 538 spec->input_mux = &ad1986a_capture_source;
481 spec->mixers = ad1986a_mixers; 539 spec->num_mixers = 1;
482 spec->init_verbs = ad1986a_init_verbs; 540 spec->mixers[0] = ad1986a_mixers;
541 spec->num_init_verbs = 1;
542 spec->init_verbs[0] = ad1986a_init_verbs;
483 543
484 codec->patch_ops = ad198x_patch_ops; 544 codec->patch_ops = ad198x_patch_ops;
485 545
@@ -495,6 +555,7 @@ static int patch_ad1986a(struct hda_codec *codec)
495#define AD1983_ADC 0x04 555#define AD1983_ADC 0x04
496 556
497static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC }; 557static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
558static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
498 559
499static struct hda_input_mux ad1983_capture_source = { 560static struct hda_input_mux ad1983_capture_source = {
500 .num_items = 4, 561 .num_items = 4,
@@ -619,6 +680,7 @@ static struct hda_verb ad1983_init_verbs[] = {
619 { } /* end */ 680 { } /* end */
620}; 681};
621 682
683
622static int patch_ad1983(struct hda_codec *codec) 684static int patch_ad1983(struct hda_codec *codec)
623{ 685{
624 struct ad198x_spec *spec; 686 struct ad198x_spec *spec;
@@ -634,10 +696,13 @@ static int patch_ad1983(struct hda_codec *codec)
634 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids); 696 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
635 spec->multiout.dac_nids = ad1983_dac_nids; 697 spec->multiout.dac_nids = ad1983_dac_nids;
636 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT; 698 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
637 spec->adc_nid = AD1983_ADC; 699 spec->num_adc_nids = 1;
700 spec->adc_nids = ad1983_adc_nids;
638 spec->input_mux = &ad1983_capture_source; 701 spec->input_mux = &ad1983_capture_source;
639 spec->mixers = ad1983_mixers; 702 spec->num_mixers = 1;
640 spec->init_verbs = ad1983_init_verbs; 703 spec->mixers[0] = ad1983_mixers;
704 spec->num_init_verbs = 1;
705 spec->init_verbs[0] = ad1983_init_verbs;
641 spec->spdif_route = 0; 706 spec->spdif_route = 0;
642 707
643 codec->patch_ops = ad198x_patch_ops; 708 codec->patch_ops = ad198x_patch_ops;
@@ -655,6 +720,7 @@ static int patch_ad1983(struct hda_codec *codec)
655#define AD1981_ADC 0x04 720#define AD1981_ADC 0x04
656 721
657static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC }; 722static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
723static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
658 724
659/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */ 725/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
660static struct hda_input_mux ad1981_capture_source = { 726static struct hda_input_mux ad1981_capture_source = {
@@ -775,10 +841,13 @@ static int patch_ad1981(struct hda_codec *codec)
775 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids); 841 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
776 spec->multiout.dac_nids = ad1981_dac_nids; 842 spec->multiout.dac_nids = ad1981_dac_nids;
777 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT; 843 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
778 spec->adc_nid = AD1981_ADC; 844 spec->num_adc_nids = 1;
845 spec->adc_nids = ad1981_adc_nids;
779 spec->input_mux = &ad1981_capture_source; 846 spec->input_mux = &ad1981_capture_source;
780 spec->mixers = ad1981_mixers; 847 spec->num_mixers = 1;
781 spec->init_verbs = ad1981_init_verbs; 848 spec->mixers[0] = ad1981_mixers;
849 spec->num_init_verbs = 1;
850 spec->init_verbs[0] = ad1981_init_verbs;
782 spec->spdif_route = 0; 851 spec->spdif_route = 0;
783 852
784 codec->patch_ops = ad198x_patch_ops; 853 codec->patch_ops = ad198x_patch_ops;
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 7327deb6df9f..cffb83fdcff7 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -57,6 +57,7 @@ enum {
57enum { 57enum {
58 ALC260_BASIC, 58 ALC260_BASIC,
59 ALC260_HP, 59 ALC260_HP,
60 ALC260_FUJITSU_S702x,
60 ALC260_MODEL_LAST /* last tag */ 61 ALC260_MODEL_LAST /* last tag */
61}; 62};
62 63
@@ -72,6 +73,7 @@ enum {
72#define PIN_VREF50 0x21 73#define PIN_VREF50 0x21
73#define PIN_OUT 0x40 74#define PIN_OUT 0x40
74#define PIN_HP 0xc0 75#define PIN_HP 0xc0
76#define PIN_HP_AMP 0x80
75 77
76struct alc_spec { 78struct alc_spec {
77 /* codec parameterization */ 79 /* codec parameterization */
@@ -113,8 +115,6 @@ struct alc_spec {
113 /* PCM information */ 115 /* PCM information */
114 struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */ 116 struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */
115 117
116 struct semaphore bind_mutex; /* for bound controls */
117
118 /* dynamic controls, init_verbs and input_mux */ 118 /* dynamic controls, init_verbs and input_mux */
119 struct auto_pin_cfg autocfg; 119 struct auto_pin_cfg autocfg;
120 unsigned int num_kctl_alloc, num_kctl_used; 120 unsigned int num_kctl_alloc, num_kctl_used;
@@ -218,72 +218,53 @@ static int alc880_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *uc
218 218
219 219
220/* 220/*
221 * bound volume controls 221 * Control of pin widget settings via the mixer. Only boolean settings are
222 * 222 * supported, so VrefEn can't be controlled using these functions as they
223 * bind multiple volumes (# indices, from 0) 223 * stand.
224 */ 224 */
225 225static int alc_pinctl_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
226#define AMP_VAL_IDX_SHIFT 19
227#define AMP_VAL_IDX_MASK (0x0f<<19)
228
229static int alc_bind_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
230{ 226{
231 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 227 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
232 struct alc_spec *spec = codec->spec; 228 uinfo->count = 1;
233 unsigned long pval; 229 uinfo->value.integer.min = 0;
234 230 uinfo->value.integer.max = 1;
235 down(&spec->bind_mutex);
236 pval = kcontrol->private_value;
237 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
238 snd_hda_mixer_amp_switch_info(kcontrol, uinfo);
239 kcontrol->private_value = pval;
240 up(&spec->bind_mutex);
241 return 0; 231 return 0;
242} 232}
243 233
244static int alc_bind_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 234static int alc_pinctl_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
245{ 235{
246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 236 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
247 struct alc_spec *spec = codec->spec; 237 hda_nid_t nid = kcontrol->private_value & 0xffff;
248 unsigned long pval; 238 long mask = (kcontrol->private_value >> 16) & 0xff;
249 239 long *valp = ucontrol->value.integer.value;
250 down(&spec->bind_mutex); 240
251 pval = kcontrol->private_value; 241 *valp = 0;
252 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */ 242 if (snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00) & mask)
253 snd_hda_mixer_amp_switch_get(kcontrol, ucontrol); 243 *valp = 1;
254 kcontrol->private_value = pval;
255 up(&spec->bind_mutex);
256 return 0; 244 return 0;
257} 245}
258 246
259static int alc_bind_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 247static int alc_pinctl_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
260{ 248{
261 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 249 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
262 struct alc_spec *spec = codec->spec; 250 hda_nid_t nid = kcontrol->private_value & 0xffff;
263 unsigned long pval; 251 long mask = (kcontrol->private_value >> 16) & 0xff;
264 int i, indices, change = 0; 252 long *valp = ucontrol->value.integer.value;
265 253 unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);
266 down(&spec->bind_mutex); 254 int change = ((pinctl & mask)!=0) != *valp;
267 pval = kcontrol->private_value; 255
268 indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT; 256 if (change)
269 for (i = 0; i < indices; i++) { 257 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
270 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) | (i << AMP_VAL_IDX_SHIFT); 258 *valp?(pinctl|mask):(pinctl&~mask));
271 change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
272 }
273 kcontrol->private_value = pval;
274 up(&spec->bind_mutex);
275 return change; 259 return change;
276} 260}
277 261
278#define ALC_BIND_MUTE_MONO(xname, nid, channel, indices, direction) \ 262#define ALC_PINCTL_SWITCH(xname, nid, mask) \
279 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 263 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
280 .info = alc_bind_switch_info, \ 264 .info = alc_pinctl_switch_info, \
281 .get = alc_bind_switch_get, \ 265 .get = alc_pinctl_switch_get, \
282 .put = alc_bind_switch_put, \ 266 .put = alc_pinctl_switch_put, \
283 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, indices, direction) } 267 .private_value = (nid) | (mask<<16) }
284
285#define ALC_BIND_MUTE(xname,nid,indices,dir) ALC_BIND_MUTE_MONO(xname,nid,3,indices,dir)
286
287 268
288/* 269/*
289 * ALC880 3-stack model 270 * ALC880 3-stack model
@@ -354,13 +335,13 @@ static struct alc_channel_mode alc880_threestack_modes[2] = {
354 335
355static snd_kcontrol_new_t alc880_three_stack_mixer[] = { 336static snd_kcontrol_new_t alc880_three_stack_mixer[] = {
356 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 337 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
357 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 338 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
358 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 339 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
359 ALC_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT), 340 HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
360 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT), 341 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
361 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 342 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
362 ALC_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT), 343 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
363 ALC_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT), 344 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
364 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 345 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
365 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 346 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
366 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 347 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
@@ -441,7 +422,7 @@ static snd_kcontrol_new_t alc880_capture_alt_mixer[] = {
441/* additional mixers to alc880_three_stack_mixer */ 422/* additional mixers to alc880_three_stack_mixer */
442static snd_kcontrol_new_t alc880_five_stack_mixer[] = { 423static snd_kcontrol_new_t alc880_five_stack_mixer[] = {
443 HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 424 HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
444 ALC_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT), 425 HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
445 { } /* end */ 426 { } /* end */
446}; 427};
447 428
@@ -498,15 +479,15 @@ static struct alc_channel_mode alc880_sixstack_modes[1] = {
498 479
499static snd_kcontrol_new_t alc880_six_stack_mixer[] = { 480static snd_kcontrol_new_t alc880_six_stack_mixer[] = {
500 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 481 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
501 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 482 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
502 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 483 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
503 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 484 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
504 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT), 485 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
505 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 486 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
506 ALC_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT), 487 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
507 ALC_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT), 488 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
508 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 489 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
509 ALC_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT), 490 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
510 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 491 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
511 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 492 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
512 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 493 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
@@ -566,13 +547,13 @@ static struct alc_channel_mode alc880_w810_modes[1] = {
566/* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */ 547/* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
567static snd_kcontrol_new_t alc880_w810_base_mixer[] = { 548static snd_kcontrol_new_t alc880_w810_base_mixer[] = {
568 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 549 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
569 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 550 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
570 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 551 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
571 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 552 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
572 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT), 553 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
573 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 554 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
574 ALC_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT), 555 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
575 ALC_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT), 556 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
576 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 557 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
577 { } /* end */ 558 { } /* end */
578}; 559};
@@ -597,9 +578,9 @@ static struct alc_channel_mode alc880_2_jack_modes[1] = {
597 578
598static snd_kcontrol_new_t alc880_z71v_mixer[] = { 579static snd_kcontrol_new_t alc880_z71v_mixer[] = {
599 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 580 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
600 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 581 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
601 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 582 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
602 ALC_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT), 583 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
603 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 584 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
604 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 585 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
605 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 586 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
@@ -623,9 +604,9 @@ static hda_nid_t alc880_f1734_dac_nids[1] = {
623 604
624static snd_kcontrol_new_t alc880_f1734_mixer[] = { 605static snd_kcontrol_new_t alc880_f1734_mixer[] = {
625 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 606 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
626 ALC_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT), 607 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
627 HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 608 HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
628 ALC_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT), 609 HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
629 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 610 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
630 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 611 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
631 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 612 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
@@ -648,13 +629,13 @@ static snd_kcontrol_new_t alc880_f1734_mixer[] = {
648 629
649static snd_kcontrol_new_t alc880_asus_mixer[] = { 630static snd_kcontrol_new_t alc880_asus_mixer[] = {
650 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 631 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
651 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 632 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
652 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 633 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
653 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 634 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
654 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT), 635 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
655 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 636 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
656 ALC_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT), 637 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
657 ALC_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT), 638 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
658 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 639 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
659 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 640 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
660 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 641 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
@@ -1383,10 +1364,10 @@ static snd_kcontrol_new_t alc880_test_mixer[] = {
1383 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 1364 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1384 HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT), 1365 HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
1385 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 1366 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1386 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 1367 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1387 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 1368 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1388 ALC_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT), 1369 HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
1389 ALC_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT), 1370 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1390 PIN_CTL_TEST("Front Pin Mode", 0x14), 1371 PIN_CTL_TEST("Front Pin Mode", 0x14),
1391 PIN_CTL_TEST("Surround Pin Mode", 0x15), 1372 PIN_CTL_TEST("Surround Pin Mode", 0x15),
1392 PIN_CTL_TEST("CLFE Pin Mode", 0x16), 1373 PIN_CTL_TEST("CLFE Pin Mode", 0x16),
@@ -1769,7 +1750,7 @@ enum {
1769static snd_kcontrol_new_t alc880_control_templates[] = { 1750static snd_kcontrol_new_t alc880_control_templates[] = {
1770 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 1751 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1771 HDA_CODEC_MUTE(NULL, 0, 0, 0), 1752 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1772 ALC_BIND_MUTE(NULL, 0, 0, 0), 1753 HDA_BIND_MUTE(NULL, 0, 0, 0),
1773}; 1754};
1774 1755
1775/* add dynamic controls */ 1756/* add dynamic controls */
@@ -2087,7 +2068,6 @@ static int patch_alc880(struct hda_codec *codec)
2087 if (spec == NULL) 2068 if (spec == NULL)
2088 return -ENOMEM; 2069 return -ENOMEM;
2089 2070
2090 init_MUTEX(&spec->bind_mutex);
2091 codec->spec = spec; 2071 codec->spec = spec;
2092 2072
2093 board_config = snd_hda_check_board_config(codec, alc880_cfg_tbl); 2073 board_config = snd_hda_check_board_config(codec, alc880_cfg_tbl);
@@ -2205,6 +2185,17 @@ static struct hda_input_mux alc260_capture_source = {
2205 }, 2185 },
2206}; 2186};
2207 2187
2188/* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack
2189 * and the internal CD lines.
2190 */
2191static struct hda_input_mux alc260_fujitsu_capture_source = {
2192 .num_items = 2,
2193 .items = {
2194 { "Mic/Line", 0x0 },
2195 { "CD", 0x4 },
2196 },
2197};
2198
2208/* 2199/*
2209 * This is just place-holder, so there's something for alc_build_pcms to look 2200 * This is just place-holder, so there's something for alc_build_pcms to look
2210 * at when it calculates the maximum number of channels. ALC260 has no mixer 2201 * at when it calculates the maximum number of channels. ALC260 has no mixer
@@ -2217,7 +2208,7 @@ static struct alc_channel_mode alc260_modes[1] = {
2217 2208
2218static snd_kcontrol_new_t alc260_base_mixer[] = { 2209static snd_kcontrol_new_t alc260_base_mixer[] = {
2219 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT), 2210 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
2220 ALC_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT), 2211 HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
2221 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT), 2212 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
2222 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT), 2213 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
2223 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT), 2214 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
@@ -2229,9 +2220,9 @@ static snd_kcontrol_new_t alc260_base_mixer[] = {
2229 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT), 2220 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
2230 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT), 2221 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
2231 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT), 2222 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
2232 ALC_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT), 2223 HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
2233 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT), 2224 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2234 ALC_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT), 2225 HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
2235 HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT), 2226 HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
2236 HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT), 2227 HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
2237 { 2228 {
@@ -2246,7 +2237,7 @@ static snd_kcontrol_new_t alc260_base_mixer[] = {
2246 2237
2247static snd_kcontrol_new_t alc260_hp_mixer[] = { 2238static snd_kcontrol_new_t alc260_hp_mixer[] = {
2248 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT), 2239 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
2249 ALC_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT), 2240 HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
2250 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT), 2241 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
2251 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT), 2242 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
2252 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT), 2243 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
@@ -2256,9 +2247,9 @@ static snd_kcontrol_new_t alc260_hp_mixer[] = {
2256 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT), 2247 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
2257 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT), 2248 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
2258 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT), 2249 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
2259 ALC_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT), 2250 HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
2260 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT), 2251 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2261 ALC_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT), 2252 HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
2262 HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT), 2253 HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
2263 HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT), 2254 HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
2264 { 2255 {
@@ -2271,6 +2262,30 @@ static snd_kcontrol_new_t alc260_hp_mixer[] = {
2271 { } /* end */ 2262 { } /* end */
2272}; 2263};
2273 2264
2265static snd_kcontrol_new_t alc260_fujitsu_mixer[] = {
2266 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
2267 HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
2268 ALC_PINCTL_SWITCH("Headphone Amp Switch", 0x14, PIN_HP_AMP),
2269 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
2270 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
2271 HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
2272 HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
2273 HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
2274 HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
2275 HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
2276 HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
2277 HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
2278 HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
2279 {
2280 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2281 .name = "Capture Source",
2282 .info = alc_mux_enum_info,
2283 .get = alc_mux_enum_get,
2284 .put = alc_mux_enum_put,
2285 },
2286 { } /* end */
2287};
2288
2274static struct hda_verb alc260_init_verbs[] = { 2289static struct hda_verb alc260_init_verbs[] = {
2275 /* Line In pin widget for input */ 2290 /* Line In pin widget for input */
2276 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2291 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
@@ -2332,6 +2347,60 @@ static struct hda_verb alc260_init_verbs[] = {
2332 { } 2347 { }
2333}; 2348};
2334 2349
2350/* Initialisation sequence for ALC260 as configured in Fujitsu S702x
2351 * laptops.
2352 */
2353static struct hda_verb alc260_fujitsu_init_verbs[] = {
2354 /* Disable all GPIOs */
2355 {0x01, AC_VERB_SET_GPIO_MASK, 0},
2356 /* Internal speaker is connected to headphone pin */
2357 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2358 /* Headphone/Line-out jack connects to Line1 pin; make it an output */
2359 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2360 /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
2361 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2362 /* Ensure all other unused pins are disabled and muted.
2363 * Note: trying to set widget 0x15 to anything blocks all audio
2364 * output for some reason, so just leave that at the default.
2365 */
2366 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2367 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2368 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2369 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2370 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2371 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2372 /* Disable digital (SPDIF) pins */
2373 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
2374 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
2375
2376 /* Start with mixer outputs muted */
2377 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2378 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2379 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2380
2381 /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
2382 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2383 /* Unmute Line1 pin widget amp left and right (no equiv mixer ctrl) */
2384 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2385 /* Unmute pin widget used for Line-in (no equiv mixer ctrl) */
2386 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2387
2388 /* Mute capture amp left and right */
2389 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2390 /* Set ADC connection select to line in (on mic1 pin) */
2391 {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
2392
2393 /* Mute all inputs to mixer widget (even unconnected ones) */
2394 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
2395 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
2396 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
2397 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
2398 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
2399 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
2400 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
2401 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
2402};
2403
2335static struct hda_pcm_stream alc260_pcm_analog_playback = { 2404static struct hda_pcm_stream alc260_pcm_analog_playback = {
2336 .substreams = 1, 2405 .substreams = 1,
2337 .channels_min = 2, 2406 .channels_min = 2,
@@ -2347,6 +2416,8 @@ static struct hda_pcm_stream alc260_pcm_analog_capture = {
2347static struct hda_board_config alc260_cfg_tbl[] = { 2416static struct hda_board_config alc260_cfg_tbl[] = {
2348 { .modelname = "hp", .config = ALC260_HP }, 2417 { .modelname = "hp", .config = ALC260_HP },
2349 { .pci_subvendor = 0x103c, .config = ALC260_HP }, 2418 { .pci_subvendor = 0x103c, .config = ALC260_HP },
2419 { .modelname = "fujitsu", .config = ALC260_FUJITSU_S702x },
2420 { .pci_subvendor = 0x10cf, .pci_subdevice = 0x1326, .config = ALC260_FUJITSU_S702x },
2350 {} 2421 {}
2351}; 2422};
2352 2423
@@ -2359,7 +2430,6 @@ static int patch_alc260(struct hda_codec *codec)
2359 if (spec == NULL) 2430 if (spec == NULL)
2360 return -ENOMEM; 2431 return -ENOMEM;
2361 2432
2362 init_MUTEX(&spec->bind_mutex);
2363 codec->spec = spec; 2433 codec->spec = spec;
2364 2434
2365 board_config = snd_hda_check_board_config(codec, alc260_cfg_tbl); 2435 board_config = snd_hda_check_board_config(codec, alc260_cfg_tbl);
@@ -2373,14 +2443,23 @@ static int patch_alc260(struct hda_codec *codec)
2373 spec->mixers[spec->num_mixers] = alc260_hp_mixer; 2443 spec->mixers[spec->num_mixers] = alc260_hp_mixer;
2374 spec->num_mixers++; 2444 spec->num_mixers++;
2375 break; 2445 break;
2446 case ALC260_FUJITSU_S702x:
2447 spec->mixers[spec->num_mixers] = alc260_fujitsu_mixer;
2448 spec->num_mixers++;
2449 break;
2376 default: 2450 default:
2377 spec->mixers[spec->num_mixers] = alc260_base_mixer; 2451 spec->mixers[spec->num_mixers] = alc260_base_mixer;
2378 spec->num_mixers++; 2452 spec->num_mixers++;
2379 break; 2453 break;
2380 } 2454 }
2381 2455
2382 spec->init_verbs[0] = alc260_init_verbs; 2456 if (board_config != ALC260_FUJITSU_S702x) {
2383 spec->num_init_verbs = 1; 2457 spec->init_verbs[0] = alc260_init_verbs;
2458 spec->num_init_verbs = 1;
2459 } else {
2460 spec->init_verbs[0] = alc260_fujitsu_init_verbs;
2461 spec->num_init_verbs = 1;
2462 }
2384 2463
2385 spec->channel_mode = alc260_modes; 2464 spec->channel_mode = alc260_modes;
2386 spec->num_channel_mode = ARRAY_SIZE(alc260_modes); 2465 spec->num_channel_mode = ARRAY_SIZE(alc260_modes);
@@ -2393,7 +2472,11 @@ static int patch_alc260(struct hda_codec *codec)
2393 spec->multiout.num_dacs = ARRAY_SIZE(alc260_dac_nids); 2472 spec->multiout.num_dacs = ARRAY_SIZE(alc260_dac_nids);
2394 spec->multiout.dac_nids = alc260_dac_nids; 2473 spec->multiout.dac_nids = alc260_dac_nids;
2395 2474
2396 spec->input_mux = &alc260_capture_source; 2475 if (board_config != ALC260_FUJITSU_S702x) {
2476 spec->input_mux = &alc260_capture_source;
2477 } else {
2478 spec->input_mux = &alc260_fujitsu_capture_source;
2479 }
2397 switch (board_config) { 2480 switch (board_config) {
2398 case ALC260_HP: 2481 case ALC260_HP:
2399 spec->num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids); 2482 spec->num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids);
@@ -2483,15 +2566,15 @@ static int alc882_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u
2483 */ 2566 */
2484static snd_kcontrol_new_t alc882_base_mixer[] = { 2567static snd_kcontrol_new_t alc882_base_mixer[] = {
2485 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 2568 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2486 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 2569 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2487 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 2570 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2488 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 2571 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2489 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT), 2572 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2490 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 2573 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2491 ALC_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT), 2574 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2492 ALC_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT), 2575 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2493 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 2576 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2494 ALC_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT), 2577 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2495 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 2578 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2496 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 2579 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2497 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 2580 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
@@ -2609,7 +2692,6 @@ static int patch_alc882(struct hda_codec *codec)
2609 if (spec == NULL) 2692 if (spec == NULL)
2610 return -ENOMEM; 2693 return -ENOMEM;
2611 2694
2612 init_MUTEX(&spec->bind_mutex);
2613 codec->spec = spec; 2695 codec->spec = spec;
2614 2696
2615 spec->mixers[spec->num_mixers] = alc882_base_mixer; 2697 spec->mixers[spec->num_mixers] = alc882_base_mixer;
diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c
index d014b7bb70df..9c7fe0b3200a 100644
--- a/sound/pci/hda/patch_si3054.c
+++ b/sound/pci/hda/patch_si3054.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * HD audio interface patch for Silicon Labs 3054/5 modem codec 4 * HD audio interface patch for Silicon Labs 3054/5 modem codec
5 * 5 *
6 * Copyright (c) 2005 Sasha Khapyorsky <sashak@smlink.com> 6 * Copyright (c) 2005 Sasha Khapyorsky <sashak@alsa-project.org>
7 * Takashi Iwai <tiwai@suse.de> 7 * Takashi Iwai <tiwai@suse.de>
8 * 8 *
9 * 9 *
diff --git a/sound/pci/ice1712/aureon.c b/sound/pci/ice1712/aureon.c
index 2e0a31613ee6..db12b038286b 100644
--- a/sound/pci/ice1712/aureon.c
+++ b/sound/pci/ice1712/aureon.c
@@ -960,7 +960,7 @@ static int wm_adc_mux_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucont
960 if (change) 960 if (change)
961 wm_put(ice, WM_ADC_MUX, nval); 961 wm_put(ice, WM_ADC_MUX, nval);
962 snd_ice1712_restore_gpio_status(ice); 962 snd_ice1712_restore_gpio_status(ice);
963 return 0; 963 return change;
964} 964}
965 965
966/* 966/*
@@ -1672,9 +1672,9 @@ static int __devinit aureon_add_controls(ice1712_t *ice)
1672 snd_ice1712_save_gpio_status(ice); 1672 snd_ice1712_save_gpio_status(ice);
1673 id = aureon_cs8415_get(ice, CS8415_ID); 1673 id = aureon_cs8415_get(ice, CS8415_ID);
1674 if (id != 0x41) 1674 if (id != 0x41)
1675 snd_printk("No CS8415 chip. Skipping CS8415 controls.\n"); 1675 snd_printk(KERN_INFO "No CS8415 chip. Skipping CS8415 controls.\n");
1676 else if ((id & 0x0F) != 0x01) 1676 else if ((id & 0x0F) != 0x01)
1677 snd_printk("Detected unsupported CS8415 rev. (%c)\n", (char)((id & 0x0F) + 'A' - 1)); 1677 snd_printk(KERN_INFO "Detected unsupported CS8415 rev. (%c)\n", (char)((id & 0x0F) + 'A' - 1));
1678 else { 1678 else {
1679 for (i = 0; i< ARRAY_SIZE(cs8415_controls); i++) { 1679 for (i = 0; i< ARRAY_SIZE(cs8415_controls); i++) {
1680 snd_kcontrol_t *kctl; 1680 snd_kcontrol_t *kctl;
diff --git a/sound/pci/ice1712/delta.c b/sound/pci/ice1712/delta.c
index 39fbe662965d..576f69d482c9 100644
--- a/sound/pci/ice1712/delta.c
+++ b/sound/pci/ice1712/delta.c
@@ -546,7 +546,7 @@ static int __devinit snd_ice1712_delta_init(ice1712_t *ice)
546 case ICE1712_SUBDEVICE_DELTA1010LT: 546 case ICE1712_SUBDEVICE_DELTA1010LT:
547 case ICE1712_SUBDEVICE_VX442: 547 case ICE1712_SUBDEVICE_VX442:
548 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { 548 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
549 snd_printk("unable to create I2C bus\n"); 549 snd_printk(KERN_ERR "unable to create I2C bus\n");
550 return err; 550 return err;
551 } 551 }
552 ice->i2c->private_data = ice; 552 ice->i2c->private_data = ice;
diff --git a/sound/pci/ice1712/ews.c b/sound/pci/ice1712/ews.c
index e36efa1bdac3..c8ec5cac3c17 100644
--- a/sound/pci/ice1712/ews.c
+++ b/sound/pci/ice1712/ews.c
@@ -438,7 +438,7 @@ static int __devinit snd_ice1712_ews_init(ice1712_t *ice)
438 438
439 /* create i2c */ 439 /* create i2c */
440 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { 440 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
441 snd_printk("unable to create I2C bus\n"); 441 snd_printk(KERN_ERR "unable to create I2C bus\n");
442 return err; 442 return err;
443 } 443 }
444 ice->i2c->private_data = ice; 444 ice->i2c->private_data = ice;
@@ -448,7 +448,7 @@ static int __devinit snd_ice1712_ews_init(ice1712_t *ice)
448 switch (ice->eeprom.subvendor) { 448 switch (ice->eeprom.subvendor) {
449 case ICE1712_SUBDEVICE_DMX6FIRE: 449 case ICE1712_SUBDEVICE_DMX6FIRE:
450 if ((err = snd_i2c_device_create(ice->i2c, "PCF9554", ICE1712_6FIRE_PCF9554_ADDR, &ice->spec.i2cdevs[EWS_I2C_6FIRE])) < 0) { 450 if ((err = snd_i2c_device_create(ice->i2c, "PCF9554", ICE1712_6FIRE_PCF9554_ADDR, &ice->spec.i2cdevs[EWS_I2C_6FIRE])) < 0) {
451 snd_printk("PCF9554 initialization failed\n"); 451 snd_printk(KERN_ERR "PCF9554 initialization failed\n");
452 return err; 452 return err;
453 } 453 }
454 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80); 454 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
@@ -791,7 +791,7 @@ static int snd_ice1712_6fire_read_pca(ice1712_t *ice, unsigned char reg)
791 byte = 0; 791 byte = 0;
792 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) { 792 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
793 snd_i2c_unlock(ice->i2c); 793 snd_i2c_unlock(ice->i2c);
794 printk("cannot read pca\n"); 794 printk(KERN_ERR "cannot read pca\n");
795 return -EIO; 795 return -EIO;
796 } 796 }
797 snd_i2c_unlock(ice->i2c); 797 snd_i2c_unlock(ice->i2c);
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index a6d98013c331..5aca37798c32 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -387,7 +387,7 @@ int __devinit snd_ice1712_init_cs8427(ice1712_t *ice, int addr)
387 if ((err = snd_cs8427_create(ice->i2c, addr, 387 if ((err = snd_cs8427_create(ice->i2c, addr,
388 (ice->cs8427_timeout * HZ) / 1000, 388 (ice->cs8427_timeout * HZ) / 1000,
389 &ice->cs8427)) < 0) { 389 &ice->cs8427)) < 0) {
390 snd_printk("CS8427 initialization failed\n"); 390 snd_printk(KERN_ERR "CS8427 initialization failed\n");
391 return err; 391 return err;
392 } 392 }
393 ice->spdif.ops.open = open_cs8427; 393 ice->spdif.ops.open = open_cs8427;
@@ -2348,12 +2348,12 @@ static int __devinit snd_ice1712_read_eeprom(ice1712_t *ice, const char *modelna
2348 if (ice->eeprom.size < 6) 2348 if (ice->eeprom.size < 6)
2349 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */ 2349 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2350 else if (ice->eeprom.size > 32) { 2350 else if (ice->eeprom.size > 32) {
2351 snd_printk("invalid EEPROM (size = %i)\n", ice->eeprom.size); 2351 snd_printk(KERN_ERR "invalid EEPROM (size = %i)\n", ice->eeprom.size);
2352 return -EIO; 2352 return -EIO;
2353 } 2353 }
2354 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05); 2354 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2355 if (ice->eeprom.version != 1) { 2355 if (ice->eeprom.version != 1) {
2356 snd_printk("invalid EEPROM version %i\n", ice->eeprom.version); 2356 snd_printk(KERN_ERR "invalid EEPROM version %i\n", ice->eeprom.version);
2357 /* return -EIO; */ 2357 /* return -EIO; */
2358 } 2358 }
2359 size = ice->eeprom.size - 6; 2359 size = ice->eeprom.size - 6;
@@ -2524,7 +2524,7 @@ static int __devinit snd_ice1712_create(snd_card_t * card,
2524 /* check, if we can restrict PCI DMA transfers to 28 bits */ 2524 /* check, if we can restrict PCI DMA transfers to 28 bits */
2525 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 || 2525 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2526 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) { 2526 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2527 snd_printk("architecture does not support 28bit PCI busmaster DMA\n"); 2527 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
2528 pci_disable_device(pci); 2528 pci_disable_device(pci);
2529 return -ENXIO; 2529 return -ENXIO;
2530 } 2530 }
@@ -2573,7 +2573,7 @@ static int __devinit snd_ice1712_create(snd_card_t * card,
2573 ice->profi_port = pci_resource_start(pci, 3); 2573 ice->profi_port = pci_resource_start(pci, 3);
2574 2574
2575 if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1712", (void *) ice)) { 2575 if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1712", (void *) ice)) {
2576 snd_printk("unable to grab IRQ %d\n", pci->irq); 2576 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2577 snd_ice1712_free(ice); 2577 snd_ice1712_free(ice);
2578 return -EIO; 2578 return -EIO;
2579 } 2579 }
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index c3ce8f93740b..5b4293f5a652 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -675,9 +675,12 @@ static snd_pcm_hardware_t snd_vt1724_spdif =
675 SNDRV_PCM_INFO_MMAP_VALID | 675 SNDRV_PCM_INFO_MMAP_VALID |
676 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START), 676 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
677 .formats = SNDRV_PCM_FMTBIT_S32_LE, 677 .formats = SNDRV_PCM_FMTBIT_S32_LE,
678 .rates = SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000, 678 .rates = (SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|
679 SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|
680 SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400|
681 SNDRV_PCM_RATE_192000),
679 .rate_min = 32000, 682 .rate_min = 32000,
680 .rate_max = 48000, 683 .rate_max = 192000,
681 .channels_min = 2, 684 .channels_min = 2,
682 .channels_max = 2, 685 .channels_max = 2,
683 .buffer_bytes_max = (1UL << 18), /* 16bits dword */ 686 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
@@ -905,6 +908,10 @@ static void update_spdif_rate(ice1712_t *ice, unsigned int rate)
905 case 44100: break; 908 case 44100: break;
906 case 48000: nval |= 2 << 12; break; 909 case 48000: nval |= 2 << 12; break;
907 case 32000: nval |= 3 << 12; break; 910 case 32000: nval |= 3 << 12; break;
911 case 88200: nval |= 4 << 12; break;
912 case 96000: nval |= 5 << 12; break;
913 case 192000: nval |= 6 << 12; break;
914 case 176400: nval |= 7 << 12; break;
908 } 915 }
909 if (val != nval) 916 if (val != nval)
910 update_spdif_bits(ice, nval); 917 update_spdif_bits(ice, nval);
@@ -1292,22 +1299,32 @@ static int snd_vt1724_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *
1292 1299
1293static unsigned int encode_spdif_bits(snd_aes_iec958_t *diga) 1300static unsigned int encode_spdif_bits(snd_aes_iec958_t *diga)
1294{ 1301{
1295 unsigned int val; 1302 unsigned int val, rbits;
1296 1303
1297 val = diga->status[0] & 0x03; /* professional, non-audio */ 1304 val = diga->status[0] & 0x03; /* professional, non-audio */
1298 if (val & 0x01) { 1305 if (val & 0x01) {
1299 /* professional */ 1306 /* professional */
1300 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) == IEC958_AES0_PRO_EMPHASIS_5015) 1307 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) == IEC958_AES0_PRO_EMPHASIS_5015)
1301 val |= 1U << 3; 1308 val |= 1U << 3;
1302 switch (diga->status[0] & IEC958_AES0_PRO_FS) { 1309 rbits = (diga->status[4] >> 3) & 0x0f;
1303 case IEC958_AES0_PRO_FS_44100: 1310 if (rbits) {
1304 break; 1311 switch (rbits) {
1305 case IEC958_AES0_PRO_FS_32000: 1312 case 2: val |= 5 << 12; break; /* 96k */
1306 val |= 3U << 12; 1313 case 3: val |= 6 << 12; break; /* 192k */
1307 break; 1314 case 10: val |= 4 << 12; break; /* 88.2k */
1308 default: 1315 case 11: val |= 7 << 12; break; /* 176.4k */
1309 val |= 2U << 12; 1316 }
1310 break; 1317 } else {
1318 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
1319 case IEC958_AES0_PRO_FS_44100:
1320 break;
1321 case IEC958_AES0_PRO_FS_32000:
1322 val |= 3U << 12;
1323 break;
1324 default:
1325 val |= 2U << 12;
1326 break;
1327 }
1311 } 1328 }
1312 } else { 1329 } else {
1313 /* consumer */ 1330 /* consumer */
@@ -2154,7 +2171,7 @@ static int __devinit snd_vt1724_create(snd_card_t * card,
2154 ice->profi_port = pci_resource_start(pci, 1); 2171 ice->profi_port = pci_resource_start(pci, 1);
2155 2172
2156 if (request_irq(pci->irq, snd_vt1724_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1724", (void *) ice)) { 2173 if (request_irq(pci->irq, snd_vt1724_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1724", (void *) ice)) {
2157 snd_printk("unable to grab IRQ %d\n", pci->irq); 2174 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2158 snd_vt1724_free(ice); 2175 snd_vt1724_free(ice);
2159 return -EIO; 2176 return -EIO;
2160 } 2177 }
diff --git a/sound/pci/ice1712/pontis.c b/sound/pci/ice1712/pontis.c
index a5f852b1f575..773a1ecb75ce 100644
--- a/sound/pci/ice1712/pontis.c
+++ b/sound/pci/ice1712/pontis.c
@@ -794,8 +794,7 @@ static int __devinit pontis_init(ice1712_t *ice)
794 /* initialize WM8776 codec */ 794 /* initialize WM8776 codec */
795 for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2) 795 for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2)
796 wm_put(ice, wm_inits[i], wm_inits[i+1]); 796 wm_put(ice, wm_inits[i], wm_inits[i+1]);
797 set_current_state(TASK_UNINTERRUPTIBLE); 797 schedule_timeout_uninterruptible(1);
798 schedule_timeout(1);
799 for (i = 0; i < ARRAY_SIZE(wm_inits2); i += 2) 798 for (i = 0; i < ARRAY_SIZE(wm_inits2); i += 2)
800 wm_put(ice, wm_inits2[i], wm_inits2[i+1]); 799 wm_put(ice, wm_inits2[i], wm_inits2[i+1]);
801 800
diff --git a/sound/pci/ice1712/revo.c b/sound/pci/ice1712/revo.c
index d48d42524ac5..1fe21009ca84 100644
--- a/sound/pci/ice1712/revo.c
+++ b/sound/pci/ice1712/revo.c
@@ -128,17 +128,6 @@ static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
128 .mask_flags = 0, 128 .mask_flags = 0,
129}; 129};
130 130
131static unsigned int rates[] = {
132 32000, 44100, 48000, 64000, 88200, 96000,
133 176400, 192000,
134};
135
136static snd_pcm_hw_constraint_list_t revo_rates = {
137 .count = ARRAY_SIZE(rates),
138 .list = rates,
139 .mask = 0,
140};
141
142static int __devinit revo_init(ice1712_t *ice) 131static int __devinit revo_init(ice1712_t *ice)
143{ 132{
144 akm4xxx_t *ak; 133 akm4xxx_t *ak;
@@ -173,8 +162,6 @@ static int __devinit revo_init(ice1712_t *ice)
173 break; 162 break;
174 } 163 }
175 164
176 ice->hw_rates = &revo_rates; /* AK codecs don't support lower than 32k */
177
178 return 0; 165 return 0;
179} 166}
180 167
diff --git a/sound/pci/ice1712/vt1720_mobo.c b/sound/pci/ice1712/vt1720_mobo.c
index ab61e383024f..90c85cd95479 100644
--- a/sound/pci/ice1712/vt1720_mobo.c
+++ b/sound/pci/ice1712/vt1720_mobo.c
@@ -71,6 +71,22 @@ static unsigned char k8x800_eeprom[] __devinitdata = {
71 0x00, /* - */ 71 0x00, /* - */
72}; 72};
73 73
74static unsigned char sn25p_eeprom[] __devinitdata = {
75 0x01, /* SYSCONF: clock 256, 1ADC, 2DACs */
76 0x02, /* ACLINK: ACLINK, packed */
77 0x00, /* I2S: - */
78 0x41, /* SPDIF: - */
79 0xff, /* GPIO_DIR */
80 0xff, /* GPIO_DIR1 */
81 0x00, /* - */
82 0xff, /* GPIO_MASK */
83 0xff, /* GPIO_MASK1 */
84 0x00, /* - */
85 0x00, /* GPIO_STATE */
86 0x00, /* GPIO_STATE1 */
87 0x00, /* - */
88};
89
74 90
75/* entry point */ 91/* entry point */
76struct snd_ice1712_card_info snd_vt1720_mobo_cards[] __devinitdata = { 92struct snd_ice1712_card_info snd_vt1720_mobo_cards[] __devinitdata = {
@@ -113,11 +129,11 @@ struct snd_ice1712_card_info snd_vt1720_mobo_cards[] __devinitdata = {
113 { 129 {
114 .subvendor = VT1720_SUBDEVICE_SN25P, 130 .subvendor = VT1720_SUBDEVICE_SN25P,
115 .name = "Shuttle SN25P", 131 .name = "Shuttle SN25P",
116 /* identical with k8x800 */ 132 .model = "sn25p",
117 .chip_init = k8x800_init, 133 .chip_init = k8x800_init,
118 .build_controls = k8x800_add_controls, 134 .build_controls = k8x800_add_controls,
119 .eeprom_size = sizeof(k8x800_eeprom), 135 .eeprom_size = sizeof(k8x800_eeprom),
120 .eeprom_data = k8x800_eeprom, 136 .eeprom_data = sn25p_eeprom,
121 }, 137 },
122 { } /* terminator */ 138 { } /* terminator */
123}; 139};
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 1a96198a17ae..0801083f32dd 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -64,36 +64,35 @@ MODULE_SUPPORTED_DEVICE("{{Intel,82801AA-ICH},"
64 "{AMD,AMD8111}," 64 "{AMD,AMD8111},"
65 "{ALI,M5455}}"); 65 "{ALI,M5455}}");
66 66
67static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 67static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
68static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 68static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
69static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 69static int ac97_clock = 0;
70static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; 70static char *ac97_quirk;
71static char *ac97_quirk[SNDRV_CARDS]; 71static int buggy_semaphore;
72static int buggy_semaphore[SNDRV_CARDS]; 72static int buggy_irq = -1; /* auto-check */
73static int buggy_irq[SNDRV_CARDS]; 73static int xbox;
74static int xbox[SNDRV_CARDS]; 74
75 75module_param(index, int, 0444);
76#ifdef SUPPORT_MIDI
77static int mpu_port[SNDRV_CARDS]; /* disabled */
78#endif
79
80module_param_array(index, int, NULL, 0444);
81MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard."); 76MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
82module_param_array(id, charp, NULL, 0444); 77module_param(id, charp, 0444);
83MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard."); 78MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard.");
84module_param_array(enable, bool, NULL, 0444); 79module_param(ac97_clock, int, 0444);
85MODULE_PARM_DESC(enable, "Enable Intel i8x0 soundcard.");
86module_param_array(ac97_clock, int, NULL, 0444);
87MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect)."); 80MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect).");
88module_param_array(ac97_quirk, charp, NULL, 0444); 81module_param(ac97_quirk, charp, 0444);
89MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); 82MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
90module_param_array(buggy_semaphore, bool, NULL, 0444); 83module_param(buggy_semaphore, bool, 0444);
91MODULE_PARM_DESC(buggy_semaphore, "Enable workaround for hardwares with problematic codec semaphores."); 84MODULE_PARM_DESC(buggy_semaphore, "Enable workaround for hardwares with problematic codec semaphores.");
92module_param_array(buggy_irq, bool, NULL, 0444); 85module_param(buggy_irq, bool, 0444);
93MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards."); 86MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards.");
94module_param_array(xbox, bool, NULL, 0444); 87module_param(xbox, bool, 0444);
95MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection."); 88MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection.");
96 89
90/* just for backward compatibility */
91static int enable;
92module_param(enable, bool, 0444);
93static int joystick;
94module_param(joystick, int, 0444);
95
97/* 96/*
98 * Direct registers 97 * Direct registers
99 */ 98 */
@@ -539,7 +538,7 @@ static int snd_intel8x0_codec_semaphore(intel8x0_t *chip, unsigned int codec)
539 /* access to some forbidden (non existant) ac97 registers will not 538 /* access to some forbidden (non existant) ac97 registers will not
540 * reset the semaphore. So even if you don't get the semaphore, still 539 * reset the semaphore. So even if you don't get the semaphore, still
541 * continue the access. We don't need the semaphore anyway. */ 540 * continue the access. We don't need the semaphore anyway. */
542 snd_printk("codec_semaphore: semaphore is not ready [0x%x][0x%x]\n", 541 snd_printk(KERN_ERR "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
543 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA))); 542 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
544 iagetword(chip, 0); /* clear semaphore flag */ 543 iagetword(chip, 0); /* clear semaphore flag */
545 /* I don't care about the semaphore */ 544 /* I don't care about the semaphore */
@@ -554,7 +553,7 @@ static void snd_intel8x0_codec_write(ac97_t *ac97,
554 553
555 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) { 554 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
556 if (! chip->in_ac97_init) 555 if (! chip->in_ac97_init)
557 snd_printk("codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 556 snd_printk(KERN_ERR "codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
558 } 557 }
559 iaputword(chip, reg + ac97->num * 0x80, val); 558 iaputword(chip, reg + ac97->num * 0x80, val);
560} 559}
@@ -568,7 +567,7 @@ static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
568 567
569 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) { 568 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
570 if (! chip->in_ac97_init) 569 if (! chip->in_ac97_init)
571 snd_printk("codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 570 snd_printk(KERN_ERR "codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
572 res = 0xffff; 571 res = 0xffff;
573 } else { 572 } else {
574 res = iagetword(chip, reg + ac97->num * 0x80); 573 res = iagetword(chip, reg + ac97->num * 0x80);
@@ -576,7 +575,7 @@ static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
576 /* reset RCS and preserve other R/WC bits */ 575 /* reset RCS and preserve other R/WC bits */
577 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI)); 576 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
578 if (! chip->in_ac97_init) 577 if (! chip->in_ac97_init)
579 snd_printk("codec_read %d: read timeout for register 0x%x\n", ac97->num, reg); 578 snd_printk(KERN_ERR "codec_read %d: read timeout for register 0x%x\n", ac97->num, reg);
580 res = 0xffff; 579 res = 0xffff;
581 } 580 }
582 } 581 }
@@ -607,16 +606,19 @@ static int snd_intel8x0_ali_codec_ready(intel8x0_t *chip, int mask)
607 if (val & mask) 606 if (val & mask)
608 return 0; 607 return 0;
609 } 608 }
610 snd_printd(KERN_WARNING "intel8x0: AC97 codec ready timeout.\n"); 609 if (! chip->in_ac97_init)
610 snd_printd(KERN_WARNING "intel8x0: AC97 codec ready timeout.\n");
611 return -EBUSY; 611 return -EBUSY;
612} 612}
613 613
614static int snd_intel8x0_ali_codec_semaphore(intel8x0_t *chip) 614static int snd_intel8x0_ali_codec_semaphore(intel8x0_t *chip)
615{ 615{
616 int time = 100; 616 int time = 100;
617 if (chip->buggy_semaphore)
618 return 0; /* just ignore ... */
617 while (time-- && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY)) 619 while (time-- && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY))
618 udelay(1); 620 udelay(1);
619 if (! time) 621 if (! time && ! chip->in_ac97_init)
620 snd_printk(KERN_WARNING "ali_codec_semaphore timeout\n"); 622 snd_printk(KERN_WARNING "ali_codec_semaphore timeout\n");
621 return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY); 623 return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY);
622} 624}
@@ -1716,6 +1718,12 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
1716 .type = AC97_TUNE_HP_ONLY 1718 .type = AC97_TUNE_HP_ONLY
1717 }, 1719 },
1718 { 1720 {
1721 .subvendor = 0x1025,
1722 .subdevice = 0x0083,
1723 .name = "Acer Aspire 3003LCi",
1724 .type = AC97_TUNE_HP_ONLY
1725 },
1726 {
1719 .subvendor = 0x1028, 1727 .subvendor = 0x1028,
1720 .subdevice = 0x00d8, 1728 .subdevice = 0x00d8,
1721 .name = "Dell Precision 530", /* AD1885 */ 1729 .name = "Dell Precision 530", /* AD1885 */
@@ -1758,6 +1766,12 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
1758 .type = AC97_TUNE_HP_ONLY 1766 .type = AC97_TUNE_HP_ONLY
1759 }, 1767 },
1760 { 1768 {
1769 .subvendor = 0x1028,
1770 .subdevice = 0x0191,
1771 .name = "Dell Inspiron 8600",
1772 .type = AC97_TUNE_HP_ONLY
1773 },
1774 {
1761 .subvendor = 0x103c, 1775 .subvendor = 0x103c,
1762 .subdevice = 0x006d, 1776 .subdevice = 0x006d,
1763 .name = "HP zv5000", 1777 .name = "HP zv5000",
@@ -2022,7 +2036,6 @@ static int __devinit snd_intel8x0_mixer(intel8x0_t *chip, int ac97_clock, const
2022 if ((err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus)) < 0) 2036 if ((err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus)) < 0)
2023 goto __err; 2037 goto __err;
2024 pbus->private_free = snd_intel8x0_mixer_free_ac97_bus; 2038 pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
2025 pbus->shared_type = AC97_SHARED_TYPE_ICH; /* shared with modem driver */
2026 if (ac97_clock >= 8000 && ac97_clock <= 48000) 2039 if (ac97_clock >= 8000 && ac97_clock <= 48000)
2027 pbus->clock = ac97_clock; 2040 pbus->clock = ac97_clock;
2028 /* FIXME: my test board doesn't work well with VRA... */ 2041 /* FIXME: my test board doesn't work well with VRA... */
@@ -2131,14 +2144,13 @@ static void do_ali_reset(intel8x0_t *chip)
2131 iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383); 2144 iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383);
2132 iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383); 2145 iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383);
2133 iputdword(chip, ICHREG(ALI_INTERFACECR), 2146 iputdword(chip, ICHREG(ALI_INTERFACECR),
2134 ICH_ALI_IF_MC|ICH_ALI_IF_PI|ICH_ALI_IF_PO); 2147 ICH_ALI_IF_PI|ICH_ALI_IF_PO);
2135 iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000); 2148 iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000);
2136 iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000); 2149 iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000);
2137} 2150}
2138 2151
2139#define do_delay(chip) do {\ 2152#define do_delay(chip) do {\
2140 set_current_state(TASK_UNINTERRUPTIBLE);\ 2153 schedule_timeout_uninterruptible(1);\
2141 schedule_timeout(1);\
2142} while (0) 2154} while (0)
2143 2155
2144static int snd_intel8x0_ich_chip_init(intel8x0_t *chip, int probing) 2156static int snd_intel8x0_ich_chip_init(intel8x0_t *chip, int probing)
@@ -2166,7 +2178,7 @@ static int snd_intel8x0_ich_chip_init(intel8x0_t *chip, int probing)
2166 goto __ok; 2178 goto __ok;
2167 do_delay(chip); 2179 do_delay(chip);
2168 } while (time_after_eq(end_time, jiffies)); 2180 } while (time_after_eq(end_time, jiffies));
2169 snd_printk("AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT))); 2181 snd_printk(KERN_ERR "AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT)));
2170 return -EIO; 2182 return -EIO;
2171 2183
2172 __ok: 2184 __ok:
@@ -2441,7 +2453,7 @@ static void __devinit intel8x0_measure_ac97_clock(intel8x0_t *chip)
2441 2453
2442 subs = chip->pcm[0]->streams[0].substream; 2454 subs = chip->pcm[0]->streams[0].substream;
2443 if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) { 2455 if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
2444 snd_printk("no playback buffer allocated - aborting measure ac97 clock\n"); 2456 snd_printk(KERN_WARNING "no playback buffer allocated - aborting measure ac97 clock\n");
2445 return; 2457 return;
2446 } 2458 }
2447 ichdev = &chip->ichd[ICHD_PCMOUT]; 2459 ichdev = &chip->ichd[ICHD_PCMOUT];
@@ -2477,7 +2489,7 @@ static void __devinit intel8x0_measure_ac97_clock(intel8x0_t *chip)
2477 do_gettimeofday(&stop_time); 2489 do_gettimeofday(&stop_time);
2478 /* stop */ 2490 /* stop */
2479 if (chip->device_type == DEVICE_ALI) { 2491 if (chip->device_type == DEVICE_ALI) {
2480 iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 8)); 2492 iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 16));
2481 iputbyte(chip, port + ICH_REG_OFF_CR, 0); 2493 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
2482 while (igetbyte(chip, port + ICH_REG_OFF_CR)) 2494 while (igetbyte(chip, port + ICH_REG_OFF_CR))
2483 ; 2495 ;
@@ -2556,7 +2568,6 @@ struct ich_reg_info {
2556static int __devinit snd_intel8x0_create(snd_card_t * card, 2568static int __devinit snd_intel8x0_create(snd_card_t * card,
2557 struct pci_dev *pci, 2569 struct pci_dev *pci,
2558 unsigned long device_type, 2570 unsigned long device_type,
2559 int buggy_sem,
2560 intel8x0_t ** r_intel8x0) 2571 intel8x0_t ** r_intel8x0)
2561{ 2572{
2562 intel8x0_t *chip; 2573 intel8x0_t *chip;
@@ -2614,18 +2625,17 @@ static int __devinit snd_intel8x0_create(snd_card_t * card,
2614 chip->card = card; 2625 chip->card = card;
2615 chip->pci = pci; 2626 chip->pci = pci;
2616 chip->irq = -1; 2627 chip->irq = -1;
2617 chip->buggy_semaphore = buggy_sem; 2628
2629 /* module parameters */
2630 chip->buggy_irq = buggy_irq;
2631 chip->buggy_semaphore = buggy_semaphore;
2632 if (xbox)
2633 chip->xbox = 1;
2618 2634
2619 if (pci->vendor == PCI_VENDOR_ID_INTEL && 2635 if (pci->vendor == PCI_VENDOR_ID_INTEL &&
2620 pci->device == PCI_DEVICE_ID_INTEL_440MX) 2636 pci->device == PCI_DEVICE_ID_INTEL_440MX)
2621 chip->fix_nocache = 1; /* enable workaround */ 2637 chip->fix_nocache = 1; /* enable workaround */
2622 2638
2623 /* some Nforce[2] and ICH boards have problems with IRQ handling.
2624 * Needs to return IRQ_HANDLED for unknown irqs.
2625 */
2626 if (device_type == DEVICE_NFORCE)
2627 chip->buggy_irq = 1;
2628
2629 if ((err = pci_request_regions(pci, card->shortname)) < 0) { 2639 if ((err = pci_request_regions(pci, card->shortname)) < 0) {
2630 kfree(chip); 2640 kfree(chip);
2631 pci_disable_device(pci); 2641 pci_disable_device(pci);
@@ -2644,7 +2654,7 @@ static int __devinit snd_intel8x0_create(snd_card_t * card,
2644 chip->remap_addr = ioremap_nocache(chip->addr, 2654 chip->remap_addr = ioremap_nocache(chip->addr,
2645 pci_resource_len(pci, 2)); 2655 pci_resource_len(pci, 2));
2646 if (chip->remap_addr == NULL) { 2656 if (chip->remap_addr == NULL) {
2647 snd_printk("AC'97 space ioremap problem\n"); 2657 snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
2648 snd_intel8x0_free(chip); 2658 snd_intel8x0_free(chip);
2649 return -EIO; 2659 return -EIO;
2650 } 2660 }
@@ -2657,7 +2667,7 @@ static int __devinit snd_intel8x0_create(snd_card_t * card,
2657 chip->remap_bmaddr = ioremap_nocache(chip->bmaddr, 2667 chip->remap_bmaddr = ioremap_nocache(chip->bmaddr,
2658 pci_resource_len(pci, 3)); 2668 pci_resource_len(pci, 3));
2659 if (chip->remap_bmaddr == NULL) { 2669 if (chip->remap_bmaddr == NULL) {
2660 snd_printk("Controller space ioremap problem\n"); 2670 snd_printk(KERN_ERR "Controller space ioremap problem\n");
2661 snd_intel8x0_free(chip); 2671 snd_intel8x0_free(chip);
2662 return -EIO; 2672 return -EIO;
2663 } 2673 }
@@ -2666,15 +2676,6 @@ static int __devinit snd_intel8x0_create(snd_card_t * card,
2666 } 2676 }
2667 2677
2668 port_inited: 2678 port_inited:
2669 if (request_irq(pci->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
2670 snd_printk("unable to grab IRQ %d\n", pci->irq);
2671 snd_intel8x0_free(chip);
2672 return -EBUSY;
2673 }
2674 chip->irq = pci->irq;
2675 pci_set_master(pci);
2676 synchronize_irq(chip->irq);
2677
2678 chip->bdbars_count = bdbars[device_type]; 2679 chip->bdbars_count = bdbars[device_type];
2679 2680
2680 /* initialize offsets */ 2681 /* initialize offsets */
@@ -2725,13 +2726,27 @@ static int __devinit snd_intel8x0_create(snd_card_t * card,
2725 int_sta_masks = 0; 2726 int_sta_masks = 0;
2726 for (i = 0; i < chip->bdbars_count; i++) { 2727 for (i = 0; i < chip->bdbars_count; i++) {
2727 ichdev = &chip->ichd[i]; 2728 ichdev = &chip->ichd[i];
2728 ichdev->bdbar = ((u32 *)chip->bdbars.area) + (i * ICH_MAX_FRAGS * 2); 2729 ichdev->bdbar = ((u32 *)chip->bdbars.area) +
2729 ichdev->bdbar_addr = chip->bdbars.addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2); 2730 (i * ICH_MAX_FRAGS * 2);
2731 ichdev->bdbar_addr = chip->bdbars.addr +
2732 (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
2730 int_sta_masks |= ichdev->int_sta_mask; 2733 int_sta_masks |= ichdev->int_sta_mask;
2731 } 2734 }
2732 chip->int_sta_reg = device_type == DEVICE_ALI ? ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA; 2735 chip->int_sta_reg = device_type == DEVICE_ALI ?
2736 ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA;
2733 chip->int_sta_mask = int_sta_masks; 2737 chip->int_sta_mask = int_sta_masks;
2734 2738
2739 /* request irq after initializaing int_sta_mask, etc */
2740 if (request_irq(pci->irq, snd_intel8x0_interrupt,
2741 SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
2742 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2743 snd_intel8x0_free(chip);
2744 return -EBUSY;
2745 }
2746 chip->irq = pci->irq;
2747 pci_set_master(pci);
2748 synchronize_irq(chip->irq);
2749
2735 if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) { 2750 if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) {
2736 snd_intel8x0_free(chip); 2751 snd_intel8x0_free(chip);
2737 return err; 2752 return err;
@@ -2782,20 +2797,12 @@ static struct shortname_table {
2782static int __devinit snd_intel8x0_probe(struct pci_dev *pci, 2797static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
2783 const struct pci_device_id *pci_id) 2798 const struct pci_device_id *pci_id)
2784{ 2799{
2785 static int dev;
2786 snd_card_t *card; 2800 snd_card_t *card;
2787 intel8x0_t *chip; 2801 intel8x0_t *chip;
2788 int err; 2802 int err;
2789 struct shortname_table *name; 2803 struct shortname_table *name;
2790 2804
2791 if (dev >= SNDRV_CARDS) 2805 card = snd_card_new(index, id, THIS_MODULE, 0);
2792 return -ENODEV;
2793 if (!enable[dev]) {
2794 dev++;
2795 return -ENOENT;
2796 }
2797
2798 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2799 if (card == NULL) 2806 if (card == NULL)
2800 return -ENOMEM; 2807 return -ENOMEM;
2801 2808
@@ -2819,17 +2826,23 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
2819 } 2826 }
2820 } 2827 }
2821 2828
2829 if (buggy_irq < 0) {
2830 /* some Nforce[2] and ICH boards have problems with IRQ handling.
2831 * Needs to return IRQ_HANDLED for unknown irqs.
2832 */
2833 if (pci_id->driver_data == DEVICE_NFORCE)
2834 buggy_irq = 1;
2835 else
2836 buggy_irq = 0;
2837 }
2838
2822 if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data, 2839 if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data,
2823 buggy_semaphore[dev], &chip)) < 0) { 2840 &chip)) < 0) {
2824 snd_card_free(card); 2841 snd_card_free(card);
2825 return err; 2842 return err;
2826 } 2843 }
2827 if (buggy_irq[dev])
2828 chip->buggy_irq = 1;
2829 if (xbox[dev])
2830 chip->xbox = 1;
2831 2844
2832 if ((err = snd_intel8x0_mixer(chip, ac97_clock[dev], ac97_quirk[dev])) < 0) { 2845 if ((err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk)) < 0) {
2833 snd_card_free(card); 2846 snd_card_free(card);
2834 return err; 2847 return err;
2835 } 2848 }
@@ -2844,7 +2857,7 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
2844 "%s with %s at %#lx, irq %i", card->shortname, 2857 "%s with %s at %#lx, irq %i", card->shortname,
2845 snd_ac97_get_short_name(chip->ac97[0]), chip->addr, chip->irq); 2858 snd_ac97_get_short_name(chip->ac97[0]), chip->addr, chip->irq);
2846 2859
2847 if (! ac97_clock[dev]) 2860 if (! ac97_clock)
2848 intel8x0_measure_ac97_clock(chip); 2861 intel8x0_measure_ac97_clock(chip);
2849 2862
2850 if ((err = snd_card_register(card)) < 0) { 2863 if ((err = snd_card_register(card)) < 0) {
@@ -2852,7 +2865,6 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
2852 return err; 2865 return err;
2853 } 2866 }
2854 pci_set_drvdata(pci, card); 2867 pci_set_drvdata(pci, card);
2855 dev++;
2856 return 0; 2868 return 0;
2857} 2869}
2858 2870
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index 9e2060d56c24..acfb197a833c 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz> 4 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
5 * 5 *
6 * This is modified (by Sasha Khapyorsky <sashak@smlink.com>) version 6 * This is modified (by Sasha Khapyorsky <sashak@alsa-project.org>) version
7 * of ALSA ICH sound driver intel8x0.c . 7 * of ALSA ICH sound driver intel8x0.c .
8 * 8 *
9 * 9 *
@@ -56,20 +56,21 @@ MODULE_SUPPORTED_DEVICE("{{Intel,82801AA-ICH},"
56 "{NVidia,NForce3 Modem}," 56 "{NVidia,NForce3 Modem},"
57 "{AMD,AMD768}}"); 57 "{AMD,AMD768}}");
58 58
59static int index[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -2}; /* Exclude the first card */ 59static int index = -2; /* Exclude the first card */
60static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 60static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
61static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 61static int ac97_clock = 0;
62static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
63 62
64module_param_array(index, int, NULL, 0444); 63module_param(index, int, 0444);
65MODULE_PARM_DESC(index, "Index value for Intel i8x0 modemcard."); 64MODULE_PARM_DESC(index, "Index value for Intel i8x0 modemcard.");
66module_param_array(id, charp, NULL, 0444); 65module_param(id, charp, 0444);
67MODULE_PARM_DESC(id, "ID string for Intel i8x0 modemcard."); 66MODULE_PARM_DESC(id, "ID string for Intel i8x0 modemcard.");
68module_param_array(enable, bool, NULL, 0444); 67module_param(ac97_clock, int, 0444);
69MODULE_PARM_DESC(enable, "Enable Intel i8x0 modemcard.");
70module_param_array(ac97_clock, int, NULL, 0444);
71MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect)."); 68MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect).");
72 69
70/* just for backward compatibility */
71static int enable;
72module_param(enable, bool, 0444);
73
73/* 74/*
74 * Direct registers 75 * Direct registers
75 */ 76 */
@@ -362,7 +363,7 @@ static int snd_intel8x0m_codec_semaphore(intel8x0_t *chip, unsigned int codec)
362 /* access to some forbidden (non existant) ac97 registers will not 363 /* access to some forbidden (non existant) ac97 registers will not
363 * reset the semaphore. So even if you don't get the semaphore, still 364 * reset the semaphore. So even if you don't get the semaphore, still
364 * continue the access. We don't need the semaphore anyway. */ 365 * continue the access. We don't need the semaphore anyway. */
365 snd_printk("codec_semaphore: semaphore is not ready [0x%x][0x%x]\n", 366 snd_printk(KERN_ERR "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
366 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA))); 367 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
367 iagetword(chip, 0); /* clear semaphore flag */ 368 iagetword(chip, 0); /* clear semaphore flag */
368 /* I don't care about the semaphore */ 369 /* I don't care about the semaphore */
@@ -377,7 +378,7 @@ static void snd_intel8x0_codec_write(ac97_t *ac97,
377 378
378 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) { 379 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) {
379 if (! chip->in_ac97_init) 380 if (! chip->in_ac97_init)
380 snd_printk("codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 381 snd_printk(KERN_ERR "codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
381 } 382 }
382 iaputword(chip, reg + ac97->num * 0x80, val); 383 iaputword(chip, reg + ac97->num * 0x80, val);
383} 384}
@@ -391,7 +392,7 @@ static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
391 392
392 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) { 393 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) {
393 if (! chip->in_ac97_init) 394 if (! chip->in_ac97_init)
394 snd_printk("codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 395 snd_printk(KERN_ERR "codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
395 res = 0xffff; 396 res = 0xffff;
396 } else { 397 } else {
397 res = iagetword(chip, reg + ac97->num * 0x80); 398 res = iagetword(chip, reg + ac97->num * 0x80);
@@ -399,7 +400,7 @@ static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
399 /* reset RCS and preserve other R/WC bits */ 400 /* reset RCS and preserve other R/WC bits */
400 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI)); 401 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
401 if (! chip->in_ac97_init) 402 if (! chip->in_ac97_init)
402 snd_printk("codec_read %d: read timeout for register 0x%x\n", ac97->num, reg); 403 snd_printk(KERN_ERR "codec_read %d: read timeout for register 0x%x\n", ac97->num, reg);
403 res = 0xffff; 404 res = 0xffff;
404 } 405 }
405 } 406 }
@@ -746,6 +747,7 @@ static int __devinit snd_intel8x0_pcm1(intel8x0_t *chip, int device, struct ich_
746 747
747 pcm->private_data = chip; 748 pcm->private_data = chip;
748 pcm->info_flags = 0; 749 pcm->info_flags = 0;
750 pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
749 if (rec->suffix) 751 if (rec->suffix)
750 sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix); 752 sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
751 else 753 else
@@ -854,7 +856,6 @@ static int __devinit snd_intel8x0_mixer(intel8x0_t *chip, int ac97_clock)
854 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0) 856 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0)
855 goto __err; 857 goto __err;
856 pbus->private_free = snd_intel8x0_mixer_free_ac97_bus; 858 pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
857 pbus->shared_type = AC97_SHARED_TYPE_ICH; /* shared with audio driver */
858 if (ac97_clock >= 8000 && ac97_clock <= 48000) 859 if (ac97_clock >= 8000 && ac97_clock <= 48000)
859 pbus->clock = ac97_clock; 860 pbus->clock = ac97_clock;
860 chip->ac97_bus = pbus; 861 chip->ac97_bus = pbus;
@@ -889,8 +890,7 @@ static int __devinit snd_intel8x0_mixer(intel8x0_t *chip, int ac97_clock)
889 */ 890 */
890 891
891#define do_delay(chip) do {\ 892#define do_delay(chip) do {\
892 set_current_state(TASK_UNINTERRUPTIBLE);\ 893 schedule_timeout_uninterruptible(1);\
893 schedule_timeout(1);\
894} while (0) 894} while (0)
895 895
896static int snd_intel8x0m_ich_chip_init(intel8x0_t *chip, int probing) 896static int snd_intel8x0m_ich_chip_init(intel8x0_t *chip, int probing)
@@ -916,7 +916,7 @@ static int snd_intel8x0m_ich_chip_init(intel8x0_t *chip, int probing)
916 goto __ok; 916 goto __ok;
917 do_delay(chip); 917 do_delay(chip);
918 } while (time_after_eq(end_time, jiffies)); 918 } while (time_after_eq(end_time, jiffies));
919 snd_printk("AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT))); 919 snd_printk(KERN_ERR "AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT)));
920 return -EIO; 920 return -EIO;
921 921
922 __ok: 922 __ok:
@@ -1142,7 +1142,7 @@ static int __devinit snd_intel8x0m_create(snd_card_t * card,
1142 chip->remap_addr = ioremap_nocache(chip->addr, 1142 chip->remap_addr = ioremap_nocache(chip->addr,
1143 pci_resource_len(pci, 2)); 1143 pci_resource_len(pci, 2));
1144 if (chip->remap_addr == NULL) { 1144 if (chip->remap_addr == NULL) {
1145 snd_printk("AC'97 space ioremap problem\n"); 1145 snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
1146 snd_intel8x0_free(chip); 1146 snd_intel8x0_free(chip);
1147 return -EIO; 1147 return -EIO;
1148 } 1148 }
@@ -1155,7 +1155,7 @@ static int __devinit snd_intel8x0m_create(snd_card_t * card,
1155 chip->remap_bmaddr = ioremap_nocache(chip->bmaddr, 1155 chip->remap_bmaddr = ioremap_nocache(chip->bmaddr,
1156 pci_resource_len(pci, 3)); 1156 pci_resource_len(pci, 3));
1157 if (chip->remap_bmaddr == NULL) { 1157 if (chip->remap_bmaddr == NULL) {
1158 snd_printk("Controller space ioremap problem\n"); 1158 snd_printk(KERN_ERR "Controller space ioremap problem\n");
1159 snd_intel8x0_free(chip); 1159 snd_intel8x0_free(chip);
1160 return -EIO; 1160 return -EIO;
1161 } 1161 }
@@ -1165,7 +1165,7 @@ static int __devinit snd_intel8x0m_create(snd_card_t * card,
1165 1165
1166 port_inited: 1166 port_inited:
1167 if (request_irq(pci->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) { 1167 if (request_irq(pci->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
1168 snd_printk("unable to grab IRQ %d\n", pci->irq); 1168 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1169 snd_intel8x0_free(chip); 1169 snd_intel8x0_free(chip);
1170 return -EBUSY; 1170 return -EBUSY;
1171 } 1171 }
@@ -1263,20 +1263,12 @@ static struct shortname_table {
1263static int __devinit snd_intel8x0m_probe(struct pci_dev *pci, 1263static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
1264 const struct pci_device_id *pci_id) 1264 const struct pci_device_id *pci_id)
1265{ 1265{
1266 static int dev;
1267 snd_card_t *card; 1266 snd_card_t *card;
1268 intel8x0_t *chip; 1267 intel8x0_t *chip;
1269 int err; 1268 int err;
1270 struct shortname_table *name; 1269 struct shortname_table *name;
1271 1270
1272 if (dev >= SNDRV_CARDS) 1271 card = snd_card_new(index, id, THIS_MODULE, 0);
1273 return -ENODEV;
1274 if (!enable[dev]) {
1275 dev++;
1276 return -ENOENT;
1277 }
1278
1279 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1280 if (card == NULL) 1272 if (card == NULL)
1281 return -ENOMEM; 1273 return -ENOMEM;
1282 1274
@@ -1295,7 +1287,7 @@ static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
1295 return err; 1287 return err;
1296 } 1288 }
1297 1289
1298 if ((err = snd_intel8x0_mixer(chip, ac97_clock[dev])) < 0) { 1290 if ((err = snd_intel8x0_mixer(chip, ac97_clock)) < 0) {
1299 snd_card_free(card); 1291 snd_card_free(card);
1300 return err; 1292 return err;
1301 } 1293 }
@@ -1314,7 +1306,6 @@ static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
1314 return err; 1306 return err;
1315 } 1307 }
1316 pci_set_drvdata(pci, card); 1308 pci_set_drvdata(pci, card);
1317 dev++;
1318 return 0; 1309 return 0;
1319} 1310}
1320 1311
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 2693b6f731f3..99eb76c56f81 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -1492,7 +1492,7 @@ static int snd_m3_pcm_hw_params(snd_pcm_substream_t * substream,
1492 /* set buffer address */ 1492 /* set buffer address */
1493 s->buffer_addr = substream->runtime->dma_addr; 1493 s->buffer_addr = substream->runtime->dma_addr;
1494 if (s->buffer_addr & 0x3) { 1494 if (s->buffer_addr & 0x3) {
1495 snd_printk("oh my, not aligned\n"); 1495 snd_printk(KERN_ERR "oh my, not aligned\n");
1496 s->buffer_addr = s->buffer_addr & ~0x3; 1496 s->buffer_addr = s->buffer_addr & ~0x3;
1497 } 1497 }
1498 return 0; 1498 return 0;
@@ -1942,7 +1942,7 @@ static int snd_m3_ac97_wait(m3_t *chip)
1942 return 0; 1942 return 0;
1943 } while (i-- > 0); 1943 } while (i-- > 0);
1944 1944
1945 snd_printk("ac97 serial bus busy\n"); 1945 snd_printk(KERN_ERR "ac97 serial bus busy\n");
1946 return 1; 1946 return 1;
1947} 1947}
1948 1948
@@ -2046,8 +2046,7 @@ static void snd_m3_ac97_reset(m3_t *chip)
2046 outw(0, io + GPIO_DATA); 2046 outw(0, io + GPIO_DATA);
2047 outw(dir | GPO_PRIMARY_AC97, io + GPIO_DIRECTION); 2047 outw(dir | GPO_PRIMARY_AC97, io + GPIO_DIRECTION);
2048 2048
2049 set_current_state(TASK_UNINTERRUPTIBLE); 2049 schedule_timeout_uninterruptible(msecs_to_jiffies(delay1));
2050 schedule_timeout((delay1 * HZ) / 1000);
2051 2050
2052 outw(GPO_PRIMARY_AC97, io + GPIO_DATA); 2051 outw(GPO_PRIMARY_AC97, io + GPIO_DATA);
2053 udelay(5); 2052 udelay(5);
@@ -2055,8 +2054,7 @@ static void snd_m3_ac97_reset(m3_t *chip)
2055 outw(IO_SRAM_ENABLE | SERIAL_AC_LINK_ENABLE, io + RING_BUS_CTRL_A); 2054 outw(IO_SRAM_ENABLE | SERIAL_AC_LINK_ENABLE, io + RING_BUS_CTRL_A);
2056 outw(~0, io + GPIO_MASK); 2055 outw(~0, io + GPIO_MASK);
2057 2056
2058 set_current_state(TASK_UNINTERRUPTIBLE); 2057 schedule_timeout_uninterruptible(msecs_to_jiffies(delay2));
2059 schedule_timeout((delay2 * HZ) / 1000);
2060 2058
2061 if (! snd_m3_try_read_vendor(chip)) 2059 if (! snd_m3_try_read_vendor(chip))
2062 break; 2060 break;
@@ -2101,8 +2099,7 @@ static int __devinit snd_m3_mixer(m3_t *chip)
2101 2099
2102 /* seems ac97 PCM needs initialization.. hack hack.. */ 2100 /* seems ac97 PCM needs initialization.. hack hack.. */
2103 snd_ac97_write(chip->ac97, AC97_PCM, 0x8000 | (15 << 8) | 15); 2101 snd_ac97_write(chip->ac97, AC97_PCM, 0x8000 | (15 << 8) | 15);
2104 set_current_state(TASK_UNINTERRUPTIBLE); 2102 schedule_timeout_uninterruptible(msecs_to_jiffies(100));
2105 schedule_timeout(HZ / 10);
2106 snd_ac97_write(chip->ac97, AC97_PCM, 0); 2103 snd_ac97_write(chip->ac97, AC97_PCM, 0);
2107 2104
2108 memset(&id, 0, sizeof(id)); 2105 memset(&id, 0, sizeof(id));
@@ -2367,7 +2364,7 @@ static int __devinit snd_m3_assp_client_init(m3_t *chip, m3_dma_t *s, int index)
2367 address = 0x1100 + ((data_bytes/2) * index); 2364 address = 0x1100 + ((data_bytes/2) * index);
2368 2365
2369 if ((address + (data_bytes/2)) >= 0x1c00) { 2366 if ((address + (data_bytes/2)) >= 0x1c00) {
2370 snd_printk("no memory for %d bytes at ind %d (addr 0x%x)\n", 2367 snd_printk(KERN_ERR "no memory for %d bytes at ind %d (addr 0x%x)\n",
2371 data_bytes, index, address); 2368 data_bytes, index, address);
2372 return -ENOMEM; 2369 return -ENOMEM;
2373 } 2370 }
@@ -2476,6 +2473,7 @@ snd_m3_chip_init(m3_t *chip)
2476 t |= ASSP_0_WS_ENABLE; 2473 t |= ASSP_0_WS_ENABLE;
2477 outb(t, chip->iobase + ASSP_CONTROL_A); 2474 outb(t, chip->iobase + ASSP_CONTROL_A);
2478 2475
2476 snd_m3_assp_init(chip); /* download DSP code before starting ASSP below */
2479 outb(RUN_ASSP, chip->iobase + ASSP_CONTROL_B); 2477 outb(RUN_ASSP, chip->iobase + ASSP_CONTROL_B);
2480 2478
2481 outb(0x00, io + HARDWARE_VOL_CTRL); 2479 outb(0x00, io + HARDWARE_VOL_CTRL);
@@ -2655,7 +2653,7 @@ snd_m3_create(snd_card_t *card, struct pci_dev *pci,
2655 /* check, if we can restrict PCI DMA transfers to 28 bits */ 2653 /* check, if we can restrict PCI DMA transfers to 28 bits */
2656 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 || 2654 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2657 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) { 2655 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2658 snd_printk("architecture does not support 28bit PCI busmaster DMA\n"); 2656 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
2659 pci_disable_device(pci); 2657 pci_disable_device(pci);
2660 return -ENXIO; 2658 return -ENXIO;
2661 } 2659 }
@@ -2734,14 +2732,13 @@ snd_m3_create(snd_card_t *card, struct pci_dev *pci,
2734 2732
2735 snd_m3_ac97_reset(chip); 2733 snd_m3_ac97_reset(chip);
2736 2734
2737 snd_m3_assp_init(chip);
2738 snd_m3_amp_enable(chip, 1); 2735 snd_m3_amp_enable(chip, 1);
2739 2736
2740 tasklet_init(&chip->hwvol_tq, snd_m3_update_hw_volume, (unsigned long)chip); 2737 tasklet_init(&chip->hwvol_tq, snd_m3_update_hw_volume, (unsigned long)chip);
2741 2738
2742 if (request_irq(pci->irq, snd_m3_interrupt, SA_INTERRUPT|SA_SHIRQ, 2739 if (request_irq(pci->irq, snd_m3_interrupt, SA_INTERRUPT|SA_SHIRQ,
2743 card->driver, (void *)chip)) { 2740 card->driver, (void *)chip)) {
2744 snd_printk("unable to grab IRQ %d\n", pci->irq); 2741 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2745 snd_m3_free(chip); 2742 snd_m3_free(chip);
2746 return -ENOMEM; 2743 return -ENOMEM;
2747 } 2744 }
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c
index 1a62c7f6c52b..c341c99ec783 100644
--- a/sound/pci/mixart/mixart.c
+++ b/sound/pci/mixart/mixart.c
@@ -451,8 +451,7 @@ static int mixart_sync_nonblock_events(mixart_mgr_t *mgr)
451 snd_printk(KERN_ERR "mixart: cannot process nonblock events!\n"); 451 snd_printk(KERN_ERR "mixart: cannot process nonblock events!\n");
452 return -EBUSY; 452 return -EBUSY;
453 } 453 }
454 set_current_state(TASK_UNINTERRUPTIBLE); 454 schedule_timeout_uninterruptible(1);
455 schedule_timeout(1);
456 } 455 }
457 return 0; 456 return 0;
458} 457}
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 5c55a3b1d121..e7aa15178453 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -52,37 +52,43 @@ MODULE_SUPPORTED_DEVICE("{{NeoMagic,NM256AV},"
52 * some compile conditions. 52 * some compile conditions.
53 */ 53 */
54 54
55static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 55static int index = SNDRV_DEFAULT_IDX1; /* Index */
56static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 56static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
57static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 57static int playback_bufsize = 16;
58static int playback_bufsize[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 16}; 58static int capture_bufsize = 16;
59static int capture_bufsize[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 16}; 59static int force_ac97; /* disabled as default */
60static int force_ac97[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* disabled as default */ 60static int buffer_top; /* not specified */
61static int buffer_top[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* not specified */ 61static int use_cache; /* disabled */
62static int use_cache[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* disabled */ 62static int vaio_hack; /* disabled */
63static int vaio_hack[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* disabled */ 63static int reset_workaround;
64static int reset_workaround[SNDRV_CARDS]; 64static int reset_workaround_2;
65 65
66module_param_array(index, int, NULL, 0444); 66module_param(index, int, 0444);
67MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard."); 67MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
68module_param_array(id, charp, NULL, 0444); 68module_param(id, charp, 0444);
69MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard."); 69MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
70module_param_array(enable, bool, NULL, 0444); 70module_param(playback_bufsize, int, 0444);
71MODULE_PARM_DESC(enable, "Enable this soundcard.");
72module_param_array(playback_bufsize, int, NULL, 0444);
73MODULE_PARM_DESC(playback_bufsize, "DAC frame size in kB for " CARD_NAME " soundcard."); 71MODULE_PARM_DESC(playback_bufsize, "DAC frame size in kB for " CARD_NAME " soundcard.");
74module_param_array(capture_bufsize, int, NULL, 0444); 72module_param(capture_bufsize, int, 0444);
75MODULE_PARM_DESC(capture_bufsize, "ADC frame size in kB for " CARD_NAME " soundcard."); 73MODULE_PARM_DESC(capture_bufsize, "ADC frame size in kB for " CARD_NAME " soundcard.");
76module_param_array(force_ac97, bool, NULL, 0444); 74module_param(force_ac97, bool, 0444);
77MODULE_PARM_DESC(force_ac97, "Force to use AC97 codec for " CARD_NAME " soundcard."); 75MODULE_PARM_DESC(force_ac97, "Force to use AC97 codec for " CARD_NAME " soundcard.");
78module_param_array(buffer_top, int, NULL, 0444); 76module_param(buffer_top, int, 0444);
79MODULE_PARM_DESC(buffer_top, "Set the top address of audio buffer for " CARD_NAME " soundcard."); 77MODULE_PARM_DESC(buffer_top, "Set the top address of audio buffer for " CARD_NAME " soundcard.");
80module_param_array(use_cache, bool, NULL, 0444); 78module_param(use_cache, bool, 0444);
81MODULE_PARM_DESC(use_cache, "Enable the cache for coefficient table access."); 79MODULE_PARM_DESC(use_cache, "Enable the cache for coefficient table access.");
82module_param_array(vaio_hack, bool, NULL, 0444); 80module_param(vaio_hack, bool, 0444);
83MODULE_PARM_DESC(vaio_hack, "Enable workaround for Sony VAIO notebooks."); 81MODULE_PARM_DESC(vaio_hack, "Enable workaround for Sony VAIO notebooks.");
84module_param_array(reset_workaround, bool, NULL, 0444); 82module_param(reset_workaround, bool, 0444);
85MODULE_PARM_DESC(reset_workaround, "Enable AC97 RESET workaround for some laptops."); 83MODULE_PARM_DESC(reset_workaround, "Enable AC97 RESET workaround for some laptops.");
84module_param(reset_workaround_2, bool, 0444);
85MODULE_PARM_DESC(reset_workaround_2, "Enable extended AC97 RESET workaround for some other laptops.");
86
87/* just for backward compatibility */
88static int enable;
89module_param(enable, bool, 0444);
90
91
86 92
87/* 93/*
88 * hw definitions 94 * hw definitions
@@ -226,6 +232,7 @@ struct snd_nm256 {
226 unsigned int coeffs_current: 1; /* coeff. table is loaded? */ 232 unsigned int coeffs_current: 1; /* coeff. table is loaded? */
227 unsigned int use_cache: 1; /* use one big coef. table */ 233 unsigned int use_cache: 1; /* use one big coef. table */
228 unsigned int reset_workaround: 1; /* Workaround for some laptops to avoid freeze */ 234 unsigned int reset_workaround: 1; /* Workaround for some laptops to avoid freeze */
235 unsigned int reset_workaround_2: 1; /* Extended workaround for some other laptops to avoid freeze */
229 236
230 int mixer_base; /* register offset of ac97 mixer */ 237 int mixer_base; /* register offset of ac97 mixer */
231 int mixer_status_offset; /* offset of mixer status reg. */ 238 int mixer_status_offset; /* offset of mixer status reg. */
@@ -313,9 +320,9 @@ static inline void
313snd_nm256_write_buffer(nm256_t *chip, void *src, int offset, int size) 320snd_nm256_write_buffer(nm256_t *chip, void *src, int offset, int size)
314{ 321{
315 offset -= chip->buffer_start; 322 offset -= chip->buffer_start;
316#ifdef SNDRV_CONFIG_DEBUG 323#ifdef CONFIG_SND_DEBUG
317 if (offset < 0 || offset >= chip->buffer_size) { 324 if (offset < 0 || offset >= chip->buffer_size) {
318 snd_printk("write_buffer invalid offset = %d size = %d\n", offset, size); 325 snd_printk(KERN_ERR "write_buffer invalid offset = %d size = %d\n", offset, size);
319 return; 326 return;
320 } 327 }
321#endif 328#endif
@@ -459,7 +466,7 @@ static int snd_nm256_acquire_irq(nm256_t *chip)
459 if (chip->irq < 0) { 466 if (chip->irq < 0) {
460 if (request_irq(chip->pci->irq, chip->interrupt, SA_INTERRUPT|SA_SHIRQ, 467 if (request_irq(chip->pci->irq, chip->interrupt, SA_INTERRUPT|SA_SHIRQ,
461 chip->card->driver, (void*)chip)) { 468 chip->card->driver, (void*)chip)) {
462 snd_printk("unable to grab IRQ %d\n", chip->pci->irq); 469 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->pci->irq);
463 up(&chip->irq_mutex); 470 up(&chip->irq_mutex);
464 return -EBUSY; 471 return -EBUSY;
465 } 472 }
@@ -1199,8 +1206,11 @@ snd_nm256_ac97_reset(ac97_t *ac97)
1199 /* Dell latitude LS will lock up by this */ 1206 /* Dell latitude LS will lock up by this */
1200 snd_nm256_writeb(chip, 0x6cc, 0x87); 1207 snd_nm256_writeb(chip, 0x6cc, 0x87);
1201 } 1208 }
1202 snd_nm256_writeb(chip, 0x6cc, 0x80); 1209 if (! chip->reset_workaround_2) {
1203 snd_nm256_writeb(chip, 0x6cc, 0x0); 1210 /* Dell latitude CSx will lock up by this */
1211 snd_nm256_writeb(chip, 0x6cc, 0x80);
1212 snd_nm256_writeb(chip, 0x6cc, 0x0);
1213 }
1204} 1214}
1205 1215
1206/* create an ac97 mixer interface */ 1216/* create an ac97 mixer interface */
@@ -1263,7 +1273,7 @@ snd_nm256_peek_for_sig(nm256_t *chip)
1263 1273
1264 temp = ioremap_nocache(chip->buffer_addr + chip->buffer_end - 0x400, 16); 1274 temp = ioremap_nocache(chip->buffer_addr + chip->buffer_end - 0x400, 16);
1265 if (temp == NULL) { 1275 if (temp == NULL) {
1266 snd_printk("Unable to scan for card signature in video RAM\n"); 1276 snd_printk(KERN_ERR "Unable to scan for card signature in video RAM\n");
1267 return -EBUSY; 1277 return -EBUSY;
1268 } 1278 }
1269 1279
@@ -1277,7 +1287,7 @@ snd_nm256_peek_for_sig(nm256_t *chip)
1277 if (pointer == 0xffffffff || 1287 if (pointer == 0xffffffff ||
1278 pointer < chip->buffer_size || 1288 pointer < chip->buffer_size ||
1279 pointer > chip->buffer_end) { 1289 pointer > chip->buffer_end) {
1280 snd_printk("invalid signature found: 0x%x\n", pointer); 1290 snd_printk(KERN_ERR "invalid signature found: 0x%x\n", pointer);
1281 iounmap(temp); 1291 iounmap(temp);
1282 return -ENODEV; 1292 return -ENODEV;
1283 } else { 1293 } else {
@@ -1347,14 +1357,8 @@ static int snd_nm256_free(nm256_t *chip)
1347 iounmap(chip->cport); 1357 iounmap(chip->cport);
1348 if (chip->buffer) 1358 if (chip->buffer)
1349 iounmap(chip->buffer); 1359 iounmap(chip->buffer);
1350 if (chip->res_cport) { 1360 release_and_free_resource(chip->res_cport);
1351 release_resource(chip->res_cport); 1361 release_and_free_resource(chip->res_buffer);
1352 kfree_nocheck(chip->res_cport);
1353 }
1354 if (chip->res_buffer) {
1355 release_resource(chip->res_buffer);
1356 kfree_nocheck(chip->res_buffer);
1357 }
1358 if (chip->irq >= 0) 1362 if (chip->irq >= 0)
1359 free_irq(chip->irq, (void*)chip); 1363 free_irq(chip->irq, (void*)chip);
1360 1364
@@ -1420,14 +1424,14 @@ snd_nm256_create(snd_card_t *card, struct pci_dev *pci,
1420 chip->res_cport = request_mem_region(chip->cport_addr, NM_PORT2_SIZE, 1424 chip->res_cport = request_mem_region(chip->cport_addr, NM_PORT2_SIZE,
1421 card->driver); 1425 card->driver);
1422 if (chip->res_cport == NULL) { 1426 if (chip->res_cport == NULL) {
1423 snd_printk("memory region 0x%lx (size 0x%x) busy\n", 1427 snd_printk(KERN_ERR "memory region 0x%lx (size 0x%x) busy\n",
1424 chip->cport_addr, NM_PORT2_SIZE); 1428 chip->cport_addr, NM_PORT2_SIZE);
1425 err = -EBUSY; 1429 err = -EBUSY;
1426 goto __error; 1430 goto __error;
1427 } 1431 }
1428 chip->cport = ioremap_nocache(chip->cport_addr, NM_PORT2_SIZE); 1432 chip->cport = ioremap_nocache(chip->cport_addr, NM_PORT2_SIZE);
1429 if (chip->cport == NULL) { 1433 if (chip->cport == NULL) {
1430 snd_printk("unable to map control port %lx\n", chip->cport_addr); 1434 snd_printk(KERN_ERR "unable to map control port %lx\n", chip->cport_addr);
1431 err = -ENOMEM; 1435 err = -ENOMEM;
1432 goto __error; 1436 goto __error;
1433 } 1437 }
@@ -1485,7 +1489,7 @@ snd_nm256_create(snd_card_t *card, struct pci_dev *pci,
1485 chip->buffer_size, 1489 chip->buffer_size,
1486 card->driver); 1490 card->driver);
1487 if (chip->res_buffer == NULL) { 1491 if (chip->res_buffer == NULL) {
1488 snd_printk("nm256: buffer 0x%lx (size 0x%x) busy\n", 1492 snd_printk(KERN_ERR "nm256: buffer 0x%lx (size 0x%x) busy\n",
1489 chip->buffer_addr, chip->buffer_size); 1493 chip->buffer_addr, chip->buffer_size);
1490 err = -EBUSY; 1494 err = -EBUSY;
1491 goto __error; 1495 goto __error;
@@ -1493,7 +1497,7 @@ snd_nm256_create(snd_card_t *card, struct pci_dev *pci,
1493 chip->buffer = ioremap_nocache(chip->buffer_addr, chip->buffer_size); 1497 chip->buffer = ioremap_nocache(chip->buffer_addr, chip->buffer_size);
1494 if (chip->buffer == NULL) { 1498 if (chip->buffer == NULL) {
1495 err = -ENOMEM; 1499 err = -ENOMEM;
1496 snd_printk("unable to map ring buffer at %lx\n", chip->buffer_addr); 1500 snd_printk(KERN_ERR "unable to map ring buffer at %lx\n", chip->buffer_addr);
1497 goto __error; 1501 goto __error;
1498 } 1502 }
1499 1503
@@ -1542,7 +1546,7 @@ struct nm256_quirk {
1542 int type; 1546 int type;
1543}; 1547};
1544 1548
1545enum { NM_BLACKLISTED, NM_RESET_WORKAROUND }; 1549enum { NM_BLACKLISTED, NM_RESET_WORKAROUND, NM_RESET_WORKAROUND_2 };
1546 1550
1547static struct nm256_quirk nm256_quirks[] __devinitdata = { 1551static struct nm256_quirk nm256_quirks[] __devinitdata = {
1548 /* HP omnibook 4150 has cs4232 codec internally */ 1552 /* HP omnibook 4150 has cs4232 codec internally */
@@ -1551,6 +1555,8 @@ static struct nm256_quirk nm256_quirks[] __devinitdata = {
1551 { .vendor = 0x104d, .device = 0x8041, .type = NM_RESET_WORKAROUND }, 1555 { .vendor = 0x104d, .device = 0x8041, .type = NM_RESET_WORKAROUND },
1552 /* Dell Latitude LS */ 1556 /* Dell Latitude LS */
1553 { .vendor = 0x1028, .device = 0x0080, .type = NM_RESET_WORKAROUND }, 1557 { .vendor = 0x1028, .device = 0x0080, .type = NM_RESET_WORKAROUND },
1558 /* Dell Latitude CSx */
1559 { .vendor = 0x1028, .device = 0x0091, .type = NM_RESET_WORKAROUND_2 },
1554 { } /* terminator */ 1560 { } /* terminator */
1555}; 1561};
1556 1562
@@ -1558,7 +1564,6 @@ static struct nm256_quirk nm256_quirks[] __devinitdata = {
1558static int __devinit snd_nm256_probe(struct pci_dev *pci, 1564static int __devinit snd_nm256_probe(struct pci_dev *pci,
1559 const struct pci_device_id *pci_id) 1565 const struct pci_device_id *pci_id)
1560{ 1566{
1561 static int dev;
1562 snd_card_t *card; 1567 snd_card_t *card;
1563 nm256_t *chip; 1568 nm256_t *chip;
1564 int err; 1569 int err;
@@ -1566,13 +1571,6 @@ static int __devinit snd_nm256_probe(struct pci_dev *pci,
1566 struct nm256_quirk *q; 1571 struct nm256_quirk *q;
1567 u16 subsystem_vendor, subsystem_device; 1572 u16 subsystem_vendor, subsystem_device;
1568 1573
1569 if (dev >= SNDRV_CARDS)
1570 return -ENODEV;
1571 if (!enable[dev]) {
1572 dev++;
1573 return -ENOENT;
1574 }
1575
1576 pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor); 1574 pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
1577 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device); 1575 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device);
1578 1576
@@ -1582,14 +1580,17 @@ static int __devinit snd_nm256_probe(struct pci_dev *pci,
1582 case NM_BLACKLISTED: 1580 case NM_BLACKLISTED:
1583 printk(KERN_INFO "nm256: The device is blacklisted. Loading stopped\n"); 1581 printk(KERN_INFO "nm256: The device is blacklisted. Loading stopped\n");
1584 return -ENODEV; 1582 return -ENODEV;
1583 case NM_RESET_WORKAROUND_2:
1584 reset_workaround_2 = 1;
1585 /* Fall-through */
1585 case NM_RESET_WORKAROUND: 1586 case NM_RESET_WORKAROUND:
1586 reset_workaround[dev] = 1; 1587 reset_workaround = 1;
1587 break; 1588 break;
1588 } 1589 }
1589 } 1590 }
1590 } 1591 }
1591 1592
1592 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 1593 card = snd_card_new(index, id, THIS_MODULE, 0);
1593 if (card == NULL) 1594 if (card == NULL)
1594 return -ENOMEM; 1595 return -ENOMEM;
1595 1596
@@ -1604,40 +1605,45 @@ static int __devinit snd_nm256_probe(struct pci_dev *pci,
1604 strcpy(card->driver, "NM256XL+"); 1605 strcpy(card->driver, "NM256XL+");
1605 break; 1606 break;
1606 default: 1607 default:
1607 snd_printk("invalid device id 0x%x\n", pci->device); 1608 snd_printk(KERN_ERR "invalid device id 0x%x\n", pci->device);
1608 snd_card_free(card); 1609 snd_card_free(card);
1609 return -EINVAL; 1610 return -EINVAL;
1610 } 1611 }
1611 1612
1612 if (vaio_hack[dev]) 1613 if (vaio_hack)
1613 xbuffer_top = 0x25a800; /* this avoids conflicts with XFree86 server */ 1614 xbuffer_top = 0x25a800; /* this avoids conflicts with XFree86 server */
1614 else 1615 else
1615 xbuffer_top = buffer_top[dev]; 1616 xbuffer_top = buffer_top;
1616 1617
1617 if (playback_bufsize[dev] < 4) 1618 if (playback_bufsize < 4)
1618 playback_bufsize[dev] = 4; 1619 playback_bufsize = 4;
1619 if (playback_bufsize[dev] > 128) 1620 if (playback_bufsize > 128)
1620 playback_bufsize[dev] = 128; 1621 playback_bufsize = 128;
1621 if (capture_bufsize[dev] < 4) 1622 if (capture_bufsize < 4)
1622 capture_bufsize[dev] = 4; 1623 capture_bufsize = 4;
1623 if (capture_bufsize[dev] > 128) 1624 if (capture_bufsize > 128)
1624 capture_bufsize[dev] = 128; 1625 capture_bufsize = 128;
1625 if ((err = snd_nm256_create(card, pci, 1626 if ((err = snd_nm256_create(card, pci,
1626 playback_bufsize[dev] * 1024, /* in bytes */ 1627 playback_bufsize * 1024, /* in bytes */
1627 capture_bufsize[dev] * 1024, /* in bytes */ 1628 capture_bufsize * 1024, /* in bytes */
1628 force_ac97[dev], 1629 force_ac97,
1629 xbuffer_top, 1630 xbuffer_top,
1630 use_cache[dev], 1631 use_cache,
1631 &chip)) < 0) { 1632 &chip)) < 0) {
1632 snd_card_free(card); 1633 snd_card_free(card);
1633 return err; 1634 return err;
1634 } 1635 }
1635 1636
1636 if (reset_workaround[dev]) { 1637 if (reset_workaround) {
1637 snd_printdd(KERN_INFO "nm256: reset_workaround activated\n"); 1638 snd_printdd(KERN_INFO "nm256: reset_workaround activated\n");
1638 chip->reset_workaround = 1; 1639 chip->reset_workaround = 1;
1639 } 1640 }
1640 1641
1642 if (reset_workaround_2) {
1643 snd_printdd(KERN_INFO "nm256: reset_workaround_2 activated\n");
1644 chip->reset_workaround_2 = 1;
1645 }
1646
1641 if ((err = snd_nm256_pcm(chip, 0)) < 0 || 1647 if ((err = snd_nm256_pcm(chip, 0)) < 0 ||
1642 (err = snd_nm256_mixer(chip)) < 0) { 1648 (err = snd_nm256_mixer(chip)) < 0) {
1643 snd_card_free(card); 1649 snd_card_free(card);
@@ -1655,7 +1661,6 @@ static int __devinit snd_nm256_probe(struct pci_dev *pci,
1655 } 1661 }
1656 1662
1657 pci_set_drvdata(pci, card); 1663 pci_set_drvdata(pci, card);
1658 dev++;
1659 return 0; 1664 return 0;
1660} 1665}
1661 1666
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index cd313af6ebcf..e6627b0e38e4 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -1369,13 +1369,13 @@ static int __devinit snd_rme32_create(rme32_t * rme32)
1369 rme32->port = pci_resource_start(rme32->pci, 0); 1369 rme32->port = pci_resource_start(rme32->pci, 0);
1370 1370
1371 if (request_irq(pci->irq, snd_rme32_interrupt, SA_INTERRUPT | SA_SHIRQ, "RME32", (void *) rme32)) { 1371 if (request_irq(pci->irq, snd_rme32_interrupt, SA_INTERRUPT | SA_SHIRQ, "RME32", (void *) rme32)) {
1372 snd_printk("unable to grab IRQ %d\n", pci->irq); 1372 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1373 return -EBUSY; 1373 return -EBUSY;
1374 } 1374 }
1375 rme32->irq = pci->irq; 1375 rme32->irq = pci->irq;
1376 1376
1377 if ((rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE)) == 0) { 1377 if ((rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE)) == 0) {
1378 snd_printk("unable to remap memory region 0x%lx-0x%lx\n", 1378 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n",
1379 rme32->port, rme32->port + RME32_IO_SIZE - 1); 1379 rme32->port, rme32->port + RME32_IO_SIZE - 1);
1380 return -ENOMEM; 1380 return -ENOMEM;
1381 } 1381 }
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index c495cae78dbf..0eddeb16a10f 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -1570,13 +1570,13 @@ snd_rme96_create(rme96_t *rme96)
1570 rme96->port = pci_resource_start(rme96->pci, 0); 1570 rme96->port = pci_resource_start(rme96->pci, 0);
1571 1571
1572 if (request_irq(pci->irq, snd_rme96_interrupt, SA_INTERRUPT|SA_SHIRQ, "RME96", (void *)rme96)) { 1572 if (request_irq(pci->irq, snd_rme96_interrupt, SA_INTERRUPT|SA_SHIRQ, "RME96", (void *)rme96)) {
1573 snd_printk("unable to grab IRQ %d\n", pci->irq); 1573 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1574 return -EBUSY; 1574 return -EBUSY;
1575 } 1575 }
1576 rme96->irq = pci->irq; 1576 rme96->irq = pci->irq;
1577 1577
1578 if ((rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE)) == 0) { 1578 if ((rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE)) == 0) {
1579 snd_printk("unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1); 1579 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1);
1580 return -ENOMEM; 1580 return -ENOMEM;
1581 } 1581 }
1582 1582
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 52525eb198c7..845158b01b02 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -671,11 +671,7 @@ static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
671 } 671 }
672 } 672 }
673 673
674 if ((1000 / HZ) < 3000) { 674 ssleep(3);
675 ssleep(3);
676 } else {
677 mdelay(3000);
678 }
679 675
680 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) { 676 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
681 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n"); 677 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");
@@ -692,7 +688,7 @@ static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
692 688
693 } 689 }
694 if (hdsp->state & HDSP_InitializationComplete) { 690 if (hdsp->state & HDSP_InitializationComplete) {
695 snd_printk("Hammerfall-DSP: firmware loaded from cache, restoring defaults\n"); 691 snd_printk(KERN_INFO "Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
696 spin_lock_irqsave(&hdsp->lock, flags); 692 spin_lock_irqsave(&hdsp->lock, flags);
697 snd_hdsp_set_defaults(hdsp); 693 snd_hdsp_set_defaults(hdsp);
698 spin_unlock_irqrestore(&hdsp->lock, flags); 694 spin_unlock_irqrestore(&hdsp->lock, flags);
@@ -709,9 +705,8 @@ static int hdsp_get_iobox_version (hdsp_t *hdsp)
709 705
710 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM); 706 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
711 hdsp_write (hdsp, HDSP_fifoData, 0); 707 hdsp_write (hdsp, HDSP_fifoData, 0);
712 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) { 708 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0)
713 return -EIO; 709 return -EIO;
714 }
715 710
716 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD); 711 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
717 hdsp_write (hdsp, HDSP_fifoData, 0); 712 hdsp_write (hdsp, HDSP_fifoData, 0);
@@ -726,22 +721,30 @@ static int hdsp_get_iobox_version (hdsp_t *hdsp)
726 } 721 }
727 } else { 722 } else {
728 /* firmware was already loaded, get iobox type */ 723 /* firmware was already loaded, get iobox type */
729 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) { 724 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
730 hdsp->io_type = Multiface; 725 hdsp->io_type = Multiface;
731 } else { 726 else
732 hdsp->io_type = Digiface; 727 hdsp->io_type = Digiface;
733 }
734 } 728 }
735 return 0; 729 return 0;
736} 730}
737 731
738 732
739static int hdsp_check_for_firmware (hdsp_t *hdsp) 733static int hdsp_check_for_firmware (hdsp_t *hdsp, int show_err)
740{ 734{
741 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; 735 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
742 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 736 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
743 snd_printk("Hammerfall-DSP: firmware not present.\n"); 737 snd_printk(KERN_ERR "Hammerfall-DSP: firmware not present.\n");
744 hdsp->state &= ~HDSP_FirmwareLoaded; 738 hdsp->state &= ~HDSP_FirmwareLoaded;
739 if (! show_err)
740 return -EIO;
741 /* try to load firmware */
742 if (hdsp->state & HDSP_FirmwareCached) {
743 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0)
744 snd_printk(KERN_ERR "Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
745 } else {
746 snd_printk(KERN_ERR "Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
747 }
745 return -EIO; 748 return -EIO;
746 } 749 }
747 return 0; 750 return 0;
@@ -775,9 +778,9 @@ static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout)
775 778
776static int hdsp_read_gain (hdsp_t *hdsp, unsigned int addr) 779static int hdsp_read_gain (hdsp_t *hdsp, unsigned int addr)
777{ 780{
778 if (addr >= HDSP_MATRIX_MIXER_SIZE) { 781 if (addr >= HDSP_MATRIX_MIXER_SIZE)
779 return 0; 782 return 0;
780 } 783
781 return hdsp->mixer_matrix[addr]; 784 return hdsp->mixer_matrix[addr];
782} 785}
783 786
@@ -802,13 +805,11 @@ static int hdsp_write_gain(hdsp_t *hdsp, unsigned int addr, unsigned short data)
802 memory." 805 memory."
803 */ 806 */
804 807
805 if (hdsp->io_type == H9632 && addr >= 512) { 808 if (hdsp->io_type == H9632 && addr >= 512)
806 return 0; 809 return 0;
807 }
808 810
809 if (hdsp->io_type == H9652 && addr >= 1352) { 811 if (hdsp->io_type == H9652 && addr >= 1352)
810 return 0; 812 return 0;
811 }
812 813
813 hdsp->mixer_matrix[addr] = data; 814 hdsp->mixer_matrix[addr] = data;
814 815
@@ -832,9 +833,8 @@ static int hdsp_write_gain(hdsp_t *hdsp, unsigned int addr, unsigned short data)
832 833
833 ad = (addr << 16) + data; 834 ad = (addr << 16) + data;
834 835
835 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) { 836 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
836 return -1; 837 return -1;
837 }
838 838
839 hdsp_write (hdsp, HDSP_fifoData, ad); 839 hdsp_write (hdsp, HDSP_fifoData, ad);
840 hdsp->mixer_matrix[addr] = data; 840 hdsp->mixer_matrix[addr] = data;
@@ -851,9 +851,8 @@ static int snd_hdsp_use_is_exclusive(hdsp_t *hdsp)
851 851
852 spin_lock_irqsave(&hdsp->lock, flags); 852 spin_lock_irqsave(&hdsp->lock, flags);
853 if ((hdsp->playback_pid != hdsp->capture_pid) && 853 if ((hdsp->playback_pid != hdsp->capture_pid) &&
854 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0)) { 854 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
855 ret = 0; 855 ret = 0;
856 }
857 spin_unlock_irqrestore(&hdsp->lock, flags); 856 spin_unlock_irqrestore(&hdsp->lock, flags);
858 return ret; 857 return ret;
859} 858}
@@ -880,9 +879,8 @@ static int hdsp_spdif_sample_rate(hdsp_t *hdsp)
880 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister); 879 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
881 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask); 880 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
882 881
883 if (status & HDSP_SPDIFErrorFlag) { 882 if (status & HDSP_SPDIFErrorFlag)
884 return 0; 883 return 0;
885 }
886 884
887 switch (rate_bits) { 885 switch (rate_bits) {
888 case HDSP_spdifFrequency32KHz: return 32000; 886 case HDSP_spdifFrequency32KHz: return 32000;
@@ -918,9 +916,8 @@ static snd_pcm_uframes_t hdsp_hw_pointer(hdsp_t *hdsp)
918 916
919 position = hdsp_read(hdsp, HDSP_statusRegister); 917 position = hdsp_read(hdsp, HDSP_statusRegister);
920 918
921 if (!hdsp->precise_ptr) { 919 if (!hdsp->precise_ptr)
922 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0; 920 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
923 }
924 921
925 position &= HDSP_BufferPositionMask; 922 position &= HDSP_BufferPositionMask;
926 position /= 4; 923 position /= 4;
@@ -989,19 +986,19 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
989 if (!(hdsp->control_register & HDSP_ClockModeMaster)) { 986 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
990 if (called_internally) { 987 if (called_internally) {
991 /* request from ctl or card initialization */ 988 /* request from ctl or card initialization */
992 snd_printk("Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n"); 989 snd_printk(KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
993 return -1; 990 return -1;
994 } else { 991 } else {
995 /* hw_param request while in AutoSync mode */ 992 /* hw_param request while in AutoSync mode */
996 int external_freq = hdsp_external_sample_rate(hdsp); 993 int external_freq = hdsp_external_sample_rate(hdsp);
997 int spdif_freq = hdsp_spdif_sample_rate(hdsp); 994 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
998 995
999 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) { 996 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1000 snd_printk("Hammerfall-DSP: Detected ADAT in double speed mode\n"); 997 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in double speed mode\n");
1001 } else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) { 998 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1002 snd_printk("Hammerfall-DSP: Detected ADAT in quad speed mode\n"); 999 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in quad speed mode\n");
1003 } else if (rate != external_freq) { 1000 else if (rate != external_freq) {
1004 snd_printk("Hammerfall-DSP: No AutoSync source for requested rate\n"); 1001 snd_printk(KERN_INFO "Hammerfall-DSP: No AutoSync source for requested rate\n");
1005 return -1; 1002 return -1;
1006 } 1003 }
1007 } 1004 }
@@ -1019,63 +1016,53 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
1019 exists for externally-driven rate changes. All we can do 1016 exists for externally-driven rate changes. All we can do
1020 is to flag rate changes in the read/write routines. */ 1017 is to flag rate changes in the read/write routines. */
1021 1018
1022 if (rate > 96000 && hdsp->io_type != H9632) { 1019 if (rate > 96000 && hdsp->io_type != H9632)
1023 return -EINVAL; 1020 return -EINVAL;
1024 }
1025 1021
1026 switch (rate) { 1022 switch (rate) {
1027 case 32000: 1023 case 32000:
1028 if (current_rate > 48000) { 1024 if (current_rate > 48000)
1029 reject_if_open = 1; 1025 reject_if_open = 1;
1030 }
1031 rate_bits = HDSP_Frequency32KHz; 1026 rate_bits = HDSP_Frequency32KHz;
1032 break; 1027 break;
1033 case 44100: 1028 case 44100:
1034 if (current_rate > 48000) { 1029 if (current_rate > 48000)
1035 reject_if_open = 1; 1030 reject_if_open = 1;
1036 }
1037 rate_bits = HDSP_Frequency44_1KHz; 1031 rate_bits = HDSP_Frequency44_1KHz;
1038 break; 1032 break;
1039 case 48000: 1033 case 48000:
1040 if (current_rate > 48000) { 1034 if (current_rate > 48000)
1041 reject_if_open = 1; 1035 reject_if_open = 1;
1042 }
1043 rate_bits = HDSP_Frequency48KHz; 1036 rate_bits = HDSP_Frequency48KHz;
1044 break; 1037 break;
1045 case 64000: 1038 case 64000:
1046 if (current_rate <= 48000 || current_rate > 96000) { 1039 if (current_rate <= 48000 || current_rate > 96000)
1047 reject_if_open = 1; 1040 reject_if_open = 1;
1048 }
1049 rate_bits = HDSP_Frequency64KHz; 1041 rate_bits = HDSP_Frequency64KHz;
1050 break; 1042 break;
1051 case 88200: 1043 case 88200:
1052 if (current_rate <= 48000 || current_rate > 96000) { 1044 if (current_rate <= 48000 || current_rate > 96000)
1053 reject_if_open = 1; 1045 reject_if_open = 1;
1054 }
1055 rate_bits = HDSP_Frequency88_2KHz; 1046 rate_bits = HDSP_Frequency88_2KHz;
1056 break; 1047 break;
1057 case 96000: 1048 case 96000:
1058 if (current_rate <= 48000 || current_rate > 96000) { 1049 if (current_rate <= 48000 || current_rate > 96000)
1059 reject_if_open = 1; 1050 reject_if_open = 1;
1060 }
1061 rate_bits = HDSP_Frequency96KHz; 1051 rate_bits = HDSP_Frequency96KHz;
1062 break; 1052 break;
1063 case 128000: 1053 case 128000:
1064 if (current_rate < 128000) { 1054 if (current_rate < 128000)
1065 reject_if_open = 1; 1055 reject_if_open = 1;
1066 }
1067 rate_bits = HDSP_Frequency128KHz; 1056 rate_bits = HDSP_Frequency128KHz;
1068 break; 1057 break;
1069 case 176400: 1058 case 176400:
1070 if (current_rate < 128000) { 1059 if (current_rate < 128000)
1071 reject_if_open = 1; 1060 reject_if_open = 1;
1072 }
1073 rate_bits = HDSP_Frequency176_4KHz; 1061 rate_bits = HDSP_Frequency176_4KHz;
1074 break; 1062 break;
1075 case 192000: 1063 case 192000:
1076 if (current_rate < 128000) { 1064 if (current_rate < 128000)
1077 reject_if_open = 1; 1065 reject_if_open = 1;
1078 }
1079 rate_bits = HDSP_Frequency192KHz; 1066 rate_bits = HDSP_Frequency192KHz;
1080 break; 1067 break;
1081 default: 1068 default:
@@ -1096,11 +1083,10 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
1096 if (rate >= 128000) { 1083 if (rate >= 128000) {
1097 hdsp->channel_map = channel_map_H9632_qs; 1084 hdsp->channel_map = channel_map_H9632_qs;
1098 } else if (rate > 48000) { 1085 } else if (rate > 48000) {
1099 if (hdsp->io_type == H9632) { 1086 if (hdsp->io_type == H9632)
1100 hdsp->channel_map = channel_map_H9632_ds; 1087 hdsp->channel_map = channel_map_H9632_ds;
1101 } else { 1088 else
1102 hdsp->channel_map = channel_map_ds; 1089 hdsp->channel_map = channel_map_ds;
1103 }
1104 } else { 1090 } else {
1105 switch (hdsp->io_type) { 1091 switch (hdsp->io_type) {
1106 case Multiface: 1092 case Multiface:
@@ -1131,54 +1117,48 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
1131static unsigned char snd_hdsp_midi_read_byte (hdsp_t *hdsp, int id) 1117static unsigned char snd_hdsp_midi_read_byte (hdsp_t *hdsp, int id)
1132{ 1118{
1133 /* the hardware already does the relevant bit-mask with 0xff */ 1119 /* the hardware already does the relevant bit-mask with 0xff */
1134 if (id) { 1120 if (id)
1135 return hdsp_read(hdsp, HDSP_midiDataIn1); 1121 return hdsp_read(hdsp, HDSP_midiDataIn1);
1136 } else { 1122 else
1137 return hdsp_read(hdsp, HDSP_midiDataIn0); 1123 return hdsp_read(hdsp, HDSP_midiDataIn0);
1138 }
1139} 1124}
1140 1125
1141static void snd_hdsp_midi_write_byte (hdsp_t *hdsp, int id, int val) 1126static void snd_hdsp_midi_write_byte (hdsp_t *hdsp, int id, int val)
1142{ 1127{
1143 /* the hardware already does the relevant bit-mask with 0xff */ 1128 /* the hardware already does the relevant bit-mask with 0xff */
1144 if (id) { 1129 if (id)
1145 hdsp_write(hdsp, HDSP_midiDataOut1, val); 1130 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1146 } else { 1131 else
1147 hdsp_write(hdsp, HDSP_midiDataOut0, val); 1132 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1148 }
1149} 1133}
1150 1134
1151static int snd_hdsp_midi_input_available (hdsp_t *hdsp, int id) 1135static int snd_hdsp_midi_input_available (hdsp_t *hdsp, int id)
1152{ 1136{
1153 if (id) { 1137 if (id)
1154 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff); 1138 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1155 } else { 1139 else
1156 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff); 1140 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1157 }
1158} 1141}
1159 1142
1160static int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id) 1143static int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id)
1161{ 1144{
1162 int fifo_bytes_used; 1145 int fifo_bytes_used;
1163 1146
1164 if (id) { 1147 if (id)
1165 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff; 1148 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1166 } else { 1149 else
1167 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff; 1150 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1168 }
1169 1151
1170 if (fifo_bytes_used < 128) { 1152 if (fifo_bytes_used < 128)
1171 return 128 - fifo_bytes_used; 1153 return 128 - fifo_bytes_used;
1172 } else { 1154 else
1173 return 0; 1155 return 0;
1174 }
1175} 1156}
1176 1157
1177static void snd_hdsp_flush_midi_input (hdsp_t *hdsp, int id) 1158static void snd_hdsp_flush_midi_input (hdsp_t *hdsp, int id)
1178{ 1159{
1179 while (snd_hdsp_midi_input_available (hdsp, id)) { 1160 while (snd_hdsp_midi_input_available (hdsp, id))
1180 snd_hdsp_midi_read_byte (hdsp, id); 1161 snd_hdsp_midi_read_byte (hdsp, id);
1181 }
1182} 1162}
1183 1163
1184static int snd_hdsp_midi_output_write (hdsp_midi_t *hmidi) 1164static int snd_hdsp_midi_output_write (hdsp_midi_t *hmidi)
@@ -1219,28 +1199,23 @@ static int snd_hdsp_midi_input_read (hdsp_midi_t *hmidi)
1219 spin_lock_irqsave (&hmidi->lock, flags); 1199 spin_lock_irqsave (&hmidi->lock, flags);
1220 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) { 1200 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1221 if (hmidi->input) { 1201 if (hmidi->input) {
1222 if (n_pending > (int)sizeof (buf)) { 1202 if (n_pending > (int)sizeof (buf))
1223 n_pending = sizeof (buf); 1203 n_pending = sizeof (buf);
1224 } 1204 for (i = 0; i < n_pending; ++i)
1225 for (i = 0; i < n_pending; ++i) {
1226 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); 1205 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1227 } 1206 if (n_pending)
1228 if (n_pending) {
1229 snd_rawmidi_receive (hmidi->input, buf, n_pending); 1207 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1230 }
1231 } else { 1208 } else {
1232 /* flush the MIDI input FIFO */ 1209 /* flush the MIDI input FIFO */
1233 while (--n_pending) { 1210 while (--n_pending)
1234 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); 1211 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1235 }
1236 } 1212 }
1237 } 1213 }
1238 hmidi->pending = 0; 1214 hmidi->pending = 0;
1239 if (hmidi->id) { 1215 if (hmidi->id)
1240 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable; 1216 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1241 } else { 1217 else
1242 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable; 1218 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1243 }
1244 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register); 1219 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1245 spin_unlock_irqrestore (&hmidi->lock, flags); 1220 spin_unlock_irqrestore (&hmidi->lock, flags);
1246 return snd_hdsp_midi_output_write (hmidi); 1221 return snd_hdsp_midi_output_write (hmidi);
@@ -1310,9 +1285,8 @@ static void snd_hdsp_midi_output_trigger(snd_rawmidi_substream_t * substream, in
1310 hmidi->istimer++; 1285 hmidi->istimer++;
1311 } 1286 }
1312 } else { 1287 } else {
1313 if (hmidi->istimer && --hmidi->istimer <= 0) { 1288 if (hmidi->istimer && --hmidi->istimer <= 0)
1314 del_timer (&hmidi->timer); 1289 del_timer (&hmidi->timer);
1315 }
1316 } 1290 }
1317 spin_unlock_irqrestore (&hmidi->lock, flags); 1291 spin_unlock_irqrestore (&hmidi->lock, flags);
1318 if (up) 1292 if (up)
@@ -1400,9 +1374,8 @@ static int __devinit snd_hdsp_create_midi (snd_card_t *card, hdsp_t *hdsp, int i
1400 spin_lock_init (&hdsp->midi[id].lock); 1374 spin_lock_init (&hdsp->midi[id].lock);
1401 1375
1402 sprintf (buf, "%s MIDI %d", card->shortname, id+1); 1376 sprintf (buf, "%s MIDI %d", card->shortname, id+1);
1403 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0) { 1377 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1404 return -1; 1378 return -1;
1405 }
1406 1379
1407 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1); 1380 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1408 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id]; 1381 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
@@ -1588,11 +1561,10 @@ static int hdsp_spdif_out(hdsp_t *hdsp)
1588 1561
1589static int hdsp_set_spdif_output(hdsp_t *hdsp, int out) 1562static int hdsp_set_spdif_output(hdsp_t *hdsp, int out)
1590{ 1563{
1591 if (out) { 1564 if (out)
1592 hdsp->control_register |= HDSP_SPDIFOpticalOut; 1565 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1593 } else { 1566 else
1594 hdsp->control_register &= ~HDSP_SPDIFOpticalOut; 1567 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1595 }
1596 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1568 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1597 return 0; 1569 return 0;
1598} 1570}
@@ -1642,11 +1614,10 @@ static int hdsp_spdif_professional(hdsp_t *hdsp)
1642 1614
1643static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val) 1615static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val)
1644{ 1616{
1645 if (val) { 1617 if (val)
1646 hdsp->control_register |= HDSP_SPDIFProfessional; 1618 hdsp->control_register |= HDSP_SPDIFProfessional;
1647 } else { 1619 else
1648 hdsp->control_register &= ~HDSP_SPDIFProfessional; 1620 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1649 }
1650 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1621 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1651 return 0; 1622 return 0;
1652} 1623}
@@ -1687,11 +1658,10 @@ static int hdsp_spdif_emphasis(hdsp_t *hdsp)
1687 1658
1688static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val) 1659static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val)
1689{ 1660{
1690 if (val) { 1661 if (val)
1691 hdsp->control_register |= HDSP_SPDIFEmphasis; 1662 hdsp->control_register |= HDSP_SPDIFEmphasis;
1692 } else { 1663 else
1693 hdsp->control_register &= ~HDSP_SPDIFEmphasis; 1664 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1694 }
1695 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1665 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1696 return 0; 1666 return 0;
1697} 1667}
@@ -1732,11 +1702,10 @@ static int hdsp_spdif_nonaudio(hdsp_t *hdsp)
1732 1702
1733static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val) 1703static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val)
1734{ 1704{
1735 if (val) { 1705 if (val)
1736 hdsp->control_register |= HDSP_SPDIFNonAudio; 1706 hdsp->control_register |= HDSP_SPDIFNonAudio;
1737 } else { 1707 else
1738 hdsp->control_register &= ~HDSP_SPDIFNonAudio; 1708 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1739 }
1740 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1709 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1741 return 0; 1710 return 0;
1742} 1711}
@@ -1921,11 +1890,10 @@ static int snd_hdsp_get_autosync_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_
1921 1890
1922static int hdsp_system_clock_mode(hdsp_t *hdsp) 1891static int hdsp_system_clock_mode(hdsp_t *hdsp)
1923{ 1892{
1924 if (hdsp->control_register & HDSP_ClockModeMaster) { 1893 if (hdsp->control_register & HDSP_ClockModeMaster)
1925 return 0; 1894 return 0;
1926 } else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate) { 1895 else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
1927 return 0; 1896 return 0;
1928 }
1929 return 1; 1897 return 1;
1930} 1898}
1931 1899
@@ -2074,16 +2042,17 @@ static int snd_hdsp_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_val
2074 val = ucontrol->value.enumerated.item[0]; 2042 val = ucontrol->value.enumerated.item[0];
2075 if (val < 0) val = 0; 2043 if (val < 0) val = 0;
2076 if (hdsp->io_type == H9632) { 2044 if (hdsp->io_type == H9632) {
2077 if (val > 9) val = 9; 2045 if (val > 9)
2046 val = 9;
2078 } else { 2047 } else {
2079 if (val > 6) val = 6; 2048 if (val > 6)
2049 val = 6;
2080 } 2050 }
2081 spin_lock_irq(&hdsp->lock); 2051 spin_lock_irq(&hdsp->lock);
2082 if (val != hdsp_clock_source(hdsp)) { 2052 if (val != hdsp_clock_source(hdsp))
2083 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0; 2053 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2084 } else { 2054 else
2085 change = 0; 2055 change = 0;
2086 }
2087 spin_unlock_irq(&hdsp->lock); 2056 spin_unlock_irq(&hdsp->lock);
2088 return change; 2057 return change;
2089} 2058}
@@ -2193,11 +2162,10 @@ static int snd_hdsp_put_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
2193 if (val < 0) val = 0; 2162 if (val < 0) val = 0;
2194 if (val > 2) val = 2; 2163 if (val > 2) val = 2;
2195 spin_lock_irq(&hdsp->lock); 2164 spin_lock_irq(&hdsp->lock);
2196 if (val != hdsp_da_gain(hdsp)) { 2165 if (val != hdsp_da_gain(hdsp))
2197 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0; 2166 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2198 } else { 2167 else
2199 change = 0; 2168 change = 0;
2200 }
2201 spin_unlock_irq(&hdsp->lock); 2169 spin_unlock_irq(&hdsp->lock);
2202 return change; 2170 return change;
2203} 2171}
@@ -2279,11 +2247,10 @@ static int snd_hdsp_put_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
2279 if (val < 0) val = 0; 2247 if (val < 0) val = 0;
2280 if (val > 2) val = 2; 2248 if (val > 2) val = 2;
2281 spin_lock_irq(&hdsp->lock); 2249 spin_lock_irq(&hdsp->lock);
2282 if (val != hdsp_ad_gain(hdsp)) { 2250 if (val != hdsp_ad_gain(hdsp))
2283 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0; 2251 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2284 } else { 2252 else
2285 change = 0; 2253 change = 0;
2286 }
2287 spin_unlock_irq(&hdsp->lock); 2254 spin_unlock_irq(&hdsp->lock);
2288 return change; 2255 return change;
2289} 2256}
@@ -2365,11 +2332,10 @@ static int snd_hdsp_put_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
2365 if (val < 0) val = 0; 2332 if (val < 0) val = 0;
2366 if (val > 2) val = 2; 2333 if (val > 2) val = 2;
2367 spin_lock_irq(&hdsp->lock); 2334 spin_lock_irq(&hdsp->lock);
2368 if (val != hdsp_phone_gain(hdsp)) { 2335 if (val != hdsp_phone_gain(hdsp))
2369 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0; 2336 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2370 } else { 2337 else
2371 change = 0; 2338 change = 0;
2372 }
2373 spin_unlock_irq(&hdsp->lock); 2339 spin_unlock_irq(&hdsp->lock);
2374 return change; 2340 return change;
2375} 2341}
@@ -2385,19 +2351,17 @@ static int snd_hdsp_put_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
2385 2351
2386static int hdsp_xlr_breakout_cable(hdsp_t *hdsp) 2352static int hdsp_xlr_breakout_cable(hdsp_t *hdsp)
2387{ 2353{
2388 if (hdsp->control_register & HDSP_XLRBreakoutCable) { 2354 if (hdsp->control_register & HDSP_XLRBreakoutCable)
2389 return 1; 2355 return 1;
2390 }
2391 return 0; 2356 return 0;
2392} 2357}
2393 2358
2394static int hdsp_set_xlr_breakout_cable(hdsp_t *hdsp, int mode) 2359static int hdsp_set_xlr_breakout_cable(hdsp_t *hdsp, int mode)
2395{ 2360{
2396 if (mode) { 2361 if (mode)
2397 hdsp->control_register |= HDSP_XLRBreakoutCable; 2362 hdsp->control_register |= HDSP_XLRBreakoutCable;
2398 } else { 2363 else
2399 hdsp->control_register &= ~HDSP_XLRBreakoutCable; 2364 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2400 }
2401 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 2365 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2402 return 0; 2366 return 0;
2403} 2367}
@@ -2450,19 +2414,17 @@ static int snd_hdsp_put_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_el
2450 2414
2451static int hdsp_aeb(hdsp_t *hdsp) 2415static int hdsp_aeb(hdsp_t *hdsp)
2452{ 2416{
2453 if (hdsp->control_register & HDSP_AnalogExtensionBoard) { 2417 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
2454 return 1; 2418 return 1;
2455 }
2456 return 0; 2419 return 0;
2457} 2420}
2458 2421
2459static int hdsp_set_aeb(hdsp_t *hdsp, int mode) 2422static int hdsp_set_aeb(hdsp_t *hdsp, int mode)
2460{ 2423{
2461 if (mode) { 2424 if (mode)
2462 hdsp->control_register |= HDSP_AnalogExtensionBoard; 2425 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2463 } else { 2426 else
2464 hdsp->control_register &= ~HDSP_AnalogExtensionBoard; 2427 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2465 }
2466 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 2428 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2467 return 0; 2429 return 0;
2468} 2430}
@@ -2705,11 +2667,10 @@ static int hdsp_line_out(hdsp_t *hdsp)
2705 2667
2706static int hdsp_set_line_output(hdsp_t *hdsp, int out) 2668static int hdsp_set_line_output(hdsp_t *hdsp, int out)
2707{ 2669{
2708 if (out) { 2670 if (out)
2709 hdsp->control_register |= HDSP_LineOut; 2671 hdsp->control_register |= HDSP_LineOut;
2710 } else { 2672 else
2711 hdsp->control_register &= ~HDSP_LineOut; 2673 hdsp->control_register &= ~HDSP_LineOut;
2712 }
2713 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 2674 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2714 return 0; 2675 return 0;
2715} 2676}
@@ -2760,11 +2721,10 @@ static int snd_hdsp_put_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
2760 2721
2761static int hdsp_set_precise_pointer(hdsp_t *hdsp, int precise) 2722static int hdsp_set_precise_pointer(hdsp_t *hdsp, int precise)
2762{ 2723{
2763 if (precise) { 2724 if (precise)
2764 hdsp->precise_ptr = 1; 2725 hdsp->precise_ptr = 1;
2765 } else { 2726 else
2766 hdsp->precise_ptr = 0; 2727 hdsp->precise_ptr = 0;
2767 }
2768 return 0; 2728 return 0;
2769} 2729}
2770 2730
@@ -2814,11 +2774,10 @@ static int snd_hdsp_put_precise_pointer(snd_kcontrol_t * kcontrol, snd_ctl_elem_
2814 2774
2815static int hdsp_set_use_midi_tasklet(hdsp_t *hdsp, int use_tasklet) 2775static int hdsp_set_use_midi_tasklet(hdsp_t *hdsp, int use_tasklet)
2816{ 2776{
2817 if (use_tasklet) { 2777 if (use_tasklet)
2818 hdsp->use_midi_tasklet = 1; 2778 hdsp->use_midi_tasklet = 1;
2819 } else { 2779 else
2820 hdsp->use_midi_tasklet = 0; 2780 hdsp->use_midi_tasklet = 0;
2821 }
2822 return 0; 2781 return 0;
2823} 2782}
2824 2783
@@ -2889,11 +2848,10 @@ static int snd_hdsp_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *
2889 source = ucontrol->value.integer.value[0]; 2848 source = ucontrol->value.integer.value[0];
2890 destination = ucontrol->value.integer.value[1]; 2849 destination = ucontrol->value.integer.value[1];
2891 2850
2892 if (source >= hdsp->max_channels) { 2851 if (source >= hdsp->max_channels)
2893 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination); 2852 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2894 } else { 2853 else
2895 addr = hdsp_input_to_output_key(hdsp,source, destination); 2854 addr = hdsp_input_to_output_key(hdsp,source, destination);
2896 }
2897 2855
2898 spin_lock_irq(&hdsp->lock); 2856 spin_lock_irq(&hdsp->lock);
2899 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr); 2857 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
@@ -2916,11 +2874,10 @@ static int snd_hdsp_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *
2916 source = ucontrol->value.integer.value[0]; 2874 source = ucontrol->value.integer.value[0];
2917 destination = ucontrol->value.integer.value[1]; 2875 destination = ucontrol->value.integer.value[1];
2918 2876
2919 if (source >= hdsp->max_channels) { 2877 if (source >= hdsp->max_channels)
2920 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination); 2878 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2921 } else { 2879 else
2922 addr = hdsp_input_to_output_key(hdsp,source, destination); 2880 addr = hdsp_input_to_output_key(hdsp,source, destination);
2923 }
2924 2881
2925 gain = ucontrol->value.integer.value[2]; 2882 gain = ucontrol->value.integer.value[2];
2926 2883
@@ -2957,14 +2914,12 @@ static int hdsp_wc_sync_check(hdsp_t *hdsp)
2957{ 2914{
2958 int status2 = hdsp_read(hdsp, HDSP_status2Register); 2915 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2959 if (status2 & HDSP_wc_lock) { 2916 if (status2 & HDSP_wc_lock) {
2960 if (status2 & HDSP_wc_sync) { 2917 if (status2 & HDSP_wc_sync)
2961 return 2; 2918 return 2;
2962 } else { 2919 else
2963 return 1; 2920 return 1;
2964 } 2921 } else
2965 } else {
2966 return 0; 2922 return 0;
2967 }
2968 return 0; 2923 return 0;
2969} 2924}
2970 2925
@@ -2988,14 +2943,13 @@ static int snd_hdsp_get_wc_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_va
2988static int hdsp_spdif_sync_check(hdsp_t *hdsp) 2943static int hdsp_spdif_sync_check(hdsp_t *hdsp)
2989{ 2944{
2990 int status = hdsp_read(hdsp, HDSP_statusRegister); 2945 int status = hdsp_read(hdsp, HDSP_statusRegister);
2991 if (status & HDSP_SPDIFErrorFlag) { 2946 if (status & HDSP_SPDIFErrorFlag)
2992 return 0; 2947 return 0;
2993 } else { 2948 else {
2994 if (status & HDSP_SPDIFSync) { 2949 if (status & HDSP_SPDIFSync)
2995 return 2; 2950 return 2;
2996 } else { 2951 else
2997 return 1; 2952 return 1;
2998 }
2999 } 2953 }
3000 return 0; 2954 return 0;
3001} 2955}
@@ -3021,14 +2975,12 @@ static int hdsp_adatsync_sync_check(hdsp_t *hdsp)
3021{ 2975{
3022 int status = hdsp_read(hdsp, HDSP_statusRegister); 2976 int status = hdsp_read(hdsp, HDSP_statusRegister);
3023 if (status & HDSP_TimecodeLock) { 2977 if (status & HDSP_TimecodeLock) {
3024 if (status & HDSP_TimecodeSync) { 2978 if (status & HDSP_TimecodeSync)
3025 return 2; 2979 return 2;
3026 } else { 2980 else
3027 return 1; 2981 return 1;
3028 } 2982 } else
3029 } else {
3030 return 0; 2983 return 0;
3031 }
3032} 2984}
3033 2985
3034static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 2986static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
@@ -3051,14 +3003,12 @@ static int hdsp_adat_sync_check(hdsp_t *hdsp, int idx)
3051 int status = hdsp_read(hdsp, HDSP_statusRegister); 3003 int status = hdsp_read(hdsp, HDSP_statusRegister);
3052 3004
3053 if (status & (HDSP_Lock0>>idx)) { 3005 if (status & (HDSP_Lock0>>idx)) {
3054 if (status & (HDSP_Sync0>>idx)) { 3006 if (status & (HDSP_Sync0>>idx))
3055 return 2; 3007 return 2;
3056 } else { 3008 else
3057 return 1; 3009 return 1;
3058 } 3010 } else
3059 } else {
3060 return 0; 3011 return 0;
3061 }
3062} 3012}
3063 3013
3064static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 3014static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
@@ -3171,9 +3121,8 @@ static int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
3171 snd_kcontrol_t *kctl; 3121 snd_kcontrol_t *kctl;
3172 3122
3173 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) { 3123 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3174 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0) { 3124 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3175 return err; 3125 return err;
3176 }
3177 if (idx == 1) /* IEC958 (S/PDIF) Stream */ 3126 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3178 hdsp->spdif_ctl = kctl; 3127 hdsp->spdif_ctl = kctl;
3179 } 3128 }
@@ -3181,32 +3130,28 @@ static int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
3181 /* ADAT SyncCheck status */ 3130 /* ADAT SyncCheck status */
3182 snd_hdsp_adat_sync_check.name = "ADAT Lock Status"; 3131 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3183 snd_hdsp_adat_sync_check.index = 1; 3132 snd_hdsp_adat_sync_check.index = 1;
3184 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) { 3133 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3185 return err; 3134 return err;
3186 }
3187 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) { 3135 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3188 for (idx = 1; idx < 3; ++idx) { 3136 for (idx = 1; idx < 3; ++idx) {
3189 snd_hdsp_adat_sync_check.index = idx+1; 3137 snd_hdsp_adat_sync_check.index = idx+1;
3190 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) { 3138 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3191 return err; 3139 return err;
3192 }
3193 } 3140 }
3194 } 3141 }
3195 3142
3196 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */ 3143 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3197 if (hdsp->io_type == H9632) { 3144 if (hdsp->io_type == H9632) {
3198 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) { 3145 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3199 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0) { 3146 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
3200 return err; 3147 return err;
3201 }
3202 } 3148 }
3203 } 3149 }
3204 3150
3205 /* AEB control for H96xx card */ 3151 /* AEB control for H96xx card */
3206 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) { 3152 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3207 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0) { 3153 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
3208 return err; 3154 return err;
3209 }
3210 } 3155 }
3211 3156
3212 return 0; 3157 return 0;
@@ -3228,12 +3173,11 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3228 char *clock_source; 3173 char *clock_source;
3229 int x; 3174 int x;
3230 3175
3231 if (hdsp_check_for_iobox (hdsp)) { 3176 if (hdsp_check_for_iobox (hdsp))
3232 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n"); 3177 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
3233 return; 3178 return;
3234 }
3235 3179
3236 if (hdsp_check_for_firmware(hdsp)) { 3180 if (hdsp_check_for_firmware(hdsp, 0)) {
3237 if (hdsp->state & HDSP_FirmwareCached) { 3181 if (hdsp->state & HDSP_FirmwareCached) {
3238 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) { 3182 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3239 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n"); 3183 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
@@ -3314,11 +3258,10 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3314 } 3258 }
3315 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source); 3259 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3316 3260
3317 if (hdsp_system_clock_mode(hdsp)) { 3261 if (hdsp_system_clock_mode(hdsp))
3318 system_clock_mode = "Slave"; 3262 system_clock_mode = "Slave";
3319 } else { 3263 else
3320 system_clock_mode = "Master"; 3264 system_clock_mode = "Master";
3321 }
3322 3265
3323 switch (hdsp_pref_sync_ref (hdsp)) { 3266 switch (hdsp_pref_sync_ref (hdsp)) {
3324 case HDSP_SYNC_FROM_WORD: 3267 case HDSP_SYNC_FROM_WORD:
@@ -3400,85 +3343,75 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3400 break; 3343 break;
3401 } 3344 }
3402 3345
3403 if (hdsp->control_register & HDSP_SPDIFOpticalOut) { 3346 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3404 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n"); 3347 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3405 } else { 3348 else
3406 snd_iprintf(buffer, "IEC958 output: Coaxial only\n"); 3349 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3407 }
3408 3350
3409 if (hdsp->control_register & HDSP_SPDIFProfessional) { 3351 if (hdsp->control_register & HDSP_SPDIFProfessional)
3410 snd_iprintf(buffer, "IEC958 quality: Professional\n"); 3352 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3411 } else { 3353 else
3412 snd_iprintf(buffer, "IEC958 quality: Consumer\n"); 3354 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3413 }
3414 3355
3415 if (hdsp->control_register & HDSP_SPDIFEmphasis) { 3356 if (hdsp->control_register & HDSP_SPDIFEmphasis)
3416 snd_iprintf(buffer, "IEC958 emphasis: on\n"); 3357 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3417 } else { 3358 else
3418 snd_iprintf(buffer, "IEC958 emphasis: off\n"); 3359 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3419 }
3420 3360
3421 if (hdsp->control_register & HDSP_SPDIFNonAudio) { 3361 if (hdsp->control_register & HDSP_SPDIFNonAudio)
3422 snd_iprintf(buffer, "IEC958 NonAudio: on\n"); 3362 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3423 } else { 3363 else
3424 snd_iprintf(buffer, "IEC958 NonAudio: off\n"); 3364 snd_iprintf(buffer, "IEC958 NonAudio: off\n");
3425 } 3365 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0)
3426 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0) {
3427 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x); 3366 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x);
3428 } else { 3367 else
3429 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n"); 3368 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n");
3430 }
3431 3369
3432 snd_iprintf(buffer, "\n"); 3370 snd_iprintf(buffer, "\n");
3433 3371
3434 /* Sync Check */ 3372 /* Sync Check */
3435 x = status & HDSP_Sync0; 3373 x = status & HDSP_Sync0;
3436 if (status & HDSP_Lock0) { 3374 if (status & HDSP_Lock0)
3437 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock"); 3375 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock");
3438 } else { 3376 else
3439 snd_iprintf(buffer, "ADAT1: No Lock\n"); 3377 snd_iprintf(buffer, "ADAT1: No Lock\n");
3440 }
3441 3378
3442 switch (hdsp->io_type) { 3379 switch (hdsp->io_type) {
3443 case Digiface: 3380 case Digiface:
3444 case H9652: 3381 case H9652:
3445 x = status & HDSP_Sync1; 3382 x = status & HDSP_Sync1;
3446 if (status & HDSP_Lock1) { 3383 if (status & HDSP_Lock1)
3447 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock"); 3384 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
3448 } else { 3385 else
3449 snd_iprintf(buffer, "ADAT2: No Lock\n"); 3386 snd_iprintf(buffer, "ADAT2: No Lock\n");
3450 }
3451 x = status & HDSP_Sync2; 3387 x = status & HDSP_Sync2;
3452 if (status & HDSP_Lock2) { 3388 if (status & HDSP_Lock2)
3453 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock"); 3389 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock");
3454 } else { 3390 else
3455 snd_iprintf(buffer, "ADAT3: No Lock\n"); 3391 snd_iprintf(buffer, "ADAT3: No Lock\n");
3456 } 3392 break;
3457 default: 3393 default:
3458 /* relax */ 3394 /* relax */
3459 break; 3395 break;
3460 } 3396 }
3461 3397
3462 x = status & HDSP_SPDIFSync; 3398 x = status & HDSP_SPDIFSync;
3463 if (status & HDSP_SPDIFErrorFlag) { 3399 if (status & HDSP_SPDIFErrorFlag)
3464 snd_iprintf (buffer, "SPDIF: No Lock\n"); 3400 snd_iprintf (buffer, "SPDIF: No Lock\n");
3465 } else { 3401 else
3466 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock"); 3402 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
3467 }
3468 3403
3469 x = status2 & HDSP_wc_sync; 3404 x = status2 & HDSP_wc_sync;
3470 if (status2 & HDSP_wc_lock) { 3405 if (status2 & HDSP_wc_lock)
3471 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock"); 3406 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
3472 } else { 3407 else
3473 snd_iprintf (buffer, "Word Clock: No Lock\n"); 3408 snd_iprintf (buffer, "Word Clock: No Lock\n");
3474 }
3475 3409
3476 x = status & HDSP_TimecodeSync; 3410 x = status & HDSP_TimecodeSync;
3477 if (status & HDSP_TimecodeLock) { 3411 if (status & HDSP_TimecodeLock)
3478 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock"); 3412 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
3479 } else { 3413 else
3480 snd_iprintf(buffer, "ADAT Sync: No Lock\n"); 3414 snd_iprintf(buffer, "ADAT Sync: No Lock\n");
3481 }
3482 3415
3483 snd_iprintf(buffer, "\n"); 3416 snd_iprintf(buffer, "\n");
3484 3417
@@ -3527,11 +3460,10 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3527 3460
3528 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no"); 3461 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
3529 3462
3530 if (hdsp->control_register & HDSP_AnalogExtensionBoard) { 3463 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
3531 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n"); 3464 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
3532 } else { 3465 else
3533 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n"); 3466 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n");
3534 }
3535 snd_iprintf(buffer, "\n"); 3467 snd_iprintf(buffer, "\n");
3536 } 3468 }
3537 3469
@@ -3610,25 +3542,22 @@ static int snd_hdsp_set_defaults(hdsp_t *hdsp)
3610#else 3542#else
3611 hdsp->control2_register = 0; 3543 hdsp->control2_register = 0;
3612#endif 3544#endif
3613 if (hdsp->io_type == H9652) { 3545 if (hdsp->io_type == H9652)
3614 snd_hdsp_9652_enable_mixer (hdsp); 3546 snd_hdsp_9652_enable_mixer (hdsp);
3615 } else { 3547 else
3616 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register); 3548 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3617 }
3618 3549
3619 hdsp_reset_hw_pointer(hdsp); 3550 hdsp_reset_hw_pointer(hdsp);
3620 hdsp_compute_period_size(hdsp); 3551 hdsp_compute_period_size(hdsp);
3621 3552
3622 /* silence everything */ 3553 /* silence everything */
3623 3554
3624 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i) { 3555 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i)
3625 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN; 3556 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3626 }
3627 3557
3628 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) { 3558 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3629 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN)) { 3559 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
3630 return -EIO; 3560 return -EIO;
3631 }
3632 } 3561 }
3633 3562
3634 /* H9632 specific defaults */ 3563 /* H9632 specific defaults */
@@ -3649,12 +3578,10 @@ static void hdsp_midi_tasklet(unsigned long arg)
3649{ 3578{
3650 hdsp_t *hdsp = (hdsp_t *)arg; 3579 hdsp_t *hdsp = (hdsp_t *)arg;
3651 3580
3652 if (hdsp->midi[0].pending) { 3581 if (hdsp->midi[0].pending)
3653 snd_hdsp_midi_input_read (&hdsp->midi[0]); 3582 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3654 } 3583 if (hdsp->midi[1].pending)
3655 if (hdsp->midi[1].pending) {
3656 snd_hdsp_midi_input_read (&hdsp->midi[1]); 3584 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3657 }
3658} 3585}
3659 3586
3660static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs) 3587static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
@@ -3674,9 +3601,8 @@ static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *reg
3674 midi0 = status & HDSP_midi0IRQPending; 3601 midi0 = status & HDSP_midi0IRQPending;
3675 midi1 = status & HDSP_midi1IRQPending; 3602 midi1 = status & HDSP_midi1IRQPending;
3676 3603
3677 if (!audio && !midi0 && !midi1) { 3604 if (!audio && !midi0 && !midi1)
3678 return IRQ_NONE; 3605 return IRQ_NONE;
3679 }
3680 3606
3681 hdsp_write(hdsp, HDSP_interruptConfirmation, 0); 3607 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3682 3608
@@ -3684,13 +3610,11 @@ static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *reg
3684 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff; 3610 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3685 3611
3686 if (audio) { 3612 if (audio) {
3687 if (hdsp->capture_substream) { 3613 if (hdsp->capture_substream)
3688 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 3614 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3689 }
3690 3615
3691 if (hdsp->playback_substream) { 3616 if (hdsp->playback_substream)
3692 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream); 3617 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3693 }
3694 } 3618 }
3695 3619
3696 if (midi0 && midi0status) { 3620 if (midi0 && midi0status) {
@@ -3735,15 +3659,13 @@ static char *hdsp_channel_buffer_location(hdsp_t *hdsp,
3735 3659
3736 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL); 3660 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL);
3737 3661
3738 if ((mapped_channel = hdsp->channel_map[channel]) < 0) { 3662 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3739 return NULL; 3663 return NULL;
3740 }
3741 3664
3742 if (stream == SNDRV_PCM_STREAM_CAPTURE) { 3665 if (stream == SNDRV_PCM_STREAM_CAPTURE)
3743 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES); 3666 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3744 } else { 3667 else
3745 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES); 3668 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3746 }
3747} 3669}
3748 3670
3749static int snd_hdsp_playback_copy(snd_pcm_substream_t *substream, int channel, 3671static int snd_hdsp_playback_copy(snd_pcm_substream_t *substream, int channel,
@@ -3824,20 +3746,11 @@ static int snd_hdsp_hw_params(snd_pcm_substream_t *substream,
3824 pid_t this_pid; 3746 pid_t this_pid;
3825 pid_t other_pid; 3747 pid_t other_pid;
3826 3748
3827 if (hdsp_check_for_iobox (hdsp)) { 3749 if (hdsp_check_for_iobox (hdsp))
3828 return -EIO; 3750 return -EIO;
3829 }
3830 3751
3831 if (hdsp_check_for_firmware(hdsp)) { 3752 if (hdsp_check_for_firmware(hdsp, 1))
3832 if (hdsp->state & HDSP_FirmwareCached) {
3833 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3834 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
3835 }
3836 } else {
3837 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
3838 }
3839 return -EIO; 3753 return -EIO;
3840 }
3841 3754
3842 spin_lock_irq(&hdsp->lock); 3755 spin_lock_irq(&hdsp->lock);
3843 3756
@@ -3908,9 +3821,8 @@ static int snd_hdsp_channel_info(snd_pcm_substream_t *substream,
3908 3821
3909 snd_assert(info->channel < hdsp->max_channels, return -EINVAL); 3822 snd_assert(info->channel < hdsp->max_channels, return -EINVAL);
3910 3823
3911 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) { 3824 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0)
3912 return -EINVAL; 3825 return -EINVAL;
3913 }
3914 3826
3915 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES; 3827 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
3916 info->first = 0; 3828 info->first = 0;
@@ -3923,14 +3835,9 @@ static int snd_hdsp_ioctl(snd_pcm_substream_t *substream,
3923{ 3835{
3924 switch (cmd) { 3836 switch (cmd) {
3925 case SNDRV_PCM_IOCTL1_RESET: 3837 case SNDRV_PCM_IOCTL1_RESET:
3926 {
3927 return snd_hdsp_reset(substream); 3838 return snd_hdsp_reset(substream);
3928 }
3929 case SNDRV_PCM_IOCTL1_CHANNEL_INFO: 3839 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
3930 { 3840 return snd_hdsp_channel_info(substream, arg);
3931 snd_pcm_channel_info_t *info = arg;
3932 return snd_hdsp_channel_info(substream, info);
3933 }
3934 default: 3841 default:
3935 break; 3842 break;
3936 } 3843 }
@@ -3944,20 +3851,11 @@ static int snd_hdsp_trigger(snd_pcm_substream_t *substream, int cmd)
3944 snd_pcm_substream_t *other; 3851 snd_pcm_substream_t *other;
3945 int running; 3852 int running;
3946 3853
3947 if (hdsp_check_for_iobox (hdsp)) { 3854 if (hdsp_check_for_iobox (hdsp))
3948 return -EIO; 3855 return -EIO;
3949 }
3950 3856
3951 if (hdsp_check_for_firmware(hdsp)) { 3857 if (hdsp_check_for_firmware(hdsp, 1))
3952 if (hdsp->state & HDSP_FirmwareCached) {
3953 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3954 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
3955 }
3956 } else {
3957 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
3958 }
3959 return -EIO; 3858 return -EIO;
3960 }
3961 3859
3962 spin_lock(&hdsp->lock); 3860 spin_lock(&hdsp->lock);
3963 running = hdsp->running; 3861 running = hdsp->running;
@@ -4022,20 +3920,11 @@ static int snd_hdsp_prepare(snd_pcm_substream_t *substream)
4022 hdsp_t *hdsp = snd_pcm_substream_chip(substream); 3920 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4023 int result = 0; 3921 int result = 0;
4024 3922
4025 if (hdsp_check_for_iobox (hdsp)) { 3923 if (hdsp_check_for_iobox (hdsp))
4026 return -EIO; 3924 return -EIO;
4027 }
4028 3925
4029 if (hdsp_check_for_firmware(hdsp)) { 3926 if (hdsp_check_for_firmware(hdsp, 1))
4030 if (hdsp->state & HDSP_FirmwareCached) {
4031 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4032 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4033 }
4034 } else {
4035 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4036 }
4037 return -EIO; 3927 return -EIO;
4038 }
4039 3928
4040 spin_lock_irq(&hdsp->lock); 3929 spin_lock_irq(&hdsp->lock);
4041 if (!hdsp->running) 3930 if (!hdsp->running)
@@ -4285,20 +4174,11 @@ static int snd_hdsp_playback_open(snd_pcm_substream_t *substream)
4285 hdsp_t *hdsp = snd_pcm_substream_chip(substream); 4174 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4286 snd_pcm_runtime_t *runtime = substream->runtime; 4175 snd_pcm_runtime_t *runtime = substream->runtime;
4287 4176
4288 if (hdsp_check_for_iobox (hdsp)) { 4177 if (hdsp_check_for_iobox (hdsp))
4289 return -EIO; 4178 return -EIO;
4290 }
4291 4179
4292 if (hdsp_check_for_firmware(hdsp)) { 4180 if (hdsp_check_for_firmware(hdsp, 1))
4293 if (hdsp->state & HDSP_FirmwareCached) {
4294 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4295 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4296 }
4297 } else {
4298 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4299 }
4300 return -EIO; 4181 return -EIO;
4301 }
4302 4182
4303 spin_lock_irq(&hdsp->lock); 4183 spin_lock_irq(&hdsp->lock);
4304 4184
@@ -4367,20 +4247,11 @@ static int snd_hdsp_capture_open(snd_pcm_substream_t *substream)
4367 hdsp_t *hdsp = snd_pcm_substream_chip(substream); 4247 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4368 snd_pcm_runtime_t *runtime = substream->runtime; 4248 snd_pcm_runtime_t *runtime = substream->runtime;
4369 4249
4370 if (hdsp_check_for_iobox (hdsp)) { 4250 if (hdsp_check_for_iobox (hdsp))
4371 return -EIO; 4251 return -EIO;
4372 }
4373 4252
4374 if (hdsp_check_for_firmware(hdsp)) { 4253 if (hdsp_check_for_firmware(hdsp, 1))
4375 if (hdsp->state & HDSP_FirmwareCached) {
4376 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4377 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4378 }
4379 } else {
4380 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4381 }
4382 return -EIO; 4254 return -EIO;
4383 }
4384 4255
4385 spin_lock_irq(&hdsp->lock); 4256 spin_lock_irq(&hdsp->lock);
4386 4257
@@ -4589,19 +4460,17 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4589 int i; 4460 int i;
4590 4461
4591 if (!(hdsp->state & HDSP_FirmwareLoaded)) { 4462 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4592 snd_printk("Hammerfall-DSP: Firmware needs to be uploaded to the card.\n"); 4463 snd_printk(KERN_ERR "Hammerfall-DSP: Firmware needs to be uploaded to the card.\n");
4593 return -EINVAL; 4464 return -EINVAL;
4594 } 4465 }
4595 spin_lock_irqsave(&hdsp->lock, flags); 4466 spin_lock_irqsave(&hdsp->lock, flags);
4596 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp); 4467 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4597 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp); 4468 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4598 if (hdsp->io_type != H9632) { 4469 if (hdsp->io_type != H9632)
4599 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp); 4470 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4600 }
4601 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp); 4471 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4602 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i) { 4472 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i)
4603 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i); 4473 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4604 }
4605 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp); 4474 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4606 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp); 4475 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
4607 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp); 4476 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
@@ -4621,9 +4490,8 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4621 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp); 4490 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4622 4491
4623 } 4492 }
4624 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) { 4493 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4625 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp); 4494 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
4626 }
4627 spin_unlock_irqrestore(&hdsp->lock, flags); 4495 spin_unlock_irqrestore(&hdsp->lock, flags);
4628 if (copy_to_user(argp, &info, sizeof(info))) 4496 if (copy_to_user(argp, &info, sizeof(info)))
4629 return -EFAULT; 4497 return -EFAULT;
@@ -4645,15 +4513,13 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4645 4513
4646 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; 4514 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4647 if (hdsp->io_type == Undefined) { 4515 if (hdsp->io_type == Undefined) {
4648 if ((err = hdsp_get_iobox_version(hdsp)) < 0) { 4516 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4649 return err; 4517 return err;
4650 }
4651 } 4518 }
4652 hdsp_version.io_type = hdsp->io_type; 4519 hdsp_version.io_type = hdsp->io_type;
4653 hdsp_version.firmware_rev = hdsp->firmware_rev; 4520 hdsp_version.firmware_rev = hdsp->firmware_rev;
4654 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version)))) { 4521 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))))
4655 return -EFAULT; 4522 return -EFAULT;
4656 }
4657 break; 4523 break;
4658 } 4524 }
4659 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: { 4525 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
@@ -4668,38 +4534,33 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4668 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded)) 4534 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4669 return -EBUSY; 4535 return -EBUSY;
4670 4536
4671 snd_printk("Hammerfall-DSP: initializing firmware upload\n"); 4537 snd_printk(KERN_INFO "Hammerfall-DSP: initializing firmware upload\n");
4672 firmware = (hdsp_firmware_t __user *)argp; 4538 firmware = (hdsp_firmware_t __user *)argp;
4673 4539
4674 if (get_user(firmware_data, &firmware->firmware_data)) { 4540 if (get_user(firmware_data, &firmware->firmware_data))
4675 return -EFAULT; 4541 return -EFAULT;
4676 }
4677 4542
4678 if (hdsp_check_for_iobox (hdsp)) { 4543 if (hdsp_check_for_iobox (hdsp))
4679 return -EIO; 4544 return -EIO;
4680 }
4681 4545
4682 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0) { 4546 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0)
4683 return -EFAULT; 4547 return -EFAULT;
4684 }
4685 4548
4686 hdsp->state |= HDSP_FirmwareCached; 4549 hdsp->state |= HDSP_FirmwareCached;
4687 4550
4688 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0) { 4551 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4689 return err; 4552 return err;
4690 }
4691 4553
4692 if (!(hdsp->state & HDSP_InitializationComplete)) { 4554 if (!(hdsp->state & HDSP_InitializationComplete)) {
4693 if ((err = snd_hdsp_enable_io(hdsp)) < 0) { 4555 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4694 return err; 4556 return err;
4695 }
4696 4557
4697 snd_hdsp_initialize_channels(hdsp); 4558 snd_hdsp_initialize_channels(hdsp);
4698 snd_hdsp_initialize_midi_flush(hdsp); 4559 snd_hdsp_initialize_midi_flush(hdsp);
4699 4560
4700 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) { 4561 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4701 snd_printk("Hammerfall-DSP: error creating alsa devices\n"); 4562 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
4702 return err; 4563 return err;
4703 } 4564 }
4704 } 4565 }
4705 break; 4566 break;
@@ -4790,7 +4651,7 @@ static int snd_hdsp_enable_io (hdsp_t *hdsp)
4790 int i; 4651 int i;
4791 4652
4792 if (hdsp_fifo_wait (hdsp, 0, 100)) { 4653 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4793 snd_printk("Hammerfall-DSP: enable_io fifo_wait failed\n"); 4654 snd_printk(KERN_ERR "Hammerfall-DSP: enable_io fifo_wait failed\n");
4794 return -EIO; 4655 return -EIO;
4795 } 4656 }
4796 4657
@@ -4856,25 +4717,25 @@ static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4856 int err; 4717 int err;
4857 4718
4858 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) { 4719 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
4859 snd_printk("Hammerfall-DSP: Error creating pcm interface\n"); 4720 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating pcm interface\n");
4860 return err; 4721 return err;
4861 } 4722 }
4862 4723
4863 4724
4864 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) { 4725 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
4865 snd_printk("Hammerfall-DSP: Error creating first midi interface\n"); 4726 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating first midi interface\n");
4866 return err; 4727 return err;
4867 } 4728 }
4868 4729
4869 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) { 4730 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
4870 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) { 4731 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
4871 snd_printk("Hammerfall-DSP: Error creating second midi interface\n"); 4732 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating second midi interface\n");
4872 return err; 4733 return err;
4873 } 4734 }
4874 } 4735 }
4875 4736
4876 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) { 4737 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
4877 snd_printk("Hammerfall-DSP: Error creating ctl interface\n"); 4738 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating ctl interface\n");
4878 return err; 4739 return err;
4879 } 4740 }
4880 4741
@@ -4887,7 +4748,7 @@ static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4887 hdsp->playback_substream = NULL; 4748 hdsp->playback_substream = NULL;
4888 4749
4889 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) { 4750 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
4890 snd_printk("Hammerfall-DSP: Error setting default values\n"); 4751 snd_printk(KERN_ERR "Hammerfall-DSP: Error setting default values\n");
4891 return err; 4752 return err;
4892 } 4753 }
4893 4754
@@ -4897,7 +4758,7 @@ static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4897 hdsp->port, hdsp->irq); 4758 hdsp->port, hdsp->irq);
4898 4759
4899 if ((err = snd_card_register(card)) < 0) { 4760 if ((err = snd_card_register(card)) < 0) {
4900 snd_printk("Hammerfall-DSP: error registering card\n"); 4761 snd_printk(KERN_ERR "Hammerfall-DSP: error registering card\n");
4901 return err; 4762 return err;
4902 } 4763 }
4903 hdsp->state |= HDSP_InitializationComplete; 4764 hdsp->state |= HDSP_InitializationComplete;
@@ -4963,18 +4824,17 @@ static int __devinit hdsp_request_fw_loader(hdsp_t *hdsp)
4963 return err; 4824 return err;
4964 4825
4965 if (!(hdsp->state & HDSP_InitializationComplete)) { 4826 if (!(hdsp->state & HDSP_InitializationComplete)) {
4966 if ((err = snd_hdsp_enable_io(hdsp)) < 0) { 4827 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4967 return err; 4828 return err;
4968 }
4969 4829
4970 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) { 4830 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
4971 snd_printk("Hammerfall-DSP: error creating hwdep device\n"); 4831 snd_printk(KERN_ERR "Hammerfall-DSP: error creating hwdep device\n");
4972 return err; 4832 return err;
4973 } 4833 }
4974 snd_hdsp_initialize_channels(hdsp); 4834 snd_hdsp_initialize_channels(hdsp);
4975 snd_hdsp_initialize_midi_flush(hdsp); 4835 snd_hdsp_initialize_midi_flush(hdsp);
4976 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) { 4836 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4977 snd_printk("Hammerfall-DSP: error creating alsa devices\n"); 4837 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
4978 return err; 4838 return err;
4979 } 4839 }
4980 } 4840 }
@@ -5029,11 +4889,11 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5029 strcpy(card->driver, "H-DSP"); 4889 strcpy(card->driver, "H-DSP");
5030 strcpy(card->mixername, "Xilinx FPGA"); 4890 strcpy(card->mixername, "Xilinx FPGA");
5031 4891
5032 if (hdsp->firmware_rev < 0xa) { 4892 if (hdsp->firmware_rev < 0xa)
5033 return -ENODEV; 4893 return -ENODEV;
5034 } else if (hdsp->firmware_rev < 0x64) { 4894 else if (hdsp->firmware_rev < 0x64)
5035 hdsp->card_name = "RME Hammerfall DSP"; 4895 hdsp->card_name = "RME Hammerfall DSP";
5036 } else if (hdsp->firmware_rev < 0x96) { 4896 else if (hdsp->firmware_rev < 0x96) {
5037 hdsp->card_name = "RME HDSP 9652"; 4897 hdsp->card_name = "RME HDSP 9652";
5038 is_9652 = 1; 4898 is_9652 = 1;
5039 } else { 4899 } else {
@@ -5042,9 +4902,8 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5042 is_9632 = 1; 4902 is_9632 = 1;
5043 } 4903 }
5044 4904
5045 if ((err = pci_enable_device(pci)) < 0) { 4905 if ((err = pci_enable_device(pci)) < 0)
5046 return err; 4906 return err;
5047 }
5048 4907
5049 pci_set_master(hdsp->pci); 4908 pci_set_master(hdsp->pci);
5050 4909
@@ -5052,12 +4911,12 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5052 return err; 4911 return err;
5053 hdsp->port = pci_resource_start(pci, 0); 4912 hdsp->port = pci_resource_start(pci, 0);
5054 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) { 4913 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5055 snd_printk("Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1); 4914 snd_printk(KERN_ERR "Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5056 return -EBUSY; 4915 return -EBUSY;
5057 } 4916 }
5058 4917
5059 if (request_irq(pci->irq, snd_hdsp_interrupt, SA_INTERRUPT|SA_SHIRQ, "hdsp", (void *)hdsp)) { 4918 if (request_irq(pci->irq, snd_hdsp_interrupt, SA_INTERRUPT|SA_SHIRQ, "hdsp", (void *)hdsp)) {
5060 snd_printk("Hammerfall-DSP: unable to use IRQ %d\n", pci->irq); 4919 snd_printk(KERN_ERR "Hammerfall-DSP: unable to use IRQ %d\n", pci->irq);
5061 return -EBUSY; 4920 return -EBUSY;
5062 } 4921 }
5063 4922
@@ -5065,71 +4924,58 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5065 hdsp->precise_ptr = 1; 4924 hdsp->precise_ptr = 1;
5066 hdsp->use_midi_tasklet = 1; 4925 hdsp->use_midi_tasklet = 1;
5067 4926
5068 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0) { 4927 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5069 return err; 4928 return err;
5070 }
5071 4929
5072 if (!is_9652 && !is_9632) { 4930 if (!is_9652 && !is_9632) {
5073 /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */ 4931 /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */
5074 if ((1000 / HZ) < 2000) { 4932 ssleep(2);
5075 ssleep(2);
5076 } else {
5077 mdelay(2000);
5078 }
5079 4933
5080 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 4934 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5081#ifdef HDSP_FW_LOADER 4935#ifdef HDSP_FW_LOADER
5082 if ((err = hdsp_request_fw_loader(hdsp)) < 0) { 4936 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5083 /* we don't fail as this can happen 4937 /* we don't fail as this can happen
5084 if userspace is not ready for 4938 if userspace is not ready for
5085 firmware upload 4939 firmware upload
5086 */ 4940 */
5087 snd_printk("Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n"); 4941 snd_printk(KERN_ERR "Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n");
5088 } else { 4942 else
5089 /* init is complete, we return */ 4943 /* init is complete, we return */
5090 return 0; 4944 return 0;
5091 }
5092#endif 4945#endif
5093 /* no iobox connected, we defer initialization */ 4946 /* no iobox connected, we defer initialization */
5094 snd_printk("Hammerfall-DSP: card initialization pending : waiting for firmware\n"); 4947 snd_printk(KERN_INFO "Hammerfall-DSP: card initialization pending : waiting for firmware\n");
5095 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) { 4948 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5096 return err; 4949 return err;
5097 }
5098 return 0; 4950 return 0;
5099 } else { 4951 } else {
5100 snd_printk("Hammerfall-DSP: Firmware already present, initializing card.\n"); 4952 snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n");
5101 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) { 4953 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5102 hdsp->io_type = Multiface; 4954 hdsp->io_type = Multiface;
5103 } else { 4955 else
5104 hdsp->io_type = Digiface; 4956 hdsp->io_type = Digiface;
5105 }
5106 } 4957 }
5107 } 4958 }
5108 4959
5109 if ((err = snd_hdsp_enable_io(hdsp)) != 0) { 4960 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5110 return err; 4961 return err;
5111 }
5112 4962
5113 if (is_9652) { 4963 if (is_9652)
5114 hdsp->io_type = H9652; 4964 hdsp->io_type = H9652;
5115 }
5116 4965
5117 if (is_9632) { 4966 if (is_9632)
5118 hdsp->io_type = H9632; 4967 hdsp->io_type = H9632;
5119 }
5120 4968
5121 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) { 4969 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5122 return err; 4970 return err;
5123 }
5124 4971
5125 snd_hdsp_initialize_channels(hdsp); 4972 snd_hdsp_initialize_channels(hdsp);
5126 snd_hdsp_initialize_midi_flush(hdsp); 4973 snd_hdsp_initialize_midi_flush(hdsp);
5127 4974
5128 hdsp->state |= HDSP_FirmwareLoaded; 4975 hdsp->state |= HDSP_FirmwareLoaded;
5129 4976
5130 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0) { 4977 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5131 return err; 4978 return err;
5132 }
5133 4979
5134 return 0; 4980 return 0;
5135} 4981}
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index fc3f3283ff37..60a1141f1327 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -3563,8 +3563,7 @@ static int snd_hdspm_free(hdspm_t * hdspm)
3563 free_irq(hdspm->irq, (void *) hdspm); 3563 free_irq(hdspm->irq, (void *) hdspm);
3564 3564
3565 3565
3566 if (hdspm->mixer) 3566 kfree(hdspm->mixer);
3567 kfree(hdspm->mixer);
3568 3567
3569 if (hdspm->iobase) 3568 if (hdspm->iobase)
3570 iounmap(hdspm->iobase); 3569 iounmap(hdspm->iobase);
diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
index b600f45e1834..59fcef9b6b81 100644
--- a/sound/pci/rme9652/rme9652.c
+++ b/sound/pci/rme9652/rme9652.c
@@ -779,7 +779,7 @@ static inline int rme9652_spdif_sample_rate(rme9652_t *s)
779 break; 779 break;
780 780
781 default: 781 default:
782 snd_printk("%s: unknown S/PDIF input rate (bits = 0x%x)\n", 782 snd_printk(KERN_ERR "%s: unknown S/PDIF input rate (bits = 0x%x)\n",
783 s->card_name, rate_bits); 783 s->card_name, rate_bits);
784 return 0; 784 return 0;
785 break; 785 break;
@@ -2496,12 +2496,12 @@ static int __devinit snd_rme9652_create(snd_card_t *card,
2496 rme9652->port = pci_resource_start(pci, 0); 2496 rme9652->port = pci_resource_start(pci, 0);
2497 rme9652->iobase = ioremap_nocache(rme9652->port, RME9652_IO_EXTENT); 2497 rme9652->iobase = ioremap_nocache(rme9652->port, RME9652_IO_EXTENT);
2498 if (rme9652->iobase == NULL) { 2498 if (rme9652->iobase == NULL) {
2499 snd_printk("unable to remap region 0x%lx-0x%lx\n", rme9652->port, rme9652->port + RME9652_IO_EXTENT - 1); 2499 snd_printk(KERN_ERR "unable to remap region 0x%lx-0x%lx\n", rme9652->port, rme9652->port + RME9652_IO_EXTENT - 1);
2500 return -EBUSY; 2500 return -EBUSY;
2501 } 2501 }
2502 2502
2503 if (request_irq(pci->irq, snd_rme9652_interrupt, SA_INTERRUPT|SA_SHIRQ, "rme9652", (void *)rme9652)) { 2503 if (request_irq(pci->irq, snd_rme9652_interrupt, SA_INTERRUPT|SA_SHIRQ, "rme9652", (void *)rme9652)) {
2504 snd_printk("unable to request IRQ %d\n", pci->irq); 2504 snd_printk(KERN_ERR "unable to request IRQ %d\n", pci->irq);
2505 return -EBUSY; 2505 return -EBUSY;
2506 } 2506 }
2507 rme9652->irq = pci->irq; 2507 rme9652->irq = pci->irq;
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index 1f6c2bfd43fd..9a35474aad05 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -591,7 +591,7 @@ static irqreturn_t snd_sonicvibes_interrupt(int irq, void *dev_id, struct pt_reg
591 return IRQ_NONE; 591 return IRQ_NONE;
592 if (status == 0xff) { /* failure */ 592 if (status == 0xff) { /* failure */
593 outb(sonic->irqmask = ~0, SV_REG(sonic, IRQMASK)); 593 outb(sonic->irqmask = ~0, SV_REG(sonic, IRQMASK));
594 snd_printk("IRQ failure - interrupts disabled!!\n"); 594 snd_printk(KERN_ERR "IRQ failure - interrupts disabled!!\n");
595 return IRQ_HANDLED; 595 return IRQ_HANDLED;
596 } 596 }
597 if (sonic->pcm) { 597 if (sonic->pcm) {
@@ -1205,14 +1205,8 @@ static int snd_sonicvibes_free(sonicvibes_t *sonic)
1205 pci_write_config_dword(sonic->pci, 0x48, sonic->dmac_port); 1205 pci_write_config_dword(sonic->pci, 0x48, sonic->dmac_port);
1206 if (sonic->irq >= 0) 1206 if (sonic->irq >= 0)
1207 free_irq(sonic->irq, (void *)sonic); 1207 free_irq(sonic->irq, (void *)sonic);
1208 if (sonic->res_dmaa) { 1208 release_and_free_resource(sonic->res_dmaa);
1209 release_resource(sonic->res_dmaa); 1209 release_and_free_resource(sonic->res_dmac);
1210 kfree_nocheck(sonic->res_dmaa);
1211 }
1212 if (sonic->res_dmac) {
1213 release_resource(sonic->res_dmac);
1214 kfree_nocheck(sonic->res_dmac);
1215 }
1216 pci_release_regions(sonic->pci); 1210 pci_release_regions(sonic->pci);
1217 pci_disable_device(sonic->pci); 1211 pci_disable_device(sonic->pci);
1218 kfree(sonic); 1212 kfree(sonic);
@@ -1245,7 +1239,7 @@ static int __devinit snd_sonicvibes_create(snd_card_t * card,
1245 /* check, if we can restrict PCI DMA transfers to 24 bits */ 1239 /* check, if we can restrict PCI DMA transfers to 24 bits */
1246 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 || 1240 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
1247 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) { 1241 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
1248 snd_printk("architecture does not support 24bit PCI busmaster DMA\n"); 1242 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n");
1249 pci_disable_device(pci); 1243 pci_disable_device(pci);
1250 return -ENXIO; 1244 return -ENXIO;
1251 } 1245 }
@@ -1273,7 +1267,7 @@ static int __devinit snd_sonicvibes_create(snd_card_t * card,
1273 sonic->game_port = pci_resource_start(pci, 4); 1267 sonic->game_port = pci_resource_start(pci, 4);
1274 1268
1275 if (request_irq(pci->irq, snd_sonicvibes_interrupt, SA_INTERRUPT|SA_SHIRQ, "S3 SonicVibes", (void *)sonic)) { 1269 if (request_irq(pci->irq, snd_sonicvibes_interrupt, SA_INTERRUPT|SA_SHIRQ, "S3 SonicVibes", (void *)sonic)) {
1276 snd_printk("unable to grab IRQ %d\n", pci->irq); 1270 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1277 snd_sonicvibes_free(sonic); 1271 snd_sonicvibes_free(sonic);
1278 return -EBUSY; 1272 return -EBUSY;
1279 } 1273 }
@@ -1287,24 +1281,24 @@ static int __devinit snd_sonicvibes_create(snd_card_t * card,
1287 if (!dmaa) { 1281 if (!dmaa) {
1288 dmaa = dmaio; 1282 dmaa = dmaio;
1289 dmaio += 0x10; 1283 dmaio += 0x10;
1290 snd_printk("BIOS did not allocate DDMA channel A i/o, allocated at 0x%x\n", dmaa); 1284 snd_printk(KERN_INFO "BIOS did not allocate DDMA channel A i/o, allocated at 0x%x\n", dmaa);
1291 } 1285 }
1292 if (!dmac) { 1286 if (!dmac) {
1293 dmac = dmaio; 1287 dmac = dmaio;
1294 dmaio += 0x10; 1288 dmaio += 0x10;
1295 snd_printk("BIOS did not allocate DDMA channel C i/o, allocated at 0x%x\n", dmac); 1289 snd_printk(KERN_INFO "BIOS did not allocate DDMA channel C i/o, allocated at 0x%x\n", dmac);
1296 } 1290 }
1297 pci_write_config_dword(pci, 0x40, dmaa); 1291 pci_write_config_dword(pci, 0x40, dmaa);
1298 pci_write_config_dword(pci, 0x48, dmac); 1292 pci_write_config_dword(pci, 0x48, dmac);
1299 1293
1300 if ((sonic->res_dmaa = request_region(dmaa, 0x10, "S3 SonicVibes DDMA-A")) == NULL) { 1294 if ((sonic->res_dmaa = request_region(dmaa, 0x10, "S3 SonicVibes DDMA-A")) == NULL) {
1301 snd_sonicvibes_free(sonic); 1295 snd_sonicvibes_free(sonic);
1302 snd_printk("unable to grab DDMA-A port at 0x%x-0x%x\n", dmaa, dmaa + 0x10 - 1); 1296 snd_printk(KERN_ERR "unable to grab DDMA-A port at 0x%x-0x%x\n", dmaa, dmaa + 0x10 - 1);
1303 return -EBUSY; 1297 return -EBUSY;
1304 } 1298 }
1305 if ((sonic->res_dmac = request_region(dmac, 0x10, "S3 SonicVibes DDMA-C")) == NULL) { 1299 if ((sonic->res_dmac = request_region(dmac, 0x10, "S3 SonicVibes DDMA-C")) == NULL) {
1306 snd_sonicvibes_free(sonic); 1300 snd_sonicvibes_free(sonic);
1307 snd_printk("unable to grab DDMA-C port at 0x%x-0x%x\n", dmac, dmac + 0x10 - 1); 1301 snd_printk(KERN_ERR "unable to grab DDMA-C port at 0x%x-0x%x\n", dmac, dmac + 0x10 - 1);
1308 return -EBUSY; 1302 return -EBUSY;
1309 } 1303 }
1310 1304
diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index 777da9a7298b..b9b93c7faafd 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -153,7 +153,7 @@ static unsigned short snd_trident_codec_read(ac97_t *ac97, unsigned short reg)
153 } 153 }
154 154
155 if (count == 0 && !trident->ac97_detect) { 155 if (count == 0 && !trident->ac97_detect) {
156 snd_printk("ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n", reg, data); 156 snd_printk(KERN_ERR "ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n", reg, data);
157 data = 0; 157 data = 0;
158 } 158 }
159 159
@@ -2893,7 +2893,8 @@ static void snd_trident_notify_pcm_change1(snd_card_t * card, snd_kcontrol_t *kc
2893{ 2893{
2894 snd_ctl_elem_id_t id; 2894 snd_ctl_elem_id_t id;
2895 2895
2896 snd_runtime_check(kctl != NULL, return); 2896 if (! kctl)
2897 return;
2897 if (activate) 2898 if (activate)
2898 kctl->vd[num].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; 2899 kctl->vd[num].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
2899 else 2900 else
@@ -2989,13 +2990,13 @@ static int __devinit snd_trident_mixer(trident_t * trident, int pcm_spdif_device
2989 _ac97.num = 1; 2990 _ac97.num = 1;
2990 err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97_sec); 2991 err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97_sec);
2991 if (err < 0) 2992 if (err < 0)
2992 snd_printk("SI7018: the secondary codec - invalid access\n"); 2993 snd_printk(KERN_ERR "SI7018: the secondary codec - invalid access\n");
2993#if 0 // only for my testing purpose --jk 2994#if 0 // only for my testing purpose --jk
2994 { 2995 {
2995 ac97_t *mc97; 2996 ac97_t *mc97;
2996 err = snd_ac97_modem(trident->card, &_ac97, &mc97); 2997 err = snd_ac97_modem(trident->card, &_ac97, &mc97);
2997 if (err < 0) 2998 if (err < 0)
2998 snd_printk("snd_ac97_modem returned error %i\n", err); 2999 snd_printk(KERN_ERR "snd_ac97_modem returned error %i\n", err);
2999 } 3000 }
3000#endif 3001#endif
3001 } 3002 }
@@ -3206,8 +3207,7 @@ static inline void snd_trident_free_gameport(trident_t *chip) { }
3206 */ 3207 */
3207static inline void do_delay(trident_t *chip) 3208static inline void do_delay(trident_t *chip)
3208{ 3209{
3209 set_current_state(TASK_UNINTERRUPTIBLE); 3210 schedule_timeout_uninterruptible(1);
3210 schedule_timeout(1);
3211} 3211}
3212 3212
3213/* 3213/*
@@ -3243,7 +3243,7 @@ static int snd_trident_sis_reset(trident_t *trident)
3243 goto __si7018_ok; 3243 goto __si7018_ok;
3244 do_delay(trident); 3244 do_delay(trident);
3245 } while (time_after_eq(end_time, jiffies)); 3245 } while (time_after_eq(end_time, jiffies));
3246 snd_printk("AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL))); 3246 snd_printk(KERN_ERR "AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)));
3247 if (r-- > 0) { 3247 if (r-- > 0) {
3248 end_time = jiffies + HZ; 3248 end_time = jiffies + HZ;
3249 do { 3249 do {
@@ -3541,7 +3541,7 @@ int __devinit snd_trident_create(snd_card_t * card,
3541 /* check, if we can restrict PCI DMA transfers to 30 bits */ 3541 /* check, if we can restrict PCI DMA transfers to 30 bits */
3542 if (pci_set_dma_mask(pci, 0x3fffffff) < 0 || 3542 if (pci_set_dma_mask(pci, 0x3fffffff) < 0 ||
3543 pci_set_consistent_dma_mask(pci, 0x3fffffff) < 0) { 3543 pci_set_consistent_dma_mask(pci, 0x3fffffff) < 0) {
3544 snd_printk("architecture does not support 30bit PCI busmaster DMA\n"); 3544 snd_printk(KERN_ERR "architecture does not support 30bit PCI busmaster DMA\n");
3545 pci_disable_device(pci); 3545 pci_disable_device(pci);
3546 return -ENXIO; 3546 return -ENXIO;
3547 } 3547 }
@@ -3578,7 +3578,7 @@ int __devinit snd_trident_create(snd_card_t * card,
3578 trident->port = pci_resource_start(pci, 0); 3578 trident->port = pci_resource_start(pci, 0);
3579 3579
3580 if (request_irq(pci->irq, snd_trident_interrupt, SA_INTERRUPT|SA_SHIRQ, "Trident Audio", (void *) trident)) { 3580 if (request_irq(pci->irq, snd_trident_interrupt, SA_INTERRUPT|SA_SHIRQ, "Trident Audio", (void *) trident)) {
3581 snd_printk("unable to grab IRQ %d\n", pci->irq); 3581 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
3582 snd_trident_free(trident); 3582 snd_trident_free(trident);
3583 return -EBUSY; 3583 return -EBUSY;
3584 } 3584 }
diff --git a/sound/pci/trident/trident_memory.c b/sound/pci/trident/trident_memory.c
index 333d3790692a..f3e6c546af74 100644
--- a/sound/pci/trident/trident_memory.c
+++ b/sound/pci/trident/trident_memory.c
@@ -170,11 +170,11 @@ __found_pages:
170static int is_valid_page(unsigned long ptr) 170static int is_valid_page(unsigned long ptr)
171{ 171{
172 if (ptr & ~0x3fffffffUL) { 172 if (ptr & ~0x3fffffffUL) {
173 snd_printk("max memory size is 1GB!!\n"); 173 snd_printk(KERN_ERR "max memory size is 1GB!!\n");
174 return 0; 174 return 0;
175 } 175 }
176 if (ptr & (SNDRV_TRIDENT_PAGE_SIZE-1)) { 176 if (ptr & (SNDRV_TRIDENT_PAGE_SIZE-1)) {
177 snd_printk("page is not aligned\n"); 177 snd_printk(KERN_ERR "page is not aligned\n");
178 return 0; 178 return 0;
179 } 179 }
180 return 1; 180 return 1;
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 3c0205b91e10..523eace250f7 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -41,6 +41,9 @@
41 * device for applications. 41 * device for applications.
42 * - clean up the code, separate low-level initialization 42 * - clean up the code, separate low-level initialization
43 * routines for each chipset. 43 * routines for each chipset.
44 *
45 * Sep. 26, 2005 Karsten Wiese <annabellesgarden@yahoo.de>
46 * - Optimize position calculation for the 823x chips.
44 */ 47 */
45 48
46#include <sound/driver.h> 49#include <sound/driver.h>
@@ -73,36 +76,37 @@ MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C,pci},{VIA,VT8233A/C,8235}}");
73#define SUPPORT_JOYSTICK 1 76#define SUPPORT_JOYSTICK 1
74#endif 77#endif
75 78
76static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 79static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
77static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 80static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
78static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 81static long mpu_port;
79static long mpu_port[SNDRV_CARDS];
80#ifdef SUPPORT_JOYSTICK 82#ifdef SUPPORT_JOYSTICK
81static int joystick[SNDRV_CARDS]; 83static int joystick;
82#endif 84#endif
83static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 48000}; 85static int ac97_clock = 48000;
84static char *ac97_quirk[SNDRV_CARDS]; 86static char *ac97_quirk;
85static int dxs_support[SNDRV_CARDS]; 87static int dxs_support;
86 88
87module_param_array(index, int, NULL, 0444); 89module_param(index, int, 0444);
88MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge."); 90MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge.");
89module_param_array(id, charp, NULL, 0444); 91module_param(id, charp, 0444);
90MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge."); 92MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge.");
91module_param_array(enable, bool, NULL, 0444); 93module_param(mpu_port, long, 0444);
92MODULE_PARM_DESC(enable, "Enable audio part of VIA 82xx bridge.");
93module_param_array(mpu_port, long, NULL, 0444);
94MODULE_PARM_DESC(mpu_port, "MPU-401 port. (VT82C686x only)"); 94MODULE_PARM_DESC(mpu_port, "MPU-401 port. (VT82C686x only)");
95#ifdef SUPPORT_JOYSTICK 95#ifdef SUPPORT_JOYSTICK
96module_param_array(joystick, bool, NULL, 0444); 96module_param(joystick, bool, 0444);
97MODULE_PARM_DESC(joystick, "Enable joystick. (VT82C686x only)"); 97MODULE_PARM_DESC(joystick, "Enable joystick. (VT82C686x only)");
98#endif 98#endif
99module_param_array(ac97_clock, int, NULL, 0444); 99module_param(ac97_clock, int, 0444);
100MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz)."); 100MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
101module_param_array(ac97_quirk, charp, NULL, 0444); 101module_param(ac97_quirk, charp, 0444);
102MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); 102MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
103module_param_array(dxs_support, int, NULL, 0444); 103module_param(dxs_support, int, 0444);
104MODULE_PARM_DESC(dxs_support, "Support for DXS channels (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 = no VRA, 5 = enable any sample rate)"); 104MODULE_PARM_DESC(dxs_support, "Support for DXS channels (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 = no VRA, 5 = enable any sample rate)");
105 105
106/* just for backward compatibility */
107static int enable;
108module_param(enable, bool, 0444);
109
106 110
107/* revision numbers for via686 */ 111/* revision numbers for via686 */
108#define VIA_REV_686_A 0x10 112#define VIA_REV_686_A 0x10
@@ -130,6 +134,7 @@ MODULE_PARM_DESC(dxs_support, "Support for DXS channels (0 = auto, 1 = enable, 2
130/* common offsets */ 134/* common offsets */
131#define VIA_REG_OFFSET_STATUS 0x00 /* byte - channel status */ 135#define VIA_REG_OFFSET_STATUS 0x00 /* byte - channel status */
132#define VIA_REG_STAT_ACTIVE 0x80 /* RO */ 136#define VIA_REG_STAT_ACTIVE 0x80 /* RO */
137#define VIA8233_SHADOW_STAT_ACTIVE 0x08 /* RO */
133#define VIA_REG_STAT_PAUSED 0x40 /* RO */ 138#define VIA_REG_STAT_PAUSED 0x40 /* RO */
134#define VIA_REG_STAT_TRIGGER_QUEUED 0x08 /* RO */ 139#define VIA_REG_STAT_TRIGGER_QUEUED 0x08 /* RO */
135#define VIA_REG_STAT_STOPPED 0x04 /* RWC */ 140#define VIA_REG_STAT_STOPPED 0x04 /* RWC */
@@ -328,6 +333,9 @@ struct via_dev {
328 unsigned int fragsize; 333 unsigned int fragsize;
329 unsigned int bufsize; 334 unsigned int bufsize;
330 unsigned int bufsize2; 335 unsigned int bufsize2;
336 int hwptr_done; /* processed frame position in the buffer */
337 int in_interrupt;
338 int shadow_shift;
331}; 339};
332 340
333 341
@@ -360,7 +368,8 @@ struct _snd_via82xx {
360 unsigned int mpu_port_saved; 368 unsigned int mpu_port_saved;
361#endif 369#endif
362 370
363 unsigned char playback_volume[2]; /* for VIA8233/C/8235; default = 0 */ 371 unsigned char playback_volume[4][2]; /* for VIA8233/C/8235; default = 0 */
372 unsigned char playback_volume_c[2]; /* for VIA8233/C/8235; default = 0 */
364 373
365 unsigned int intr_mask; /* SGD_SHADOW mask to check interrupts */ 374 unsigned int intr_mask; /* SGD_SHADOW mask to check interrupts */
366 375
@@ -393,8 +402,10 @@ struct _snd_via82xx {
393}; 402};
394 403
395static struct pci_device_id snd_via82xx_ids[] = { 404static struct pci_device_id snd_via82xx_ids[] = {
396 { 0x1106, 0x3058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, }, /* 686A */ 405 /* 0x1106, 0x3058 */
397 { 0x1106, 0x3059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, }, /* VT8233 */ 406 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, }, /* 686A */
407 /* 0x1106, 0x3059 */
408 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, }, /* VT8233 */
398 { 0, } 409 { 0, }
399}; 410};
400 411
@@ -548,7 +559,7 @@ static void snd_via82xx_codec_write(ac97_t *ac97,
548{ 559{
549 via82xx_t *chip = ac97->private_data; 560 via82xx_t *chip = ac97->private_data;
550 unsigned int xval; 561 unsigned int xval;
551 562
552 xval = !ac97->num ? VIA_REG_AC97_CODEC_ID_PRIMARY : VIA_REG_AC97_CODEC_ID_SECONDARY; 563 xval = !ac97->num ? VIA_REG_AC97_CODEC_ID_PRIMARY : VIA_REG_AC97_CODEC_ID_SECONDARY;
553 xval <<= VIA_REG_AC97_CODEC_ID_SHIFT; 564 xval <<= VIA_REG_AC97_CODEC_ID_SHIFT;
554 xval |= reg << VIA_REG_AC97_CMD_SHIFT; 565 xval |= reg << VIA_REG_AC97_CMD_SHIFT;
@@ -596,14 +607,15 @@ static void snd_via82xx_channel_reset(via82xx_t *chip, viadev_t *viadev)
596 outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */ 607 outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */
597 // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); 608 // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR));
598 viadev->lastpos = 0; 609 viadev->lastpos = 0;
610 viadev->hwptr_done = 0;
599} 611}
600 612
601 613
602/* 614/*
603 * Interrupt handler 615 * Interrupt handler
616 * Used for 686 and 8233A
604 */ 617 */
605 618static irqreturn_t snd_via686_interrupt(int irq, void *dev_id, struct pt_regs *regs)
606static irqreturn_t snd_via82xx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
607{ 619{
608 via82xx_t *chip = dev_id; 620 via82xx_t *chip = dev_id;
609 unsigned int status; 621 unsigned int status;
@@ -622,13 +634,23 @@ static irqreturn_t snd_via82xx_interrupt(int irq, void *dev_id, struct pt_regs *
622 for (i = 0; i < chip->num_devs; i++) { 634 for (i = 0; i < chip->num_devs; i++) {
623 viadev_t *viadev = &chip->devs[i]; 635 viadev_t *viadev = &chip->devs[i];
624 unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS)); 636 unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
625 c_status &= (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED); 637 if (! (c_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED)))
626 if (! c_status)
627 continue; 638 continue;
628 if (viadev->substream && viadev->running) { 639 if (viadev->substream && viadev->running) {
640 /*
641 * Update hwptr_done based on 'period elapsed'
642 * interrupts. We'll use it, when the chip returns 0
643 * for OFFSET_CURR_COUNT.
644 */
645 if (c_status & VIA_REG_STAT_EOL)
646 viadev->hwptr_done = 0;
647 else
648 viadev->hwptr_done += viadev->fragsize;
649 viadev->in_interrupt = c_status;
629 spin_unlock(&chip->reg_lock); 650 spin_unlock(&chip->reg_lock);
630 snd_pcm_period_elapsed(viadev->substream); 651 snd_pcm_period_elapsed(viadev->substream);
631 spin_lock(&chip->reg_lock); 652 spin_lock(&chip->reg_lock);
653 viadev->in_interrupt = 0;
632 } 654 }
633 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */ 655 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
634 } 656 }
@@ -637,6 +659,60 @@ static irqreturn_t snd_via82xx_interrupt(int irq, void *dev_id, struct pt_regs *
637} 659}
638 660
639/* 661/*
662 * Interrupt handler
663 */
664static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id, struct pt_regs *regs)
665{
666 via82xx_t *chip = dev_id;
667 unsigned int status;
668 unsigned int i;
669 int irqreturn = 0;
670
671 /* check status for each stream */
672 spin_lock(&chip->reg_lock);
673 status = inl(VIAREG(chip, SGD_SHADOW));
674
675 for (i = 0; i < chip->num_devs; i++) {
676 viadev_t *viadev = &chip->devs[i];
677 snd_pcm_substream_t *substream;
678 unsigned char c_status, shadow_status;
679
680 shadow_status = (status >> viadev->shadow_shift) &
681 (VIA8233_SHADOW_STAT_ACTIVE|VIA_REG_STAT_EOL|
682 VIA_REG_STAT_FLAG);
683 c_status = shadow_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG);
684 if (!c_status)
685 continue;
686
687 substream = viadev->substream;
688 if (substream && viadev->running) {
689 /*
690 * Update hwptr_done based on 'period elapsed'
691 * interrupts. We'll use it, when the chip returns 0
692 * for OFFSET_CURR_COUNT.
693 */
694 if (c_status & VIA_REG_STAT_EOL)
695 viadev->hwptr_done = 0;
696 else
697 viadev->hwptr_done += viadev->fragsize;
698 viadev->in_interrupt = c_status;
699 if (shadow_status & VIA8233_SHADOW_STAT_ACTIVE)
700 viadev->in_interrupt |= VIA_REG_STAT_ACTIVE;
701 spin_unlock(&chip->reg_lock);
702
703 snd_pcm_period_elapsed(substream);
704
705 spin_lock(&chip->reg_lock);
706 viadev->in_interrupt = 0;
707 }
708 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
709 irqreturn = 1;
710 }
711 spin_unlock(&chip->reg_lock);
712 return IRQ_RETVAL(irqreturn);
713}
714
715/*
640 * PCM callbacks 716 * PCM callbacks
641 */ 717 */
642 718
@@ -699,6 +775,8 @@ static inline unsigned int calc_linear_pos(viadev_t *viadev, unsigned int idx, u
699 size = viadev->idx_table[idx].size; 775 size = viadev->idx_table[idx].size;
700 base = viadev->idx_table[idx].offset; 776 base = viadev->idx_table[idx].offset;
701 res = base + size - count; 777 res = base + size - count;
778 if (res >= viadev->bufsize)
779 res -= viadev->bufsize;
702 780
703 /* check the validity of the calculated position */ 781 /* check the validity of the calculated position */
704 if (size < count) { 782 if (size < count) {
@@ -728,9 +806,6 @@ static inline unsigned int calc_linear_pos(viadev_t *viadev, unsigned int idx, u
728 } 806 }
729 } 807 }
730 } 808 }
731 viadev->lastpos = res; /* remember the last position */
732 if (res >= viadev->bufsize)
733 res -= viadev->bufsize;
734 return res; 809 return res;
735} 810}
736 811
@@ -758,6 +833,7 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(snd_pcm_substream_t *substream)
758 else /* CURR_PTR holds the address + 8 */ 833 else /* CURR_PTR holds the address + 8 */
759 idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries; 834 idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries;
760 res = calc_linear_pos(viadev, idx, count); 835 res = calc_linear_pos(viadev, idx, count);
836 viadev->lastpos = res; /* remember the last position */
761 spin_unlock(&chip->reg_lock); 837 spin_unlock(&chip->reg_lock);
762 838
763 return bytes_to_frames(substream->runtime, res); 839 return bytes_to_frames(substream->runtime, res);
@@ -771,30 +847,44 @@ static snd_pcm_uframes_t snd_via8233_pcm_pointer(snd_pcm_substream_t *substream)
771 via82xx_t *chip = snd_pcm_substream_chip(substream); 847 via82xx_t *chip = snd_pcm_substream_chip(substream);
772 viadev_t *viadev = (viadev_t *)substream->runtime->private_data; 848 viadev_t *viadev = (viadev_t *)substream->runtime->private_data;
773 unsigned int idx, count, res; 849 unsigned int idx, count, res;
774 int timeout = 5000; 850 int status;
775 851
776 snd_assert(viadev->tbl_entries, return 0); 852 snd_assert(viadev->tbl_entries, return 0);
777 if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE)) 853
778 return 0;
779 spin_lock(&chip->reg_lock); 854 spin_lock(&chip->reg_lock);
780 do { 855 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT));
781 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)); 856 status = viadev->in_interrupt;
782 /* some mobos read 0 count */ 857 if (!status)
783 if ((count & 0xffffff) || ! viadev->running) 858 status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
784 break; 859
785 } while (--timeout); 860 if (!(status & VIA_REG_STAT_ACTIVE)) {
786 if (! timeout) 861 res = 0;
787 snd_printd(KERN_ERR "zero position is read\n"); 862 goto unlock;
788 idx = count >> 24; 863 }
789 if (idx >= viadev->tbl_entries) { 864 if (count & 0xffffff) {
865 idx = count >> 24;
866 if (idx >= viadev->tbl_entries) {
790#ifdef POINTER_DEBUG 867#ifdef POINTER_DEBUG
791 printk("fail: invalid idx = %i/%i\n", idx, viadev->tbl_entries); 868 printk(KERN_DEBUG "fail: invalid idx = %i/%i\n", idx, viadev->tbl_entries);
792#endif 869#endif
793 res = viadev->lastpos; 870 res = viadev->lastpos;
871 } else {
872 count &= 0xffffff;
873 res = calc_linear_pos(viadev, idx, count);
874 }
794 } else { 875 } else {
795 count &= 0xffffff; 876 res = viadev->hwptr_done;
796 res = calc_linear_pos(viadev, idx, count); 877 if (!viadev->in_interrupt) {
797 } 878 if (status & VIA_REG_STAT_EOL) {
879 res = 0;
880 } else
881 if (status & VIA_REG_STAT_FLAG) {
882 res += viadev->fragsize;
883 }
884 }
885 }
886unlock:
887 viadev->lastpos = res;
798 spin_unlock(&chip->reg_lock); 888 spin_unlock(&chip->reg_lock);
799 889
800 return bytes_to_frames(substream->runtime, res); 890 return bytes_to_frames(substream->runtime, res);
@@ -936,8 +1026,8 @@ static int snd_via8233_playback_prepare(snd_pcm_substream_t *substream)
936 snd_assert((rbits & ~0xfffff) == 0, return -EINVAL); 1026 snd_assert((rbits & ~0xfffff) == 0, return -EINVAL);
937 snd_via82xx_channel_reset(chip, viadev); 1027 snd_via82xx_channel_reset(chip, viadev);
938 snd_via82xx_set_table_ptr(chip, viadev); 1028 snd_via82xx_set_table_ptr(chip, viadev);
939 outb(chip->playback_volume[0], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L)); 1029 outb(chip->playback_volume[viadev->reg_offset / 0x10][0], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L));
940 outb(chip->playback_volume[1], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R)); 1030 outb(chip->playback_volume[viadev->reg_offset / 0x10][1], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R));
941 outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | /* format */ 1031 outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | /* format */
942 (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | /* stereo */ 1032 (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | /* stereo */
943 rbits | /* rate */ 1033 rbits | /* rate */
@@ -1239,9 +1329,10 @@ static snd_pcm_ops_t snd_via8233_capture_ops = {
1239}; 1329};
1240 1330
1241 1331
1242static void init_viadev(via82xx_t *chip, int idx, unsigned int reg_offset, int direction) 1332static void init_viadev(via82xx_t *chip, int idx, unsigned int reg_offset, int shadow_pos, int direction)
1243{ 1333{
1244 chip->devs[idx].reg_offset = reg_offset; 1334 chip->devs[idx].reg_offset = reg_offset;
1335 chip->devs[idx].shadow_shift = shadow_pos * 4;
1245 chip->devs[idx].direction = direction; 1336 chip->devs[idx].direction = direction;
1246 chip->devs[idx].port = chip->port + reg_offset; 1337 chip->devs[idx].port = chip->port + reg_offset;
1247} 1338}
@@ -1271,9 +1362,9 @@ static int __devinit snd_via8233_pcm_new(via82xx_t *chip)
1271 chip->pcms[0] = pcm; 1362 chip->pcms[0] = pcm;
1272 /* set up playbacks */ 1363 /* set up playbacks */
1273 for (i = 0; i < 4; i++) 1364 for (i = 0; i < 4; i++)
1274 init_viadev(chip, i, 0x10 * i, 0); 1365 init_viadev(chip, i, 0x10 * i, i, 0);
1275 /* capture */ 1366 /* capture */
1276 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 1); 1367 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
1277 1368
1278 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1369 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1279 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1370 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0)
@@ -1289,9 +1380,9 @@ static int __devinit snd_via8233_pcm_new(via82xx_t *chip)
1289 strcpy(pcm->name, chip->card->shortname); 1380 strcpy(pcm->name, chip->card->shortname);
1290 chip->pcms[1] = pcm; 1381 chip->pcms[1] = pcm;
1291 /* set up playback */ 1382 /* set up playback */
1292 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 0); 1383 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
1293 /* set up capture */ 1384 /* set up capture */
1294 init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 1); 1385 init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1);
1295 1386
1296 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1387 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1297 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1388 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0)
@@ -1324,9 +1415,9 @@ static int __devinit snd_via8233a_pcm_new(via82xx_t *chip)
1324 strcpy(pcm->name, chip->card->shortname); 1415 strcpy(pcm->name, chip->card->shortname);
1325 chip->pcms[0] = pcm; 1416 chip->pcms[0] = pcm;
1326 /* set up playback */ 1417 /* set up playback */
1327 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 0); 1418 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
1328 /* capture */ 1419 /* capture */
1329 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 1); 1420 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
1330 1421
1331 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1422 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1332 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1423 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0)
@@ -1345,7 +1436,7 @@ static int __devinit snd_via8233a_pcm_new(via82xx_t *chip)
1345 strcpy(pcm->name, chip->card->shortname); 1436 strcpy(pcm->name, chip->card->shortname);
1346 chip->pcms[1] = pcm; 1437 chip->pcms[1] = pcm;
1347 /* set up playback */ 1438 /* set up playback */
1348 init_viadev(chip, chip->playback_devno, 0x30, 0); 1439 init_viadev(chip, chip->playback_devno, 0x30, 3, 0);
1349 1440
1350 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1441 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1351 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1442 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0)
@@ -1375,8 +1466,8 @@ static int __devinit snd_via686_pcm_new(via82xx_t *chip)
1375 pcm->private_data = chip; 1466 pcm->private_data = chip;
1376 strcpy(pcm->name, chip->card->shortname); 1467 strcpy(pcm->name, chip->card->shortname);
1377 chip->pcms[0] = pcm; 1468 chip->pcms[0] = pcm;
1378 init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0); 1469 init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0);
1379 init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 1); 1470 init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1);
1380 1471
1381 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1472 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1382 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1473 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0)
@@ -1497,14 +1588,46 @@ static int snd_via8233_dxs_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_in
1497static int snd_via8233_dxs_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1588static int snd_via8233_dxs_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1498{ 1589{
1499 via82xx_t *chip = snd_kcontrol_chip(kcontrol); 1590 via82xx_t *chip = snd_kcontrol_chip(kcontrol);
1500 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[0]; 1591 unsigned int idx = snd_ctl_get_ioff(kcontrol, &ucontrol->id);
1501 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[1]; 1592
1593 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][0];
1594 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][1];
1595 return 0;
1596}
1597
1598static int snd_via8233_pcmdxs_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1599{
1600 via82xx_t *chip = snd_kcontrol_chip(kcontrol);
1601 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[0];
1602 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[1];
1502 return 0; 1603 return 0;
1503} 1604}
1504 1605
1505static int snd_via8233_dxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1606static int snd_via8233_dxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1506{ 1607{
1507 via82xx_t *chip = snd_kcontrol_chip(kcontrol); 1608 via82xx_t *chip = snd_kcontrol_chip(kcontrol);
1609 unsigned int idx = snd_ctl_get_ioff(kcontrol, &ucontrol->id);
1610 unsigned long port = chip->port + 0x10 * idx;
1611 unsigned char val;
1612 int i, change = 0;
1613
1614 for (i = 0; i < 2; i++) {
1615 val = ucontrol->value.integer.value[i];
1616 if (val > VIA_DXS_MAX_VOLUME)
1617 val = VIA_DXS_MAX_VOLUME;
1618 val = VIA_DXS_MAX_VOLUME - val;
1619 change |= val != chip->playback_volume[idx][i];
1620 if (change) {
1621 chip->playback_volume[idx][i] = val;
1622 outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
1623 }
1624 }
1625 return change;
1626}
1627
1628static int snd_via8233_pcmdxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1629{
1630 via82xx_t *chip = snd_kcontrol_chip(kcontrol);
1508 unsigned int idx; 1631 unsigned int idx;
1509 unsigned char val; 1632 unsigned char val;
1510 int i, change = 0; 1633 int i, change = 0;
@@ -1514,11 +1637,12 @@ static int snd_via8233_dxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_val
1514 if (val > VIA_DXS_MAX_VOLUME) 1637 if (val > VIA_DXS_MAX_VOLUME)
1515 val = VIA_DXS_MAX_VOLUME; 1638 val = VIA_DXS_MAX_VOLUME;
1516 val = VIA_DXS_MAX_VOLUME - val; 1639 val = VIA_DXS_MAX_VOLUME - val;
1517 if (val != chip->playback_volume[i]) { 1640 if (val != chip->playback_volume_c[i]) {
1518 change = 1; 1641 change = 1;
1519 chip->playback_volume[i] = val; 1642 chip->playback_volume_c[i] = val;
1520 for (idx = 0; idx < 4; idx++) { 1643 for (idx = 0; idx < 4; idx++) {
1521 unsigned long port = chip->port + 0x10 * idx; 1644 unsigned long port = chip->port + 0x10 * idx;
1645 chip->playback_volume[idx][i] = val;
1522 outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); 1646 outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
1523 } 1647 }
1524 } 1648 }
@@ -1526,10 +1650,19 @@ static int snd_via8233_dxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_val
1526 return change; 1650 return change;
1527} 1651}
1528 1652
1529static snd_kcontrol_new_t snd_via8233_dxs_volume_control __devinitdata = { 1653static snd_kcontrol_new_t snd_via8233_pcmdxs_volume_control __devinitdata = {
1530 .name = "PCM Playback Volume", 1654 .name = "PCM Playback Volume",
1531 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1655 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1532 .info = snd_via8233_dxs_volume_info, 1656 .info = snd_via8233_dxs_volume_info,
1657 .get = snd_via8233_pcmdxs_volume_get,
1658 .put = snd_via8233_pcmdxs_volume_put,
1659};
1660
1661static snd_kcontrol_new_t snd_via8233_dxs_volume_control __devinitdata = {
1662 .name = "VIA DXS Playback Volume",
1663 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1664 .count = 4,
1665 .info = snd_via8233_dxs_volume_info,
1533 .get = snd_via8233_dxs_volume_get, 1666 .get = snd_via8233_dxs_volume_get,
1534 .put = snd_via8233_dxs_volume_put, 1667 .put = snd_via8233_dxs_volume_put,
1535}; 1668};
@@ -1616,12 +1749,12 @@ static int __devinit snd_via82xx_mixer_new(via82xx_t *chip, const char *quirk_ov
1616 return err; 1749 return err;
1617 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus; 1750 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus;
1618 chip->ac97_bus->clock = chip->ac97_clock; 1751 chip->ac97_bus->clock = chip->ac97_clock;
1619 chip->ac97_bus->shared_type = AC97_SHARED_TYPE_VIA;
1620 1752
1621 memset(&ac97, 0, sizeof(ac97)); 1753 memset(&ac97, 0, sizeof(ac97));
1622 ac97.private_data = chip; 1754 ac97.private_data = chip;
1623 ac97.private_free = snd_via82xx_mixer_free_ac97; 1755 ac97.private_free = snd_via82xx_mixer_free_ac97;
1624 ac97.pci = chip->pci; 1756 ac97.pci = chip->pci;
1757 ac97.scaps = AC97_SCAP_SKIP_MODEM;
1625 if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0) 1758 if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0)
1626 return err; 1759 return err;
1627 1760
@@ -1637,12 +1770,12 @@ static int __devinit snd_via82xx_mixer_new(via82xx_t *chip, const char *quirk_ov
1637 1770
1638#ifdef SUPPORT_JOYSTICK 1771#ifdef SUPPORT_JOYSTICK
1639#define JOYSTICK_ADDR 0x200 1772#define JOYSTICK_ADDR 0x200
1640static int __devinit snd_via686_create_gameport(via82xx_t *chip, int dev, unsigned char *legacy) 1773static int __devinit snd_via686_create_gameport(via82xx_t *chip, unsigned char *legacy)
1641{ 1774{
1642 struct gameport *gp; 1775 struct gameport *gp;
1643 struct resource *r; 1776 struct resource *r;
1644 1777
1645 if (!joystick[dev]) 1778 if (!joystick)
1646 return -ENODEV; 1779 return -ENODEV;
1647 1780
1648 r = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport"); 1781 r = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport");
@@ -1654,8 +1787,7 @@ static int __devinit snd_via686_create_gameport(via82xx_t *chip, int dev, unsign
1654 chip->gameport = gp = gameport_allocate_port(); 1787 chip->gameport = gp = gameport_allocate_port();
1655 if (!gp) { 1788 if (!gp) {
1656 printk(KERN_ERR "via82xx: cannot allocate memory for gameport\n"); 1789 printk(KERN_ERR "via82xx: cannot allocate memory for gameport\n");
1657 release_resource(r); 1790 release_and_free_resource(r);
1658 kfree_nocheck(r);
1659 return -ENOMEM; 1791 return -ENOMEM;
1660 } 1792 }
1661 1793
@@ -1681,12 +1813,11 @@ static void snd_via686_free_gameport(via82xx_t *chip)
1681 1813
1682 gameport_unregister_port(chip->gameport); 1814 gameport_unregister_port(chip->gameport);
1683 chip->gameport = NULL; 1815 chip->gameport = NULL;
1684 release_resource(r); 1816 release_and_free_resource(r);
1685 kfree_nocheck(r);
1686 } 1817 }
1687} 1818}
1688#else 1819#else
1689static inline int snd_via686_create_gameport(via82xx_t *chip, int dev, unsigned char *legacy) 1820static inline int snd_via686_create_gameport(via82xx_t *chip, unsigned char *legacy)
1690{ 1821{
1691 return -ENOSYS; 1822 return -ENOSYS;
1692} 1823}
@@ -1698,7 +1829,7 @@ static inline void snd_via686_free_gameport(via82xx_t *chip) { }
1698 * 1829 *
1699 */ 1830 */
1700 1831
1701static int __devinit snd_via8233_init_misc(via82xx_t *chip, int dev) 1832static int __devinit snd_via8233_init_misc(via82xx_t *chip)
1702{ 1833{
1703 int i, err, caps; 1834 int i, err, caps;
1704 unsigned char val; 1835 unsigned char val;
@@ -1724,12 +1855,19 @@ static int __devinit snd_via8233_init_misc(via82xx_t *chip, int dev)
1724 strcpy(sid.name, "PCM Playback Volume"); 1855 strcpy(sid.name, "PCM Playback Volume");
1725 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 1856 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1726 if (! snd_ctl_find_id(chip->card, &sid)) { 1857 if (! snd_ctl_find_id(chip->card, &sid)) {
1858 snd_printd(KERN_INFO "Using DXS as PCM Playback\n");
1859 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_pcmdxs_volume_control, chip));
1860 if (err < 0)
1861 return err;
1862 }
1863 else /* Using DXS when PCM emulation is enabled is really weird */
1864 {
1865 /* Standalone DXS controls */
1727 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs_volume_control, chip)); 1866 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs_volume_control, chip));
1728 if (err < 0) 1867 if (err < 0)
1729 return err; 1868 return err;
1730 } 1869 }
1731 } 1870 }
1732
1733 /* select spdif data slot 10/11 */ 1871 /* select spdif data slot 10/11 */
1734 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val); 1872 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val);
1735 val = (val & ~VIA8233_SPDIF_SLOT_MASK) | VIA8233_SPDIF_SLOT_1011; 1873 val = (val & ~VIA8233_SPDIF_SLOT_MASK) | VIA8233_SPDIF_SLOT_1011;
@@ -1739,7 +1877,7 @@ static int __devinit snd_via8233_init_misc(via82xx_t *chip, int dev)
1739 return 0; 1877 return 0;
1740} 1878}
1741 1879
1742static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev) 1880static int __devinit snd_via686_init_misc(via82xx_t *chip)
1743{ 1881{
1744 unsigned char legacy, legacy_cfg; 1882 unsigned char legacy, legacy_cfg;
1745 int rev_h = 0; 1883 int rev_h = 0;
@@ -1750,32 +1888,33 @@ static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev)
1750 legacy &= ~VIA_FUNC_ENABLE_GAME; /* disable joystick */ 1888 legacy &= ~VIA_FUNC_ENABLE_GAME; /* disable joystick */
1751 if (chip->revision >= VIA_REV_686_H) { 1889 if (chip->revision >= VIA_REV_686_H) {
1752 rev_h = 1; 1890 rev_h = 1;
1753 if (mpu_port[dev] >= 0x200) { /* force MIDI */ 1891 if (mpu_port >= 0x200) { /* force MIDI */
1754 mpu_port[dev] &= 0xfffc; 1892 mpu_port &= 0xfffc;
1755 pci_write_config_dword(chip->pci, 0x18, mpu_port[dev] | 0x01); 1893 pci_write_config_dword(chip->pci, 0x18, mpu_port | 0x01);
1756#ifdef CONFIG_PM 1894#ifdef CONFIG_PM
1757 chip->mpu_port_saved = mpu_port[dev]; 1895 chip->mpu_port_saved = mpu_port;
1758#endif 1896#endif
1759 } else { 1897 } else {
1760 mpu_port[dev] = pci_resource_start(chip->pci, 2); 1898 mpu_port = pci_resource_start(chip->pci, 2);
1761 } 1899 }
1762 } else { 1900 } else {
1763 switch (mpu_port[dev]) { /* force MIDI */ 1901 switch (mpu_port) { /* force MIDI */
1764 case 0x300: 1902 case 0x300:
1765 case 0x310: 1903 case 0x310:
1766 case 0x320: 1904 case 0x320:
1767 case 0x330: 1905 case 0x330:
1768 legacy_cfg &= ~(3 << 2); 1906 legacy_cfg &= ~(3 << 2);
1769 legacy_cfg |= (mpu_port[dev] & 0x0030) >> 2; 1907 legacy_cfg |= (mpu_port & 0x0030) >> 2;
1770 break; 1908 break;
1771 default: /* no, use BIOS settings */ 1909 default: /* no, use BIOS settings */
1772 if (legacy & VIA_FUNC_ENABLE_MIDI) 1910 if (legacy & VIA_FUNC_ENABLE_MIDI)
1773 mpu_port[dev] = 0x300 + ((legacy_cfg & 0x000c) << 2); 1911 mpu_port = 0x300 + ((legacy_cfg & 0x000c) << 2);
1774 break; 1912 break;
1775 } 1913 }
1776 } 1914 }
1777 if (mpu_port[dev] >= 0x200 && 1915 if (mpu_port >= 0x200 &&
1778 (chip->mpu_res = request_region(mpu_port[dev], 2, "VIA82xx MPU401")) != NULL) { 1916 (chip->mpu_res = request_region(mpu_port, 2, "VIA82xx MPU401"))
1917 != NULL) {
1779 if (rev_h) 1918 if (rev_h)
1780 legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */ 1919 legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */
1781 legacy |= VIA_FUNC_ENABLE_MIDI; 1920 legacy |= VIA_FUNC_ENABLE_MIDI;
@@ -1783,16 +1922,17 @@ static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev)
1783 if (rev_h) 1922 if (rev_h)
1784 legacy &= ~VIA_FUNC_MIDI_PNP; /* disable PCI I/O 2 */ 1923 legacy &= ~VIA_FUNC_MIDI_PNP; /* disable PCI I/O 2 */
1785 legacy &= ~VIA_FUNC_ENABLE_MIDI; 1924 legacy &= ~VIA_FUNC_ENABLE_MIDI;
1786 mpu_port[dev] = 0; 1925 mpu_port = 0;
1787 } 1926 }
1788 1927
1789 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); 1928 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
1790 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg); 1929 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg);
1791 if (chip->mpu_res) { 1930 if (chip->mpu_res) {
1792 if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A, 1931 if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A,
1793 mpu_port[dev], 1, 1932 mpu_port, 1,
1794 chip->irq, 0, &chip->rmidi) < 0) { 1933 chip->irq, 0, &chip->rmidi) < 0) {
1795 printk(KERN_WARNING "unable to initialize MPU-401 at 0x%lx, skipping\n", mpu_port[dev]); 1934 printk(KERN_WARNING "unable to initialize MPU-401"
1935 " at 0x%lx, skipping\n", mpu_port);
1796 legacy &= ~VIA_FUNC_ENABLE_MIDI; 1936 legacy &= ~VIA_FUNC_ENABLE_MIDI;
1797 } else { 1937 } else {
1798 legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */ 1938 legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */
@@ -1800,7 +1940,7 @@ static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev)
1800 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); 1940 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
1801 } 1941 }
1802 1942
1803 snd_via686_create_gameport(chip, dev, &legacy); 1943 snd_via686_create_gameport(chip, &legacy);
1804 1944
1805#ifdef CONFIG_PM 1945#ifdef CONFIG_PM
1806 chip->legacy_saved = legacy; 1946 chip->legacy_saved = legacy;
@@ -1887,12 +2027,11 @@ static int snd_via82xx_chip_init(via82xx_t *chip)
1887 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); 2027 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);
1888 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */ 2028 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */
1889 break; 2029 break;
1890 set_current_state(TASK_UNINTERRUPTIBLE); 2030 schedule_timeout_uninterruptible(1);
1891 schedule_timeout(1);
1892 } while (time_before(jiffies, end_time)); 2031 } while (time_before(jiffies, end_time));
1893 2032
1894 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 2033 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)
1895 snd_printk("AC'97 codec is not ready [0x%x]\n", val); 2034 snd_printk(KERN_ERR "AC'97 codec is not ready [0x%x]\n", val);
1896 2035
1897#if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */ 2036#if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */
1898 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 2037 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
@@ -1907,8 +2046,7 @@ static int snd_via82xx_chip_init(via82xx_t *chip)
1907 chip->ac97_secondary = 1; 2046 chip->ac97_secondary = 1;
1908 goto __ac97_ok2; 2047 goto __ac97_ok2;
1909 } 2048 }
1910 set_current_state(TASK_INTERRUPTIBLE); 2049 schedule_timeout_interruptible(1);
1911 schedule_timeout(1);
1912 } while (time_before(jiffies, end_time)); 2050 } while (time_before(jiffies, end_time));
1913 /* This is ok, the most of motherboards have only one codec */ 2051 /* This is ok, the most of motherboards have only one codec */
1914 2052
@@ -1940,8 +2078,10 @@ static int snd_via82xx_chip_init(via82xx_t *chip)
1940 int i, idx; 2078 int i, idx;
1941 for (idx = 0; idx < 4; idx++) { 2079 for (idx = 0; idx < 4; idx++) {
1942 unsigned long port = chip->port + 0x10 * idx; 2080 unsigned long port = chip->port + 0x10 * idx;
1943 for (i = 0; i < 2; i++) 2081 for (i = 0; i < 2; i++) {
1944 outb(chip->playback_volume[i], port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); 2082 chip->playback_volume[idx][i]=chip->playback_volume_c[i];
2083 outb(chip->playback_volume_c[i], port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
2084 }
1945 } 2085 }
1946 } 2086 }
1947 2087
@@ -2020,10 +2160,7 @@ static int snd_via82xx_free(via82xx_t *chip)
2020 __end_hw: 2160 __end_hw:
2021 if (chip->irq >= 0) 2161 if (chip->irq >= 0)
2022 free_irq(chip->irq, (void *)chip); 2162 free_irq(chip->irq, (void *)chip);
2023 if (chip->mpu_res) { 2163 release_and_free_resource(chip->mpu_res);
2024 release_resource(chip->mpu_res);
2025 kfree_nocheck(chip->mpu_res);
2026 }
2027 pci_release_regions(chip->pci); 2164 pci_release_regions(chip->pci);
2028 2165
2029 if (chip->chip_type == TYPE_VIA686) { 2166 if (chip->chip_type == TYPE_VIA686) {
@@ -2084,9 +2221,12 @@ static int __devinit snd_via82xx_create(snd_card_t * card,
2084 return err; 2221 return err;
2085 } 2222 }
2086 chip->port = pci_resource_start(pci, 0); 2223 chip->port = pci_resource_start(pci, 0);
2087 if (request_irq(pci->irq, snd_via82xx_interrupt, SA_INTERRUPT|SA_SHIRQ, 2224 if (request_irq(pci->irq,
2225 chip_type == TYPE_VIA8233 ?
2226 snd_via8233_interrupt : snd_via686_interrupt,
2227 SA_INTERRUPT|SA_SHIRQ,
2088 card->driver, (void *)chip)) { 2228 card->driver, (void *)chip)) {
2089 snd_printk("unable to grab IRQ %d\n", pci->irq); 2229 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2090 snd_via82xx_free(chip); 2230 snd_via82xx_free(chip);
2091 return -EBUSY; 2231 return -EBUSY;
2092 } 2232 }
@@ -2178,6 +2318,7 @@ static int __devinit check_dxs_list(struct pci_dev *pci)
2178 { .subvendor = 0x147b, .subdevice = 0x1415, .action = VIA_DXS_NO_VRA }, /* Abit AV8 */ 2318 { .subvendor = 0x147b, .subdevice = 0x1415, .action = VIA_DXS_NO_VRA }, /* Abit AV8 */
2179 { .subvendor = 0x14ff, .subdevice = 0x0403, .action = VIA_DXS_ENABLE }, /* Twinhead mobo */ 2319 { .subvendor = 0x14ff, .subdevice = 0x0403, .action = VIA_DXS_ENABLE }, /* Twinhead mobo */
2180 { .subvendor = 0x14ff, .subdevice = 0x0408, .action = VIA_DXS_SRC }, /* Twinhead laptop */ 2320 { .subvendor = 0x14ff, .subdevice = 0x0408, .action = VIA_DXS_SRC }, /* Twinhead laptop */
2321 { .subvendor = 0x1558, .subdevice = 0x4701, .action = VIA_DXS_SRC }, /* Clevo D470 */
2181 { .subvendor = 0x1584, .subdevice = 0x8120, .action = VIA_DXS_ENABLE }, /* Gericom/Targa/Vobis/Uniwill laptop */ 2322 { .subvendor = 0x1584, .subdevice = 0x8120, .action = VIA_DXS_ENABLE }, /* Gericom/Targa/Vobis/Uniwill laptop */
2182 { .subvendor = 0x1584, .subdevice = 0x8123, .action = VIA_DXS_NO_VRA }, /* Uniwill (Targa Visionary XP-210) */ 2323 { .subvendor = 0x1584, .subdevice = 0x8123, .action = VIA_DXS_NO_VRA }, /* Uniwill (Targa Visionary XP-210) */
2183 { .subvendor = 0x161f, .subdevice = 0x202b, .action = VIA_DXS_NO_VRA }, /* Amira Note book */ 2324 { .subvendor = 0x161f, .subdevice = 0x202b, .action = VIA_DXS_NO_VRA }, /* Amira Note book */
@@ -2221,7 +2362,6 @@ static int __devinit check_dxs_list(struct pci_dev *pci)
2221static int __devinit snd_via82xx_probe(struct pci_dev *pci, 2362static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2222 const struct pci_device_id *pci_id) 2363 const struct pci_device_id *pci_id)
2223{ 2364{
2224 static int dev;
2225 snd_card_t *card; 2365 snd_card_t *card;
2226 via82xx_t *chip; 2366 via82xx_t *chip;
2227 unsigned char revision; 2367 unsigned char revision;
@@ -2229,14 +2369,7 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2229 unsigned int i; 2369 unsigned int i;
2230 int err; 2370 int err;
2231 2371
2232 if (dev >= SNDRV_CARDS) 2372 card = snd_card_new(index, id, THIS_MODULE, 0);
2233 return -ENODEV;
2234 if (!enable[dev]) {
2235 dev++;
2236 return -ENOENT;
2237 }
2238
2239 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2240 if (card == NULL) 2373 if (card == NULL)
2241 return -ENOMEM; 2374 return -ENOMEM;
2242 2375
@@ -2259,12 +2392,12 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2259 } 2392 }
2260 } 2393 }
2261 if (chip_type != TYPE_VIA8233A) { 2394 if (chip_type != TYPE_VIA8233A) {
2262 if (dxs_support[dev] == VIA_DXS_AUTO) 2395 if (dxs_support == VIA_DXS_AUTO)
2263 dxs_support[dev] = check_dxs_list(pci); 2396 dxs_support = check_dxs_list(pci);
2264 /* force to use VIA8233 or 8233A model according to 2397 /* force to use VIA8233 or 8233A model according to
2265 * dxs_support module option 2398 * dxs_support module option
2266 */ 2399 */
2267 if (dxs_support[dev] == VIA_DXS_DISABLE) 2400 if (dxs_support == VIA_DXS_DISABLE)
2268 chip_type = TYPE_VIA8233A; 2401 chip_type = TYPE_VIA8233A;
2269 else 2402 else
2270 chip_type = TYPE_VIA8233; 2403 chip_type = TYPE_VIA8233;
@@ -2282,14 +2415,15 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2282 goto __error; 2415 goto __error;
2283 } 2416 }
2284 2417
2285 if ((err = snd_via82xx_create(card, pci, chip_type, revision, ac97_clock[dev], &chip)) < 0) 2418 if ((err = snd_via82xx_create(card, pci, chip_type, revision,
2419 ac97_clock, &chip)) < 0)
2286 goto __error; 2420 goto __error;
2287 if ((err = snd_via82xx_mixer_new(chip, ac97_quirk[dev])) < 0) 2421 if ((err = snd_via82xx_mixer_new(chip, ac97_quirk)) < 0)
2288 goto __error; 2422 goto __error;
2289 2423
2290 if (chip_type == TYPE_VIA686) { 2424 if (chip_type == TYPE_VIA686) {
2291 if ((err = snd_via686_pcm_new(chip)) < 0 || 2425 if ((err = snd_via686_pcm_new(chip)) < 0 ||
2292 (err = snd_via686_init_misc(chip, dev)) < 0) 2426 (err = snd_via686_init_misc(chip)) < 0)
2293 goto __error; 2427 goto __error;
2294 } else { 2428 } else {
2295 if (chip_type == TYPE_VIA8233A) { 2429 if (chip_type == TYPE_VIA8233A) {
@@ -2299,16 +2433,16 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2299 } else { 2433 } else {
2300 if ((err = snd_via8233_pcm_new(chip)) < 0) 2434 if ((err = snd_via8233_pcm_new(chip)) < 0)
2301 goto __error; 2435 goto __error;
2302 if (dxs_support[dev] == VIA_DXS_48K) 2436 if (dxs_support == VIA_DXS_48K)
2303 chip->dxs_fixed = 1; 2437 chip->dxs_fixed = 1;
2304 else if (dxs_support[dev] == VIA_DXS_NO_VRA) 2438 else if (dxs_support == VIA_DXS_NO_VRA)
2305 chip->no_vra = 1; 2439 chip->no_vra = 1;
2306 else if (dxs_support[dev] == VIA_DXS_SRC) { 2440 else if (dxs_support == VIA_DXS_SRC) {
2307 chip->no_vra = 1; 2441 chip->no_vra = 1;
2308 chip->dxs_src = 1; 2442 chip->dxs_src = 1;
2309 } 2443 }
2310 } 2444 }
2311 if ((err = snd_via8233_init_misc(chip, dev)) < 0) 2445 if ((err = snd_via8233_init_misc(chip)) < 0)
2312 goto __error; 2446 goto __error;
2313 } 2447 }
2314 2448
@@ -2329,7 +2463,6 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2329 return err; 2463 return err;
2330 } 2464 }
2331 pci_set_drvdata(pci, card); 2465 pci_set_drvdata(pci, card);
2332 dev++;
2333 return 0; 2466 return 0;
2334 2467
2335 __error: 2468 __error:
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index 7eac6f6ac737..011f0fb63bf9 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -26,7 +26,7 @@
26/* 26/*
27 * Changes: 27 * Changes:
28 * 28 *
29 * Sep. 2, 2004 Sasha Khapyorsky <sashak@smlink.com> 29 * Sep. 2, 2004 Sasha Khapyorsky <sashak@alsa-project.org>
30 * Modified from original audio driver 'via82xx.c' to support AC97 30 * Modified from original audio driver 'via82xx.c' to support AC97
31 * modems. 31 * modems.
32 */ 32 */
@@ -55,20 +55,21 @@ MODULE_DESCRIPTION("VIA VT82xx modem");
55MODULE_LICENSE("GPL"); 55MODULE_LICENSE("GPL");
56MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C modem,pci}}"); 56MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C modem,pci}}");
57 57
58static int index[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -2}; /* Exclude the first card */ 58static int index = -2; /* Exclude the first card */
59static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 59static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
60static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 60static int ac97_clock = 48000;
61static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 48000};
62 61
63module_param_array(index, int, NULL, 0444); 62module_param(index, int, 0444);
64MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge."); 63MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge.");
65module_param_array(id, charp, NULL, 0444); 64module_param(id, charp, 0444);
66MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge."); 65MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge.");
67module_param_array(enable, bool, NULL, 0444); 66module_param(ac97_clock, int, 0444);
68MODULE_PARM_DESC(enable, "Enable modem part of VIA 82xx bridge.");
69module_param_array(ac97_clock, int, NULL, 0444);
70MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz)."); 67MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
71 68
69/* just for backward compatibility */
70static int enable;
71module_param(enable, bool, 0444);
72
72 73
73/* 74/*
74 * Direct registers 75 * Direct registers
@@ -569,7 +570,7 @@ static inline unsigned int calc_linear_pos(viadev_t *viadev, unsigned int idx, u
569 res = viadev->lastpos; 570 res = viadev->lastpos;
570 } else if (check_invalid_pos(viadev, res)) { 571 } else if (check_invalid_pos(viadev, res)) {
571#ifdef POINTER_DEBUG 572#ifdef POINTER_DEBUG
572 printk("fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n", idx, viadev->tbl_entries, viadev->lastpos, viadev->bufsize2, viadev->idx_table[idx].offset, viadev->idx_table[idx].size, count); 573 printk(KERN_DEBUG "fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n", idx, viadev->tbl_entries, viadev->lastpos, viadev->bufsize2, viadev->idx_table[idx].offset, viadev->idx_table[idx].size, count);
573#endif 574#endif
574 if (count && size < count) { 575 if (count && size < count) {
575 snd_printd(KERN_ERR "invalid via82xx_cur_ptr, using last valid pointer\n"); 576 snd_printd(KERN_ERR "invalid via82xx_cur_ptr, using last valid pointer\n");
@@ -832,6 +833,7 @@ static int __devinit snd_via686_pcm_new(via82xx_t *chip)
832 return err; 833 return err;
833 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via686_playback_ops); 834 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via686_playback_ops);
834 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via686_capture_ops); 835 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via686_capture_ops);
836 pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
835 pcm->private_data = chip; 837 pcm->private_data = chip;
836 strcpy(pcm->name, chip->card->shortname); 838 strcpy(pcm->name, chip->card->shortname);
837 chip->pcms[0] = pcm; 839 chip->pcms[0] = pcm;
@@ -878,7 +880,6 @@ static int __devinit snd_via82xx_mixer_new(via82xx_t *chip)
878 return err; 880 return err;
879 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus; 881 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus;
880 chip->ac97_bus->clock = chip->ac97_clock; 882 chip->ac97_bus->clock = chip->ac97_clock;
881 chip->ac97_bus->shared_type = AC97_SHARED_TYPE_VIA;
882 883
883 memset(&ac97, 0, sizeof(ac97)); 884 memset(&ac97, 0, sizeof(ac97));
884 ac97.private_data = chip; 885 ac97.private_data = chip;
@@ -967,12 +968,11 @@ static int snd_via82xx_chip_init(via82xx_t *chip)
967 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); 968 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);
968 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */ 969 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */
969 break; 970 break;
970 set_current_state(TASK_UNINTERRUPTIBLE); 971 schedule_timeout_uninterruptible(1);
971 schedule_timeout(1);
972 } while (time_before(jiffies, end_time)); 972 } while (time_before(jiffies, end_time));
973 973
974 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 974 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)
975 snd_printk("AC'97 codec is not ready [0x%x]\n", val); 975 snd_printk(KERN_ERR "AC'97 codec is not ready [0x%x]\n", val);
976 976
977 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 977 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
978 VIA_REG_AC97_SECONDARY_VALID | 978 VIA_REG_AC97_SECONDARY_VALID |
@@ -986,8 +986,7 @@ static int snd_via82xx_chip_init(via82xx_t *chip)
986 chip->ac97_secondary = 1; 986 chip->ac97_secondary = 1;
987 goto __ac97_ok2; 987 goto __ac97_ok2;
988 } 988 }
989 set_current_state(TASK_INTERRUPTIBLE); 989 schedule_timeout_interruptible(1);
990 schedule_timeout(1);
991 } while (time_before(jiffies, end_time)); 990 } while (time_before(jiffies, end_time));
992 /* This is ok, the most of motherboards have only one codec */ 991 /* This is ok, the most of motherboards have only one codec */
993 992
@@ -1101,7 +1100,7 @@ static int __devinit snd_via82xx_create(snd_card_t * card,
1101 chip->port = pci_resource_start(pci, 0); 1100 chip->port = pci_resource_start(pci, 0);
1102 if (request_irq(pci->irq, snd_via82xx_interrupt, SA_INTERRUPT|SA_SHIRQ, 1101 if (request_irq(pci->irq, snd_via82xx_interrupt, SA_INTERRUPT|SA_SHIRQ,
1103 card->driver, (void *)chip)) { 1102 card->driver, (void *)chip)) {
1104 snd_printk("unable to grab IRQ %d\n", pci->irq); 1103 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1105 snd_via82xx_free(chip); 1104 snd_via82xx_free(chip);
1106 return -EBUSY; 1105 return -EBUSY;
1107 } 1106 }
@@ -1135,7 +1134,6 @@ static int __devinit snd_via82xx_create(snd_card_t * card,
1135static int __devinit snd_via82xx_probe(struct pci_dev *pci, 1134static int __devinit snd_via82xx_probe(struct pci_dev *pci,
1136 const struct pci_device_id *pci_id) 1135 const struct pci_device_id *pci_id)
1137{ 1136{
1138 static int dev;
1139 snd_card_t *card; 1137 snd_card_t *card;
1140 via82xx_t *chip; 1138 via82xx_t *chip;
1141 unsigned char revision; 1139 unsigned char revision;
@@ -1143,14 +1141,7 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
1143 unsigned int i; 1141 unsigned int i;
1144 int err; 1142 int err;
1145 1143
1146 if (dev >= SNDRV_CARDS) 1144 card = snd_card_new(index, id, THIS_MODULE, 0);
1147 return -ENODEV;
1148 if (!enable[dev]) {
1149 dev++;
1150 return -ENOENT;
1151 }
1152
1153 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1154 if (card == NULL) 1145 if (card == NULL)
1155 return -ENOMEM; 1146 return -ENOMEM;
1156 1147
@@ -1167,7 +1158,8 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
1167 goto __error; 1158 goto __error;
1168 } 1159 }
1169 1160
1170 if ((err = snd_via82xx_create(card, pci, chip_type, revision, ac97_clock[dev], &chip)) < 0) 1161 if ((err = snd_via82xx_create(card, pci, chip_type, revision,
1162 ac97_clock, &chip)) < 0)
1171 goto __error; 1163 goto __error;
1172 if ((err = snd_via82xx_mixer_new(chip)) < 0) 1164 if ((err = snd_via82xx_mixer_new(chip)) < 0)
1173 goto __error; 1165 goto __error;
@@ -1191,7 +1183,6 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
1191 return err; 1183 return err;
1192 } 1184 }
1193 pci_set_drvdata(pci, card); 1185 pci_set_drvdata(pci, card);
1194 dev++;
1195 return 0; 1186 return 0;
1196 1187
1197 __error: 1188 __error:
diff --git a/sound/pci/ymfpci/ymfpci.c b/sound/pci/ymfpci/ymfpci.c
index 2e69abe51aa9..1bbba32517ff 100644
--- a/sound/pci/ymfpci/ymfpci.c
+++ b/sound/pci/ymfpci/ymfpci.c
@@ -130,8 +130,7 @@ static int __devinit snd_ymfpci_create_gameport(ymfpci_t *chip, int dev,
130 chip->gameport = gp = gameport_allocate_port(); 130 chip->gameport = gp = gameport_allocate_port();
131 if (!gp) { 131 if (!gp) {
132 printk(KERN_ERR "ymfpci: cannot allocate memory for gameport\n"); 132 printk(KERN_ERR "ymfpci: cannot allocate memory for gameport\n");
133 release_resource(r); 133 release_and_free_resource(r);
134 kfree_nocheck(r);
135 return -ENOMEM; 134 return -ENOMEM;
136 } 135 }
137 136
@@ -161,8 +160,7 @@ void snd_ymfpci_free_gameport(ymfpci_t *chip)
161 gameport_unregister_port(chip->gameport); 160 gameport_unregister_port(chip->gameport);
162 chip->gameport = NULL; 161 chip->gameport = NULL;
163 162
164 release_resource(r); 163 release_and_free_resource(r);
165 kfree_nocheck(r);
166 } 164 }
167} 165}
168#else 166#else
@@ -267,14 +265,8 @@ static int __devinit snd_card_ymfpci_probe(struct pci_dev *pci,
267 old_legacy_ctrl, 265 old_legacy_ctrl,
268 &chip)) < 0) { 266 &chip)) < 0) {
269 snd_card_free(card); 267 snd_card_free(card);
270 if (mpu_res) { 268 release_and_free_resource(mpu_res);
271 release_resource(mpu_res); 269 release_and_free_resource(fm_res);
272 kfree_nocheck(mpu_res);
273 }
274 if (fm_res) {
275 release_resource(fm_res);
276 kfree_nocheck(fm_res);
277 }
278 return err; 270 return err;
279 } 271 }
280 chip->fm_res = fm_res; 272 chip->fm_res = fm_res;
@@ -328,7 +320,7 @@ static int __devinit snd_card_ymfpci_probe(struct pci_dev *pci,
328 pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl); 320 pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
329 } else if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { 321 } else if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
330 snd_card_free(card); 322 snd_card_free(card);
331 snd_printk("cannot create opl3 hwdep\n"); 323 snd_printk(KERN_ERR "cannot create opl3 hwdep\n");
332 return err; 324 return err;
333 } 325 }
334 } 326 }
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index 27fa523639ae..88a43e091d77 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -92,9 +92,9 @@ static int snd_ymfpci_codec_ready(ymfpci_t *chip, int secondary)
92 if ((snd_ymfpci_readw(chip, reg) & 0x8000) == 0) 92 if ((snd_ymfpci_readw(chip, reg) & 0x8000) == 0)
93 return 0; 93 return 0;
94 set_current_state(TASK_UNINTERRUPTIBLE); 94 set_current_state(TASK_UNINTERRUPTIBLE);
95 schedule_timeout(1); 95 schedule_timeout_uninterruptible(1);
96 } while (time_before(jiffies, end_time)); 96 } while (time_before(jiffies, end_time));
97 snd_printk("codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_ymfpci_readw(chip, reg)); 97 snd_printk(KERN_ERR "codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_ymfpci_readw(chip, reg));
98 return -EBUSY; 98 return -EBUSY;
99} 99}
100 100
@@ -728,8 +728,7 @@ static void snd_ymfpci_irq_wait(ymfpci_t *chip)
728 init_waitqueue_entry(&wait, current); 728 init_waitqueue_entry(&wait, current);
729 add_wait_queue(&chip->interrupt_sleep, &wait); 729 add_wait_queue(&chip->interrupt_sleep, &wait);
730 atomic_inc(&chip->interrupt_sleep_count); 730 atomic_inc(&chip->interrupt_sleep_count);
731 set_current_state(TASK_UNINTERRUPTIBLE); 731 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
732 schedule_timeout(HZ/20);
733 remove_wait_queue(&chip->interrupt_sleep, &wait); 732 remove_wait_queue(&chip->interrupt_sleep, &wait);
734 } 733 }
735} 734}
@@ -1421,15 +1420,18 @@ static snd_kcontrol_new_t snd_ymfpci_drec_source __devinitdata = {
1421 * Mixer controls 1420 * Mixer controls
1422 */ 1421 */
1423 1422
1424#define YMFPCI_SINGLE(xname, xindex, reg) \ 1423#define YMFPCI_SINGLE(xname, xindex, reg, shift) \
1425{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 1424{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1426 .info = snd_ymfpci_info_single, \ 1425 .info = snd_ymfpci_info_single, \
1427 .get = snd_ymfpci_get_single, .put = snd_ymfpci_put_single, \ 1426 .get = snd_ymfpci_get_single, .put = snd_ymfpci_put_single, \
1428 .private_value = reg } 1427 .private_value = ((reg) | ((shift) << 16)) }
1429 1428
1430static int snd_ymfpci_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 1429static int snd_ymfpci_info_single(snd_kcontrol_t *kcontrol,
1430 snd_ctl_elem_info_t *uinfo)
1431{ 1431{
1432 switch (kcontrol->private_value) { 1432 int reg = kcontrol->private_value & 0xffff;
1433
1434 switch (reg) {
1433 case YDSXGR_SPDIFOUTCTRL: break; 1435 case YDSXGR_SPDIFOUTCTRL: break;
1434 case YDSXGR_SPDIFINCTRL: break; 1436 case YDSXGR_SPDIFINCTRL: break;
1435 default: return -EINVAL; 1437 default: return -EINVAL;
@@ -1441,30 +1443,35 @@ static int snd_ymfpci_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
1441 return 0; 1443 return 0;
1442} 1444}
1443 1445
1444static int snd_ymfpci_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1446static int snd_ymfpci_get_single(snd_kcontrol_t *kcontrol,
1447 snd_ctl_elem_value_t *ucontrol)
1445{ 1448{
1446 ymfpci_t *chip = snd_kcontrol_chip(kcontrol); 1449 ymfpci_t *chip = snd_kcontrol_chip(kcontrol);
1447 int reg = kcontrol->private_value; 1450 int reg = kcontrol->private_value & 0xffff;
1448 unsigned int shift = 0, mask = 1; 1451 unsigned int shift = (kcontrol->private_value >> 16) & 0xff;
1452 unsigned int mask = 1;
1449 1453
1450 switch (kcontrol->private_value) { 1454 switch (reg) {
1451 case YDSXGR_SPDIFOUTCTRL: break; 1455 case YDSXGR_SPDIFOUTCTRL: break;
1452 case YDSXGR_SPDIFINCTRL: break; 1456 case YDSXGR_SPDIFINCTRL: break;
1453 default: return -EINVAL; 1457 default: return -EINVAL;
1454 } 1458 }
1455 ucontrol->value.integer.value[0] = (snd_ymfpci_readl(chip, reg) >> shift) & mask; 1459 ucontrol->value.integer.value[0] =
1460 (snd_ymfpci_readl(chip, reg) >> shift) & mask;
1456 return 0; 1461 return 0;
1457} 1462}
1458 1463
1459static int snd_ymfpci_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1464static int snd_ymfpci_put_single(snd_kcontrol_t *kcontrol,
1465 snd_ctl_elem_value_t *ucontrol)
1460{ 1466{
1461 ymfpci_t *chip = snd_kcontrol_chip(kcontrol); 1467 ymfpci_t *chip = snd_kcontrol_chip(kcontrol);
1462 int reg = kcontrol->private_value; 1468 int reg = kcontrol->private_value & 0xffff;
1463 unsigned int shift = 0, mask = 1; 1469 unsigned int shift = (kcontrol->private_value >> 16) & 0xff;
1470 unsigned int mask = 1;
1464 int change; 1471 int change;
1465 unsigned int val, oval; 1472 unsigned int val, oval;
1466 1473
1467 switch (kcontrol->private_value) { 1474 switch (reg) {
1468 case YDSXGR_SPDIFOUTCTRL: break; 1475 case YDSXGR_SPDIFOUTCTRL: break;
1469 case YDSXGR_SPDIFINCTRL: break; 1476 case YDSXGR_SPDIFINCTRL: break;
1470 default: return -EINVAL; 1477 default: return -EINVAL;
@@ -1583,8 +1590,9 @@ YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ", PLAYBACK,VOLUME), 0, YDSXGR_ZVOUTVO
1583YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE,VOLUME), 0, YDSXGR_ZVLOOPVOL), 1590YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE,VOLUME), 0, YDSXGR_ZVLOOPVOL),
1584YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK,VOLUME), 1, YDSXGR_SPDIFOUTVOL), 1591YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK,VOLUME), 1, YDSXGR_SPDIFOUTVOL),
1585YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,VOLUME), 1, YDSXGR_SPDIFLOOPVOL), 1592YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,VOLUME), 1, YDSXGR_SPDIFLOOPVOL),
1586YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), 0, YDSXGR_SPDIFOUTCTRL), 1593YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), 0, YDSXGR_SPDIFOUTCTRL, 0),
1587YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0, YDSXGR_SPDIFINCTRL), 1594YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0, YDSXGR_SPDIFINCTRL, 0),
1595YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("Loop",NONE,NONE), 0, YDSXGR_SPDIFINCTRL, 4),
1588{ 1596{
1589 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1597 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1590 .name = "4ch Duplication", 1598 .name = "4ch Duplication",
@@ -1842,9 +1850,7 @@ static int snd_ymfpci_timer_start(snd_timer_t *timer)
1842 unsigned int count; 1850 unsigned int count;
1843 1851
1844 chip = snd_timer_chip(timer); 1852 chip = snd_timer_chip(timer);
1845 count = timer->sticks - 1; 1853 count = (timer->sticks << 1) - 1;
1846 if (count == 0) /* minimum time is 20.8 us */
1847 count = 1;
1848 spin_lock_irqsave(&chip->reg_lock, flags); 1854 spin_lock_irqsave(&chip->reg_lock, flags);
1849 snd_ymfpci_writew(chip, YDSXGR_TIMERCOUNT, count); 1855 snd_ymfpci_writew(chip, YDSXGR_TIMERCOUNT, count);
1850 snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x03); 1856 snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x03);
@@ -1868,14 +1874,14 @@ static int snd_ymfpci_timer_precise_resolution(snd_timer_t *timer,
1868 unsigned long *num, unsigned long *den) 1874 unsigned long *num, unsigned long *den)
1869{ 1875{
1870 *num = 1; 1876 *num = 1;
1871 *den = 96000; 1877 *den = 48000;
1872 return 0; 1878 return 0;
1873} 1879}
1874 1880
1875static struct _snd_timer_hardware snd_ymfpci_timer_hw = { 1881static struct _snd_timer_hardware snd_ymfpci_timer_hw = {
1876 .flags = SNDRV_TIMER_HW_AUTO, 1882 .flags = SNDRV_TIMER_HW_AUTO,
1877 .resolution = 10417, /* 1/2fs = 10.41666...us */ 1883 .resolution = 20833, /* 1/fs = 20.8333...us */
1878 .ticks = 65536, 1884 .ticks = 0x8000,
1879 .start = snd_ymfpci_timer_start, 1885 .start = snd_ymfpci_timer_start,
1880 .stop = snd_ymfpci_timer_stop, 1886 .stop = snd_ymfpci_timer_stop,
1881 .precise_resolution = snd_ymfpci_timer_precise_resolution, 1887 .precise_resolution = snd_ymfpci_timer_precise_resolution,
@@ -2142,14 +2148,8 @@ static int snd_ymfpci_free(ymfpci_t *chip)
2142#ifdef CONFIG_PM 2148#ifdef CONFIG_PM
2143 vfree(chip->saved_regs); 2149 vfree(chip->saved_regs);
2144#endif 2150#endif
2145 if (chip->mpu_res) { 2151 release_and_free_resource(chip->mpu_res);
2146 release_resource(chip->mpu_res); 2152 release_and_free_resource(chip->fm_res);
2147 kfree_nocheck(chip->mpu_res);
2148 }
2149 if (chip->fm_res) {
2150 release_resource(chip->fm_res);
2151 kfree_nocheck(chip->fm_res);
2152 }
2153 snd_ymfpci_free_gameport(chip); 2153 snd_ymfpci_free_gameport(chip);
2154 if (chip->reg_area_virt) 2154 if (chip->reg_area_virt)
2155 iounmap(chip->reg_area_virt); 2155 iounmap(chip->reg_area_virt);
@@ -2158,10 +2158,7 @@ static int snd_ymfpci_free(ymfpci_t *chip)
2158 2158
2159 if (chip->irq >= 0) 2159 if (chip->irq >= 0)
2160 free_irq(chip->irq, (void *)chip); 2160 free_irq(chip->irq, (void *)chip);
2161 if (chip->res_reg_area) { 2161 release_and_free_resource(chip->res_reg_area);
2162 release_resource(chip->res_reg_area);
2163 kfree_nocheck(chip->res_reg_area);
2164 }
2165 2162
2166 pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl); 2163 pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl);
2167 2164
@@ -2290,12 +2287,12 @@ int __devinit snd_ymfpci_create(snd_card_t * card,
2290 pci_set_master(pci); 2287 pci_set_master(pci);
2291 2288
2292 if ((chip->res_reg_area = request_mem_region(chip->reg_area_phys, 0x8000, "YMFPCI")) == NULL) { 2289 if ((chip->res_reg_area = request_mem_region(chip->reg_area_phys, 0x8000, "YMFPCI")) == NULL) {
2293 snd_printk("unable to grab memory region 0x%lx-0x%lx\n", chip->reg_area_phys, chip->reg_area_phys + 0x8000 - 1); 2290 snd_printk(KERN_ERR "unable to grab memory region 0x%lx-0x%lx\n", chip->reg_area_phys, chip->reg_area_phys + 0x8000 - 1);
2294 snd_ymfpci_free(chip); 2291 snd_ymfpci_free(chip);
2295 return -EBUSY; 2292 return -EBUSY;
2296 } 2293 }
2297 if (request_irq(pci->irq, snd_ymfpci_interrupt, SA_INTERRUPT|SA_SHIRQ, "YMFPCI", (void *) chip)) { 2294 if (request_irq(pci->irq, snd_ymfpci_interrupt, SA_INTERRUPT|SA_SHIRQ, "YMFPCI", (void *) chip)) {
2298 snd_printk("unable to grab IRQ %d\n", pci->irq); 2295 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2299 snd_ymfpci_free(chip); 2296 snd_ymfpci_free(chip);
2300 return -EBUSY; 2297 return -EBUSY;
2301 } 2298 }
diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c b/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c
index 0a954dc11b73..20b86d8df7a3 100644
--- a/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c
+++ b/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c
@@ -50,9 +50,9 @@ static int snd_pcm_alloc_vmalloc_buffer(snd_pcm_substream_t *subs, size_t size)
50 if (runtime->dma_area) { 50 if (runtime->dma_area) {
51 if (runtime->dma_bytes >= size) 51 if (runtime->dma_bytes >= size)
52 return 0; /* already enough large */ 52 return 0; /* already enough large */
53 vfree_nocheck(runtime->dma_area); 53 vfree(runtime->dma_area);
54 } 54 }
55 runtime->dma_area = vmalloc_nocheck(size); 55 runtime->dma_area = vmalloc_32(size);
56 if (! runtime->dma_area) 56 if (! runtime->dma_area)
57 return -ENOMEM; 57 return -ENOMEM;
58 runtime->dma_bytes = size; 58 runtime->dma_bytes = size;
@@ -67,7 +67,7 @@ static int snd_pcm_free_vmalloc_buffer(snd_pcm_substream_t *subs)
67{ 67{
68 snd_pcm_runtime_t *runtime = subs->runtime; 68 snd_pcm_runtime_t *runtime = subs->runtime;
69 if (runtime->dma_area) { 69 if (runtime->dma_area) {
70 vfree_nocheck(runtime->dma_area); 70 vfree(runtime->dma_area);
71 runtime->dma_area = NULL; 71 runtime->dma_area = NULL;
72 } 72 }
73 return 0; 73 return 0;
diff --git a/sound/ppc/beep.c b/sound/ppc/beep.c
index 1681ee13efbb..d4ec6cc3f1c5 100644
--- a/sound/ppc/beep.c
+++ b/sound/ppc/beep.c
@@ -171,8 +171,6 @@ static int snd_pmac_beep_event(struct input_dev *dev, unsigned int type, unsigne
171 * beep volume mixer 171 * beep volume mixer
172 */ 172 */
173 173
174#define chip_t pmac_t
175
176static int snd_pmac_info_beep(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 174static int snd_pmac_info_beep(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
177{ 175{
178 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 176 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index 392b2abd9f13..db2f1815fc30 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -220,7 +220,8 @@ static int snd_pmac_pcm_prepare(pmac_t *chip, pmac_stream_t *rec, snd_pcm_substr
220 220
221 /* set up constraints */ 221 /* set up constraints */
222 astr = snd_pmac_get_stream(chip, another_stream(rec->stream)); 222 astr = snd_pmac_get_stream(chip, another_stream(rec->stream));
223 snd_runtime_check(astr, return -EINVAL); 223 if (! astr)
224 return -EINVAL;
224 astr->cur_freqs = 1 << rate_index; 225 astr->cur_freqs = 1 << rate_index;
225 astr->cur_formats = 1 << runtime->format; 226 astr->cur_formats = 1 << runtime->format;
226 chip->rate_index = rate_index; 227 chip->rate_index = rate_index;
@@ -467,7 +468,8 @@ static int snd_pmac_hw_rule_rate(snd_pcm_hw_params_t *params,
467 pmac_stream_t *rec = snd_pmac_get_stream(chip, rule->deps[0]); 468 pmac_stream_t *rec = snd_pmac_get_stream(chip, rule->deps[0]);
468 int i, freq_table[8], num_freqs; 469 int i, freq_table[8], num_freqs;
469 470
470 snd_runtime_check(rec, return -EINVAL); 471 if (! rec)
472 return -EINVAL;
471 num_freqs = 0; 473 num_freqs = 0;
472 for (i = chip->num_freqs - 1; i >= 0; i--) { 474 for (i = chip->num_freqs - 1; i >= 0; i--) {
473 if (rec->cur_freqs & (1 << i)) 475 if (rec->cur_freqs & (1 << i))
@@ -484,7 +486,8 @@ static int snd_pmac_hw_rule_format(snd_pcm_hw_params_t *params,
484 pmac_t *chip = rule->private; 486 pmac_t *chip = rule->private;
485 pmac_stream_t *rec = snd_pmac_get_stream(chip, rule->deps[0]); 487 pmac_stream_t *rec = snd_pmac_get_stream(chip, rule->deps[0]);
486 488
487 snd_runtime_check(rec, return -EINVAL); 489 if (! rec)
490 return -EINVAL;
488 return snd_mask_refine_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 491 return snd_mask_refine_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
489 rec->cur_formats); 492 rec->cur_formats);
490} 493}
@@ -569,7 +572,8 @@ static int snd_pmac_pcm_close(pmac_t *chip, pmac_stream_t *rec, snd_pcm_substrea
569 snd_pmac_dma_stop(rec); 572 snd_pmac_dma_stop(rec);
570 573
571 astr = snd_pmac_get_stream(chip, another_stream(rec->stream)); 574 astr = snd_pmac_get_stream(chip, another_stream(rec->stream));
572 snd_runtime_check(astr, return -EINVAL); 575 if (! astr)
576 return -EINVAL;
573 577
574 /* reset constraints */ 578 /* reset constraints */
575 astr->cur_freqs = chip->freqs_ok; 579 astr->cur_freqs = chip->freqs_ok;
@@ -1158,7 +1162,6 @@ int __init snd_pmac_new(snd_card_t *card, pmac_t **chip_return)
1158 .dev_free = snd_pmac_dev_free, 1162 .dev_free = snd_pmac_dev_free,
1159 }; 1163 };
1160 1164
1161 snd_runtime_check(chip_return, return -EINVAL);
1162 *chip_return = NULL; 1165 *chip_return = NULL;
1163 1166
1164 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1167 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
@@ -1382,7 +1385,8 @@ static int snd_pmac_sleep_notify(struct pmu_sleep_notifier *self, int when)
1382 pmac_t *chip; 1385 pmac_t *chip;
1383 1386
1384 chip = sleeping_pmac; 1387 chip = sleeping_pmac;
1385 snd_runtime_check(chip, return 0); 1388 if (! chip)
1389 return 0;
1386 1390
1387 switch (when) { 1391 switch (when) {
1388 case PBOOK_SLEEP_NOW: 1392 case PBOOK_SLEEP_NOW:
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c
index f4361c518e46..1f8d27a6152e 100644
--- a/sound/sparc/cs4231.c
+++ b/sound/sparc/cs4231.c
@@ -61,13 +61,37 @@ MODULE_DESCRIPTION("Sun CS4231");
61MODULE_LICENSE("GPL"); 61MODULE_LICENSE("GPL");
62MODULE_SUPPORTED_DEVICE("{{Sun,CS4231}}"); 62MODULE_SUPPORTED_DEVICE("{{Sun,CS4231}}");
63 63
64typedef struct snd_cs4231 { 64#ifdef SBUS_SUPPORT
65 spinlock_t lock; 65typedef struct sbus_dma_info {
66 void __iomem *port; 66 spinlock_t lock;
67 int dir;
68 void __iomem *regs;
69} sbus_dma_info_t;
70#endif
71
72typedef struct snd_cs4231 cs4231_t;
73
74typedef struct cs4231_dma_control {
75 void (*prepare)(struct cs4231_dma_control *dma_cont, int dir);
76 void (*enable)(struct cs4231_dma_control *dma_cont, int on);
77 int (*request)(struct cs4231_dma_control *dma_cont, dma_addr_t bus_addr, size_t len);
78 unsigned int (*address)(struct cs4231_dma_control *dma_cont);
79 void (*reset)(cs4231_t *chip);
80 void (*preallocate)(cs4231_t *chip, snd_pcm_t *pcm);
67#ifdef EBUS_SUPPORT 81#ifdef EBUS_SUPPORT
68 struct ebus_dma_info eb2c; 82 struct ebus_dma_info ebus_info;
69 struct ebus_dma_info eb2p; 83#endif
84#ifdef SBUS_SUPPORT
85 struct sbus_dma_info sbus_info;
70#endif 86#endif
87} cs4231_dma_control_t;
88
89struct snd_cs4231 {
90 spinlock_t lock;
91 void __iomem *port;
92
93 cs4231_dma_control_t p_dma;
94 cs4231_dma_control_t c_dma;
71 95
72 u32 flags; 96 u32 flags;
73#define CS4231_FLAG_EBUS 0x00000001 97#define CS4231_FLAG_EBUS 0x00000001
@@ -106,7 +130,7 @@ typedef struct snd_cs4231 {
106 unsigned int irq[2]; 130 unsigned int irq[2];
107 unsigned int regs_size; 131 unsigned int regs_size;
108 struct snd_cs4231 *next; 132 struct snd_cs4231 *next;
109} cs4231_t; 133};
110 134
111static cs4231_t *cs4231_list; 135static cs4231_t *cs4231_list;
112 136
@@ -251,6 +275,15 @@ static cs4231_t *cs4231_list;
251#define APCPNVA 0x38UL /* APC Play DMA Next Address */ 275#define APCPNVA 0x38UL /* APC Play DMA Next Address */
252#define APCPNC 0x3cUL /* APC Play Next Count */ 276#define APCPNC 0x3cUL /* APC Play Next Count */
253 277
278/* Defines for SBUS DMA-routines */
279
280#define APCVA 0x0UL /* APC DMA Address */
281#define APCC 0x4UL /* APC Count */
282#define APCNVA 0x8UL /* APC DMA Next Address */
283#define APCNC 0xcUL /* APC Next Count */
284#define APC_PLAY 0x30UL /* Play registers start at 0x30 */
285#define APC_RECORD 0x20UL /* Record registers start at 0x20 */
286
254/* APCCSR bits */ 287/* APCCSR bits */
255 288
256#define APC_INT_PENDING 0x800000 /* Interrupt Pending */ 289#define APC_INT_PENDING 0x800000 /* Interrupt Pending */
@@ -569,8 +602,7 @@ static void snd_cs4231_mce_down(cs4231_t *chip)
569 spin_unlock_irqrestore(&chip->lock, flags); 602 spin_unlock_irqrestore(&chip->lock, flags);
570} 603}
571 604
572#ifdef EBUS_SUPPORT 605static void snd_cs4231_advance_dma(struct cs4231_dma_control *dma_cont, snd_pcm_substream_t *substream, unsigned int *periods_sent)
573static void snd_cs4231_ebus_advance_dma(struct ebus_dma_info *p, snd_pcm_substream_t *substream, unsigned int *periods_sent)
574{ 606{
575 snd_pcm_runtime_t *runtime = substream->runtime; 607 snd_pcm_runtime_t *runtime = substream->runtime;
576 608
@@ -581,129 +613,41 @@ static void snd_cs4231_ebus_advance_dma(struct ebus_dma_info *p, snd_pcm_substre
581 if (period_size >= (1 << 24)) 613 if (period_size >= (1 << 24))
582 BUG(); 614 BUG();
583 615
584 if (ebus_dma_request(p, runtime->dma_addr + offset, period_size)) 616 if (dma_cont->request(dma_cont, runtime->dma_addr + offset, period_size))
585 return; 617 return;
586 (*periods_sent) = ((*periods_sent) + 1) % runtime->periods; 618 (*periods_sent) = ((*periods_sent) + 1) % runtime->periods;
587 } 619 }
588} 620}
589#endif
590
591#ifdef SBUS_SUPPORT
592static void snd_cs4231_sbus_advance_dma(snd_pcm_substream_t *substream, unsigned int *periods_sent)
593{
594 cs4231_t *chip = snd_pcm_substream_chip(substream);
595 snd_pcm_runtime_t *runtime = substream->runtime;
596
597 unsigned int period_size = snd_pcm_lib_period_bytes(substream);
598 unsigned int offset = period_size * (*periods_sent % runtime->periods);
599
600 if (runtime->period_size > 0xffff + 1)
601 BUG();
602
603 switch (substream->stream) {
604 case SNDRV_PCM_STREAM_PLAYBACK:
605 sbus_writel(runtime->dma_addr + offset, chip->port + APCPNVA);
606 sbus_writel(period_size, chip->port + APCPNC);
607 break;
608 case SNDRV_PCM_STREAM_CAPTURE:
609 sbus_writel(runtime->dma_addr + offset, chip->port + APCCNVA);
610 sbus_writel(period_size, chip->port + APCCNC);
611 break;
612 }
613
614 (*periods_sent) = (*periods_sent + 1) % runtime->periods;
615}
616#endif
617 621
618static void cs4231_dma_trigger(snd_pcm_substream_t *substream, unsigned int what, int on) 622static void cs4231_dma_trigger(snd_pcm_substream_t *substream, unsigned int what, int on)
619{ 623{
620 cs4231_t *chip = snd_pcm_substream_chip(substream); 624 cs4231_t *chip = snd_pcm_substream_chip(substream);
625 cs4231_dma_control_t *dma_cont;
621 626
622#ifdef EBUS_SUPPORT 627 if (what & CS4231_PLAYBACK_ENABLE) {
623 if (chip->flags & CS4231_FLAG_EBUS) { 628 dma_cont = &chip->p_dma;
624 if (what & CS4231_PLAYBACK_ENABLE) {
625 if (on) {
626 ebus_dma_prepare(&chip->eb2p, 0);
627 ebus_dma_enable(&chip->eb2p, 1);
628 snd_cs4231_ebus_advance_dma(&chip->eb2p,
629 chip->playback_substream,
630 &chip->p_periods_sent);
631 } else {
632 ebus_dma_enable(&chip->eb2p, 0);
633 }
634 }
635 if (what & CS4231_RECORD_ENABLE) {
636 if (on) {
637 ebus_dma_prepare(&chip->eb2c, 1);
638 ebus_dma_enable(&chip->eb2c, 1);
639 snd_cs4231_ebus_advance_dma(&chip->eb2c,
640 chip->capture_substream,
641 &chip->c_periods_sent);
642 } else {
643 ebus_dma_enable(&chip->eb2c, 0);
644 }
645 }
646 } else {
647#endif
648#ifdef SBUS_SUPPORT
649 u32 csr = sbus_readl(chip->port + APCCSR);
650 /* I don't know why, but on sbus the period counter must
651 * only start counting after the first period is sent.
652 * Therefore this dummy thing.
653 */
654 unsigned int dummy = 0;
655
656 switch (what) {
657 case CS4231_PLAYBACK_ENABLE:
658 if (on) { 629 if (on) {
659 csr &= ~APC_XINT_PLAY; 630 dma_cont->prepare(dma_cont, 0);
660 sbus_writel(csr, chip->port + APCCSR); 631 dma_cont->enable(dma_cont, 1);
661 632 snd_cs4231_advance_dma(dma_cont,
662 csr &= ~APC_PPAUSE; 633 chip->playback_substream,
663 sbus_writel(csr, chip->port + APCCSR); 634 &chip->p_periods_sent);
664
665 snd_cs4231_sbus_advance_dma(substream, &dummy);
666
667 csr |= APC_GENL_INT | APC_PLAY_INT | APC_XINT_ENA |
668 APC_XINT_PLAY | APC_XINT_EMPT | APC_XINT_GENL |
669 APC_XINT_PENA | APC_PDMA_READY;
670 sbus_writel(csr, chip->port + APCCSR);
671 } else { 635 } else {
672 csr |= APC_PPAUSE; 636 dma_cont->enable(dma_cont, 0);
673 sbus_writel(csr, chip->port + APCCSR);
674
675 csr &= ~APC_PDMA_READY;
676 sbus_writel(csr, chip->port + APCCSR);
677 } 637 }
678 break; 638 }
679 case CS4231_RECORD_ENABLE: 639 if (what & CS4231_RECORD_ENABLE) {
640 dma_cont = &chip->c_dma;
680 if (on) { 641 if (on) {
681 csr &= ~APC_XINT_CAPT; 642 dma_cont->prepare(dma_cont, 1);
682 sbus_writel(csr, chip->port + APCCSR); 643 dma_cont->enable(dma_cont, 1);
683 644 snd_cs4231_advance_dma(dma_cont,
684 csr &= ~APC_CPAUSE; 645 chip->capture_substream,
685 sbus_writel(csr, chip->port + APCCSR); 646 &chip->c_periods_sent);
686
687 snd_cs4231_sbus_advance_dma(substream, &dummy);
688
689 csr |= APC_GENL_INT | APC_CAPT_INT | APC_XINT_ENA |
690 APC_XINT_CAPT | APC_XINT_CEMP | APC_XINT_GENL |
691 APC_CDMA_READY;
692
693 sbus_writel(csr, chip->port + APCCSR);
694 } else { 647 } else {
695 csr |= APC_CPAUSE; 648 dma_cont->enable(dma_cont, 0);
696 sbus_writel(csr, chip->port + APCCSR);
697
698 csr &= ~APC_CDMA_READY;
699 sbus_writel(csr, chip->port + APCCSR);
700 } 649 }
701 break;
702 }
703#endif
704#ifdef EBUS_SUPPORT
705 } 650 }
706#endif
707} 651}
708 652
709static int snd_cs4231_trigger(snd_pcm_substream_t *substream, int cmd) 653static int snd_cs4231_trigger(snd_pcm_substream_t *substream, int cmd)
@@ -1136,10 +1080,7 @@ static int snd_cs4231_playback_prepare(snd_pcm_substream_t *substream)
1136 if (runtime->period_size > 0xffff + 1) 1080 if (runtime->period_size > 0xffff + 1)
1137 BUG(); 1081 BUG();
1138 1082
1139 snd_cs4231_out(chip, CS4231_PLY_LWR_CNT, (runtime->period_size - 1) & 0x00ff);
1140 snd_cs4231_out(chip, CS4231_PLY_UPR_CNT, (runtime->period_size - 1) >> 8 & 0x00ff);
1141 chip->p_periods_sent = 0; 1083 chip->p_periods_sent = 0;
1142
1143 spin_unlock_irqrestore(&chip->lock, flags); 1084 spin_unlock_irqrestore(&chip->lock, flags);
1144 1085
1145 return 0; 1086 return 0;
@@ -1171,16 +1112,14 @@ static int snd_cs4231_capture_hw_free(snd_pcm_substream_t *substream)
1171static int snd_cs4231_capture_prepare(snd_pcm_substream_t *substream) 1112static int snd_cs4231_capture_prepare(snd_pcm_substream_t *substream)
1172{ 1113{
1173 cs4231_t *chip = snd_pcm_substream_chip(substream); 1114 cs4231_t *chip = snd_pcm_substream_chip(substream);
1174 snd_pcm_runtime_t *runtime = substream->runtime;
1175 unsigned long flags; 1115 unsigned long flags;
1176 1116
1177 spin_lock_irqsave(&chip->lock, flags); 1117 spin_lock_irqsave(&chip->lock, flags);
1178 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_RECORD_ENABLE | 1118 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_RECORD_ENABLE |
1179 CS4231_RECORD_PIO); 1119 CS4231_RECORD_PIO);
1180 1120
1181 snd_cs4231_out(chip, CS4231_REC_LWR_CNT, (runtime->period_size - 1) & 0x00ff);
1182 snd_cs4231_out(chip, CS4231_REC_LWR_CNT, (runtime->period_size - 1) >> 8 & 0x00ff);
1183 1121
1122 chip->c_periods_sent = 0;
1184 spin_unlock_irqrestore(&chip->lock, flags); 1123 spin_unlock_irqrestore(&chip->lock, flags);
1185 1124
1186 return 0; 1125 return 0;
@@ -1199,134 +1138,55 @@ static void snd_cs4231_overrange(cs4231_t *chip)
1199 chip->capture_substream->runtime->overrange++; 1138 chip->capture_substream->runtime->overrange++;
1200} 1139}
1201 1140
1202static irqreturn_t snd_cs4231_generic_interrupt(cs4231_t *chip) 1141static void snd_cs4231_play_callback(cs4231_t *cookie)
1203{
1204 unsigned long flags;
1205 unsigned char status;
1206
1207 /*This is IRQ is not raised by the cs4231*/
1208 if (!(__cs4231_readb(chip, CS4231P(chip, STATUS)) & CS4231_GLOBALIRQ))
1209 return IRQ_NONE;
1210
1211 status = snd_cs4231_in(chip, CS4231_IRQ_STATUS);
1212
1213 if (status & CS4231_TIMER_IRQ) {
1214 if (chip->timer)
1215 snd_timer_interrupt(chip->timer, chip->timer->sticks);
1216 }
1217
1218 if (status & CS4231_RECORD_IRQ)
1219 snd_cs4231_overrange(chip);
1220
1221 /* ACK the CS4231 interrupt. */
1222 spin_lock_irqsave(&chip->lock, flags);
1223 snd_cs4231_outm(chip, CS4231_IRQ_STATUS, ~CS4231_ALL_IRQS | ~status, 0);
1224 spin_unlock_irqrestore(&chip->lock, flags);
1225
1226 return 0;
1227}
1228
1229#ifdef SBUS_SUPPORT
1230static irqreturn_t snd_cs4231_sbus_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1231{
1232 cs4231_t *chip = dev_id;
1233
1234 /* ACK the APC interrupt. */
1235 u32 csr = sbus_readl(chip->port + APCCSR);
1236
1237 sbus_writel(csr, chip->port + APCCSR);
1238
1239 if ((chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE) &&
1240 (csr & APC_PLAY_INT) &&
1241 (csr & APC_XINT_PNVA) &&
1242 !(csr & APC_XINT_EMPT)) {
1243 snd_cs4231_sbus_advance_dma(chip->playback_substream,
1244 &chip->p_periods_sent);
1245 snd_pcm_period_elapsed(chip->playback_substream);
1246 }
1247
1248 if ((chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) &&
1249 (csr & APC_CAPT_INT) &&
1250 (csr & APC_XINT_CNVA)) {
1251 snd_cs4231_sbus_advance_dma(chip->capture_substream,
1252 &chip->c_periods_sent);
1253 snd_pcm_period_elapsed(chip->capture_substream);
1254 }
1255
1256 return snd_cs4231_generic_interrupt(chip);
1257}
1258#endif
1259
1260#ifdef EBUS_SUPPORT
1261static void snd_cs4231_ebus_play_callback(struct ebus_dma_info *p, int event, void *cookie)
1262{ 1142{
1263 cs4231_t *chip = cookie; 1143 cs4231_t *chip = cookie;
1264 1144
1265 if (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE) { 1145 if (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE) {
1266 snd_pcm_period_elapsed(chip->playback_substream); 1146 snd_pcm_period_elapsed(chip->playback_substream);
1267 snd_cs4231_ebus_advance_dma(p, chip->playback_substream, 1147 snd_cs4231_advance_dma(&chip->p_dma, chip->playback_substream,
1268 &chip->p_periods_sent); 1148 &chip->p_periods_sent);
1269 } 1149 }
1270} 1150}
1271 1151
1272static void snd_cs4231_ebus_capture_callback(struct ebus_dma_info *p, int event, void *cookie) 1152static void snd_cs4231_capture_callback(cs4231_t *cookie)
1273{ 1153{
1274 cs4231_t *chip = cookie; 1154 cs4231_t *chip = cookie;
1275 1155
1276 if (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) { 1156 if (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) {
1277 snd_pcm_period_elapsed(chip->capture_substream); 1157 snd_pcm_period_elapsed(chip->capture_substream);
1278 snd_cs4231_ebus_advance_dma(p, chip->capture_substream, 1158 snd_cs4231_advance_dma(&chip->c_dma, chip->capture_substream,
1279 &chip->c_periods_sent); 1159 &chip->c_periods_sent);
1280 } 1160 }
1281} 1161}
1282#endif
1283 1162
1284static snd_pcm_uframes_t snd_cs4231_playback_pointer(snd_pcm_substream_t *substream) 1163static snd_pcm_uframes_t snd_cs4231_playback_pointer(snd_pcm_substream_t *substream)
1285{ 1164{
1286 cs4231_t *chip = snd_pcm_substream_chip(substream); 1165 cs4231_t *chip = snd_pcm_substream_chip(substream);
1287 size_t ptr, residue, period_bytes; 1166 cs4231_dma_control_t *dma_cont = &chip->p_dma;
1288 1167 size_t ptr;
1168
1289 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) 1169 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE))
1290 return 0; 1170 return 0;
1291 period_bytes = snd_pcm_lib_period_bytes(substream); 1171 ptr = dma_cont->address(dma_cont);
1292 ptr = period_bytes * chip->p_periods_sent; 1172 if (ptr != 0)
1293#ifdef EBUS_SUPPORT 1173 ptr -= substream->runtime->dma_addr;
1294 if (chip->flags & CS4231_FLAG_EBUS) { 1174
1295 residue = ebus_dma_residue(&chip->eb2p);
1296 } else {
1297#endif
1298#ifdef SBUS_SUPPORT
1299 residue = sbus_readl(chip->port + APCPC);
1300#endif
1301#ifdef EBUS_SUPPORT
1302 }
1303#endif
1304 ptr += period_bytes - residue;
1305
1306 return bytes_to_frames(substream->runtime, ptr); 1175 return bytes_to_frames(substream->runtime, ptr);
1307} 1176}
1308 1177
1309static snd_pcm_uframes_t snd_cs4231_capture_pointer(snd_pcm_substream_t * substream) 1178static snd_pcm_uframes_t snd_cs4231_capture_pointer(snd_pcm_substream_t * substream)
1310{ 1179{
1311 cs4231_t *chip = snd_pcm_substream_chip(substream); 1180 cs4231_t *chip = snd_pcm_substream_chip(substream);
1312 size_t ptr, residue, period_bytes; 1181 cs4231_dma_control_t *dma_cont = &chip->c_dma;
1182 size_t ptr;
1313 1183
1314 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE)) 1184 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE))
1315 return 0; 1185 return 0;
1316 period_bytes = snd_pcm_lib_period_bytes(substream); 1186 ptr = dma_cont->address(dma_cont);
1317 ptr = period_bytes * chip->c_periods_sent; 1187 if (ptr != 0)
1318#ifdef EBUS_SUPPORT 1188 ptr -= substream->runtime->dma_addr;
1319 if (chip->flags & CS4231_FLAG_EBUS) { 1189
1320 residue = ebus_dma_residue(&chip->eb2c);
1321 } else {
1322#endif
1323#ifdef SBUS_SUPPORT
1324 residue = sbus_readl(chip->port + APCCC);
1325#endif
1326#ifdef EBUS_SUPPORT
1327 }
1328#endif
1329 ptr += period_bytes - residue;
1330 return bytes_to_frames(substream->runtime, ptr); 1190 return bytes_to_frames(substream->runtime, ptr);
1331} 1191}
1332 1192
@@ -1362,30 +1222,8 @@ static int snd_cs4231_probe(cs4231_t *chip)
1362 spin_lock_irqsave(&chip->lock, flags); 1222 spin_lock_irqsave(&chip->lock, flags);
1363 1223
1364 1224
1365 /* Reset DMA engine. */ 1225 /* Reset DMA engine (sbus only). */
1366#ifdef EBUS_SUPPORT 1226 chip->p_dma.reset(chip);
1367 if (chip->flags & CS4231_FLAG_EBUS) {
1368 /* Done by ebus_dma_register */
1369 } else {
1370#endif
1371#ifdef SBUS_SUPPORT
1372 sbus_writel(APC_CHIP_RESET, chip->port + APCCSR);
1373 sbus_writel(0x00, chip->port + APCCSR);
1374 sbus_writel(sbus_readl(chip->port + APCCSR) | APC_CDC_RESET,
1375 chip->port + APCCSR);
1376
1377 udelay(20);
1378
1379 sbus_writel(sbus_readl(chip->port + APCCSR) & ~APC_CDC_RESET,
1380 chip->port + APCCSR);
1381 sbus_writel(sbus_readl(chip->port + APCCSR) | (APC_XINT_ENA |
1382 APC_XINT_PENA |
1383 APC_XINT_CENA),
1384 chip->port + APCCSR);
1385#endif
1386#ifdef EBUS_SUPPORT
1387 }
1388#endif
1389 1227
1390 __cs4231_readb(chip, CS4231P(chip, STATUS)); /* clear any pendings IRQ */ 1228 __cs4231_readb(chip, CS4231P(chip, STATUS)); /* clear any pendings IRQ */
1391 __cs4231_writeb(chip, 0, CS4231P(chip, STATUS)); 1229 __cs4231_writeb(chip, 0, CS4231P(chip, STATUS));
@@ -1505,8 +1343,8 @@ static int snd_cs4231_playback_close(snd_pcm_substream_t *substream)
1505{ 1343{
1506 cs4231_t *chip = snd_pcm_substream_chip(substream); 1344 cs4231_t *chip = snd_pcm_substream_chip(substream);
1507 1345
1508 chip->playback_substream = NULL;
1509 snd_cs4231_close(chip, CS4231_MODE_PLAY); 1346 snd_cs4231_close(chip, CS4231_MODE_PLAY);
1347 chip->playback_substream = NULL;
1510 1348
1511 return 0; 1349 return 0;
1512} 1350}
@@ -1515,8 +1353,8 @@ static int snd_cs4231_capture_close(snd_pcm_substream_t *substream)
1515{ 1353{
1516 cs4231_t *chip = snd_pcm_substream_chip(substream); 1354 cs4231_t *chip = snd_pcm_substream_chip(substream);
1517 1355
1518 chip->capture_substream = NULL;
1519 snd_cs4231_close(chip, CS4231_MODE_RECORD); 1356 snd_cs4231_close(chip, CS4231_MODE_RECORD);
1357 chip->capture_substream = NULL;
1520 1358
1521 return 0; 1359 return 0;
1522} 1360}
@@ -1571,21 +1409,7 @@ int snd_cs4231_pcm(cs4231_t *chip)
1571 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; 1409 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
1572 strcpy(pcm->name, "CS4231"); 1410 strcpy(pcm->name, "CS4231");
1573 1411
1574#ifdef EBUS_SUPPORT 1412 chip->p_dma.preallocate(chip, pcm);
1575 if (chip->flags & CS4231_FLAG_EBUS) {
1576 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1577 snd_dma_pci_data(chip->dev_u.pdev),
1578 64*1024, 128*1024);
1579 } else {
1580#endif
1581#ifdef SBUS_SUPPORT
1582 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_SBUS,
1583 snd_dma_sbus_data(chip->dev_u.sdev),
1584 64*1024, 128*1024);
1585#endif
1586#ifdef EBUS_SUPPORT
1587 }
1588#endif
1589 1413
1590 chip->pcm = pcm; 1414 chip->pcm = pcm;
1591 1415
@@ -1942,6 +1766,180 @@ out_err:
1942} 1766}
1943 1767
1944#ifdef SBUS_SUPPORT 1768#ifdef SBUS_SUPPORT
1769
1770static irqreturn_t snd_cs4231_sbus_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1771{
1772 unsigned long flags;
1773 unsigned char status;
1774 u32 csr;
1775 cs4231_t *chip = dev_id;
1776
1777 /*This is IRQ is not raised by the cs4231*/
1778 if (!(__cs4231_readb(chip, CS4231P(chip, STATUS)) & CS4231_GLOBALIRQ))
1779 return IRQ_NONE;
1780
1781 /* ACK the APC interrupt. */
1782 csr = sbus_readl(chip->port + APCCSR);
1783
1784 sbus_writel(csr, chip->port + APCCSR);
1785
1786 if ((csr & APC_PDMA_READY) &&
1787 (csr & APC_PLAY_INT) &&
1788 (csr & APC_XINT_PNVA) &&
1789 !(csr & APC_XINT_EMPT))
1790 snd_cs4231_play_callback(chip);
1791
1792 if ((csr & APC_CDMA_READY) &&
1793 (csr & APC_CAPT_INT) &&
1794 (csr & APC_XINT_CNVA) &&
1795 !(csr & APC_XINT_EMPT))
1796 snd_cs4231_capture_callback(chip);
1797
1798 status = snd_cs4231_in(chip, CS4231_IRQ_STATUS);
1799
1800 if (status & CS4231_TIMER_IRQ) {
1801 if (chip->timer)
1802 snd_timer_interrupt(chip->timer, chip->timer->sticks);
1803 }
1804
1805 if ((status & CS4231_RECORD_IRQ) && (csr & APC_CDMA_READY))
1806 snd_cs4231_overrange(chip);
1807
1808 /* ACK the CS4231 interrupt. */
1809 spin_lock_irqsave(&chip->lock, flags);
1810 snd_cs4231_outm(chip, CS4231_IRQ_STATUS, ~CS4231_ALL_IRQS | ~status, 0);
1811 spin_unlock_irqrestore(&chip->lock, flags);
1812
1813 return 0;
1814}
1815
1816/*
1817 * SBUS DMA routines
1818 */
1819
1820int sbus_dma_request(struct cs4231_dma_control *dma_cont, dma_addr_t bus_addr, size_t len)
1821{
1822 unsigned long flags;
1823 u32 test, csr;
1824 int err;
1825 sbus_dma_info_t *base = &dma_cont->sbus_info;
1826
1827 if (len >= (1 << 24))
1828 return -EINVAL;
1829 spin_lock_irqsave(&base->lock, flags);
1830 csr = sbus_readl(base->regs + APCCSR);
1831 err = -EINVAL;
1832 test = APC_CDMA_READY;
1833 if ( base->dir == APC_PLAY )
1834 test = APC_PDMA_READY;
1835 if (!(csr & test))
1836 goto out;
1837 err = -EBUSY;
1838 csr = sbus_readl(base->regs + APCCSR);
1839 test = APC_XINT_CNVA;
1840 if ( base->dir == APC_PLAY )
1841 test = APC_XINT_PNVA;
1842 if (!(csr & test))
1843 goto out;
1844 err = 0;
1845 sbus_writel(bus_addr, base->regs + base->dir + APCNVA);
1846 sbus_writel(len, base->regs + base->dir + APCNC);
1847out:
1848 spin_unlock_irqrestore(&base->lock, flags);
1849 return err;
1850}
1851
1852void sbus_dma_prepare(struct cs4231_dma_control *dma_cont, int d)
1853{
1854 unsigned long flags;
1855 u32 csr, test;
1856 sbus_dma_info_t *base = &dma_cont->sbus_info;
1857
1858 spin_lock_irqsave(&base->lock, flags);
1859 csr = sbus_readl(base->regs + APCCSR);
1860 test = APC_GENL_INT | APC_PLAY_INT | APC_XINT_ENA |
1861 APC_XINT_PLAY | APC_XINT_PEMP | APC_XINT_GENL |
1862 APC_XINT_PENA;
1863 if ( base->dir == APC_RECORD )
1864 test = APC_GENL_INT | APC_CAPT_INT | APC_XINT_ENA |
1865 APC_XINT_CAPT | APC_XINT_CEMP | APC_XINT_GENL;
1866 csr |= test;
1867 sbus_writel(csr, base->regs + APCCSR);
1868 spin_unlock_irqrestore(&base->lock, flags);
1869}
1870
1871void sbus_dma_enable(struct cs4231_dma_control *dma_cont, int on)
1872{
1873 unsigned long flags;
1874 u32 csr, shift;
1875 sbus_dma_info_t *base = &dma_cont->sbus_info;
1876
1877 spin_lock_irqsave(&base->lock, flags);
1878 if (!on) {
1879 if (base->dir == APC_PLAY) {
1880 sbus_writel(0, base->regs + base->dir + APCNVA);
1881 sbus_writel(1, base->regs + base->dir + APCC);
1882 }
1883 else
1884 {
1885 sbus_writel(0, base->regs + base->dir + APCNC);
1886 sbus_writel(0, base->regs + base->dir + APCVA);
1887 }
1888 }
1889 udelay(600);
1890 csr = sbus_readl(base->regs + APCCSR);
1891 shift = 0;
1892 if ( base->dir == APC_PLAY )
1893 shift = 1;
1894 if (on)
1895 csr &= ~(APC_CPAUSE << shift);
1896 else
1897 csr |= (APC_CPAUSE << shift);
1898 sbus_writel(csr, base->regs + APCCSR);
1899 if (on)
1900 csr |= (APC_CDMA_READY << shift);
1901 else
1902 csr &= ~(APC_CDMA_READY << shift);
1903 sbus_writel(csr, base->regs + APCCSR);
1904
1905 spin_unlock_irqrestore(&base->lock, flags);
1906}
1907
1908unsigned int sbus_dma_addr(struct cs4231_dma_control *dma_cont)
1909{
1910 sbus_dma_info_t *base = &dma_cont->sbus_info;
1911
1912 return sbus_readl(base->regs + base->dir + APCVA);
1913}
1914
1915void sbus_dma_reset(cs4231_t *chip)
1916{
1917 sbus_writel(APC_CHIP_RESET, chip->port + APCCSR);
1918 sbus_writel(0x00, chip->port + APCCSR);
1919 sbus_writel(sbus_readl(chip->port + APCCSR) | APC_CDC_RESET,
1920 chip->port + APCCSR);
1921
1922 udelay(20);
1923
1924 sbus_writel(sbus_readl(chip->port + APCCSR) & ~APC_CDC_RESET,
1925 chip->port + APCCSR);
1926 sbus_writel(sbus_readl(chip->port + APCCSR) | (APC_XINT_ENA |
1927 APC_XINT_PENA |
1928 APC_XINT_CENA),
1929 chip->port + APCCSR);
1930}
1931
1932void sbus_dma_preallocate(cs4231_t *chip, snd_pcm_t *pcm)
1933{
1934 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_SBUS,
1935 snd_dma_sbus_data(chip->dev_u.sdev),
1936 64*1024, 128*1024);
1937}
1938
1939/*
1940 * Init and exit routines
1941 */
1942
1945static int snd_cs4231_sbus_free(cs4231_t *chip) 1943static int snd_cs4231_sbus_free(cs4231_t *chip)
1946{ 1944{
1947 if (chip->irq[0]) 1945 if (chip->irq[0])
@@ -1983,6 +1981,8 @@ static int __init snd_cs4231_sbus_create(snd_card_t *card,
1983 return -ENOMEM; 1981 return -ENOMEM;
1984 1982
1985 spin_lock_init(&chip->lock); 1983 spin_lock_init(&chip->lock);
1984 spin_lock_init(&chip->c_dma.sbus_info.lock);
1985 spin_lock_init(&chip->p_dma.sbus_info.lock);
1986 init_MUTEX(&chip->mce_mutex); 1986 init_MUTEX(&chip->mce_mutex);
1987 init_MUTEX(&chip->open_mutex); 1987 init_MUTEX(&chip->open_mutex);
1988 chip->card = card; 1988 chip->card = card;
@@ -1998,6 +1998,25 @@ static int __init snd_cs4231_sbus_create(snd_card_t *card,
1998 return -EIO; 1998 return -EIO;
1999 } 1999 }
2000 2000
2001 chip->c_dma.sbus_info.regs = chip->port;
2002 chip->p_dma.sbus_info.regs = chip->port;
2003 chip->c_dma.sbus_info.dir = APC_RECORD;
2004 chip->p_dma.sbus_info.dir = APC_PLAY;
2005
2006 chip->p_dma.prepare = sbus_dma_prepare;
2007 chip->p_dma.enable = sbus_dma_enable;
2008 chip->p_dma.request = sbus_dma_request;
2009 chip->p_dma.address = sbus_dma_addr;
2010 chip->p_dma.reset = sbus_dma_reset;
2011 chip->p_dma.preallocate = sbus_dma_preallocate;
2012
2013 chip->c_dma.prepare = sbus_dma_prepare;
2014 chip->c_dma.enable = sbus_dma_enable;
2015 chip->c_dma.request = sbus_dma_request;
2016 chip->c_dma.address = sbus_dma_addr;
2017 chip->c_dma.reset = sbus_dma_reset;
2018 chip->c_dma.preallocate = sbus_dma_preallocate;
2019
2001 if (request_irq(sdev->irqs[0], snd_cs4231_sbus_interrupt, 2020 if (request_irq(sdev->irqs[0], snd_cs4231_sbus_interrupt,
2002 SA_SHIRQ, "cs4231", chip)) { 2021 SA_SHIRQ, "cs4231", chip)) {
2003 snd_printdd("cs4231-%d: Unable to grab SBUS IRQ %s\n", 2022 snd_printdd("cs4231-%d: Unable to grab SBUS IRQ %s\n",
@@ -2051,15 +2070,70 @@ static int cs4231_sbus_attach(struct sbus_dev *sdev)
2051#endif 2070#endif
2052 2071
2053#ifdef EBUS_SUPPORT 2072#ifdef EBUS_SUPPORT
2073
2074static void snd_cs4231_ebus_play_callback(struct ebus_dma_info *p, int event, void *cookie)
2075{
2076 cs4231_t *chip = cookie;
2077
2078 snd_cs4231_play_callback(chip);
2079}
2080
2081static void snd_cs4231_ebus_capture_callback(struct ebus_dma_info *p, int event, void *cookie)
2082{
2083 cs4231_t *chip = cookie;
2084
2085 snd_cs4231_capture_callback(chip);
2086}
2087
2088/*
2089 * EBUS DMA wrappers
2090 */
2091
2092int _ebus_dma_request(struct cs4231_dma_control *dma_cont, dma_addr_t bus_addr, size_t len)
2093{
2094 return ebus_dma_request(&dma_cont->ebus_info, bus_addr, len);
2095}
2096
2097void _ebus_dma_enable(struct cs4231_dma_control *dma_cont, int on)
2098{
2099 ebus_dma_enable(&dma_cont->ebus_info, on);
2100}
2101
2102void _ebus_dma_prepare(struct cs4231_dma_control *dma_cont, int dir)
2103{
2104 ebus_dma_prepare(&dma_cont->ebus_info, dir);
2105}
2106
2107unsigned int _ebus_dma_addr(struct cs4231_dma_control *dma_cont)
2108{
2109 return ebus_dma_addr(&dma_cont->ebus_info);
2110}
2111
2112void _ebus_dma_reset(cs4231_t *chip)
2113{
2114 return;
2115}
2116
2117void _ebus_dma_preallocate(cs4231_t *chip, snd_pcm_t *pcm)
2118{
2119 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
2120 snd_dma_pci_data(chip->dev_u.pdev),
2121 64*1024, 128*1024);
2122}
2123
2124/*
2125 * Init and exit routines
2126 */
2127
2054static int snd_cs4231_ebus_free(cs4231_t *chip) 2128static int snd_cs4231_ebus_free(cs4231_t *chip)
2055{ 2129{
2056 if (chip->eb2c.regs) { 2130 if (chip->c_dma.ebus_info.regs) {
2057 ebus_dma_unregister(&chip->eb2c); 2131 ebus_dma_unregister(&chip->c_dma.ebus_info);
2058 iounmap(chip->eb2c.regs); 2132 iounmap(chip->c_dma.ebus_info.regs);
2059 } 2133 }
2060 if (chip->eb2p.regs) { 2134 if (chip->p_dma.ebus_info.regs) {
2061 ebus_dma_unregister(&chip->eb2p); 2135 ebus_dma_unregister(&chip->p_dma.ebus_info);
2062 iounmap(chip->eb2p.regs); 2136 iounmap(chip->p_dma.ebus_info.regs);
2063 } 2137 }
2064 2138
2065 if (chip->port) 2139 if (chip->port)
@@ -2097,8 +2171,8 @@ static int __init snd_cs4231_ebus_create(snd_card_t *card,
2097 return -ENOMEM; 2171 return -ENOMEM;
2098 2172
2099 spin_lock_init(&chip->lock); 2173 spin_lock_init(&chip->lock);
2100 spin_lock_init(&chip->eb2c.lock); 2174 spin_lock_init(&chip->c_dma.ebus_info.lock);
2101 spin_lock_init(&chip->eb2p.lock); 2175 spin_lock_init(&chip->p_dma.ebus_info.lock);
2102 init_MUTEX(&chip->mce_mutex); 2176 init_MUTEX(&chip->mce_mutex);
2103 init_MUTEX(&chip->open_mutex); 2177 init_MUTEX(&chip->open_mutex);
2104 chip->flags |= CS4231_FLAG_EBUS; 2178 chip->flags |= CS4231_FLAG_EBUS;
@@ -2106,43 +2180,57 @@ static int __init snd_cs4231_ebus_create(snd_card_t *card,
2106 chip->dev_u.pdev = edev->bus->self; 2180 chip->dev_u.pdev = edev->bus->self;
2107 memcpy(&chip->image, &snd_cs4231_original_image, 2181 memcpy(&chip->image, &snd_cs4231_original_image,
2108 sizeof(snd_cs4231_original_image)); 2182 sizeof(snd_cs4231_original_image));
2109 strcpy(chip->eb2c.name, "cs4231(capture)"); 2183 strcpy(chip->c_dma.ebus_info.name, "cs4231(capture)");
2110 chip->eb2c.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; 2184 chip->c_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER;
2111 chip->eb2c.callback = snd_cs4231_ebus_capture_callback; 2185 chip->c_dma.ebus_info.callback = snd_cs4231_ebus_capture_callback;
2112 chip->eb2c.client_cookie = chip; 2186 chip->c_dma.ebus_info.client_cookie = chip;
2113 chip->eb2c.irq = edev->irqs[0]; 2187 chip->c_dma.ebus_info.irq = edev->irqs[0];
2114 strcpy(chip->eb2p.name, "cs4231(play)"); 2188 strcpy(chip->p_dma.ebus_info.name, "cs4231(play)");
2115 chip->eb2p.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; 2189 chip->p_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER;
2116 chip->eb2p.callback = snd_cs4231_ebus_play_callback; 2190 chip->p_dma.ebus_info.callback = snd_cs4231_ebus_play_callback;
2117 chip->eb2p.client_cookie = chip; 2191 chip->p_dma.ebus_info.client_cookie = chip;
2118 chip->eb2p.irq = edev->irqs[1]; 2192 chip->p_dma.ebus_info.irq = edev->irqs[1];
2193
2194 chip->p_dma.prepare = _ebus_dma_prepare;
2195 chip->p_dma.enable = _ebus_dma_enable;
2196 chip->p_dma.request = _ebus_dma_request;
2197 chip->p_dma.address = _ebus_dma_addr;
2198 chip->p_dma.reset = _ebus_dma_reset;
2199 chip->p_dma.preallocate = _ebus_dma_preallocate;
2200
2201 chip->c_dma.prepare = _ebus_dma_prepare;
2202 chip->c_dma.enable = _ebus_dma_enable;
2203 chip->c_dma.request = _ebus_dma_request;
2204 chip->c_dma.address = _ebus_dma_addr;
2205 chip->c_dma.reset = _ebus_dma_reset;
2206 chip->c_dma.preallocate = _ebus_dma_preallocate;
2119 2207
2120 chip->port = ioremap(edev->resource[0].start, 0x10); 2208 chip->port = ioremap(edev->resource[0].start, 0x10);
2121 chip->eb2p.regs = ioremap(edev->resource[1].start, 0x10); 2209 chip->p_dma.ebus_info.regs = ioremap(edev->resource[1].start, 0x10);
2122 chip->eb2c.regs = ioremap(edev->resource[2].start, 0x10); 2210 chip->c_dma.ebus_info.regs = ioremap(edev->resource[2].start, 0x10);
2123 if (!chip->port || !chip->eb2p.regs || !chip->eb2c.regs) { 2211 if (!chip->port || !chip->p_dma.ebus_info.regs || !chip->c_dma.ebus_info.regs) {
2124 snd_cs4231_ebus_free(chip); 2212 snd_cs4231_ebus_free(chip);
2125 snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev); 2213 snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev);
2126 return -EIO; 2214 return -EIO;
2127 } 2215 }
2128 2216
2129 if (ebus_dma_register(&chip->eb2c)) { 2217 if (ebus_dma_register(&chip->c_dma.ebus_info)) {
2130 snd_cs4231_ebus_free(chip); 2218 snd_cs4231_ebus_free(chip);
2131 snd_printdd("cs4231-%d: Unable to register EBUS capture DMA\n", dev); 2219 snd_printdd("cs4231-%d: Unable to register EBUS capture DMA\n", dev);
2132 return -EBUSY; 2220 return -EBUSY;
2133 } 2221 }
2134 if (ebus_dma_irq_enable(&chip->eb2c, 1)) { 2222 if (ebus_dma_irq_enable(&chip->c_dma.ebus_info, 1)) {
2135 snd_cs4231_ebus_free(chip); 2223 snd_cs4231_ebus_free(chip);
2136 snd_printdd("cs4231-%d: Unable to enable EBUS capture IRQ\n", dev); 2224 snd_printdd("cs4231-%d: Unable to enable EBUS capture IRQ\n", dev);
2137 return -EBUSY; 2225 return -EBUSY;
2138 } 2226 }
2139 2227
2140 if (ebus_dma_register(&chip->eb2p)) { 2228 if (ebus_dma_register(&chip->p_dma.ebus_info)) {
2141 snd_cs4231_ebus_free(chip); 2229 snd_cs4231_ebus_free(chip);
2142 snd_printdd("cs4231-%d: Unable to register EBUS play DMA\n", dev); 2230 snd_printdd("cs4231-%d: Unable to register EBUS play DMA\n", dev);
2143 return -EBUSY; 2231 return -EBUSY;
2144 } 2232 }
2145 if (ebus_dma_irq_enable(&chip->eb2p, 1)) { 2233 if (ebus_dma_irq_enable(&chip->p_dma.ebus_info, 1)) {
2146 snd_cs4231_ebus_free(chip); 2234 snd_cs4231_ebus_free(chip);
2147 snd_printdd("cs4231-%d: Unable to enable EBUS play IRQ\n", dev); 2235 snd_printdd("cs4231-%d: Unable to enable EBUS play IRQ\n", dev);
2148 return -EBUSY; 2236 return -EBUSY;
diff --git a/sound/sparc/dbri.c b/sound/sparc/dbri.c
index b5c4c15ae7f0..59a771294709 100644
--- a/sound/sparc/dbri.c
+++ b/sound/sparc/dbri.c
@@ -343,9 +343,6 @@ typedef struct snd_dbri {
343 struct snd_dbri *next; 343 struct snd_dbri *next;
344} snd_dbri_t; 344} snd_dbri_t;
345 345
346/* Needed for the ALSA macros to work */
347#define chip_t snd_dbri_t
348
349#define DBRI_MAX_VOLUME 63 /* Output volume */ 346#define DBRI_MAX_VOLUME 63 /* Output volume */
350#define DBRI_MAX_GAIN 15 /* Input gain */ 347#define DBRI_MAX_GAIN 15 /* Input gain */
351#define DBRI_RIGHT_BALANCE 255 348#define DBRI_RIGHT_BALANCE 255
@@ -1767,7 +1764,7 @@ play:
1767 spin_unlock_irqrestore(&dbri->lock, flags); 1764 spin_unlock_irqrestore(&dbri->lock, flags);
1768} 1765}
1769 1766
1770DECLARE_TASKLET(xmit_descs_task, xmit_descs, 0); 1767static DECLARE_TASKLET(xmit_descs_task, xmit_descs, 0);
1771 1768
1772/* transmission_complete_intr() 1769/* transmission_complete_intr()
1773 * 1770 *
diff --git a/sound/synth/emux/emux_synth.c b/sound/synth/emux/emux_synth.c
index 751bf1272af3..bd71b73be657 100644
--- a/sound/synth/emux/emux_synth.c
+++ b/sound/synth/emux/emux_synth.c
@@ -171,7 +171,6 @@ snd_emux_note_off(void *p, int note, int vel, snd_midi_channel_t *chan)
171 vp = &emu->voices[ch]; 171 vp = &emu->voices[ch];
172 if (STATE_IS_PLAYING(vp->state) && 172 if (STATE_IS_PLAYING(vp->state) &&
173 vp->chan == chan && vp->key == note) { 173 vp->chan == chan && vp->key == note) {
174 vp->time = emu->use_time++;
175 vp->state = SNDRV_EMUX_ST_RELEASED; 174 vp->state = SNDRV_EMUX_ST_RELEASED;
176 if (vp->ontime == jiffies) { 175 if (vp->ontime == jiffies) {
177 /* if note-off is sent too shortly after 176 /* if note-off is sent too shortly after
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index 2ead878bcb8f..99dae024b640 100644
--- a/sound/usb/usbaudio.c
+++ b/sound/usb/usbaudio.c
@@ -41,7 +41,6 @@
41#include <sound/driver.h> 41#include <sound/driver.h>
42#include <linux/bitops.h> 42#include <linux/bitops.h>
43#include <linux/init.h> 43#include <linux/init.h>
44#include <linux/interrupt.h>
45#include <linux/list.h> 44#include <linux/list.h>
46#include <linux/slab.h> 45#include <linux/slab.h>
47#include <linux/string.h> 46#include <linux/string.h>
@@ -185,7 +184,6 @@ struct snd_usb_substream {
185 unsigned int num_formats; /* number of supported audio formats (list) */ 184 unsigned int num_formats; /* number of supported audio formats (list) */
186 struct list_head fmt_list; /* format list */ 185 struct list_head fmt_list; /* format list */
187 spinlock_t lock; 186 spinlock_t lock;
188 struct tasklet_struct start_period_elapsed; /* for start trigger */
189 187
190 struct snd_urb_ops ops; /* callbacks (must be filled at init) */ 188 struct snd_urb_ops ops; /* callbacks (must be filled at init) */
191}; 189};
@@ -480,6 +478,28 @@ static int retire_playback_sync_urb_hs(snd_usb_substream_t *subs,
480} 478}
481 479
482/* 480/*
481 * Prepare urb for streaming before playback starts.
482 *
483 * We don't care about (or have) any data, so we just send a transfer delimiter.
484 */
485static int prepare_startup_playback_urb(snd_usb_substream_t *subs,
486 snd_pcm_runtime_t *runtime,
487 struct urb *urb)
488{
489 unsigned int i;
490 snd_urb_ctx_t *ctx = urb->context;
491
492 urb->dev = ctx->subs->dev;
493 urb->number_of_packets = subs->packs_per_ms;
494 for (i = 0; i < subs->packs_per_ms; ++i) {
495 urb->iso_frame_desc[i].offset = 0;
496 urb->iso_frame_desc[i].length = 0;
497 }
498 urb->transfer_buffer_length = 0;
499 return 0;
500}
501
502/*
483 * prepare urb for playback data pipe 503 * prepare urb for playback data pipe
484 * 504 *
485 * Since a URB can handle only a single linear buffer, we must use double 505 * Since a URB can handle only a single linear buffer, we must use double
@@ -568,12 +588,8 @@ static int prepare_playback_urb(snd_usb_substream_t *subs,
568 subs->hwptr_done -= runtime->buffer_size; 588 subs->hwptr_done -= runtime->buffer_size;
569 spin_unlock_irqrestore(&subs->lock, flags); 589 spin_unlock_irqrestore(&subs->lock, flags);
570 urb->transfer_buffer_length = offs * stride; 590 urb->transfer_buffer_length = offs * stride;
571 if (period_elapsed) { 591 if (period_elapsed)
572 if (likely(subs->running)) 592 snd_pcm_period_elapsed(subs->pcm_substream);
573 snd_pcm_period_elapsed(subs->pcm_substream);
574 else
575 tasklet_hi_schedule(&subs->start_period_elapsed);
576 }
577 return 0; 593 return 0;
578} 594}
579 595
@@ -588,22 +604,12 @@ static int retire_playback_urb(snd_usb_substream_t *subs,
588 return 0; 604 return 0;
589} 605}
590 606
591/*
592 * Delay the snd_pcm_period_elapsed() call until after the start trigger
593 * callback so that we're not longer in the substream's lock.
594 */
595static void start_period_elapsed(unsigned long data)
596{
597 snd_usb_substream_t *subs = (snd_usb_substream_t *)data;
598 snd_pcm_period_elapsed(subs->pcm_substream);
599}
600
601 607
602/* 608/*
603 */ 609 */
604static struct snd_urb_ops audio_urb_ops[2] = { 610static struct snd_urb_ops audio_urb_ops[2] = {
605 { 611 {
606 .prepare = prepare_playback_urb, 612 .prepare = prepare_startup_playback_urb,
607 .retire = retire_playback_urb, 613 .retire = retire_playback_urb,
608 .prepare_sync = prepare_playback_sync_urb, 614 .prepare_sync = prepare_playback_sync_urb,
609 .retire_sync = retire_playback_sync_urb, 615 .retire_sync = retire_playback_sync_urb,
@@ -618,7 +624,7 @@ static struct snd_urb_ops audio_urb_ops[2] = {
618 624
619static struct snd_urb_ops audio_urb_ops_high_speed[2] = { 625static struct snd_urb_ops audio_urb_ops_high_speed[2] = {
620 { 626 {
621 .prepare = prepare_playback_urb, 627 .prepare = prepare_startup_playback_urb,
622 .retire = retire_playback_urb, 628 .retire = retire_playback_urb,
623 .prepare_sync = prepare_playback_sync_urb_hs, 629 .prepare_sync = prepare_playback_sync_urb_hs,
624 .retire_sync = retire_playback_sync_urb_hs, 630 .retire_sync = retire_playback_sync_urb_hs,
@@ -692,9 +698,9 @@ static int snd_pcm_alloc_vmalloc_buffer(snd_pcm_substream_t *subs, size_t size)
692 if (runtime->dma_area) { 698 if (runtime->dma_area) {
693 if (runtime->dma_bytes >= size) 699 if (runtime->dma_bytes >= size)
694 return 0; /* already large enough */ 700 return 0; /* already large enough */
695 vfree_nocheck(runtime->dma_area); 701 vfree(runtime->dma_area);
696 } 702 }
697 runtime->dma_area = vmalloc_nocheck(size); 703 runtime->dma_area = vmalloc(size);
698 if (! runtime->dma_area) 704 if (! runtime->dma_area)
699 return -ENOMEM; 705 return -ENOMEM;
700 runtime->dma_bytes = size; 706 runtime->dma_bytes = size;
@@ -706,7 +712,7 @@ static int snd_pcm_free_vmalloc_buffer(snd_pcm_substream_t *subs)
706{ 712{
707 snd_pcm_runtime_t *runtime = subs->runtime; 713 snd_pcm_runtime_t *runtime = subs->runtime;
708 if (runtime->dma_area) { 714 if (runtime->dma_area) {
709 vfree_nocheck(runtime->dma_area); 715 vfree(runtime->dma_area);
710 runtime->dma_area = NULL; 716 runtime->dma_area = NULL;
711 } 717 }
712 return 0; 718 return 0;
@@ -838,8 +844,7 @@ static int wait_clear_urbs(snd_usb_substream_t *subs)
838 } 844 }
839 if (! alive) 845 if (! alive)
840 break; 846 break;
841 set_current_state(TASK_UNINTERRUPTIBLE); 847 schedule_timeout_uninterruptible(1);
842 schedule_timeout(1);
843 } while (time_before(jiffies, end_time)); 848 } while (time_before(jiffies, end_time));
844 if (alive) 849 if (alive)
845 snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive); 850 snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive);
@@ -864,25 +869,40 @@ static snd_pcm_uframes_t snd_usb_pcm_pointer(snd_pcm_substream_t *substream)
864 869
865 870
866/* 871/*
867 * start/stop substream 872 * start/stop playback substream
868 */ 873 */
869static int snd_usb_pcm_trigger(snd_pcm_substream_t *substream, int cmd) 874static int snd_usb_pcm_playback_trigger(snd_pcm_substream_t *substream,
875 int cmd)
870{ 876{
871 snd_usb_substream_t *subs = (snd_usb_substream_t *)substream->runtime->private_data; 877 snd_usb_substream_t *subs = substream->runtime->private_data;
872 int err;
873 878
874 switch (cmd) { 879 switch (cmd) {
875 case SNDRV_PCM_TRIGGER_START: 880 case SNDRV_PCM_TRIGGER_START:
876 err = start_urbs(subs, substream->runtime); 881 subs->ops.prepare = prepare_playback_urb;
877 break; 882 return 0;
878 case SNDRV_PCM_TRIGGER_STOP: 883 case SNDRV_PCM_TRIGGER_STOP:
879 err = deactivate_urbs(subs, 0, 0); 884 return deactivate_urbs(subs, 0, 0);
880 break;
881 default: 885 default:
882 err = -EINVAL; 886 return -EINVAL;
883 break; 887 }
888}
889
890/*
891 * start/stop capture substream
892 */
893static int snd_usb_pcm_capture_trigger(snd_pcm_substream_t *substream,
894 int cmd)
895{
896 snd_usb_substream_t *subs = substream->runtime->private_data;
897
898 switch (cmd) {
899 case SNDRV_PCM_TRIGGER_START:
900 return start_urbs(subs, substream->runtime);
901 case SNDRV_PCM_TRIGGER_STOP:
902 return deactivate_urbs(subs, 0, 0);
903 default:
904 return -EINVAL;
884 } 905 }
885 return err < 0 ? err : 0;
886} 906}
887 907
888 908
@@ -1044,7 +1064,7 @@ static int init_substream_urbs(snd_usb_substream_t *subs, unsigned int period_by
1044 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 1064 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
1045 u->urb->interval = 1 << subs->datainterval; 1065 u->urb->interval = 1 << subs->datainterval;
1046 u->urb->context = u; 1066 u->urb->context = u;
1047 u->urb->complete = snd_usb_complete_callback(snd_complete_urb); 1067 u->urb->complete = snd_complete_urb;
1048 } 1068 }
1049 1069
1050 if (subs->syncpipe) { 1070 if (subs->syncpipe) {
@@ -1070,7 +1090,7 @@ static int init_substream_urbs(snd_usb_substream_t *subs, unsigned int period_by
1070 u->urb->number_of_packets = 1; 1090 u->urb->number_of_packets = 1;
1071 u->urb->interval = 1 << subs->syncinterval; 1091 u->urb->interval = 1 << subs->syncinterval;
1072 u->urb->context = u; 1092 u->urb->context = u;
1073 u->urb->complete = snd_usb_complete_callback(snd_complete_sync_urb); 1093 u->urb->complete = snd_complete_sync_urb;
1074 } 1094 }
1075 } 1095 }
1076 return 0; 1096 return 0;
@@ -1414,7 +1434,7 @@ static int snd_usb_hw_free(snd_pcm_substream_t *substream)
1414static int snd_usb_pcm_prepare(snd_pcm_substream_t *substream) 1434static int snd_usb_pcm_prepare(snd_pcm_substream_t *substream)
1415{ 1435{
1416 snd_pcm_runtime_t *runtime = substream->runtime; 1436 snd_pcm_runtime_t *runtime = substream->runtime;
1417 snd_usb_substream_t *subs = (snd_usb_substream_t *)runtime->private_data; 1437 snd_usb_substream_t *subs = runtime->private_data;
1418 1438
1419 if (! subs->cur_audiofmt) { 1439 if (! subs->cur_audiofmt) {
1420 snd_printk(KERN_ERR "usbaudio: no format is specified!\n"); 1440 snd_printk(KERN_ERR "usbaudio: no format is specified!\n");
@@ -1434,7 +1454,13 @@ static int snd_usb_pcm_prepare(snd_pcm_substream_t *substream)
1434 deactivate_urbs(subs, 0, 1); 1454 deactivate_urbs(subs, 0, 1);
1435 wait_clear_urbs(subs); 1455 wait_clear_urbs(subs);
1436 1456
1437 return 0; 1457 /* for playback, submit the URBs now; otherwise, the first hwptr_done
1458 * updates for all URBs would happen at the same time when starting */
1459 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
1460 subs->ops.prepare = prepare_startup_playback_urb;
1461 return start_urbs(subs, runtime);
1462 } else
1463 return 0;
1438} 1464}
1439 1465
1440static snd_pcm_hardware_t snd_usb_playback = 1466static snd_pcm_hardware_t snd_usb_playback =
@@ -1848,7 +1874,7 @@ static snd_pcm_ops_t snd_usb_playback_ops = {
1848 .hw_params = snd_usb_hw_params, 1874 .hw_params = snd_usb_hw_params,
1849 .hw_free = snd_usb_hw_free, 1875 .hw_free = snd_usb_hw_free,
1850 .prepare = snd_usb_pcm_prepare, 1876 .prepare = snd_usb_pcm_prepare,
1851 .trigger = snd_usb_pcm_trigger, 1877 .trigger = snd_usb_pcm_playback_trigger,
1852 .pointer = snd_usb_pcm_pointer, 1878 .pointer = snd_usb_pcm_pointer,
1853 .page = snd_pcm_get_vmalloc_page, 1879 .page = snd_pcm_get_vmalloc_page,
1854}; 1880};
@@ -1860,7 +1886,7 @@ static snd_pcm_ops_t snd_usb_capture_ops = {
1860 .hw_params = snd_usb_hw_params, 1886 .hw_params = snd_usb_hw_params,
1861 .hw_free = snd_usb_hw_free, 1887 .hw_free = snd_usb_hw_free,
1862 .prepare = snd_usb_pcm_prepare, 1888 .prepare = snd_usb_pcm_prepare,
1863 .trigger = snd_usb_pcm_trigger, 1889 .trigger = snd_usb_pcm_capture_trigger,
1864 .pointer = snd_usb_pcm_pointer, 1890 .pointer = snd_usb_pcm_pointer,
1865 .page = snd_pcm_get_vmalloc_page, 1891 .page = snd_pcm_get_vmalloc_page,
1866}; 1892};
@@ -2079,9 +2105,6 @@ static void init_substream(snd_usb_stream_t *as, int stream, struct audioformat
2079 2105
2080 INIT_LIST_HEAD(&subs->fmt_list); 2106 INIT_LIST_HEAD(&subs->fmt_list);
2081 spin_lock_init(&subs->lock); 2107 spin_lock_init(&subs->lock);
2082 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
2083 tasklet_init(&subs->start_period_elapsed, start_period_elapsed,
2084 (unsigned long)subs);
2085 2108
2086 subs->stream = as; 2109 subs->stream = as;
2087 subs->direction = stream; 2110 subs->direction = stream;
@@ -2755,9 +2778,9 @@ static int create_fixed_stream_quirk(snd_usb_audio_t *chip,
2755/* 2778/*
2756 * create a stream for an interface with proper descriptors 2779 * create a stream for an interface with proper descriptors
2757 */ 2780 */
2758static int create_standard_interface_quirk(snd_usb_audio_t *chip, 2781static int create_standard_audio_quirk(snd_usb_audio_t *chip,
2759 struct usb_interface *iface, 2782 struct usb_interface *iface,
2760 const snd_usb_audio_quirk_t *quirk) 2783 const snd_usb_audio_quirk_t *quirk)
2761{ 2784{
2762 struct usb_host_interface *alts; 2785 struct usb_host_interface *alts;
2763 struct usb_interface_descriptor *altsd; 2786 struct usb_interface_descriptor *altsd;
@@ -2765,24 +2788,14 @@ static int create_standard_interface_quirk(snd_usb_audio_t *chip,
2765 2788
2766 alts = &iface->altsetting[0]; 2789 alts = &iface->altsetting[0];
2767 altsd = get_iface_desc(alts); 2790 altsd = get_iface_desc(alts);
2768 switch (quirk->type) { 2791 err = parse_audio_endpoints(chip, altsd->bInterfaceNumber);
2769 case QUIRK_AUDIO_STANDARD_INTERFACE:
2770 err = parse_audio_endpoints(chip, altsd->bInterfaceNumber);
2771 if (!err)
2772 usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0); /* reset the current interface */
2773 break;
2774 case QUIRK_MIDI_STANDARD_INTERFACE:
2775 err = snd_usb_create_midi_interface(chip, iface, NULL);
2776 break;
2777 default:
2778 snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
2779 return -ENXIO;
2780 }
2781 if (err < 0) { 2792 if (err < 0) {
2782 snd_printk(KERN_ERR "cannot setup if %d: error %d\n", 2793 snd_printk(KERN_ERR "cannot setup if %d: error %d\n",
2783 altsd->bInterfaceNumber, err); 2794 altsd->bInterfaceNumber, err);
2784 return err; 2795 return err;
2785 } 2796 }
2797 /* reset the current interface */
2798 usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0);
2786 return 0; 2799 return 0;
2787} 2800}
2788 2801
@@ -3044,7 +3057,7 @@ static int snd_usb_create_quirk(snd_usb_audio_t *chip,
3044 [QUIRK_MIDI_RAW] = snd_usb_create_midi_interface, 3057 [QUIRK_MIDI_RAW] = snd_usb_create_midi_interface,
3045 [QUIRK_MIDI_EMAGIC] = snd_usb_create_midi_interface, 3058 [QUIRK_MIDI_EMAGIC] = snd_usb_create_midi_interface,
3046 [QUIRK_MIDI_MIDITECH] = snd_usb_create_midi_interface, 3059 [QUIRK_MIDI_MIDITECH] = snd_usb_create_midi_interface,
3047 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_interface_quirk, 3060 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
3048 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, 3061 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
3049 [QUIRK_AUDIO_EDIROL_UA700_UA25] = create_ua700_ua25_quirk, 3062 [QUIRK_AUDIO_EDIROL_UA700_UA25] = create_ua700_ua25_quirk,
3050 [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk, 3063 [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk,
@@ -3222,7 +3235,6 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3222 struct usb_interface *intf, 3235 struct usb_interface *intf,
3223 const struct usb_device_id *usb_id) 3236 const struct usb_device_id *usb_id)
3224{ 3237{
3225 struct usb_host_config *config = dev->actconfig;
3226 const snd_usb_audio_quirk_t *quirk = (const snd_usb_audio_quirk_t *)usb_id->driver_info; 3238 const snd_usb_audio_quirk_t *quirk = (const snd_usb_audio_quirk_t *)usb_id->driver_info;
3227 int i, err; 3239 int i, err;
3228 snd_usb_audio_t *chip; 3240 snd_usb_audio_t *chip;
@@ -3243,7 +3255,6 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3243 if (id == USB_ID(0x041e, 0x3000)) { 3255 if (id == USB_ID(0x041e, 0x3000)) {
3244 if (snd_usb_extigy_boot_quirk(dev, intf) < 0) 3256 if (snd_usb_extigy_boot_quirk(dev, intf) < 0)
3245 goto __err_val; 3257 goto __err_val;
3246 config = dev->actconfig;
3247 } 3258 }
3248 /* SB Audigy 2 NX needs its own boot-up magic, too */ 3259 /* SB Audigy 2 NX needs its own boot-up magic, too */
3249 if (id == USB_ID(0x041e, 0x3020)) { 3260 if (id == USB_ID(0x041e, 0x3020)) {
@@ -3272,11 +3283,6 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3272 /* it's a fresh one. 3283 /* it's a fresh one.
3273 * now look for an empty slot and create a new card instance 3284 * now look for an empty slot and create a new card instance
3274 */ 3285 */
3275 /* first, set the current configuration for this device */
3276 if (usb_reset_configuration(dev) < 0) {
3277 snd_printk(KERN_ERR "cannot reset configuration (value 0x%x)\n", get_cfg_desc(config)->bConfigurationValue);
3278 goto __error;
3279 }
3280 for (i = 0; i < SNDRV_CARDS; i++) 3286 for (i = 0; i < SNDRV_CARDS; i++)
3281 if (enable[i] && ! usb_chip[i] && 3287 if (enable[i] && ! usb_chip[i] &&
3282 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) && 3288 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index ad9eab211d8f..b5802022bb19 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -249,14 +249,6 @@ void snd_usbmidi_disconnect(struct list_head *p);
249#define get_cfg_desc(cfg) (&(cfg)->desc) 249#define get_cfg_desc(cfg) (&(cfg)->desc)
250#endif 250#endif
251 251
252#ifndef usb_pipe_needs_resubmit
253#define usb_pipe_needs_resubmit(pipe) 1
254#endif
255
256#ifndef snd_usb_complete_callback
257#define snd_usb_complete_callback(x) (x)
258#endif
259
260#ifndef snd_usb_get_speed 252#ifndef snd_usb_get_speed
261#define snd_usb_get_speed(dev) ((dev)->speed) 253#define snd_usb_get_speed(dev) ((dev)->speed)
262#endif 254#endif
diff --git a/sound/usb/usbmidi.c b/sound/usb/usbmidi.c
index f1a2e2c2e02f..f8aa662562a0 100644
--- a/sound/usb/usbmidi.c
+++ b/sound/usb/usbmidi.c
@@ -47,7 +47,6 @@
47#include <linux/timer.h> 47#include <linux/timer.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <sound/core.h> 49#include <sound/core.h>
50#include <sound/minors.h>
51#include <sound/rawmidi.h> 50#include <sound/rawmidi.h>
52#include "usbaudio.h" 51#include "usbaudio.h"
53 52
@@ -246,10 +245,8 @@ static void snd_usbmidi_in_urb_complete(struct urb* urb, struct pt_regs *regs)
246 } 245 }
247 } 246 }
248 247
249 if (usb_pipe_needs_resubmit(urb->pipe)) { 248 urb->dev = ep->umidi->chip->dev;
250 urb->dev = ep->umidi->chip->dev; 249 snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
251 snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
252 }
253} 250}
254 251
255static void snd_usbmidi_out_urb_complete(struct urb* urb, struct pt_regs *regs) 252static void snd_usbmidi_out_urb_complete(struct urb* urb, struct pt_regs *regs)
@@ -863,13 +860,12 @@ static int snd_usbmidi_in_endpoint_create(snd_usb_midi_t* umidi,
863 return -ENOMEM; 860 return -ENOMEM;
864 } 861 }
865 if (ep_info->in_interval) 862 if (ep_info->in_interval)
866 usb_fill_int_urb(ep->urb, umidi->chip->dev, pipe, buffer, length, 863 usb_fill_int_urb(ep->urb, umidi->chip->dev, pipe, buffer,
867 snd_usb_complete_callback(snd_usbmidi_in_urb_complete), 864 length, snd_usbmidi_in_urb_complete, ep,
868 ep, ep_info->in_interval); 865 ep_info->in_interval);
869 else 866 else
870 usb_fill_bulk_urb(ep->urb, umidi->chip->dev, pipe, buffer, length, 867 usb_fill_bulk_urb(ep->urb, umidi->chip->dev, pipe, buffer,
871 snd_usb_complete_callback(snd_usbmidi_in_urb_complete), 868 length, snd_usbmidi_in_urb_complete, ep);
872 ep);
873 ep->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 869 ep->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
874 870
875 rep->in = ep; 871 rep->in = ep;
@@ -933,8 +929,7 @@ static int snd_usbmidi_out_endpoint_create(snd_usb_midi_t* umidi,
933 return -ENOMEM; 929 return -ENOMEM;
934 } 930 }
935 usb_fill_bulk_urb(ep->urb, umidi->chip->dev, pipe, buffer, 931 usb_fill_bulk_urb(ep->urb, umidi->chip->dev, pipe, buffer,
936 ep->max_transfer, 932 ep->max_transfer, snd_usbmidi_out_urb_complete, ep);
937 snd_usb_complete_callback(snd_usbmidi_out_urb_complete), ep);
938 ep->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 933 ep->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
939 934
940 spin_lock_init(&ep->buffer_lock); 935 spin_lock_init(&ep->buffer_lock);
@@ -1550,46 +1545,45 @@ int snd_usb_create_midi_interface(snd_usb_audio_t* chip,
1550 1545
1551 /* detect the endpoint(s) to use */ 1546 /* detect the endpoint(s) to use */
1552 memset(endpoints, 0, sizeof(endpoints)); 1547 memset(endpoints, 0, sizeof(endpoints));
1553 if (!quirk) { 1548 switch (quirk ? quirk->type : QUIRK_MIDI_STANDARD_INTERFACE) {
1549 case QUIRK_MIDI_STANDARD_INTERFACE:
1554 err = snd_usbmidi_get_ms_info(umidi, endpoints); 1550 err = snd_usbmidi_get_ms_info(umidi, endpoints);
1555 } else { 1551 break;
1556 switch (quirk->type) { 1552 case QUIRK_MIDI_FIXED_ENDPOINT:
1557 case QUIRK_MIDI_FIXED_ENDPOINT: 1553 memcpy(&endpoints[0], quirk->data,
1558 memcpy(&endpoints[0], quirk->data, 1554 sizeof(snd_usb_midi_endpoint_info_t));
1559 sizeof(snd_usb_midi_endpoint_info_t)); 1555 err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
1560 err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1); 1556 break;
1561 break; 1557 case QUIRK_MIDI_YAMAHA:
1562 case QUIRK_MIDI_YAMAHA: 1558 err = snd_usbmidi_detect_yamaha(umidi, &endpoints[0]);
1563 err = snd_usbmidi_detect_yamaha(umidi, &endpoints[0]); 1559 break;
1564 break; 1560 case QUIRK_MIDI_MIDIMAN:
1565 case QUIRK_MIDI_MIDIMAN: 1561 umidi->usb_protocol_ops = &snd_usbmidi_midiman_ops;
1566 umidi->usb_protocol_ops = &snd_usbmidi_midiman_ops; 1562 memcpy(&endpoints[0], quirk->data,
1567 memcpy(&endpoints[0], quirk->data, 1563 sizeof(snd_usb_midi_endpoint_info_t));
1568 sizeof(snd_usb_midi_endpoint_info_t)); 1564 err = 0;
1569 err = 0; 1565 break;
1570 break; 1566 case QUIRK_MIDI_NOVATION:
1571 case QUIRK_MIDI_NOVATION: 1567 umidi->usb_protocol_ops = &snd_usbmidi_novation_ops;
1572 umidi->usb_protocol_ops = &snd_usbmidi_novation_ops; 1568 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
1573 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints); 1569 break;
1574 break; 1570 case QUIRK_MIDI_RAW:
1575 case QUIRK_MIDI_RAW: 1571 umidi->usb_protocol_ops = &snd_usbmidi_raw_ops;
1576 umidi->usb_protocol_ops = &snd_usbmidi_raw_ops; 1572 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
1577 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints); 1573 break;
1578 break; 1574 case QUIRK_MIDI_EMAGIC:
1579 case QUIRK_MIDI_EMAGIC: 1575 umidi->usb_protocol_ops = &snd_usbmidi_emagic_ops;
1580 umidi->usb_protocol_ops = &snd_usbmidi_emagic_ops; 1576 memcpy(&endpoints[0], quirk->data,
1581 memcpy(&endpoints[0], quirk->data, 1577 sizeof(snd_usb_midi_endpoint_info_t));
1582 sizeof(snd_usb_midi_endpoint_info_t)); 1578 err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1);
1583 err = snd_usbmidi_detect_endpoints(umidi, &endpoints[0], 1); 1579 break;
1584 break; 1580 case QUIRK_MIDI_MIDITECH:
1585 case QUIRK_MIDI_MIDITECH: 1581 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
1586 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints); 1582 break;
1587 break; 1583 default:
1588 default: 1584 snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
1589 snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type); 1585 err = -ENXIO;
1590 err = -ENXIO; 1586 break;
1591 break;
1592 }
1593 } 1587 }
1594 if (err < 0) { 1588 if (err < 0) {
1595 kfree(umidi); 1589 kfree(umidi);
diff --git a/sound/usb/usbmixer.c b/sound/usb/usbmixer.c
index c3c08c9cb46e..e570d140258d 100644
--- a/sound/usb/usbmixer.c
+++ b/sound/usb/usbmixer.c
@@ -911,7 +911,7 @@ static void build_feature_ctl(mixer_build_t *state, unsigned char *desc,
911 case USB_ID(0x0672, 0x1041): 911 case USB_ID(0x0672, 0x1041):
912 if (!strcmp(kctl->id.name, "PCM Playback Volume") && 912 if (!strcmp(kctl->id.name, "PCM Playback Volume") &&
913 cval->min == -15616) { 913 cval->min == -15616) {
914 snd_printk("using volume control quirk for the UDA1321/N101 chip\n"); 914 snd_printk(KERN_INFO "using volume control quirk for the UDA1321/N101 chip\n");
915 cval->max = -256; 915 cval->max = -256;
916 } 916 }
917 } 917 }
diff --git a/sound/usb/usbquirks.h b/sound/usb/usbquirks.h
index 948759da6563..ba506c3871f4 100644
--- a/sound/usb/usbquirks.h
+++ b/sound/usb/usbquirks.h
@@ -294,6 +294,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
294 } 294 }
295}, 295},
296{ 296{
297 /* a later revision uses ID 0x0099 */
297 USB_DEVICE(0x0582, 0x0005), 298 USB_DEVICE(0x0582, 0x0005),
298 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 299 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
299 .vendor_name = "EDIROL", 300 .vendor_name = "EDIROL",
@@ -384,6 +385,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
384 } 385 }
385}, 386},
386{ 387{
388 /* a later revision uses ID 0x009d */
387 USB_DEVICE(0x0582, 0x0009), 389 USB_DEVICE(0x0582, 0x0009),
388 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 390 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
389 .vendor_name = "EDIROL", 391 .vendor_name = "EDIROL",
@@ -532,6 +534,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
532 } 534 }
533}, 535},
534{ 536{
537 /* has ID 0x0013 when not in "Advanced Driver" mode */
535 USB_DEVICE(0x0582, 0x0012), 538 USB_DEVICE(0x0582, 0x0012),
536 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 539 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
537 .vendor_name = "Roland", 540 .vendor_name = "Roland",
@@ -545,6 +548,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
545 } 548 }
546}, 549},
547{ 550{
551 /* has ID 0x0015 when not in "Advanced Driver" mode */
548 USB_DEVICE(0x0582, 0x0014), 552 USB_DEVICE(0x0582, 0x0014),
549 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 553 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
550 .vendor_name = "EDIROL", 554 .vendor_name = "EDIROL",
@@ -558,6 +562,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
558 } 562 }
559}, 563},
560{ 564{
565 /* has ID 0x0017 when not in "Advanced Driver" mode */
561 USB_DEVICE(0x0582, 0x0016), 566 USB_DEVICE(0x0582, 0x0016),
562 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 567 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
563 .vendor_name = "EDIROL", 568 .vendor_name = "EDIROL",
@@ -588,6 +593,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
588 } 593 }
589}, 594},
590{ 595{
596 /* has ID 0x001c when not in "Advanced Driver" mode */
591 USB_DEVICE(0x0582, 0x001b), 597 USB_DEVICE(0x0582, 0x001b),
592 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 598 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
593 .vendor_name = "Roland", 599 .vendor_name = "Roland",
@@ -618,6 +624,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
618 } 624 }
619}, 625},
620{ 626{
627 /* has ID 0x001e when not in "Advanced Driver" mode */
621 USB_DEVICE(0x0582, 0x001d), 628 USB_DEVICE(0x0582, 0x001d),
622 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 629 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
623 .vendor_name = "Roland", 630 .vendor_name = "Roland",
@@ -631,6 +638,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
631 } 638 }
632}, 639},
633{ 640{
641 /* has ID 0x0024 when not in "Advanced Driver" mode */
634 USB_DEVICE(0x0582, 0x0023), 642 USB_DEVICE(0x0582, 0x0023),
635 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 643 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
636 .vendor_name = "EDIROL", 644 .vendor_name = "EDIROL",
@@ -675,6 +683,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
675 } 683 }
676}, 684},
677{ 685{
686 /* has ID 0x0028 when not in "Advanced Driver" mode */
678 USB_DEVICE(0x0582, 0x0027), 687 USB_DEVICE(0x0582, 0x0027),
679 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 688 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
680 .vendor_name = "EDIROL", 689 .vendor_name = "EDIROL",
@@ -688,6 +697,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
688 } 697 }
689}, 698},
690{ 699{
700 /* has ID 0x002a when not in "Advanced Driver" mode */
691 USB_DEVICE(0x0582, 0x0029), 701 USB_DEVICE(0x0582, 0x0029),
692 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 702 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
693 .vendor_name = "EDIROL", 703 .vendor_name = "EDIROL",
@@ -732,6 +742,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
732 } 742 }
733}, 743},
734{ 744{
745 /* has ID 0x002e when not in "Advanced Driver" mode */
735 USB_DEVICE(0x0582, 0x002d), 746 USB_DEVICE(0x0582, 0x002d),
736 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 747 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
737 .vendor_name = "Roland", 748 .vendor_name = "Roland",
@@ -745,6 +756,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
745 } 756 }
746}, 757},
747{ 758{
759 /* has ID 0x0030 when not in "Advanced Driver" mode */
748 USB_DEVICE(0x0582, 0x002f), 760 USB_DEVICE(0x0582, 0x002f),
749 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 761 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
750 .vendor_name = "Roland", 762 .vendor_name = "Roland",
@@ -758,6 +770,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
758 } 770 }
759}, 771},
760{ 772{
773 /* has ID 0x0034 when not in "Advanced Driver" mode */
761 USB_DEVICE(0x0582, 0x0033), 774 USB_DEVICE(0x0582, 0x0033),
762 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 775 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
763 .vendor_name = "EDIROL", 776 .vendor_name = "EDIROL",
@@ -770,7 +783,12 @@ YAMAHA_DEVICE(0x7010, "UB99"),
770 } 783 }
771 } 784 }
772}, 785},
786 /* TODO: add Roland M-1000 support */
773{ 787{
788 /*
789 * Has ID 0x0038 when not in "Advanced Driver" mode;
790 * later revisions use IDs 0x0054 and 0x00a2.
791 */
774 USB_DEVICE(0x0582, 0x0037), 792 USB_DEVICE(0x0582, 0x0037),
775 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 793 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
776 .vendor_name = "Roland", 794 .vendor_name = "Roland",
@@ -815,6 +833,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
815 } 833 }
816}, 834},
817{ 835{
836 /* has ID 0x0041 when not in "Advanced Driver" mode */
818 USB_DEVICE(0x0582, 0x0040), 837 USB_DEVICE(0x0582, 0x0040),
819 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 838 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
820 .vendor_name = "Roland", 839 .vendor_name = "Roland",
@@ -828,6 +847,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
828 } 847 }
829}, 848},
830{ 849{
850 /* has ID 0x0043 when not in "Advanced Driver" mode */
831 USB_DEVICE(0x0582, 0x0042), 851 USB_DEVICE(0x0582, 0x0042),
832 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 852 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
833 .vendor_name = "Roland", 853 .vendor_name = "Roland",
@@ -871,6 +891,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
871 } 891 }
872}, 892},
873{ 893{
894 /* has ID 0x004a when not in "Advanced Driver" mode */
874 USB_DEVICE(0x0582, 0x0048), 895 USB_DEVICE(0x0582, 0x0048),
875 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 896 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
876 .vendor_name = "EDIROL", 897 .vendor_name = "EDIROL",
@@ -883,7 +904,9 @@ YAMAHA_DEVICE(0x7010, "UB99"),
883 } 904 }
884 } 905 }
885}, 906},
907 /* TODO: add Edirol M-100FX support */
886{ 908{
909 /* has ID 0x004f when not in "Advanced Driver" mode */
887 USB_DEVICE(0x0582, 0x004d), 910 USB_DEVICE(0x0582, 0x004d),
888 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 911 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
889 .vendor_name = "EDIROL", 912 .vendor_name = "EDIROL",
@@ -931,7 +954,9 @@ YAMAHA_DEVICE(0x7010, "UB99"),
931 .type = QUIRK_MIDI_STANDARD_INTERFACE 954 .type = QUIRK_MIDI_STANDARD_INTERFACE
932 } 955 }
933}, 956},
957 /* TODO: add Roland EXR support */
934{ 958{
959 /* has ID 0x0067 when not in "Advanced Driver" mode */
935 USB_DEVICE(0x0582, 0x0065), 960 USB_DEVICE(0x0582, 0x0065),
936 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 961 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
937 .vendor_name = "EDIROL", 962 .vendor_name = "EDIROL",
@@ -945,6 +970,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
945 } 970 }
946}, 971},
947{ 972{
973 /* has ID 0x006b when not in "Advanced Driver" mode */
948 USB_DEVICE_VENDOR_SPEC(0x0582, 0x006a), 974 USB_DEVICE_VENDOR_SPEC(0x0582, 0x006a),
949 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 975 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
950 .vendor_name = "Roland", 976 .vendor_name = "Roland",
@@ -958,6 +984,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
958 } 984 }
959}, 985},
960{ 986{
987 /* has ID 0x006e when not in "Advanced Driver" mode */
961 USB_DEVICE(0x0582, 0x006d), 988 USB_DEVICE(0x0582, 0x006d),
962 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 989 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
963 .vendor_name = "Roland", 990 .vendor_name = "Roland",
@@ -1002,6 +1029,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1002 } 1029 }
1003}, 1030},
1004{ 1031{
1032 /* has ID 0x0076 when not in "Advanced Driver" mode */
1005 USB_DEVICE(0x0582, 0x0075), 1033 USB_DEVICE(0x0582, 0x0075),
1006 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 1034 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
1007 .vendor_name = "BOSS", 1035 .vendor_name = "BOSS",
@@ -1015,10 +1043,11 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1015 } 1043 }
1016}, 1044},
1017{ 1045{
1046 /* has ID 0x007b when not in "Advanced Driver" mode */
1018 USB_DEVICE_VENDOR_SPEC(0x0582, 0x007a), 1047 USB_DEVICE_VENDOR_SPEC(0x0582, 0x007a),
1019 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) { 1048 .driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
1020 .vendor_name = "Roland", 1049 .vendor_name = "Roland",
1021 /* RD-700SX, RD-300SX */ 1050 /* "RD" or "RD-700SX"? */
1022 .ifnum = 0, 1051 .ifnum = 0,
1023 .type = QUIRK_MIDI_FIXED_ENDPOINT, 1052 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1024 .data = & (const snd_usb_midi_endpoint_info_t) { 1053 .data = & (const snd_usb_midi_endpoint_info_t) {
@@ -1048,6 +1077,15 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1048 } 1077 }
1049 } 1078 }
1050}, 1079},
1080 /* TODO: add Edirol UA-101 support */
1081 /* TODO: add Roland G-70 support */
1082 /* TODO: add Roland V-SYNTH XT support */
1083 /* TODO: add BOSS GT-PRO support */
1084 /* TODO: add Edirol PC-50 support */
1085 /* TODO: add Edirol PC-80 support */
1086 /* TODO: add Edirol UA-1EX support */
1087 /* TODO: add Edirol UM-3 support */
1088 /* TODO: add Edirol MD-P1 support */
1051 1089
1052/* Midiman/M-Audio devices */ 1090/* Midiman/M-Audio devices */
1053{ 1091{
diff --git a/sound/usb/usx2y/usX2Yhwdep.c b/sound/usb/usx2y/usX2Yhwdep.c
index 0281a362857a..8abe08611df6 100644
--- a/sound/usb/usx2y/usX2Yhwdep.c
+++ b/sound/usb/usx2y/usX2Yhwdep.c
@@ -193,7 +193,7 @@ static int usX2Y_create_alsa_devices(snd_card_t* card)
193 193
194 do { 194 do {
195 if ((err = usX2Y_create_usbmidi(card)) < 0) { 195 if ((err = usX2Y_create_usbmidi(card)) < 0) {
196 snd_printk("usX2Y_create_alsa_devices: usX2Y_create_usbmidi error %i \n", err); 196 snd_printk(KERN_ERR "usX2Y_create_alsa_devices: usX2Y_create_usbmidi error %i \n", err);
197 break; 197 break;
198 } 198 }
199 if ((err = usX2Y_audio_create(card)) < 0) 199 if ((err = usX2Y_audio_create(card)) < 0)
@@ -224,7 +224,7 @@ static int snd_usX2Y_hwdep_dsp_load(snd_hwdep_t *hw, snd_hwdep_dsp_image_t *dsp)
224 } 224 }
225 err = usb_set_interface(dev, 0, 1); 225 err = usb_set_interface(dev, 0, 1);
226 if (err) 226 if (err)
227 snd_printk("usb_set_interface error \n"); 227 snd_printk(KERN_ERR "usb_set_interface error \n");
228 else 228 else
229 err = usb_bulk_msg(dev, usb_sndbulkpipe(dev, 2), buf, dsp->length, &lret, 6000); 229 err = usb_bulk_msg(dev, usb_sndbulkpipe(dev, 2), buf, dsp->length, &lret, 6000);
230 kfree(buf); 230 kfree(buf);
@@ -235,17 +235,17 @@ static int snd_usX2Y_hwdep_dsp_load(snd_hwdep_t *hw, snd_hwdep_dsp_image_t *dsp)
235 msleep(250); // give the device some time 235 msleep(250); // give the device some time
236 err = usX2Y_AsyncSeq04_init(priv); 236 err = usX2Y_AsyncSeq04_init(priv);
237 if (err) { 237 if (err) {
238 snd_printk("usX2Y_AsyncSeq04_init error \n"); 238 snd_printk(KERN_ERR "usX2Y_AsyncSeq04_init error \n");
239 return err; 239 return err;
240 } 240 }
241 err = usX2Y_In04_init(priv); 241 err = usX2Y_In04_init(priv);
242 if (err) { 242 if (err) {
243 snd_printk("usX2Y_In04_init error \n"); 243 snd_printk(KERN_ERR "usX2Y_In04_init error \n");
244 return err; 244 return err;
245 } 245 }
246 err = usX2Y_create_alsa_devices(hw->card); 246 err = usX2Y_create_alsa_devices(hw->card);
247 if (err) { 247 if (err) {
248 snd_printk("usX2Y_create_alsa_devices error %i \n", err); 248 snd_printk(KERN_ERR "usX2Y_create_alsa_devices error %i \n", err);
249 snd_card_free(hw->card); 249 snd_card_free(hw->card);
250 return err; 250 return err;
251 } 251 }
diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c
index e6e6da159671..cf77313c609d 100644
--- a/sound/usb/usx2y/usbusx2y.c
+++ b/sound/usb/usx2y/usbusx2y.c
@@ -251,9 +251,8 @@ static void i_usX2Y_In04Int(struct urb* urb, struct pt_regs *regs)
251 } 251 }
252 } 252 }
253 253
254 if (err) { 254 if (err)
255 snd_printk("In04Int() usb_submit_urb err=%i\n", err); 255 snd_printk(KERN_ERR "In04Int() usb_submit_urb err=%i\n", err);
256 }
257 256
258 urb->dev = usX2Y->chip.dev; 257 urb->dev = usX2Y->chip.dev;
259 usb_submit_urb(urb, GFP_ATOMIC); 258 usb_submit_urb(urb, GFP_ATOMIC);
diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index 0f09e0de52dd..affda973cece 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -78,7 +78,7 @@ static int usX2Y_urb_capt_retire(snd_usX2Y_substream_t *subs)
78 for (i = 0; i < nr_of_packs(); i++) { 78 for (i = 0; i < nr_of_packs(); i++) {
79 cp = (unsigned char*)urb->transfer_buffer + urb->iso_frame_desc[i].offset; 79 cp = (unsigned char*)urb->transfer_buffer + urb->iso_frame_desc[i].offset;
80 if (urb->iso_frame_desc[i].status) { /* active? hmm, skip this */ 80 if (urb->iso_frame_desc[i].status) { /* active? hmm, skip this */
81 snd_printk("activ frame status %i. Most propably some hardware problem.\n", urb->iso_frame_desc[i].status); 81 snd_printk(KERN_ERR "activ frame status %i. Most propably some hardware problem.\n", urb->iso_frame_desc[i].status);
82 return urb->iso_frame_desc[i].status; 82 return urb->iso_frame_desc[i].status;
83 } 83 }
84 len = urb->iso_frame_desc[i].actual_length / usX2Y->stride; 84 len = urb->iso_frame_desc[i].actual_length / usX2Y->stride;
@@ -134,7 +134,7 @@ static int usX2Y_urb_play_prepare(snd_usX2Y_substream_t *subs,
134 counts = cap_urb->iso_frame_desc[pack].actual_length / usX2Y->stride; 134 counts = cap_urb->iso_frame_desc[pack].actual_length / usX2Y->stride;
135 count += counts; 135 count += counts;
136 if (counts < 43 || counts > 50) { 136 if (counts < 43 || counts > 50) {
137 snd_printk("should not be here with counts=%i\n", counts); 137 snd_printk(KERN_ERR "should not be here with counts=%i\n", counts);
138 return -EPIPE; 138 return -EPIPE;
139 } 139 }
140 /* set up descriptor */ 140 /* set up descriptor */
@@ -196,7 +196,7 @@ static int usX2Y_urb_submit(snd_usX2Y_substream_t *subs, struct urb *urb, int fr
196 urb->hcpriv = NULL; 196 urb->hcpriv = NULL;
197 urb->dev = subs->usX2Y->chip.dev; /* we need to set this at each time */ 197 urb->dev = subs->usX2Y->chip.dev; /* we need to set this at each time */
198 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 198 if ((err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
199 snd_printk("usb_submit_urb() returned %i\n", err); 199 snd_printk(KERN_ERR "usb_submit_urb() returned %i\n", err);
200 return err; 200 return err;
201 } 201 }
202 return 0; 202 return 0;
@@ -283,16 +283,16 @@ static void usX2Y_clients_stop(usX2Ydev_t *usX2Y)
283 283
284static void usX2Y_error_urb_status(usX2Ydev_t *usX2Y, snd_usX2Y_substream_t *subs, struct urb *urb) 284static void usX2Y_error_urb_status(usX2Ydev_t *usX2Y, snd_usX2Y_substream_t *subs, struct urb *urb)
285{ 285{
286 snd_printk("ep=%i stalled with status=%i\n", subs->endpoint, urb->status); 286 snd_printk(KERN_ERR "ep=%i stalled with status=%i\n", subs->endpoint, urb->status);
287 urb->status = 0; 287 urb->status = 0;
288 usX2Y_clients_stop(usX2Y); 288 usX2Y_clients_stop(usX2Y);
289} 289}
290 290
291static void usX2Y_error_sequence(usX2Ydev_t *usX2Y, snd_usX2Y_substream_t *subs, struct urb *urb) 291static void usX2Y_error_sequence(usX2Ydev_t *usX2Y, snd_usX2Y_substream_t *subs, struct urb *urb)
292{ 292{
293 snd_printk("Sequence Error!(hcd_frame=%i ep=%i%s;wait=%i,frame=%i).\n" 293 snd_printk(KERN_ERR "Sequence Error!(hcd_frame=%i ep=%i%s;wait=%i,frame=%i).\n"
294 "Most propably some urb of usb-frame %i is still missing.\n" 294 KERN_ERR "Most propably some urb of usb-frame %i is still missing.\n"
295 "Cause could be too long delays in usb-hcd interrupt handling.\n", 295 KERN_ERR "Cause could be too long delays in usb-hcd interrupt handling.\n",
296 usb_get_current_frame_number(usX2Y->chip.dev), 296 usb_get_current_frame_number(usX2Y->chip.dev),
297 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", usX2Y->wait_iso_frame, urb->start_frame, usX2Y->wait_iso_frame); 297 subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", usX2Y->wait_iso_frame, urb->start_frame, usX2Y->wait_iso_frame);
298 usX2Y_clients_stop(usX2Y); 298 usX2Y_clients_stop(usX2Y);
@@ -653,9 +653,8 @@ static void i_usX2Y_04Int(struct urb* urb, struct pt_regs *regs)
653{ 653{
654 usX2Ydev_t* usX2Y = urb->context; 654 usX2Ydev_t* usX2Y = urb->context;
655 655
656 if (urb->status) { 656 if (urb->status)
657 snd_printk("snd_usX2Y_04Int() urb->status=%i\n", urb->status); 657 snd_printk(KERN_ERR "snd_usX2Y_04Int() urb->status=%i\n", urb->status);
658 }
659 if (0 == --usX2Y->US04->len) 658 if (0 == --usX2Y->US04->len)
660 wake_up(&usX2Y->In04WaitQueue); 659 wake_up(&usX2Y->In04WaitQueue);
661} 660}
@@ -740,7 +739,7 @@ static int usX2Y_format_set(usX2Ydev_t *usX2Y, snd_pcm_format_t format)
740 } 739 }
741 usb_kill_urb(usX2Y->In04urb); 740 usb_kill_urb(usX2Y->In04urb);
742 if ((err = usb_set_interface(usX2Y->chip.dev, 0, alternate))) { 741 if ((err = usb_set_interface(usX2Y->chip.dev, 0, alternate))) {
743 snd_printk("usb_set_interface error \n"); 742 snd_printk(KERN_ERR "usb_set_interface error \n");
744 return err; 743 return err;
745 } 744 }
746 usX2Y->In04urb->dev = usX2Y->chip.dev; 745 usX2Y->In04urb->dev = usX2Y->chip.dev;
@@ -787,7 +786,7 @@ static int snd_usX2Y_pcm_hw_params(snd_pcm_substream_t *substream,
787 } 786 }
788 } 787 }
789 if (0 > (err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)))) { 788 if (0 > (err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)))) {
790 snd_printk("snd_pcm_lib_malloc_pages(%p, %i) returned %i\n", substream, params_buffer_bytes(hw_params), err); 789 snd_printk(KERN_ERR "snd_pcm_lib_malloc_pages(%p, %i) returned %i\n", substream, params_buffer_bytes(hw_params), err);
791 return err; 790 return err;
792 } 791 }
793 return 0; 792 return 0;
diff --git a/sound/usb/usx2y/usx2yhwdeppcm.c b/sound/usb/usx2y/usx2yhwdeppcm.c
index d0199c4e5551..0dc828ff9e94 100644
--- a/sound/usb/usx2y/usx2yhwdeppcm.c
+++ b/sound/usb/usx2y/usx2yhwdeppcm.c
@@ -73,7 +73,7 @@ static int usX2Y_usbpcm_urb_capt_retire(snd_usX2Y_substream_t *subs)
73 } 73 }
74 for (i = 0; i < nr_of_packs(); i++) { 74 for (i = 0; i < nr_of_packs(); i++) {
75 if (urb->iso_frame_desc[i].status) { /* active? hmm, skip this */ 75 if (urb->iso_frame_desc[i].status) { /* active? hmm, skip this */
76 snd_printk("activ frame status %i. Most propably some hardware problem.\n", urb->iso_frame_desc[i].status); 76 snd_printk(KERN_ERR "activ frame status %i. Most propably some hardware problem.\n", urb->iso_frame_desc[i].status);
77 return urb->iso_frame_desc[i].status; 77 return urb->iso_frame_desc[i].status;
78 } 78 }
79 lens += urb->iso_frame_desc[i].actual_length / usX2Y->stride; 79 lens += urb->iso_frame_desc[i].actual_length / usX2Y->stride;
@@ -126,7 +126,7 @@ static int usX2Y_hwdep_urb_play_prepare(snd_usX2Y_substream_t *subs,
126 /* calculate the size of a packet */ 126 /* calculate the size of a packet */
127 counts = shm->captured_iso[shm->playback_iso_head].length / usX2Y->stride; 127 counts = shm->captured_iso[shm->playback_iso_head].length / usX2Y->stride;
128 if (counts < 43 || counts > 50) { 128 if (counts < 43 || counts > 50) {
129 snd_printk("should not be here with counts=%i\n", counts); 129 snd_printk(KERN_ERR "should not be here with counts=%i\n", counts);
130 return -EPIPE; 130 return -EPIPE;
131 } 131 }
132 /* set up descriptor */ 132 /* set up descriptor */